Skip to content

fix(events): drop rewound turns when rewind target is outside the window - #7860

Open
ninglinLiu wants to merge 14 commits into
google:mainfrom
ninglinLiu:fix/7859-rewind-window-leak
Open

ninglinLiu wants to merge 14 commits into
google:mainfrom
ninglinLiu:fix/7859-rewind-window-leak

Conversation

@ninglinLiu

Copy link
Copy Markdown
Contributor

Description

_apply_rewinds only removed a rewound span when the target invocation was present in the loaded event list. With RunConfig.get_session_config=GetSessionConfig(num_recent_events=…) (or after_timestamp) the window can start after the rewind target, so the marker matched nothing and rewound turns leaked back into the LLM prompt.

When the target is missing from the list, stop the backward walk so every earlier event stays out of the active history. That covers truncated windows and unknown rewind targets.

Fixes #7859

Test plan

  • Extended tests/unittests/events/test_rewind_events.py with a window-style case (inv-1 target omitted; inv-2 events before the marker are dropped)
  • Updated the unknown-target case to expect an empty active list

AI assistance

Prepared with Cursor assistance; I verified the _apply_rewinds walk and the new unit tests.

_apply_rewinds only jumped when the rewind target invocation was present
in the loaded list. A GetSessionConfig.num_recent_events / after_timestamp
window that starts after the target left the rewind marker without a
match, so later (rewound) turns leaked back into the LLM prompt.

When the target is missing, stop the backward walk so every earlier event
in the list stays out of the active history.

Fixes google#7859
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

A num_recent_events window puts rewound turns back into the prompt

2 participants