The context compactor computed split_point against convo_msgs (system messages filtered out) but applied it directly to session.history which includes the system messages. After compaction, the original system prompt was dropped and replaced by an off-by-N slice of the full history. This silently dropped the system prompt (preset, persona, RAG context) from every compacted session — the model would lose persona, RAG, and preset guidance on the next turn after a long conversation. The split in maybe_compact does: convo_msgs = [m for m in messages if m['role'] != 'system'] split_point = len(convo_msgs) // 2 so split_point is indexed against the system-stripped list. But the helper _update_session_history took (session, split_point, summary) and did session.history[split_point:]. session.history is the full list including the leading system messages, so this dropped the first system_msg_count messages. Fix: pass system_msg_count=len(system_msgs) into _update_session_history and use session.history[system_msg_count + split_point:] as the recent slice, with session.history[:system_msg_count] prepended to preserve persona/preset/RAG system messages. Validated: tests/test_compactor_data_loss.py both tests now pass (were failing). tests/test_context_compactor.py 12 pre-existing tests still pass. Symptom was: post-compaction history = [summary] + assistant_1 + user_2 + assistant_2 (system_A was lost). Co-authored-by: Ernest Hysa <ernest@example.com>
14 KiB
14 KiB