From 28a1e8421def818fb6d7b208a5115f99a976a2dc Mon Sep 17 00:00:00 2001 From: Thomas Camlong Date: Fri, 7 Aug 2026 14:59:16 +0200 Subject: [PATCH] fix: handle missing message in assistant generation telemetry getGenerationTelemetry threw NOT_FOUND when the stored message id did not match a persisted message (e.g. the assistant message is still streaming or was just removed), surfacing as a failed tRPC query in the console. Return an empty complete result instead, matching the existing graceful handling for providers without OpenRouter telemetry, and only fire the client query once both threadId and messageId are available. --- apps/nextjs/src/components/assistant/assistant-panel.tsx | 2 +- packages/api/src/router/assistant.ts | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/apps/nextjs/src/components/assistant/assistant-panel.tsx b/apps/nextjs/src/components/assistant/assistant-panel.tsx index e7efa70a7..c64cb11b0 100644 --- a/apps/nextjs/src/components/assistant/assistant-panel.tsx +++ b/apps/nextjs/src/components/assistant/assistant-panel.tsx @@ -930,7 +930,7 @@ const RequestTelemetry = () => { const generationQuery = clientApi.assistant.getGenerationTelemetry.useQuery( { threadId: threadId ?? "", messageId }, { - enabled: opened && persistedTelemetry?.provider === "openrouter" && Boolean(threadId), + enabled: opened && persistedTelemetry?.provider === "openrouter" && Boolean(threadId) && Boolean(messageId), refetchInterval: (query) => query.state.data?.complete === false && query.state.dataUpdateCount < 6 ? 1500 : false, retry: 2, diff --git a/packages/api/src/router/assistant.ts b/packages/api/src/router/assistant.ts index f06fef768..3c7957d29 100644 --- a/packages/api/src/router/assistant.ts +++ b/packages/api/src/router/assistant.ts @@ -738,7 +738,7 @@ export const assistantRouter = createTRPCRouter({ }), getConfigurationAsync(ctx.db), ]); - if (!message) throw new TRPCError({ code: "NOT_FOUND", message: "Message not found." }); + if (!message) return { complete: true, generations: [] }; if (configuration?.provider !== "openrouter" || !configuration.encryptedApiKey) { return { complete: true, generations: [] }; }