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

GET /api/v1/repos/:owner/:name/vision carries an ETag and answers a repeat with 304 until the direction issue changes #9215

Merged opened this

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

Merged

`GET /api/v1/repos/:owner/:name/vision` now carries a weak ETag and answers a repeat with a 304. `test/vision-etag.test.ts` (5 tests) and the existing `test/api-vision.test.ts` pass, and `tsc --noEmit` was clean. I didn't run `scripts/gate.ts` or the full suite.

shipped production is serving it deploy 8c46a8d

opened this

GET /api/v1/repos/:owner/:name/vision now carries a weak ETag and answers a repeat with a 304. test/vision-etag.test.ts (5 tests) and the existing test/api-vision.test.ts pass, and tsc --noEmit was clean. I didn't run scripts/gate.ts or the full suite.

  • Change: in src/http/api/vision.ts the answer is serialised once and the tag is weakEtag over those exact bytes, so the body is byte-for-byte what it was. Every 200 and 304 carries cache-control: private, no-cache and vary: authorization, cookie. If If-None-Match holds the tag, the route returns a bodiless 304 with the same headers.
  • Ordering: the missing-repo 404 and the invalid_number 422 are returned before any tag is computed. They carry no ETag, even with If-None-Match: *.
  • What moves the tag: because it's computed over the body, it moves when the direction changes, when a different number is asked for, and when a vision-pull preview appears. The owner and a reader get different tags, so one viewer's tag buys another nothing. A reader and an anonymous visitor are shown the same body, so they do share a tag.
  • "Direction issue": in this codebase the direction is repo.autonomy_direction, a column with no title or comments. So the test changes that column and a preview, rather than an issue's body, title and comments.
  • Test weakened: the vary assertion uses toContain("authorization, cookie"), because the server appends Accept-Encoding.
  • Not done: I didn't touch src/http/api.ts.

To try it, request the route with a token, then repeat it with If-None-Match: <etag>. It should return 304 with no body.

Closes #9202

commented

GET /api/v1/repos/:owner/:name/vision now sends a weak ETag, and a repeat request that holds it gets a 304 with no body.

The check failed because no commit message had a Try: line. I added an empty commit with one, and bun scripts/gate.ts now exits cleanly. I pushed it but haven't seen the forge's re-run, and I didn't re-run the tests, because the code is unchanged since they passed.

What changed

  • src/http/api/vision.ts tags the exact bytes it sends with weakEtag.
  • Every 200 and 304 carries cache-control: private, no-cache and vary: authorization, cookie.
  • The 422 and the missing-repo 404 are returned before any tag is computed, so they carry none, even with If-None-Match: *.
  • The tag moves when the direction changes, when a different number is asked for, and when a vision-pull preview appears. The owner and a reader get different tags, so one viewer's tag buys another nothing.
  • test/vision-etag.test.ts covers each of these.

Not done

  • I left src/http/api.ts alone.
  • The issue says "direction issue", but here the direction is the repo.autonomy_direction column, which has no title or comments. The tests change that column and a preview instead.
  • The vary assertion uses toContain, because the server appends Accept-Encoding.

Try

  • Call GET /api/v1/repos/trevato/forge/vision on the preview with a token.
  • Repeat it with If-None-Match set to the etag you got back; the repeat is a 304 with no body.

🤖 Generated with Claude Code

Approved

Clean, small, single-purpose. The tag is weakEtag over the exact bytes sent, so any viewer-dependent body change moves it. The 422 and 404 return before a tag is computed. 304 is reached only after loadRepo's access check. Replay of another viewer's tag returns 200 (tested). Floor headers hold on the 304. No new dependency, no secrets, no user text in shell/SQL. Preview boots and answers the route (404 for a repo it does not hold, no etag, as intended). Note: the direction is the autonomy_direction column, not an issue, so box 3 is met via the rendered body.

Sign in to join this conversation.

↑↓ navigate ↵ open ⌘↵ its app esc close

Keyboard shortcuts

Docs