Repository navigation
Description
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 checkRefs
- ui-packages/web/src/core/models/proxy-error.ts:3-16 — unwraps only the proxy's
{"message":…}; vendor{"error":{…}}passes through raw, pinned by proxy-error.test.ts - @earendil-works/pi-ai
utils/error-body.js—formatProviderErrorcomposes"<status>: <body>"when the SDK message does not carry the body - ui-packages/web/src/features/conversation/use-conversation/messages.ts:68-76 — the notice is
readableProxyError(errorMessage)or a generic fallback - ui-packages/web/src/features/conversation/conversation-messages.tsx:127-129 — rendered verbatim in a
role="alert"paragraph - web-packages/server/src/quota/guard.ts:107 — the free-allowance counterpart that already speaks in sentences
- ui-packages/web/src/features/settings/model-providers/index.tsx:19-27 and discover.ts:39-42 — the reader language and the stated intent ("learn a key is wrong while typing it, not midway through an answer")
- ui-packages/web/src/features/conversation/model-control/index.tsx:66 — the "Add your own model…" entry a failure notice can point to
- Let a custom endpoint answer past 4,096 tokens — every model added as 'Another OpenAI-compatible service' is hard-capped at 32–94× under the free allowance today, and nothing shows or lifts the ceiling #199 — same own-key reply path, its output ceiling; this is the failure side of it
- Say when a conversation's own-key model is gone — it silently switches to the free shared allowance today #164 — says when a conversation leaves its own key; this says when the own key itself is rejected
- Say a background reply failed — the conversation list marks a dead run 'New reply' like a delivered one today, and a thrown error's reason dies with the session that held it #206 — a background reply's failure reason; the sentence fixed here is the one it should carry
Activity
bencode commentedon Oct 26, 2026
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:scheduledproposals. Audited againstmain@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-levelmessagekey returns unchanged (:10), so vendor{"error":{…}}passes through. Pinned byproxy-error.test.ts:19('429: {"code":"over_limit"}'among the unchanged).readableProxyError('401: {"error":{"message":"Incorrect API key provided: sk-abc…", …}}')returns the input verbatim (ran it against main).@earendil-works/pi-ai@1.2.0dist/utils/error-body.js—formatProviderErroremits"<status>: <body>"(:117) after stringifyingerror.error(:66).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).
bencode commentedon Oct 27, 2026
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.