fix(llm-test): an unreported reasoning-token counter is not a warning

Measured against the gateway this deployment actually uses (ai.lago.dev), a
"Reply with OK" request comes back with usage.completion_tokens_details: {} --
the provider does not report a reasoning counter at all. Thinking is
verifiably off there (2 completion tokens, 424 ms, versus ~235 tokens and
~3.5x latency when on), but reasoning_tokens is undefined, not 0.

The verdict had two states, so a healthy production connection rendered amber
with "the model is still thinking" -- the button would have reported a working
configuration as broken. The reasoning verdict is now three-state:

- reported 0        -> reasoning_disabled: true, green
- not reported      -> reasoning_tokens: null, no warning, neutral card that
                       says it cannot be confirmed from the usage block
- reported and > 0  -> amber + the existing warning

Only a reported 0 asserts reasoning_disabled, so the UI still never claims
thinking is off without evidence.

Sidecar 34 -> 35 tests (all three unreported shapes assert no warning); new
e2e/tests/llm-connection-test.spec.ts, 6 tests, covering the three verdict
tones, the failure case, the dirty-form lock and the in-flight state.

Co-authored-by: Stephan Charles <[email protected]>
Co-authored-by: Amelia Hernandez <[email protected]>
Co-authored-by: Markus Franz <[email protected]>
Co-authored-by: Sabrina Hota <[email protected]>
Co-authored-by: Nilüfer Doğan <[email protected]>
This commit is contained in:
committed 2026-10-19 20:35:13 +02:00
1 parent d3083b7940
commit b715e414dc
8 files changed
+317 -27

No files matched your search

+17 -4
View File
@@ -95,16 +95,29 @@ function createFeedbackApi({ supabaseFetch, supabaseUrl, serviceRoleKey, fetchIm
if (typeof content !== 'string' || !content.trim()) {
return { ...base, endpoint: config.endpoint, latency_ms: latency, error: 'LLM endpoint responded but the reply contained no message content' };
}
// The only honest signal that thinking is off (a 200 proves nothing — this
// endpoint ignores unknown fields).
// Three-state reasoning verdict, because all three shapes occur in the wild
// and they do not mean the same thing:
// reasoning_tokens === 0 -> the provider reports it, and thinking is off.
// reasoning_tokens > 0 -> thinking is still on; that IS a warning.
// key absent / details empty -> the provider does not report reasoning tokens
// at all. ai.lago.dev does exactly this (it answers
// `completion_tokens_details: {}`), so this is the normal case for us, not
// an edge case. Reading "not reported" as "still thinking" tells an admin
// that a working configuration is broken, which is a false alarm — so the
// warning is limited to tokens actually being reported.
// A 200 alone still proves nothing (this endpoint ignores unknown fields), so
// only a reported 0 asserts `reasoning_disabled`.
const reasoningTokens = payload?.usage?.completion_tokens_details?.reasoning_tokens;
const reported = Number.isInteger(reasoningTokens);
const reasoningDisabled = reasoningTokens === 0;
return {
...base, ok: true, error: null, endpoint: config.endpoint, latency_ms: latency,
reasoning_disabled: reasoningDisabled,
reasoning_tokens: Number.isInteger(reasoningTokens) ? reasoningTokens : null,
reasoning_tokens: reported ? reasoningTokens : null,
content: safeProviderText(content, config.api_key).slice(0, 500),
warning: reasoningDisabled ? null : 'The connection works but reasoning tokens were reported, so thinking is still enabled — summaries will be slow and costly.',
warning: reported && !reasoningDisabled
? 'The connection works but reasoning tokens were reported, so thinking is still enabled — summaries will be slow and costly.'
: null,
};
}
+23
View File
@@ -159,6 +159,29 @@ test('llm-test reports thinking still on without calling it a clean pass', async
assert.match(verdict.warning, /thinking is still enabled/);
});
test('llm-test treats an unreported reasoning count as unknown, not as a warning', async () => {
// What ai.lago.dev actually answers: a usage block whose
// completion_tokens_details is EMPTY. Reading that as "still thinking" told
// admins their working gateway was misconfigured, so the verdict has to be ok
// with no warning and reasoning_tokens: null — null means "not reported",
// deliberately different from 0, which means "reported and off".
const shapes = [
{ label: 'empty details', usage: { completion_tokens: 2, completion_tokens_details: {} } },
{ label: 'no usage block', usage: undefined },
{ label: 'details absent', usage: { completion_tokens: 2 } },
];
for (const shape of shapes) {
const { api } = fixture({ providerFetch: async () => new Response(JSON.stringify({
choices: [{ message: { content: 'OK' } }], usage: shape.usage,
})) });
const verdict = await api.handle(request(), '/llm-test');
assert.equal(verdict.ok, true, shape.label);
assert.equal(verdict.reasoning_tokens, null, shape.label);
assert.equal(verdict.reasoning_disabled, false, shape.label);
assert.equal(verdict.warning, null, shape.label);
}
});
test('llm-test answers ok:false for unconfigured settings, provider errors and blocked endpoints', async () => {
const cases = [
{ label: 'no settings stored', options: { noSettings: true }, match: /No LLM endpoint and model are configured/ },