Skip to content

Fix automatic compaction dropping the newest user turn - #603

Open
elrensmin wants to merge 2 commits into
huggingface:mainfrom
elrensmin:fix/compaction-keeps-newest-user-turn
Open

Fix automatic compaction dropping the newest user turn#603
elrensmin wants to merge 2 commits into
huggingface:mainfrom
elrensmin:fix/compaction-keeps-newest-user-turn

Conversation

@elrensmin

Copy link
Copy Markdown

Motivation

_first_recent_context_index decides where automatic compaction starts keeping rows. Its "keep whole user turns" logic could move the boundary past the last user message, silently destroying the most recent context:

  • [user, assistant, user, assistant] kept only the final assistant reply, dropping the newest user prompt.
  • [user, assistant, toolResult, toolResult] compacted the entire context including the newest turn.

Summary of behavior changes

  • The compaction boundary is now clamped to the last user message, so the newest user turn and its reply are always retained.
  • When nothing can be kept without dropping the newest turn, automatic compaction is skipped instead of compacting everything.

Tests / checks

  • Added pure-function regression tests for the boundary cases in tests/test_coding_session.py.
  • CI checks clean

Notes

  • Localized to _first_recent_context_index in tau_coding.session; no cross-layer changes.
  • Added dev-notes/compaction-keeps-newest-user-turn.md.

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.

1 participant