Repository navigation
fix(compaction): long sessions lose their own decisions when recent tool output overflows the summary - #195028
Conversation
…urns The safeguard reserved room for the whole suffix before sizing the generated summary body, so verbatim preserved-turn context (mostly tool output) cut the model's own decisions, TODOs and identifiers. The body now reserves only the suffix's required sections; preserved turns take what remains, a cut keeps their heading, and the generated split-turn summary is reserved ahead of older preserved turns. Preserved tool results keep a 160-char head excerpt. Suffix budgeting moves to compaction-safeguard-budget.ts. Refs #194408 Co-authored-by: obviyus <[email protected]>
|
🦞👀 Pull request received. I will update this pull request when review starts. ClawSweeper review completeClawSweeper finished reviewing this revision. The review result is being finalized. |
|
Codex review: needs maintainer review before merge. What this changesThis PR prioritizes generated compaction summaries over verbatim recent turns and shortens preserved tool-result excerpts. Example: A 10,018-character generated summary and twelve bulky recent messages exceed the 16,000-character artifact limit.
Review scores
ProductKind: Bug fix · Worth it: Yes · Fix scope: Partial Merge readiness✅ Ready for maintainer review Keep open: this PR addresses a current-main compaction retention bug, and the introduced changes contain no actionable correctness or security finding. Priority: P2 Before mergeNone. FindingsNone. Tests
Agent review detailsHow this fits togetherThe safeguard receives prepared conversation history and generated summaries, combines them with recent context and diagnostic sections, and returns a bounded summary for session persistence and subsequent model requests. flowchart TD
A[Prepared conversation history] --> B[Summary provider]
B --> C[Generated summary body]
A --> D[Recent context and diagnostics]
C --> E[Safeguard budget owner]
D --> E
E --> F[Persisted compaction summary]
F --> G[Next model request]
Technical reviewBest possible solution: Keep the existing safeguard as the single budget owner and let verbatim context yield to generated facts within the current cap. Do we have a high-confidence way to reproduce the issue? Current-main allocation demonstrably lets a bulky suffix cut an otherwise affordable generated body, and the new boundary regressions encode that case; no target code was executed during this read-only review. Is this the best way to solve the issue? The repair changes allocation at the existing finalization owner, removes the superseded reservation path, and preserves token fitting and atomic context boundaries without introducing a competing policy. AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning medium; reviewed against 31af70774f99. Provenance checked
TestingProof path: in-process harness. SecurityNone. EvidenceWhat I checked:
Likely related people:
PR surfaceSource +83, Tests +46, Other +129. Total +258 across 9 files. Added test files: 0. View PR surface stats
Preflight sourceSource unknown. Source comparison at the observed PR snapshot only. Completion is self-reported; body, policy, tests, execution, and report bytes are not verified. LabelsLabel changes: No label changes. Label justifications:
Rating scale6/6 🦀 challenger crab · 5/6 🦞 diamond lobster · 4/6 🐚 platinum hermit · 3/6 🦐 gold shrimp · 2/6 🦪 silver shellfish · 1/6 🧂 unranked krab. Overall follows the weaker of proof and patch quality; ✨ marks media proof (a screenshot, video, or linked artifact) that directly shows the changed behavior. WorkflowClawSweeper edits this one comment on every review. Comment HistoryReview history (3 earlier review cycles)
Reviewed November 8, 2026, 12:52 AM ET / 05:52 UTC (Revision 4). |
…y QA proof Always reserving the generated split-turn summary could crowd out required tail sections (tool failures, file operations, workspace rules) when both the body and the split summary were large. The suffix is now assembled in chronological order (preserved turns, split turn, required sections), so the head-first tail cap trims older verbatim turns first and the reservation is removed. A restored context heading keeps its leading separator. Adds a qa-lab scenario that overflows a tool-heavy seeded session through the real Gateway and asserts the persisted summary keeps the generated body whole and excerpts preserved tool output; transcript seeding gains tool calls and results, and mock compaction summaries move to their own module. Refs #194408 Co-authored-by: obviyus <[email protected]>
|
🦞👀 Re-review progress:
|
Co-authored-by: obviyus <[email protected]>
|
🦞👀 Re-review progress:
|
Co-authored-by: obviyus <[email protected]>
Co-authored-by: obviyus <[email protected]>
|
🦞👀 Re-review progress:
|
|
Merged via squash.
|
…ool output overflows the summary (openclaw#195028) * fix(compaction): keep generated summary ahead of verbatim preserved turns The safeguard reserved room for the whole suffix before sizing the generated summary body, so verbatim preserved-turn context (mostly tool output) cut the model's own decisions, TODOs and identifiers. The body now reserves only the suffix's required sections; preserved turns take what remains, a cut keeps their heading, and the generated split-turn summary is reserved ahead of older preserved turns. Preserved tool results keep a 160-char head excerpt. Suffix budgeting moves to compaction-safeguard-budget.ts. Refs openclaw#194408 Co-authored-by: obviyus <[email protected]> * fix(compaction): order suffix chronologically and add summary-priority QA proof Always reserving the generated split-turn summary could crowd out required tail sections (tool failures, file operations, workspace rules) when both the body and the split summary were large. The suffix is now assembled in chronological order (preserved turns, split turn, required sections), so the head-first tail cap trims older verbatim turns first and the reservation is removed. A restored context heading keeps its leading separator. Adds a qa-lab scenario that overflows a tool-heavy seeded session through the real Gateway and asserts the persisted summary keeps the generated body whole and excerpts preserved tool output; transcript seeding gains tool calls and results, and mock compaction summaries move to their own module. Refs openclaw#194408 Co-authored-by: obviyus <[email protected]> * test(compaction): tighten split-turn file-ops regression Co-authored-by: obviyus <[email protected]> * test: allocate test lines for compaction summary priority regressions Co-authored-by: obviyus <[email protected]> * test: size compaction test-line allocation to measured growth Co-authored-by: obviyus <[email protected]> Co-authored-by: Ayaan Zaidi <[email protected]>
…ool output overflows the summary (#195028) * fix(compaction): keep generated summary ahead of verbatim preserved turns The safeguard reserved room for the whole suffix before sizing the generated summary body, so verbatim preserved-turn context (mostly tool output) cut the model's own decisions, TODOs and identifiers. The body now reserves only the suffix's required sections; preserved turns take what remains, a cut keeps their heading, and the generated split-turn summary is reserved ahead of older preserved turns. Preserved tool results keep a 160-char head excerpt. Suffix budgeting moves to compaction-safeguard-budget.ts. Refs #194408 Co-authored-by: obviyus <[email protected]> * fix(compaction): order suffix chronologically and add summary-priority QA proof Always reserving the generated split-turn summary could crowd out required tail sections (tool failures, file operations, workspace rules) when both the body and the split summary were large. The suffix is now assembled in chronological order (preserved turns, split turn, required sections), so the head-first tail cap trims older verbatim turns first and the reservation is removed. A restored context heading keeps its leading separator. Adds a qa-lab scenario that overflows a tool-heavy seeded session through the real Gateway and asserts the persisted summary keeps the generated body whole and excerpts preserved tool output; transcript seeding gains tool calls and results, and mock compaction summaries move to their own module. Refs #194408 Co-authored-by: obviyus <[email protected]> * test(compaction): tighten split-turn file-ops regression Co-authored-by: obviyus <[email protected]> * test: allocate test lines for compaction summary priority regressions Co-authored-by: obviyus <[email protected]> * test: size compaction test-line allocation to measured growth Co-authored-by: obviyus <[email protected]> Co-authored-by: Ayaan Zaidi <[email protected]> (cherry picked from commit 2d4ec7b) Release adaptation: retain the 2026.11.3 branch's assembleSuffix and splitPreservedRecentTurns owners, current request recovery and session-store seeding contracts, and existing 16000-character/runtime decisions. Adapt the three regressions to current fixtures; preserve the upstream atomic-boundary fixture expansion and extract the two priority regressions into a coherent sibling to avoid growing the grandfathered oversized test file, and record 103 net test lines. Rename the QA final-answer marker to avoid the mock continuation-keyword heuristic while preserving all real-boundary assertions. No configuration or public-contract change. Closure: canonical probe found only the three expected owner/test conflicts. Companion audit through 742ed31 found no later same-path fix or PR-number companion; current fitter/quality/QA contracts are present-equivalent. Independent read-only review found no P0-P2 issues. Proof: two new owning-hook regressions failed before the fix; 55 focused core tests and 138 QA adapter tests pass. The real isolated Gateway/mock scenario passes including overflow recovery, intact generated summary and excerpted tool output. Focused native types, type-aware lint, format, line-cap and exact test allocation checks pass. Final independent read-only review found no P0-P2 issues. Co-authored-by: RomneyDa <[email protected]>
Release adaptation: Keep the release SQLite planner helper private and omit agent-port-projections.ts, which does not exist on this release line. Preserve all baseline assertions by materializing four small test fixtures, and exercise lazy payload reads through the actual SQLite planner rather than a fake source. Allocate the exact 64 net test lines. No schema, config, or authority changes. Later same-path followups through 568d89f: 8633af9 (#194591) is the non-applicable PostgreSQL surrogate repair; b6ed907 (#193682) is the non-applicable schema41 hydration migration. Neither is a streaming prerequisite. Existing #195028 and #196277 repair contracts remain intact. Verified: baseline lazy-read regression fails; 32 focused tests pass across five suites, including compiled-worker publication and authority boundaries. Targeted types, lint, format, and whitespace checks pass. Fresh independent read-only review found no P0-P2 issues. (cherry picked from commit 7bc0ae7) Co-authored-by: vincentkoc <[email protected]> Co-authored-by: RomneyDa <[email protected]>
Related: #194408
What Problem This Solves
Fixes: after compaction the agent forgets decisions, TODOs and IDs from the summarized span when the most recent turns before the cut carried a lot of tool output.
User Impact
User impact: compacted summaries keep almost all of the model's own decisions and TODOs at the same 16,000-character size, with no extra replay cost and no new setting.
Why This Change Was Made
The persisted summary holds the model-written summary plus verbatim "recent turns preserved" context. Before this change the body only got half the budget once that suffix was large, so verbatim tool output (each result up to 600 chars, dozens per turn) displaced the generated summary. In 16 replayed production compactions the model's summary was always 6.9k–12.7k chars and would have fit on its own.
[N more chars omitted at compaction], similar to how Hermes Agent demotes stale tail tool output to stubs.compaction-safeguard-budget.ts(line-cap ratchet).This is an alternative to raising the cap (#194719): the replay showed the cap was binding because of how it was split, not because summaries needed more room.
Evidence
Replay of 16 truncated production compactions from one long-running agent (tokensBefore 144k–1.05M). Each span was rebuilt from stored entries with
prepareCompactionand run through the real safeguard with the qualityGuard on, using the same cached Opus 5.5 summary responses for every variant:32k gets the last few points at roughly +2–3% cached-context cost per compaction window (a summary is replayed on a mean of 336 requests); 64k adds nothing over 32k.
End-to-end (real Gateway child, qa-channel, mock-openai provider): new scenario
qa/scenarios/runtime/compaction-summary-priority.yamlseeds a session with three tool-heavy recent turns, overflows once, recovers through one safeguard compaction and delivers the final answer.[N more chars omitted at compaction].compaction-retry-mutating-toolpasses.compaction-empty-response-recovery,compaction-reasoning-only-recovery,goal-context-survives-compaction,cjk-tool-result-budgetandgateway-compaction-abortfail identically on unmodified main (44a5a65).Tests:
keeps a generated summary whole when verbatim preserved turns overflow the capandkeeps only a head excerpt of preserved tool output. Both fail on main.finally trims a raw tool interaction only at its atomic boundary: fixture raised from 12 to 80 tool results so the interaction still overflows with excerpted output.keeps required file operations when a large split-turn summary meets a large body(fails with the first revision's split-turn reservation).compaction-safeguard*.test.ts(5 files, 57 tests) andpackages/agent-core/src/harness/compaction(132 tests) pass.pnpm check:changed: all steps pass exceptchangelog attributions, which fails on main on untouchedCHANGELOG/*.mdfiles.src/agents/sessions/agent-session-compaction.test.tshas 5 local failures that reproduce identically on main without this change.Gaps: the replay did not measure compounding across successive compactions (each case started from the stored 16k summary), and identifiers lost before the summarizer (its input is sampled to 160k chars) are unaffected by this change.