diff --git a/CHANGELOG.md b/CHANGELOG.md index 67836fd68b4..baca2665007 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -194,6 +194,7 @@ Docs: https://docs.openclaw.ai - Agents/replay: sanitize malformed assistant tool-call replay blocks before provider replay so follow-up Anthropic requests do not inherit the downstream `replace` crash. (#50005) Thanks @jalehman. - Plugins/context engines: retry strict legacy `assemble()` calls without the new `prompt` field when older engines reject it, preserving prompt-aware retrieval compatibility for pre-prompt plugins. (#50848) thanks @danhdoan. - Agents/embedded transport errors: distinguish common network failures like connection refused, DNS lookup failure, and interrupted sockets from true timeouts in embedded-run user messaging and lifecycle diagnostics. (#51419) Thanks @scoootscooob. +- Discord/startup logging: report client initialization while the gateway is still connecting instead of claiming Discord is logged in before readiness is reached. (#51425) Thanks @scoootscooob. ### Breaking diff --git a/extensions/discord/src/monitor/provider.ts b/extensions/discord/src/monitor/provider.ts index 523f7c54c36..8388438f37d 100644 --- a/extensions/discord/src/monitor/provider.ts +++ b/extensions/discord/src/monitor/provider.ts @@ -92,6 +92,7 @@ import { resolveDiscordPresenceUpdate } from "./presence.js"; import { resolveDiscordAllowlistConfig } from "./provider.allowlist.js"; import { runDiscordGatewayLifecycle } from "./provider.lifecycle.js"; import { resolveDiscordRestFetch } from "./rest-fetch.js"; +import { formatDiscordStartupStatusMessage } from "./startup-status.js"; import type { DiscordMonitorStatusSink } from "./status.js"; import { createNoopThreadBindingManager, @@ -972,7 +973,12 @@ export async function monitorDiscordProvider(opts: MonitorDiscordOpts = {}) { const botIdentity = botUserId && botUserName ? `${botUserId} (${botUserName})` : (botUserId ?? botUserName ?? ""); - runtime.log?.(`logged in to discord${botIdentity ? ` as ${botIdentity}` : ""}`); + runtime.log?.( + formatDiscordStartupStatusMessage({ + gatewayReady: lifecycleGateway?.isConnected === true, + botIdentity: botIdentity || undefined, + }), + ); if (lifecycleGateway?.isConnected) { opts.setStatus?.(createConnectedChannelStatusPatch()); } diff --git a/extensions/discord/src/monitor/startup-status.test.ts b/extensions/discord/src/monitor/startup-status.test.ts new file mode 100644 index 00000000000..47cc84202d6 --- /dev/null +++ b/extensions/discord/src/monitor/startup-status.test.ts @@ -0,0 +1,30 @@ +import { describe, expect, it } from "vitest"; +import { formatDiscordStartupStatusMessage } from "./startup-status.js"; + +describe("formatDiscordStartupStatusMessage", () => { + it("reports logged-in status only after the gateway is ready", () => { + expect( + formatDiscordStartupStatusMessage({ + gatewayReady: true, + botIdentity: "bot-1 (Molty)", + }), + ).toBe("logged in to discord as bot-1 (Molty)"); + }); + + it("reports client initialization while gateway readiness is still pending", () => { + expect( + formatDiscordStartupStatusMessage({ + gatewayReady: false, + botIdentity: "bot-1 (Molty)", + }), + ).toBe("discord client initialized as bot-1 (Molty); awaiting gateway readiness"); + }); + + it("handles missing identity without awkward punctuation", () => { + expect( + formatDiscordStartupStatusMessage({ + gatewayReady: false, + }), + ).toBe("discord client initialized; awaiting gateway readiness"); + }); +}); diff --git a/extensions/discord/src/monitor/startup-status.ts b/extensions/discord/src/monitor/startup-status.ts new file mode 100644 index 00000000000..94f311912b8 --- /dev/null +++ b/extensions/discord/src/monitor/startup-status.ts @@ -0,0 +1,10 @@ +export function formatDiscordStartupStatusMessage(params: { + gatewayReady: boolean; + botIdentity?: string; +}): string { + const identitySuffix = params.botIdentity ? ` as ${params.botIdentity}` : ""; + if (params.gatewayReady) { + return `logged in to discord${identitySuffix}`; + } + return `discord client initialized${identitySuffix}; awaiting gateway readiness`; +}