← Back to PRs

#20801: fix: auto-select enabled account when only one is available

by mariusorani open 2026-02-19 09:39 View on GitHub →
size: M
## 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