fix(insights): cancel the Coach tool-loop provider calls on disconnect

Thread the request abort signal through runCoachToolLoop into each
per-round completion so a mid-generation client disconnect tears down
the upstream call instead of paying the full token cost. Completes the
no-tools-path wiring to cover the tool-retrieval path as well.

Regenerate the OpenAPI spec for the trimmed OCR-capability reason enum.
This commit is contained in:
Marc-André Bombeck committed 2026-06-26 09:30:08 +02:00
1 parent ca1cf53d2c
commit bf29ab1e0e
3 files changed
+7 -1

No files matched your search

-1
View File
@@ -19630,7 +19630,6 @@ components:
- type: string - type: string
enum: enum:
- no-provider - no-provider
- text-only-model
- enable-local-ocr - enable-local-ocr
- type: "null" - type: "null"
pdfSupported: pdfSupported:
+3
View File
@@ -549,6 +549,9 @@ Reply now as the assistant, in ${locale === "de" ? "German" : "English"}. Fetch
temperature: AI_BUDGETS.coach.temperature, temperature: AI_BUDGETS.coach.temperature,
maxTokens: AI_BUDGETS.coach.maxTokens, maxTokens: AI_BUDGETS.coach.maxTokens,
fallbackWindow: effectiveScope?.window, fallbackWindow: effectiveScope?.window,
// v1.20.1 — thread the abort signal so a mid-generation disconnect tears
// down the per-round provider calls instead of paying the full cost.
signal: request.signal,
}); });
result = loop.result; result = loop.result;
workingProviderType = loop.workingProviderType; workingProviderType = loop.workingProviderType;
+4
View File
@@ -58,6 +58,8 @@ export async function runCoachToolLoop(args: {
maxTokens?: number; maxTokens?: number;
fallbackWindow?: CoachScopeWindow; fallbackWindow?: CoachScopeWindow;
ledger?: ProviderHealthLedger; ledger?: ProviderHealthLedger;
/** Aborts the per-round provider calls on client disconnect. */
signal?: AbortSignal;
}): Promise<CoachToolLoopResult> { }): Promise<CoachToolLoopResult> {
const { const {
userId, userId,
@@ -68,6 +70,7 @@ export async function runCoachToolLoop(args: {
maxTokens, maxTokens,
fallbackWindow, fallbackWindow,
ledger, ledger,
signal,
} = args; } = args;
const messages: AiMessage[] = [...args.messages]; const messages: AiMessage[] = [...args.messages];
@@ -92,6 +95,7 @@ export async function runCoachToolLoop(args: {
messages, messages,
temperature, temperature,
maxTokens, maxTokens,
signal,
...(offerTools ...(offerTools
? { tools, toolChoice: "auto" as const } ? { tools, toolChoice: "auto" as const }
: { toolChoice: "none" as const }), : { toolChoice: "none" as const }),