Repository navigation
fix(cli): treat post-turn compaction failures as non-fatal (fixes #94688) - #94698
zenglingbiao wants to merge 3 commits into
Conversation
…nclaw#94688) The assistant reply is already generated and written to the session transcript before post-turn CLI compaction runs. Treating compaction failures as fatal would discard the already-generated reply. Instead, log a warning and continue so the reply is delivered.
|
Thanks for the context here. I swept through the related work, and this is now duplicate or superseded. Close as superseded: this PR addresses the right P1 bug, but it changes the generic compaction helper without knowing whether the completed turn has deliverable content, while the open member-authored lifecycle fix in #94928 is a cleaner canonical landing path. Root-cause cluster Members:
Proposal only: this assessment does not dispatch repair, suppress jobs, mutate sibling items, close, or merge anything. Canonical path: Close this source PR and review #94928 as the canonical lifecycle-owner fix, then close sibling candidates after one fix lands. So I’m closing this here and keeping the remaining discussion on #94928. Review detailsBest possible solution: Close this source PR and review #94928 as the canonical lifecycle-owner fix, then close sibling candidates after one fix lands. Do we have a high-confidence way to reproduce the issue? Yes. Source inspection shows current main persists the CLI transcript, awaits post-turn compaction, and reaches final delivery only afterward; forcing Is this the best way to solve the issue? No. This PR is a plausible symptom fix, but the best fix is the caller-level lifecycle guard in #94928 because it can check deliverable outbound content and keep no-reply failures fatal. Security review: Security review cleared: Security review cleared: the diff changes TypeScript compaction control flow and tests only, with no dependency, workflow, secret, permission, package, or supply-chain surface changed. AGENTS.md: found and applied where relevant. What I checked:
Likely related people:
Codex review notes: model internal, reasoning high; reviewed against d1b917120a47. |
…-compaction-nonfatal
|
@clawsweeper re-review |
|
🦞🧹 I asked ClawSweeper to review this item again. |
|
🦞✅ Reason: structured ClawSweeper close marker: close-required (sha=52b9bcde66f060dd948431c3215ad2f83ded07f3) Closed:
|
Summary
Connection errorafter the assistant reply has already been generated and written to the session transcript. TherunCliTurnCompactionLifecyclefunction throws on compaction failure, which causes the entire turn to be treated as a failure — discarding the already-generated reply.runCliTurnCompactionLifecycleinsrc/agents/command/cli-compaction.tsthrows on both native harness compaction failure (line 623) and context engine compaction failure (line 666). Compaction runs AFTER model generation, so the assistant reply already exists when the throw occurs.throw new Error(...)calls withlog.warn(...)+return params.sessionEntry. The warning is logged for operators, but the turn proceeds and delivers the already-generated reply.src/agents/command/cli-compaction.ts— two throw sites converted to warn+returnpromptErrorSource = "compaction"Reproduction
openai/gpt-5.4)CLI transcript compaction failederror is thrown → turn fails, reply discardedReal behavior proof
Behavior or issue addressed (94688): Post-turn CLI compaction failures no longer abort the turn after the assistant reply was generated. The two throw sites (native harness line 623, context engine line 666) now return the session entry with a warning log instead of throwing.
Real environment tested: Linux, Node v22.22.0, OpenClaw 2026.6.8 built from source at upstream/main commit 7207072. A standalone
node --import tsxscript drives the realrunCliTurnCompactionLifecyclefunction against a real SessionManager, real JSONL session file, and real JSON store — the same dependencies used in production. The script injects a hung context-engine compaction to trigger the exact failure path described in the issue.Exact steps or command run after this patch: ran the proof script twice — once on upstream/main (before fix) and once on the PR branch (after fix) — each creating a real temporary session file and store, then calling
runCliTurnCompactionLifecyclewithtimeoutSeconds=1to force a compaction timeout.Evidence before fix:
Evidence after fix:
Observed result after fix: Before the fix,
runCliTurnCompactionLifecyclethrowsCLI transcript compaction failed— the turn fails and the already-generated reply is discarded. After the fix, the same compaction timeout returns the session entry with a warning log — the turn succeeds and the reply is preserved. The proof script exercises the real production function against real file-based dependencies (SessionManager, JSONL transcript, JSON store), not mocked tests.What was not tested: Live Codex app-server connection failure was not driven — this requires a running Codex instance with model credentials. The proof script exercises the exact same code path (context-engine compaction timeout) against real file dependencies.
Repro confirmation: The proof script at
openclaw-issue-94688-evidence/proof.mjsis checked into the evidence directory. Rungit checkout upstream/main && node --import tsx proof.mjsto see FAIL (throws, exit 1). Rungit checkout <PR-branch> && node --import tsx proof.mjsto see PASS (returns session entry, exit 0). The colocated regression tests insrc/agents/command/cli-compaction.test.tsadditionally cover the same paths.Risk / Mitigation
Mitigation: The next turn will attempt compaction again. The embedded agent runner independently handles overflow-triggered compaction. The warning log preserves visibility for operators.
Change Type (select all)
Scope (select all touched areas)
Regression Test Plan
node --import tsx proof.mjs(standalone behavioral proof — exercises real function against real files)node scripts/run-vitest.mjs src/agents/command/cli-compaction.test.ts(38 tests including updated throw→return assertions)pnpm build && node openclaw.mjs --version(build verification)Review Findings Addressed
N/A (initial submission with updated standalone-script proof)
Linked Issue/PR
Fixes #94688