Skip to content

fix(agent): metadata flag on compression summary messages, wire-safe key (salvages #38434)#45281

Merged
teknium1 merged 2 commits into
mainfrom
fix/compaction-summary-metadata-flag
Jun 12, 2026
Merged

fix(agent): metadata flag on compression summary messages, wire-safe key (salvages #38434)#45281
teknium1 merged 2 commits into
mainfrom
fix/compaction-summary-metadata-flag

Conversation

@teknium1

Copy link
Copy Markdown
Contributor

Summary

Context compression summary messages now carry an in-process metadata flag (_compressed_summary: True) so frontends (CLI, Desktop, gateway, TUI) can identify them without content-prefix heuristics (#38389).

Closes #38389. (Dupes #38391, #38392 close with it.)

Changes

  • agent/context_compressor.py: flag set on the standalone summary message AND the merge-into-tail message; _has_compressed_summary_metadata() helper for consumers — from fix(agent): add metadata flag to context compression summary messages #38389 #38434 by @kyssta-exe
  • Key renamed during salvage: the PR used is_compressed_summary (bare key) — that would ride messages onto the wire, and strict gateways (Fireworks, Mistral, Moonshot/Kimi, opencode-go) 400 on unknown message keys ("Extra inputs are not permitted"). Renamed to underscore-prefixed _compressed_summary, which the existing wire sanitizers (ChatCompletionsTransport.convert_messages + the summary-path mirror in chat_completion_helpers.py) already strip
  • tests/agent/test_compressed_summary_metadata.py: flag set in-process, underscore invariant, transport strips it without destroying the in-process flag

Validation

Result
E2E (real compress() + real ChatCompletionsTransport) 61→13 msgs, exactly 1 flagged, 0 wire leaks, originals intact
metadata + prefix-semantics + anchor suites 33 passed

Attribution

Salvages #38434 by @kyssta-exe — commit re-applied onto current main (conflicted with the _SUMMARY_END_MARKER hoist) with authorship preserved; rebase-merge to keep per-commit credit. The key rename is our follow-up commit.

Infographic

compressed-summary-metadata

kyssta-exe and others added 2 commits June 12, 2026 16:32
…#38389)

Summary messages (standalone insertion and merge-into-tail) now carry a
metadata flag so frontends (CLI, Desktop, gateway, TUI) can distinguish
them from real assistant/user messages without content-prefix heuristics.

Re-applied from PR #38434 onto current main (conflicted with the
_SUMMARY_END_MARKER hoist). Key renamed from the PR's
'is_compressed_summary' to '_compressed_summary': the wire sanitizers
strip underscore-prefixed message keys, so the flag stays in-process and
can never reach strict gateways (Fireworks/Mistral/Kimi reject unknown
keys with 'Extra inputs are not permitted').
@github-actions

Copy link
Copy Markdown
Contributor

🔎 Lint report: fix/compaction-summary-metadata-flag vs origin/main

ruff

Total: 0 on HEAD, 0 on base (➖ 0)

🆕 New issues: none

✅ Fixed issues: none

Unchanged: 0 pre-existing issues carried over.

ty (type checker)

Total: 10882 on HEAD, 10881 on base (🆕 +1)

🆕 New issues (1):

Rule Count
unresolved-import 1
First entries
tests/agent/test_compressed_summary_metadata.py:17: [unresolved-import] unresolved-import: Cannot resolve imported module `pytest`

✅ Fixed issues: none

Unchanged: 5705 pre-existing issues carried over.

Diagnostics are surfaced as warnings — this check never fails the build.

@liuhao1024

Copy link
Copy Markdown
Contributor

Verification: Code Review — Clean ✅

Reviewed the compressed-summary metadata flag. Key checks:

  1. Underscore-prefix for wire safety: COMPRESSED_SUMMARY_METADATA_KEY = "_compressed_summary" — the _ prefix ensures the chat-completions wire sanitizer strips it before API calls. The test test_key_is_underscore_prefixed explicitly guards this invariant. Strict gateways (Fireworks, Mistral, Moonshot) won't see it.

  2. Merge-into-tail path: The flag is set on both standalone summary messages and merged-into-tail messages. test_exactly_one_flagged_message_after_compress verifies exactly one flagged message per compress() call.

  3. Helper method correctness: _has_compressed_summary_metadata handles non-dict and None inputs cleanly.

  4. Wire sanitization test: test_chat_completions_transport_strips_flag verifies the flag is stripped in the wire representation while the original in-process messages retain it.

No issues found. Clean, well-tested behavioral addition with proper wire-safety guarantees.

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.

Context compression summaries injected as regular assistant messages, polluting visible conversation

3 participants