Skip to content

fix(discord): show live bot connection status - #2250

Open
Zchary1106 wants to merge 3 commits into
moeru-ai:mainfrom
Zchary1106:codex/fix-discord-status-2243
Open

fix(discord): show live bot connection status#2250
Zchary1106 wants to merge 3 commits into
moeru-ai:mainfrom
Zchary1106:codex/fix-discord-status-2243

Conversation

@Zchary1106

Copy link
Copy Markdown

Summary

  • Publish Discord adapter lifecycle events only after an actual Discord gateway connection is ready, and publish non-ready events for disabled, missing-token, failed, and disconnected states.
  • Listen for Discord module status in the settings store and show the green configuration indicator only while the bot is live.
  • Fix the adapter's readiness checks to call Client#isReady().
  • Add focused Discord adapter connection-status tests and a package test command.

Validation

  • pnpm --filter @proj-airi/discord-bot test
  • pnpm --filter @proj-airi/discord-bot typecheck
  • pnpm 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.ts
  • git diff --check

Fixes #2243

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

馃挕 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".

Comment thread packages/stage-ui/src/stores/modules/discord.ts
'module:announced',
'module:configure',
'module:de-announced',
'module:status',

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge 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 馃憤聽/ 馃憥.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

fixed

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

馃挕 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)

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge 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 馃憤聽/ 馃憥.

Comment on lines 123 to 126
if (this.discordClient.isReady()) {
log.log('Disabling Discord bot as per configuration...')
await this.discordClient.destroy()
}

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge 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>

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

馃挕 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) => {

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge 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')

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge 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 馃憤聽/ 馃憥.

@lietblue lietblue added bug Something isn't working extension/channel-discord Official supported extensions, related to Discord channel pr-review/well-informed Pull Request that well described, with screenshots or tests, or explained well, easier to review scope/extension Scope related to extension api, or internally known as tentacle api, mod api, plugin api scope/ui Scope related to UI/UX, or interface improve, perf, and bugs and removed pr-review/well-informed Pull Request that well described, with screenshots or tests, or explained well, easier to review labels Aug 13, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working extension/channel-discord Official supported extensions, related to Discord channel scope/extension Scope related to extension api, or internally known as tentacle api, mod api, plugin api scope/ui Scope related to UI/UX, or interface improve, perf, and bugs

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Discord status not correct

2 participants