Repository navigation
fix: preserve tool errors when summary recovery fails - #139309
Conversation
|
🦞👀 Pull request received. I will update this pull request when review starts. ClawSweeper review completeClawSweeper finished reviewing this revision. The review result is being finalized. |
Codex Review SummaryThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
There was a problem hiding this comment.
🟢 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_REPLYscenario.
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.
| completion === initial | ||
| ? ("failed" as const) | ||
| : finalizationOutcome === "empty" | ||
| ? ("completed-empty" as const) | ||
| : finalizationOutcome, |
|
Codex review: needs maintainer review before merge. Reviewed September 6, 2026, 2:05 AM ET / 06:05 UTC. ClawSweeper reviewWhat this changesPreserves 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 Review scores
Verification
How this fits togetherAfter 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
Before mergeNone. Agent review detailsSecurityNone. PR surfaceSource +6, Tests +76. Total +82 across 3 files. View PR surface stats
Review metrics
Technical reviewBest 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. LabelsLabel changes:
Label justifications:
EvidenceWhat I checked:
Likely related people:
Rating scale
Overall follows the weaker of proof and patch quality. Workflow
HistoryReview history (1 earlier review cycle)
|
|
@clawsweeper re-review |
|
🦞🧹 I asked ClawSweeper to review this item again. Re-review progress:
|
|
Merged via squash.
|
Related: #139253 — failed cron command followed by
NO_REPLYreports 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_REPLYcase 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
3e4becea5e2ce38ede69e8ecf5302805ecbfc09cand headd335dfd8d1e8771215494c4e506aa7230457d1a3on personal Cloudflare Crabbox, with Node 24.15.0, pnpm 12.3.4, the pinned Codex 0.153.4 binary, and liveopenai/gpt-5.6-lunaresponses.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_overloadedfor continuation and summary requests. The channel was the syntheticqa-channelplugin 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.isError: trueEach 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.