Skip to content

fix(agent): retry transient settled finalization - #126404

Closed
MagMueller wants to merge 5 commits into
openclaw:mainfrom
MagMueller:agent/max-turn-finalization
Closed

MagMueller wants to merge 5 commits into
openclaw:mainfrom
MagMueller:agent/max-turn-finalization

Conversation

@MagMueller

@MagMueller MagMueller commented Aug 19, 2026 •

Copy link
Copy Markdown
Contributor

Related: #126255

What Problem This Solves

After a tool turn is fully settled, OpenClaw can need one isolated, tool-free request to produce a visible final answer. A transient stream-idle or retryable provider interruption in that request can otherwise discard a completed browser task.

Design

  • Retry settled-turn finalization at most once.
  • Retry only a typed transient/rate-limit or idle failure with no completed assistant message, no capability activity, and no canonical replay/recovery blocker.
  • Preserve all existing settlement, side-effect, delivery, compaction, Codex app-server, timeout, and cancellation gates.
  • Keep both attempts tool-free; tool calls, empty responses, non-retryable failures, and unsafe state fail closed.
  • Bound the finalization operation with its own 300-second AbortSignal composed with the live parent signal.
  • Do not mutate the model's requestTimeoutMs; explicit provider policy and the local-provider post-event idle exemption remain unchanged.

Evidence

  • 4 files, 286 insertions / 25 deletions against current upstream main.
  • Current head: 9a3fffeab9008cc7a9b7c2a49f0e4dacba35aa37, rebased onto 3ae680f7143336e6918f8819163a3cbf21882e92.
  • pnpm check:changed passed after rebase.
  • Focused finalizer/harness suites and both core typecheck lanes pass.
  • Required branch autoreview found no finding and rated the patch correct at 0.97 confidence.

Evaluation result

Combined with #126255 and #127796, full run 32556602972 scored 86/106 (81.13%), above historical Laith OpenClaw at 82/106. Browser lifecycle was clean on all 106 tasks, with zero Harness IPC/capture timeout signatures. A final exact-current-head smoke/full rerun is being recorded separately before merge.

@clawsweeper

clawsweeper Bot commented Aug 19, 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 docs Improvements or additions to documentation cli CLI command changes commands Command implementations agents Agent runtime and tooling size: XL triage: needs-pr-context Candidate: external PR body lacks required problem context or evidence. and removed triage: needs-pr-context Candidate: external PR body lacks required problem context or evidence. labels Aug 19, 2026
@clawsweeper clawsweeper Bot added P2 Normal backlog priority with limited blast radius. 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 Aug 19, 2026
@clawsweeper

clawsweeper Bot commented Aug 19, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: needs real behavior proof before merge.

What this changes

This PR retries a transient, capability-free finalizer failure once and adds a five-minute deadline to each finalization attempt.

Example: A browser task completes, but its isolated final-answer request receives HTTP 503.

  • Before: Finalization fails without another summary request.
  • After: An eligible failure receives one additional tool-free request that can produce the final answer.

Review scores

Measure Result What it means
Overall readiness 🧂 unranked krab (1/6) Useful recovery work, but the unchanged head retains three confirmed defects and lacks inspectable proof of the changed transport behavior.
Proof confidence 🧂 unranked krab (1/6) Real behavior proof is necessary before merge. See Before merge.
Patch quality 🦪 silver shellfish (2/6) 3 actionable review findings remain.

Product

Kind: Bug fix · Worth it: Yes · Fix scope: Complete
User problem: Completed tool work can lose its useful final answer when the isolated summary request encounters a transient failure.
Reason: Recovering the answer without repeating completed actions has clear user value and belongs in the existing core finalization owner.

Merge readiness

⛔ Blocked before merge - 6 items remain

Keep open: this PR contains distinct, maintainer-engaged recovery work that current main does not replace; the three previously reported correctness blockers remain.

Priority: P2
Reviewed head: 3f1e47da60d5d816cd52987587a41a29706dfa8a

Before merge

  • Add real behavior proof - The supplied combined browser benchmark does not show a transient failure inside the changed isolated finalizer followed by its single tool-free retry and recovered answer. Its linked Actions run returned HTTP 404, and the added tests mock the backend or construct attempt results. Provide a production-owner trace using the real transport, with credentials, private endpoints, IP addresses, and personal data redacted. After adding proof, update the PR body, then request a new review with @clawsweeper re-review. The PR author or someone with repository write access can request it.
  • Honor configured timeouts in the finalizer deadline (P1) - With both the run budget and provider request timeout set to 600000 ms, a valid finalizer that needs 360 seconds is aborted at 300 seconds by this new signal. Preserving model.requestTimeoutMs does not preserve its behavior because AbortSignal.any selects the earlier deadline. The added timeout test mocks the deadline and checks a shorter 45000 ms provider value, so it misses this regression. Reuse the configured attempt deadline instead of imposing an unconditional ceiling.
  • Wait through the short rate-limit window before retrying (P2) - A capability-free prompt failure containing HTTP 429: too many requests; Retry-After: 2 seconds is classified as retryable, but this call starts the only retry immediately. A provider enforcing that window rejects the second request before recovery becomes possible. classifyRateLimitWindow already returns retryAfterSeconds; carry the delay to this owner and wait with cancellation before issuing the second request.
  • Carry structured transport codes into retry classification (P2) - A prompt error such as Object.assign(new Error('read failed'), { code: 'ECONNRESET' }) loses its top-level code here: formatErrorMessage does not request includeCode, and the constructed signal supplies only message and a text-derived status. Consequently hasTransientRetryEvidence receives no code and rejects a transport failure it explicitly supports. Preserve structured code/status evidence when constructing the failover signal and cover this case without embedding the code in the message.
  • Complete next step - Resolve the GitHub-reported conflicts by integrating the retry into current main's existing finalization loop and retaining its lifecycle and configured attempt controls.
  • Explain or restore the original intent of Finalizer timeout ownership - fix: recover final replies after settled tool-only turns #110565: The original restricted attempt retained the caller's timeout; current main and v2026.10.4 use configured attempt controls rather than a separate fixed ceiling.

Findings

  • [P1] Honor configured timeouts in the finalizer deadline — src/agents/embedded-agent-runner/run/settled-turn-finalization.ts:208-211
  • [P2] Wait through the short rate-limit window before retrying — src/agents/embedded-agent-runner/run/settled-turn-finalization.ts:131-135
  • [P2] Carry structured transport codes into retry classification — src/agents/harness/settled-turn-finalization-result.ts:45-51

Provenance

Tests

  • Missing end-to-end proof: Provide a redacted real-transport trace through the production finalizer showing an injected transient failure, one tool-free retry, recovered delivery, and preserved configured deadlines; demonstrate focused regressions failing before the repair.
Agent review details

How this fits together

After tool execution settles, the embedded runner sends frozen context through the selected harness's restricted finalizer and converts its result into terminal reply payloads.

flowchart TD
 A[Settled tool execution] --> B[Terminal preparation]
 B --> C[Finalization eligibility]
 C --> D[Restricted harness finalizer]
 D --> E[Transient failure classification]
 E --> D
 D --> F[Terminal reply delivery]
Loading

Technical review

Best possible solution:

Extend current main's existing finalization loop with bounded typed retries, configured deadlines, cancellation-aware rate-limit waits, and preserved structured transport evidence.

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

Source establishes the failure paths and the three patch defects; no target code or tests were executed under this read-only review.

Is this the best way to solve the issue?

The restricted-finalizer boundary is the right repair location, but this implementation is incomplete; replaying the original tool-bearing request would be unsafe, while current main's existing loop and attempt controls provide a smaller integration point.

Full review comments:

  • [P1] Honor configured timeouts in the finalizer deadline — src/agents/embedded-agent-runner/run/settled-turn-finalization.ts:208-211
    With both the run budget and provider request timeout set to 600000 ms, a valid finalizer that needs 360 seconds is aborted at 300 seconds by this new signal. Preserving model.requestTimeoutMs does not preserve its behavior because AbortSignal.any selects the earlier deadline. The added timeout test mocks the deadline and checks a shorter 45000 ms provider value, so it misses this regression. Reuse the configured attempt deadline instead of imposing an unconditional ceiling.
    Confidence: 0.99
  • [P2] Wait through the short rate-limit window before retrying — src/agents/embedded-agent-runner/run/settled-turn-finalization.ts:131-135
    A capability-free prompt failure containing HTTP 429: too many requests; Retry-After: 2 seconds is classified as retryable, but this call starts the only retry immediately. A provider enforcing that window rejects the second request before recovery becomes possible. classifyRateLimitWindow already returns retryAfterSeconds; carry the delay to this owner and wait with cancellation before issuing the second request.
    Confidence: 0.99
  • [P2] Carry structured transport codes into retry classification — src/agents/harness/settled-turn-finalization-result.ts:45-51
    A prompt error such as Object.assign(new Error('read failed'), { code: 'ECONNRESET' }) loses its top-level code here: formatErrorMessage does not request includeCode, and the constructed signal supplies only message and a text-derived status. Consequently hasTransientRetryEvidence receives no code and rejects a transport failure it explicitly supports. Preserve structured code/status evidence when constructing the failover signal and cover this case without embedding the code in the message.
    Confidence: 0.98

Overall correctness: patch is incorrect
Overall confidence: 0.98

AGENTS.md: found and applied where relevant.

Codex review notes: model internal, reasoning medium; reviewed against 137e7b2abc87.

Provenance checked

  • Unsuccessful finalizer result rejection changes intended behavior with a stated reason (6eea20c: The original repair deliberately rejected unsuccessful attempts to keep finalization capability-free and fail closed.)

Testing

Proof path: unit tests only.

Security

None.

Evidence

Acceptance criteria:

  • pnpm test src/agents/embedded-agent-runner/run/settled-turn-finalization.test.ts src/agents/harness/settled-turn-finalization-result.test.ts
  • pnpm test src/agents/harness/selection.test.ts src/agents/harness/lifecycle.test.ts
  • pnpm check:changed
  • git diff --check

What I checked:

  • Pinned introduction and size: The introduced diff changes only the two production finalization modules and their colocated tests: production +92/-22, tests +194/-3. (src/agents/embedded-agent-runner/run/settled-turn-finalization.ts:110, 3f1e47da60d5)
  • Configured timeout contract: The new abort signal always expires at 300000 ms, while the existing idle-timeout owner explicitly honors longer provider request timeouts; attempt-timeout preparation independently uses the configured attempt budget. (src/agents/embedded-agent-runner/run/settled-turn-finalization.ts:208, 3f1e47da60d5)
  • Retry classification and scheduling: The classifier constructs a signal from formatted message text alone; the runner immediately issues its second request. classifyRateLimitWindow already exposes short-window retryAfterSeconds, and hasTransientRetryEvidence accepts structured transport codes. (src/agents/harness/settled-turn-finalization-result.ts:45, 3f1e47da60d5)
  • Entry point and restricted owner boundary: run-loop calls terminal finalization; backend dispatches through harness selection and lifecycle validation; the built-in harness executes a restricted attempt before result projection. Codex uses its separate bounded finalizer and does not produce this PR's retryable error. (src/agents/embedded-agent-runner/run-loop.ts:538, 3f1e47da60d5)
  • Current-main comparison: Current main retries empty finalization results, but thrown finalizer failures leave that loop through its catch. It already owns configured finalizer deadlines through createAttemptControls and resolveAgentTimeoutMs. (src/agents/embedded-agent-runner/run/settled-turn-finalization.ts, 137e7b2abc87)
  • Maintainer engagement preserves distinct scope: VACInc explicitly states that the merged eligibility, transport-recovery, ordinary-attempt retry, and cron-fallback repairs do not supersede this PR's transient-finalizer retry. The September 4 comment expressly distinguishes scope from approval.

Likely related people:

  • joshavant: Raw commit 6eea20c adds src/agents/harness/settled-turn-finalization-result.ts:28 relative to its recorded parents. This identifies author metadata, not feature responsibility or a PR merger. (role: source-line author; confidence: high; commits: 6eea20ce181e; files: src/agents/harness/settled-turn-finalization-result.ts)
  • Peter Steinberger: Raw commit df5d85a adds src/agents/embedded-agent-runner/run/settled-turn-finalization.ts:112 relative to its recorded parents. This identifies author metadata, not feature responsibility or a PR merger. (role: source-line author; confidence: high; commits: df5d85a5b2ff; files: src/agents/embedded-agent-runner/run/settled-turn-finalization.ts)

PR surface

Source +70, Tests +191. Total +261 across 4 files. Added test files: 0.

View PR surface stats
Area Files Added Removed Net
Source 2 92 22 +70
Tests 2 194 3 +191
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 4 286 25 +261

Review metrics

Metric Value Why it matters
Production versus test LOC Production +92/-22 (net +70); tests +194/-3 (net +191) Typed retry eligibility and accounting add a real recovery capability; remove the separate fixed-deadline machinery and integrate orchestration into the existing current-main loop.
Finalizer deadline Added one unconditional 300000 ms ceiling per attempt This changes effective timeout behavior even when existing provider and run budgets permit longer requests.

Labels

Label changes:

No label changes.

Label justifications:

  • P2: Focused post-tool recovery work with concrete correctness blockers and limited runtime scope.
  • merge-risk: 🚨 compatibility: The new abort signal overrides existing configurations that intentionally allow finalization requests longer than five minutes.
  • rating: 🧂 unranked krab: Overall readiness is 🧂 unranked krab; proof is 🧂 unranked krab and patch quality is 🦪 silver shellfish.
  • status: 📣 needs proof: The PR needs real behavior proof before ClawSweeper can clear the contributor ask.

Rating scale

6/6 🦀 challenger crab · 5/6 🦞 diamond lobster · 4/6 🐚 platinum hermit · 3/6 🦐 gold shrimp · 2/6 🦪 silver shellfish · 1/6 🧂 unranked krab. Overall follows the weaker of proof and patch quality; ✨ marks media proof (a screenshot, video, or linked artifact) that directly shows the changed behavior.

Workflow

ClawSweeper edits this one comment on every review. Comment @clawsweeper re-review for a fresh review only. Repair and merge execution lanes are retired.

History

Review history (5 earlier review cycles)
  • reviewed 2026-09-08T16:18:52.023Z sha 3f1e47d :: needs real behavior proof before merge. :: [P1] Honor configured timeouts in the finalizer deadline | [P2] Wait through the rate-limit window before retrying
  • reviewed September 21, 2026, 10:47 PM ET / September 22, 2026, 02:47 UTC (Revision 2) sha unknown :: needs real behavior proof before merge. :: [P1] Honor configured timeouts in the finalizer deadline | [P2] Wait through the rate-limit window before retrying
  • reviewed 2026-09-22T02:47:23.613Z sha 3f1e47d :: needs real behavior proof before merge. :: [P1] Honor configured timeouts in the finalizer deadline | [P2] Wait through the rate-limit window before retrying
  • reviewed 2026-09-26T19:58:37.371Z sha 3f1e47d :: needs real behavior proof before merge. :: [P1] Respect configured timeouts in the finalizer deadline | [P2] Wait through the short rate-limit window before retrying | [P2] Carry structured transport codes into retry classification
  • reviewed 2026-10-03T06:36:57.762Z sha 3f1e47d :: needs real behavior proof before merge. :: [P1] Respect configured timeouts in the finalizer deadline | [P2] Wait through the short rate-limit window before retrying | [P2] Carry structured transport codes into retry classification

Reviewed October 18, 2026, 1:00 AM ET / 05:00 UTC (Revision 6).

@clawsweeper clawsweeper Bot added merge-risk: 🚨 auth-provider 🚨 May break OAuth, tokens, provider routing, model choice, or credentials. rating: 🧂 unranked krab Not merge-ready due to missing proof or serious correctness/safety concerns. and removed rating: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. labels Aug 19, 2026
@MagMueller

Copy link
Copy Markdown
Contributor Author

@clawsweeper re-review

The PR body now includes the required real 106-task behavior proof, including the negative result: --max-turns 35 enforced the bound but reduced accuracy from 75/106 to 51/106. This is therefore explicitly an opt-in local CLI control, not a browser default or dependency. The benchmark adapter now leaves it disabled unless an experiment sets enforce_max_turns=true. The existing targeted recovery result remains labeled as a narrow cohort, not a benchmark claim.

@clawsweeper

clawsweeper Bot commented Aug 19, 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: 🦐 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. and removed rating: 🧂 unranked krab Not merge-ready due to missing proof or serious correctness/safety concerns. status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask. labels Aug 19, 2026
@MagMueller
MagMueller force-pushed the agent/max-turn-finalization branch from 6f11544 to c6ca82a Compare August 22, 2026 06:50
@openclaw-barnacle openclaw-barnacle Bot added size: S and removed docs Improvements or additions to documentation cli CLI command changes commands Command implementations size: XL labels Aug 22, 2026
@MagMueller MagMueller changed the title feat(agent): add bounded turn finalization fix(agent): retry transient settled finalization Aug 22, 2026
@clawsweeper clawsweeper Bot added the rating: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. label Aug 28, 2026
@clawsweeper clawsweeper Bot removed merge-risk: 🚨 compatibility 🚨 May break existing users, config, migrations, defaults, or upgrade paths. merge-risk: 🚨 availability 🚨 May cause crashes, hangs, restart loops, stalls, or process outages. labels Sep 3, 2026
@clawsweeper

clawsweeper Bot commented Sep 3, 2026

Copy link
Copy Markdown
Contributor

ClawSweeper recorded closeout evidence for this proposed close.

@VACInc

VACInc commented Sep 4, 2026

Copy link
Copy Markdown
Member

Scope clarification after #138362: that merge repairs eligibility for the initial tool-free finalization request; it does not implement this PR's typed transient-finalizer retry.

At ca3c749a510, the finalization loop retries an empty outcome, while a thrown finalizer failure proceeds to the existing failure-honest fallback. See the current loop and failure handling.

The typed transient retry and deadline policy proposed here therefore require a separate assessment. Neither the new eligibility fix nor the existence of #133520's fallback alone establishes identical behavior. I am not closing this PR as a duplicate of #138362; this note is a scope distinction, not approval of the proposed retry policy.

@VACInc

VACInc commented Sep 6, 2026

Copy link
Copy Markdown
Member

Related update: #138985 has merged. It addresses recovery eligibility after transport failures, not the typed transient-finalizer retry and deadline policy proposed here. This PR is not being closed as superseded by that merge.

@VACInc

VACInc commented Sep 6, 2026

Copy link
Copy Markdown
Member

Related merge: #140367 landed in main on September 6, 2026 (04081aa). It makes a truncated ordinary completions call eligible for the existing tool-free finalization path after settled tools, even when pre-tool commentary was delivered.

This differs from retrying a transient failure inside the isolated finalization request itself. #140367 does not implement this PR's transient-finalizer retry policy or deadline changes. Leaving this PR open.

@clawsweeper clawsweeper Bot added P2 Normal backlog priority with limited blast radius. merge-risk: 🚨 compatibility 🚨 May break existing users, config, migrations, defaults, or upgrade paths. rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. and removed P1 High-priority user-facing bug, regression, or broken workflow. rating: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. labels Sep 8, 2026
@VACInc

VACInc commented Sep 13, 2026

Copy link
Copy Markdown
Member

#147203, merged as fc1975991f22403d4a8a723c2a27071bbc16d55f, retries the preceding ordinary embedded attempt after an eligible settled-tool model idle timeout.

This PR targets a different stage: transient failure inside the isolated, tools-disabled finalization attempt itself. The merged change does not replace that finalization-retry behavior. Keeping this PR open.

@VACInc

VACInc commented Sep 21, 2026

Copy link
Copy Markdown
Member

Related: #154930 merged into main and silences the host-generated missing-summary fallback for cron-triggered runs. Release availability and deployment are unverified.

This does not implement the typed transient-finalizer retry or 300-second deadline proposed here. Silencing a cron placeholder after unsuccessful recovery is different from recovering a useful answer by retrying the isolated finalizer. Keeping this PR open; its retry and deadline policy is not replaced by the merged fix.

@clawsweeper clawsweeper Bot removed the merge-risk: 🚨 availability 🚨 May cause crashes, hangs, restart loops, stalls, or process outages. label Sep 22, 2026
@clawsweeper clawsweeper Bot added rating: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. and removed rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. labels Sep 26, 2026
@openclaw-barnacle

Copy link
Copy Markdown

This pull request has been automatically marked as stale due to inactivity.
Please add updates or it will be closed.

@openclaw-barnacle

Copy link
Copy Markdown

Closing due to inactivity.
If you believe this PR should be revived, post in #clawtributors on Discord to talk to a maintainer.
That channel is the escape hatch for high-quality PRs that get auto-closed.

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

Labels

agents Agent runtime and tooling merge-risk: 🚨 compatibility 🚨 May break existing users, config, migrations, defaults, or upgrade paths. P2 Normal backlog priority with limited blast radius. rating: 🧂 unranked krab Not merge-ready due to missing proof or serious correctness/safety concerns. size: M stale Marked as stale due to inactivity status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants