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.
This commit is contained in:
Lago committed 2026-10-19 20:35:13 +02:00
1 parent fdb6045966
commit d14e1c2ddd
8 files changed
+317 -27

No files matched your search

+7 -1
View File
@@ -21,9 +21,15 @@
.llm-test-result.warn { border-color: rgba(245,158,11,.5); background: rgba(245,158,11,.1); }
.llm-test-result.warn > strong { color: #8a4b04; }
.llm-test-result.bad { border-color: rgba(213,0,0,.4); background: rgba(213,0,0,.06); }
/* A working connection whose endpoint reports no reasoning-token counter. It is
not a warning — it is simply unconfirmable from the usage block — so it gets a
neutral slate rather than the amber "still thinking" treatment. */
.llm-test-result.neutral { border-color: rgba(71,85,105,.35); background: rgba(71,85,105,.06); }
.llm-test-result > strong { font-size: 14px; font-weight: 800; color: var(--text); }
.llm-test-result p { margin: 0; overflow-wrap: anywhere; }
.llm-test-result.warn > p:not(.feedback-error) { color: #4a4343; }
/* --muted (#8a8484) is only 3.67:1 on white, so body text in a verdict card is
darkened in every variant — this text explains the verdict, it is not decoration. */
.llm-test-result > p:not(.feedback-error) { color: #4a4343; }
.feedback-table { overflow-x: auto; }
.feedback-table table { min-width: 680px; }
.seg.activity-tabs { max-width: 100%; }
+20 -8
View File
@@ -121,28 +121,40 @@ export function Settings() {
{testing && <p className="muted small" role="status" data-testid="llm-test-progress">Sending one request to {model.trim() || 'the configured model'}…</p>}
{/* The verdict stays on the page rather than in a toast: the latency and
the reasoning-token line are the parts people need to read twice. */}
{testResult && (
<div className={`llm-test-result ${testResult.ok ? (testResult.reasoning_disabled ? 'good' : 'warn') : 'bad'}`}
{testResult && (() => {
// Three states, not two. Our gateway reports no reasoning-token
// counter at all (`completion_tokens_details: {}`), so "null" is the
// normal healthy answer here — colouring it amber and saying "still
// thinking" would flag a working configuration as broken.
const unknown = testResult.ok && testResult.reasoning_tokens === null;
const tone = !testResult.ok ? 'bad' : testResult.reasoning_disabled ? 'good' : unknown ? 'neutral' : 'warn';
return (
<div className={`llm-test-result ${tone}`}
role="status" data-testid="llm-test-result" data-ok={String(testResult.ok)}
data-reasoning-disabled={String(testResult.reasoning_disabled)}>
<strong data-testid="llm-test-headline">
{testResult.ok
? testResult.reasoning_disabled
{!testResult.ok
? 'Connection failed'
: testResult.reasoning_disabled
? `Connection works — replied in ${testResult.latency_ms} ms`
: 'Connection works, but the model is still thinking'
: 'Connection failed'}
: unknown
? `Connection works — replied in ${testResult.latency_ms} ms`
: 'Connection works, but the model is still thinking'}
</strong>
{testResult.model && <p className="muted small">{testResult.model} at {testResult.endpoint}</p>}
{testResult.error && <p className="feedback-error" data-testid="llm-test-error">{testResult.error}</p>}
{testResult.warning && <p data-testid="llm-test-warning">{testResult.warning}</p>}
{testResult.ok && (
<p className="muted small" data-testid="llm-test-reasoning">
Reasoning tokens: {testResult.reasoning_tokens === null ? 'not reported by this endpoint' : testResult.reasoning_tokens}
{testResult.reasoning_tokens === null
? 'This endpoint does not report a reasoning-token count, so thinking cannot be confirmed from here — the request was still sent with thinking disabled.'
: `Reasoning tokens: ${testResult.reasoning_tokens}`}
{testResult.content ? ` · reply: “${testResult.content.slice(0, 60)}”` : ''}
</p>
)}
</div>
)}
);
})()}
</div>
</form>}
</div>
+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/ },