Skip to content

fix: preserve tool errors when summary recovery fails - #139309

Merged
altaywtf merged 1 commit into
mainfrom
t3code/investigate-glitch-setup-issue
Sep 6, 2026
Merged

altaywtf merged 1 commit into
mainfrom
t3code/investigate-glitch-setup-issue

Conversation

@altaywtf

@altaywtf altaywtf commented Sep 5, 2026 •

Copy link
Copy Markdown
Member

Related: #139253 — failed cron command followed by NO_REPLY reports a fallback as success.

Additional instructions

This PR uses an upstream branch that maintainers can push to.

What Problem This Solves

Fixes an issue where users running a tool that fails would receive a generic non-error reply when the assistant produced no final answer and summary recovery also returned empty or threw.

The exact NO_REPLY case reported in #139253 is already addressed on main by #137775, which removed tool-error suppression. This PR covers the remaining case where no final answer was authored and unsuccessful recovery overwrites the original tool failure.

Why This Change Was Made

The settled-turn finalization owner now retains the original failed completion and passes it through normal terminal preparation when recovery produces no answer. This preserves error delivery, terminal and replay state, accumulated usage, and provider-failure bookkeeping without appending a misleading fallback to the transcript.

Actual recovered answers and the existing fallback for successful tool runs retain their behavior. Production changes are +44/-38 lines (net +6); the growth preserves original completion ownership through the shared preparation path. Tests are +95/-19 lines (net +76). No configuration, schema, dependency, or public protocol changes.

User Impact

Unsuccessful summary recovery preserves the failed completion and its error state. The existing delivery layer decides whether to present a tool warning or a provider error. Completed actions are not replayed and no generic fallback is appended for the failed tool.

Evidence

I ran the same isolated Gateway/native Codex scenario on the exact parent 3e4becea5e2ce38ede69e8ecf5302805ecbfc09c and head d335dfd8d1e8771215494c4e506aa7230457d1a3 on personal Cloudflare Crabbox, with Node 24.15.0, pnpm 12.3.4, the pinned Codex 0.153.4 binary, and live openai/gpt-5.6-luna responses.

The live model executed a real command that recorded one execution, printed a diagnostic, and exited 127. After the execution marker existed, an HTTP/SSE proxy deliberately returned 503 server_is_overloaded for continuation and summary requests. The channel was the synthetic qa-channel plugin and HTTP bus; the Gateway and native Codex processes were real. No model completion or tool result was fabricated. The proxy explicitly rejected WebSocket probes with 426 to select HTTP/SSE.

Observed result Parent PR head
Real command executions / exit 1 / 127 1 / 127
Native authored final answer None None
Recovery Attempted, failed on injected overload Attempted, failed on injected overload
Channel reply Generic “The tool run finished, but no final summary was produced…” “⚠️ Selected model is at capacity. Try a different model, or wait and retry.”
Channel error flag Absent isError: true
Generic fallback in canonical SQLite transcript 1 0
Original failed tool result persisted Yes Yes

Each failed-chat run recorded one successful live provider POST, five injected continuation failures, and five injected summary failures. Gateway finalization timestamps bracket the summary requests. Native command-completion records, the execution marker, and the canonical transcript agree on one failed execution. Channel reply IDs match the observed Gateway run IDs. The same no-fallback assertion failed on the parent and passed on the head.

Both revisions passed a live successful-command control: one execution with exit 0, two successful provider POSTs, and a success reply without injected failures.

The head's isolated cron check recorded status: error, error/summary: ⚠️ Bash failed, one failed execution, and no fallback transcript entry. It did not announce a normal completion, matching the existing fatal structured-error policy. Its summary context was unavailable; the direct-chat comparison above separately proves a real summary transport failure.

Supporting checks: the independent baseline/head contract and focused finalization, recovery, transport and cron suites produced 87 passing head tests. Exact-head CI also passed: https://github.com/openclaw/openclaw/actions/runs/33986584643. A fresh full QA-enabled head build passed; the baseline used the source-owned runtime-only build and did not generate declarations. All final Gateway process trees were confirmed stopped without cleanup errors, and the Cloudflare lease was stopped.

Earlier unsuccessful proof-driver attempts are retained in the evidence package: one incorrectly expected a cron announce despite existing suppression, and another expected the literal tool-warning wording instead of the capacity-error presentation. Neither is counted as a passing delivery proof.

Remaining scope: this is not Telegram Test Server evidence, and it does not establish full resolution of the original cron/NO_REPLY incident. The exact NO_REPLY case is separately handled by #137775. No Telegram screenshot or video was captured, and no production runtime was changed.

@clawsweeper

clawsweeper Bot commented Sep 5, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
ClawSweeper picked this up.

Pull request received. I will update this pull request when review starts.

ClawSweeper review complete

ClawSweeper finished reviewing this revision. The review result is being finalized.

View the workflow run.

@openclaw-barnacle openclaw-barnacle Bot added the agents Agent runtime and tooling label Sep 5, 2026
@altaywtf
altaywtf marked this pull request as ready for review September 5, 2026 19:15
Copilot AI lite review requested due to automatic review settings September 5, 2026 19:15
@openclaw-barnacle openclaw-barnacle Bot added the maintainer Maintainer-authored PR label Sep 5, 2026
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Sep 5, 2026 •

Copy link
Copy Markdown
Contributor

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-09-05T19:20:42.069005Z d335dfd Draft marked ready
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟢 Approval recommended

The behavioral change is well-scoped to settled-turn finalization and is supported by targeted regression tests; only a small maintainability nit remains.

Pull request overview

This PR adjusts embedded-run “settled turn” finalization so that when a tool run failed and no final assistant answer exists, an empty/throwing summary-recovery attempt no longer overwrites the original tool failure with the host fallback “no final summary was produced” message.

Changes:

  • Disallow terminal fallback transcript/appended summary when the settled attempt already contains a lastToolError, preserving the original tool-failure warning and terminal ownership if recovery fails or is empty.
  • Tighten cancellation handling so aborted finalization preserves cancellation before any terminal delivery or fallback persistence.
  • Add/extend tests covering unavailable/empty recovery with and without tool failures, including the failed-command + NO_REPLY scenario.
File summaries
File Description
src/agents/embedded-agent-runner/run/settled-turn-finalization.ts Ensures tool-failure outcomes are preserved when summary recovery is empty/unavailable; refines cancellation/fallback flow.
src/agents/embedded-agent-runner/run/settled-turn-finalization.test.ts Adds regression coverage for “failed command + NO_REPLY” and for empty/throwing recovery preserving tool failure; updates fallback/cancellation expectations.
src/agents/embedded-agent-runner/run/settled-turn-finalization.unavailable.test.ts Extends backend/transcript unavailability tests to include the “tool failed” variant and asserts no misleading fallback persistence.
Review details
  • Files reviewed: 3/3 changed files
  • Comments generated: 1
  • Review effort level: Lite

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment on lines +278 to +282
completion === initial
? ("failed" as const)
: finalizationOutcome === "empty"
? ("completed-empty" as const)
: finalizationOutcome,
@clawsweeper clawsweeper Bot added P2 Normal backlog priority with limited blast radius. proof: telegram-e2e This PR needs Telegram Test Server proof with the repository E2E skill. rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR. labels Sep 5, 2026
@clawsweeper

clawsweeper Bot commented Sep 5, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge. Reviewed September 6, 2026, 2:05 AM ET / 06:05 UTC.

ClawSweeper review

What this changes

Preserves the original tool failure and completion state when summary recovery returns no answer, instead of replacing them with a generic successful-looking fallback.

Merge readiness

✅ Ready for maintainer review

This remains a useful, focused repair absent from current main. No blocking findings; the new parent-versus-head runtime evidence addresses the previous review’s delivery-proof request without claiming full resolution of the related cron incident.

Priority: P2
Reviewed head: d335dfd8d1e8771215494c4e506aa7230457d1a3

Review scores

Measure Result What it means
Overall readiness 🐚 platinum hermit (4/6) A focused owner-boundary repair with relevant comparative runtime evidence and regression coverage; no blocking defect found.
Proof confidence 🦞 diamond lobster (5/6) Sufficient (live_output): The captured parent/head Gateway and native Codex run exercises the changed finalization owner through a real failed command and injected HTTP overloads: the head delivers an error, preserves one execution, and omits the fallback transcript entry. This satisfies the previous delivery-proof request; successful-command controls supplement it, while Telegram and full cron-incident resolution remain outside the demonstrated scope.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Verification

Check Result Evidence
Real behavior Verified Sufficient (live_output): The captured parent/head Gateway and native Codex run exercises the changed finalization owner through a real failed command and injected HTTP overloads: the head delivers an error, preserves one execution, and omits the fallback transcript entry. This satisfies the previous delivery-proof request; successful-command controls supplement it, while Telegram and full cron-incident resolution remain outside the demonstrated scope.
Evidence reviewed 11 items Introduced change and ownership boundary: The pinned merge-base-to-head diff changes recovery selection and completion preservation in the existing owner. Production is +44/-38; tests are +95/-19. The supplied verified test merge contains the same three-file change, without the unrelated base-branch drift.
Still necessary on current main: Current main permits the host fallback based only on silentExpected and reconstructs a fresh completion after unsuccessful recovery; it lacks the branch’s lastToolError preservation.
Latest release comparison: The inspected v2026.9.2 implementation also allows fallback without checking lastToolError and replaces terminal ownership; this requested repair is not present in that release.
Findings None None.
Security None None.

How this fits together

After an agent finishes its tools without answering, the shared agent runner asks its selected runtime for a tool-free summary. Terminal preparation then turns the resulting completion into channel replies, transcript entries, and run-status metadata.

flowchart TD
  A[Completed tool work] --> B[Shared agent runner]
  B --> C[Tool-free summary recovery]
  C --> D{Answer recovered?}
  D -->|Yes| E[Prepare recovered answer]
  D -->|No| F[Preserve original tool failure]
  E --> G[Channel reply and run status]
  F --> G
Loading

Before merge

None.

Agent review details

Security

None.

PR surface

Source +6, Tests +76. Total +82 across 3 files.

View PR surface stats
Area Files Added Removed Net
Source 1 44 38 +6
Tests 2 95 19 +76
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 3 139 57 +82

Review metrics

Metric Value Why it matters
Production versus regression coverage Production net +6; tests net +76 Production growth preserves original completion ownership through shared preparation; test growth covers unsuccessful recovery and retains successful fallback and cancellation coverage.

Technical review

Best possible solution:

Keep failed completion ownership in the shared finalization owner and reuse normal error preparation; the six net production lines preserve that boundary without adding a parallel delivery path.

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

Yes: current main still replaces a failed tool completion after unsuccessful summary recovery, and the supplied exact-parent/head run demonstrates the resulting fallback discrepancy. This reviewer did not execute a current-main reproduction.

Is this the best way to solve the issue?

Yes: preserving the original completion at its recovery owner retains error, replay, and bookkeeping semantics together; changing channel formatting or disabling recovery would leave the underlying ownership problem unresolved.

AGENTS.md: found and applied where relevant.

Codex review notes: model internal, reasoning medium; reviewed against 1ad2e83fd7d5.

Labels

Label changes:

  • add proof: sufficient: Contributor real behavior proof is sufficient. The captured parent/head Gateway and native Codex run exercises the changed finalization owner through a real failed command and injected HTTP overloads: the head delivers an error, preserves one execution, and omits the fallback transcript entry. This satisfies the previous delivery-proof request; successful-command controls supplement it, while Telegram and full cron-incident resolution remain outside the demonstrated scope.
  • add rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🦞 diamond lobster and patch quality is 🐚 platinum hermit.
  • remove rating: 🦐 gold shrimp: Current PR rating is rating: 🐚 platinum hermit, so this older rating label is no longer current.

Label justifications:

  • P2: Repairs misleading error presentation in the bounded case where a tool fails and summary recovery also produces no answer.
  • rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🦞 diamond lobster and patch quality is 🐚 platinum hermit.
  • status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR. Sufficient (live_output): The captured parent/head Gateway and native Codex run exercises the changed finalization owner through a real failed command and injected HTTP overloads: the head delivers an error, preserves one execution, and omits the fallback transcript entry. This satisfies the previous delivery-proof request; successful-command controls supplement it, while Telegram and full cron-incident resolution remain outside the demonstrated scope.
  • proof: sufficient: Contributor real behavior proof is sufficient. The captured parent/head Gateway and native Codex run exercises the changed finalization owner through a real failed command and injected HTTP overloads: the head delivers an error, preserves one execution, and omits the fallback transcript entry. This satisfies the previous delivery-proof request; successful-command controls supplement it, while Telegram and full cron-incident resolution remain outside the demonstrated scope.
  • proof: telegram-e2e: This PR needs Telegram Test Server proof with the repository E2E skill. The shared terminal reply changes from a generic fallback to an error and is observable in Telegram; the supplied QA-channel proof is not Telegram Test Server evidence.

Evidence

What I checked:

  • Introduced change and ownership boundary: The pinned merge-base-to-head diff changes recovery selection and completion preservation in the existing owner. Production is +44/-38; tests are +95/-19. The supplied verified test merge contains the same three-file change, without the unrelated base-branch drift. (src/agents/embedded-agent-runner/run/settled-turn-finalization.ts:132, d335dfd8d1e8)
  • Still necessary on current main: Current main permits the host fallback based only on silentExpected and reconstructs a fresh completion after unsuccessful recovery; it lacks the branch’s lastToolError preservation. (src/agents/embedded-agent-runner/run/settled-turn-finalization.ts:133, 1ad2e83fd7d5)
  • Latest release comparison: The inspected v2026.9.2 implementation also allows fallback without checking lastToolError and replaces terminal ownership; this requested repair is not present in that release. (src/agents/embedded-agent-runner/run/settled-turn-finalization.ts:133, 3928bad9badf)
  • Caller, preparation, and retry invariant: The run loop consumes the preserved completion and clears provider-failure bookkeeping only for answered/completed-empty recovery. Terminal preparation reads lastToolError through the existing payload builder; terminal resolution blocks ordinary retries once finalization has been attempted. The backend dispatches through the selected harness, so the fix is shared rather than Codex-specific. (src/agents/embedded-agent-runner/run-loop.ts:556, d335dfd8d1e8)
  • Established error-delivery contract: The agent-loop documentation requires a warning when tool failure would otherwise leave no reply. Existing payload preparation marks tool warnings and provider errors as errors; preserving the original completion reuses those presentation rules. Public docs: docs/concepts/agent-loop.md. (docs/concepts/agent-loop.md:111, d335dfd8d1e8)
  • Regression and sibling coverage: Read both changed test modules and adjacent provider-error coverage. Cases cover empty/throwing recovery, explicit NO_REPLY, unavailable finalization with a real transcript store, successful-tool fallback, cancellation, and writer fencing. Existing answered-recovery coverage remains. Tests were inspected, not executed during this read-only review. (src/agents/embedded-agent-runner/run/settled-turn-finalization.test.ts:432, d335dfd8d1e8)

Likely related people:

  • Peter Steinberger: Suggested for follow-up; no historical authorship or introduction is verified. (role: unverified routing candidate; confidence: low)
  • Jason (Json): Suggested for follow-up; no historical authorship or introduction is verified. (role: unverified routing candidate; confidence: low)

Rating scale

Score Internal tier Crab rank Meaning
6/6 S 🦀 challenger crab Exceptional readiness
5/6 A 🦞 diamond lobster Very strong readiness
4/6 B 🐚 platinum hermit Good normal PR; ordinary maintainer review
3/6 C 🦐 gold shrimp Useful, but confidence is limited
2/6 D 🦪 silver shellfish Proof or implementation needs work
1/6 F 🧂 unranked krab Not merge-ready
N/A NA 🌊 off-meta tidepool Rating does not apply

Overall follows the weaker of proof and patch quality.
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.

Workflow

  • 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.

History

Review history (1 earlier review cycle)
  • reviewed 2026-09-05T20:12:19.270Z sha d335dfd :: blocked before merge. :: none

@altaywtf

altaywtf commented Sep 6, 2026

Copy link
Copy Markdown
Member Author

@clawsweeper re-review

@clawsweeper

clawsweeper Bot commented Sep 6, 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 exact_review_queue).
Result: when the review finishes, ClawSweeper will create the durable review comment if needed or update the existing comment in place.

Re-review progress:

@clawsweeper clawsweeper Bot added proof: sufficient ClawSweeper judged the real behavior proof convincing. rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. and removed rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. labels Sep 6, 2026
@altaywtf
altaywtf merged commit ce2ba3b into main Sep 6, 2026
263 of 265 checks passed
@altaywtf
altaywtf deleted the t3code/investigate-glitch-setup-issue branch September 6, 2026 06:51
@altaywtf

altaywtf commented Sep 6, 2026

Copy link
Copy Markdown
Member Author

Merged via squash.

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

Labels

agents Agent runtime and tooling maintainer Maintainer-authored PR P2 Normal backlog priority with limited blast radius. proof: sufficient ClawSweeper judged the real behavior proof convincing. proof: telegram-e2e This PR needs Telegram Test Server proof with the repository E2E skill. rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. size: S status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants