mirror of
https://github.com/MBombeck/HealthLog.git
synced 2026-11-18 08:02:12 +00:00
fix(ai): ask a thinking model again when it answered with reasoning alone
Ollama serves thinking models such as Gemma 4 on /v1/chat/completions with the thought in a separate `reasoning` field. A long briefing can come back with empty `content`: the thought used the whole token budget, or the answer itself was parsed into `reasoning`. The background briefing always asks to reason, so every briefing on such a model ended in the empty-reply sentinel, which the chain logged as status 0 / cause "network" in the same second the server logged 200, and the read path showed as a timeout. The Local client and the OpenAI-compatible gateway now treat a reply with reasoning and no answer as a lesson: the endpoint and model are remembered in the reasoning dialect cache as answering only unreasoned, the call is asked once more with reasoning_effort "none", and later calls ask that way until the lesson expires. A test drives the real client, safeFetch and the pinned dispatcher against a loopback server that answers the way Ollama serves Gemma 4, and reproduces the reported log line without the fix. Failed hops now carry what the call ran into: `failure` (timeout, aborted, refused, reset, socket, parse, empty_response, reasoning_only, ...) and a code-shaped `code` on ai.chain.link_failed, closed vocabulary only. The cause only says "timeout" for a deadline, and the briefing failure marker records the kind so the empty state suggests a longer timeout only when time ran out. Refs #1267
This commit is contained in:
1 parent
bb3ee6b855
commit
221960af88
11 files changed
+1040
-51
No files matched your search
@@ -64,6 +64,7 @@ import { resolveUserTimezone } from "@/lib/tz/resolver";
|
||||
import { insightResultSchema, type InsightResult } from "@/lib/ai/types";
|
||||
import { AI_BUDGETS, resolveInsightsMaxTokens } from "@/lib/ai/ai-budgets";
|
||||
import { resolveEffectiveTimeoutMs } from "@/lib/ai/effective-timeout";
|
||||
import { providerFailureKind } from "@/lib/ai/failure-kind";
|
||||
import {
|
||||
recordBriefingFailure,
|
||||
readBriefingFailure,
|
||||
@@ -855,6 +856,10 @@ export const POST = apiHandler((request: NextRequest) =>
|
||||
: "provider-error",
|
||||
locale,
|
||||
httpStatus: failureHttpStatus,
|
||||
failureKind:
|
||||
e instanceof AllProvidersFailedError
|
||||
? (e.attempts[0]?.failureKind ?? null)
|
||||
: providerFailureKind(e).failure,
|
||||
});
|
||||
if (e instanceof AllProvidersFailedError) {
|
||||
annotate({
|
||||
|
||||
Reference in new issue
Block a user