Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 18 additions & 13 deletions src/vision/describe.ts
Original file line number Diff line number Diff line change
Expand Up @@ -102,26 +102,31 @@ export async function describeImage(
}),
{ abortSignal: linkedSignal.signal, label: "vision-sidecar" },
);
recordOutcome?.(res.status);
if (!res.ok) {
const t = await res.text().catch(() => "");
console.warn(`[vision] sidecar HTTP ${res.status} (${Date.now() - t0}ms)`);
return { text: "", error: `vision sidecar HTTP ${res.status}: ${redactSecretString(t.slice(0, 200))}` };
}
const detachBodyGuard = cancelBodyOnAbort(res.body, linkedSignal.signal);
let parsed;
try {
parsed = await parseSidecarSSE(res);
if (!res.ok) {
recordOutcome?.(res.status);
const t = await res.text().catch(() => "");
console.warn(`[vision] sidecar HTTP ${res.status} (${Date.now() - t0}ms)`);
return { text: "", error: `vision sidecar HTTP ${res.status}: ${redactSecretString(t.slice(0, 200))}` };
}
const parsed = await parseSidecarSSE(res);
if (linkedSignal.signal.aborted) throw linkedSignal.signal.reason;
recordOutcome?.(res.status);
// The backend can return HTTP 200 then stream a `response.failed`/`error` event with no text;
// surface that as a describe error instead of an empty (silently-blank) description.
if (!parsed.text.trim() && parsed.error) return { text: "", error: parsed.error };
return { text: parsed.text };
} finally {
detachBodyGuard();
}
// The backend can return HTTP 200 then stream a `response.failed`/`error` event with no text;
// surface that as a describe error instead of an empty (silently-blank) description.
if (!parsed.text.trim() && parsed.error) return { text: "", error: parsed.error };
return { text: parsed.text };
} catch (e) {
recordOutcome?.(e instanceof Error && e.name === "TimeoutError" ? "timeout" : "connect_error");
const kind = e instanceof Error && e.name === "TimeoutError" ? "timeout" : "connect_error";
const callerAborted = abortSignal?.aborted === true
&& linkedSignal.signal.aborted
&& linkedSignal.signal.reason === abortSignal.reason
&& e === linkedSignal.signal.reason;
recordOutcome?.(callerAborted ? "connect_neutral" : kind);
Comment thread
luvs01 marked this conversation as resolved.
console.warn(`[vision] sidecar ${kind} (${Date.now() - t0}ms)`);
return { text: "", error: e instanceof Error ? e.message : String(e) };
} finally {
Expand Down
13 changes: 10 additions & 3 deletions src/web-search/executor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -85,25 +85,32 @@ export async function runWebSearch(
}),
{ abortSignal: linkedSignal.signal, label: "web-search-sidecar" },
);
recordOutcome?.(res.status);
// Attach the body guard before ANY branch reads it. The success path guarded itself below,
// but the failure branch's `res.text()` runs first, so a cancel landing between fetch
// resolution and reader attach orphaned the internal rejection (found investigating #1419).
const detachBodyGuard = cancelBodyOnAbort(res.body, linkedSignal.signal);
if (!res.ok) {
recordOutcome?.(res.status);
const t = await res.text().catch(() => "");
detachBodyGuard();
console.warn(`[web-search] sidecar HTTP ${res.status} for query "${query.slice(0, 80)}" (${Date.now() - t0}ms)`);
return { text: "", sources: [], error: `sidecar HTTP ${res.status}: ${redactSecretString(t.slice(0, 200))}` };
}
try {
return await parseSidecarSSE(res);
const parsed = await parseSidecarSSE(res);
if (linkedSignal.signal.aborted) throw linkedSignal.signal.reason;
recordOutcome?.(res.status);
return parsed;
} finally {
detachBodyGuard();
}
} catch (e) {
recordOutcome?.(e instanceof Error && e.name === "TimeoutError" ? "timeout" : "connect_error");
const kind = e instanceof Error && e.name === "TimeoutError" ? "timeout" : "connect_error";
const callerAborted = abortSignal?.aborted === true
&& linkedSignal.signal.aborted
&& linkedSignal.signal.reason === abortSignal.reason
&& e === linkedSignal.signal.reason;
recordOutcome?.(callerAborted ? "connect_neutral" : kind);
Comment thread
luvs01 marked this conversation as resolved.
console.warn(`[web-search] sidecar ${kind} for query "${query.slice(0, 80)}" (${Date.now() - t0}ms)`);
return { text: "", sources: [], error: e instanceof Error ? e.message : String(e) };
} finally {
Expand Down
Loading
Loading