Repository navigation
fix(agents): restore channel and cron replies after a failed final tool - #118344
Conversation
|
Codex review: needs maintainer review before merge. Reviewed August 2, 2026, 9:30 PM ET / August 3, 2026, 01:30 UTC. ClawSweeper reviewWhat this changesThe PR permits one tools-disabled, failure-honest final reply after every terminal tool call has a matching settled result, with regressions and isolated QA scenarios for channel and cron delivery. Merge readinessThis PR remains necessary: current main still treats a failed Priority: P1 Review scores
Verification
How this fits togetherThe embedded agent runner converts a model's tool-call transcript into a final assistant payload. Channel adapters and isolated cron jobs consume that payload, so the runner's settled-turn decision determines whether users receive a final reply or a generic missing-response fallback. flowchart LR
A[Model terminal tool call] --> B[Embedded agent runner]
B --> C[Tool results and lifecycle state]
C --> D[Settled-turn safety decision]
D --> E[Tools-disabled final response]
E --> F[Channel reply or cron announcement]
Decision needed
Why: OpenClaw policy makes direct personal inspection of Before merge
Agent review detailsSecurityNone. PR surfaceSource +75, Tests +556, Other +305. Total +936 across 9 files. View PR surface stats
Review metrics
Stored data modelPersistent data-model change detected: Root-cause clusterRelationship: Members:
Proposal only: this assessment does not dispatch repair, suppress jobs, mutate sibling items, close, or merge anything. Mantis proof suggestionA short Telegram Desktop recording would provide direct user-visible confirmation that a failed tool ends with one honest final reply and no replay. A maintainer can ask Mantis to capture proof by posting this exact PR comment: Merge-risk optionsMaintainer options:
Technical reviewBest possible solution: Keep this as the canonical candidate for #118274, complete the required direct Codex contract review, then merge this shared-runner repair if that audit confirms the existing exact-call-ID and follow-up-turn assumptions. Do we have a high-confidence way to reproduce the issue? Yes, source-reproducible: current main excludes errored tool results from terminal completion and rejects Is this the best way to solve the issue? Unclear pending the required Codex contract audit: the shared embedded-runner boundary is the right owner and the patch is narrowly guarded, but the runtime assumptions about function-call identity and required follow-up must be directly verified before a merge verdict. AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning high; reviewed against f2af4e97b356. LabelsLabel justifications:
EvidenceWhat I checked:
Likely related people:
Rank-up movesOptional improvements that raise the rating; they are not merge blockers.
Rating scale
Overall follows the weaker of proof and patch quality. Workflow
HistoryReview history (1 earlier review cycle)
|
|
Merged via squash.
|
|
Thanks for landing this — treating an explicit failed One follow-up question: should the runner distinguish recoverable pre-effect tool failures from failures that may have produced side effects, instead of sending every settled failure directly into a tools-disabled finalization? For example, direct
Those failures are normally repairable by the model: re-read the current file, construct a new unique anchor, and try once more. With the new A possible bounded policy:
This would be a bounded recoverable-tool continuation, not generic automatic retry. It preserves the safety goal of this PR while avoiding premature termination for clearly fixable, side-effect-free failures. The Code Mode work in #115311 / #115869 seems directionally related, but I could not find equivalent coverage for ordinary direct Would maintainers prefer this as a separate feature/bug issue, or is it considered follow-up scope for the incomplete-turn recovery policy? |
|
I agree with separating this from the merged failure-honest terminal fix. The proposal changes execution policy, not just terminal presentation: it authorizes another mutating-capable model/tool step after a failure. That deserves a focused follow-up issue and its own safety matrix rather than expanding the settled-failure repair after merge. The bounded continuation should be driven by typed tool-boundary provenance, not message parsing. A repair continuation should require all of the following:
Examples such as OpenClaw already has useful ingredients in So my recommendation is: separate follow-up issue, narrow first implementation for direct file edits, and no generic automatic retry. |
Closes #118274
Related: #118315
Additional instructions
MUST: Keep Allow edits from maintainers enabled for this PR so maintainers
can help update the branch when needed.
What Problem This Solves
Fixes an issue where users whose final tool call fails would receive no final assistant reply in channel conversations, including Telegram, or isolated cron announcements even though every requested tool had fully settled. The failed operation became a generic missing-reply warning instead of an honest, user-visible explanation.
Reported with a detailed source reproduction by @Cuttingwater in #118274; the Telegram failure mode was independently confirmed by @wzg0911.
Why This Change Was Made
Finish settled failed-tool turns at the existing shared agent-runner owner boundary, with exactly one tools-disabled finalization only after every current-batch tool-call ID and tool owner matches its settled result. Preserve the real model assistant as the terminal owner when Code Mode projects nested tool evidence, recognize the internal synthetic error fallback without dropping genuine visible payloads, and explicitly require the model to report failures honestly.
Existing fail-closed protections remain in place for missing or partial results, wrong tool owners, stale errors, active/background work, child sessions, approvals, yielded turns, and finalization failures. The existing warning remains the fallback if finalization cannot complete.
User Impact
Channel users and scheduled-job operators receive one accurate final reply explaining a completed tool failure instead of a silent turn, generic missing-response warning, or failed cron announcement. Failed tools are never replayed, duplicate side effects are not introduced, and successful tool-turn behavior is unchanged.
Evidence
Real gateway +
qa-channel+ isolated cron end-to-end proof, using the deterministic mock OpenAI provider:Both scenarios passed. Each executes exactly one real failing Code Mode
exec, proves the persisted transcript contains one failed result and zero successful results, verifies the exact normalized parentfunction_call/function_call_outputID andENOENTpayload, observes exactly one failure-honest tools-disabled finalization, and receives exactly one visibleqa-channelreply without replay.Complete owner, projection-sibling, and mock-provider regression suites: 473 tests passed across four complete Vitest shards:
OPENCLAW_VITEST_NO_OUTPUT_TIMEOUT_MS=420000 \ OPENCLAW_VITEST_NO_OUTPUT_HEARTBEAT_MS=15000 \ FS_SAFE_NATIVE_MODE=off pnpm test \ src/agents/embedded-agent-runner/run.incomplete-turn.test.ts \ src/agents/embedded-agent-runner/run/attempt-phase-lifecycle.test.ts \ extensions/qa-lab/src/providers/mock-openai/server.test.ts \ src/agents/tool-search.test.ts \ --maxWorkers=1 --reporter=dotFull nine-path
pnpm check:changedcompleted successfully on Blacksmith Testbox, including all-project TypeScript, all core/plugin/script lint lanes, formatting, SDK contract and plugin-boundary guards, dead-export and storage guards, and zero runtime import cycles.Fresh independent xhigh autoreview completed with zero accepted findings. One suggestion to read the ephemeral isolated-cron run session was rejected using direct source and the live scenario:
src/cron/isolated-agent/run.tsremoves that transient session, whilesrc/cron/isolated-agent/run-session-state.test.tsproves the stable cron job session owns the persisted transcript.Upstream Codex protocol/runtime contract inspected directly at
openai/codex@07490c75234ed3c63291a8eb7629f04f647038fa:AI-assisted; independently reviewed and validated end to end.
Canonical Maintainer Decision and Rank-Up Moves
openai/codex@07490c75234ed3c63291a8eb7629f04f647038fa:codex-rs/protocol/src/models.rs:676,codex-rs/core/src/tools/context.rs:470,codex-rs/core/src/stream_events_utils.rs:294, andcodex-rs/core/src/session/turn.rs:363.mainwas refreshed and all nine changed paths were independently checked: no upstream commit has touched any of them since the reviewed branch base. Following the repository policy not to rebase solely because unrelatedmaincommits advanced, the proven exact head is retained; its requiredopenclaw/ci-gateisSUCCESS.