Repository navigation
fix(compaction): retain audited facts when summaries exceed cap - #128968
Conversation
|
🦞👀 Pull request received. I will update this pull request when review starts. |
|
Codex review: needs maintainer review before merge. Reviewed August 24, 2026, 10:52 PM ET / August 25, 2026, 02:52 UTC. ClawSweeper reviewWhat this changesThe PR makes safeguard-mode compaction reserve required headings, pending-ask evidence, and strict identifiers inside the 16K persisted-summary budget. Regression provenancePossible regression — probable (reproduction; reviewed change; known regression link). No predecessor PR is attributed. Merge readinessKeep this PR open for normal merge validation. The latest commit addresses the prior split-turn suffix-pressure finding, and current main still uses prefix truncation that can remove audited tail facts; no new discrete correctness defect was found. Priority: P2 Review scores
Verification
Live VerificationCommand: Result: PASS (completed) Assertions:
How this fits togetherCompaction converts session history into a bounded summary for future agent turns. The safeguard audits required sections, current asks, and identifiers before persisting the summary or failing closed. flowchart LR
A[Session history] --> B[Compaction generator]
B --> C[Structured summary]
C --> D[Retention budget planner]
D --> E[Quality audit]
E -->|accepted| F[Persisted session summary]
E -->|rejected| G[Retry or fail closed]
Before merge
Agent review detailsSecurityNone. PR surfaceSource +226, Tests +181. Total +407 across 3 files. View PR surface stats
Review metrics
Root-cause clusterRelationship: Members:
Proposal only: this assessment does not dispatch repair, suppress jobs, mutate sibling items, close, or merge anything. Merge-risk optionsMaintainer options:
Technical reviewBest possible solution: Retain the single budget-owner retention planner, with its feasible, infeasible, and split-turn regressions, then merge after exact-head checks pass. Do we have a high-confidence way to reproduce the issue? Yes, source provides a high-confidence path: current main prefix-caps the structured body before its required tail facts, while the focused regression fixtures model that overflow. This read-only review did not execute the test. Is this the best way to solve the issue? Yes. Reserving audited facts at the summary-budget owner is more maintainable than relying on retries after final truncation, and the follow-up commit covers the prior split-turn suffix gap. AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning high; reviewed against c2602ded7c03. LabelsLabel changes:
Label justifications:
EvidenceWhat I checked:
Likely related people:
Rank-up movesOptional improvements that raise the rating; they are not merge blockers.
Rating scale
Overall follows the weaker of proof and patch quality. Workflow
HistoryReview history (1 earlier review cycle)
|
Exact-head CI and real behavior proofPR head
The temporary proof branch changes only test code; the production PR branch was not modified by this live proof. |
|
/clownfish automerge |
|
/clownfish stop |
|
Merged via squash.
|
|
Got it. Clownfish is floating this back to human review. 🐠 I kept the regular |
|
Clownfish is on the reef for this PR. 🐠 I tagged A maintainer can call |
…ited identifiers Two safeguard defects made auto-compaction fail closed on tool-heavy sessions: 1. When the prepared window held only tool calls/results, the safeguard replaced it with sessionManager.getBranch() — the whole branch from root. Since #112988 made /new a reset entry inside the same transcript, that branch spans every reset and prior compaction (3,565 messages / 5.2 MB on the reporting session), so one compaction became dozens of sequential model calls until the 900s watchdog fired ("Compaction timed out"). The #78390 reason for that fallback (preparation omitting custom messages) is handled by core projectSessionEntryMessage now. Summarize only the prepared window; decide "nothing to summarize" from the boundary-scoped context (buildSessionContext), never the raw branch. Delete the fallback and its sessions_send replay sanitizers, which only existed for it. 2. #122824 moved the identifier oracle to the messages before the recent-turns split, so audited identifiers can live only in preserved turns that are capped at 600 chars/message and 8K per section. The deterministic restore added in #128968 ran only when the artifact exceeded 16K chars; an under-budget body that omits an identifier still failed the audit (missing_identifiers -> guard_blocked). Run the retention plan whenever a strict identifier is missing from the body, and only emit the truncation marker when body text was actually trimmed.
…claw#128968) * fix(compaction): retain audited facts under summary cap * fix(compaction): retain bounded ask context --------- Co-authored-by: roboclaw-bot <[email protected]>
…ited identifiers (#129423) * fix(compaction): restore omitted source identifiers * fix: log ChatGPT stream termination reasons * fix(compaction): summarize the prepared window and always restore audited identifiers Two safeguard defects made auto-compaction fail closed on tool-heavy sessions: 1. When the prepared window held only tool calls/results, the safeguard replaced it with sessionManager.getBranch() — the whole branch from root. Since #112988 made /new a reset entry inside the same transcript, that branch spans every reset and prior compaction (3,565 messages / 5.2 MB on the reporting session), so one compaction became dozens of sequential model calls until the 900s watchdog fired ("Compaction timed out"). The #78390 reason for that fallback (preparation omitting custom messages) is handled by core projectSessionEntryMessage now. Summarize only the prepared window; decide "nothing to summarize" from the boundary-scoped context (buildSessionContext), never the raw branch. Delete the fallback and its sessions_send replay sanitizers, which only existed for it. 2. #122824 moved the identifier oracle to the messages before the recent-turns split, so audited identifiers can live only in preserved turns that are capped at 600 chars/message and 8K per section. The deterministic restore added in #128968 ran only when the artifact exceeded 16K chars; an under-budget body that omits an identifier still failed the audit (missing_identifiers -> guard_blocked). Run the retention plan whenever a strict identifier is missing from the body, and only emit the truncation marker when body text was actually trimmed. * fix(compaction): fund audit sections first and cap the identifier list The retention plan protected the model-written "## Pending user asks" and "## Exact identifiers" sections verbatim. Each re-distill fed the previous summary back, so the identifier list only grew: on the reporting session it was 13,568 of a 13,953-char summary, every other section an empty heading, and the next compaction cancelled with "required quality facts exceed finalized artifact budget" because the protected content alone passed the 16K cap. Protect only what the audit requires (headings, bounded latest-ask context, the audited identifiers). Fund the two audit-bearing sections first so an oversized earlier section cannot starve them, but cap each at 25% of the content budget; the remainder is split across decisions, TODOs, and constraints. * fix(ai): log only structured ChatGPT stream termination facts projectProviderError keeps provider message/body text after credential redaction, so logging errorMessage could persist prompt- or response-derived content. Log timing, stop classification, the error class name, and the projection's structured errorCode/errorType instead, and cover a provider failure whose message must not reach the transport log. * fix(ai): classify ChatGPT stream termination locally Provider error code/type fields are provider-controlled text, so the transport warning logs a fixed local failure category (timeout, caller-abort, provider-failure, transport) plus timing instead. The failed-response test feeds hostile code/type/message values and asserts none reach the log. * fix(compaction): recover omitted conversation from the boundary-scoped range Replace the deleted whole-branch fallback with the bounded safety net it was meant to be: when the prepared window holds no real conversation, project the branch entries the preparation covered — after the last reset/compaction boundary, before firstKeptEntryId — through the core context builder and summarize that range if it contains conversation the preparation dropped. It can never reach behind a boundary, so it cannot re-read the whole session. * fix(compaction): make the audit-section cap hard even when the summary fits Two holes let the identifier snowball survive the 25% share cap: a summary that still fit the 16K budget skipped the retention plan entirely, so a 13.9K identifier dump was fed unchanged into the next re-distill; and the surplus loop handed unused budget back to the protected sections whenever the optional sections were empty — exactly the degraded shape in production. Rebuild whenever an audit section exceeds its cap, and return surplus to the optional sections only. Also classify a direct non-OK HTTP reply (CodexApiError) as a provider failure in the stream-termination diagnostic, with a direct-400 test that keeps provider text out of the log. --------- Co-authored-by: VACInc <[email protected]>
…ited identifiers (openclaw#129423) * fix(compaction): restore omitted source identifiers * fix: log ChatGPT stream termination reasons * fix(compaction): summarize the prepared window and always restore audited identifiers Two safeguard defects made auto-compaction fail closed on tool-heavy sessions: 1. When the prepared window held only tool calls/results, the safeguard replaced it with sessionManager.getBranch() — the whole branch from root. Since openclaw#112988 made /new a reset entry inside the same transcript, that branch spans every reset and prior compaction (3,565 messages / 5.2 MB on the reporting session), so one compaction became dozens of sequential model calls until the 900s watchdog fired ("Compaction timed out"). The openclaw#78390 reason for that fallback (preparation omitting custom messages) is handled by core projectSessionEntryMessage now. Summarize only the prepared window; decide "nothing to summarize" from the boundary-scoped context (buildSessionContext), never the raw branch. Delete the fallback and its sessions_send replay sanitizers, which only existed for it. 2. openclaw#122824 moved the identifier oracle to the messages before the recent-turns split, so audited identifiers can live only in preserved turns that are capped at 600 chars/message and 8K per section. The deterministic restore added in openclaw#128968 ran only when the artifact exceeded 16K chars; an under-budget body that omits an identifier still failed the audit (missing_identifiers -> guard_blocked). Run the retention plan whenever a strict identifier is missing from the body, and only emit the truncation marker when body text was actually trimmed. * fix(compaction): fund audit sections first and cap the identifier list The retention plan protected the model-written "## Pending user asks" and "## Exact identifiers" sections verbatim. Each re-distill fed the previous summary back, so the identifier list only grew: on the reporting session it was 13,568 of a 13,953-char summary, every other section an empty heading, and the next compaction cancelled with "required quality facts exceed finalized artifact budget" because the protected content alone passed the 16K cap. Protect only what the audit requires (headings, bounded latest-ask context, the audited identifiers). Fund the two audit-bearing sections first so an oversized earlier section cannot starve them, but cap each at 25% of the content budget; the remainder is split across decisions, TODOs, and constraints. * fix(ai): log only structured ChatGPT stream termination facts projectProviderError keeps provider message/body text after credential redaction, so logging errorMessage could persist prompt- or response-derived content. Log timing, stop classification, the error class name, and the projection's structured errorCode/errorType instead, and cover a provider failure whose message must not reach the transport log. * fix(ai): classify ChatGPT stream termination locally Provider error code/type fields are provider-controlled text, so the transport warning logs a fixed local failure category (timeout, caller-abort, provider-failure, transport) plus timing instead. The failed-response test feeds hostile code/type/message values and asserts none reach the log. * fix(compaction): recover omitted conversation from the boundary-scoped range Replace the deleted whole-branch fallback with the bounded safety net it was meant to be: when the prepared window holds no real conversation, project the branch entries the preparation covered — after the last reset/compaction boundary, before firstKeptEntryId — through the core context builder and summarize that range if it contains conversation the preparation dropped. It can never reach behind a boundary, so it cannot re-read the whole session. * fix(compaction): make the audit-section cap hard even when the summary fits Two holes let the identifier snowball survive the 25% share cap: a summary that still fit the 16K budget skipped the retention plan entirely, so a 13.9K identifier dump was fed unchanged into the next re-distill; and the surplus loop handed unused budget back to the protected sections whenever the optional sections were empty — exactly the degraded shape in production. Rebuild whenever an audit section exceeds its cap, and return surplus to the optional sections only. Also classify a direct non-OK HTTP reply (CodexApiError) as a provider failure in the stream-termination diagnostic, with a direct-400 test that keeps provider text out of the log. --------- Co-authored-by: VACInc <[email protected]>
Closes #125641
AI-assisted by RoboClaw (Codex).
What Problem This Solves
Fixes an issue where identifier-dense sessions could repeatedly fail compaction when an otherwise valid structured summary exceeded the 16K persisted-summary cap. Prefix truncation removed the trailing pending-ask and exact-identifier sections, so the post-budget quality guard rejected the result and left the session growing.
Why This Change Was Made
The safeguard now plans truncation at the structured-summary owner boundary. When the quality guard is enabled, finalization reserves all required headings, pending-user-ask content/evidence, and strict source identifiers before distributing the remaining body budget across lower-priority prose and optional split-turn/suffix context. Malformed output still follows the existing corrective retry, and compaction remains fail-closed when the mandatory retained facts themselves cannot fit.
The generic agent-core 16K cap, configured compaction-provider behavior, and quality-disabled behavior are unchanged.
Production delta: +186/-13 lines. The added surface is the deterministic retention planner and shared latest-ask evidence calculation needed to make the post-budget audit contract enforceable; test delta is +106/-5.
User Impact
Large sessions with dense paths, URLs, hashes, or IDs can compact successfully without disabling strict identifier preservation. OpenClaw still refuses to persist a summary when the required retained facts are intrinsically larger than the artifact cap.
Evidence
mainregression reproduced two generation attempts followed by{ cancel: true }after the valid tail was truncated.pnpm test src/agents/agent-hooks/compaction-safeguard.test.ts— 131 passed.pnpm check:changed -- src/agents/agent-hooks/compaction-safeguard-quality.ts src/agents/agent-hooks/compaction-safeguard.ts src/agents/agent-hooks/compaction-safeguard.test.ts— passed all selected core/core-test guards, format, lint, and typecheck lanes.pnpm test src/agents/agent-hooks/compaction-safeguard.test.ts -t "audit-required tail sections|reserves split-turn ask evidence"— 3 passed.git diff --check origin/main...HEAD— passed.origin/main— clean, no accepted/actionable findings.Regression coverage proves first-attempt success for feasible audited facts, fail-closed behavior when one required identifier exceeds 16K, and split-turn ask/identifier reservation before optional split context.