Repository navigation
fix: auto-select enabled account when only one is available - #20801
mariusorani wants to merge 2 commits into
Conversation
Fixes openclaw#20756 When using the message tool without specifying accountId: - If 'default' account is enabled, use it (existing behavior) - If 'default' is disabled but exactly one account is enabled, auto-select it - If multiple accounts are enabled, require explicit accountId selection - If no accounts are enabled, throw a clear error This follows the principle of least surprise — if only one account can work, pick it automatically instead of failing with a confusing error. Example config where this helps: ```json { "channels": { "whatsapp": { "accounts": { "default": { "enabled": false }, "xiaomi": { "enabled": true } } } } } ``` Previously: Tool tries 'default', fails silently Now: Tool auto-selects 'xiaomi' since it's the only enabled account
|
It's stateless, gets resolved fresh on every call: const enabledAccounts = listEnabledAccountIds({ cfg, channel });
// no caching, no persistenceSo if that account gets disabled later, next message action just re-evaluates. Either errors out or picks whatever's enabled at that point. |
When the channel plugin is not found (e.g., in tests with mock channels), fall back to the old behavior instead of throwing an error. This fixes test failures where channels like 'testchat' or 'imessage' don't have their plugins registered in the test environment.
|
CI is failing on a type error in Our account selection changes are ready for review once that's sorted. |
|
This pull request has been automatically marked as stale due to inactivity. |
|
Closing due to inactivity. |
Summary
Fixes #20756
When using the message tool without specifying
accountId, the tool now intelligently selects the appropriate account:accountIdprovided → use it (unchanged)defaultaccount is enabled → usedefault(unchanged)defaultis disabled but exactly one account is enabled → auto-select it ✨ NEWaccountIdselectionProblem
Previously, the tool would always fall back to
defaultaccount even when disabled:{ "channels": { "whatsapp": { "accounts": { "default": { "enabled": false }, "xiaomi": { "enabled": true } } } } }Result: Confusing error
No active WhatsApp Web listener (account: default)Solution
Added
resolveMessageAccountSelection()andlistEnabledAccountIds()functions inchannel-selection.tsthat check account enabled state before selection.Changes
src/infra/outbound/channel-selection.ts: Added account selection helperssrc/infra/outbound/message-action-runner.ts: Use new account selectionsrc/infra/outbound/channel-selection.test.ts: Tests for new behaviorTesting
listEnabledAccountIdsresolveMessageAccountSelectionAI Disclosure
This PR was AI-assisted (Claude). I understand the changes — they follow the same pattern as the existing
resolveMessageChannelSelectionfunction for channels, now applied to accounts.Greptile Summary
Added intelligent account auto-selection for the message tool when
accountIdis not specified. Previously, the tool would always fall back to thedefaultaccount 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 existingresolveMessageChannelSelectionfunction.Confidence Score: 5/5
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.Last reviewed commit: 95e0133
(4/5) You can add custom instructions or style guidelines for the agent here!