From d18f9abdd60cbc62a7d619eeada1f7991644491f Mon Sep 17 00:00:00 2001 From: diegosouzapw Date: Fri, 12 Jun 2026 11:49:31 -0300 Subject: [PATCH] =?UTF-8?q?fix(sse):=20make=20safeLogEvents=20async=20?= =?UTF-8?q?=E2=80=94=20'await'=20in=20a=20sync=20function=20broke=20every?= =?UTF-8?q?=20chatHelpers=20import?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit #3692 added a lazy 'await import(proxyEgress)' for egress-IP visibility inside safeLogEvents, which is a sync function — an ES syntax error. It went unnoticed because typecheck:core does not cover src/sse and no test in the merge gates loaded chatHelpers via tsx; any consumer that did (chat-context-relay and chat-route-coverage suites, integration harnesses) failed at module load with 'await can only be used inside an async function'. safeLogEvents is fire-and-forget logging with an outer try/catch, so making it async (and 'void'-ing the single chat.ts call site) preserves behavior exactly. Validation: tests/unit/chat-context-relay.test.ts + chat-route-coverage.test.ts went from failing-at-load to green (+14 tests destravados). --- src/sse/handlers/chat.ts | 4 ++-- src/sse/handlers/chatHelpers.ts | 4 +++- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/src/sse/handlers/chat.ts b/src/sse/handlers/chat.ts index 941d9f5290..778f6b2883 100644 --- a/src/sse/handlers/chat.ts +++ b/src/sse/handlers/chat.ts @@ -1058,8 +1058,8 @@ async function handleSingleModelChat( getTargetFormat(provider, credentials.providerSpecificData) || targetFormat; - // 5. Log proxy + translation events - safeLogEvents({ + // 5. Log proxy + translation events (fire-and-forget; never blocks the response) + void safeLogEvents({ result, proxyInfo, proxyLatency, diff --git a/src/sse/handlers/chatHelpers.ts b/src/sse/handlers/chatHelpers.ts index 3c4756d7ce..678a387de6 100644 --- a/src/sse/handlers/chatHelpers.ts +++ b/src/sse/handlers/chatHelpers.ts @@ -592,7 +592,9 @@ export async function safeResolveProxy(connectionId: string, apiKeyId?: string) } } -export function safeLogEvents({ +// Async because the egress-IP lookup lazy-imports proxyEgress; callers treat +// this as fire-and-forget logging (the internal try/catch swallows everything). +export async function safeLogEvents({ result, proxyInfo, proxyLatency,