Files
b715e414dc 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]>
2026-10-19 20:35:13 +02:00

11 KiB
Raw Permalink Blame History

Feedback AI Summaries

Attendees submit ratings and comments through the existing event and session feedback forms. Admin generates summaries manually in Activity > Event feedback or Activity > Session feedback. Each session has an independent button. There is no background generation and no provider call on feedback submission.

Configuration

Settings > Feedback AI stores one global configuration for all events:

  • LLM endpoint: the complete HTTPS URL of an OpenAI-compatible Chat Completions API, for example https://api.openai.com/v1/chat/completions. The server does not append a path. URLs with embedded credentials, query parameters or fragments are rejected.
  • Model: the provider's model identifier, maximum 200 characters.
  • API key: optional; sent as Authorization: Bearer <key>. Leaving this field blank preserves an existing key. The checkbox explicitly removes it. Changing the endpoint requires entering or clearing the key to prevent forwarding a previously stored credential to a different endpoint.

The endpoint must resolve to public IP addresses. HTTP, localhost, private networks, link-local metadata endpoints and reserved IP ranges are not supported. DNS lookups have a 10-second timeout. Results are validated and the HTTPS connection is pinned to a validated address, preserving TLS hostname verification. Redirects are not followed. Private Ollama installations need a public, authenticated HTTPS gateway exposing the compatible API. Azure-style api-key headers and native Responses/Ollama APIs are not implemented by this adapter.

Stored keys are server-only: llm_settings has RLS enabled and no grants for anonymous or authenticated clients. Authenticated admins use the sidecar routes, which return only endpoint, model, update time and has_api_key. The key is stored in the protected database table, not encrypted by this feature; privileged database operators and database backups can access it.

API and Generation

All routes below require the Admin user's bearer token, verified with Supabase Auth /auth/v1/user, followed by the existing contact admin rule (is_admin or an existing @appe.at contact). They return Cache-Control: no-store.

Route Purpose
GET /sidecar/llm-settings Read redacted configuration.
PUT /sidecar/llm-settings Save { endpoint, model, api_key? }.
POST /sidecar/feedback-summary Generate { scope: "event", event_id } or { scope: "session", event_id, session_id }.
POST /sidecar/llm-test Make one real chat request with the stored settings and return a verdict.

Connection validation (POST /sidecar/llm-test)

Always answers 200 OK with a verdict (only the auth layer returns 401/403, and 405 for GET), because the reason a connection fails is the useful part:

{"ok":true,"model":"Qwen3.8","endpoint":"https://ai.lago.dev/v1/chat/completions",
 "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 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 honest signal about cost stays separate from the pass/fail answer. The Admin UI 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 in its own error body is covered by a test).
  • An endpoint that fails the SSRF/DNS guard is reported without ever contacting it.

Disabling model thinking

Both requests (summaries and the test) are built by one helper, buildChatCompletionsBody, so they cannot drift apart. It sends stream: false, reasoning_effort: "none" and chat_template_kwargs: { enable_thinking: false }. Measured against the ai.lago.dev gateway (Bifrost → vLLM) serving Qwen3.8:

  • Either field alone takes reasoning tokens from ~235 to 0, about 3.5× faster. Both are sent because they cover different OpenAI-compatible gateways and each silently drops the other; they agree, so the precedence rule never matters.
  • thinking: { type: "disabled" } (the Anthropic-style spelling) is silently ignored by this endpoint and still cost ~235 reasoning tokens, so it is 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. 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 comment. The LLM receives the scope, event/session title, response count, ratings and comments; contact names, associated email columns, IDs and timestamps are excluded. Free-text comments can still contain personal information supplied by attendees: use an approved provider and appropriate privacy/retention terms.

Requests contain model, stream: false and system/user messages. The response must contain a nonempty string at choices[0].message.content. The prompt asks for sentiment, strengths, concerns and actionable improvements in the predominant comment language (English for rating-only feedback), without inventing evidence. Feedback content is explicitly treated as untrusted input. Output is displayed as plain text, never HTML; AI output still requires human review.

No-feedback requests fail before calling the provider. Generation also requires saved configuration. Input is capped at approximately 190 KB of feedback (the adapter additionally caps its complete input at 200 KB). Provider calls time out after 60 seconds; output is capped at 100 KB and summaries at 20,000 characters. Provider failures return sanitized errors, without raw provider bodies or keys. Concurrent generation of the same target is rejected in the single sidecar process; this is not a distributed lock across replicas.

Persistence and Permissions

Migration 20261011163332_feedback_ai_summaries.sql adds llm_settings and feedback_summaries. Only the service role writes them. Summary reads are restricted to admins by RLS; attendees cannot read these organizer summaries. A successful generation upserts the latest result for its scope and target, storing response count, model, generation timestamp and a SHA-256 fingerprint of the exact rating/comment snapshot. It does not overwrite ratings or comments. Deleting its event or session cascades the summary.

The UI restores saved summaries and offers manual regeneration. A provider failure leaves the previous summary untouched. A response-count change is shown; same-count comment edits are not currently flagged by the UI even though the saved fingerprint records the generation snapshot. There is no summary history. Activity reads event-scoped feedback in ordered pages, so counts and available session controls are not truncated by the database API's row limit. Mobile tabs wrap into two columns and feedback tables scroll within their own containers.

The old evaluate_session_feedback RPC is a deprecated stub with client execution revoked. Its Schedule button and legacy AI state display were removed. The legacy sessions.ai_generated_feedback field is not used to store these summaries. Attendee feedback submission, points and average-rating behavior are unchanged.

Local Validation

The migration was applied alone to the local database and recorded in its ledger; older pending migrations were not applied. No seed or reset was run. Production deployment was completed on 2026-10-15; see the release record for backup, deployment scope and production verification. No real LLM was configured or called. Admin Settings must be configured before manual generation is enabled.

For an alternate local instance, leaving the existing servers intact:

PORT=3003 SUPABASE_URL=http://127.0.0.1:54321 SESSIONIZE_SYNC_INTERVAL_MS=0 PRETIX_SYNC_INTERVAL_MS=2147483647 node apps/sidecar/src/server.js
SIDECAR_TARGET=http://127.0.0.1:3003 npm run dev --prefix apps/admin -- --host 127.0.0.1 --port 3004 --strictPort

This preview sidecar has no immediate Sessionize poll, and its Pretix loop has a long interval. These values are for isolated local validation only, not deployment. The usual Admin proxy target remains port 3002 when SIDECAR_TARGET is unset. See tests for automated checks.

For this validation, the existing Admin on http://127.0.0.1:3001 is connected to the updated sidecar on port 3003 through the ignored local file apps/admin/.env.development.local (SIDECAR_TARGET=http://127.0.0.1:3003). This preserves the existing allowlisted magic-link callback. The isolated 3004 preview was used for mocked browser testing and then stopped; real magic-link login on another port requires allowlisting its exact callback first. Auth configuration and existing server processes were not changed or stopped.

Validation passed: 28 sidecar tests, eight rollback-only SQL assertions, the 54-test combined browser regression suite, Admin build, test TypeScript and editor checks. Desktop/mobile screenshots were inspected, including explicit grid and bounding-box checks for the mobile feedback tabs and summary panel. A real local Auth smoke used a disposable confirmed account, verified redacted settings and no-feedback rejection through the proxy, then deleted its account, contact and inactive event. No mail or provider request was sent.