Skip to content

fix(channels): resolve bound agents before ordinary selection - #159533

Merged
steipete merged 4 commits into
mainfrom
fix/live2-discord-slack-binding-first
Sep 27, 2026
Merged

steipete merged 4 commits into
mainfrom
fix/live2-discord-slack-binding-first

Conversation

@steipete

Copy link
Copy Markdown
Contributor

What Problem This Solves

Discord (extensions/discord/src/monitor/message-handler.routing-preflight.ts) and Slack (extensions/slack/src/monitor/message-handler/prepare-routing.ts) resolved the ordinary agent route before consulting conversation bindings. When ordinary selection was ambiguous, an inbound message in a conversation that was already bound to a specific agent session failed with AGENT_SELECTION_REQUIRED, even though the binding answered the question. The same ordering problem applied to Slack thread and base-channel bindings. From the operator's side, a bound conversation stopped routing whenever more than one agent could match.

Why This Change Was Made

The shared helper src/channels/plugins/binding-routing.ts required a completed route as input. That forced every channel to finish ordinary selection before the binding could win. The canonical fix belongs to the helper: inspectRuntimeConversationBindingRoute and resolveRuntimeConversationBindingRoute now accept exactly one of these (mutually exclusive):

  • a completed route (unchanged behavior, used by Matrix, LINE, and gateway route ownership);
  • a deferred resolveRoute(selection) callback, which receives the binding selection first, including the explicitly bound agent id when the binding names one.

Discord, Slack, and iMessage now use the deferred form, so bound agents resolve before ordinary selection. The following is preserved:

  • Discord's stale-binding rejection (the ordinary route is kept separately for that comparison);
  • Slack's thread-before-base ownership observations;
  • iMessage's captured owner across activity persistence (it now reuses the shared helper instead of its own copy).

The shared projection also derives every agent-scoped route fact from the bound agent. When a binding targets a different agent than the ordinary route, mainSessionKey is rebuilt for the bound agent with buildAgentMainSessionKey (keeping the configured main-key name), and lastRoutePolicy is recomputed from it. Before this change, a conversation bound to agent B's main session inherited agent A's main key and was classified as a per-session route. That happened on both the deferred and the completed-route paths, which Matrix, LINE, and the gateway use.

This is an additive plugin SDK change, approved by the maintainer. No SDK entrypoints or exports were removed, and existing route-only callers are untouched. docs/plugins/sdk-runtime/channel.md documents the new option.

User Impact

Messages in Discord and Slack conversations bound to an agent session route to that bound agent even when ordinary agent selection would be ambiguous, instead of failing with AGENT_SELECTION_REQUIRED.

Evidence

Add deferred resolveRoute overloads while retaining completed-route SDK calls and Parameters inference. Migrate Discord and Slack inbound and owner routing, and replace the iMessage classification workaround. Preserve Discord stale-binding rejection and Slack thread-before-base ownership observations.

Blacksmith Testbox proof: origin/main at 80d6f07 fails Discord ambiguous routing and both Slack thread/base bindings with AGENT_SELECTION_REQUIRED. Candidate passes 131 Discord, 34 Slack, 22 iMessage, 22 binding-routing, and 10 SDK surface tests, canonical SDK export generation/checks, API diff, pnpm build, and check-changed. Isolated Codex review is scoped-clean through P2. No SDK export-count growth or baseline hand edits.
Replace the overlapping completed-route and deferred-resolver overloads with
single exclusive-union signatures while preserving existing exports and
Parameters-based callback inference. Name the explicit binding agent before
canonical normalization instead of passing an empty fallback sentinel, and
document the mutually exclusive inputs.

Make the Feishu lifecycle fixture reject deferred inputs explicitly. The
extension-test typecheck exposed its previously hidden completed-route-only
assumption; production Matrix, LINE, Gateway, Discord, and Slack callers
continue to typecheck.

Blacksmith Testbox tbx_01m3gkhbp1nw174tm4evaqbcwx proves candidate tree
23a2ef77d03c87394e4ac2097a8555ac8f27e058. Passed 144 Discord, 34 Slack,
29 iMessage, 22 core binding-routing, 13 SDK surface/declaration-budget,
and 18 Feishu lifecycle tests. SDK API diff has no removed entrypoints or
exports; surface check, export check, and check-changed pass. Isolated Codex
review is scoped-clean through P2. Formatting and lint proof ran remotely.
Rebuild mainSessionKey in the shared runtime binding projection when the
bound agent differs from the ordinary route, preserving the configured
main-key name and deriving lastRoutePolicy against the bound agent's key.
Both completed-route and deferred-route callers use this owner. Keep the
ordinary Discord route unchanged for stale-binding comparison.

Add a real Discord preflight regression with successful ordinary routing
to another agent and completed-route core regressions for default and
custom main keys. All three cases fail on the previous implementation.
Update the existing cross-agent expectation and document the invariant.
No SDK export or signature changes are needed for this repair.

Blacksmith Testbox tbx_01m3gs16t5chfk269ape0drcgf verified candidate tree
e5c25f2186355392195fc6e31ad6d0184f4eb728. Passed 33 Discord, 34 Slack,
64 iMessage, 16 Matrix, 56 LINE, 24 Feishu, 24 core binding-routing,
and 61 SDK tests, including the separate database-worker extension config.
SDK surface, export and API checks pass with no removed entrypoints or
exports. The complete check-changed gate passes. Changed regression-file
wall times with --maxWorkers=1: core 14.58s, Discord 15.74s.

Testbox run: https://github.com/openclaw/openclaw/actions/runs/36300394189
Lease stopped after proof. Review is left to the lead as requested.
@clawsweeper

clawsweeper Bot commented Sep 27, 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 docs Improvements or additions to documentation channel: discord Channel integration: discord channel: imessage Channel integration: imessage channel: slack Channel integration: slack channel: feishu Channel integration: feishu plugin: file-transfer size: L labels Sep 27, 2026
@steipete
steipete marked this pull request as ready for review September 27, 2026 08:13
@clawsweeper clawsweeper Bot added P1 High-priority user-facing bug, regression, or broken workflow. 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. rating: 🧂 unranked krab Not merge-ready due to missing proof or serious correctness/safety concerns. status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask. labels Sep 27, 2026
@clawsweeper

clawsweeper Bot commented Sep 27, 2026

Copy link
Copy Markdown
Contributor

Codex review: needs real behavior proof before merge. Reviewed September 27, 2026, 4:21 AM ET / 08:21 UTC.

ClawSweeper review

What this changes

The branch lets Discord, Slack, and iMessage use conversation bindings before ordinary agent selection, and updates the shared plugin SDK route helper, documentation, and regression tests.

Merge readiness

⛔ Blocked before merge - 9 items remain

Keep open. Current main still selects an ordinary route before checking the binding. The proposed Slack path can also select an agent removed from the configured roster, so the PR is not ready to merge.

Priority: P1
Reviewed head: 939d583c29b375819887b341a818f4e46f81349a

Review scores

Measure Result What it means
Overall readiness 🧂 unranked krab (1/6) The routing repair has focused coverage, but the removed-agent authority path and missing final-effect proof make this head unready.
Proof confidence 🦪 silver shellfish (2/6) Needs real behavior proof before merge: Authority-chain proof required: the changed Slack route can select a persisted bound agent without the active roster. The supplied tests cover configured agents and mocked binding races, but do not show allowed-agent delivery and removed-agent rejection before final workspace or reply I/O. A redacted production-path trace should cover both cases; no stored-data contract changes. 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 🧂 unranked krab (1/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 changed Slack route can select a persisted bound agent without the active roster. The supplied tests cover configured agents and mocked binding races, but do not show allowed-agent delivery and removed-agent rejection before final workspace or reply I/O. A redacted production-path trace should cover both cases; no stored-data contract changes. 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 Current main still routes first: The Discord preflight on fetched main constructs the ordinary route before resolving the conversation binding.
Binding-first projection: The introduced helper extracts the bound agent before invoking the deferred route resolver and rebuilds the selected agent's main-session key.
Introduced Slack roster bypass: When a binding supplies an agent ID, Slack passes only session config to the route resolver; the same introduced branch is used by Slack route-owner inspection.
Findings 1 actionable finding [P1] Validate the bound agent against the active roster
Security Needs attention Removed agent remains selectable through a Slack binding: The introduced session-only route config makes the existing-agent lookup see an empty roster, while reply admission rechecks binding identity rather than current agent membership. An unchanged binding can therefore select a removed agent and reach reply preparation.

How this fits together

Inbound channel messages are assigned to an agent and session before the reply engine runs. Conversation bindings supply an explicit owner, and the chosen route carries ownership facts into reply admission and delivery.

flowchart LR
A[Inbound channel message] --> B[Conversation binding inspection]
B --> C[Bound agent or ordinary selection]
C --> D[Agent and session route]
D --> E[Current binding admission]
E --> F[Agent run and reply]
Loading

Before merge

  • Add real behavior proof - Needs real behavior proof before merge: Authority-chain proof required: the changed Slack route can select a persisted bound agent without the active roster. The supplied tests cover configured agents and mocked binding races, but do not show allowed-agent delivery and removed-agent rejection before final workspace or reply I/O. A redacted production-path trace should cover both cases; no stored-data contract changes. 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.
  • Validate the bound agent against the active roster (P1) - With an explicit roster containing agent A and a retained Slack binding to removed agent B, this new session-only config hides the roster from resolveAgentRoute. Its existing-agent check then accepts B, and unchanged binding-admission checks do not detect B's removal. Validate B against the current config before constructing the bound route, and cover rejection before reply or workspace effects.
  • Resolve security concern: Removed agent remains selectable through a Slack binding - The introduced session-only route config makes the existing-agent lookup see an empty roster, while reply admission rechecks binding identity rather than current agent membership. An unchanged binding can therefore select a removed agent and reach reply preparation.
  • Resolve merge risk (P1) - A retained Slack binding can select an agent removed from the explicit roster because the new route path omits that roster; binding admission only confirms that the binding has not changed.
  • Resolve merge risk (P1) - The PR body gives test counts but omits the measured wall and CI costs required for its new and materially changed tests.
  • Complete next step (P2) - Reject bindings to agents removed from the current Slack roster, provide allowed and removed-agent final-effect proof, and add the required test-cost measurements.
  • Improve patch quality - Validate a bound Slack agent against the current configured roster before constructing its route.
  • Improve patch quality - Add a redacted final-effect trace for an allowed agent and a removed agent, showing rejection before workspace or outbound I/O; update the PR body to trigger re-review.
  • Improve patch quality - Record the required per-file test wall times and CI seconds in the PR body.

Findings

  • [P1] Validate the bound agent against the active roster — extensions/slack/src/monitor/message-handler/prepare-routing.ts:64-67
  • [high] Removed agent remains selectable through a Slack binding — extensions/slack/src/monitor/message-handler/prepare-routing.ts:65
Agent review details

Security

Needs attention: The new Slack bound-agent path can carry a retained binding past current agent-roster validation.

PR surface

Source +101, Tests +198, Docs +47. Total +346 across 15 files.

View PR surface stats
Area Files Added Removed Net
Source 9 228 127 +101
Tests 5 267 69 +198
Docs 1 47 0 +47
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 15 542 196 +346

Review metrics

Metric Value Why it matters
Plugin SDK route input 1 deferred mode added; completed mode retained The public helper gains a route-construction option while existing completed-route callers remain supported.
Production and test delta production +228/−127; tests and test support +267/−69 The stated production growth supports the shared helper and channel cutover; the changed authority path still needs correction.

Merge-risk options

Maintainer options:

  1. Validate bound agent before dispatch (recommended)
    Retain binding-first routing for configured agents, reject a removed agent before workspace or reply I/O, and demonstrate both final-effect cases.

Technical review

Best possible solution:

Keep the shared binding-first route, but check the bound Slack agent against the current roster before reply work; preserve thread precedence and the completed-route SDK contract.

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

Yes. Current main resolves an ordinary route before the binding, so an explicit multi-agent setup can fail before using its Slack or Discord binding. The removed-agent path in this PR is clear from source, but I did not execute it.

Is this the best way to solve the issue?

No, not yet. Deferring selection in the shared helper fits the existing owner, but Slack must check the bound agent against current configuration before that agent can reach reply preparation.

Full review comments:

  • [P1] Validate the bound agent against the active roster — extensions/slack/src/monitor/message-handler/prepare-routing.ts:64-67
    With an explicit roster containing agent A and a retained Slack binding to removed agent B, this new session-only config hides the roster from resolveAgentRoute. Its existing-agent check then accepts B, and unchanged binding-admission checks do not detect B's removal. Validate B against the current config before constructing the bound route, and cover rejection before reply or workspace effects.
    Confidence: 0.88

Overall correctness: patch is incorrect
Overall confidence: 0.86

AGENTS.md: found and applied where relevant.

Codex review notes: model internal, reasoning high; reviewed against 8620e9097726.

Labels

Label changes:

  • add P1: The PR addresses a broken channel workflow, but its Slack route can select an agent removed from the active roster.
  • add merge-risk: 🚨 message-delivery: That stale selection can target a Slack message at an agent the operator no longer configured.
  • add merge-risk: 🚨 security-boundary: A retained binding can carry an agent ID past the current roster check and into reply preparation.
  • add rating: 🧂 unranked krab: Overall readiness is 🧂 unranked krab; proof is 🦪 silver shellfish and patch quality is 🧂 unranked krab.
  • add 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 changed Slack route can select a persisted bound agent without the active roster. The supplied tests cover configured agents and mocked binding races, but do not show allowed-agent delivery and removed-agent rejection before final workspace or reply I/O. A redacted production-path trace should cover both cases; no stored-data contract changes. 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.

Label justifications:

  • P1: The PR addresses a broken channel workflow, but its Slack route can select an agent removed from the active roster.
  • merge-risk: 🚨 security-boundary: A retained binding can carry an agent ID past the current roster check and into reply preparation.
  • merge-risk: 🚨 message-delivery: That stale selection can target a Slack message at an agent the operator no longer configured.
  • rating: 🧂 unranked krab: Overall readiness is 🧂 unranked krab; proof is 🦪 silver shellfish and patch quality is 🧂 unranked krab.
  • 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 changed Slack route can select a persisted bound agent without the active roster. The supplied tests cover configured agents and mocked binding races, but do not show allowed-agent delivery and removed-agent rejection before final workspace or reply I/O. A redacted production-path trace should cover both cases; no stored-data contract changes. 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

Security concerns:

  • [high] Removed agent remains selectable through a Slack binding — extensions/slack/src/monitor/message-handler/prepare-routing.ts:65
    The introduced session-only route config makes the existing-agent lookup see an empty roster, while reply admission rechecks binding identity rather than current agent membership. An unchanged binding can therefore select a removed agent and reach reply preparation.
    Confidence: 0.87

What I checked:

Likely related people:

  • steipete: Suggested for follow-up; no historical authorship or introduction is verified. (role: unverified routing candidate; confidence: low)
  • obviyus: Suggested for follow-up; no historical authorship or introduction is verified. (role: unverified routing candidate; confidence: low)

Rating scale

Score Internal tier Crab rank Meaning
6/6 S 🦀 challenger crab Exceptional readiness
5/6 A 🦞 diamond lobster Very strong readiness
4/6 B 🐚 platinum hermit Good normal PR; ordinary maintainer review
3/6 C 🦐 gold shrimp Useful, but confidence is limited
2/6 D 🦪 silver shellfish Proof or implementation needs work
1/6 F 🧂 unranked krab Not merge-ready
N/A NA 🌊 off-meta tidepool Rating does not apply

Overall follows the weaker of proof and patch quality.
Shiny media proof means a screenshot, video, or linked artifact directly shows the changed behavior. Runtime, network, CSP, and security claims still need visible diagnostics.

Workflow

  • ClawSweeper keeps one durable marker-backed review comment per issue or PR.
  • Re-runs edit this comment so the latest verdict, findings, and automation markers stay together instead of adding duplicate bot comments.
  • A fresh review can be triggered by eligible @clawsweeper re-review comments, exact-item GitHub events, scheduled/background review runs, or manual workflow dispatch.
  • PR/issue authors and users with repository write access can comment @clawsweeper re-review or @clawsweeper re-run on an open PR or issue to request a fresh review only.
  • Maintainers can also comment @clawsweeper review to request a fresh review only.
  • Fresh-review commands do not start repair, autofix, rebase, CI repair, or automerge.
  • Maintainer-only repair and merge flows require explicit commands such as @clawsweeper autofix, @clawsweeper automerge, @clawsweeper fix ci, or @clawsweeper address review.
  • Maintainers can comment @clawsweeper explain to ask for more context, or @clawsweeper stop to stop active automation.

@steipete
steipete merged commit 474dc99 into main Sep 27, 2026
275 of 280 checks passed
@steipete
steipete deleted the fix/live2-discord-slack-binding-first branch September 27, 2026 09:35
@steipete

Copy link
Copy Markdown
Contributor Author

Merged via squash.

github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Sep 28, 2026
…aw#159533)

* test(channels): preserve binding-first routing regressions (WIP)

* fix(channels): resolve bound agents before ordinary selection

Add deferred resolveRoute overloads while retaining completed-route SDK calls and Parameters inference. Migrate Discord and Slack inbound and owner routing, and replace the iMessage classification workaround. Preserve Discord stale-binding rejection and Slack thread-before-base ownership observations.

Blacksmith Testbox proof: origin/main at 906ddd5 fails Discord ambiguous routing and both Slack thread/base bindings with AGENT_SELECTION_REQUIRED. Candidate passes 131 Discord, 34 Slack, 22 iMessage, 22 binding-routing, and 10 SDK surface tests, canonical SDK export generation/checks, API diff, pnpm build, and check-changed. Isolated Codex review is scoped-clean through P2. No SDK export-count growth or baseline hand edits.

* refactor(channels): make binding route inputs exclusive

Replace the overlapping completed-route and deferred-resolver overloads with
single exclusive-union signatures while preserving existing exports and
Parameters-based callback inference. Name the explicit binding agent before
canonical normalization instead of passing an empty fallback sentinel, and
document the mutually exclusive inputs.

Make the Feishu lifecycle fixture reject deferred inputs explicitly. The
extension-test typecheck exposed its previously hidden completed-route-only
assumption; production Matrix, LINE, Gateway, Discord, and Slack callers
continue to typecheck.

Blacksmith Testbox tbx_01m3gkhbp1nw174tm4evaqbcwx proves candidate tree
23a2ef77d03c87394e4ac2097a8555ac8f27e058. Passed 144 Discord, 34 Slack,
29 iMessage, 22 core binding-routing, 13 SDK surface/declaration-budget,
and 18 Feishu lifecycle tests. SDK API diff has no removed entrypoints or
exports; surface check, export check, and check-changed pass. Isolated Codex
review is scoped-clean through P2. Formatting and lint proof ran remotely.

* fix(channels): keep bound route main sessions with their agent

Rebuild mainSessionKey in the shared runtime binding projection when the
bound agent differs from the ordinary route, preserving the configured
main-key name and deriving lastRoutePolicy against the bound agent's key.
Both completed-route and deferred-route callers use this owner. Keep the
ordinary Discord route unchanged for stale-binding comparison.

Add a real Discord preflight regression with successful ordinary routing
to another agent and completed-route core regressions for default and
custom main keys. All three cases fail on the previous implementation.
Update the existing cross-agent expectation and document the invariant.
No SDK export or signature changes are needed for this repair.

Blacksmith Testbox tbx_01m3gs16t5chfk269ape0drcgf verified candidate tree
e5c25f2186355392195fc6e31ad6d0184f4eb728. Passed 33 Discord, 34 Slack,
64 iMessage, 16 Matrix, 56 LINE, 24 Feishu, 24 core binding-routing,
and 61 SDK tests, including the separate database-worker extension config.
SDK surface, export and API checks pass with no removed entrypoints or
exports. The complete check-changed gate passes. Changed regression-file
wall times with --maxWorkers=1: core 14.58s, Discord 15.74s.

Testbox run: https://github.com/openclaw/openclaw/actions/runs/36300394189
Lease stopped after proof. Review is left to the lead as requested.

Co-authored-by: Peter Steinberger <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

channel: discord Channel integration: discord channel: feishu Channel integration: feishu channel: imessage Channel integration: imessage channel: slack Channel integration: slack docs Improvements or additions to documentation 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. P1 High-priority user-facing bug, regression, or broken workflow. plugin: file-transfer rating: 🧂 unranked krab Not merge-ready due to missing proof or serious correctness/safety concerns. 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.

1 participant