Skip to content

fix(channels): keep ACP configured bindings authoritative over stale non-ACP runtime bindings - #140073

Closed
LiuwqGit wants to merge 1 commit into
openclaw:mainfrom
LiuwqGit:feat/issue-115354-acp-runtime-binding-priority
Closed

LiuwqGit wants to merge 1 commit into
openclaw:mainfrom
LiuwqGit:feat/issue-115354-acp-runtime-binding-priority

Conversation

@LiuwqGit

@LiuwqGit LiuwqGit commented Sep 6, 2026 •

Copy link
Copy Markdown
Contributor

AI-assisted: yes

Closes #115354

What Problem This Solves

  • Fixes an issue where users who have a per-peer ACP configured binding (e.g. {type: "acp", agentId: "claude", match: {channel: "feishu", peer: {kind: "direct", id: "ou_user_a"}}}) would have their messages routed to the wrong agent whenever a persisted non-ACP runtime binding record (stale agent:{agentId}:{channel}:{accountId}:direct:{peerId} rows previously written by catch-all bindings) also exists for that conversation — the stale runtime record silently nullified the configured ACP binding.
  • Related: fix(plugin-sdk): unbind conversation bindings on session deletion #133694 (closed — unbind-on-session-delete approach rejected in favor of a generation-aware design, tracked separately); per the source trace in the issue discussion, the catch-all creation path was already removed by fix(gateway): keep conversation delivery within agent bindings #126424, but the resolver-level precedence flaw remained latent for stale rows.
  • Trigger: any message from a conversation that matches both a configured ACP binding and a leftover generic non-ACP runtime binding record in the channel binding store.

Why This Change Was Made

  • Intended outcome: resolveRuntimeConversationBindingRoute now refuses to rewrite a route that a configured binding already claimed only for generic targetKind: "session" records that lack bind-API provenance. bindGenericCurrentConversation stamps metadata.bindingOrigin: "generic-bind-api" on every record it writes (including refreshes of legacy rows onto the same target — an explicit rebind is itself evidence of intent), so records created through the public SDK bind API keep their runtime precedence over configured bindings, while provenance-less generic session rows can only originate from the removed legacy catch-all writer (fix(gateway): keep conversation delivery within agent bindings #126424) and are treated as stale. Live runtime overrides keep their existing precedence: fresh generic SDK bindings, records targeting an ACP session (explicit /acp spawn --bind here), active subagent thread bindings (targetKind: "subagent" created by bindThreadForSubagentSpawn), and plugin-owned records. The guard sits next to the existing cron-run and plugin-owned checks. Callers that run configured-first (generic gateway ingress, Feishu, Telegram, iMessage, and now LINE) pass the configured-binding result through so the resolver can enforce this precedence.
  • Deliberately preserved behaviors: fresh generic bindings written through the public bind API still take precedence over configured bindings (addressing the review's SDK-compatibility finding — getSessionBindingService().bind() / bindGenericCurrentConversation() remain authoritative for intentional runtime binds); runtime records targeting an ACP session still take precedence; active subagent thread bindings still override a configured ACP binding (an intentionally spawned subagent keeps receiving follow-ups); plugin-owned records are still observed without rewriting; records whose target equals the configured target are still applied and touched; with no configured binding context the resolver behaves exactly as before.
  • LINE ingress previously resolved runtime bindings without the configured-binding result, so inbound messages followed a stale runtime record while Gateway conversation-send and queued-recovery authorization followed the configured ACP owner. LINE now feeds the configured route into the shared resolver (resolveLineConversationRoute), keeping ingress and delivery authorization on the same precedence at both boundaries.
  • Out of scope: Discord and Slack use channel-owned resolvers with intentionally different (runtime-first) precedence and are unchanged. Session-liveness/generation-aware unbinding of stale records (issue "Bug 2" direction) is a separate, larger design per the fix(plugin-sdk): unbind conversation bindings on session deletion #133694 discussion; this PR only stops stale generic rows from overriding configured bindings. Records created through the public bind API before this change carry no provenance and are therefore treated as stale; an intentional rebind through the same API restores their runtime precedence.
  • Highest-risk area: routing precedence between binding layers; mitigated by regression tests covering all guard branches (stale suppression, fresh-SDK override, ACP override, subagent override, matching-target apply), LINE ingress agreement tests, and gateway send/ownership tests that authorize the configured owner while rejecting the competing agent before any transport I/O, including queued-recovery after reassignment.

User Impact

  • Success criteria: a conversation that matches a configured ACP binding keeps routing to that binding's agent/session when a stale generic non-ACP runtime binding row exists for it; the ignored row is not touched (no liveness extension). Fresh SDK binds, explicit ACP runtime binds, active subagent thread bindings, and plugin-owned bindings behave exactly as before, and LINE ingress now selects the same owner that Gateway delivery authorization enforces.
  • What should reviewers focus on: src/channels/plugins/binding-routing.ts (guard next to the cron/plugin-owned checks, scoped to provenance-less generic targetKind: "session" records), src/plugins/conversation-binding-metadata.ts (bindingOrigin provenance constant and predicate), src/infra/outbound/current-conversation-bindings.ts (bindGenericCurrentConversation stamping provenance), extensions/line/src/bot-message-context.ts (resolveLineConversationRoute passing configuredBindingRoute), and the tests in src/channels/plugins/binding-routing.test.ts ("still lets a fresh generic bind-API runtime binding override the configured route"), src/infra/outbound/current-conversation-bindings.test.ts ("stamps bind-API provenance on every record it writes"), src/gateway/conversation-send-binding-precedence.test.ts (allowed delivery, competing agent rejected before transport, queued recovery after reassignment), and src/gateway/conversation-route-ownership.test.ts (configured owner eligible / competing agent denied; reassignment to a live subagent binding followed by the evaluator).

Evidence

  • Real environment tested: No live Feishu/Telegram/LINE credentials were available; verification is at the deterministic routing and delivery-authorization layer with real compiled config bindings, real registered channel binding adapters (LINE uses its real lineBindingsAdapter), a real per-agent conversation registry and delivery store for the send/queued-recovery boundary tests, and the real resolver/ownership chain (no mocks of the code under test; only the transport action is replaced) in an isolated worktree at commit 7b3178d (rebased onto the latest main).
  • Exact steps or commands run after this patch:
    # regression tests (RED for the new provenance case on the previous head 9a06ed9ce9f, GREEN after the fix)
    node scripts/run-vitest.mjs run src/channels/plugins/binding-routing.test.ts \
      src/infra/outbound/current-conversation-bindings.test.ts \
      src/gateway/conversation-send-binding-precedence.test.ts \
      src/gateway/conversation-route-ownership.test.ts \
      extensions/line/src/conversation-route.test.ts \
      extensions/imessage/src/conversation-route.test.ts
    # type-checked test shards covering every changed file
    node --import ./scripts/tsx.mjs scripts/run-tsgo-core-test-shards.mts --changed-paths-json '[<6 changed files>]'
    # format + lint + same-directory tests for all changed files + tsgo:core
    skills/fix-pr/scripts/validate.sh <changed files>
  • Evidence after fix:
    $ node scripts/run-vitest.mjs run src/channels/plugins/binding-routing.test.ts
     ✯ |channels| binding-routing > keeps a configured binding route when a non-ACP runtime binding targets a different session  (stale provenance-less row ignored)
     ✯ |channels| binding-routing > still lets a runtime binding that targets an ACP session override the configured route
     ✯ |channels| binding-routing > still lets a live subagent runtime binding override the configured route  (targetKind "subagent" keeps runtime precedence)
     ✯ |channels| binding-routing > still lets a fresh generic bind-API runtime binding override the configured route  (provenance-stamped SDK bind keeps runtime precedence)
     ✯ |channels| binding-routing > still applies a non-ACP runtime binding that matches the configured target
         Tests  15 passed (15)
    
    $ node scripts/run-vitest.mjs run src/infra/outbound/current-conversation-bindings.test.ts
     ✯ |infra| generic current-conversation bindings > stamps bind-API provenance on every record it writes  (new binds stamped; rebinding a legacy row stamps it too)
         (full suite green)
    
    $ node scripts/run-vitest.mjs run src/gateway/conversation-send-binding-precedence.test.ts
     ✯ |gateway-core| ... > delivers for the configured ACP owner when only a stale generic runtime record exists  (send authorized, transport invoked once)
     ✯ |gateway-core| ... > rejects the competing agent before any transport attempt  (ConversationInputError, transport never invoked)
     ✯ |gateway-core| ... > follows a live subagent reassignment through queued delivery recovery  (reassigned owner recovers, previous owner throws PlatformMessageNotDispatchedError)
         Tests  3 passed (3)
    
    $ node --import ./scripts/tsx.mjs scripts/run-tsgo-core-test-shards.mts --changed-paths-json '[...]'
    [check:changed] core test graphs: agents-root, agents-other, agents-tools, gateway-root, gateway-other, infra, commands, plugins-platform, config-cli, messaging, services, other, ui-pages, ui-e2e, ui-other, packages
    (exit 0 — all 16 affected graphs)
    
    $ skills/fix-pr/scripts/validate.sh <changed files>
    [test] passed 3 Vitest shards in 33.11s
    [validate] 4/4 tsgo:core 类型检查
    [validate] 全部通过 ✅
    
  • Observed result after fix: a stale generic non-ACP runtime binding record no longer redirects a conversation that a configured ACP binding claims (message routes to the configured ACP agent, ignored row untouched); a fresh binding written through the public bind API keeps routing the conversation to its intentional target; a live subagent thread binding keeps receiving follow-ups; and LINE ingress selects the same owner that the Gateway send boundary (entry eligibility + pre-transport delivery authorization) and queued-recovery boundary enforce — the approved owner is eligible and delivered while the competing agent is denied before any transport I/O, and after reassignment to a live subagent binding the reassigned owner's queued operation recovers while the previous owner's is rejected.
  • Before evidence (optional, visual changes encouraged): on the previous head (9a06ed9ce9f) the new provenance regression test failed — a fresh generic bind-API binding was suppressed (touch never called; the configured route won) — reproducing the review's SDK-compatibility finding. On the head before that (953eef2b) the subagent/LINE/ownership regression tests failed as previously documented. On unpatched origin/main the original end-to-end test failed with expected 'main' to be 'codex' — the stale row routed the conversation to agent main and the configured ACP binding was never honored.
  • What was not tested: live message delivery through a real Feishu/Telegram/LINE/iMessage account — no credentials are available in this environment; the Telegram Test Server E2E (qa-lab live transport with a Convex-leased real-user driver, proof: telegram-e2e) requires maintainer/CI Convex credentials that are not available to contributors, so real Telegram routing proof cannot be produced here. Discord/Slack channel-owned resolvers (unchanged by design), and the generation-aware stale-record cleanup direction discussed in fix(plugin-sdk): unbind conversation bindings on session deletion #133694 are also not covered. CI lanes (changed-project tests, full test-type check) pending on GitHub Actions.
  • Proof tier: L2
  • Proof limitations: Routing and delivery-authorization behavior is proven deterministically at the resolver/ingress/send/queued-recovery layers (real gateway send and recovery authorization chains, real per-agent conversation registry and delivery stores, transport replaced) rather than through a live channel account.
  • Review state: Awaiting CI + maintainer review

@clawsweeper

clawsweeper Bot commented Sep 6, 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 channel: imessage Channel integration: imessage channel: telegram Channel integration: telegram gateway Gateway runtime channel: feishu Channel integration: feishu size: S labels Sep 6, 2026
@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. merge-risk: 🚨 message-delivery 🚨 May drop, duplicate, misroute, suppress, or wrongly target messages. merge-risk: 🚨 security-boundary 🚨 May affect sandboxing, authorization, credentials, or sensitive data. 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. labels Sep 6, 2026
@clawsweeper

clawsweeper Bot commented Sep 6, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: needs real behavior proof before merge. Reviewed September 6, 2026, 10:29 AM ET / 14:29 UTC.

ClawSweeper review

What this changes

The PR changes conversation routing to favor configured ACP coding-agent bindings over unmarked session bindings, adds provenance to generic binding writes, and aligns LINE ingress with Gateway ownership checks.

Regression provenance

Possible regression — suspected (reviewed change). No predecessor PR is attributed.

Merge readiness

⛔ Blocked before merge - 8 items remain

The fix remains necessary on current main. LINE routing consistency is repaired, but the earlier SDK compatibility concern remains partly unresolved for adapter-backed and pre-upgrade bindings.

Priority: P2
Reviewed head: 7b3178d6445d3d349c8f681f32a672e3d71ad788
Owner decision: Required. See Decision needed.

Review scores

Measure Result What it means
Overall readiness 🦪 silver shellfish (2/6) Useful routing consolidation and expanded regression coverage remain blocked by incomplete SDK compatibility and final-delivery proof.
Proof confidence 🦪 silver shellfish (2/6) Needs real behavior proof before merge: Authority-chain proof required: the inspected head-specific evidence improves entry authorization coverage, but the send mock bypasses onDeliveryAttempt and queued recovery only invokes its checker. Demonstrate the real dispatch boundary for allowed and competing agents using fresh adapter and retained bindings, including reassignment before recovery; Telegram runtime proof also remains outstanding. The unavailable body tail is not treated as absent evidence. After adding proof, update the PR body; ClawSweeper should re-review automatically. If it does not, the PR author or someone with repository write access can comment @clawsweeper re-review.
Patch quality 🦐 gold shrimp (3/6) Security review found an item that needs attention.

Verification

Check Result Evidence
Real behavior Needs proof Needs real behavior proof before merge: Authority-chain proof required: the inspected head-specific evidence improves entry authorization coverage, but the send mock bypasses onDeliveryAttempt and queued recovery only invokes its checker. Demonstrate the real dispatch boundary for allowed and competing agents using fresh adapter and retained bindings, including reassignment before recovery; Telegram runtime proof also remains outstanding. The unavailable body tail is not treated as absent evidence. After adding proof, update the PR body; ClawSweeper should re-review automatically. If it does not, the PR author or someone with repository write access can comment @clawsweeper re-review.
Evidence reviewed 10 items Pinned introduced change: The inspected merge-base-to-head diff adds the provenance guard and stamps only the generic storage writer. Host-verified test-merge parents separately establish that unrelated base drift is not this PR's change.
Current main still applies runtime precedence: The fetched main resolver applies non-cron runtime bindings without the proposed configured-binding guard. The supplied merged ownership PR does not implement this remaining precedence repair.
SDK adapter writes bypass provenance: SessionBindingService.bind dispatches directly to adapter.bind when registered; only its fallback invokes bindGenericCurrentConversation. Feishu's adapter forwards input.metadata unchanged, and Telegram likewise persists the supplied metadata without adding bindingOrigin. Fresh explicit non-ACP session binds through these paths therefore still match the new stale-row guard.
Findings 2 actionable findings [P1] [P1] Preserve explicit bindings written through channel adapters
[P1] [P1] Preserve intentional bindings retained from released versions
Security Needs attention Intentional runtime ownership can be discarded: With a conflicting configured assignment, an unmarked explicit runtime binding is ignored and the configured agent becomes eligible for conversation delivery. Both current adapter writes and retained released bindings can have this shape; provenance absence is insufficient authority to transfer ownership.

How this fits together

Channel routing combines configured agent assignments with runtime conversation bindings to select a session. The Gateway reuses that selection to authorize conversation discovery, sends, and queued delivery recovery.

flowchart TD
  A[Incoming channel message] --> C[Binding precedence]
  B[Configured agent assignment] --> C
  D[Runtime conversation binding] --> C
  C --> E[Selected agent and session]
  E --> F[Gateway ownership check]
  F --> G[Allow or reject delivery]
Loading

Decision needed

Question Recommendation
How should existing unmarked SDK bindings retain their ownership while obsolete catch-all rows are retired? Preserve ambiguous existing bindings: Keep their current precedence until an accepted migration or explicit owner action identifies obsolete rows.

Why: The same persisted shape represents both legitimate released bindings and unwanted legacy rows; absence of the new marker cannot establish which interpretation is correct.

Before merge

  • Add real behavior proof - Needs real behavior proof before merge: Authority-chain proof required: the inspected head-specific evidence improves entry authorization coverage, but the send mock bypasses onDeliveryAttempt and queued recovery only invokes its checker. Demonstrate the real dispatch boundary for allowed and competing agents using fresh adapter and retained bindings, including reassignment before recovery; Telegram runtime proof also remains outstanding. The unavailable body tail is not treated as absent evidence. After adding proof, update the PR body; ClawSweeper should re-review automatically. If it does not, the PR author or someone with repository write access can comment @clawsweeper re-review.
  • [P1] Preserve explicit bindings written through channel adapters (P1) - The prior SDK finding is only partially fixed. SessionBindingService.bind() calls adapter.bind() when an adapter exists, bypassing this writer. Feishu and Telegram adapters preserve caller metadata without adding bindingOrigin, so a fresh intentional targetKind: "session" bind to a non-ACP target is still suppressed when configured ACP routing matches. Messages and Gateway eligibility then switch to the configured agent. Establish provenance at the common explicit-bind boundary and preserve it through adapter projections; exercise the real service-to-adapter path.
  • [P1] Preserve intentional bindings retained from released versions (P1) - Missing provenance does not prove a catch-all origin: v2026.9.2's public generic bind API also writes active session records without this field. Upgrading with an intentional non-ACP runtime override therefore silently changes the selected agent and delivery authorization until the operator rebinds it, as the PR body acknowledges. Preserve ambiguous existing records or provide an owner-approved migration with upgrade coverage; stamping future writes alone cannot safely classify old rows.
  • Resolve security concern: Intentional runtime ownership can be discarded - With a conflicting configured assignment, an unmarked explicit runtime binding is ignored and the configured agent becomes eligible for conversation delivery. Both current adapter writes and retained released bindings can have this shape; provenance absence is insufficient authority to transfer ownership.
  • Resolve merge risk (P1) - Existing intentional SDK bindings can stop receiving messages after upgrade until an operator rebinds them; acceptance and a safe transition for that behavior are unresolved.
  • Resolve merge risk (P1) - Discarding an intentional runtime assignment can authorize the configured agent instead; available proof does not cover these competing-owner cases through final dispatch or queued recovery.
  • Complete next step (P2) - Resolve both binding compatibility findings and obtain approval for the retained-state transition, then add real delivery and Telegram proof. Redact credentials, IP addresses, phone numbers, and private endpoints. Updating the PR body should trigger another review; otherwise ask a maintainer to comment @clawsweeper re-review.
  • Resolve maintainer decision - Resolve the maintainer decision shown above before merge.

Findings

  • [P1] [P1] Preserve explicit bindings written through channel adapters — src/infra/outbound/current-conversation-bindings.ts:476-478
  • [P1] [P1] Preserve intentional bindings retained from released versions — src/channels/plugins/binding-routing.ts:185-190
  • [high] Intentional runtime ownership can be discarded — src/channels/plugins/binding-routing.ts:186
Agent review details

Security

Needs attention: The new stale-row classification can replace an intentional runtime owner with the configured agent at the Gateway authorization boundary.

PR surface

Source +93, Tests +776, Docs +9. Total +878 across 16 files.

View PR surface stats
Area Files Added Removed Net
Source 9 137 44 +93
Tests 6 777 1 +776
Docs 1 9 0 +9
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 16 923 45 +878

Review metrics

Metric Value Why it matters
Production versus test growth Production net +93 lines; tests net +776 lines Production growth primarily extracts LINE route resolution and adds provenance handling; the larger test expansion covers routing and ownership cases.
Persisted provenance 1 new metadata field; 1 of 2 service dispatch paths stamps it The adapter-backed branch bypasses the generic writer on which the new routing predicate depends.

Root-cause cluster

Relationship: fixed_by_candidate
Canonical: #115354
Summary: This PR is a candidate for the linked issue's precedence problem; session-generation cleanup remains separate.

Members:

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

Merge-risk options

Maintainer options:

  1. Complete binding provenance and upgrade handling (recommended)
    Cover adapter-backed writers and preserve ambiguous retained bindings under an approved compatibility rule before demonstrating delivery ownership.
  2. Pause the precedence change
    Keep the linked issue open while owners establish a reliable legacy-row classification.

Technical review

Best possible solution:

Preserve intentional runtime ownership across all binding producers and upgrades, with an owner-approved distinction for obsolete rows and consistent ingress and delivery enforcement.

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

Yes, from source: create a non-ACP session binding through a registered channel adapter alongside a conflicting configured ACP binding; the adapter omits the marker and the new resolver ignores the intentional assignment. This read-only review did not execute tests.

Is this the best way to solve the issue?

No, not yet: sharing precedence across ingress and delivery is appropriate, but stamping only the fallback writer and treating every unmarked retained row as obsolete does not preserve the SDK contract.

Full review comments:

  • [P1] [P1] Preserve explicit bindings written through channel adapters — src/infra/outbound/current-conversation-bindings.ts:476-478
    The prior SDK finding is only partially fixed. SessionBindingService.bind() calls adapter.bind() when an adapter exists, bypassing this writer. Feishu and Telegram adapters preserve caller metadata without adding bindingOrigin, so a fresh intentional targetKind: "session" bind to a non-ACP target is still suppressed when configured ACP routing matches. Messages and Gateway eligibility then switch to the configured agent. Establish provenance at the common explicit-bind boundary and preserve it through adapter projections; exercise the real service-to-adapter path.
    Confidence: 0.99
  • [P1] [P1] Preserve intentional bindings retained from released versions — src/channels/plugins/binding-routing.ts:185-190
    Missing provenance does not prove a catch-all origin: v2026.9.2's public generic bind API also writes active session records without this field. Upgrading with an intentional non-ACP runtime override therefore silently changes the selected agent and delivery authorization until the operator rebinds it, as the PR body acknowledges. Preserve ambiguous existing records or provide an owner-approved migration with upgrade coverage; stamping future writes alone cannot safely classify old rows.
    Confidence: 0.99

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 9ed5275a5956.

Labels

Label justifications:

  • P2: This is a bounded routing repair for conversations with conflicting configured and runtime bindings.
  • merge-risk: 🚨 compatibility: Released intentional bindings lack the new marker and lose precedence without a migration.
  • merge-risk: 🚨 message-delivery: Fresh adapter-backed bindings can be ignored, sending subsequent messages to a different agent.
  • merge-risk: 🚨 security-boundary: The changed precedence also selects which agent passes Gateway delivery authorization.
  • 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. Needs real behavior proof before merge: Authority-chain proof required: the inspected head-specific evidence improves entry authorization coverage, but the send mock bypasses onDeliveryAttempt and queued recovery only invokes its checker. Demonstrate the real dispatch boundary for allowed and competing agents using fresh adapter and retained bindings, including reassignment before recovery; Telegram runtime proof also remains outstanding. The unavailable body tail is not treated as absent evidence. After adding proof, update the PR body; ClawSweeper should re-review automatically. If it does not, the PR author or someone with repository write access can comment @clawsweeper re-review.
  • proof: telegram-e2e: This PR needs Telegram Test Server proof with the repository E2E skill. The selected responding agent and session can change for Telegram conversations, which is observable through a Test Server exchange.

Evidence

Security concerns:

  • [high] Intentional runtime ownership can be discarded — src/channels/plugins/binding-routing.ts:186
    With a conflicting configured assignment, an unmarked explicit runtime binding is ignored and the configured agent becomes eligible for conversation delivery. Both current adapter writes and retained released bindings can have this shape; provenance absence is insufficient authority to transfer ownership.
    Confidence: 0.98

What I checked:

  • Pinned introduced change: The inspected merge-base-to-head diff adds the provenance guard and stamps only the generic storage writer. Host-verified test-merge parents separately establish that unrelated base drift is not this PR's change. (src/channels/plugins/binding-routing.ts:184, 7b3178d6445d)
  • Current main still applies runtime precedence: The fetched main resolver applies non-cron runtime bindings without the proposed configured-binding guard. The supplied merged ownership PR does not implement this remaining precedence repair. (src/channels/plugins/binding-routing.ts:130, 9ed5275a5956)
  • SDK adapter writes bypass provenance: SessionBindingService.bind dispatches directly to adapter.bind when registered; only its fallback invokes bindGenericCurrentConversation. Feishu's adapter forwards input.metadata unchanged, and Telegram likewise persists the supplied metadata without adding bindingOrigin. Fresh explicit non-ACP session binds through these paths therefore still match the new stale-row guard. (src/infra/outbound/session-binding-service.ts:291, 7b3178d6445d)
  • Concrete channel adapter producer: The Telegram adapter accepts a session target, constructs a record from input.metadata, and persists it. This is a current producer of intentional unmarked bindings, not a removed legacy writer. (extensions/telegram/src/thread-bindings.ts:573, 7b3178d6445d)
  • Released bindings lack the new marker: In v2026.9.2, the generic bind API writes active session records with caller metadata and lastActivityAt, without bindingOrigin. An intentional binding retained from that release is indistinguishable by this predicate from the stale rows being suppressed. (src/infra/outbound/current-conversation-bindings.ts:430, 3928bad9badf)
  • Persistence compatibility checkpoint: Repository storage guidance explicitly requires accepted design discussion for a second interpretation of existing durable data. The PR acknowledges that old intentional SDK bindings lose precedence until rebound; supplied discussion contains no maintainer acceptance of that transition. Public docs: docs/reference/database-schemas.md. (docs/reference/database-schemas.md:430, 7b3178d6445d)

Likely related people:

  • Josh Avant: Raw commit 0b85966 adds src/gateway/conversation-route-ownership.ts:136 relative to its recorded parents. This identifies author metadata, not feature responsibility or a PR merger. (role: source-line author; confidence: high; commits: 0b8596607208; files: src/gateway/conversation-route-ownership.ts)
  • Peter Steinberger: Suggested for follow-up; no historical authorship or introduction is verified. (role: unverified routing candidate; confidence: low)

Rank-up moves

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

  • Preserve explicit bindings through adapter-backed writes and an approved upgrade policy for existing unmarked records.
  • Show allowed delivery and rejection of competing or reassigned agents through production dispatch and queued recovery, including the final attempt check.
  • Add redacted Telegram Test Server evidence showing the selected agent and preserved runtime overrides; terminal output or diagnostic recordings are suitable.

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-09-06T11:36:43.465Z sha 953eef2b392e379a81fd2dc7e51095a24635f9ef :: needs real behavior proof before merge. :: [P1] Preserve intentional live non-ACP bindings | [P1] Keep LINE ingress and Gateway ownership precedence consistent
  • reviewed 2026-09-06T11:47:05.123Z sha 953eef2b392e379a81fd2dc7e51095a24635f9ef :: needs real behavior proof before merge. :: [P1] Preserve intentional live non-ACP bindings | [P1] Keep LINE ingress and Gateway ownership precedence consistent
  • reviewed 2026-09-06T12:34:14.591Z sha 513d78f1d9cd625cc15235f1e26d166bb484ca13 :: needs real behavior proof before merge. :: none
  • reviewed 2026-09-06T13:09:32.820Z sha 9a06ed9ce9f08d25c1520772d31b074e4af53bea :: needs real behavior proof before merge. :: [P1] [P1] Distinguish obsolete rows from fresh SDK session bindings

@LiuwqGit LiuwqGit closed this Sep 6, 2026
@LiuwqGit LiuwqGit reopened this Sep 6, 2026
@LiuwqGit

LiuwqGit commented Sep 6, 2026

Copy link
Copy Markdown
Contributor Author

Note on the failing preflight/ci-gate checks: the job fails with GitHub annotation Job outputs exceed 1,048,576 bytes — the PR CI manifest's job outputs (test-shard matrices derived from the changed-file closure) exceed GitHub's 1 MB job-output cap. This appears to be a CI-infrastructure limitation independent of this branch's code: #140067 (src/infra + src/node-host only, no extensions) fails with the identical annotation at the same time, while other PRs created minutes apart pass. A close/reopen retrigger reproduced the same deterministic failure, and I have no admin rights to re-run. Every locally runnable gate on this branch is green: targeted vitest suites for all changed areas, validate.sh (oxfmt + oxlint + same-directory tests + tsgo:core), and the affected test-type shards (plugins-platform, messaging, gateway-root, gateway-other, extensions-test) all pass.

@LiuwqGit
LiuwqGit force-pushed the feat/issue-115354-acp-runtime-binding-priority branch from 953eef2 to 513d78f Compare September 6, 2026 12:27
@openclaw-barnacle openclaw-barnacle Bot added channel: line Channel integration: line size: L and removed size: S labels Sep 6, 2026
@LiuwqGit

LiuwqGit commented Sep 6, 2026

Copy link
Copy Markdown
Contributor Author

Follow-up addressing both P1 findings from the ClawSweeper review of 953eef2b (now at 513d78f1d9c, rebased on latest main):

[P1] Preserve intentional live non-ACP bindings — The guard in resolveRuntimeConversationBindingRoute is now scoped to generic targetKind: "session" records with a non-ACP target. That record shape has no live producer since the legacy catch-all writer was removed (#126424): all current non-plugin, non-ACP runtime binds are either ACP-session targets (explicit /acp spawn --bind here) or targetKind: "subagent" thread bindings created by bindThreadForSubagentSpawn. Active subagent bindings therefore keep their runtime precedence over configured ACP bindings (a spawned subagent keeps receiving follow-ups), and only the stale generic rows are suppressed. Covered by a new resolver regression test plus ingress-level tests.

[P1] Keep LINE ingress and Gateway ownership precedence consistent — LINE ingress now resolves its route through resolveLineConversationRoute, which passes the configured-binding result into the shared runtime resolver exactly like the Gateway generic ownership evaluator. Ingress and delivery authorization (conversation-send, delivery attempts, queued recovery all reuse the same evaluator) now select the same owner for both configured and runtime targets. Covered by LINE route tests plus new gateway ownership tests: configured owner eligible / competing agent denied with only a stale generic record, and a live subagent reassignment followed (configured owner denied, subagent owner eligible).

Authority-chain evidence (still deterministic, L2 — no live channel credentials available): the new gateway tests exercise the real evaluator that gates delivery before any transport I/O (approved owner succeeds, competing agent rejected), and LINE ingress agreement is asserted against the same precedence inputs. Real Telegram Test Server proof remains outstanding (no credentials locally); noted in the PR body as a pending limitation.

Regarding the failing preflight/ci-gate checks: both fail with the CI-manifest annotation Job outputs exceed 1,048,576 bytes — a GitHub job-output size limit hit by the preflight manifest, also reproduced on unrelated #140067 (src/infra + src/node-host only). This appears to be CI-infrastructure-level and not fixable from this branch; every locally runnable gate (targeted vitest suites for all changed areas, validate.sh with tsgo:core, affected test-type shards) is green.

@LiuwqGit
LiuwqGit force-pushed the feat/issue-115354-acp-runtime-binding-priority branch from 513d78f to 9a06ed9 Compare September 6, 2026 13:03
…non-ACP runtime bindings

Conversations that match a configured ACP binding could still be routed
through a persisted non-ACP runtime binding record (e.g. stale rows written
by legacy catch-all bindings), sending messages to the wrong agent.

The configured-binding guard in resolveRuntimeConversationBindingRoute now
suppresses only generic session-kind records that lack bind-API provenance:
bindGenericCurrentConversation stamps bindingOrigin metadata on every record
it writes (including refreshes of legacy rows), so intentional SDK bindings
keep their runtime precedence while provenance-less rows can no longer
nullify a configured binding. Records targeting an ACP session (explicit
/acp spawn binds), active subagent thread bindings, and plugin-owned records
keep their existing precedence.

LINE ingress resolved runtime bindings without the configured-binding result,
so inbound messages still followed a stale runtime record while Gateway
conversation-send and queued-recovery authorization followed the configured
ACP owner. LINE now passes the configured route into the shared resolver,
keeping ingress and delivery authorization on the same precedence.

Fixes openclaw#115354
@LiuwqGit
LiuwqGit force-pushed the feat/issue-115354-acp-runtime-binding-priority branch from 9a06ed9 to 7b3178d Compare September 6, 2026 14:22
@openclaw-barnacle openclaw-barnacle Bot added the docs Improvements or additions to documentation label Sep 6, 2026
@LiuwqGit

LiuwqGit commented Sep 6, 2026

Copy link
Copy Markdown
Contributor Author

Follow-up for the ClawSweeper review of 9a06ed9 — addressed the P1 SDK-compatibility finding, the security concern, and the delivery-boundary proof gap in 7b3178d (rebased onto latest main).

[P1] Distinguish obsolete rows from fresh SDK session bindings — fixed via bind-API provenance. bindGenericCurrentConversation now stamps metadata.bindingOrigin: "generic-bind-api" on every record it writes, including refreshes of a legacy row onto the same target (an explicit rebind is itself evidence of intent). The configured-binding guard now suppresses only generic targetKind: "session" records lacking that provenance — a shape that can only originate from the removed legacy catch-all writer. Fresh generic bindings created through getSessionBindingService().bind() / bindGenericCurrentConversation() keep their runtime precedence, so intentional plugin/SDK binds are no longer silently discarded, per the recommended "preserve explicit runtime bindings" direction. Documented in docs/plugins/sdk-channel-plugins.md. Transition note (also in the PR body): records created through the bind API before this change carry no provenance and are treated as stale; an intentional rebind restores their precedence.

Security concern / delivery-boundary proof — added src/gateway/conversation-send-binding-precedence.test.ts. These run the real runGatewayConversationSend authorization chain (entry assertConversationRouteEligibleForAgent + pre-transport assertConversationDeliveryAttemptAuthorized) and the real queued-recovery boundary (assertQueuedConversationDeliveryAttemptAuthorized) with a real per-agent conversation registry and delivery store — only the transport action is replaced:

  1. Allowed delivery: with only a stale generic runtime record present, the configured ACP owner's send is authorized and reaches the transport exactly once.
  2. Competing agent rejected before transport: the catch-all agent's send throws ConversationInputError ("not available to this agent") with zero transport invocations.
  3. Queued recovery after reassignment: after the conversation is reassigned to a live subagent thread binding, the reassigned owner's queued operation recovers while the previous owner's queued recovery throws PlatformMessageNotDispatchedError.

Regression coverage added: the new provenance case was RED on the previous head (fresh bind suppressed — reproducing the finding) and is GREEN now; current-conversation-bindings.test.ts covers provenance stamping and legacy-row rebinding; the resolver suite covers all guard branches (stale suppression, fresh-SDK override, ACP override, subagent override, matching-target apply).

Telegram Test Server proof (proof: telegram-e2e): the qa-lab Telegram live transport requires a Convex-leased real-user driver with maintainer/CI credentials that are not available in this environment, so a real Telegram routing proof cannot be produced here — noted honestly under "What was not tested" in the PR body. The deterministic routing/ownership chain that governs which agent receives a Telegram conversation (generic gateway ingress passes the configured route through extensions/telegram/src/conversation-route.ts) is covered by the tests above.

CI lanes are pending on GitHub Actions for the new head.

@LiuwqGit

LiuwqGit commented Sep 7, 2026

Copy link
Copy Markdown
Contributor Author

Closing for now: the remaining CI failure (checks-node-compact-large-9 / src/transcripts/status.producer.test.ts) is a flaky test unrelated to this diff — the file has zero overlap with the changes here and passes locally. Will revisit if this resurfaces. Thanks for the reviews.

@LiuwqGit LiuwqGit closed this Sep 7, 2026
@LiuwqGit
LiuwqGit deleted the feat/issue-115354-acp-runtime-binding-priority branch September 22, 2026 14:47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

channel: feishu Channel integration: feishu channel: imessage Channel integration: imessage channel: line Channel integration: line channel: telegram Channel integration: telegram docs Improvements or additions to documentation gateway Gateway runtime merge-risk: 🚨 compatibility 🚨 May break existing users, config, migrations, defaults, or upgrade paths. merge-risk: 🚨 message-delivery 🚨 May drop, duplicate, misroute, suppress, or wrongly target messages. merge-risk: 🚨 security-boundary 🚨 May affect sandboxing, authorization, credentials, or sensitive data. P2 Normal backlog priority with limited blast radius. 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. size: L 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.

Catch-all binding creates stale runtime bindings that override ACP configured bindings

1 participant