fix(discord): show live bot connection status - #2250
Conversation
There was a problem hiding this comment.
馃挕 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 251089f26c
鈩癸笍 About Codex in GitHub
Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 馃憤.
When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".
| 'module:announced', | ||
| 'module:configure', | ||
| 'module:de-announced', | ||
| 'module:status', |
There was a problem hiding this comment.
Replay module status for late subscribers
Because App.vue initializes useModsServerChannelStore at startup, module:status can arrive before useDiscordStore is created; registerListener only replays types in REPLAYABLE_EVENT_TYPES, and this adds module:status to the subscribed events without making it replayable. If the bot publishes ready before the user opens the Discord settings or modules page, connected stays false until another status transition, so the live indicator remains off. Snapshot/replay module status or initialize this listener before connecting.
Useful? React with 馃憤聽/ 馃憥.
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
There was a problem hiding this comment.
馃挕 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 7ed5afd8d2
鈩癸笍 About Codex in GitHub
Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 馃憤.
When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".
| if (REPLAYABLE_EVENT_TYPES.has(event.type as keyof WebSocketEvents)) | ||
| if (event.type === 'module:status') { | ||
| const moduleStatusEvent = event as WebSocketBaseEvent<'module:status', WebSocketEvents['module:status']> | ||
| moduleStatusEvents.set(moduleStatusEvent.data.identity.id, moduleStatusEvent) |
There was a problem hiding this comment.
Clear module status when modules disappear
When a module process disappears without sending its own module:status update (for example the Discord bot process crashes or its websocket closes), the server cleanup path broadcasts extension:module:de-announced from packages/server-runtime/src/index.ts:435, but this cache keeps the previous status and replays it to later subscribers. A Discord settings store opened after that disconnect can receive the stale ready status and set connected back to true, so clear the cached module status when the matching module is de-announced or removed from the registry.
Useful? React with 馃憤聽/ 馃憥.
| if (this.discordClient.isReady()) { | ||
| log.log('Disabling Discord bot as per configuration...') | ||
| await this.discordClient.destroy() | ||
| } |
There was a problem hiding this comment.
Stop the client even before it is ready
If the user disables Discord while the client is still connecting or reconnecting, isReady() is false, so this branch publishes configuration-needed but leaves the in-flight Discord gateway session alive; when that session later reaches ClientReady, the new handler publishes ready and the bot remains online despite the disabled setting. Call destroy() for an existing connection attempt as well as for a ready client, and apply the same shutdown rule to the missing-token path.
Useful? React with 馃憤聽/ 馃憥.
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
There was a problem hiding this comment.
馃挕 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: c6ef237111
鈩癸笍 About Codex in GitHub
Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 馃憤.
When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".
| const connected = ref(false) | ||
| const modsChannel = useModsServerChannelStore() | ||
|
|
||
| modsChannel.onEvent('module:status', (event) => { |
There was a problem hiding this comment.
Clear connected state when the module de-announces
Fresh evidence after the cache fix: this store only listens to module:status, while the server cleanup path sends extension:module:de-announced when the Discord process disappears without a final status. In an already-open settings page or modules grid, connected stays true because deleting the replay cache in channel-server does not call this listener. Listen for the de-announced or unhealthy event, or synthesize a non-ready status when that event arrives.
Useful? React with 馃憤聽/ 馃憥.
| } | ||
|
|
||
| log.log(`Discord bot ready! User: ${readyClient.user.tag}`) | ||
| this.publishConnectionStatus('ready') |
There was a problem hiding this comment.
Replay ready status to peers that connect later
This publishes ready only at Discord's ClientReady event, so a stage UI peer that connects after the bot is already ready never receives the live status. The server registry sync only lists modules, not their last module:status, and the new client-side cache can replay only events that this UI client already saw. As a result, opening the app after the bot has started leaves the Discord card disconnected until another status transition occurs.
Useful? React with 馃憤聽/ 馃憥.
Summary
Client#isReady().Validation
pnpm --filter @proj-airi/discord-bot testpnpm --filter @proj-airi/discord-bot typecheckpnpm exec eslint integrations/discord-bot/src/adapters/airi-adapter.ts integrations/discord-bot/src/adapters/airi-adapter.test.ts integrations/discord-bot/vitest.config.ts packages/stage-ui/src/stores/modules/discord.ts packages/stage-ui/src/components/modules/MessagingDiscord.vue packages/stage-ui/src/stores/mods/api/channel-server.tsgit diff --checkFixes #2243