Skip to content

fix(auto-reply): preserve post-compaction failure context in user-facing recovery message (#67750) - #87691

Closed
sweetcornna wants to merge 1 commit into
openclaw:mainfrom
sweetcornna:fix/67750-compaction-embedded-timeout
Closed

sweetcornna wants to merge 1 commit into
openclaw:mainfrom
sweetcornna:fix/67750-compaction-embedded-timeout

Conversation

@sweetcornna

Copy link
Copy Markdown
Contributor

Summary

What problem does this PR solve?

When auto-compaction succeeds inside a turn and the retried run still fails (e.g. LLM idle timeout (120s), fallback exhausted with billing-skipped candidates), runAgentTurnWithFallback's catch path collapses the failure into either the generic ⚠️ Something went wrong while processing your request. Please try again, or use /new to start a fresh session. copy or a bare cause-specific message (e.g. BILLING_ERROR_USER_MESSAGE). Either way, the user loses the fact that compaction was attempted, that the timeout was on the retried turn, and which fallback candidates failed for which reason — exactly the chain in the bug report at src/auto-reply/reply/agent-runner-execution.ts.

Why does this matter now?

#67750 was filed against the user-facing chain in src/auto-reply/reply/agent-runner-execution.ts. The same catch block is on the hot path for every messaging surface (embedded harness runs and Codex / Pi-style CLI dispatch), so the same erasure happens across channels.

What is the intended outcome?

The user-facing message preserves the post-compaction signal already tracked in autoCompactionCount and the per-attempt reason chain already carried on FallbackSummaryError.attempts. Cause-specific copy (billing, rate-limit, timeout, oauth) is preserved verbatim so existing actionable hints still surface; the generic catch-all gains a structured Auto-compaction succeeded, but the retried turn still failed — ... prefix plus a concrete next step instead of bare /new.

What is intentionally out of scope?

  • No changes to the model-fallback engine (src/agents/model-fallback.ts) or to FallbackSummaryError's shape.
  • No changes to the embedded harness compaction lifecycle (src/agents/embedded-agent-subscribe.ts) — the attemptCompactionCount increment in the outer execution layer (src/auto-reply/reply/agent-runner-execution.ts:2535,2631) is already the source of truth.
  • Heartbeat (HEARTBEAT_EXTERNAL_RUN_FAILURE_TEXT) and control-UI surfaces keep their existing copy contracts.

What does success look like?

Three new vitest cases under runAgentTurnWithFallback cover: (1) post-compaction FallbackSummaryError with timeout + billing-skip attempts surfaces both compaction context and the per-attempt summary; (2) post-compaction plain failure surfaces the structured prefix plus the generic-mode guidance; (3) failure without a successful compaction still produces the plain GENERIC_EXTERNAL_RUN_FAILURE_TEXT.

What should reviewers focus on?

  • The wrap is gated on autoCompactionCount > 0 && !params.isHeartbeat && !shouldSurfaceToControlUi, so existing copy tests (rate-limit, billing-only, gateway-restart, Codex usage-limit, missing-API-key, CLI subprocess timeout) keep their exact strings.
  • The attempt summary cap (POST_COMPACTION_ATTEMPT_SUMMARY_MAX_CHARS = 240) is sized to keep the prefix concise on transports with text-length caps.

Linked context

Which issue does this close?

Closes #67750

Which issues, PRs, or discussions are related?

Related #67750

Was this requested by a maintainer or owner?

No — addressing the labelled P2 / clawsweeper:fix-shape-clear / clawsweeper:queueable-fix / clawsweeper:source-repro triage on #67750.

Real behavior proof (required for external PRs)

  • Behavior or issue addressed: Post-auto-compaction LLM idle timeout collapses the cause chain into the generic /new fallback (or a bare BILLING_ERROR_USER_MESSAGE) and erases the compaction-succeeded signal that is already tracked in autoCompactionCount and on FallbackSummaryError.attempts.
  • Real environment tested: Source-level repro via vitest mocks of the inner runEmbeddedAgent + runWithModelFallback seam that drive the exact failure shape from the bug report (embedded run emits compaction phase=end completed=true, then throws an LLM idle timeout; fallback layer rejects with a FallbackSummaryError containing reason: "timeout" plus reason: "billing" skip entries). The clawsweeper:source-repro label on the issue already covers the source-of-truth chain at src/auto-reply/reply/agent-runner-execution.ts:2660-2811.
  • Exact steps or command run after this patch: node scripts/run-vitest.mjs src/auto-reply/reply/agent-runner-execution.test.ts (149 tests, all passing). pnpm tsgo:core and pnpm tsgo:core:test (clean). pnpm format:check src/auto-reply/reply/agent-runner-execution.ts src/auto-reply/reply/agent-runner-execution.test.ts (clean). node scripts/run-oxlint.mjs src/auto-reply/reply/agent-runner-execution.ts src/auto-reply/reply/agent-runner-execution.test.ts (clean).
  • Evidence after fix: Test surfaces post-compaction context when the retried turn times out (#67750) asserts the rendered text contains Auto-compaction succeeded, retains the cause-specific billing copy, and includes the per-attempt summary openai-codex/gpt-5.4 timed out plus anthropic/claude-opus-4-7 skipped (billing). Test surfaces post-compaction context for plain failures without a fallback summary asserts the generic-mode guidance ("The context was compacted but no candidate could finish the turn ...") instead of the bare /new copy.
  • Observed result after fix: Vitest output: Test Files 1 passed (1) / Tests 149 passed (149).
  • What was not tested: No live LLM timeout repro against a real provider. The issue is labelled clawsweeper:source-repro precisely because the failure chain is observable in source plus emitted log lines (see the verbatim repro evidence in the issue body), and the diff exercises the exact autoCompactionCount > 0 && FallbackSummaryError seam from that chain.
  • Proof limitations or environment constraints: Triggering the live 120s LLM idle timeout would require either an actual provider hang or a configured billing-disabled fallback chain, neither of which is reliable to set up without disturbing other users. The source-level mocks reproduce the exact error shape from the repro log.
  • Before evidence (optional but encouraged): Before this patch, src/auto-reply/reply/agent-runner-execution.ts:2795-2805 would resolve fallbackText to either BILLING_ERROR_USER_MESSAGE (when hasBillingAttemptSummary is true) or GENERIC_EXTERNAL_RUN_FAILURE_TEXT (when no specific classifier matches) — both of which drop autoCompactionCount and the FallbackSummaryError.attempts cause chain on the floor.

Tests and validation

Which commands did you run?

  • node scripts/run-vitest.mjs src/auto-reply/reply/agent-runner-execution.test.ts (149 passed)
  • node scripts/run-vitest.mjs src/auto-reply/reply/agent-runner-execution.test.ts src/auto-reply/reply/agent-runner-helpers.test.ts src/auto-reply/reply/agent-runner.misc.runreplyagent.test.ts src/auto-reply/reply/agent-runner.runreplyagent.e2e.test.ts (194 passed)
  • node scripts/run-vitest.mjs src/auto-reply/reply/followup-runner.test.ts (55 passed — sibling-surface check; followup-runner shares autoCompactionCount but uses a different non-user-facing failure path)
  • pnpm tsgo:core and pnpm tsgo:core:test (clean)
  • pnpm format:check (clean)

What regression coverage was added or updated?

Three new cases in src/auto-reply/reply/agent-runner-execution.test.ts under describe("runAgentTurnWithFallback"):

  1. surfaces post-compaction context when the retried turn times out (#67750) — full repro of the bug-report failure chain (compaction succeeds; retried turn timeout; fallback exhausted with timeout + billing-skip attempts). Asserts the rendered text preserves compaction context, the resolved cause-specific copy, and the per-attempt summary.
  2. surfaces post-compaction context for plain failures without a fallback summary — covers the generic catch-all branch when the error is a plain Error (no FallbackSummaryError), confirming the structured prefix and the specific next-step guidance replace the bare /new fallback.
  3. does not add post-compaction context when no compaction succeeded — regression guard so the wrap stays scoped to autoCompactionCount > 0 and ordinary unknown errors still resolve to GENERIC_EXTERNAL_RUN_FAILURE_TEXT.

What failed before this fix, if known?

Test #1 above would have produced result.payload.text === "billing" (the mocked BILLING_ERROR_USER_MESSAGE), with no mention of compaction or the per-attempt timeout. Test #2 would have produced result.payload.text === GENERIC_RUN_FAILURE_TEXT, with no mention of compaction succeeding.

If no test was added, why not?

N/A — tests added.

Risk checklist

Did user-visible behavior change? (Yes/No)

Yes — only on the post-auto-compaction failure path. The pre-compaction failure path (autoCompactionCount === 0) returns the existing fallbackText unchanged, and existing tests for billing, rate-limit, gateway-restart, Codex usage-limit, missing-API-key, CLI subprocess timeout, and the generic copy all still assert their exact strings.

Did config, environment, or migration behavior change? (Yes/No)

No.

Did security, auth, secrets, network, or tool execution behavior change? (Yes/No)

No.

What is the highest-risk area?

User-facing copy on the post-compaction failure path. Wrong wording on a hot error path can confuse users about whether the message they sent was processed.

How is that risk mitigated?

  • The wrap is gated on three independent predicates (autoCompactionCount > 0, !params.isHeartbeat, !shouldSurfaceToControlUi), so heartbeat probes and the control-UI logs path keep their existing copy.
  • Cause-specific resolved text (BILLING_ERROR_USER_MESSAGE, rate-limit cooldown, Codex usage-limit, missing-API-key, OAuth re-auth, CLI timeout) is preserved verbatim — the wrap only prepends/appends, never replaces.
  • All 149 existing agent-runner-execution.test.ts cases still pass (including every surfaces X copy contract).

Current review state

What is the next action?

Maintainer review.

What is still waiting on author, maintainer, CI, or external proof?

CI run on the new commit.

Which bot or reviewer comments were addressed?

None yet — first revision.

@openclaw-barnacle openclaw-barnacle Bot added size: M triage: mock-only-proof Candidate: PR proof only shows tests, mocks, snapshots, lint, typecheck, or CI. labels May 28, 2026
@clawsweeper

clawsweeper Bot commented May 28, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: needs real behavior proof before merge. Reviewed June 25, 2026, 9:38 PM ET / 01:38 UTC.

Summary
The PR adds post-auto-compaction context and fallback-attempt summaries to runAgentTurnWithFallback user-facing failure copy, with regression tests for fallback-summary, plain-error, and no-compaction paths.

PR surface: Source +104, Tests +143. Total +247 across 2 files.

Reproducibility: yes. at source level: current main records successful compaction and structured fallback attempts, then resolves the terminal message through generic or cause-specific copy without post-compaction context. No live timeout was reproduced in this read-only review.

Review metrics: none identified.

Root-cause cluster
Relationship: fixed_by_candidate
Canonical: #67750
Summary: This PR is the focused candidate fix for the canonical post-successful-compaction failure-copy issue; the newer timeout-copy PR partially overlaps but does not cover mixed fallback attempt context.

Members:

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

Merge readiness
Overall: 🦪 silver shellfish
Proof: 🦪 silver shellfish
Patch quality: 🐚 platinum hermit
Result: blocked until real behavior proof from a real setup is added.

Overall follows the weaker of proof and patch quality, so missing proof can cap an otherwise strong patch.

Rank-up moves:

  • [P1] Add redacted real gateway/channel output, terminal output, logs, a recording, or a linked artifact showing the post-compaction recovery message after this patch.
  • Refresh or rebuild the branch against current main and reconcile the overlap with fix(auto-reply): surface model timeout failures once #95742.

Proof guidance:

  • [P1] Needs real behavior proof before merge: The PR body provides source-level Vitest mocks and command output only; it still needs redacted real gateway/channel output, terminal output, logs, a recording, or a linked artifact before merge unless maintainers override proof. After adding proof, update the PR body; ClawSweeper should re-review automatically. If it does not, the PR author or someone with repository write access can comment @clawsweeper re-review.

Mantis proof suggestion
A short real gateway/channel or terminal proof would materially help because the remaining blocker is after-fix real behavior proof of the rendered recovery message. A maintainer can ask Mantis to capture proof by posting this exact PR comment:

@openclaw-mantis visual task: prove the post-auto-compaction failure recovery message includes compaction context and fallback-attempt details after the retried turn fails.

Risk before merge

  • [P1] The PR body provides source-level mocks and command output only; external PR policy still needs redacted real gateway/channel output, terminal output, logs, a recording, a linked artifact, or a maintainer proof override before merge.
  • [P1] The live PR is dirty against current main, so the exact merged auto-reply failure path cannot be judged until the branch is refreshed or rebuilt.
  • [P2] fix(auto-reply): surface model timeout failures once #95742 overlaps the same timeout-copy seam and should be reconciled with this PR's unique post-compaction and fallback-attempt context before merge.

Maintainer options:

  1. Refresh And Prove The Merged Recovery Copy (recommended)
    Rebase or rebuild on current main, reconcile the timeout-copy overlap, and add redacted real gateway/channel output, terminal output, logs, a recording, or a linked artifact showing the post-compaction recovery message.
  2. Accept Maintainer Proof Override
    Maintainers can explicitly accept source-level proof for this hard-to-trigger timeout chain, but should still require a clean merge result against current main.
  3. Pause Behind The Timeout-Copy PR
    Maintainers can wait for fix(auto-reply): surface model timeout failures once #95742 to land first, then decide whether this PR should be rebuilt as the narrower post-compaction follow-up.

Next step before merge

  • [P1] The remaining action is contributor proof or maintainer proof override plus conflict/reconciliation against current main, not a narrow automated repair.

Security
Cleared: The diff changes TypeScript failure-message formatting and tests only, with no dependency, workflow, secret, package, install, or code-execution surface changes.

Review details

Best possible solution:

Refresh this branch or make a narrow replacement on current main, preserve the unique post-compaction attempt summary alongside #95742 timeout copy, and add real behavior proof or a maintainer proof override before merge.

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

Yes at source level: current main records successful compaction and structured fallback attempts, then resolves the terminal message through generic or cause-specific copy without post-compaction context. No live timeout was reproduced in this read-only review.

Is this the best way to solve the issue?

Yes as a fix shape: the existing terminal failure-copy seam already has autoCompactionCount and FallbackSummaryError attempts, so preserving that context there is narrow and maintainable. The branch still needs refresh/proof before the final merged patch can be accepted.

AGENTS.md: found and applied where relevant.

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

Label changes

Label justifications:

  • P2: This is a normal-priority user-facing auto-reply recovery-message bug with bounded runtime scope.
  • merge-risk: 🚨 other: The PR changes hot-path recovery copy across messaging surfaces and overlaps an unmerged timeout-copy PR, so green tests alone do not settle the final user-facing wording.
  • rating: 🦪 silver shellfish: Overall readiness is 🦪 silver shellfish; proof is 🦪 silver shellfish and patch quality is 🐚 platinum hermit.
  • status: 📣 needs proof: The PR needs real behavior proof before ClawSweeper can clear the contributor ask. Needs real behavior proof before merge: The PR body provides source-level Vitest mocks and command output only; it still needs redacted real gateway/channel output, terminal output, logs, a recording, or a linked artifact before merge unless maintainers override proof. After adding proof, update the PR body; ClawSweeper should re-review automatically. If it does not, the PR author or someone with repository write access can comment @clawsweeper re-review.
Evidence reviewed

PR surface:

Source +104, Tests +143. Total +247 across 2 files.

View PR surface stats
Area Files Added Removed Net
Source 1 105 1 +104
Tests 1 143 0 +143
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 2 248 1 +247

What I checked:

  • Repository policy read: Root repository policy was read fully and applied to require current-main source checks, related item checks, and proof/merge-risk review for fallback behavior. (AGENTS.md:1, 6830aa39eaa1)
  • Current main records successful compaction: Current main increments attemptCompactionCount on completed compaction events and accumulates it into autoCompactionCount, so the signal this PR uses already exists before the terminal failure path. (src/auto-reply/reply/agent-runner-execution.ts:2807, 6830aa39eaa1)
  • Current main still drops post-compaction context: The terminal catch path resolves billing/rate-limit/context/control-UI/generic text and passes only that text into conversation filtering; autoCompactionCount is not included in the user-visible fallback message. (src/auto-reply/reply/agent-runner-execution.ts:3263, 6830aa39eaa1)
  • Generic failure copy remains in main: The generic external-run failure text still matches the reported /new fallback copy when no more specific classifier wins. (src/auto-reply/reply/agent-runner-failure-copy.ts:2, 6830aa39eaa1)
  • Current tests preserve the old erasure behavior: The existing mixed-cause fallback exhaustion test expects only billing guidance and asserts away the all-model details, showing current coverage does not preserve post-compaction attempt context. (src/auto-reply/reply/agent-runner-execution.test.ts:5791, 6830aa39eaa1)
  • Fallback summary contract carries the needed attempts: FallbackSummaryError carries structured attempts, and model fallback records provider/model/reason/error entries before throwing the summary, matching the PR's proposed source of per-attempt user context. (src/agents/model-fallback.ts:599, 6830aa39eaa1)

Likely related people:

  • vincentkoc: Recent GitHub history shows repeated changes in agent-runner-execution.ts and model-fallback.ts, including fallback state and error-normalization work adjacent to this PR. (role: recent area contributor; confidence: high; commits: 14e448e0e13d, 2b75806197ab, 80805ad7a583; files: src/auto-reply/reply/agent-runner-execution.ts, src/agents/model-fallback.ts)
  • steipete: Recent history includes terminal failure classifier work and model-fallback changes in the same failure-reporting area. (role: adjacent terminal-failure contributor; confidence: medium; commits: 0314819f918a, b7d363cadff4; files: src/auto-reply/reply/agent-runner-execution.ts, src/agents/model-fallback.ts)
  • jalehman: Recent history shows auto-reply session seam and Codex typing/agent-runner work touching the same runner module. (role: recent session/refactor contributor; confidence: medium; commits: b6bc3ed0dbd8, 127e174c9e4d; files: src/auto-reply/reply/agent-runner-execution.ts)
  • Ayaan Zaidi: Local blame for the current terminal fallback and compaction-count lines maps to an aggregate repair commit committed by Ayaan Zaidi; the bot-authored aggregate makes this weaker routing evidence. (role: recent aggregate committer; confidence: low; commits: ace22feb3fe2; files: src/auto-reply/reply/agent-runner-execution.ts)
What the crustacean ranks mean
  • 🦀 challenger crab: rare, exceptional readiness with strong proof, clean implementation, and convincing validation.
  • 🦞 diamond lobster: very strong readiness with only minor maintainer review expected.
  • 🐚 platinum hermit: good normal PR, likely mergeable with ordinary maintainer review.
  • 🦐 gold shrimp: useful signal, but proof or patch confidence is still limited.
  • 🦪 silver shellfish: thin signal; proof, validation, or implementation needs work.
  • 🧂 unranked krab: not merge-ready because proof is missing/unusable or there are serious correctness or safety concerns.
  • 🌊 off-meta tidepool: rating does not apply to this item.

Shiny media proof means a screenshot, video, or linked artifact directly shows the changed behavior. Runtime, network, CSP, and security claims still need visible diagnostics.

How this review workflow works
  • ClawSweeper keeps one durable marker-backed review comment per issue or PR.
  • Re-runs edit this comment so the latest verdict, findings, and automation markers stay together instead of adding duplicate bot comments.
  • A fresh review can be triggered by eligible @clawsweeper re-review comments, exact-item GitHub events, scheduled/background review runs, or manual workflow dispatch.
  • PR/issue authors and users with repository write access can comment @clawsweeper re-review or @clawsweeper re-run on an open PR or issue to request a fresh review only.
  • Maintainers can also comment @clawsweeper review to request a fresh review only.
  • Fresh-review commands do not start repair, autofix, rebase, CI repair, or automerge.
  • Maintainer-only repair and merge flows require explicit commands such as @clawsweeper autofix, @clawsweeper automerge, @clawsweeper fix ci, or @clawsweeper address review.
  • Maintainers can comment @clawsweeper explain to ask for more context, or @clawsweeper stop to stop active automation.

@clawsweeper clawsweeper Bot added rating: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask. P2 Normal backlog priority with limited blast radius. labels May 28, 2026
@clawsweeper clawsweeper Bot added rating: 🌊 off-meta tidepool PR readiness rating does not apply to this item. and removed rating: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask. labels May 29, 2026
@sweetcornna
sweetcornna force-pushed the fix/67750-compaction-embedded-timeout branch from d2813b8 to 5b8a9e2 Compare June 3, 2026 08:19
@clawsweeper clawsweeper Bot added rating: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask. and removed rating: 🌊 off-meta tidepool PR readiness rating does not apply to this item. labels Jun 3, 2026
@clawsweeper clawsweeper Bot added merge-risk: 🚨 other 🚨 Merging this PR has meaningful risk outside the owned taxonomy. rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. rating: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. and removed rating: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. labels Jun 19, 2026
@clawsweeper

clawsweeper Bot commented Jul 9, 2026

Copy link
Copy Markdown
Contributor

@sweetcornna thanks for the PR. ClawSweeper is still waiting on real behavior proof before this can move forward.

Useful proof can be a screenshot, short video, terminal output, copied live output, linked artifact, or redacted logs that show the changed behavior after the fix. Please redact private tokens, phone numbers, private endpoints, customer data, and anything else sensitive.

Once proof is added to the PR body or a comment, ClawSweeper or a maintainer can re-check it.

@steipete

steipete commented Jul 9, 2026

Copy link
Copy Markdown
Contributor

Thanks for the work here. I’m closing this stalled branch to keep the PR queue actionable: the head has not changed since June 3, it is conflicted with current main, and the requested real behavior proof is still missing.

#67750 remains open because current main still drops the post-compaction context; #95742 is only a partial overlap, not a complete replacement. If you want to resume this, please open or refresh a current-main version with redacted live output (or an explicit maintainer proof override) and reconcile the timeout-copy overlap. Thank you.

@steipete steipete closed this Jul 9, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

merge-risk: 🚨 other 🚨 Merging this PR has meaningful risk outside the owned taxonomy. P2 Normal backlog priority with limited blast radius. rating: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. size: M status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask. triage: mock-only-proof Candidate: PR proof only shows tests, mocks, snapshots, lint, typecheck, or CI.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: Successful auto-compaction can still end in a 120s embedded timeout and generic /new fallback

3 participants