Skip to content

fix(agents): settle nested code mode bridge calls - #128440

Merged
steipete merged 1 commit into
mainfrom
steipete/fix-code-mode-bridge-settlement
Aug 24, 2026
Merged

steipete merged 1 commit into
mainfrom
steipete/fix-code-mode-bridge-settlement

Conversation

@steipete

Copy link
Copy Markdown
Contributor

What Problem This Solves

Fixes an issue where users running QuickJS Code Mode with a nested bridge tool call could see the run remain in waiting / pending_tools indefinitely without the requested target ever being invoked. The nested synthetic lifecycle recursively awaited the outer block-reply presentation flush, creating a deadlock before the call produced any outcome.

Why This Change Was Made

Make the nested synthetic lifecycle skip only the duplicate block-reply presentation boundary while preserving normal hooks, telemetry, and approvals. Race bridge calls against call, run, and context closure, and ensure each bridge call settles and wakes the owner exactly once.

Landed #128088 handles outcomes after they exist; this change fixes calls that never produced an outcome.

User Impact

QuickJS Code Mode nested bridge calls reach their target and finish deterministically, including cancellation and closure paths, instead of silently hanging before invocation. Existing lifecycle hooks, telemetry, and approval behavior remain intact.

Evidence

  • Deterministic pre-fix reproduction observed waiting / pending_tools with zero target invocations.
  • Focused validation: node scripts/run-vitest.mjs src/agents/code-mode.bridge.lifecycle.test.ts src/agents/code-mode.bridge.test.ts src/agents/code-mode.wait.test.ts src/agents/code-mode.agent-loop.test.ts src/agents/code-mode-worker-lifecycle.test.ts — five files, 66 tests passed across two Vitest shards.
  • Changed gates, formatting, type, lint, import-cycle, and diff checks passed; two clean autoreviews.
  • Production LOC: +81/-60 (net +21); tests/test-support: +289/-3 (net +286).

@clawsweeper

clawsweeper Bot commented Aug 24, 2026

Copy link
Copy Markdown
Contributor

🦞👀
ClawSweeper picked this up.

Pull request received. I will update this pull request when review starts.

@openclaw-barnacle openclaw-barnacle Bot added agents Agent runtime and tooling size: M maintainer Maintainer-authored PR labels Aug 24, 2026
@steipete
steipete marked this pull request as ready for review August 24, 2026 01:07
@steipete steipete self-assigned this Aug 24, 2026
@clawsweeper clawsweeper Bot added merge-risk: 🚨 availability 🚨 May cause crashes, hangs, restart loops, stalls, or process outages. P1 High-priority user-facing bug, regression, or broken workflow. rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR. labels Aug 24, 2026
@clawsweeper

clawsweeper Bot commented Aug 24, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge. Reviewed August 23, 2026, 9:58 PM ET / August 24, 2026, 01:58 UTC.

ClawSweeper review

What this changes

The PR prevents nested Code Mode bridge calls from re-entering the outer reply-flush boundary and makes them settle when the call, run, or context closes.

Merge readiness

⚠️ Ready for maintainer review - 2 items remain

No blocking correctness finding found. Current main still lacks the nested lifecycle boundary and closure races, so this active maintainer PR remains necessary; its availability-sensitive path should proceed through normal exact-head merge validation.

Priority: P1
Reviewed head: a55304466842da2ea50a8a9dc06be2c507482081

Review scores

Measure Result What it means
Overall readiness 🐚 platinum hermit (4/6) A focused owner-boundary repair with credible QuickJS lifecycle coverage and no blocking review finding.
Proof confidence 🌊 off-meta tidepool Not applicable: This maintainer-authored PR is not subject to the external-contributor proof gate; its body supplies focused harness and CI evidence.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Verification

Check Result Evidence
Real behavior Not applicable Not applicable: This maintainer-authored PR is not subject to the external-contributor proof gate; its body supplies focused harness and CI evidence.
Evidence reviewed 6 items Current-main gap: Current main creates bridge signals only from the request signal and per-call controller, then directly awaits the bridge request; it has neither context-abort participation nor an abort race for an abort-ignoring target.
Owner-boundary repair: The PR combines request, context, and per-call abort signals at bridge creation and settles the bridge through the existing abort-race helper before recording one settlement.
Duplicate-flush root cause: The embedded executor owns nested target calls, while the lifecycle start now bypasses only the already-owned presentation boundary for explicitly nested work; normal starts retain their flush path.
Findings None None.
Security None None.

Live Verification

Command: node scripts/run-vitest.mjs src/agents/code-mode.bridge.lifecycle.test.ts

Result: FAIL (partial) — step 2 expect_output Code Mode subscribed bridge lifecycle: expected terminal output was not visible within 30 seconds: "Code Mode subscribed bridge lifecycle"

node scripts/run-vitest.mjs src/agents/code-mode.bridge.lifecycle.test.ts
runner@runnervm76f27:/tmp/clawsweeper-live-proof-128440-AYFYoL/target$ node scripts/run-vitest.mjs src/agents/code-mode.bridge.lifecycle.test.ts
node scripts/run-vitest.mjs src/agents/code-mode.bridge.lifecycle.test.ts
[test] starting test/vitest/vitest.agents-core.config.ts

 RUN  v4.1.10 /tmp/clawsweeper-live-proof-128440-AYFYoL/target

 ✓  agents-core  src/agents/code-mode.bridge.lifecycle.test.ts (7 tests) 3891ms
     ✓ starts a subscribed nested tool without re-entering its outer presentation flush  520ms
     ✓ settles subscribed nested dispatch exactly once across repeated exec and wait turns  1275ms
     ✓ preserves the initiating sessions_yield result across its run-owner handoff  419ms
     ✓ settles an abort-ignoring subscribed tool exactly once after 'explicit cancellation'  621ms
     ✓ settles an abort-ignoring subscribed tool exactly once after 'run-owner loss'  632ms

 Test Files  1 passed (1)
      Tests  7 passed (7)
   Start at  01:59:02
   Duration  21.61s (transform 14.35s, setup 966ms, import 16.39s, tests 3.89s, environment 0ms)

[test] passed 1 Vitest shard in 27.32s
runner@runnervm76f27:/tmp/clawsweeper-live-proof-128440-AYFYoL/target$ node scripts/run-vitest.mjs src/agents/code-mode.bridge.lifecycle.test.ts
[test] starting test/vitest/vitest.agents-core.config.ts

 RUN  v4.1.10 /tmp/clawsweeper-live-proof-128440-AYFYoL/target



























Assertions:

  • FAIL expect_output: Code Mode subscribed bridge lifecycle

How this fits together

Code Mode converts JavaScript tool calls into embedded agent tool lifecycles. The lifecycle invokes the target tool, handles presentation and cancellation, then returns a settled result to the suspended Code Mode run.

flowchart LR
  A[Code Mode JavaScript] --> B[Bridge request]
  B --> C[Embedded tool lifecycle]
  C --> D{Nested lifecycle?}
  D -->|Yes| E[Skip duplicate reply flush]
  D -->|No| F[Flush reply boundary]
  E --> G[Run target with closure race]
  F --> G
  G --> H[Settled result to Code Mode]
Loading

Before merge

  • Resolve merge risk (P1) - Production code grows by 21 net lines in the availability-critical bridge settlement path; the added closure harness is strong source evidence, but exact-head validation should confirm the abort-ignoring target remains detached without leaving lifecycle activity active.
  • Complete next step (P2) - This active maintainer-owned PR has no concrete mechanical repair remaining; normal exact-head maintainer merge review is the appropriate route.
Agent review details

Security

None.

PR surface

Source +25, Tests +282. Total +307 across 7 files.

View PR surface stats
Area Files Added Removed Net
Source 6 88 63 +25
Tests 1 282 0 +282
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 7 370 63 +307

Review metrics

Metric Value Why it matters
Production versus regression coverage production +81/-60 (net +21); tests +282/-0; test support +7/-3 The production growth centralizes closure settlement in existing lifecycle owners, while the added coverage exercises the original deadlock and four closure modes.

Merge-risk options

Maintainer options:

  1. Land with exact-head liveness confirmation (recommended)
    Accept the bounded background-completion tradeoff after exact-head CI confirms the added QuickJS closure and lifecycle regression coverage.

Technical review

Best possible solution:

Keep the single nested-lifecycle marker and shared abort race at the bridge/lifecycle owners; no net-neutral absorption was identified because call, context, and run closure must all settle the stored bridge result.

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

Yes, from source: current main re-enters the ordinary lifecycle start for an inner bridge target, whose reply flush can await the outer presentation boundary; the added harness models that cycle and its closure variants.

Is this the best way to solve the issue?

Yes. Marking the nested lifecycle at its owner and racing settlement at the bridge boundary is narrower and safer than suppressing flushes in target tools or adding downstream timeouts.

AGENTS.md: found and applied where relevant.

Codex review notes: model internal, reasoning high; reviewed against 24c463749fb1.

Labels

Label justifications:

  • P1: A nested Code Mode target can otherwise leave an active agent run waiting indefinitely without invoking the requested tool.
  • merge-risk: 🚨 availability: The patch changes abort, completion, and presentation coordination for nested agent tool lifecycles.
  • rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🌊 off-meta tidepool and patch quality is 🐚 platinum hermit.
  • status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR. Not applicable: This maintainer-authored PR is not subject to the external-contributor proof gate; its body supplies focused harness and CI evidence.

Evidence

What I checked:

  • Current-main gap: Current main creates bridge signals only from the request signal and per-call controller, then directly awaits the bridge request; it has neither context-abort participation nor an abort race for an abort-ignoring target. (src/agents/code-mode-state.ts:354, 24c463749fb1)
  • Owner-boundary repair: The PR combines request, context, and per-call abort signals at bridge creation and settles the bridge through the existing abort-race helper before recording one settlement. (src/agents/code-mode-state.ts:348, a55304466842)
  • Duplicate-flush root cause: The embedded executor owns nested target calls, while the lifecycle start now bypasses only the already-owned presentation boundary for explicitly nested work; normal starts retain their flush path. (src/agents/embedded-agent-subscribe.handlers.tools.start.ts:620, a55304466842)
  • Boundary regression coverage: The added real-QuickJS harness covers the circular flush, repeated exec/wait settlement, yield handoff, and four closure paths for an abort-ignoring target. (src/agents/code-mode.bridge.lifecycle.test.ts:93, a55304466842)
  • Codex dependency boundary: This is OpenClaw's embedded Code Mode path, not a Codex-harness change: the model gate explicitly says provider-native Codex runs never reach this runtime. No affirmative dependency signal requires sibling Codex inspection. (src/agents/code-mode-runtime.ts:193, a55304466842)
  • Feature-history routing: History shows Peter Steinberger carried prior Code Mode global-tool and teardown work; the current lifecycle lines blame to this proposed commit. (src/agents/code-mode-state.ts:348, 4249df34b42a)

Likely related people:

  • steipete: Prior merged Code Mode global-tool and lifecycle work appears in the history, and the current PR’s affected lifecycle lines are authored by this account. (role: Code Mode feature-history contributor; confidence: high; commits: 4249df34b42a, 6f29b0a8b125; files: src/agents/code-mode-state.ts, src/agents/embedded-agent-runner/run/attempt-stream-prepare.ts)
  • Dallin Romney: Recent embedded-agent lifecycle history includes adjacent timeout-settlement work. (role: recent adjacent lifecycle contributor; confidence: medium; commits: 8122e5cdccfb; files: src/agents/embedded-agent-subscribe.handlers.tools.start.ts)

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 (1 earlier review cycle)
  • reviewed 2026-08-24T01:14:56.025Z sha a553044 :: needs maintainer review before merge. :: none

@steipete
steipete merged commit 353b4b8 into main Aug 24, 2026
305 checks passed
@steipete
steipete deleted the steipete/fix-code-mode-bridge-settlement branch August 24, 2026 04:48
@steipete

Copy link
Copy Markdown
Contributor Author

Merged via squash.

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

Labels

agents Agent runtime and tooling maintainer Maintainer-authored PR merge-risk: 🚨 availability 🚨 May cause crashes, hangs, restart loops, stalls, or process outages. P1 High-priority user-facing bug, regression, or broken workflow. rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. size: M status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant