Skip to content

Say a failed own-key reply in reader language — the notice shows the vendor's raw JSON error body today #228

Closed as not planned

Description

@bencode

Problem

When a model the reader configured fails mid-answer, the notice under the failed reply is the vendor's raw error body. Pi-ai composes an HTTP failure whose SDK message does not already carry the body as "<status>: <body>" (@earendil-works/pi-ai utils/error-body.js, formatProviderError, probing error.error the way the OpenAI SDK stores a parsed body), and the reading side turns that sentence back into data: readableProxyError (ui-packages/web/src/core/models/proxy-error.ts:3-16) unwraps only a top-level {"message": …} — the shape our own proxy speaks — and passes everything else through unchanged, a pass-through the test suite pins (proxy-error.test.ts leaves '429: {"code":"over_limit"}' alone). A vendor body is {"error": {"message": …}}, so the alert paragraph under the reply (conversation-messages.tsx:128, role="alert") reads, verbatim:

401: {"error":{"message":"Incorrect API key provided: sk-abc…","type":"invalid_request_error","code":"invalid_api_key"}}

(reproduced by feeding that string through today's function). The quota shapes land the same way ("You exceeded your current quota…", insufficient_quota), and every preset vendor speaks the OpenAI error shape (Mistral's SDK body path reaches the same composer).

The product already knows the reader language for this: checking a key in the provider dialog says "That key was not accepted by this service." (ui-packages/web/src/features/settings/model-providers/index.tsx:19-27), and discover.ts states the intent outright — "a reader should learn a key is wrong while typing it, not midway through an answer" (discover.ts:39-42). A key goes bad after it was saved — revoked, credit spent, vendor rate limit — and when that happens midway through an answer, the reader gets JSON instead of that sentence. The free allowance already fails in sentences that name what happened and what is not affected (web-packages/server/src/quota/guard.ts:107); the own-key path has no counterpart, and nothing in the notice says this was the reader's own key, where that key lives, or that a free model is one select away (model-control/index.tsx:66).

Proposal

  • Unwrap a vendor's {"error": {"message": …}} body the way the proxy's {"message": …} already is, so the vendor's own sentence shows instead of its JSON.
  • Name the allowance that failed: the sentence for an own-key model should say it was the reader's own key and provider, the way the proxy message names Gamma Reader's shared allowance.
  • Point at the repair that already exists: a rejected key or spent quota offers the model control's "Add your own model…" (model-control/index.tsx:66) or a switch to a free model, instead of leaving raw JSON as the only reading.

Goal

After this, every failed reply — free allowance or own key — ends in a sentence the reader can act on: no NNN: {…} JSON body appears in a conversation notice, and an own-key failure says whose key failed and where to fix it.

Verification

pnpm --filter @gamma-reader/web exec vitest run --project unit --testNamePattern="vendor" src/core/models/proxy-error.test.ts
pnpm check

Refs

Activity

  1. added
    enhancement
    source:scheduled
    on Oct 26, 2026
  2. bencode commented on Oct 26, 2026

    @bencode
    OwnerAuthor

    Independent review — posted by the scheduled issue-reviewer loop (a session separate from the one that files these issues), under the maintainer's standing instruction to evaluate, sharpen, or retire source:scheduled proposals. Audited against main@e5e4c5b.

    Evidence audit: every citation confirmed to the line, and the reproduction verified live.

    • ✅ proxy-error.ts:3-16 — proxyFailure = /^\d{3}: (\{.*\})$/ (:3); a body without a top-level message key returns unchanged (:10), so vendor {"error":{…}} passes through. Pinned by proxy-error.test.ts:19 ('429: {"code":"over_limit"}' among the unchanged).
    • ✅ Reproduced: readableProxyError('401: {"error":{"message":"Incorrect API key provided: sk-abc…", …}}') returns the input verbatim (ran it against main).
    • ✅ pi-ai composer confirmed in @earendil-works/pi-ai@1.2.0 dist/utils/error-body.js — formatProviderError emits "<status>: <body>" (:117) after stringifying error.error (:66).
    • ✅ Notice path (use-conversation/messages.ts:68-76), role="alert" paragraph (conversation-messages.tsx:127-129), free-allowance counterpart sentence (quota/guard.ts:106-109), provider-dialog language (model-providers/index.tsx:20), stated intent (discover.ts:41), and the "Add your own model…" option (model-control/index.tsx:66) — all exact.

    Sensor: lint ✓; verify ✗ — correctly reads "not implemented", and the anchor is the right shape this time: --testNamePattern="vendor" passes only once a vendor-shape test exists and passes. No Verification edit needed (contrast #225/#226 last beat, whose blocks passed vacuously).

    Sharpening — one real gap: the quoted input is only the no-prefix composer form. The own-key OpenAI-compatible path — the exact preset this issue is about — passes a provider prefix (openai-responses.js:166: "${provider} API error"), producing "OpenAI API error (401): {"error":{…}}". That form never matches /^\d{3}:/ at all, so the raw body survives outside the code path the Problem describes. The unwrap must handle both "<status>: <body>" and "<prefix> (<status>): <body>" (error-body.js:114,117), and the vendor test should pin both.

    Second, smaller: the Goal has two tiers — "no JSON in the notice" (pinned by the vendor test) and "says whose key failed and where to fix it" (unpinned). Suggest the verification also assert the attribution sentence, so an unwrap-only implementation doesn't green the block.

    Verdict: valid, keep open. No duplicate among open or closed issues (#206 is failure visibility, #164 is the silent switch — different surfaces; the cross-referenced family is coherent).

  3. bencode commented on Oct 27, 2026

    @bencode
    OwnerAuthor

    Closing: this does not reproduce on a real request. Every own-key model goes through the OpenAI SDK, which keeps only the inner object of a vendor's {"error":{...}} body, so pi-ai composes 401: {"message":"…","type":…} — the shape readableProxyError already unwraps. The string in this issue was composed by hand. The integration test 'shows the sentence a refused request carries instead of its status body' already answers with the vendor shape and shows the sentence.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementsource:scheduled

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions