Skip to content

fix: completion turns lose delegation tools after same-model retries - #163032

Merged
obviyus merged 2 commits into
openclaw:mainfrom
stackingrockss:fix/163020-same-model-retry-tools
Oct 2, 2026
Merged

obviyus merged 2 commits into
openclaw:mainfrom
stackingrockss:fix/163020-same-model-retry-tools

Conversation

@stackingrockss

@stackingrockss stackingrockss commented Oct 1, 2026 •

Copy link
Copy Markdown
Contributor

Fixes #163020

What Problem This Solves

Fixes: requester completion and settle turns lose sessions_send/sessions_spawn after a transient timeout, overload, or HTTP 520 retry that stays on the same provider/model.

User Impact

User impact: authorized coordinators can continue existing work after same-model recovery instead of requiring a fresh user message to restore delegation. No migration or permission expansion is required.

Why This Change Was Made

Separate retry diagnostics from actual fallback routing at the embedded run-loop owner. Retain retry reasons for exhaustion handling, but derive fallback state from actual fallback traces or the caller's routing provenance. An explicit fallback stage remains restricted even when its reason is absent or two providers use the same model identifier.

Security impact: genuine fallback-completion report-only gating remains enabled. Ordinary authorization, child-depth hard-denies, disabled tools, allowlists, and live admitted-run authority are unchanged. This is runtime-only: no UI, dependencies, installed-runtime changes, deployment, or Gateway restart.

Evidence

Real candidate behavior, not mocked attempts

Verified on clean head 1e88389059cb23bd42e1f8fd63bb70157ba2fa8d using a disposable normally bootstrapped Gateway, preconfigured synthetic agents, a signed ephemeral operator identity, and a controlled HTTP/SSE model service. The public agent request carried completion/settle provenance. Model requests, retry ownership, dynamic tool discovery, tool dispatch, subagent launch, peer execution, and settlement all used the candidate's real owners; none of those boundaries were mocked or bypassed.

The synthetic service first returned HTTP 520. The Gateway logged transient same-model retry 1/8 ... reason=server_error. On recovery, the model called actual tool_search and tool_call: spawn was accepted and its child executed, then send executed a real peer run and returned PEER_OK.

A before comparison restored only the original retry-fallback expression in an isolated source build. The same real HTTP 520 recovery then lost spawn discovery and executed no peer. The reviewed expression was restored, the clean candidate rebuilt, and the after proof rerun with assertions:

Original expression:
  sameModelRetry=true; spawnDiscovered=false; peerExecutions=0

Clean candidate:
  sameModelRetry=true
  spawnDiscovered=true; sendDiscovered=true
  sessions_spawn.status=accepted
  sessions_send.status=ok; reply=PEER_OK
  peerExecutions=2

Real negative controls:
  actual provider/model fallback after HTTP 401:
    discovery excludes send/spawn; direct known-id calls rejected
  configured denied agent:
    discovery excludes send/spawn; direct known-id calls rejected
  extra peer executions from rejected calls=0

The fallback control used a distinct configured provider/model and the real fallback owner; its trace selected the backup and completed successfully. The driver asserted both negative controls and the positive effects, then cleaned up its disposable Gateway/state. Temporary builds and proof files are not committed.

Regression, quality, review, and CI

  • Real-entry regression covers timeout, overload and HTTP 520 recovery, announce/settle provenance, and built-in/Codex harness dispatch. Before-fix cases fail with erroneous report_only; candidate passes. Genuine fallback, absent fallback reason, disabled tools and restricted allowlists remain covered.
  • Current-head CI: shared integration 133 passed, 76.59 s Vitest duration (node job); local focused completion suite 13 passed, 25.10 s Vitest / 54.87 s wall. Tests reuse the shared harness and mock retry delays, not real timers.
  • Delegation capability, live admitted-authority revocation/settlement, subagent scope and dispatch owner: 55 passed; child/tool-policy suite: 18 passed.
  • Repository changed-lanes quality passed, including core/test types, lint, formatting, ratchets, source contracts and import cycles. git diff --check passed. Candidate build passed.
  • Repository-native isolated P2 Auto Review completed before commits, and fresh review of this exact committed head plus the assertion-bearing real-proof driver is scoped-clean, no actionable findings.
  • Current-head CI and applicable security-review gate are green, no failing or pending checks (CI gate). An earlier intermittent UI startup-readiness failure was investigated; no UI repair is included and no manual CI rerun was requested.

Limits: the real transport proof uses a synthetic HTTP service, not an external paid model API. Codex/CLI physical attempts remain mocked regression coverage, not claimed live-provider proof. The installed Gateway was never modified or restarted. This evidence addresses ClawSweeper's requested recovered discovery and real session-tool execution; fresh bot review is pending.

Maintainer verification on the unchanged head

Independently verified 1e88389059cb23bd42e1f8fd63bb70157ba2fa8d against main e0d16ecdd58187a389bf7fb8722de6fb07e8c2a6 in isolated Docker Gateways built from both revisions. The parent actually called sessions_spawn, yielded, and received its child's successful completion. A recording provider returned one HTTP 503 on the resulting native requester-settle turn.

Captured request Main Candidate
First completion request sessions_send, sessions_spawn, sessions_yield Same
Same-model retry after 503 sessions_yield only sessions_send, sessions_spawn, sessions_yield
Ordinary non-completion request and retry All three tools All three tools

Both Gateways logged transient same-model retry 1/8 ... reason=server_error. The candidate completed the requester-settle turn successfully.

Live provider gate: repeated the real parent/child lifecycle on the exact candidate. The recording proxy injected one 503, then forwarded the retry to OpenAI gpt-4.1-mini. That request retained all three tools, returned HTTP 200, and the Gateway emitted P163020_COMPLETION_OK with stopReason=stop. Exactly one real OpenAI request; utility model, heartbeat, cron, session observer, memory search and compaction memory-flush jobs were disabled. The parent/child setup responses were synthetic; the recovered completion response came from OpenAI.

Regression: the existing completion regression group passed 13/13 on the candidate (31.16 s Vitest, 46.53 s wrapper wall). Applying those tests to the pinned main runtime produced 9 failures / 4 passes, including the same-model cases receiving report_only instead of full (29.38 s Vitest, 44.79 s wrapper wall). Both runtime builds passed. No product-code changes or CI reruns were needed.

No overlap with Pash/Sarah changes: neither author has commits on these three changed files in the inspected main history. Thanks to @stackingrockss for reporting the defect, implementing the owner-level repair, and supplying the regression coverage.

@clawsweeper

clawsweeper Bot commented Oct 1, 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 agents Agent runtime and tooling size: S labels Oct 1, 2026
@clawsweeper clawsweeper Bot added P1 High-priority user-facing bug, regression, or broken workflow. 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 Oct 1, 2026
@clawsweeper

clawsweeper Bot commented Oct 1, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge. Reviewed October 1, 2026, 7:56 PM ET / 23:56 UTC (Revision 5).

ClawSweeper review

What this changes

The PR preserves authorized delegation tools after same-model retries while retaining completion-turn restrictions for genuine model fallback.

Merge readiness

✅ Ready for maintainer review

This PR remains necessary and has no actionable correctness findings. The updated runtime evidence satisfies the prior proof request; current main still contains the reported defect.

Priority: P1
Reviewed head: 1e88389059cb23bd42e1f8fd63bb70157ba2fa8d

Review scores

Measure Result What it means
Overall readiness 🐚 platinum hermit (4/6) A focused owner-level repair with useful regressions and sufficient before/after runtime proof.
Proof confidence 🐚 platinum hermit (4/6) Sufficient (live_output): The captured body provides copied before/after live output from the exact-head Gateway's public agent entrypoint using real HTTP/SSE transport: HTTP 520 recovery restores discovery and actual send/spawn execution. Actual fallback and denied-tool controls reject calls without peer execution, satisfying the previous proof request. No stored-data contract changes.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Verification

Check Result Evidence
Real behavior Verified Sufficient (live_output): The captured body provides copied before/after live output from the exact-head Gateway's public agent entrypoint using real HTTP/SSE transport: HTTP 520 recovery restores discovery and actual send/spawn execution. Actual fallback and denied-tool controls reject calls without peer execution, satisfying the previous proof request. No stored-data contract changes.
Evidence reviewed 8 items Pinned introduced change: The merge-base-to-head diff changes only the fallback-reason producer, fallback activation, and their shared-entry regression coverage. Base-only changes are excluded from ownership assessment.
Current main still needs the repair: Current main resolves fallback reason from a fallback trace or lastRetryFailoverReason. Attempt dispatch treats any nonempty fallback reason as fallbackActive; completion provenance then selects report_only and removes session delegation tools.
Latest release retains the defect: The latest-release endpoint identifies v2026.9.7, and its run-loop source retains the resolver ending in lastRetryFailoverReason. The central repair is therefore neither already on inspected main nor already shipped in the latest release.
Findings None None.
Security None None.

How this fits together

The embedded agent runner turns incoming agent requests and completion notifications into model attempts. Its retry and routing decisions determine which authorized tools the recovered attempt can discover and execute.

flowchart TD
  A[Agent request or completion notification] --> B[Embedded run loop]
  B --> C[Same-model retry or actual fallback]
  C --> D[Delegation capability]
  D --> E[Authorized tool catalog]
  E --> F[Session send or child launch]
  F --> G[Execution and settlement]
Loading

Before merge

None.

Agent review details

Security

None.

PR surface

Source +7, Tests +139. Total +146 across 3 files.

View PR surface stats
Area Files Added Removed Net
Source 2 9 2 +7
Tests 1 139 0 +139
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 3 148 2 +146

Review metrics

None.

Root-cause cluster

Relationship: fixed_by_candidate
Canonical: #163020
Summary: This PR is the candidate fix for the linked same-model retry defect.

Members:

Proposal only: this assessment does not dispatch repair, suppress jobs, mutate sibling items, close, or merge anything.

Technical review

Best possible solution:

Keep retry diagnostics separate from actual routing facts so recovery preserves existing grants and genuine fallback completion turns remain report-only.

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

Yes, from source: a same-model retry records a failure reason that current main converts into fallbackActive, removing delegation tools for completion provenance. This read-only review did not execute the runtime.

Is this the best way to solve the issue?

Yes. Repairing fallback classification at its producer preserves the shared restriction owner and existing authorization contracts.

AGENTS.md: found and applied where relevant.

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

Labels

Label changes:

  • add proof: sufficient: Contributor real behavior proof is sufficient. The captured body provides copied before/after live output from the exact-head Gateway's public agent entrypoint using real HTTP/SSE transport: HTTP 520 recovery restores discovery and actual send/spawn execution. Actual fallback and denied-tool controls reject calls without peer execution, satisfying the previous proof request. No stored-data contract changes.
  • add rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🐚 platinum hermit and patch quality is 🐚 platinum hermit. Replaced prior rating: 🦪 silver shellfish.
  • remove rating: 🦪 silver shellfish: Current PR rating is rating: 🐚 platinum hermit, so this older rating label is no longer current.
  • remove status: 📣 needs proof: Current PR status no longer selects a status label.

Label justifications:

  • P1: The existing recovery defect interrupts authorized agent coordination during completion and settle turns.
  • rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🐚 platinum hermit and patch quality is 🐚 platinum hermit. Replaced prior rating: 🦪 silver shellfish.
  • proof: sufficient: Contributor real behavior proof is sufficient. The captured body provides copied before/after live output from the exact-head Gateway's public agent entrypoint using real HTTP/SSE transport: HTTP 520 recovery restores discovery and actual send/spawn execution. Actual fallback and denied-tool controls reject calls without peer execution, satisfying the previous proof request. No stored-data contract changes.

Evidence

What I checked:

  • Pinned introduced change: The merge-base-to-head diff changes only the fallback-reason producer, fallback activation, and their shared-entry regression coverage. Base-only changes are excluded from ownership assessment. (src/agents/embedded-agent-runner/run-loop.ts:152, 1e88389059cb)
  • Current main still needs the repair: Current main resolves fallback reason from a fallback trace or lastRetryFailoverReason. Attempt dispatch treats any nonempty fallback reason as fallbackActive; completion provenance then selects report_only and removes session delegation tools. (src/agents/embedded-agent-runner/run-loop.ts:151, c3f2837f569e)
  • Latest release retains the defect: The latest-release endpoint identifies v2026.9.7, and its run-loop source retains the resolver ending in lastRetryFailoverReason. The central repair is therefore neither already on inspected main nor already shipped in the latest release. (src/agents/embedded-agent-runner/run-loop.ts:145, c074824a27c9)
  • After-fix production-boundary proof: The fully supplied captured body, sourceRevision 04c70dba8d35d2e086ac9ff476c6fdd7d25736c904c9b13eaeb728ccd4d196aa, reports a disposable normally bootstrapped Gateway at the exact head, a public agent request with completion/settle provenance, and a real HTTP/SSE service injecting HTTP 520. Copied output records recovered send/spawn discovery, accepted spawn, successful send returning PEER_OK, and two peer executions. Restoring only the original expression loses spawn discovery and executes no peer. Actual fallback and configured-denial controls reject direct calls with zero additional peer executions. This addresses the previous review's specific rank-up request; it does not claim live Codex-provider coverage. (1e88389059cb)
  • Restrictions and live authority remain owned: Dispatch explicitly recognizes fallback provenance even without a reason. The unchanged delegation owner still restricts completion turns with disabled tools or restrictive allowlists, and agent assembly applies that gate after ordinary authorization. Retries reuse the admitted context; tool bindings and spawn execution retain current-source and lifecycle guards. No persisted authority, configuration, schema, dependency, or publication contract changes. (src/agents/embedded-agent-runner/run/run-attempt-dispatch.ts:257, 1e88389059cb)
  • Regression scope and implementation boundary: The added matrix exercises four same-model recovery cases, three explicit fallback cases, and two restricted-tool cases through the shared runner entry. Physical attempts and retry waits are mocked; the Codex-labeled fixture registers an OpenClaw test harness whose runAttempt calls the mock, rather than testing sibling Codex code or protocol. The runtime evidence separately exercises the real built-in path. The body records focused-suite and CI timing. (src/agents/embedded-agent-runner/run.prompt-timeout-fallback.test-support.ts:39, 1e88389059cb)

Likely related people:

  • MertBasar0: Suggested for follow-up; no historical authorship or introduction is verified. (role: unverified routing candidate; confidence: low)
  • steipete: 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 (4 earlier review cycles)
  • reviewed 2026-10-01T22:16:07.111Z sha 7ee4a46 :: needs real behavior proof before merge. :: none
  • reviewed 2026-10-01T22:32:54.525Z sha 7ee4a46 :: needs real behavior proof before merge. :: none
  • reviewed 2026-10-01T22:45:21.679Z sha 7ee4a46 :: needs real behavior proof before merge. :: none
  • reviewed 2026-10-01T23:13:32.474Z sha 1e88389 :: needs real behavior proof before merge. :: none

@obviyus
obviyus merged commit c96350d into openclaw:main Oct 2, 2026
140 checks passed
@obviyus

obviyus commented Oct 2, 2026

Copy link
Copy Markdown
Collaborator

Landed as c96350d. Thanks @stackingrockss, for both the report and the fix, and congrats on your first OpenClaw PR!

github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Oct 2, 2026
…penclaw#163032)

Fixes openclaw#163020.

A same-model transient retry of a requester completion turn now keeps `sessions_send` and `sessions_spawn` in the tool set, so the requester can keep delegating after recovering.

Proof: real isolated Gateways where a parent spawns a worker and receives its completion, with an injected 503 on the first completion request. main dropped both tools on the retry; this change keeps them. First-attempt tool lists and ordinary-turn retries are unchanged. Live check: after the injected 503, a real OpenAI request returned 200 with the full tool list and the completion turn finished. Regression tests fail on main and pass here.

Co-authored-by: Ayaan Zaidi <[email protected]>
yozakura-ava pushed a commit to yozakura-ava/openclaw that referenced this pull request Oct 6, 2026
…penclaw#163032)

Fixes openclaw#163020.

A same-model transient retry of a requester completion turn now keeps `sessions_send` and `sessions_spawn` in the tool set, so the requester can keep delegating after recovering.

Proof: real isolated Gateways where a parent spawns a worker and receives its completion, with an injected 503 on the first completion request. main dropped both tools on the retry; this change keeps them. First-attempt tool lists and ordinary-turn retries are unchanged. Live check: after the injected 503, a real OpenAI request returned 200 with the full tool list and the completion turn finished. Regression tests fail on main and pass here.

Co-authored-by: Ayaan Zaidi <[email protected]>
(cherry picked from commit c96350d)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

agents Agent runtime and tooling P1 High-priority user-facing bug, regression, or broken workflow. rating: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. size: S 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.

[Bug]: Same-model transient retry strips sessions_send/sessions_spawn from requester completion turns

2 participants