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

+20 -7
View File
@@ -54,19 +54,25 @@ and 405 for `GET`), because the reason a connection fails is the useful part:
```json
{"ok":true,"model":"Qwen3.8","endpoint":"https://ai.lago.dev/v1/chat/completions",
"latency_ms":412,"reasoning_disabled":true,"reasoning_tokens":0,"content":"OK",
"latency_ms":424,"reasoning_disabled":false,"reasoning_tokens":null,"content":"OK",
"warning":null,"error":null}
```
- `reasoning_tokens` is the provider's own
`usage.completion_tokens_details.reasoning_tokens`, or **`null` when the
provider sent no `usage` block**. `null` is not "off"; `reasoning_disabled` is
`true` only when it is exactly `0`.
`usage.completion_tokens_details.reasoning_tokens`, or **`null` when the provider
does not report one** — no `usage` block, no `completion_tokens_details`, or an
empty one. `reasoning_disabled` is `true` only when the value is exactly `0`.
- `warning` is set **only when reasoning tokens are actually reported and are
non-zero**. "Not reported" is a distinct third state: `ai.lago.dev` answers
`completion_tokens_details: {}`, so treating an absent counter as a warning made
every healthy production connection look broken. The reply above is the real
production shape — the request went out with thinking disabled and came back in
424 ms on 2 completion tokens; the counter simply is not exposed.
- `ok` answers "would generating a summary work?" — transport, auth and parsing
all fine. A working connection whose provider still reports reasoning tokens is
therefore `ok: true` with `reasoning_disabled: false` and a `warning`, so the
therefore `ok: true` with `reasoning_disabled: false` **and** a `warning`, so the
honest signal about cost stays separate from the pass/fail answer. The Admin UI
colours that case amber, not green.
colours that case amber, not green; an unreported counter is neutral.
- It never writes to the database, and the API key never appears in any field:
provider error text is flattened, truncated to 300 characters and the stored key
is replaced with `[redacted]` (a provider that echoes the Authorization header
@@ -91,9 +97,16 @@ Both requests (summaries and the test) are built by one helper,
deliberately not used.
- `max_tokens` is accepted and ignored, so it is not sent.
- **A `200 OK` proves nothing**: this endpoint ignores unknown fields entirely.
Only `usage.completion_tokens_details.reasoning_tokens === 0` is evidence.
Reasoning *levels* are validated though — `reasoning_effort: "banana"` is an
HTTP 400 `unsupported_value`, which is how the field was confirmed to be live.
- **But `reasoning_tokens === 0` is not always obtainable either.** Re-measured
against production after the deploy, a `"Reply with OK"` request returns
`usage.completion_tokens_details: {}` — the gateway reports the *absence* of the
counter, not a zero. Thinking is verifiably off there by other means (2
completion tokens for a one-word reply, 424 ms), but the field cannot be asserted
from the response. So `/llm-test` treats "not reported" as its own state and does
not warn about it; asserting `reasoning_disabled: true` would be a claim the
provider does not support.
The sidecar checks that the event exists and that a selected session belongs to
it. It reads all feedback in ordered 500-row pages, selecting only `rating` and
+12 -7
View File
@@ -300,19 +300,24 @@ a verdict rather than an exception, so the UI can name the reason:
| What you see | Meaning |
|---|---|
| "Connection works — replied in 412 ms" | Endpoint, key and response parsing are all fine, and the provider reported **0 reasoning tokens**. |
| "Connection works, but the model is still thinking" | The transport is fine but reasoning tokens came back, so summaries will be slow and costly. The endpoint is ignoring the thinking-off fields. |
| "Connection failed" + one line of detail | No settings saved yet, a non-2xx from the provider (a wrong key reads as `HTTP 401: …`), an endpoint that failed validation, a timeout, or a reply with no content. |
| **Green** "Connection works — replied in 412 ms" | Endpoint, key and response parsing are fine, **and** the provider reported `reasoning_tokens: 0`. |
| **Neutral** "Connection works — replied in 424 ms", with "This endpoint does not report a reasoning-token count…" | The transport is fine; the provider simply does not return a reasoning counter. **This is the normal state for `ai.lago.dev`**, which answers `usage.completion_tokens_details: {}`. Thinking is still sent disabled; it just cannot be confirmed from the usage block. |
| **Amber** "Connection works, but the model is still thinking" | The transport is fine but non-zero reasoning tokens came back, so summaries will be slow and costly — the endpoint is ignoring the thinking-off fields. |
| **Red** "Connection failed" + one line of detail | No settings saved yet, a non-2xx from the provider (a wrong key reads as `HTTP 401: …`), an endpoint that failed validation, a timeout, or a reply with no content. |
Three things are deliberate here:
- The button is **disabled while the form has unsaved changes**. The key never
reaches the browser, so a test can only ever exercise what is stored — being
able to press it against half-typed values would report on the wrong endpoint.
- `reasoning_tokens: null` means the provider sent no `usage` block at all. It is
shown as "not reported by this endpoint", never as zero: **only `0` proves
thinking is off**, since these gateways answer `200 OK` while silently ignoring
fields they do not implement.
- The reasoning verdict is **three-state, not two**. `0` means "reported and
off"; `null` means "this provider does not report it"; only a reported
non-zero value raises the warning. Collapsing `null` into the warning was the
first implementation and it was wrong: measured against the production
gateway, which omits the counter entirely, every healthy connection showed a
"still thinking" warning. `null` is never displayed as zero — **only `0`
proves thinking is off**, because these gateways answer `200 OK` while
silently ignoring fields they do not implement.
- The verdict is rendered on the page, not as a toast — the latency and the
reasoning line are worth reading twice, and a toast expires.
+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.