#16685: Fix cli agents/approvals/discord routing edge cases
channel: discord
gateway
cli
agents
stale
size: S
## Summary
- Fixes the CLI route-first dispatcher so `openclaw agents add` is routed through normal command parsing and no longer fails with `unknown command 'agents'`.
- Fixes exec approval forwarding behavior: `sessionFilter` no longer blocks forwarding in `mode: targets`.
- Improves Discord inbound session classification using resolved route session key to avoid direct/channel misclassification.
## Related issues
- Closes #16267
- Closes #16184
- Closes #16149
## Testing
- Not run in this environment due missing toolchain constraints (`pnpm` not installed / test deps unavailable).
<!-- greptile_comment -->
<h3>Greptile Summary</h3>
Fixed CLI dispatcher to properly route all `openclaw agents` subcommands through normal command parsing instead of only handling `agents list`. The old route matched only `agents list`, causing `openclaw agents add` and other subcommands to fail with "unknown command 'agents'".
- **CLI routing fix**: Changed `routeAgentsCommand` to match all `agents` commands and delegate to full program parser, enabling proper subcommand discovery for `add`, `delete`, and `set-identity`.
- **Exec approval forwarding fix**: In `mode: targets`, `sessionFilter` no longer blocks forwarding when explicit targets are configured. The filter now only applies in `session` and `both` modes as intended.
- **Discord session classification**: Uses resolved route session key to determine direct vs channel sessions, preventing misclassification when routing rules differ from Discord channel type.
- **Session file path resolution**: Added `agentId` parameter threading through `resolveSessionFilePath` calls to correctly resolve multi-agent session transcript paths.
- **Config schema**: Added `gateway.auth.rateLimit` field with validation and metadata.
- **Error pattern refinement**: Improved 402 billing error regex to avoid false positives on response text containing "402".
<h3>Confidence Score: 4/5</h3>
- This PR is safe to merge with low risk - fixes critical CLI routing bugs and approval forwarding logic with good test coverage
- The changes fix well-scoped bugs with clear logic improvements. CLI routing now properly delegates to full command parser. Approval forwarding correctly applies `sessionFilter` only in relevant modes. Discord classification uses authoritative route data. All changes follow consistent patterns and include test coverage. Minor risk from the broad CLI routing change, but the delegation to existing parser is the correct solution.
- No files require special attention
<sub>Last reviewed commit: d022421</sub>
<!-- 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>
<!-- /greptile_comment -->
Most Similar PRs
#9051: fix(sessions): respect dmScope config in CLI agent commands
by benleavett · 2026-02-04
82.3%
#15852: fix: pass agentId when resolving IRC session paths
by MisterGuy420 · 2026-02-14
81.4%
#15744: fix: allow cross-agent session path validation
by scottgl9 · 2026-02-13
79.8%
#11788: feat: inter-agent communication via CLI scripts
by jingkang0822 · 2026-02-08
79.7%
#15792: fix: pass agentId to resolveSessionFilePath in additional call sites
by MisterGuy420 · 2026-02-13
79.1%
#16194: fix: route exec approvals to explicit targets regardless of session...
by MisterGuy420 · 2026-02-14
78.8%
#18593: fix: resolve symlinks in session path validation (#18553)
by EpaL · 2026-02-16
78.4%
#15176: fix(sessions): allow channel-routed session IDs and cross-agent paths
by cathrynlavery · 2026-02-13
78.2%
#4878: fix: string/type handling and API fixes (#4537, #4380, #4373, #4547...
by lailoo · 2026-01-30
77.8%
#15982: fix: pass agentId to resolveSessionFilePath in reply flow (NX-003)
by automagik-genie · 2026-02-14
77.8%