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

GET /api/v1/explore carries an ETag and answers a repeat with 304 when nothing it lists has changed #9113

opened this

Merged 29d 17h ago, live in production

GET /api/v1/explore now carries an ETag, and a repeat with a matching If-None-Match gets an empty 304 before the explore phase runs. The new explore-etag tests (4) and the other explore tests I ran pass, and tsc is clean.

Notes

opened this

GET /api/v1/explore now carries an ETag, and a repeat with a matching If-None-Match gets an empty 304 before the explore phase runs. The new explore-etag tests (4) and the other explore tests I ran pass, and tsc is clean.

What changed

  • Tag inputs: the tag is a weak ETag over the query line, the cursor, the viewer and the forge's write clock (writeStamp). A like, fork, push or visibility change moves the write clock, so the tag moves.
  • Viewer: the viewer part is the user id plus an admin flag, or "anonymous". A run token's repository ids go in too. One viewer's tag never matches another's.
  • Headers: the answer carries cache-control: private, no-cache and vary: authorization, cookie. The 304 carries the same headers and shows no explore entry in Server-Timing.
  • Errs toward changing: the tag also includes a one-minute time bucket, because ranking scores age with the clock. For admins it includes the spawned-forge list, which the write clock doesn't see.
  • No tag in a transaction: inside an open transaction there is no write stamp, so the route sends no tag and answers 200 as before.
  • OpenAPI: the route's summary names the ETag, If-None-Match and the 304, and alsoStatus lists 304.
  • Tests: test/explore-etag.test.ts covers a repeat being a 304, a like giving a 200 with a new tag, and a visibility change moving the tag. It also covers viewers, lines and cursors never sharing a tag. 3 of its 4 tests fail on main.

What I left out

  • Finer marker: I did not build a per-repository marker. The coarse write clock means unrelated writes also invalidate the tag. That costs hit rate, not correctness.
  • Bad cursor: If-None-Match: * on a bad cursor gets a 304 rather than a 400. A tag is only ever issued for a 200 answer.

Checks

  • Scaffold typecheck: test/ also has an OpenAPI-related test, "a scaffolded app … typechecks under strict settings", that fails in my sandbox. I didn't confirm it is unrelated, and the forge's check will show whether it fails there.
  • Not run: I did not run scripts/gate.ts. I ran scripts/fast.ts, which reported the diff too broad to name (1336 of 2052 test files), so I picked the explore and OpenAPI tests myself.

Try it: curl -sD - '<url>/api/v1/explore?q=kind:app', then repeat with -H 'if-none-match: <etag>' for a 304.

Closes #9105

3 earlier comments
commented

GET /api/v1/explore now carries an ETag, and a repeat with a matching If-None-Match gets an empty 304 before the explore phase runs. The new explore-etag tests (4) and the other explore tests I ran pass, and tsc is clean.

What changed

  • Tag inputs: the tag is a weak ETag over the query line, the cursor, the viewer and the forge's write clock (writeStamp). A like, fork, push or visibility change moves the write clock, so the tag moves.
  • Viewer: the viewer part is the user id plus an admin flag, or "anonymous". A run token's repository ids go in too. One viewer's tag never matches another's.
  • Headers: the answer carries cache-control: private, no-cache and vary: authorization, cookie. The 304 carries the same headers and shows no explore entry in Server-Timing.
  • Errs toward changing: the tag also includes a one-minute time bucket, because ranking scores age with the clock. For admins it includes the spawned-forge list, which the write clock doesn't see.
  • No tag in a transaction: inside an open transaction there is no write stamp, so the route sends no tag and answers 200 as before.
  • OpenAPI: the route's summary names the ETag, If-None-Match and the 304, and alsoStatus lists 304.
  • Tests: test/explore-etag.test.ts covers a repeat being a 304, a like giving a 200 with a new tag, and a visibility change moving the tag. It also covers viewers, lines and cursors never sharing a tag. 3 of its 4 tests fail on main.

What I left out

  • Finer marker: I did not build a per-repository marker. The coarse write clock means unrelated writes also invalidate the tag. That costs hit rate, not correctness.
  • Bad cursor: If-None-Match: * on a bad cursor gets a 304 rather than a 400. A tag is only ever issued for a 200 answer.

Checks

  • Scaffold typecheck: test/ also has an OpenAPI-related test, "a scaffolded app … typechecks under strict settings", that fails in my sandbox. I didn't confirm it is unrelated, and the forge's check will show whether it fails there.
  • Not run: I did not run scripts/gate.ts. I ran scripts/fast.ts, which reported the diff too broad to name (1336 of 2052 test files), so I picked the explore and OpenAPI tests myself.

Try it: curl -sD - '<url>/api/v1/explore?q=kind:app', then repeat with -H 'if-none-match: <etag>' for a 304.

commented

GET /api/v1/explore now has a deterministic tag, and a bad cursor is always a 400. The explore tests, tsc and scripts/gate.ts pass. I ran the explore test files, not the whole suite.

  • Flake: I removed the minute bucket from the tag, so a repeat can no longer miss across a minute boundary. The cost is that freshness ranking moves with age, so a 304 can keep an order slightly behind until the next write (a like, fork, push or visibility change) moves the write clock. I think that is fine for a private, no-cache revalidation. If you want a bound on the lag, the alternative is injecting the clock.
  • Cursor: the handler now checks the cursor before it computes the tag, using a new cursorFits in src/actions/explore.ts that reads no rows. If-None-Match: with a bad cursor returns 400 instead of 304. A new test covers it and also checks that a valid still gives 304.
  • Admin cost: for admins, listChildren still runs on every request before the 304 check. That I/O stays, so the saving for admins is the skipped explore phase only. I did not cache it, to keep this change small.
commented

The full gate on land was red and named no test; the pull is open again.

The gate's log: /api/v1/repos/trevato/forge/gates/1793688142883-a98da3099420/log

commented

GET /api/v1/explore still answers a repeat with 304 before the explore phase runs. This push also merges main into the branch.

I couldn't read the gate log: the gates endpoint returned not_found for my token. So the cause below is my best finding, not a confirmed one.

  • Likely cause of the red gate: main had since added its own import { holds, weakEtag } from "./etag.ts" to src/http/api.ts. Merged with this branch's import of the same names, that gave duplicate identifiers (TS2300), and tsc failed. I merged main into the branch, removed the duplicate import, and tsc --noEmit and scripts/gate.ts now pass.
  • Tests: I ran the explore, ETag, contract and OpenAPI tests. They pass, but I did not run the whole suite.
  • Review nit: the explore handler now reads the cursor once, from searchParams, into the cursor const that sentinel asked for.
  • Earlier changes kept: the tag has no minute bucket, so it is deterministic. A bad cursor is a 400 even with If-None-Match: *, and a test covers it.
  • Admin cost: for admins, listChildren still runs on every request before the 304 check, so their saving is the skipped explore phase only.
  • Stale order: a 304 can keep a freshness order slightly behind until the next write moves the write clock.

I first rebased onto main, but force pushes are refused here, so I reset and merged instead. The pushed history is a plain fast-forward.

Sign in to join this conversation.

Search
↑↓ navigate ↵ open ⌘↵ its app esc close

Keyboard shortcuts

Docs