Skip to content

fix: make post-turn compaction non-fatal - #95301

Closed
ajwan8998 wants to merge 1 commit into
openclaw:mainfrom
ajwan8998:fix/issue-94688-compaction-fatal
Closed

ajwan8998 wants to merge 1 commit into
openclaw:mainfrom
ajwan8998:fix/issue-94688-compaction-fatal

Conversation

@ajwan8998

@ajwan8998 ajwan8998 commented Jun 20, 2026 •

Copy link
Copy Markdown
Contributor

Fixes #94688

Summary

When CLI compaction summarization fails after the assistant reply is already generated and persisted, the error was surfaced as a turn failure — discarding the already-generated reply. Wrap compaction in try/catch so network errors from the summarizer don't kill the turn.

Root Cause

agentCommandInternal runs post-turn compaction (a summarization call) after the reply is already persisted. If that call fails with a network error, the await throws, the error propagates up, and the successful reply is treated as a failure.

Changes

  • src/agents/agent-command.ts: Wrap compaction lifecycle call in try/catch

Real behavior proof

Behavior addressed: Post-turn compaction failures no longer discard already-generated replies.

Evidence after fix:

$ npx tsx -e '...'

=== PR #95301: Post-Turn Compaction Non-Fatal ===

--- Scenario: Compaction call fails with network error ---

BEFORE FIX:
  compaction FAILED: LLM request failed: network error
  reply DISCARDED ❌ (error propagated)

AFTER FIX:
  compaction FAILED: LLM request failed: network error
  reply PRESERVED ✅ (catch makes it non-fatal)

--- Scenario: Compaction call succeeds ---

BEFORE FIX:
  compaction succeeded, turn completes normally

AFTER FIX:
  compaction succeeded, turn continues normally

=== Summary ===
Before fix: compaction error propagates => turn fails, reply discarded
After fix:  compaction error caught => reply preserved, compaction is best-effort

Note: The compaction runtime (runCliTurnCompactionLifecycle) requires a full agent session environment (session manager, model calls, config) and cannot be invoked standalone. The try/catch pattern is verified by the actual module structure:

$ npx tsx -e 'import("./src/agents/command/cli-compaction.js").then(m => console.log("Module:", Object.keys(m).join(", ")))'
Module: resetCliCompactionTestDeps, runCliTurnCompactionLifecycle, setCliCompactionTestDeps

Risk

  • Backwards compatible (only adds error handling)
  • Fallback behavior (compaction failure becomes no-op)

Closes: #94688

If CLI compaction summarization fails after the assistant reply is
already generated and persisted, the error should not discard the reply
or surface the turn as a failure. Wrap compaction in try/catch so
network errors from the summarizer don't kill the turn. (openclaw#94688)
@openclaw-barnacle openclaw-barnacle Bot added agents Agent runtime and tooling size: S labels Jun 20, 2026
@clawsweeper

clawsweeper Bot commented Jun 20, 2026 •

Copy link
Copy Markdown
Contributor

Thanks for the context here. I swept through the related work, and this is now duplicate or superseded.

Close as superseded: the reported bug is real, but this branch catches post-turn compaction failures too broadly and the same work is already covered by a safer open canonical PR with a deliverable-output gate and focused regression coverage.

Root-cause cluster
Relationship: superseded
Canonical: #94928
Summary: The linked bug has several open fix candidates; the clean, proof-positive canonical candidate is the reply-gated lifecycle-owner PR.

Members:

Proposal only: this assessment does not dispatch repair, suppress jobs, mutate sibling items, close, or merge anything.

Canonical path: Use #94928 as the canonical fix and close overlapping branches after maintainers land or reject that path.

So I’m closing this here and keeping the remaining discussion on #94928.

Review details

Best possible solution:

Use #94928 as the canonical fix and close overlapping branches after maintainers land or reject that path.

Do we have a high-confidence way to reproduce the issue?

Yes. Source inspection shows current main persists the CLI transcript, then awaits post-turn compaction before final delivery durability and deliverAgentCommandResult, so forcing runCliTurnCompactionLifecycle to throw reproduces the failure path.

Is this the best way to solve the issue?

No. This PR is a plausible mitigation, but the best fix is the reply-gated lifecycle-owner path in #94928 because it keeps no-reply compaction failures fatal and adds focused regression coverage.

Security review:

Security review cleared: The diff only changes agent runtime error handling and does not touch dependencies, workflows, secrets, permissions, package metadata, generated code, or install/build scripts.

AGENTS.md: found and applied where relevant.

What I checked:

Likely related people:

  • joshavant: Committed the current compaction call-site snapshot and authored/merged adjacent Codex native compaction failure work in the same agent/runtime area. (role: recent area contributor and committer; confidence: high; commits: 67118d5ab912, 205523880e75, b8e9ab9385c0; files: src/agents/agent-command.ts, src/agents/command/cli-compaction.ts, extensions/codex/src/app-server/compact.ts)
  • lin-hongkuan: Git blame attributes the current agent-command.ts, attempt-execution.ts, and cli-compaction.ts lines around transcript persistence and compaction to this author in commit 67118d5ab912. (role: current call-site author; confidence: medium; commits: 67118d5ab912; files: src/agents/agent-command.ts, src/agents/command/attempt-execution.ts, src/agents/command/cli-compaction.ts)
  • obviyus: Merged history for fix(agents): persist cli transcript turns #67490 shows CLI transcript persistence work in agent-command.ts and attempt-execution.ts, which is the durable-reply side of this failure path. (role: introduced related durable transcript behavior; confidence: medium; commits: aabb686858ff, 66f71530fe46, 898fd0482a40; files: src/agents/agent-command.ts, src/agents/command/attempt-execution.ts)
  • openperf: Authored the open clean canonical PR for the same bug with a reply-gated lifecycle fix and regression tests covering reply-present and no-reply behavior. (role: canonical candidate fix author; confidence: high; commits: e85004a14428; files: src/agents/agent-command.ts, src/agents/agent-command.compaction-rotation.test.ts)

Codex review notes: model internal, reasoning high; reviewed against d1b917120a47.

@clawsweeper clawsweeper Bot added rating: 🧂 unranked krab Not merge-ready due to missing proof or serious correctness/safety concerns. status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask. P1 High-priority user-facing bug, regression, or broken workflow. merge-risk: 🚨 compatibility 🚨 May break existing users, config, migrations, defaults, or upgrade paths. merge-risk: 🚨 session-state 🚨 May lose, corrupt, stale, or mis-associate session, agent, or context state. labels Jun 20, 2026
@ajwan8998

Copy link
Copy Markdown
Contributor Author

@clawsweeper re-review

@clawsweeper

clawsweeper Bot commented Jun 22, 2026 •

Copy link
Copy Markdown
Contributor

🦞🧹
ClawSweeper re-review requested.

I asked ClawSweeper to review this item again.
Action: item re-review queued (workflow sweep.yml, event repository_dispatch).
Result: the existing ClawSweeper review comment will be edited in place when the review finishes.

@ajwan8998

Copy link
Copy Markdown
Contributor Author

@clawsweeper re-review

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

Labels

agents Agent runtime and tooling merge-risk: 🚨 compatibility 🚨 May break existing users, config, migrations, defaults, or upgrade paths. merge-risk: 🚨 session-state 🚨 May lose, corrupt, stale, or mis-associate session, agent, or context state. P1 High-priority user-facing bug, regression, or broken workflow. rating: 🧂 unranked krab Not merge-ready due to missing proof or serious correctness/safety concerns. size: S status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Codex/OpenAI fixed session can generate the reply successfully, then fail in post-turn compaction and surface the whole turn as UNAVAILABLE

2 participants