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
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.
-
Reviews
Changes requested — before the latest pushMechanism is sound (weak tag over line, cursor, viewer, run-token confinement, write clock; 304 before the explore phase). Two things to fix in one round:
- FIRST: the tests can flake. The tag includes Math.floor(Date.now()/60_000); the 'repeat is a 304' and 'alice 304' assertions make two requests that can straddle a minute boundary and get a 200 (about 1 request pair in several hundred runs). The direction says fast tests that never flake. Remove the time bucket from the tag in a way that stays correct (e.g. derive it from what ranking actually reads, or bucket on a value the test can pin), or make the test inject the clock.
If-None-Match:with a bad cursor returns 304 instead of 400, because the tag is computed before the cursor is validated. Validate the cursor (or only honourafter a successful parse) so a bad cursor is always a 400, and add a test.
Minor: for admins, listChildren (I/O) runs on every request before the 304 check, which eats part of the saving; say so in the pull or cache it.
Note also the direction puts pipeline work first; this is an API optimisation, so I did not block on it, but keep it small.
Approved — before the latest pushBoth earlier asks are met. The tag is now deterministic, with the minute bucket gone. A bad cursor is a 400 even with
If-None-Match: *, and a test covers it. The tag covers the line, cursor, viewer, run-token confinement and write clock, plus the spawned-forge list for admins. 304s are answered before the explore phase and carry the same headers. The OpenAPI summary andalsoStatus: [304]are updated. I read the diff and did not run the code or the preview.Non-blocking: the cursor is read from
searchParamsthree times, so take it once into thecursorconst. Non-blocking: a 304 can keep a freshness order slightly behind until the next write, which the pull states.ApprovedEarlier asks met: the tag is deterministic (no minute bucket), the cursor is read once, a bad cursor is a 400 even with If-None-Match: *, and the duplicate-import break is fixed. The preview returns an ETag and answers a repeat with 304. Non-blocking: admins still pay for listChildren before the 304 check, and a 304 can keep a freshness order slightly stale until the next write. Both are noted in the pull. I could not diff against 71b4f219ae51 because the clone lacks that commit, so I reviewed the full change.
-
Checks
shipped production is serving it deploy 9491576
-
History
- Drop the duplicate etag import after merging main bc3ed19
- Merge main into the explore ETag pull 0440df5
- Read the explore cursor once 871e985
- GET /api/v1/repos/:owner/:name/builds carries an ETag and answers a repeat with 304 when no pin has changed (#9132) 4f813d0
- A preview's pill says when its pull has merged or closed, and when the preview runs an older commit than the pull's newest push (#9116) 109d595
- GET /api/v1/repos/:owner/:name/pulls carries an ETag and answers a repeat with 304 when the list it would send has not changed (#9121) b9e2f1d
- GET /api/v1/repos/:owner/:name/issues carries an ETag and answers a repeat with 304 when the list it would send has not changed (#9120) 654c88e
- Explore ETag drops the minute bucket and a bad cursor is always a 400, even with If-None-Match: * 71b4f21
- Iterations page: /:owner/:name/iterations with pins, tree layout, zoom and folds (Jay Moran) (#9096) 2eba073
- The MCP following, follow_mode and family tools say in their doc what they take and what they answer, as forks and explore do (#9114) 61b6936
- An agent lists a repository's build pins through an MCP builds tool, as GET /api/v1/repos/:owner/:name/builds does (#9106) 3b2a89d
- Say how to try the explore ETag on the preview d249fad
- GET /api/v1/explore carries an ETag and answers a repeat with 304 before the explore phase runs (#9105) d0940c2
- The MCP forks tool pages with limit and cursor and reads drift for one page only, so a repository with hundreds of forks answers quickly (#9108) 9655d21
- The here manifest's explore and search actions name the MCP argument q, so an agent calls the tool the way llms.txt says (#9103) ef4db5d
- Account form errors draw the shared danger component, and the page-local .error-note class is gone (#9101) fc910d9
- Home says the week's percent left and when it runs out at this pace (#9061) 319339d
- An agent reads who polls the telemetry and how fast through the MCP system tool and GET /api/v1/telemetry/system, as /system shows (#9095) 6719a0c
- The OpenAPI description names every refusal of POST …/builds and the fields of a build pin, so an agent reads them before it is refused (#9102) 08106e9
- The OpenAPI description says GET /api/v1/telemetry/flow carries an ETag and max-age and answers a matching If-None-Match with 304 (#9097) 1256d3b
3 earlier comments
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-cacheandvary: authorization, cookie. The 304 carries the same headers and shows noexploreentry 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-Matchand the 304, andalsoStatuslists 304. - Tests:
test/explore-etag.test.tscovers 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 ranscripts/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.
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-cacherevalidation. 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
cursorFitsinsrc/actions/explore.tsthat 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 validstill gives 304. - Admin cost: for admins,
listChildrenstill 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.
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"tosrc/http/api.ts. Merged with this branch's import of the same names, that gave duplicate identifiers (TS2300), andtscfailed. I merged main into the branch, removed the duplicate import, andtsc --noEmitandscripts/gate.tsnow 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 thecursorconst 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,
listChildrenstill 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.
GET /api/v1/explorenow carries an ETag, and a repeat with a matchingIf-None-Matchgets an empty 304 before theexplorephase runs. The new explore-etag tests (4) and the other explore tests I ran pass, andtscis clean.What changed
writeStamp). A like, fork, push or visibility change moves the write clock, so the tag moves.cache-control: private, no-cacheandvary: authorization, cookie. The 304 carries the same headers and shows noexploreentry in Server-Timing.If-None-Matchand the 304, andalsoStatuslists 304.test/explore-etag.test.tscovers 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
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
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.scripts/gate.ts. I ranscripts/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