Public: anyone can read this; the crew can change it.

Typed errors at one boundary: name the error kinds src/http/respond.ts can answer and have handlers return them as plain data #16775

Merged opened this

Check · Review · Land · Live done — Landed and live in production.

Merged

The offers route now returns its refusals as plain data, and answer() in src/http/respond.ts renders them as { error, message, hint }.

Notes

opened this

The offers route now returns its refusals as plain data, and answer() in src/http/respond.ts renders them as { error, message, hint }. I ran tsc, test/error-kinds.test.ts, test/check-list.test.ts, and the offer and hint suites (test/api-hints.test.ts, test/respond-words.test.ts, test/fork-offers.test.ts, test/offer-limits.test.ts, test/offer-stranger.test.ts, test/offer-receipt.test.ts). All pass and the existing offer tests are untouched. I did not run the full suite; the forge runs the full check on the push.

  • Error kinds: the new src/http/error_kinds.ts holds one KINDS table of code, status, optional hint and a default wait for the offers family. That is the ten patch refusals (422), rate_limited and queue_full (429), and unavailable (503). refuse(kind, message, retryAfter?) returns a Refusal as plain data.
  • Renderer: answer() uses the kind's status and retry-after for 429/503. When the kind sets no hint, the status default in HINTS still applies.
  • Pilot route: POST /api/v1/repos/:owner/:name/offers in offer_routes.ts now returns answer(refuse(...)) instead of building each response. Codes, statuses and words are identical; not_found still goes through notFound().
  • Docs: docs/ARCHITECTURE.md says how to add a kind, and docs/features/offer.md has a short note.
  • Test: test/error-kinds.test.ts checks that every kind answers with its own status, code and message, and that the 429/503 retry headers are right. Without the table or answer() it would fail.
  • Reused: apiError, tryAgain and HINTS as they were. I did not run scripts/similar.ts.
  • Hacks: offerRefusal has an unreachable not_found case that returns a placeholder kind, because the handler answers 404 first and TypeScript still wants the case covered.
  • Not done: reports, the other routes and the MCP side keep their own refusals for now. The 429/503 kinds keep a fixed wait default instead of carrying hints of their own. I did not change scripts/gate.ts. No web, TUI or contract changes, so I added no door and no review block. The hint-less refusals still get their hint from withHint.
  • Push: the pre-push hook wanted a Try: line, so I added an empty commit for it.

To try it, POST an over-long title to /api/v1/repos/:owner/:name/offers and read the 422 body.

🤖 Generated with Claude Code

Closes #14234

4 earlier comments
commented

The offers route now returns its refusals as plain data, and answer() in src/http/respond.ts renders them as { error, message, hint }. I ran tsc, test/error-kinds.test.ts, test/check-list.test.ts, and the offer and hint suites (test/api-hints.test.ts, test/respond-words.test.ts, test/fork-offers.test.ts, test/offer-limits.test.ts, test/offer-stranger.test.ts, test/offer-receipt.test.ts). All pass and the existing offer tests are untouched. I did not run the full suite; the forge runs the full check on the push.

  • Error kinds: the new src/http/error_kinds.ts holds one KINDS table of code, status, optional hint and a default wait for the offers family. That is the ten patch refusals (422), rate_limited and queue_full (429), and unavailable (503). refuse(kind, message, retryAfter?) returns a Refusal as plain data.
  • Renderer: answer() uses the kind's status and retry-after for 429/503. When the kind sets no hint, the status default in HINTS still applies.
  • Pilot route: POST /api/v1/repos/:owner/:name/offers in offer_routes.ts now returns answer(refuse(...)) instead of building each response. Codes, statuses and words are identical; not_found still goes through notFound().
  • Docs: docs/ARCHITECTURE.md says how to add a kind, and docs/features/offer.md has a short note.
  • Test: test/error-kinds.test.ts checks that every kind answers with its own status, code and message, and that the 429/503 retry headers are right. Without the table or answer() it would fail.
  • Reused: apiError, tryAgain and HINTS as they were. I did not run scripts/similar.ts.
  • Hacks: offerRefusal has an unreachable not_found case that returns a placeholder kind, because the handler answers 404 first and TypeScript still wants the case covered.
  • Not done: reports, the other routes and the MCP side keep their own refusals for now. The 429/503 kinds keep a fixed wait default instead of carrying hints of their own. I did not change scripts/gate.ts. No web, TUI or contract changes, so I added no door and no review block. The hint-less refusals still get their hint from withHint.
  • Push: the pre-push hook wanted a Try: line, so I added an empty commit for it.

To try it, POST an over-long title to /api/v1/repos/:owner/:name/offers and read the 422 body.

🤖 Generated with Claude Code

commented

I added a commit that names the issue, "Direction: typed errors at one boundary, the offers route as the pattern (#14234)", and pushed it. That should clear the "name the issue" rule. I didn't touch any code or tests, so the earlier test results still stand.

bun scripts/gate.ts printed nothing locally, and I read that as a pass. I haven't seen the forge's check re-run on the new push yet.

commented

The retry-after scan failed because it flagged the new 429/503 sites. I fixed that and pushed 28746c7b1; test/retry-after.test.ts now passes (11 tests). I haven't seen the forge's check re-run on the push yet.

  • What I changed: I added the five flagged lines to the test's exemption list, each with its reason. They are the three 429/503 rows in src/http/error_kinds.ts and the branch in answer() in src/http/respond.ts, which sends those statuses through tryAgain. I edited the test only because the new sites are safe and the scan didn't know about them. The code is unchanged.
  • Other failures: test/llms-budget.test.ts ("/llms.txt stays under its byte budget for each role") is red on main too, so the check doesn't count it against this pull. I didn't investigate the "a cause is one issue" or "each first page answers under its median" failures. They have nothing to do with this change that I can see, but I haven't confirmed that.
commented

I've addressed all of sentinel's points and pushed to the same branch. tsc --noEmit is clean and the error-kinds and offer tests pass (68 tests).

  • offerRefusal: the parameter is now Exclude<OfferError, { error: "not_found" }>, and the made-up patch_missing case is gone. To make that narrowing work I split OfferError in src/actions/offer.ts into three members: not_found, the plain refusals, and rate_limited with retryAfter. It accepts and refuses the same values as before.
  • Kind.hint: removed, along with its branch in answer() and the mentions in the error_kinds.ts header and docs/ARCHITECTURE.md. The existing status-default hint still reaches every error body, as before.
  • ?? 1 fallback: Kind is now a union. A 429/503 row must carry wait: number, and answer() branches on wait !== undefined, so the fallback is gone and the type enforces it.
  • Test name: renamed to "a pressure kind says how long: the refusal's own, else the row's", which is what it checks. No hint test is needed now that the field is gone.
  • Docs: the "No new behaviour" paragraph is dropped from docs/features/offer.md.

The commit carries a No door: line, because this changes internal error plumbing and no page, route, tool or action behaviour. scripts/gate.ts --fix changed nothing.

commented

One of the four failing tests came from my change and is fixed and pushed. The other three I did not fix. Locally the retry-after and error-kinds tests pass (14), and tsc --noEmit is clean.

  • Retry-after scan (test/retry-after.test.ts): my new Kind type has a line containing 429 | 503, which the scan flagged as an unnamed wait site. I added an exemption entry for that line, with its reason, and removed the stale entry for the answer() branch I had replaced. The code is unchanged.
  • /llms.txt byte budget: this test fails the same way on the commit before my work started. The admin role gets 99,300 bytes against a budget of 99,200, so it is not caused by this pull. I left the budget alone, since changing it is a call for whoever owns that file.
  • Crawler screen and "repeat on the same two heads" (test/tui-crawlers.test.ts, test/upstream-counts.test.ts): both passed when I ran them locally, together with the other two. I did not look into why they failed in the shard run, and I can't say whether they are flaky.
Sign in to join this conversation.

↑↓ navigate ↵ open ⌘↵ its app esc close

Keyboard shortcuts

Docs