Repository navigation
fix(agents): finalize settled turns after provider errors - #138353
roboclaw-bot wants to merge 3 commits into
Conversation
Co-authored-by: Vito Cappello <[email protected]>
|
🦞👀 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. |
OpenClaw-Publication: b77ddd12-9afe-4a1c-8208-136de875e56d Co-authored-by: Vito Cappello <[email protected]>
8f6ba0d to
370d5b6
Compare
OpenClaw-Publication: fd424476-611c-4773-8bfe-dc45e168cb81 Co-authored-by: Vito Cappello <[email protected]>
370d5b6 to
261ee55
Compare
|
Codex review: blocked before merge. Reviewed September 4, 2026, 12:07 PM ET / 16:07 UTC. ClawSweeper reviewWhat this changesThe branch marks generated terminal model-failure replies as internal metadata and lets an exactly settled tool turn use the existing tool-free finalizer instead of treating that generated error as an assistant answer. Merge readiness⛔ Blocked before merge - 2 items remain Keep this focused bug-fix PR open: current main still has the brittle payload-shape eligibility gate, while the branch replaces it with producer-owned metadata and retains the settled-tool safety gates. No blocking correctness finding was identified; the protected Priority: P2 Review scores
Verification
How this fits togetherThe embedded agent runner turns provider results and tool activity into channel reply payloads. Terminal recovery checks whether the exact tool batch is safely settled, then may request a tool-free final answer before channel delivery. flowchart LR
A[Provider turn] --> B[Embedded agent runner]
B --> C[Reply payload preparation]
C --> D[Terminal recovery decision]
E[Settled tool transcript] --> D
D --> F[Tool-free finalizer]
F --> G[Channel reply]
Before merge
Agent review detailsSecurityNone. PR surfaceSource -3, Tests +56. Total +53 across 5 files. View PR surface stats
Review metrics
Root-cause clusterRelationship: Members:
Proposal only: this assessment does not dispatch repair, suppress jobs, mutate sibling items, close, or merge anything. Merge-risk optionsMaintainer options:
Technical reviewBest possible solution: Retain producer-owned generated-failure metadata and the existing exact-settlement gates, then merge after maintainer confirmation that replacing this narrow generated error with an isolated final summary is intended. Do we have a high-confidence way to reproduce the issue? Yes—source establishes the path: current main counts the generated error payload, while the added focused test constructs the settled-tool/provider-error scenario and exercises the terminal-finalization boundary. Is this the best way to solve the issue? Yes—the repair records the fact at the generated-error producer and reuses the settled-turn owner’s existing safety checks, replacing a brittle payload-shape heuristic without whole-turn replay. AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning high; reviewed against 300c092d8b4a. 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)
|
|
Closing this parallel duplicate at Vito’s request. The canonical repair is #138362, which includes the producer-owned payload-provenance fix, the additional terminal-safety coverage, and real HTTP 503 loopback proof that completed tools execute only once. VACInc is credited as co-author on the canonical PR’s commits and in its description. This closure does not merge either PR or delete this branch. |
Closes #126848
What Problem This Solves
A tool-using turn can finish and persist its exact tool batch, then lose the final model call to a transient network failure. Whole-turn replay is correctly blocked because tools may have side effects, but terminal preparation converts that provider failure into a generated error payload before the isolated, tool-free finalizer decides whether a usable answer already exists. The generated error is counted as an answer, so finalization never starts and completed work receives only the provider error.
This is the residual composition gap left after #128840 added the settled transcript producer. #133520 handles finalizer failure after finalization starts; it cannot help when this earlier eligibility gate returns null. The trigger and stream-resume work in #119720 and #126845 is related but does not replace failure-safe terminal recovery.
Why This Change Was Made
Reply payloads already carry WeakMap-only producer provenance for generated tool-error warnings. This change adds the matching producer fact for generated terminal model-failure payloads, then makes settled-turn eligibility discount only payloads carrying one of those two generated-failure facts.
Actual assistant output, unmarked or structured errors, media, message delivery, cancellation, unsettled/async tools, and non-transient failures still block finalization through the existing gates. The repair removes the old payload-key shape heuristic and does not change whole-turn retry policy, configuration, persistence, protocol, or provider-specific behavior.
Production LOC: +24/-27 (net -3). Tests and test support: +60/-4.
User Impact
When the exact current tool batch is proven settled and the final provider request fails transiently, OpenClaw now runs the existing isolated zero-tool finalizer and delivers its summary. Completed tools are not replayed. If finalization itself cannot answer, the existing failure-honest fallback remains authoritative.
Evidence
Pre-fix production composition probe on current main:
The new owner-boundary regression failed before the production repair because the finalizer was called zero times while the other 19 tests passed. After the repair:
node scripts/run-vitest.mjs src/agents/embedded-agent-runner/run/settled-turn-finalization.test.ts src/agents/embedded-agent-runner/run/settled-tool-evidence.test.ts src/agents/embedded-agent-runner/run/payloads.errors.test.ts src/agents/embedded-agent-runner/run/attempt.settled-turn-finalization-context.test.ts src/agents/embedded-agent-runner/run/attempt-recovery.test.ts— 110 passednode scripts/check-changed.mjs -- <five changed files>— passed core/core-test typecheck, lint, formatting, dead-export, import-cycle, schema, and architecture guardsThe regression exercises full terminal preparation: one persisted tool result, a transient final provider failure, the generated error payload, and one isolated final answer replacing that error. Existing sibling coverage retains negatives for missing finalization context, structured/unmarked output, media/delivery, cancellation, and unsettled or asynchronous work.
View the OpenClaw team session