Skip to content

fix(gateway): bind channel completion dispatch - #126113

Merged
steipete merged 3 commits into
mainfrom
steipete/fix-subagent-completion-qa-binding
Aug 19, 2026
Merged

steipete merged 3 commits into
mainfrom
steipete/fix-subagent-completion-qa-binding

Conversation

@steipete

@steipete steipete commented Aug 19, 2026 •

Copy link
Copy Markdown
Contributor

What Problem This Solves

QA Smoke profile 3 repeatedly times out subagent-completion-direct-fallback before its restart step because detached native completion reaches in-process agent dispatch without an owning Gateway instance binding.

PR #126062 added the correct resolver custody for subagent rows, but routed channel turns still bypassed the instance-bound runtime that produces that resolver. QA Channel used its global runtime instead of the exact account runtime, and native harness task completion omitted the admitted run's resolver scope.

Closes #126112.

Why This Change Was Made

This change fixes the producer boundary instead of restoring an ambient fallback:

  • routed channel turns carry the owning runtime's dispatchReplyFromConfig into the normal channel dispatcher;
  • the Gateway runtime executes that dispatcher under its lifecycle-fenced exact resolver;
  • agent admission reads the resolver from that scoped channel turn and reuses fix(gateway): bind subagent completion dispatch to instance #126062's canonical binding store;
  • QA Channel uses the exact channelRuntime supplied by its Gateway account context;
  • native harness task scopes retain the admitted run's resolver and re-enter delayed completion delivery under that lifecycle-fenced request scope.

A closed, retired, mixed-owner, restored, or absent binding still fails closed. There is no global singleton inference, retry, sleep, timeout extension, or QA-scenario bypass.

The separate generated-media recovery caller remains owned by #126001 and is intentionally excluded.

Production LOC: +104/-41 (net +63). Tests: +71/-1 (net +70). The production growth is the explicit owner-custody chain across channel runtime composition, admission, and native harness completion.

User Impact

Native subagent completions from channel-originated turns are delivered exactly once instead of silently remaining pending until QA or task timeout. Visible, silent, fallback, restart-recovered, and intentionally empty completion behavior remains intact.

Evidence

Repeated pre-fix failures on fresh PR #125954 merge refs:

Local pre-fix real scenario:

  • pnpm openclaw qa suite --provider-mode mock-openai --scenario subagent-completion-direct-fallback
  • failed after the first 60-second delivery wait;
  • Gateway logged In-process gateway dispatch requires a gateway request scope or instance binding (method: agent) three times.

Local post-fix real scenario on the initial implementation head:

  • pnpm dev qa suite --provider-mode mock-openai --scenario subagent-completion-direct-fallback
  • PASS: visible, silent, fallback, restart, and empty cases all delivered once; no silence-token or internal-metadata leak; no replay after restart.

The final-head rerun first exposed the independent current-main frozen-catalog startup regression tracked in #126123 before the scenario began. With only #126123's reviewed one-line clone boundary applied temporarily, the exact scenario passed all five visible, silent, fallback, restart, and empty cases on this final code. The temporary line was then removed and the worktree returned clean; no unrelated change is included here.

Sibling QA on the initial implementation head:

  • model-switch-tool-continuity and lobster-invaders-build: PASS through qa-channel.
  • telegram-queue-invalid-mode: PASS through the Crabline Telegram driver.

Focused regression proof:

  • the routed-runtime test fails on the pre-fix assignment because dispatchReplyFromConfig is absent from the routed turn;
  • the native harness regression proves completion delivery enters the admitted resolver scope without forwarding an ignored option;
  • the real in-process agent dispatcher consumes a lifecycle-fenced scoped resolver and retains the explicit resolver path used by existing owners;
  • latest focused Gateway, plugin SDK, subagent runtime, and runtime-channel suites: 82 tests passed;
  • final-head exact QA artifact: .artifacts/qa-e2e/suite-mszhkm2d-1f53b78f/ (1 passed, 0 failed; all five cases delivered exactly once; restart replay count 0);
  • node scripts/check-changed.mjs: PASS;
  • full production typecheck, test typecheck, and type-aware lint: PASS;
  • git diff --check: PASS;
  • private-QA build exercised through the repo-approved pnpm dev wrapper: PASS;
  • fresh Codex autoreview: clean, no accepted/actionable findings;
  • exact-head CI: https://github.com/openclaw/openclaw/actions/runs/32207823671 (green).

Direct Codex source check confirmed terminal child completion is emitted only for final Completed/Errored states and forwarded to the direct parent without triggering a new turn (codex-rs/core/src/session/mod.rs, codex-rs/protocol/src/protocol.rs). This patch changes only OpenClaw's delivery binding for that already-final completion.

@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.

@openclaw-barnacle openclaw-barnacle Bot added gateway Gateway runtime agents Agent runtime and tooling channel: qa-channel Channel integration: qa-channel size: S maintainer Maintainer-authored PR labels Aug 19, 2026
@steipete
steipete marked this pull request as ready for review August 19, 2026 01:28
@clawsweeper clawsweeper Bot added merge-risk: 🚨 message-delivery 🚨 May drop, duplicate, misroute, suppress, or wrongly target messages. P1 High-priority user-facing bug, regression, or broken workflow. rating: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. status: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action. labels Aug 19, 2026
@clawsweeper

clawsweeper Bot commented Aug 19, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge. Reviewed August 18, 2026, 10:33 PM ET / August 19, 2026, 02:33 UTC.

ClawSweeper review

What this changes

The PR preserves the owning Gateway resolver from routed channel ingress through agent admission and delayed native-harness completion delivery.

Regression provenance

Possible regression — probable (reproduction; reviewed change). No predecessor PR is attributed.

Merge readiness

⚠️ Ready for maintainer review - 3 items remain

The prior completion-scope finding is addressed: the current head carries the lifecycle-fenced resolver through channel dispatch, admission, and harness completion. No blocking patch defect found; rebase and rerun the real QA scenario after the independent catalog-startup repair. Likely related people: @steipete (high confidence).

Priority: P1
Reviewed head: 06adb12057d2c19209bdffc9a1fd20f6a3f9d158

Review scores

Measure Result What it means
Overall readiness 🐚 platinum hermit (4/6) The repair is focused, resolves the prior blocker with boundary-level tests, and has green exact-head CI; a post-rebase QA rerun would further reduce delivery risk.
Proof confidence 🌊 off-meta tidepool Not applicable: Repository metadata identifies the author as a member; the external-contributor proof gate does not apply. The PR nevertheless supplies a real ephemeral-Gateway QA pass for the behavioral implementation and notes the latest rerun was blocked before scenario start by an independent startup regression.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Verification

Check Result Evidence
Real behavior Not applicable Not applicable: Repository metadata identifies the author as a member; the external-contributor proof gate does not apply. The PR nevertheless supplies a real ephemeral-Gateway QA pass for the behavioral implementation and notes the latest rerun was blocked before scenario start by an independent startup regression.
Evidence reviewed 5 items Current-main missing path: Current main dispatches routed channel turns without carrying an instance-bound reply dispatcher, and its in-process Gateway resolver accepts only an ambient scope context or explicit option.
Lifecycle owner fix: The Gateway runtime wraps reply dispatch in the active-instance resolver scope; the scope deliberately drops any stale context before downstream dispatch resolves the Gateway.
Completion propagation: Agent admission captures the scoped resolver, the embedded attempt places it in the host-issued task scope, and completion delivery re-enters that resolver scope.
Findings None None.
Security None None.

Live Verification

Command: pnpm dev qa suite --provider-mode mock-openai --scenario subagent-completion-direct-fallback

Result: FAIL (partial) — step 2 expect_output PASS: expected terminal output was not visible within 30 seconds: "PASS"

runner@runnervm76f27:/tmp/clawsweeper-live-proof-126113-r6fnVT/target$ pnpm dev qa suite --provider-mode mock-openai --scenario subagent-completion-direct-fallb
ack
$ node scripts/run-node.mjs qa suite --provider-mode mock-openai --scenario subagent-completion-direct-fallback
pnpm dev qa suite --provider-mode mock-openai --scenario subagent-completion-direct-fallback
[openclaw] Building TypeScript (dist is stale: missing_private_qa_dist - private QA dist entry missing).
[openclaw] Building bundled plugin assets.
[canvas] build: node scripts/bundle-a2ui.mjs
[log] ‹DIR›/a2ui.bundle.js  chunk │ size: 400.66 kB
[log] ‹DIR›/a2ui-v0.9.bundle.js  chunk │ size: 615.66 kB
[log]
[success] rolldown v1.2.0 Finished in 119.09 ms
[diffs] build: node --import tsx ../../scripts/build-diffs-viewer-runtime.mts curated
[diffs-language-pack] build: node --import tsx ../../scripts/build-diffs-viewer-runtime.mts full
[discord] build: node --import tsx ../../scripts/build-discord-activity-sdk.mts
[tsdown-build] invocation 1/2 finished in 0.8s
node_modules/playwright-core/lib/coreBundle.js (65821:28) [EVAL] Use of direct ˋevalˋ function is strongly discouraged as it poses security risks and may cause
issues with minification.
       ╭─[ node_modules/playwright-core/lib/coreBundle.js:65821:29 ]
       │
 65821 │               const value = eval(ˋ(${expr})ˋ);
       │                             ──┬─
       │                               ╰─── Use of direct ˋevalˋ here.
       │
       │ Help: Consider using indirect eval. For more information, check the documentation: https://rolldown.rs/guide/troubleshooting#avoiding-direct-eval
───────╯

node_modules/playwright-core/lib/coreBundle.js (65828:28) [EVAL] Use of direct ˋevalˋ function is strongly discouraged as it poses security risks and may cause
issues with minification.
       ╭─[ node_modules/playwright-core/lib/coreBundle.js:65828:29 ]
       │
 65828 │               const value = eval(ˋ(${expr})ˋ);
       │                             ──┬─
       │                               ╰─── Use of direct ˋevalˋ here.
       │
       │ Help: Consider using indirect eval. For more information, check the documentation: https://rolldown.rs/guide/troubleshooting#avoiding-direct-eval
───────╯

node_modules/web-tree-sitter/web-tree-sitter.js (2343:30) [EVAL] Use of direct ˋevalˋ function is strongly discouraged as it poses security risks and may cause
issues with minification.
      ╭─[ node_modules/web-tree-sitter/web-tree-sitter.js:2343:31 ]
      │
 2343 │           ASM_CONSTS[start] = eval(func);
      │                               ──┬─
      │                                 ╰─── Use of direct ˋevalˋ here.
      │
      │ Help: Consider using indirect eval. For more information, check the documentation: https://rolldown.rs/guide/troubleshooting#avoiding-direct-eval
──────╯

node_modules/web-tree-sitter/web-tree-sitter.js (2366:32) [EVAL] Use of direct ˋevalˋ function is strongly discouraged as it poses security risks and may cause
issues with minification.
      ╭─[ node_modules/web-tree-sitter/web-tree-sitter.js:2366:33 ]
      │
 2366 │           moduleExports[name] = eval(func);
      │                                 ──┬─
      │                                   ╰─── Use of direct ˋevalˋ here.
      │
      │ Help: Consider using indirect eval. For more information, check the documentation: https://rolldown.rs/guide/troubleshooting#avoiding-direct-eval
──────╯

[tsdown-build] invocation 2/2 finished in 16.4s
[plugin-control-plane-loads] verified 36 built modules with native require and checked doctor closures
runtime-postbuild: 10 phases completed in 4724ms (slowest: built plugin control-plane loads 3819ms)
│


Assertions:

  • FAIL expect_output: PASS

How this fits together

Channel plugins convert inbound messages into agent runs, which can later send a completed child result back through the Gateway. This patch keeps that delayed delivery attached to the Gateway instance that admitted the original channel turn.

flowchart LR
  A[Inbound channel event] --> B[Plugin channel runtime]
  B --> C[Gateway-bound reply dispatch]
  C --> D[Agent run admission]
  D --> E[Native child completion]
  E --> F[Lifecycle-fenced resolver]
  F --> G[Completion message delivery]
Loading

Before merge

  • Resolve merge risk (P1) - The PR changes delayed completion routing across Gateway, channel, and harness boundaries; an incorrect binding could still suppress or misroute a completion message.
  • Resolve merge risk (P1) - Production grows by 63 net lines for this bug fix; the explicit custody chain is justified by the three owner boundaries, but should be retained only if the real QA rerun confirms it.
  • Complete next step (P2) - Wait for the independent catalog-startup repair, then rebase and rerun the real QA scenario on the current head before merge.
Agent review details

Security

None.

PR surface

Source +63, Tests +70. Total +133 across 17 files.

View PR surface stats
Area Files Added Removed Net
Source 14 104 41 +63
Tests 3 71 1 +70
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 17 175 42 +133

Review metrics

Metric Value Why it matters
Production versus test delta production +63 net; tests +70 net The production growth is the explicit resolver-custody path across routed dispatch, admission, and delayed completion, while tests cover each handoff.

Root-cause cluster

Relationship: fixed_by_candidate
Canonical: #126112
Summary: This PR is the explicit candidate repair for the QA completion-delivery failure.

Members:

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

Merge-risk options

Maintainer options:

  1. Rebase and rerun completion QA (recommended)
    After the catalog-startup repair reaches main, rebase this PR and run the real subagent completion scenario to confirm visible, silent, fallback, restart, and empty delivery remain exact-once.

Technical review

Best possible solution:

Keep the single lifecycle-fenced resolver chain and validate it on a rebased head with the real completion QA scenario once the independent startup regression is fixed.

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

Yes, source-reproducible: current main lacks the routed dispatcher and harness resolver propagation, matching the supplied QA scenario failure. I did not execute it because this is a read-only review and the PR reports the current-main catalog startup blocker prevents the latest rerun.

Is this the best way to solve the issue?

Yes. Carrying the existing lifecycle-fenced resolver from its owning Gateway runtime avoids restoring an ambient global fallback and repairs the producer boundary.

AGENTS.md: found and applied where relevant.

Codex review notes: model internal, reasoning high; reviewed against 23da04ba8af4.

Labels

Label changes:

  • add rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🌊 off-meta tidepool and patch quality is 🐚 platinum hermit.
  • add status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR. Not applicable: Repository metadata identifies the author as a member; the external-contributor proof gate does not apply. The PR nevertheless supplies a real ephemeral-Gateway QA pass for the behavioral implementation and notes the latest rerun was blocked before scenario start by an independent startup regression.
  • remove rating: 🦪 silver shellfish: Current PR rating is rating: 🐚 platinum hermit, so this older rating label is no longer current.
  • remove status: ⏳ waiting on author: Current PR status label is status: 👀 ready for maintainer look.

Label justifications:

  • P1: The repaired path prevents channel-originated subagent completions from remaining pending until timeout.
  • merge-risk: 🚨 message-delivery: The patch changes the Gateway binding used when delayed child completion messages are delivered.
  • 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: Repository metadata identifies the author as a member; the external-contributor proof gate does not apply. The PR nevertheless supplies a real ephemeral-Gateway QA pass for the behavioral implementation and notes the latest rerun was blocked before scenario start by an independent startup regression.

Evidence

Acceptance criteria:

  • [P2] pnpm dev qa suite --provider-mode mock-openai --scenario subagent-completion-direct-fallback.

What I checked:

Likely related people:

  • steipete: Authored the prior merged Gateway instance-binding repair and the current continuation of the same completion-delivery path. (role: recent area contributor; confidence: high; commits: 2cd87d3d27c1, 06adb12057d2; files: src/plugins/runtime/gateway-request-scope.ts, src/plugin-sdk/agent-harness-task-runtime.ts, src/gateway/server-plugins.ts)

Rank-up moves

Optional improvements that raise the rating; they are not merge blockers.

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-19T01:36:50.550Z sha f5e3226 :: needs changes before merge. :: [P1] Scope the harness completion dispatch instead of passing an ignored field

@clawsweeper clawsweeper Bot added 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. and removed rating: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. status: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action. labels Aug 19, 2026
@steipete

Copy link
Copy Markdown
Contributor Author

Land-ready evidence for head 06adb12057d2c19209bdffc9a1fd20f6a3f9d158:

  • Applied ClawSweeper's P1 finding: native harness completion now enters withPluginRuntimeGatewayContextResolver at the delivery owner instead of forwarding an undeclared/ignored option.
  • Added both halves of the boundary regression: the harness producer observes the admitted resolver scope, and the real in-process agent dispatcher consumes that scoped resolver. The existing explicit-resolver path remains covered.
  • Focused Gateway, Plugin SDK, subagent runtime, and runtime-channel proof passes: 82 tests.
  • The exact subagent-completion-direct-fallback QA scenario passes on the final code: visible, silent, fallback, restart, and empty cases each delivered exactly once; restart replay count 0; no silence-token or internal-metadata leak.
  • The QA rerun required only fix(config): clone catalog metadata before defaults #126123's reviewed one-line current-main startup fix temporarily. That line was removed after proof and is not part of this PR; the worktree is clean.
  • Full production typecheck, test typecheck, type-aware lint, check-changed, build, formatting, and diff checks pass.
  • Exact-head CI is green: https://github.com/openclaw/openclaw/actions/runs/32207823671
  • Fresh branch autoreview is clean with no accepted/actionable findings.

ClawSweeper's requested scope repair, actual dispatch regression, focused suites, and QA rerun are all applied; no rank-up move was skipped.

@steipete
steipete merged commit feda957 into main Aug 19, 2026
245 checks passed
@steipete
steipete deleted the steipete/fix-subagent-completion-qa-binding branch August 19, 2026 02:48
@steipete

Copy link
Copy Markdown
Contributor Author

Merged via squash.

steipete added a commit that referenced this pull request Aug 19, 2026
The vi.mock of resolveGatewayModelSupportsImages in
server.chat.gateway-server-chat.test.ts was added by #123847 as an
isolation workaround while the gateway shard's chat failures were
unexplained. The producers are fixed on main (#126183 for the
root-work drain race; #126062/#125946/#126113 for detached completion
binding), and the exact #126030 shard invocation is green with the
mask removed (5/5 on 95ac5b2, 2/2 on this head), so the mask now
only hides the real capability-resolution path from the suite.
steipete added a commit that referenced this pull request Aug 19, 2026
* test(gateway): drop the chat image-capability mask

The vi.mock of resolveGatewayModelSupportsImages in
server.chat.gateway-server-chat.test.ts was added by #123847 as an
isolation workaround while the gateway shard's chat failures were
unexplained. The producers are fixed on main (#126183 for the
root-work drain race; #126062/#125946/#126113 for detached completion
binding), and the exact #126030 shard invocation is green with the
mask removed (5/5 on 95ac5b2, 2/2 on this head), so the mask now
only hides the real capability-resolution path from the suite.

* test(gateway): assert inline-image dispatch after mask removal

ClawSweeper P2 on #126217: the two image sends only asserted RPC success
and drain, so a silent false from the real capability resolver would
offload the images and the suite would stay green without proving the
discovered model's image capability. Capture the dispatch args and
assert both runs deliver exactly one inline image. Teeth check: with the
discovered model narrowed to text-only input, the assertion fails with
images undefined (offloaded).
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Aug 20, 2026
* fix(gateway): bind channel completion dispatch

* fix(plugin-sdk): scope harness completion dispatch

* test(agents): cover scoped completion dispatch
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Aug 20, 2026
* test(gateway): drop the chat image-capability mask

The vi.mock of resolveGatewayModelSupportsImages in
server.chat.gateway-server-chat.test.ts was added by openclaw#123847 as an
isolation workaround while the gateway shard's chat failures were
unexplained. The producers are fixed on main (openclaw#126183 for the
root-work drain race; openclaw#126062/openclaw#125946/openclaw#126113 for detached completion
binding), and the exact openclaw#126030 shard invocation is green with the
mask removed (5/5 on 534f1cb, 2/2 on this head), so the mask now
only hides the real capability-resolution path from the suite.

* test(gateway): assert inline-image dispatch after mask removal

ClawSweeper P2 on openclaw#126217: the two image sends only asserted RPC success
and drain, so a silent false from the real capability resolver would
offload the images and the suite would stay green without proving the
discovered model's image capability. Capture the dispatch args and
assert both runs deliver exactly one inline image. Teeth check: with the
discovered model narrowed to text-only input, the assertion fails with
images undefined (offloaded).
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

agents Agent runtime and tooling channel: qa-channel Channel integration: qa-channel gateway Gateway runtime maintainer Maintainer-authored PR merge-risk: 🚨 message-delivery 🚨 May drop, duplicate, misroute, suppress, or wrongly target messages. 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.

QA: subagent completion direct fallback loses Gateway binding

1 participant