fix(sse): make safeLogEvents async — 'await' in a sync function broke every chatHelpers import

#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).
This commit is contained in:
diegosouzapw
2026-06-12 11:49:31 -03:00
parent 62eb7fe463
commit d18f9abdd6
2 changed files with 5 additions and 3 deletions

View File

@@ -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,

View File

@@ -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,