Repository navigation
fix(channels): resolve bound agents before ordinary selection - #159533
Conversation
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.
|
🦞👀 Pull request received. I will update this pull request when review starts. ClawSweeper review completeClawSweeper finished reviewing this revision. The review result is being finalized. |
|
Codex review: needs real behavior proof before merge. Reviewed September 27, 2026, 4:21 AM ET / 08:21 UTC. ClawSweeper reviewWhat this changesThe 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 Review scores
Verification
How this fits togetherInbound 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]
Before merge
Findings
Agent review detailsSecurityNeeds attention: The new Slack bound-agent path can carry a retained binding past current agent-roster validation. PR surfaceSource +101, Tests +198, Docs +47. Total +346 across 15 files. View PR surface stats
Review metrics
Merge-risk optionsMaintainer options:
Technical reviewBest 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:
Overall correctness: patch is incorrect AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning high; reviewed against 8620e9097726. LabelsLabel changes:
Label justifications:
EvidenceSecurity concerns:
What I checked:
Likely related people:
Rating scale
Overall follows the weaker of proof and patch quality. Workflow
|
|
Merged via squash.
|
…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]>
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 withAGENT_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.tsrequired 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:inspectRuntimeConversationBindingRouteandresolveRuntimeConversationBindingRoutenow accept exactly one of these (mutually exclusive):route(unchanged behavior, used by Matrix, LINE, and gateway route ownership);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:
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,
mainSessionKeyis rebuilt for the bound agent withbuildAgentMainSessionKey(keeping the configured main-key name), andlastRoutePolicyis 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.mddocuments 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
AGENT_SELECTION_REQUIRED. They pass after the fix.pnpm plugin-sdk:surface:check, the API diff (one additive option, no removals),pnpm build, andnode scripts/check-changed.mjspass.