Repository navigation
fix(agents): stop silent compaction failures - #125302
Conversation
|
🦞👀 Pull request received. I will update this pull request when review starts. |
|
Codex review: needs maintainer review before merge. Reviewed August 17, 2026, 7:47 PM ET / 23:47 UTC. ClawSweeper reviewWhat this changesThe PR replaces ambiguous session-compaction end fields with completed, skipped, failed, or aborted outcomes, then records token snapshots and failure reasons through session persistence and recovery paths. Regression provenancePossible regression — suspected (reviewed change). No predecessor PR is attributed. Merge readinessKeep open for explicit maintainer review. The PR is still needed: current main retains the ambiguous compaction-end fields, while this branch establishes a closed producer-owned outcome and its subscriber projection; no blocking correctness finding was found. Priority: P1 Review scores
Verification
How this fits togetherAgent sessions compact growing transcripts to avoid context overflow. The session producer emits a compaction result, and the embedded-session subscriber records it for persistence, retries, logs, and memory-flush rotation. flowchart LR
A[Agent transcript] --> B[Session compaction]
B --> C[Closed compaction outcome]
C --> D[Embedded session subscriber]
D --> E[Session persistence]
D --> F[Retry and memory-flush decisions]
Decision needed
Why: The PR carries the protected maintainer label and changes session lifecycle and persistence behavior, so the final merge decision requires maintainer intent despite the clean review. Before merge
Agent review detailsSecurityNone. PR surfaceSource +27, Tests +314, Other -1. Total +340 across 21 files. View PR surface stats
Review metrics
Stored data modelPersistent data-model change detected: Merge-risk optionsMaintainer options:
Technical reviewBest possible solution: Keep the producer-owned closed outcome contract, then validate the clean merge result against current main with the focused compaction and subscriber suites before landing. Do we have a high-confidence way to reproduce the issue? Yes: the checked-in focused regressions exercise the producer-to-subscriber path for auth skips, rejected cancellation, successful token projection, and bounded persisted summaries; they were not executed in this read-only review. Is this the best way to solve the issue? Yes: moving outcome truth to the session producer and projecting it once in the subscriber removes the prior parallel optional fields rather than teaching downstream consumers to infer completion. AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning high; reviewed against 389fed29cf1a. LabelsLabel justifications:
EvidenceWhat I checked:
Likely related people:
Rating scale
Overall follows the weaker of proof and patch quality. Workflow
HistoryReview history (7 earlier review cycles)
|
391fcb2 to
c08d8da
Compare
|
Addressed the remaining ClawSweeper manual-cancellation finding at exact head Manual compaction now classifies an ordinary rejection as aborted when its captured controller is signalled and clears the shared controller only while it still owns it. The new real-session producer-to-subscriber regression fails pre-fix as Focused proof: compaction 11/11, cancellation loop 2/2, subscriber handler 13/13, exact changed gate green, and fresh uncommitted autoreview clean. Exact-head CI is being refreshed now. |
|
Merged via squash.
|
* fix(agents): stop silent compaction failures * fix(agents): preserve aborted compaction outcomes * fix(agents): preserve manual abort outcomes
What Problem This Solves
Fixes an issue where automatic session compaction could fail without any recorded reason, causing sessions to keep growing until hard context overflow. Expired or missing model credentials were also collapsed into indistinguishable skips, and successful session-loop compaction never supplied the post-compaction token snapshot that session persistence expects.
Why This Change Was Made
Replace the parallel optional compaction-end fields with one closed completed/skipped/failed/aborted outcome owned by the session producer. Completed outcomes carry tokens before and after; skipped and failed outcomes carry actionable reasons; retry state exists only on completed outcomes. The embedded subscriber forwards the complete event, records the token snapshot, and projects failure reasons without changing the existing public completed/willRetry fields, so no Gateway protocol version or coordinated UI migration is required.
Automatic and manual compaction now capture the exact operation's abort controller, use that controller's signal to classify rejected work as aborted, and clear the shared controller only when it still owns that exact operation. This preserves cancellation through provider or extension rejection instead of misreporting it as failure.
Compaction summaries are now capped at 16,000 UTF-16 code units at the persistence boundary, using the same helper as the safeguard path. This is an intentional model-context bound: the summary is replayed on every subsequent request, so provider token limits alone are not a durable size guarantee. Memory-flush rotation now also requires completed === true instead of treating every compaction end as success.
Provenance: the reasonless automatic-auth/result shape was carried forward by #107948; the impossible tokensAfter read was introduced by f3e8a8a; the max-attempt guidance added in #123484 was produced but never forwarded.
User Impact
Operators now get a recorded reason when automatic compaction fails or cannot authenticate, cancelled automatic or manual compactions remain visible as benign aborts even when work rejects, overflow exhaustion is observable, and successful compaction immediately refreshes persisted context totals. Oversized summaries cannot silently consume unbounded context on every later turn.
Evidence
Final local proof on head
883a9981d9baa611622a459163343665d2c37dc0:src/agents/sessions/agent-session-compaction.test.tsfailed because the observable compaction end wasoutcome: "failed"withreason: "Compaction failed: synthetic manual cancellation rejection"; after the fix the original promise still rejects with the synthetic error while the observable end is a reasonlessoutcome: "aborted",completed: false,willRetry: false, with no compaction entry/count/token snapshot.outcome: "aborted",completed: false,willRetry: false, with no compaction entry/count/token snapshot.node scripts/run-vitest.mjs src/agents/sessions/agent-session-compaction.test.ts— 1 file, 11 tests passed.node scripts/run-vitest.mjs src/agents/sessions/agent-session-loop-correctness.test.ts -t 'preserves cancellation'— 2 tests passed; 24 unrelated tests skipped by the filter.node scripts/run-vitest.mjs src/agents/embedded-agent-subscribe.handlers.compaction.test.ts— 1 file, 13 tests passed.node_modules/.bin/oxfmt src/agents/sessions/agent-session-compaction.ts src/agents/sessions/agent-session-compaction.test.ts— clean.git diff --check— clean.node scripts/check-changed.mjs --dry-run -- src/agents/sessions/agent-session-compaction.ts src/agents/sessions/agent-session-compaction.test.ts— selected onlycoreandcoreTests.node scripts/check-changed.mjs -- src/agents/sessions/agent-session-compaction.ts src/agents/sessions/agent-session-compaction.test.ts— green, including core/core-test typecheck, lint, formatting, architecture, database, schema-version, dead-export, and import-cycle guards..claude/skills/autoreview/scripts/autoreview --mode uncommitted— clean one-pass review, TruffleHog clean, no accepted/actionable findings, overall correctness 0.99.pull_requestCI — run 32080848415 green;openclaw/ci-gategreen for883a9981d9baa611622a459163343665d2c37dc0.Changed LOC: production +204/-177 (net +27); tests/support +493/-179 (net +314); tooling +0/-1. The manual-abort follow-up itself is production +8/-4 (net +4) and test +58/-0. The tooling change is the required shrink-only deletion from
config/assertion-safety-baseline.txt. There are no unrelated paths, changelog, release/version, generated API/protocol, lockfile, dependency, or other config changes.Pre-fix evidence covered the missing automatic-auth reason, missing
tokensAfter, an uncapped 30K summary, a dropped max-attempt reason, false memory-flush rotation on incomplete compaction, unclassified auth guidance, and rejected automatic and manual cancellation being projected as failure.Live-proof gap: live-provider injection was not used because deterministically forcing provider 5xx, expired credentials, repeated hard overflow, rejected cancellation, and an oversized summary in one real account would require intentionally invalid credentials and costly context growth; owner-boundary regressions exercise those exact real AgentSession/subscriber/store paths.
AI-assisted: yes. The maintainer reviewed the complete diff and understands the ownership changes.