Skip to content

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

Closed
mariusorani wants to merge 2 commits into
openclaw:mainfrom
mariusorani:fix/message-tool-auto-select-account
Closed

mariusorani wants to merge 2 commits into
openclaw:mainfrom
mariusorani:fix/message-tool-auto-select-account

Conversation

@mariusorani

@mariusorani mariusorani commented Feb 19, 2026 •

Copy link
Copy Markdown

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:

{
  "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

  • Unit tests for listEnabledAccountIds
  • 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 Summary

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.

Confidence Score: 5/5

  • 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

Last reviewed commit: 95e0133

(4/5) You can add custom instructions or style guidelines for the agent here!

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
@mariusorani

Copy link
Copy Markdown
Author

It's stateless, gets resolved fresh on every call:

const enabledAccounts = listEnabledAccountIds({ cfg, channel });
// no caching, no persistence

So 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.
@mariusorani

Copy link
Copy Markdown
Author

CI is failing on a type error in src/daemon/launchd.test.ts - the file uses fs, path, and os without importing them (lines 177+). This exists in main as well, not related to our changes.

Our account selection changes are ready for review once that's sorted.

@openclaw-barnacle

Copy link
Copy Markdown

This pull request has been automatically marked as stale due to inactivity.
Please add updates or it will be closed.

@openclaw-barnacle openclaw-barnacle Bot added the stale Marked as stale due to inactivity label Feb 28, 2026
@openclaw-barnacle

Copy link
Copy Markdown

Closing due to inactivity.
If you believe this PR should be revived, post in #pr-thunderdome-dangerzone on Discord to talk to a maintainer.
That channel is the escape hatch for high-quality PRs that get auto-closed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

size: M stale Marked as stale due to inactivity

Projects

None yet

Development

Successfully merging this pull request may close these issues.

message tool should auto-select the only enabled account

1 participant