Skip to content

fix(acp): bound ACP threads fail to dispatch under explicit ownership - #146898

Open
vixenclawsastraagent wants to merge 5 commits into
openclaw:mainfrom
vixenclawsastraagent:fix/146365-acp-bound-dispatch-owner
Open

vixenclawsastraagent wants to merge 5 commits into
openclaw:mainfrom
vixenclawsastraagent:fix/146365-acp-bound-dispatch-owner

Conversation

@vixenclawsastraagent

@vixenclawsastraagent vixenclawsastraagent commented Sep 13, 2026 •

Copy link
Copy Markdown

Related: #146365

What Problem This Solves

Fixes: messages and /acp slash commands in a Discord thread created by /acp spawn <harness> fail with prepared reply dispatch runtime owner was not published for <harness> and are dead-lettered when agents.ownership is explicit and the harness id is not a configured agent.

User Impact

User impact: thread-bound ACP sessions on Discord dispatch again for both follow-up text and /acp slash commands, and the same runtime-binding route rewrite in Slack, Telegram, LINE, Feishu, iMessage, and Matrix now carries the configured owner too. No configuration, session-key, or persistence change; existing bindings keep working as-is.

Risk to note: this adds one public SDK export (isFreeAcpSessionKey on openclaw/plugin-sdk/routing, the same family as isAcpSessionKey) and raises the public export budget by one. MsgContext gains one optional field, RouteOwnerAgentId.

Overlap: #146651 fixes Discord text follow-ups in spawned child threads by keeping the source route for admission, and its body leaves the native slash-command path out. This PR fixes the same defect at the core route owner, so it also covers slash commands and the six other channels that apply the same rewrite. If #146651 lands first, this rebases onto it; the Discord message-path part reduces to forwarding the owner.

Why This Change Was Made

/acp spawn keys the ACP session as agent:<harness>:acp:<id>. Runtime conversation bindings rewrite the inbound route's session key and agent id to that key, and prepared reply dispatch publishes runtimes only for configured agents. Rather than renaming sessions or synthesizing a fallback owner, the binding rewrite now records the configured channel route agent as ownerAgentId on the route (only for free ACP keys, never for acp:binding: keys), the shared inbound context builder carries it as RouteOwnerAgentId, and reply dispatch prefers it for the published-runtime lookup when the session key itself is a free ACP key. Storage, transcript, and ACP execution keep the harness key's scope, which is why the session-store path and SQLite scope checks stay consistent.

Evidence

  • New regression in dispatch-from-config.lifecycle.test.ts fails on main with unexpected prepared reply dispatch owner opencode and passes on this head; it asserts the published lookup uses main while the store path, ensureSession, and transcript stay with the harness key. Core routing, context builder, session-key, Discord route/preflight/native-command/context tests added; 281 focused tests pass.
  • pnpm test:extension for discord, slack, telegram, line, feishu, imessage, matrix: all green (272/159/1/67/103/58/35 files).
  • pnpm test:contracts: 4 suites green (227 + 45 + 196 + 32 tests).
  • node scripts/check-changed.mjs: passes end to end (formatting, core/extension/test typechecks, lint, dead-export scan, import cycles, plugin boundaries, SDK export sync and surface budget, doctor contract guards).
  • pnpm build: passes (exit 0).
  • pnpm plugin-sdk:surface:check: passes after the +1 budget line. scripts/plugin-sdk-api-diff.mts --base main --head HEAD: 1 export added (isFreeAcpSessionKey), 9 reachable declarations changed by optional fields, 0 removed. pnpm docs:check-mdx passes.
  • Repository autoreview (--mode branch --base main --engine claude --max-priority P1): scoped-clean, no P0/P1 findings.
  • CI note: the CodeQL Critical Quality jobs completed analysis but failed at the SARIF upload step on both runs (09:12 and 09:29 UTC) during the GitHub incident opened 2026-09-13 09:16 UTC (elevated error rates on authorization endpoints). A fork PR cannot re-run jobs; I will retrigger once the incident is resolved.
  • Not run: live Discord/Telegram proof. The reported failure was observed live on 2026.9.3 (issue logs); this branch was not exercised against a live Gateway. Slack --bind here, Telegram topics, and the other channels are covered by unit tests only.
Source chain (main @ 17f385e; branch rebased onto 7ad2d15, no overlapping upstream changes)
  1. src/auto-reply/reply/commands-acp/lifecycle.ts mints agent:${spawn.agentId}:acp:${uuid}.
  2. src/channels/plugins/binding-routing.ts (resolveRuntimeConversationBindingRoute) and extensions/discord/src/monitor/route-resolution.ts (resolveDiscordEffectiveRoute) rewrite sessionKey/agentId to the bound key.
  3. src/auto-reply/reply/dispatch-from-config.gather.ts resolves the dispatch owner from ctx.SessionKey, which is already the harness key, so loadPublishedGatewayReplyDispatchRuntime throws.

Test plan

Pre-merge

  • Regression test fails on main, passes on this head (see Evidence)
  • Focused core + Discord suites, seven extension lanes, contract suites
  • node scripts/check-changed.mjs passes
  • pnpm build passes
  • Repository autoreview: scoped-clean
  • Live Discord proof: Not run (no isolated Gateway with a spare Discord bot token available to the author)

Post-merge

@clawsweeper

clawsweeper Bot commented Sep 13, 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.

Scott Clone added 5 commits September 13, 2026 17:25
Free ACP session keys (agent:<harness>:acp:<id>) name an external harness, not a configured agent. Runtime conversation bindings now record the configured channel route agent as ownerAgentId, channel contexts carry it as RouteOwnerAgentId, and prepared reply dispatch uses it when the session key itself is the bound harness key. Session storage and ACP execution keep the harness key's scope.
Discord thread and native slash-command routing replace the route with the bound free ACP harness key. Record the configured channel agent as ownerAgentId on the effective route and pass it into message and native-command contexts as RouteOwnerAgentId so bound threads dispatch under a published runtime instead of failing with 'prepared reply dispatch runtime owner was not published for <harness>'.
Slack, Telegram, LINE, Feishu, iMessage, and Matrix apply the same runtime conversation binding rewrite as Discord, so a bound free ACP session would lose its configured dispatch owner the same way. Forward the route's ownerAgentId into the shared inbound context builder in each channel.
Discord's effective-route rewrite needs the canonical free ACP harness key classifier from openclaw/plugin-sdk/routing, alongside the existing isAcpSessionKey and isSubagentSessionKey family. Raise the public export and callable budgets by one each.
@vixenclawsastraagent
vixenclawsastraagent force-pushed the fix/146365-acp-bound-dispatch-owner branch from 71b9b96 to a8145ed Compare September 13, 2026 09:26
@clawsweeper clawsweeper Bot added P1 High-priority user-facing bug, regression, or broken workflow. merge-risk: 🚨 compatibility 🚨 May break existing users, config, migrations, defaults, or upgrade paths. 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 Sep 13, 2026
@clawsweeper

clawsweeper Bot commented Sep 13, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: needs real behavior proof before merge.

What this changes

Preserves the configured chat agent as the reply-dispatch owner for conversations bound to an external ACP coding session across seven channels.

Review scores

Measure Result What it means
Overall readiness 🦪 silver shellfish (2/6) The repair has useful regression coverage, but mocked proof and unresolved cross-agent authority coverage limit merge confidence.
Proof confidence 🦪 silver shellfish (2/6) Real behavior proof is necessary before merge. See Before merge.
Patch quality 🦐 gold shrimp (3/6) No actionable review findings were identified.

Merge readiness

⛔ Blocked before merge - 6 items remain

This PR addresses a source-supported dispatch failure that remains on current main. It retains useful slash-command and multi-channel coverage beyond the related Discord PR, but existing proof and integration blockers remain unresolved.

Priority: P1
Reviewed head: a8145edc55d79471514252ec160658ef4233dab0
Owner decision: Required. See Decision needed.

Decision needed

  • Question: Should this repair expose isFreeAcpSessionKey and optional dispatch-owner fields through the SDK, or use a narrower existing binding contract?
  • Recommendation: Review the shared owner contract: Accept the additive contract only after integrating it with current main’s canonical binding projector and documenting its scope.
  • Why: The bug is established, but the permanent public routing contract is an owner decision that the supplied discussion has not settled.

Before merge

  • Add real behavior proof - Authority-chain proof required: the changed binding-to-dispatch path selects the configured runtime while retaining the ACP target, but available tests substitute runtime publication and harness execution. Add after-fix Discord text/native-command and Telegram Test Server evidence, including a pre-existing binding, an unauthorized sender, and removal/reassignment rejected before harness I/O. Redacted logs or terminal traces count; redact private identifiers, endpoints, and credentials. Update the PR body to trigger review, or ask a maintainer for @clawsweeper re-review. No stored-data contract change was identified.
  • Resolve merge risk - The conflicting branch must integrate with current main’s shared binding inspection helper so synchronous and asynchronous routing carry the same owner fact and retain binding revalidation.
  • Resolve merge risk - The added public SDK classifier and owner-context contract still require owner acceptance or a narrower existing-contract implementation.
  • Resolve merge risk - The cross-agent runtime handoff lacks final-effect evidence that unauthorized senders and removed or reassigned bindings are rejected before harness I/O.
  • Complete next step - Resolve conflicts through current main’s shared binding projector, obtain SDK acceptance, and supply after-fix behavior and final-effect authority proof before merge.
  • Resolve maintainer decision - Resolve the maintainer decision shown above before merge.

Findings

None.

Agent review details

How this fits together

Channel routing turns incoming messages and commands into session context. Reply dispatch needs a configured OpenClaw agent’s runtime, while ACP execution and transcripts retain the external harness’s session identity.

flowchart LR
  A[Channel message or command] --> B[Configured chat route]
  B --> C[Conversation binding]
  C --> D[Dispatch owner and ACP target]
  D --> E[Configured reply runtime]
  E --> F[ACP harness execution]
  F --> G[Reply to originating chat]
Loading

Technical review

Best possible solution:

Use one shared binding projector to preserve the configured dispatch owner and harness session identity, with an accepted SDK contract and verified behavior for existing bindings.

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

Yes, from source: bind a conversation to an ACP harness absent from configured agents, then dispatch a follow-up under explicit ownership; current main requests the harness’s unpublished runtime. This review did not execute that path.

Is this the best way to solve the issue?

The owner-versus-target separation is appropriate, but the branch needs adaptation to current main’s canonical projector and acceptance of its public SDK surface before the implementation can be endorsed for merge.

AGENTS.md: found and applied where relevant.

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

Merge-risk options

Maintainer options:

  1. Integrate and prove the owner handoff (recommended)
    Resolve conflicts through the shared projector, settle the SDK contract, and demonstrate allowed and revoked-binding cases through final harness I/O.
  2. Coordinate narrower repairs
    Coordinate with the related Discord work while preserving this PR’s distinct native-command and other-channel coverage.

Security

None.

Evidence

What I checked:

  • Pinned introduced change: Reviewed the merge-base-to-head delta, including channel propagation, dispatch selection, classifier, Doctor reuse, SDK export, documentation, and regression tests. The actual checkout and original PR head are a8145ed; no pinned test merge is available. (a8145edc55d7)
  • Current main still selects the harness owner: Current main derives the published reply-runtime owner from the source session or session agent. Runtime binding projection still rewrites that session and agent to the ACP target, without the proposed configured-owner handoff. (src/auto-reply/reply/dispatch-from-config.gather.ts:426, 12517a0fd2d9)
  • Current binding projection owner: Current main centralizes projection in inspectRuntimeConversationBindingRoute, used by synchronous and asynchronous resolution. The branch modifies the older resolver directly. The October 4 comment independently requests integration with the inspection helper: fix(acp): bound ACP threads fail to dispatch under explicit ownership #146898 (comment). (src/channels/plugins/binding-routing.ts:143, 12517a0fd2d9)
  • Proof remains supplemental: The added regression checks configured-owner lookup and harness-scoped storage/execution, but substitutes the published runtime, session stores, binding service, and ACP backend. The captured PR body explicitly says no after-fix live Gateway, Discord, or Telegram run occurred. The prior review’s two rank-up moves remain applicable. (src/auto-reply/reply/dispatch-from-config.abort-and-dedupe.test-utils.ts:1224, a8145edc55d7)
  • Authority-bearing runtime selection: RouteOwnerAgentId now selects a different configured runtime, workspace, and inbound plugin registry while execution remains harness-scoped. Existing guards were inspected, but the supplied evidence does not establish rejection of an unauthorized sender or a removed/reassigned binding before harness I/O on this changed path. (src/auto-reply/reply/dispatch-from-config.gather.ts:424, a8145edc55d7)
  • Public SDK expansion: The branch exports isFreeAcpSessionKey and adds optional owner facts to routing/context contracts. Its body acknowledges the expansion; no SDK-owner acceptance appears in the supplied discussion. Scoped SDK policy requires deliberate, aligned public contracts. (src/plugin-sdk/routing.ts:20, a8145edc55d7)

PR surface

Source +68, Tests +335, Docs +1, Other +2. Total +406 across 30 files.

View PR surface stats
Area Files Added Removed Net
Source 20 76 8 +68
Tests 8 335 0 +335
Docs 1 1 0 +1
Config 0 0 0 0
Generated 0 0 0 0
Other 1 4 2 +2
Total 30 416 10 +406

Review metrics

Metric Value Why it matters
Public SDK addition 1 callable export added The new classifier creates a supported public contract requiring explicit owner acceptance.
Production versus regression growth production net +68; tooling net +2; tests net +335 Production growth is explained by preserving and forwarding the dispatch owner; the larger regression checks identity separation but remains mocked proof.

Root-cause cluster

Relationship: fixed_by_candidate
Canonical: #146365
Summary: This PR is a candidate repair for the canonical dispatch-owner mismatch, with overlapping implementations that do not presently supersede it.

Members:

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

Labels

Label changes:

No label changes.

Label justifications:

  • P1: The linked reports establish unusable bound ACP workflows and failed channel messages under explicit ownership.
  • merge-risk: 🚨 compatibility: The patch expands the public SDK and changes dispatch-owner selection for existing runtime bindings.
  • merge-risk: 🚨 security-boundary: The new cross-agent runtime selection needs proof that sender denial and binding revocation remain effective before harness I/O.
  • rating: 🦪 silver shellfish: Overall readiness is 🦪 silver shellfish; proof is 🦪 silver shellfish and patch quality is 🦐 gold shrimp.
  • status: 📣 needs proof: The PR needs real behavior proof before ClawSweeper can clear the contributor ask.
  • proof: telegram-e2e: This PR needs Telegram Test Server proof with the repository E2E skill. The change restores visible replies and command availability in ACP-bound Telegram conversations, which requires scoped Test Server proof.

Rank-up moves

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

  • Integrate the owner fact into current main’s shared binding projector and settle the SDK contract.
  • Provide redacted after-fix Discord text/native-command and Telegram binding evidence, including a pre-existing binding.
  • Prove an unauthorized sender and a removed or reassigned binding cannot reach harness I/O.

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 (2 earlier review cycles)
  • reviewed 2026-09-13T09:57:47.518Z sha a8145ed :: needs real behavior proof before merge. :: none
  • reviewed 2026-09-24T00:14:42.040Z sha a8145ed :: needs real behavior proof before merge. :: none

Reviewed October 4, 2026, 9:25 AM ET / 13:25 UTC (Revision 3).

@jmar5439

jmar5439 commented Oct 4, 2026

Copy link
Copy Markdown

Could you please rebase this onto current main?
Runtime binding projection
has moved into inspectRuntimeConversationBindingRoute ( with the new async variant), so the
ownerAgentId hunk in
resolveRuntimeConversationBindingRoute
no longer applies to the shared path —
the owner fact needs to live in the
inspection helper for both sync and
async resolution. Once rebased, a quick
confirmation that pre-existing bindings
still dispatch would be great. Thanks!

This branch has not been deployed

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

Labels

merge-risk: 🚨 compatibility 🚨 May break existing users, config, migrations, defaults, or upgrade paths. merge-risk: 🚨 security-boundary 🚨 May affect sandboxing, authorization, credentials, or sensitive data. P1 High-priority user-facing bug, regression, or broken workflow. proof: telegram-e2e This PR needs Telegram Test Server proof with the repository E2E skill. 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.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants