Compare commits

...

2 Commits

Author SHA1 Message Date
Otto
3a939d1989 fix: correct start_index calculation for reduced slice
Sentry correctly identified that passing slice_start was wrong because
reduced_recent doesn't start at slice_start in messages_dict - it starts
at slice_start + (len(recent_messages) - keep_count).

The backwards search needs to start from the TRUE beginning of reduced_recent
in messages_dict, otherwise it will miss assistant messages between slice_start
and the actual start of reduced_recent.
2026-02-01 19:23:33 +00:00
Otto
39177b6e43 fix(copilot): use messages_dict in fallback context compaction
The fallback path in _stream_chat_chunks was passing recent_messages
(already sliced) instead of messages_dict (full conversation) to
_ensure_tool_pairs_intact. This caused the function to fail to find
assistant messages that exist in the original conversation but were
outside the sliced window.

Fix: Pass messages_dict and slice_start (relative to messages_dict)
instead of recent_messages and reduced_slice_start.

Fixes SECRT-1861
Related: SECRT-1839
2026-02-01 17:36:51 +00:00

View File

@@ -1184,11 +1184,14 @@ async def _stream_chat_chunks(
else recent_messages
)
# Ensure tool pairs stay intact in the reduced slice
reduced_slice_start = max(
# Note: Search in messages_dict (full conversation) not recent_messages
# (already sliced), so we can find assistants outside the current slice.
# Calculate where reduced_recent starts in messages_dict
reduced_start_in_dict = slice_start + max(
0, len(recent_messages) - keep_count
)
reduced_recent = _ensure_tool_pairs_intact(
reduced_recent, recent_messages, reduced_slice_start
reduced_recent, messages_dict, reduced_start_in_dict
)
if has_system_prompt:
messages = [