Skip to content

fix(compression): append END OF CONTEXT SUMMARY marker to all standalone summaries (salvages #33346)#45153

Merged
teknium1 merged 2 commits into
mainfrom
fix/end-marker-standalone-summaries
Jun 12, 2026
Merged

fix(compression): append END OF CONTEXT SUMMARY marker to all standalone summaries (salvages #33346)#45153
teknium1 merged 2 commits into
mainfrom
fix/end-marker-standalone-summaries

Conversation

@teknium1

Copy link
Copy Markdown
Contributor

Summary

The "END OF CONTEXT SUMMARY" boundary marker is now appended to every standalone compaction summary regardless of role — previously only role="user" summaries got it, so an assistant-role summary could be regurgitated verbatim by the model as its own reply (#33256).

Closes #33256.

Changes

Validation

Before After
Standalone assistant-role summary no end marker → model echoes summary as reply marker appended
Rehydrated handoff body trailing marker leaks into summarizer prompt stripped, re-appended on insertion
compressor + prefix-semantics + continuity + historical-media suites 133 passed

Attribution

Salvages #33346 by @Tranquil-Flow — cherry-picked with authorship preserved; rebase-merge to keep per-commit credit.

Infographic

summary-end-marker-all-roles

Tranquil-Flow and others added 2 commits June 12, 2026 12:22
…dalone summaries regardless of role

When the compression summary lands as an assistant-role message (head ends
with user), the end marker was not appended. Models may regurgitate the
summary text as their own visible output when there's no clear boundary
signal (#33256).

The end marker was already appended for user-role summaries (#11475, #14521)
but the assistant-role path was missed in the original fix. This ensures ALL
standalone summary messages carry the boundary marker, preventing summary
text from leaking into user-visible chat output.
…ip it on rehydration

Follow-up to the #33346 cherry-pick:
- the marker string was duplicated at both insertion sites (standalone +
  merged-into-tail); hoist to a module constant
- _strip_summary_prefix now also strips a trailing end marker so a
  rehydrated handoff body doesn't leak the boundary directive into the
  iterative-update summarizer prompt (it is re-appended on insertion)
@alt-glitch alt-glitch added type/bug Something isn't working comp/agent Core agent loop, run_agent.py, prompt builder P1 High — major feature broken, no workaround labels Jun 12, 2026
@liuhao1024

Copy link
Copy Markdown
Contributor

Verified clean — compression END OF CONTEXT SUMMARY marker for all roles

Reviewed the marker propagation across all three insertion paths:

  1. Standalone summary (summary_role == "user" or "assistant"): The condition changed from if not _merge_summary_into_tail and summary_role == "user" to if not _merge_summary_into_tail — correctly extending the marker to assistant-role standalone summaries. This addresses Context compression summary leaks into user-visible chat output #33256 where models regurgitate assistant-role summaries.

  2. Merged-into-tail: The existing marker was inlined to use _SUMMARY_END_MARKER constant — no behavior change, just deduplication. Correct.

  3. Rehydration stripping (_strip_summary_prefix): Added if text.endswith(_SUMMARY_END_MARKER): text = text[:-len(...)].rstrip() after prefix stripping. The break added to the prefix loop is correct — once a prefix matches, we skip the rest. Previously the code return-ed inside the loop, so the break + post-loop strip is equivalent but enables the marker stripping after the loop. The rstrip() preserves meaningful trailing whitespace from the summary body.

  4. Test coverage: The new test_assistant_role_summary_carries_end_marker correctly constructs a head-last=user scenario that produces summary_role="assistant" and verifies both the role and the marker. The message sequence is carefully designed with protect_first_n=2, protect_last_n=2 and 8 messages to ensure the standalone insertion path.

No issues found.

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

Labels

comp/agent Core agent loop, run_agent.py, prompt builder P1 High — major feature broken, no workaround type/bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Context compression summary leaks into user-visible chat output

4 participants