Skip to content

fix(channels): avoid built-in channel ID init cycles#48839

Open
MarsDoge wants to merge 1 commit intoopenclaw:mainfrom
MarsDoge:fix/issue-48832-channel-ids-init
Open

fix(channels): avoid built-in channel ID init cycles#48839
MarsDoge wants to merge 1 commit intoopenclaw:mainfrom
MarsDoge:fix/issue-48832-channel-ids-init

Conversation

@MarsDoge
Copy link
Copy Markdown

@MarsDoge MarsDoge commented Mar 17, 2026

Summary

  • import built-in channel ID constants from the leaf channels/ids module in config/CLI helpers and plugin sorting code
  • keep runtime helpers like normalizeAnyChannelId on channels/registry while avoiding eager constant reads through that heavier module
  • reduce the risk of bundled initialization order regressions that can surface as CHANNEL_IDS / CHAT_CHANNEL_ORDER not iterable during startup

Change Type

  • bug fix

Scope

  • channel ID imports for config validation, CLI channel option resolution, elevated allowlist matching, and channel plugin ordering

User-visible / Behavior Changes

  • startup/build outputs no longer depend on channels/registry to initialize built-in channel ID arrays before config validation and plugin sorting read them
  • fixes Windows startup regression where bundled builds could throw Cannot access 'CHANNEL_IDS' before initialization / CHAT_CHANNEL_ORDER is not iterable

Test plan

  • node scripts/tsdown-build.mjs
  • pnpm exec tsx -e "(async()=>{ const [{CHANNEL_IDS,CHAT_CHANNEL_ORDER}] = await Promise.all([import('./src/channels/registry.ts'), import('./src/config/validation.ts')]); console.log('CHANNEL_IDS', Array.isArray(CHANNEL_IDS), CHANNEL_IDS.length); console.log('CHAT_CHANNEL_ORDER', Array.isArray(CHAT_CHANNEL_ORDER), CHAT_CHANNEL_ORDER.length); })().catch(err=>{ console.error(err); process.exit(1); });"

Closes #48832

@openclaw-barnacle openclaw-barnacle bot added cli CLI command changes size: XS labels Mar 17, 2026
@greptile-apps
Copy link
Copy Markdown
Contributor

greptile-apps bot commented Mar 17, 2026

Greptile Summary

This PR breaks potential module initialization cycles on Windows bundled builds by redirecting imports of the CHANNEL_IDS and CHAT_CHANNEL_ORDER constants to the lighter-weight leaf module src/channels/ids.ts instead of routing through src/channels/registry.ts. The registry.ts module re-exports those constants from ids.ts (so existing callers remain unaffected), but eagerly requiring it also pulls in plugin runtime state machinery — which can produce undefined/null not-iterable startup errors when the module evaluation order in a bundle happens to read those arrays before they are initialized.

Key changes:

  • src/channels/ids.ts is established as the single source of truth for built-in channel ID constants (CHAT_CHANNEL_ORDER, CHANNEL_IDS, ChatChannelId).
  • Six files that only needed the constants — config schema, config validation, CLI channel options, elevated-allowlist matcher, plugin registry sorter, and setup-registry sorter — are updated to import directly from ids.ts.
  • Runtime helpers (normalizeAnyChannelId, normalizeChatChannelId) that legitimately depend on registry state are retained on registry.ts imports unchanged.
  • src/channels/registry.ts continues to re-export the constants from ids.ts, so all other call-sites continue to work without changes.

Confidence Score: 5/5

  • Safe to merge — a clean, minimal import-path refactor with no behavioral changes.
  • Every changed file only redirects constant imports (CHANNEL_IDS, CHAT_CHANNEL_ORDER) from registry.ts to the new leaf ids.ts. All runtime helper calls (normalizeChatChannelId, normalizeAnyChannelId) are correctly kept pointing at registry.ts. The registry.ts still re-exports those constants from ids.ts, so the wider codebase is unaffected. No logic was altered, no new state was introduced, and the fix directly addresses the described Windows bundled-build startup regression.
  • No files require special attention.

Last reviewed commit: 2f3e7c0

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

Labels

cli CLI command changes size: XS

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]:[Windows] Module initialization error: CHANNEL_IDS not iterable on startup

1 participant