Skip to content

fix(platform): reject duplicate platform IDs at load time - #9773

Open
weed33834 wants to merge 1 commit into
AstrBotDevs:masterfrom
weed33834:fix/duplicate-platform-id
Open

fix(platform): reject duplicate platform IDs at load time#9773
weed33834 wants to merge 1 commit into
AstrBotDevs:masterfrom
weed33834:fix/duplicate-platform-id

Conversation

@weed33834

@weed33834 weed33834 commented Aug 22, 2026

Copy link
Copy Markdown

Motivation

Fixes #9742. Proactive messages (cron jobs, send_message_to_user, etc.) are routed by platform ID and pick the first matching adapter instance. When a config contains two adapters with the same ID, every proactive send silently goes through the first adapter, i.e. the wrong QQ account.

BotConfigService.create_bot already rejects duplicate IDs at creation time (added in the FastAPI migration), but configs created before that change still load without any complaint and keep misrouting forever.

Modifications

  • �strbot/core/platform/manager.py: load_platform now skips an adapter whose ID is already loaded, with a loud error telling the user to rename one of the duplicated adapters.
  • ests/unit/test_platform_duplicate_id.py: tests for duplicate-ID skipping, distinct-ID loading, and disabled adapters not triggering the guard.

No breaking changes. No new dependencies.

Test Results

ext $ uvx --from ruff==0.15.22 ruff format --check . 501 files already formatted $ uvx --from ruff==0.15.22 ruff check . All checks passed! $ TESTING=true python -m pytest tests/unit/test_platform_duplicate_id.py tests/unit/test_core_lifecycle.py -q 29 passed $ python scripts/smoke_startup_check.py Smoke test passed

Full suite failure set is identical to a clean upstream master checkout; zero failures in touched modules.

Summary by Sourcery

Prevent duplicate platform IDs from being loaded so platform-based message routing remains unambiguous.

Bug Fixes:

  • Reject adapters with duplicate platform IDs during loading to prevent proactive messages from being routed to the wrong account.

Tests:

  • Add unit coverage for duplicate-ID rejection, distinct-ID loading, and disabled adapters.

Proactive messages are routed by platform ID and pick the first
matching adapter instance. When legacy configs contain two adapters
with the same ID, every proactive send silently goes through the
first adapter, i.e. the wrong QQ account (AstrBotDevs#9742). Creation-time
validation was added in the FastAPI migration, but configs created
before it still load without any complaint.

Skip duplicate-ID adapters at load time with a loud error so the ID
to account mapping stays unique.
@dosubot dosubot Bot added size:S This PR changes 10-29 lines, ignoring generated files. area:platform The bug / feature is about IM platform adapter, such as QQ, Lark, Telegram, WebChat and so on. labels Aug 22, 2026

@sourcery-ai sourcery-ai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey - I've reviewed your changes and they look great!

Sourcery assessment

Approved.


Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

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

Labels

area:platform The bug / feature is about IM platform adapter, such as QQ, Lark, Telegram, WebChat and so on. size:S This PR changes 10-29 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug] 创建同为aiocqhttp的适配器,不能在正确的账号上操作

1 participant