#22757: fix(routing): normalize input peer.kind in resolveAgentRoute
size: XS
Cluster:
Feishu Messaging Fixes
## Summary
Fixes a routing mismatch where `resolveAgentRoute` fails to normalize the input `peer.kind`, causing DM routing to break when a plugin passes `kind: "dm"` but the binding config uses `kind: "direct"`.
## Problem
In `resolveAgentRoute()`, the binding's `peer.kind` is normalized via `normalizeChatType()` (which maps `"dm"` → `"direct"`), but the **input** `peer.kind` is used raw:
```typescript
// Before (broken): input not normalized
const peer = input.peer ? { kind: input.peer.kind, id: normalizeId(input.peer.id) } : null;
```
This causes `matchesBindingScope` to fail because `"dm" !== "direct"`.
## Fix
```typescript
// After: input normalized consistently with bindings
const peer = input.peer ? { kind: normalizeChatType(input.peer.kind), id: normalizeId(input.peer.id) } : null;
```
**1 file changed**, 1 line modified in `src/routing/resolve-route.ts`.
Fixes #22730
## Local Validation
- `normalizeChatType` was already imported and used in the same file (line 224, for binding normalization)
- Existing test suite includes `"backward compatibility: peer.kind dm → direct"` test case
## Scope
Single line change in `src/routing/resolve-route.ts`. Uses existing `normalizeChatType()` function already imported in the file.
## AI Assistance
Claude Code assisted with locating the exact mismatch between input and binding normalization paths.
## Author
**Miloud Belarebia** — [@miloudbelarebia](https://github.com/miloudbelarebia)
<!-- greptile_comment -->
<h3>Greptile Summary</h3>
Fixes DM routing mismatch by normalizing `input.peer.kind` to map `"dm"` → `"direct"`, ensuring consistency with binding normalization.
**Key changes:**
- Applied `normalizeChatType()` to `input.peer.kind` in `resolveAgentRoute()` (line 294)
- Uses existing imported function already applied to binding peer kinds (line 224)
- Enables plugins passing `kind: "dm"` to match bindings configured with `kind: "direct"`
**Issue found:**
- `parentPeer.kind` (line 354) has the same normalization gap and should be fixed for consistency
<h3>Confidence Score: 4/5</h3>
- Safe to merge with one additional fix recommended for `parentPeer.kind` normalization
- The change correctly fixes the reported issue and has test coverage. However, `parentPeer.kind` (line 354) has the same normalization gap that should be addressed for consistency. The fix uses an existing, well-tested function and follows the same pattern already applied to bindings.
- Pay attention to line 354 in `src/routing/resolve-route.ts` - `parentPeer.kind` needs the same normalization treatment
<sub>Last reviewed commit: ff75918</sub>
<!-- greptile_other_comments_section -->
<!-- /greptile_comment -->
Most Similar PRs
#14888: fix(routing): normalize peer.kind in matchesPeer for symmetric comp...
by omair445 · 2026-02-12
88.0%
#21955: fix(line): remove redundant group:/room: prefix from buildPeerId (#...
by lailoo · 2026-02-20
75.1%
#9437: fix: normalize accountId in binding matching for consistent routing
by dbottme · 2026-02-05
71.4%
#13477: routing: normalize account ID matching for agent bindings
by davidahmann · 2026-02-10
70.9%
#15727: fix(routing): resolve channel default account instead of hardcoded ...
by FuseWeb · 2026-02-13
70.2%
#23656: fix(routing): trust binding agentId even when not in agents.list
by SleuthCo · 2026-02-22
69.5%
#20858: fix(hooks): normalize hook addresses to canonical provider:kind:id ...
by davidrudduck · 2026-02-19
69.2%
#10643: fix(slack): classify D-prefix DMs correctly when channel_type disag...
by mcaxtr · 2026-02-06
69.1%
#18801: fix(routing): use fresh config in resolveAgentRoute to prevent stal...
by mcaxtr · 2026-02-17
67.9%
#7224: feat(telegram): inherit forum topic bindings from parent group
by Buywatermelon · 2026-02-02
67.7%