#20801: fix: auto-select enabled account when only one is available
size: M
Cluster:
Signal and Discord Fixes
## Summary
Fixes #20756
When using the message tool without specifying `accountId`, the tool now intelligently selects the appropriate account:
1. **If explicit `accountId` provided** → use it (unchanged)
2. **If `default` account is enabled** → use `default` (unchanged)
3. **If `default` is disabled but exactly one account is enabled** → auto-select it ✨ NEW
4. **If multiple accounts are enabled** → require explicit `accountId` selection
5. **If no accounts are enabled** → throw a clear error
## Problem
Previously, the tool would always fall back to `default` account even when disabled:
```json
{
"channels": {
"whatsapp": {
"accounts": {
"default": { "enabled": false },
"xiaomi": { "enabled": true }
}
}
}
}
```
Result: Confusing error `No active WhatsApp Web listener (account: default)`
## Solution
Added `resolveMessageAccountSelection()` and `listEnabledAccountIds()` functions in `channel-selection.ts` that check account enabled state before selection.
## Changes
- `src/infra/outbound/channel-selection.ts`: Added account selection helpers
- `src/infra/outbound/message-action-runner.ts`: Use new account selection
- `src/infra/outbound/channel-selection.test.ts`: Tests for new behavior
## Testing
- [x] Unit tests for `listEnabledAccountIds`
- [x] Unit tests for `resolveMessageAccountSelection`
- [ ] CI checks
## AI Disclosure
This PR was AI-assisted (Claude). I understand the changes — they follow the same pattern as the existing `resolveMessageChannelSelection` function for channels, now applied to accounts.
<!-- greptile_comment -->
<h3>Greptile Summary</h3>
Added intelligent account auto-selection for the message tool when `accountId` is not specified. Previously, the tool would always fall back to the `default` account even when disabled, causing confusing errors. The new logic checks enabled state and auto-selects when exactly one account is available, following the same pattern as the existing `resolveMessageChannelSelection` function.
<h3>Confidence Score: 5/5</h3>
- This PR is safe to merge with minimal risk
- The implementation follows existing patterns in the codebase (`resolveMessageChannelSelection`), has comprehensive unit tests covering all code paths including edge cases, and the logic is straightforward with clear error messages. The change is well-scoped and fixes a specific UX issue without affecting other functionality.
- No files require special attention
<sub>Last reviewed commit: 95e0133</sub>
<!-- greptile_other_comments_section -->
<sub>(4/5) You can add custom instructions or style guidelines for the agent [here](https://app.greptile.com/review/github)!</sub>
<!-- /greptile_comment -->
Most Similar PRs
#19615: fix(discord): include default account when sub-accounts are configured
by prue-starfield · 2026-02-18
75.4%
#8507: fix: preserve accountId for multi-account agent-to-agent messaging
by djh58 · 2026-02-04
75.3%
#23333: fix(matrix): add accountId routing for multi-account message sending 🤖
by BadTurki · 2026-02-22
75.2%
#16284: fix(feishu): route tool credentials by account parameter
by Yaxuan42 · 2026-02-14
75.1%
#14789: fix: per-account dmPolicy ignored in checkInboundAccessControl
by croll83 · 2026-02-12
75.0%
#23238: fix(telegram): account named "default" silently breaks inbound polling
by anillBhoi · 2026-02-22
74.8%
#14359: fix: prefer named Telegram account over orphan 'default' in binding...
by itsGustav · 2026-02-12
74.3%
#17552: fix(agents): suppress tool error warnings when assistant already re...
by AytuncYildizli · 2026-02-15
74.1%
#15727: fix(routing): resolve channel default account instead of hardcoded ...
by FuseWeb · 2026-02-13
73.4%
#14488: Fix Telegram default account listing and CLI cache-write usage mapping
by abdulbb · 2026-02-12
73.4%