Skip to content

fix(mattermost): anchor slash command state to globalThis to fix dual-instance 503s#69038

Closed
hieptuanle wants to merge 1 commit into
openclaw:mainfrom
hieptuanle:fix/mattermost-slash-state-dual-instance
Closed

fix(mattermost): anchor slash command state to globalThis to fix dual-instance 503s#69038
hieptuanle wants to merge 1 commit into
openclaw:mainfrom
hieptuanle:fix/mattermost-slash-state-dual-instance

Conversation

@hieptuanle

@hieptuanle hieptuanle commented Apr 19, 2026

Copy link
Copy Markdown

Summary

Fixes #68113

  • Mattermost slash command callbacks always returned 503 ("not yet initialized") even after successful registration, because accountStates in slash-state.ts was a plain module-level Map that got instantiated twice — once by jiti (route registration path via loadBundledEntryExportSync) and once by native ESM (monitor/activation path via dynamic import()).
  • Fix: anchor accountStates to globalThis via Symbol.for() so both module loader instances share the same Map.

Test plan

  • pnpm test:extension mattermost — all 319 tests pass
  • pnpm check — all type, lint, import-cycle checks pass
  • pnpm build — clean build, no warnings
  • Manually verified on a live Mattermost instance: slash commands now respond correctly after gateway startup

🤖 Generated with Claude Code

…fix dual-instance bug

Route registration (jiti) and monitor activation (native ESM) load
slash-state.ts through different module loaders, creating two separate
accountStates Maps. The monitor populates one copy while the HTTP
handler reads the other (always empty), causing 503 responses for all
slash command callbacks.

Anchor accountStates to globalThis via Symbol.for() so both module
instances share the same Map.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@openclaw-barnacle openclaw-barnacle Bot added channel: mattermost Channel integration: mattermost size: XS labels Apr 19, 2026
@greptile-apps

greptile-apps Bot commented Apr 19, 2026

Copy link
Copy Markdown
Contributor

Greptile Summary

This PR fixes a dual-instance 503 regression in the Mattermost slash command flow by anchoring the shared accountStates Map to globalThis via Symbol.for(). The root cause — two distinct module loader instances (jiti and native ESM) each holding their own copy of the module-level Map — is correctly diagnosed, and the fix follows the established Node.js pattern for sharing singleton state across module loader boundaries.

Confidence Score: 5/5

Safe to merge — minimal, well-scoped change with a clear rationale and a passing test suite.

The fix is technically correct: Symbol.for() guarantees the same Symbol across module instances, and the ??= initializer ensures only one Map is ever created on globalThis. No logic changes elsewhere, no new surface area introduced, and all 319 extension tests pass.

No files require special attention.

Reviews (1): Last reviewed commit: "fix(mattermost): anchor slash command ac..." | Re-trigger Greptile

@ForceConstant

Copy link
Copy Markdown

Please merge

@Smith4545

Copy link
Copy Markdown

Please please merge

@ForceConstant

Copy link
Copy Markdown

Any updates on this?

@clawsweeper

clawsweeper Bot commented Apr 28, 2026

Copy link
Copy Markdown
Contributor

Thanks for the context here. I swept through the related work, and this is now duplicate or superseded.

This PR is a duplicate implementation candidate for the Mattermost native slash-command 503 regression already tracked by open PR #68089 and bug #68113. Current main still has the old dynamic loader plus module-local state, so the bug is not implemented-on-main; cleanup should consolidate review on the earlier, root-cause PR or an equivalent maintainer-owned fix.

Best possible solution:

Close this duplicate PR and consolidate maintainer review on #68089, or land an equivalent root-cause fix that makes route registration and monitor activation share one Mattermost slash-state module instance. Keep #68113 open until the selected fix merges and ships.

What I checked:

So I’m closing this here and keeping the remaining discussion on the canonical linked item.

Codex review notes: model gpt-5.5, reasoning high; reviewed against 7a23b2d945cc.

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

Labels

channel: mattermost Channel integration: mattermost size: XS

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: Mattermost slash commands return 503 "not yet initialized" in v2026.4.15

3 participants