#13477: routing: normalize account ID matching for agent bindings
docker
stale
## Summary
- normalize `match.accountId` and runtime `accountId` using the same canonical account normalization
- prevent fallback routing when binding and runtime account IDs differ only by case/formatting
- add regression coverage for normalized account binding matches
## Validation
- `pnpm vitest run src/routing/resolve-route.test.ts src/telegram/bot.create-telegram-bot.routes-dms-by-telegram-accountid-binding.test.ts`
Fixes #13423
<!-- greptile_comment -->
<h2>Greptile Overview</h2>
<h3>Greptile Summary</h3>
This PR updates routing account binding resolution so that accountId comparisons use the same canonical normalization as session key generation (`normalizeAccountId` from `src/routing/session-key.ts`). Concretely, `resolveAgentRoute` now normalizes the runtime accountId with the canonical normalizer, and `matchesAccountId` compares normalized forms instead of raw strings. A regression test was added to ensure bindings match when the configured accountId and runtime accountId differ only by case/formatting (e.g., `"Bot Main"` vs `"bot-main"`), preventing unintended fallback routing.
<h3>Confidence Score: 5/5</h3>
- This PR is safe to merge with minimal risk.
- Changes are small, localized, and align routing-time accountId matching with the existing canonical normalization used for session keys. The added regression test covers the reported misrouting scenario. No call sites are broken because the public API is unchanged and behavior only becomes more permissive for equivalent account IDs.
- No files require special attention
<!-- greptile_other_comments_section -->
<sub>(3/5) Reply to the agent's comments like "Can you suggest a fix for this @greptileai?" or ask follow-up questions!</sub>
**Context used:**
- Context from `dashboard` - CLAUDE.md ([source](https://app.greptile.com/review/custom-context?memory=fd949e91-5c3a-4ab5-90a1-cbe184fd6ce8))
- Context from `dashboard` - AGENTS.md ([source](https://app.greptile.com/review/custom-context?memory=0d0c8278-ef8e-4d6c-ab21-f5527e322f13))
<!-- /greptile_comment -->
Most Similar PRs
#9437: fix: normalize accountId in binding matching for consistent routing
by dbottme · 2026-02-05
89.5%
#15727: fix(routing): resolve channel default account instead of hardcoded ...
by FuseWeb · 2026-02-13
85.3%
#8507: fix: preserve accountId for multi-account agent-to-agent messaging
by djh58 · 2026-02-04
79.1%
#23656: fix(routing): trust binding agentId even when not in agents.list
by SleuthCo · 2026-02-22
78.7%
#8095: fix(sessions): include accountId in deliveryContext for outbound pe...
by codeslayer44 · 2026-02-03
77.8%
#14359: fix: prefer named Telegram account over orphan 'default' in binding...
by itsGustav · 2026-02-12
77.0%
#16685: Fix cli agents/approvals/discord routing edge cases
by craftowen · 2026-02-15
75.6%
#8357: fix(gateway): preserve accountId across gateway restarts
by alfredo-feat-volky · 2026-02-03
75.5%
#8694: Fix Telegram routing when token override omits accountId
by codvik · 2026-02-04
74.7%
#14888: fix(routing): normalize peer.kind in matchesPeer for symmetric comp...
by omair445 · 2026-02-12
74.6%