From e108db43012743ec7ca82ff9b9b6210dc9a00d02 Mon Sep 17 00:00:00 2001 From: Jonas Jesus Date: Tue, 7 Apr 2026 18:16:02 -0300 Subject: [PATCH 1/2] fix(discord): update primary instance env when onChange fires for shared-client connections MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Bootstrap starts bots with empty state (no AGENT config). When multiple connections share the same client, onChange only updated the calling connection's env — but event handlers use the primary instance's env. Now onChange also updates the primary (client-owning) instance's env so the bot has the correct AGENT config, system prompt, etc. Co-Authored-By: Claude Opus 4.6 --- discord-read/server/main.ts | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/discord-read/server/main.ts b/discord-read/server/main.ts index a451522e..198c81c8 100644 --- a/discord-read/server/main.ts +++ b/discord-read/server/main.ts @@ -184,6 +184,25 @@ const runtime = withRuntime({ const hasAuth = !!env.MESH_REQUEST_CONTEXT?.authorization; if (hasAuth) { if (isBotRunning(env)) { + // Bot is already running (possibly via shared client from bootstrap). + // Update the primary instance's env so event handlers get fresh state + // (AGENT config, system prompt, etc.) instead of the empty bootstrap state. + if (connectionId) { + const currentInstance = getInstance(connectionId); + if (currentInstance?.client) { + const { getInstanceByClient } = await import("./bot-instance.ts"); + const ownerInstance = getInstanceByClient(currentInstance.client); + if ( + ownerInstance && + ownerInstance.connectionId !== connectionId + ) { + ownerInstance.env = env; + console.log( + `[CONFIG] Updated primary instance ${ownerInstance.connectionId} env from ${connectionId} onChange`, + ); + } + } + } console.log( `[CONFIG] Bot already running for ${connectionId || "unknown"}`, ); From 33b14877d2ac6bad705101fea314d516b410c3d5 Mon Sep 17 00:00:00 2001 From: Jonas Jesus Date: Tue, 7 Apr 2026 18:20:51 -0300 Subject: [PATCH 2/2] chore(discord): remove unused CONNECTION binding and HYPERDX_API_KEY from StateSchema CONNECTION (BindingOf) was declared but never used in server code. HYPERDX_API_KEY is already read from process.env in the logger, making the StateSchema field redundant with the Kubernetes env var. Co-Authored-By: Claude Opus 4.6 --- discord-read/server/main.ts | 9 --------- discord-read/server/types/env.ts | 13 +------------ 2 files changed, 1 insertion(+), 21 deletions(-) diff --git a/discord-read/server/main.ts b/discord-read/server/main.ts index 198c81c8..faaa9917 100644 --- a/discord-read/server/main.ts +++ b/discord-read/server/main.ts @@ -71,15 +71,6 @@ const runtime = withRuntime({ const organizationId = env.MESH_REQUEST_CONTEXT?.organizationId; const token = env.MESH_REQUEST_CONTEXT?.token; - // Configure HyperDX logger if API key is provided - if (state?.HYPERDX_API_KEY) { - logger.setApiKey(state.HYPERDX_API_KEY); - logger.info("HyperDX logger configured", { - trace_id: traceId, - organizationId, - }); - } - // Database tables are managed via Supabase console.log("[Setup] Skipping database initialization (using Supabase)"); diff --git a/discord-read/server/types/env.ts b/discord-read/server/types/env.ts index f46b8324..4b151810 100644 --- a/discord-read/server/types/env.ts +++ b/discord-read/server/types/env.ts @@ -3,13 +3,10 @@ */ import type { Registry } from "@decocms/mcps-shared/registry"; -import { AgentOf, BindingOf, type DefaultEnv } from "@decocms/runtime"; +import { AgentOf, type DefaultEnv } from "@decocms/runtime"; import z from "zod"; export const StateSchema = z.object({ - // Bindings obrigatórias - CONNECTION: BindingOf("@deco/connection"), - // AI Configuration — AgentOf() resolves to a client with .STREAM() AGENT: AgentOf(), @@ -138,14 +135,6 @@ export const StateSchema = z.object({ }) .optional() .describe("How the bot responds to messages"), - - // HyperDX Configuration - HYPERDX_API_KEY: z - .string() - .optional() - .describe( - "HyperDX API key for advanced logging and observability. If not provided, logs will only go to stdout.", - ), }); export type Env = DefaultEnv;