Skip to content

[NO-JIRA] self_compact: summarize only agent-visible, non-turn-context messages - #50

Merged
johnnymo87 merged 1 commit into
patched/v1.61.1from
fix-self-compact-visible
Dec 3, 2026
Merged

johnnymo87 merged 1 commit into
patched/v1.61.1from
fix-self-compact-visible

Conversation

@johnnymo87

Copy link
Copy Markdown
Owner

Summary

Fix a regression introduced when porting the R11 self-compaction patch onto upstream v1.61.1 (which removed do_compact in aaif-goose#13575): compact_messages_with_kind passed the full conversation.messages() slice directly to oi_kit_context_management::summarize(), including agent_visible = false messages archived by earlier compactions and turn-context messages.

On long-lived sessions with prior compactions, self_compact_and_resume sent the entire archived history (millions of tokens, e.g. 3.62M tokens on a 326K visible session) to the summarizer, causing it to exceed the 1M context window even after stripping all tool responses (Failed to compact: context limit exceeded even after removing all tool responses).

This restores the exact !msg.is_turn_context() + .agent_visible_messages() projection used in v1.60.2's do_compact and v1.61.1's oi_kit_agent::compaction::CompactionOperation::summarize_standalone.

Note: this fixes archived/hidden history leaking into self_compact_and_resume; if a session's agent-visible context alone exceeds the summarizer's window even with tool responses stripped, summarize() will still return ContextLengthExceeded as upstream does.

Changes

  • crates/goose/src/context_mgmt/mod.rs: filter out turn-context messages and project via .agent_visible_messages() before calling oi_kit_context_management::summarize().
  • crates/goose/src/context_mgmt/mod.rs: add unit test self_compact_summarizes_only_agent_visible_non_turn_context_messages (verified failing before the fix, passing after).
  • .github/workflows/patched-test.yml: register the new test in the exact-match CI filter.

Verification

  • cargo test -p goose --lib -- context_mgmt::tests:: (9/9 passed)
  • cargo test -p goose --test self_compact (19/19 passed)
  • cargo fmt --check and cargo clippy -p goose --lib --test self_compact -- -D warnings clean
  • Adversarial diff review clean (no blockers)

…t messages

When self-compaction was ported onto v1.61.1 (which removed upstream's
do_compact helper in aaif-goose#13575), compact_messages_with_kind passed the full
conversation slice directly to oi_kit_context_management::summarize instead
of filtering out turn-context messages and projecting to
agent_visible_messages().

On long-lived sessions with prior compactions, self_compact_and_resume sent
the entire archived history (millions of tokens) to the summarizer, causing
it to exceed the 1M context window even after stripping all tool responses.

Restore the same !is_turn_context() + agent_visible_messages() projection
used in v1.60.2's do_compact and v1.61.1's oi_kit_agent::compaction.
@johnnymo87
johnnymo87 merged commit f9f7e72 into patched/v1.61.1 Dec 3, 2026
11 checks passed
@johnnymo87
johnnymo87 deleted the fix-self-compact-visible branch December 3, 2026 00:01
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