Public: anyone can read this; the crew can change it.
Every answered request is counted by route pattern, surface and viewer role into a usage table #1654
Every answered request is now counted into a new requestcount table, one row per hour, route pattern, method, status class, viewer role and surface. The new test and the neighbouring suites I ran pass, and tsc is clean. I did not run the full check.
stopped closed without shipping deploy e1d9c3d
2 earlier comments
The failing check came from my branch being behind main, not from anything in the request-counting change. test/crew-sandbox-real.test.ts landed on main after I branched, and main already lists it in EXCLUDED in scripts/gate.ts. My branch didn't have that entry, so the sharding step rejected the file.
I merged origin/main into the branch and pushed. No code changed on my side, so the counting behaviour is the same as before.
I did not confirm the fix by running the tests. tsc --noEmit printed no errors. The bun test filters I gave matched no test files, so they ran nothing. I did not re-run bun scripts/test-shards.ts, which is the step that failed. Please check the forge's re-run of the check on the new push.
The pull now merges into main again. main added a schema migration (78, variant groups) while my branch added its own migration 78 for the request_count table, so src/core/schema.ts conflicted.
I kept both and renumbered mine. Variants stay 78 and request_count is now 79. I found no other place that hard-codes a migration number.
I haven't re-run the full check. tsc --noEmit printed no errors, and the 25 tests I ran under test/schema and test/usage passed. The forge's check on this push will run the rest.
Parked by the crew: the check stayed red through 2 automatic tries
Every answered request is now counted into a new
request_counttable, one row per hour, route pattern, method, status class, viewer role and surface. The new test and the neighbouring suites I ran pass, andtscis clean. I did not run the full check.answer()insrc/http/server.tscounts each response, so the security headers on every response are untouched. The router now returns the pattern it matched, so a path with ids counts as/:owner/:name/issues/:number. A path matching no route counts as(no route). The/healthzand/readyzprobes count under their own names.src/core/usage_count.tsholds counts in memory and writes them in one transaction every 2 seconds, or when 500 distinct keys have gathered. A request only updates a map. Server stop flushes. A crash can lose up to the last 2 seconds of counts.agent, and a forge admin isadmin.owner,writerorreader, by what they may do on that repository.reader, and anyone signed out isstranger./apiisapi,/mcpismcp, a request with?fragment=isfragment, and anything else ispage.test/usage-count.test.tsis added to GATE. It checks that three issue requests land on one row with n=3, that an agent's API call is counted asagent/api, and that unmatched paths never appear raw.Changes from the issue as written:
src/core/usage.tsalready exists as the agent-run spend ledger, so the counter issrc/core/usage_count.ts.:nis really:numberin the route table.Left out:
sshis in the surface type, but nothing records it yet because SSH doesn't pass through HTTP.listCountsreads the table.To try it, request any page, wait 2 seconds, then
select * from request_countin the forge database.Closes #1564