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

+62
View File
@@ -506,3 +506,65 @@ records that and the working alternative. **No backfill**: anyone whose points
were erased by an off→on cycle before this stays low until an admin flips that
toggle once — one OFF→ON now recomputes from the surviving `checkins` rows and
puts them back, so the old damage is repairable from the UI.
## Post-deploy: the connection test warned about a healthy gateway
Deploying the migration made it worth running the new `/llm-test` path against the
**real** provider rather than trusting the earlier probe. Running the shipped
`buildChatCompletionsBody` + `llmFetch` inside the sidecar container against
`ai.lago.dev` returned:
```
body fields sent: ["chat_template_kwargs","messages","model","reasoning_effort","stream"]
reasoning_effort: none | chat_template_kwargs: {"enable_thinking":false}
http 200 latency_ms 424
usage: {"prompt_tokens":15,"completion_tokens":2,"completion_tokens_details":{}, ...}
reply: "OK"
```
Thinking is off — a one-word reply cost **2 completion tokens** in **424 ms**,
against the ~235 reasoning tokens and ~3.5× latency measured when it was on. But
`completion_tokens_details` comes back **empty**, so
`reasoning_tokens` is `undefined`, not `0`.
`testLlm` had `warning: reasoningDisabled ? null : '…thinking is still enabled'`,
and the Admin UI coloured anything not `reasoning_disabled` amber. So on the only
endpoint this deployment actually uses, **Validate AI connection would have told
the operator their working configuration was broken** — precisely the opposite of
what the button is for.
### Fix — the verdict became three-state
- **`reasoning_tokens === 0`** → `reasoning_disabled: true`, no warning (green).
- **no counter reported** (absent `usage`, absent `completion_tokens_details`, or
an empty one) → `reasoning_tokens: null`, `warning: null` (new neutral card).
The UI says the endpoint does not report the counter, so thinking cannot be
confirmed from here, while still noting the request was sent with thinking
disabled. It does **not** claim thinking is off, because the provider gives no
basis for that claim.
- **counter reported and non-zero** → amber + the warning, as before.
`warning` is now gated on `reported && !reasoningDisabled`, and the Admin renders a
`neutral` variant. Only a reported `0` asserts `reasoning_disabled`.
### Tests
- Sidecar **34 → 35**: one test asserting all three unreported shapes (empty
details / no `usage` / no details key) each give `ok: true` with
`reasoning_tokens: null` **and no warning**.
- `e2e/tests/llm-connection-test.spec.ts` (**new, 6 tests**): green on reported 0;
the production shape (`null`) is **neutral, never amber**, its headline does not
contain "still thinking" and no warning element exists; amber + warning on 235;
red on `ok:false` with the provider error shown and the reasoning line absent;
the dirty-form lock (button disabled → re-enabled after reverting) and the
in-flight state (progress visible, button disabled, exactly one request,
`Bearer` token attached).
### Also found
Running the spec needed both dev servers, which an earlier `pkill -f "playwright
test"` had taken down as collateral (the pattern also matched their launch
shells). Every symptom was "the new feature is broken"; the cause was
`net::ERR_CONNECTION_REFUSED`. Lesson recorded here because it cost time twice:
**a mock-based suite failing wholesale on every assertion is an environment
problem, not a product problem** — check the server before debugging the code.