Skip to content

fix(#95734): [Bug]: agents add --bind generates accountId format, but router only matches peer format - #95745

Closed
solodmd wants to merge 2 commits into
openclaw:mainfrom
solodmd:autofix/fix-agents-add-bind-peer-format-95734-95734
Closed

solodmd wants to merge 2 commits into
openclaw:mainfrom
solodmd:autofix/fix-agents-add-bind-peer-format-95734-95734

Conversation

@solodmd

@solodmd solodmd commented Jun 22, 2026 •

Copy link
Copy Markdown
Contributor

Closes #95734

What Problem This Solves

Fixes an issue where openclaw agents add --bind "feishu:oc_test" generates bindings using the accountId field, but the routing engine matches conversations using the peer field. Messages in Feishu groups fall through to the default agent instead of the bound agent.

Users creating channel-specific agents (e.g., Feishu group bindings) had to manually edit openclaw.json after every agents add command to convert accountId to peer format — otherwise group messages were silently routed to the default agent.

Why This Change Was Made

The parseBindingSpecs function in src/commands/agents.bindings.ts only recognized a 2-segment format <channel>:<account> which maps to match.accountId. However, route resolution (src/routing/resolve-route.ts) uses match.peer as the conversation-specific routing tier (checked at priority 1), while match.accountId is a lower-priority tier (priority 7). This means accountId-based bindings were ignored for group chat routing.

The fix introduces a new 3-segment binding format <channel>:<peer_kind>:<peer_id> (e.g., feishu:group:oc_test) that creates a match.peer = { kind, id } binding, which the router matches at the highest conversation-specific tier.

Key design decisions:

  • peer_kind is validated against the ChatType enum (direct, group, channel) via normalizeChatType() with dm → direct alias support
  • Empty or invalid peer segments produce explicit error messages
  • Specs with more than 3 segments are rejected with a clear error documenting both valid formats
  • The existing 2-segment format <channel>:<account> is preserved unchanged for backward compatibility

Non-goals:

  • Migrating existing accountId-format bindings in openclaw.json to peer format (users must update manually or re-run agents add)
  • Changes to the routing engine itself — this fix is in the CLI binding parser only

User Impact

Users can now run openclaw agents add --bind 'feishu:group:oc_test' and the generated binding will use match.peer = { kind: "group", id: "oc_test" }, which the routing engine correctly matches for Feishu group messages.

Evidence

CLI command output

$ pnpm openclaw agents add test-agent --bind 'feishu:group:oc_test' --non-interactive --workspace /tmp/oc-evidence

Updated config: ~/.openclaw/openclaw.json
  Backup: ~/.openclaw/openclaw.json.bak
Workspace OK: /tmp/oc-evidence
Sessions OK: ~/.openclaw/agents/test-agent/sessions
Agent: test-agent
Workspace: /tmp/oc-evidence
Agent dir: ~/.openclaw/agents/test-agent/agent

Generated binding in openclaw.json

{
  "bindings": [
    {
      "type": "route",
      "agentId": "test-agent",
      "match": {
        "channel": "feishu",
        "peer": {
          "kind": "group",
          "id": "oc_test"
        }
      }
    }
  ]
}

Parser-level proof (all edge cases)

// 3-segment peer binding — NEW
parseBindingSpecs({ specs: ["feishu:group:oc_test"] })
// → { bindings: [{ match: { channel: "feishu", peer: { kind: "group", id: "oc_test" } } }] }

// 2-segment account binding — backward compatible
parseBindingSpecs({ specs: ["telegram:default"] })
// → { bindings: [{ match: { channel: "telegram", accountId: "default" } }] }

// 1-segment channel-only — backward compatible
parseBindingSpecs({ specs: ["telegram"] })
// → { bindings: [{ match: { channel: "telegram" } }] }

// dm alias → direct
parseBindingSpecs({ specs: ["matrix:dm:user123"] })
// → { bindings: [{ match: { channel: "matrix", peer: { kind: "direct", id: "user123" } } }] }

// Invalid peer kind → error
parseBindingSpecs({ specs: ["matrix:room:oc_test"] })
// → { errors: ['Peer kind "room" is not valid. Use one of: direct, group, channel.'] }

// Empty peer kind → error
parseBindingSpecs({ specs: ["matrix::oc_test"] })
// → { errors: ['Peer kind is empty.'] }

// Empty peer id → error
parseBindingSpecs({ specs: ["matrix:group:"] })
// → { errors: ['Peer id is empty.'] }

// Too many segments → error
parseBindingSpecs({ specs: ["matrix:a:b:c"] })
// → { errors: ['Too many segments.'] }

Test results

$ pnpm test src/commands/agents.bind.matrix.integration.test.ts
Test Files  1 passed (1)
     Tests  9 passed (9)

Proof limitations

  • No live Feishu environment available; validation is limited to the binding parser and test suite.
  • End-to-end Feishu message routing requires an active Feishu bot token and group setup.

@openclaw-barnacle openclaw-barnacle Bot added commands Command implementations size: M labels Jun 22, 2026
@solodmd
solodmd force-pushed the autofix/fix-agents-add-bind-peer-format-95734-95734 branch from 4783fdf to c764406 Compare June 22, 2026 12:26
@clawsweeper clawsweeper Bot added 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. P2 Normal backlog priority with limited blast radius. merge-risk: 🚨 compatibility 🚨 May break existing users, config, migrations, defaults, or upgrade paths. labels Jun 22, 2026
@clawsweeper

clawsweeper Bot commented Jun 22, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: found issues before merge. Reviewed June 27, 2026, 2:57 AM ET / 06:57 UTC.

Summary
The PR adds a three-segment <channel>:<peer_kind>:<peer_id> bind parser branch, tests, and CLI docs so bind specs can generate match.peer route bindings.

PR surface: Source +40, Tests +118, Docs +8. Total +166 across 3 files.

Reproducibility: yes. source-level: current main and v2026.6.10 parse feishu:oc_test as match.accountId, while route resolution prioritizes match.peer for conversation routing. I did not run a live Feishu route in this read-only review.

Review metrics: 2 noteworthy metrics.

  • Public bind grammar: 1 added. The PR adds a user-facing CLI input form that writes persisted route bindings, so compatibility and docs need maintainer review.
  • Reported bind form: 1 unchanged. The original feishu:<id> form still maps to accountId, which is the core fix-readiness question.

Root-cause cluster
Relationship: fixed_by_candidate
Canonical: #95734
Summary: This PR is one candidate fix for the canonical Feishu agents add --bind accountId-vs-peer routing bug; no candidate has merged yet.

Members:

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

Merge readiness
Overall: 🧂 unranked krab
Proof: 🐚 platinum hermit
Patch quality: 🧂 unranked krab
Result: blocked by patch quality or review findings.

Overall follows the weaker of proof and patch quality, so missing proof can cap an otherwise strong patch.

Rank-up moves:

  • [P2] Fix or explicitly retarget the original feishu:<chat_id> bind path.
  • [P2] Add regression coverage for the chosen Feishu peer/account grammar, including an account-binding escape or default-account scope.

Risk before merge

  • [P1] Merging this as the fix would document a new channel:kind:id syntax while the reported feishu:<chat_id> command still writes accountId, so the linked routing bug can remain reproducible.
  • [P1] The new peer syntax writes no accountId, leaving account-plus-peer routing for multi-account channels as an unresolved public grammar and upgrade-safety choice.

Maintainer options:

  1. Fix the reported bind path before merge (recommended)
    Update the parser or Feishu binding resolution so feishu:<chat_id> can generate a peer binding while preserving a clear account-binding escape and tests.
  2. Accept this only as additive syntax
    Maintainers can choose to land the three-segment grammar as a new feature, but then this PR should not close the existing Feishu two-segment routing bug.
  3. Choose another candidate fix
    Pause this branch if a sibling PR better matches the desired Feishu grammar, then close remaining candidates only after one fix merges.

Next step before merge

  • [P2] Manual review is needed because the blocker is the public bind grammar and compatibility choice across competing PRs, not a narrow bot-safe repair.

Security
Cleared: Cleared: the diff only changes CLI parsing, docs, and tests; it does not touch workflows, dependencies, permissions, secrets, downloads, or package resolution.

Review findings

  • [P1] Handle the reported Feishu bind form — src/commands/agents.bindings.ts:341-358
Review details

Best possible solution:

Land one compatibility-safe Feishu bind grammar that fixes the reported two-segment flow with an explicit account escape, or retarget this PR as additive syntax and keep the canonical bug open.

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

Yes, source-level: current main and v2026.6.10 parse feishu:oc_test as match.accountId, while route resolution prioritizes match.peer for conversation routing. I did not run a live Feishu route in this read-only review.

Is this the best way to solve the issue?

No, not as a fix for the linked bug: the parser boundary is plausible for an explicit new syntax, but the reported two-segment Feishu command remains unchanged. The safer path is to fix that form or clearly keep it as separate canonical work.

Full review comments:

  • [P1] Handle the reported Feishu bind form — src/commands/agents.bindings.ts:341-358
    The linked report is for openclaw agents add --bind 'feishu:oc_test', but this branch still sends every two-segment bind through the accountId path. After the patch, that exact command still produces match.accountId, so Feishu group traffic can still fall through unless users discover the new three-segment form. Please either make the reported form produce a peer binding with a compatibility-safe account escape, or stop closing the canonical bug from this PR.
    Confidence: 0.91

Overall correctness: patch is incorrect
Overall confidence: 0.88

AGENTS.md: found and applied where relevant.

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

Label changes

Label justifications:

  • P2: The PR targets a bounded Feishu routing bug with a manual config workaround, but the submitted fix needs compatibility and syntax review before merge.
  • merge-risk: 🚨 compatibility: The diff changes public --bind grammar and generated persisted binding shape while leaving account-plus-peer syntax unresolved.
  • merge-risk: 🚨 message-delivery: If merged as the fix, users following the reported Feishu bind command can still have group messages routed to the default or wrong agent.
  • rating: 🧂 unranked krab: Overall readiness is 🧂 unranked krab; proof is 🐚 platinum hermit and patch quality is 🧂 unranked krab.
  • status: ⏳ waiting on author: ClawSweeper has contributor-facing work open and is waiting for author action. Sufficient (terminal): Sufficient for the new CLI syntax: the PR body includes terminal output and generated config showing feishu:group:oc_test writes match.peer, though that does not make the patch correct for the original two-segment bug.
  • proof: sufficient: Contributor real behavior proof is sufficient. Sufficient for the new CLI syntax: the PR body includes terminal output and generated config showing feishu:group:oc_test writes match.peer, though that does not make the patch correct for the original two-segment bug.
Evidence reviewed

PR surface:

Source +40, Tests +118, Docs +8. Total +166 across 3 files.

View PR surface stats
Area Files Added Removed Net
Source 1 62 22 +40
Tests 1 121 3 +118
Docs 1 16 8 +8
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 3 199 33 +166

What I checked:

  • Repository policy read: Root policy and scoped docs/channel guides were read; the CLI compatibility and channel boundary guidance affected this review. (AGENTS.md:1, fbfadbd806e1)
  • PR head keeps two-segment binds as account bindings: On the PR head, the segments.length === 2 branch still resolves the second segment as accountId, so feishu:oc_test remains account-shaped. (src/commands/agents.bindings.ts:341, 5a9cd330be27)
  • PR head adds a separate peer syntax: The new peer behavior only runs for exactly three segments and writes match.peer, which proves this is an additive syntax rather than a fix for the reported two-segment command. (src/commands/agents.bindings.ts:359, 5a9cd330be27)
  • Current main source behavior: Current main parses <channel>:<account> by assigning the second segment to match.accountId, which is the behavior reported for Feishu chat IDs. (src/commands/agents.bindings.ts:319, fbfadbd806e1)
  • Routing contract: Route resolution checks binding.peer before account and channel fallback tiers, so a conversation-specific Feishu group binding must be peer-shaped to win that tier. (src/routing/resolve-route.ts:737, fbfadbd806e1)
  • Shipped behavior check: The latest release tag still uses the two-segment account parser, so the original reported behavior was shipped and is not already fixed in release. (src/commands/agents.bindings.ts:319, aa69b12d0086)

Likely related people:

  • ly-wang19: Authored the recent parser hardening PR that rejects extra colon segments in parseBindingSpecs, the exact branch this PR changes. (role: recent parser contributor; confidence: high; commits: 540ec53f9931; files: src/commands/agents.bindings.ts, src/commands/agents.bind.matrix.integration.test.ts)
  • gumadeiras: Authored and merged the account-scoped agent bind and routing command work that established the current channel:account CLI surface. (role: introduced adjacent command surface; confidence: high; commits: 96c77025263d; files: src/commands/agents.bindings.ts, src/commands/agents.commands.add.ts, src/commands/agents.commands.bind.ts)
  • joelnishanth: Authored peer-binding routing work in resolve-route.ts, which is the route tier the generated config must target. (role: adjacent peer-routing contributor; confidence: medium; commits: b554516f215f; files: src/routing/resolve-route.ts, src/routing/resolve-route.test.ts)
  • steipete: Recent history shows work on routing helper docs and agent-management CLI docs around the same public behavior surface. (role: recent routing and docs contributor; confidence: medium; commits: 9b30ff181c14, 03490ba1b94b; files: docs/cli/agents.md, src/routing/resolve-route.ts)
What the crustacean ranks mean
  • 🦀 challenger crab: rare, exceptional readiness with strong proof, clean implementation, and convincing validation.
  • 🦞 diamond lobster: very strong readiness with only minor maintainer review expected.
  • 🐚 platinum hermit: good normal PR, likely mergeable with ordinary maintainer review.
  • 🦐 gold shrimp: useful signal, but proof or patch confidence is still limited.
  • 🦪 silver shellfish: thin signal; proof, validation, or implementation needs work.
  • 🧂 unranked krab: not merge-ready because proof is missing/unusable or there are serious correctness or safety concerns.
  • 🌊 off-meta tidepool: rating does not apply to this item.

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.

How this review workflow works
  • 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.

@solodmd
solodmd force-pushed the autofix/fix-agents-add-bind-peer-format-95734-95734 branch 3 times, most recently from 4783fdf to 2b88059 Compare June 23, 2026 01:14
@solodmd
solodmd force-pushed the autofix/fix-agents-add-bind-peer-format-95734-95734 branch from 2b88059 to 4783fdf Compare June 23, 2026 01:16
@solodmd
solodmd force-pushed the autofix/fix-agents-add-bind-peer-format-95734-95734 branch from 4783fdf to 87785fe Compare June 23, 2026 01:45
@solodmd

solodmd commented Jun 23, 2026

Copy link
Copy Markdown
Contributor Author

Evidence update

Updated this PR body with real behavior proof:

What was added

  1. CLI command output showing openclaw agents add --bind 'feishu:group:oc_test' succeeding
  2. Generated openclaw.json confirming match.peer = { kind: "group", id: "oc_test" }
  3. Parser-level edge case matrix covering all paths (success, invalid kind, empty segments, too many segments, dm alias)
  4. Test results — 9/9 passing
  5. Rebased onto latest openclaw/main to pick up CI fixes (b60f6315 + 362c26a986)

cc @clawsweeper re-review

@openclaw-barnacle openclaw-barnacle Bot added the triage: needs-pr-context Candidate: external PR body lacks required problem context or evidence. label Jun 23, 2026
@solodmd

solodmd commented Jun 23, 2026

Copy link
Copy Markdown
Contributor Author

Updated PR body to match the template format (## What Problem This Solves, ## Evidence, etc.) with real CLI output and generated config.

@clawsweeper re-review

@clawsweeper

clawsweeper Bot commented Jun 23, 2026 •

Copy link
Copy Markdown
Contributor

🦞🧹
ClawSweeper re-review requested.

I asked ClawSweeper to review this item again.
Action: item re-review queued (workflow sweep.yml, event repository_dispatch).
Result: the existing ClawSweeper review comment will be edited in place when the review finishes.

@openclaw-barnacle openclaw-barnacle Bot added docs Improvements or additions to documentation and removed triage: needs-pr-context Candidate: external PR body lacks required problem context or evidence. labels Jun 23, 2026
solodmd added 2 commits June 23, 2026 15:29
Add examples, format table row, and option references for the
<channel>:<peer_kind>:<peer_id> syntax introduced in openclaw#95734 fix.
@clawsweeper clawsweeper Bot added proof: sufficient ClawSweeper judged the real behavior proof convincing. rating: 🧂 unranked krab Not merge-ready due to missing proof or serious correctness/safety concerns. status: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action. merge-risk: 🚨 message-delivery 🚨 May drop, duplicate, misroute, suppress, or wrongly target messages. and removed 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 Jun 23, 2026
@openclaw-barnacle

Copy link
Copy Markdown

This pull request has been automatically marked as stale due to inactivity.
Please add updates or it will be closed.

@openclaw-barnacle openclaw-barnacle Bot added the stale Marked as stale due to inactivity label Jul 16, 2026
@openclaw-barnacle

Copy link
Copy Markdown

Closing due to inactivity.
If you believe this PR should be revived, post in #clawtributors on Discord to talk to a maintainer.
That channel is the escape hatch for high-quality PRs that get auto-closed.

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

Labels

commands Command implementations docs Improvements or additions to documentation 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. P2 Normal backlog priority with limited blast radius. proof: sufficient ClawSweeper judged the real behavior proof convincing. rating: 🧂 unranked krab Not merge-ready due to missing proof or serious correctness/safety concerns. size: M stale Marked as stale due to inactivity status: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: agents add --bind generates accountId format, but router only matches peer format

1 participant