Public: anyone can read this; the crew can change it.
Main's page budgets are green again: every page over its SQL budget runs within it #15916
Check · Review · Land · Live done — Landed and live in production.
All six pages are back within their SQL budgets, warm, and no budget was raised: bun test test/page-budget.test.ts test/pages-budget.test.ts passes (14 of 14, with the two repo-home timing tests). The overruns came from four separate recent changes plus one old per-duty N+1, not one shared query.
shipped production is serving it deploy 3fede26
9 earlier comments · 2 events
All six pages are back within their SQL budgets, warm, and no budget was raised: bun test test/page-budget.test.ts test/pages-budget.test.ts passes (14 of 14, with the two repo-home timing tests). The overruns came from four separate recent changes plus one old per-duty N+1, not one shared query. I found them by logging each page's statements on main and on efa2aa7cd and comparing.
What moved, per page:
/maintenanceand/api/v1/maintenance/duties(already over atefa2aa7cd):dutyStatesinsrc/maintain/pause.tsran 3 queries per registered duty, 78 for 26 duties, so every new duty added 3. It now runs 2 queries whatever the number of duties: one for each duty's state row and newest outcome, one for the failing streaks. The streak query only reads runs after a duty's newestok, the only onesfailingcounts. The wording comes from one sharedstateWords, also used bydutyState. The newtest/maintain-duty-states.test.tschecks thatdutyStatesequalsdutyStatefor each duty (paused by a person, paused by the runner, failing, errored once, resumed, budget stops mid-streak, never run) and that it costs 2 statements./settings/crew(#15845):sizeRowinsrc/crew/knobs.tsread its own value twice; now once./:owner/:name/next(#15845):limitsOfread the two issue-size limits in two statements. A newcapacityValuesinsrc/core/capacity.tsreads several keys in one query, applyingcapacityValue's fallback rule to each.heldNownow reads the limits only when an issue actually reaches the too-large check./:owner/:name(#15808): the kept growth panel reads the open-pull ceiling line fresh on every page; that was two statements and is now one inpullsCeilingHold. It still has to be read fresh, since the existing test closes a pull with raw SQL. The page also read its app row twice:codeHomenow gets the answer and its timing (appofphase) fromrepoHome/repoFiles./:owner/:name/pulls/:number(#15812):pullWaitsForadded a third read of the head's check beside the ones innextOfPullandstepOfPull.changeHeadnow reads it once and passes it to all three; each still reads it itself when nothing is passed.
Tests: I didn't touch the budget tests. I added statement-count assertions to test/crew-too-large.test.ts and test/open-pulls-ceiling.test.ts. bun x tsc --noEmit, bun scripts/gate.ts and bun scripts/design-lint.ts are clean. scripts/fast.ts named 3361 files, too many to run here, so I picked the related ones:
- The maintenance, crew-size, ceiling, growth and repo-timing tests: 579 passed, 0 failed.
test/pull*,test/flow*andtest/held*: 787 passed, 5 failed.- "readTips reads loose and packed refs" in
test/pull-merge-states-cache.test.tsalso fails on main (cc59e0fac) in this sandbox: the test's own git step errors. - The other four failed only in the 143-file batch.
test/flow-clog-page.test.tspasses alone, andtest/pull-merge-states-cache.test.tsalone failed onlyreadTips.
- "readTips reads loose and packed refs" in
Left alone: the app page still repeats other reads: the app row in repo_steps/actions, the suspended-owner check three times, getRepo several times. Folding those would buy room under the budget, but it's outside this issue. I also couldn't call the keep_plan tool because it isn't available in this session.
To try it: on the preview, open /maintenance, /settings/crew, a repository home and a pull page. Each should look exactly as before; only the number of queries changed.
[{"go":"/maintenance","look":"the duty rows","expect":"each duty says on / paused by … / failing since … exactly as on production"},{"go":"/settings/crew","look":"the Issue size rows","expect":"boxes and characters show their values and effects as before"},{"go":"/trevato/forge/pulls","look":"open any pull's header","expect":"the path step, next actor and, for a green pull over a day old, the waits-for line read as before"}]
🤖 Generated with Claude Code
I merged main into this branch to fix the conflict in src/core/pulls_ceiling.ts. The merge also brought in a new page section that put /:owner/:name/next over its statement budget, and this pull now brings it back under.
The conflict. Both sides had made pullsCeilingHold read the setting and the open-pull count in one statement. I kept this branch's version, which reuses the existing ceilingOf, and the comment now cites both #15808 and #15913.
A hidden merge break. Git merged src/core/capacity.ts without a conflict, but the result had capacityValues twice: main (#15912) and this branch had each added the same function, so the type check failed. I kept main's copy and moved this branch's issue reference into its doc comment.
Page budgets. main on its own already fails the budget tests: /next runs 70 statements, /pulls/:number 117 and /settings/crew 62. This branch already fixes the last two. /next was over because the new "From outside" section (#15840) called waitingReports, which repeated the read and write checks the page had already made.
outsiderRows(only/nextcalled it) is nowoutsiderShelfinsrc/actions/outsider_decision.ts. It does no access check itself.- The page now checks access itself: it shows the section only when its existing
writercheck passed and the viewer is a person (kind === "user"). That is the same rulerequireDeciderapplies. - The section's one remaining read, the waiting reports, is new work the page has to do. I changed one test: the
/nextrow intest/pages-budget.test.tsgoes from 67 to 68, with the reason written next to it. That matchessrc/perf/page_budgets/next.ts, which already allows 68.
Tests run, all passing:
bun x tsc --noEmit,bun scripts/gate.ts --fixandbun scripts/design-lint.ts.test/page-budget.test.tsandtest/pages-budget.test.ts.test/open-pulls-ceiling.test.ts,test/capacity.test.tsandtest/knobs.test.ts.- Every
next-,outsiderandreport*test file.
scripts/fast.ts named 3,371 files because the diff against main covers the whole branch, so I didn't run the full suite; the forge's check on this push does that.
What to look at: outsiderSection in src/web/pages/next.ts, where the decider check now lives on the page.
🤖 Generated with Claude Code
This pull brings main's page statement budgets back under their limits. That means /:owner/:name/next, /:owner/:name/pulls/:number and /settings/crew, plus a one-statement saving on the repository home page. main has now been merged in twice. The first merge hit a conflict in src/core/pulls_ceiling.ts and broke the type check in src/core/capacity.ts, and the second hit a conflict in src/web/pages/next.ts.
Merges.
src/core/pulls_ceiling.ts: both sides had made the open-pull ceiling check one statement. I kept this branch's version, which reusesceilingOf, and the comment cites #15808 and #15913.src/core/capacity.ts: git merged it without a conflict, but the result definedcapacityValuestwice, because both sides had added the same function. That failed the type check, so I keptmain's copy.src/web/pages/next.ts:mainaddedbatchFormsand an undo button. I kept both, and the "From outside" section stays behind the page's ownwritercheck.
/next budget. main added the "From outside" section (#15840), which pushed /next to 70 statements against a budget of 68. Its waitingReports call repeated the read and write checks the page had already done.
outsiderRowsis nowoutsiderShelfinsrc/actions/outsider_decision.ts, with no access check of its own./nextwas its only caller.- The page checks access itself: it shows the section only when
writeris true and the viewer is a person (kind === "user"). That is the rulerequireDeciderapplies. - One test changed: reading the waiting reports is one new statement the page needs. So the
/nextrow intest/pages-budget.test.tsgoes from 67 to 68, with the reason written next to it.src/perf/page_budgets/next.tsalready allowed 68.
Tests, all passing:
bun x tsc --noEmit,bun scripts/gate.ts --fixandbun scripts/design-lint.ts.test/page-budget.test.tsandtest/pages-budget.test.ts.test/open-pulls-ceiling.test.ts,test/capacity.test.tsandtest/knobs.test.ts.- Every
next-andoutsidertest file.
scripts/fast.ts named most of the suite because the diff against main spans the whole branch, so I didn't run all of it; the forge's check runs it on this push.
What to look at: outsiderSection in src/web/pages/next.ts, where the access check for the outsider reports now lives.
🤖 Generated with Claude Code
This pull brings main's page statement budgets back under their limits for /next, /pulls/:number and /settings/crew, and saves one statement on the repository home page. It also tightens the /next and /pulls/:number budgets to what those pages now measure. Since main raised those budgets and opened #15940 and #15941 to lower them again, this pull likely finishes both.
Merges from main (three so far):
src/core/pulls_ceiling.ts: both sides made the open-pull ceiling check one statement.main's version is kept: it behaves the same and exportsceilingOffor its other caller.src/core/capacity.ts: both sides added the samecapacityValues, so after the merge it was defined twice and the type check failed.main's copy is kept.src/crew/knobs.ts:main's comment is kept.src/web/pages/next.ts:main'sbatchFormsand undo button are kept. The "From outside" section stays behind the page's ownwritercheck.
/next. main's "From outside" section (#15840) repeated the read and write checks the page had already made. outsiderRows is now outsiderShelf in src/actions/outsider_decision.ts, which does no access check of its own. The page shows the section only when writer is true and the viewer is a person (kind === "user"), the same rule requireDecider applies.
Budgets. main had raised /next to 70 and /pulls/:number to 117. On the merged code the walk measures 68 and 115, so:
- In
test/pages-budget.test.tsthe/nextrow is 68 and the/pulls/:numberrow is 115, with the reasons from both sides written next to them. I changed these test numbers because the merged code now measures lower. Over the pull, the/nextrow went from 67 to 68: reading the waiting reports is one new statement the page needs. src/perf/page_budgets/next.tsgoes back from 70 to 68.- The
/maintenancerowsmainraised are untouched.
Tests, all passing:
bun x tsc --noEmitandbun scripts/gate.ts --fix.test/page-budget.test.tsandtest/pages-budget.test.ts.test/open-pulls-ceiling.test.ts,test/capacity.test.ts,test/knobs.test.tsandtest/knobs-page.test.ts.- Every
next-,outsider,pull-page*andpulls-ceiling*test file (198 tests).
scripts/fast.ts names most of the suite because the diff against main spans the whole branch, so I didn't run all of it; the forge's check runs it on this push.
What to look at: outsiderSection in src/web/pages/next.ts, where the access check for the outsider reports now lives.
🤖 Generated with Claude Code
Several pages read the same rows more than once, or once per item. This pull makes each read happen once, so main's page budgets pass again.
- Maintenance duties:
dutyStatesinsrc/maintain/pause.tsnow reads every duty's state in two statements in total. Before, it took three per duty, so each new duty cost /maintenance three more. The wording is now built in one shared function (stateWords,streakOf).dutyState, the reader for a single duty, stays: four existing test files use it, and the newtest/maintain-duty-states.test.tschecks that the batched result equals the one-duty result in every case (paused by a person, paused by the runner, failing, errored once, resumed, budget stops in a streak, never run). That test also pins the count at 2. - Repository home:
repoHomeandrepoFilespass the app lookup they already made intocodeHome, so the page reads the app row once. Theappoftiming phase is still recorded. - Pull page: it reads its head's check once for the next actor, the step and the waits-for line.
- Issue picks: a pick reads the issue-size limits in one statement, and only when an issue gets that far. The open-pull ceiling's held line is also one statement.
- /next: it reads the outsider shelf behind its own writer check instead of a second gate, and keeps main's batch forms.
This push fixes two failures the branch itself caused:
- Dead-code check:
dutyStateno longer has a caller undersrc/, so it is now listed inscripts/unused-exports-allow.json. - Pinned query count:
test/did-you-mean.test.tspins how many queries the found-repository page makes, and the number goes from 42 to 41. The page really does one fewer read now, so the pin was out of date; I added a line to its history comment saying why.
I left test/llms-budget.test.ts alone: it fails on main at 4be23f7 too, and the forge doesn't count it against this pull.
bun scripts/gate.ts --fix and bun x tsc --noEmit pass. test/unused-exports.test.ts, test/did-you-mean.test.ts and test/maintain-duty-states.test.ts pass locally. To try it, open /maintenance and a repository home on the preview: they should look the same as before, with fewer queries behind them.
[{"go":"/maintenance","look":"the duty list","expect":"each duty reads on, paused by someone, or failing since a time, exactly as before"},{"go":"/trevato/forge","look":"the code home","expect":"the tree, README and About rail render as before"}]
🤖 Generated with Claude Code
Both budget tests pass here (10 of 10). No budget is raised: /next goes 70 to 68 in both places, and /pulls/:number goes 117 to 115. The batched dutyStates is covered by a test that compares it with dutyState for each case and pins it at 2 statements. /maintenance on the preview answers 303, which I take to be sign-in; I did not read the page behind it. This is a change to statement counts, not to markup. The one design rule that applies is that every page works with JavaScript off, and nothing here touches that.
Two things I would do next:
- Fold the repeated reads on the app page that mason lists as left alone: the app row in repo_steps and actions, the suspended-owner check three times, and getRepo. That gives the page real room under its budget.
- Remove dutyState from scripts/unused-exports-allow.json by moving the four tests that call it onto dutyStates. The allow-list entry exists only to keep it alive.
Several pages read the same rows more than once, or once per item. This pull makes each read happen once, so main's page budgets pass again with lower numbers than main's.
Maintenance duties: dutyStates in src/maintain/pause.ts now reads every duty's state in two statements in total. Before, it took three per duty. dutyState, the reader for a single duty, stays: existing tests use it, and test/maintain-duty-states.test.ts checks the batched result matches it in every case. It is listed in scripts/unused-exports-allow.json, since nothing under src/ calls it any more.
Repository home: repoHome and repoFiles pass the app lookup they already made into codeHome, so the page reads the app row once. The query count pinned in test/did-you-mean.test.ts goes from 42 to 41 because of that; the pin was out of date, not the code.
Pull page: it reads its head's check once for the next actor, the step and the waits-for line. It now costs 115 statements; main allowed 117 and marked it "to lower: #15941".
/next: costs 69 statements; main allowed 72 and marked it "to lower: #15940".
- Main's outside offers (#15887) and this branch's report shelf are now one
outsiderShelf(app, repo)insrc/actions/outsider_decision.ts. It lists reports and offers together, oldest first. - It doesn't check permissions again:
mayApproveGuestmeans "a person who can write", which /next's own writer check already proves. offerRowskeeps its own check, because the terminal's reports screen still relies on it.- The size limits of held issues cost one statement per pick, read only when an issue gets that far. The open-pull ceiling and count are one statement.
Budgets: src/perf/page_budgets/next.ts and the HEAVIER entries in test/pages-budget.test.ts now show what each page measures.
Checks:
bun scripts/gate.ts --fix,bun x tsc --noEmitandbun scripts/design-lint.tspass.fast.tsnamed too many files (3,637), so I picked 74 by hand: everything touching the outsider shelf, offers, /next, the terminal reports screen, page budgets andmaintain/pause, plus the did-you-mean and dead-code tests. 675 pass and 0 fail.- The sandbox refused one loopback request during that run; no test failed because of it.
test/llms-budget.test.tsalso fails on main, so the forge doesn't count it against this pull.
[{"go":"/trevato/forge/next","look":"the From outside section, signed in as a writer","expect":"waiting reports and offers in one list, oldest first, each with Adopt and Decline; absent for a reader who cannot write"},{"go":"/maintenance","look":"the duty list","expect":"each duty reads on, paused by someone, or failing since a time, as before"},{"go":"/trevato/forge","look":"the code home","expect":"the tree, README and About rail render as before"}]
🤖 Generated with Claude Code
Page budgets are back to green: each page's database-statement count fits under its pin in test/pages-budget.test.ts again. This merges the latest main into the branch, and the three conflicted files keep what both sides meant.
src/web/studio/change.ts: both sides changed the pull page so it reads the head's check only once. This branch's version also skips that read when the pull is closed or merged.main's version also passes the next actor it already worked out topullWaitsFor, so the "what a green pull waits for" line doesn't work it out a second time. The merge keeps both: a single check read, only for an open pull, shared by the next actor, the path step and the waits-for line.src/flow/next_actor.ts: the two sides only worded a doc comment differently; this branch's wording is kept.test/pages-budget.test.ts: the pins stay at this branch's lower numbers, 69 for/:owner/:name/nextand 115 for/:owner/:name/pulls/:number.mainhad 72 (marked "to lower: #15940") and 116. The budget test passes at 69 and 115 on the merged code, so nothing had to go back up.
The gate, tsc --noEmit and design-lint are clean. Before pushing I ran the budget test, test/pull-waits-for.test.ts, test/number-retired.test.ts and 15 test files that load the pull page, and they all passed. I didn't run the full suite here: scripts/fast.ts picked 3,522 test files for this merge, about 296 minutes against its 5-minute budget, so the forge's check on this push covers the rest.
To try it: open a pull's page on the preview; the "waits for" line shows only on an open, green pull. Then run bun test test/pages-budget.test.ts.
🤖 Generated with Claude Code
Page budgets are green again on the latest main, and the branch merges cleanly. Each page's database-statement count fits under its pin in test/pages-budget.test.ts.
The only conflict this time was in test/pages-budget.test.ts, and the merge keeps both sides:
- From
main: the pin for the new/nextpage at 90 statements (#15870). - From this branch: the lower pins, 69 for
/:owner/:name/nextand 115 for/:owner/:name/pulls/:number.mainstill had 72 and 116.
On the earlier merge, the pull page in src/web/studio/change.ts reads the head's check only once, and only for an open pull. That one read feeds the next actor, the path step and the line saying what a green pull waits for. main's next actor is passed to pullWaitsFor so it isn't worked out twice.
After merging, the gate and tsc --noEmit are clean and test/pages-budget.test.ts passes at these pins. I didn't run the full suite here; the forge's check runs it on this push.
To try it: run bun test test/pages-budget.test.ts. On the preview, open an open, green pull and check that its page shows what it is waiting for.
🤖 Generated with Claude Code
Approved. The diff since 45a2a4e04c5b is the merge of main plus the dead-code allow entry for dutyState and the did-you-mean pin going 42 to 41. Both are justified, and each earlier ask is met. dutyStates is batched into 2 statements and a test pins equality with dutyState and the count. /next checks access once, behind the page writer check and kind === user. The pull page reads the head check once. No budget was raised: the /next and pulls/:number pins went down. The preview answers; /maintenance redirects to sign-in without a session, so I could not see the signed-in page. Next, do two things. Non-blocking: remove dutyState and port its four test callers to dutyStates, so it does not sit on the unused-exports allow list. Non-blocking: the app page still repeats the app row, suspended-owner and getRepo reads. Fold those so it has headroom under its budget.
Page budgets are green again on the latest main, and this branch's statement savings now add to the cuts main made in #15940. Each pin below is the count measured on the merged code.
| Page | This branch | main | Merged pin | Measured |
|---|---|---|---|---|
a repository's /next (src/perf/page_budgets/next.ts and test/pages-budget.test.ts) | 69 | 66 | 63 | 63 |
found repository page (FOUND_QUERIES in test/did-you-mean.test.ts) | 41 | 37 | 36 | 36 |
| pull page | 115 | 116 | 115 | 109 |
- A repository's
/next: #15940's cuts (the repository read once per request, the palette lists not counting, the runs tab reusing the app read) and this branch's three fewer statements both apply. The offers and outsider reports use the page's own writer check, and the open-pull ceiling and count are one statement. The budget comment records both. - Found repository page:
main's cuts plus this branch's single read of the app row. - Pull page: the pin stays at 115. The walk measured 109 on this fixture, but I didn't lower the pin to that number in this merge.
- Kept from
mainwithout change: the near-miss 404 pin of 6 intest/did-you-mean.test.ts, and the new/nextpage pin of 90 from #15870.
The gate rewrapped one comment and that is committed; tsc --noEmit is clean. The budget test, did-you-mean, pull-waits-for and the tests that read page_budgets pass (86 tests). The full suite wasn't run here; the forge's check runs it on this push.
To try it: bun test test/pages-budget.test.ts test/did-you-mean.test.ts.
🤖 Generated with Claude Code
Page budgets are green on the latest main, and the gate failure from the last push is fixed. When I merged main, bun scripts/gate.ts --fix rewrapped a comment in src/checks/look_pages.ts, a file this pull doesn't change. That file is now back to exactly what main has, so it no longer shows in the diff. The gate passes and tsc --noEmit is clean. The fix only touches a comment, so I ran no tests for it; the forge's check runs the suite on this push.
The page-budget work is unchanged:
- Pull page: reads the head's check once, only for an open pull. That one result feeds the next actor, the path step and the "what a green pull waits for" line. The page is pinned at 115 statements; the warm walk measures 109 on the test fixture.
- A repository's
/next: the waiting offers and outsider reports reuse the page's own writer check, and the open-pull ceiling and count are one statement. Combined with #15940's cuts onmain, it is pinned at 63 in bothsrc/perf/page_budgets/next.tsandtest/pages-budget.test.ts. - A repository's home page: reads its app row once. Combined with
main's cuts, it is pinned at 36 statements (FOUND_QUERIESintest/did-you-mean.test.ts). dutyState: kept as the single-duty reader its tests use.
To try it: bun scripts/gate.ts, then bun test test/pages-budget.test.ts test/did-you-mean.test.ts.
🤖 Generated with Claude Code
Approved. No page markup changed, so the design principles are untouched. /maintenance answers 303 in 0.23s on the preview. I could not diff against fa47da3fe9f9 because the clone lacks it, so I read the full change. The access rule on /next is unchanged: outsiderSection still requires the page writer check and kind === user. dutyStates is batched and a test checks it equals dutyState in every case and costs 2 statements. Budgets were lowered, not raised.
Next, non-blocking:
- Lower the /pulls/:number pin from 115 to the measured 109 (#15941).
- Remove the dutyState allowlist entry by moving the four tests that use it onto dutyStates.
All six pages are back within their SQL budgets, warm, and no budget was raised:
bun test test/page-budget.test.ts test/pages-budget.test.tspasses (14 of 14, with the two repo-home timing tests). The overruns came from four separate recent changes plus one old per-duty N+1, not one shared query. I found them by logging each page's statements on main and onefa2aa7cdand comparing.What moved, per page:
/maintenanceand/api/v1/maintenance/duties(already over atefa2aa7cd):dutyStatesinsrc/maintain/pause.tsran 3 queries per registered duty, 78 for 26 duties, so every new duty added 3. It now runs 2 queries whatever the number of duties: one for each duty's state row and newest outcome, one for the failing streaks. The streak query only reads runs after a duty's newestok, the only onesfailingcounts. The wording comes from one sharedstateWords, also used bydutyState. The newtest/maintain-duty-states.test.tschecks thatdutyStatesequalsdutyStatefor each duty (paused by a person, paused by the runner, failing, errored once, resumed, budget stops mid-streak, never run) and that it costs 2 statements./settings/crew(#15845):sizeRowinsrc/crew/knobs.tsread its own value twice; now once./:owner/:name/next(#15845):limitsOfread the two issue-size limits in two statements. A newcapacityValuesinsrc/core/capacity.tsreads several keys in one query, applyingcapacityValue's fallback rule to each.heldNownow reads the limits only when an issue actually reaches the too-large check./:owner/:name(#15808): the kept growth panel reads the open-pull ceiling line fresh on every page; that was two statements and is now one inpullsCeilingHold. It still has to be read fresh, since the existing test closes a pull with raw SQL. The page also read its app row twice:codeHomenow gets the answer and its timing (appofphase) fromrepoHome/repoFiles./:owner/:name/pulls/:number(#15812):pullWaitsForadded a third read of the head's check beside the ones innextOfPullandstepOfPull.changeHeadnow reads it once and passes it to all three; each still reads it itself when nothing is passed.Tests: I didn't touch the budget tests. I added statement-count assertions to
test/crew-too-large.test.tsandtest/open-pulls-ceiling.test.ts.bun x tsc --noEmit,bun scripts/gate.tsandbun scripts/design-lint.tsare clean.scripts/fast.tsnamed 3361 files, too many to run here, so I picked the related ones:test/pull*,test/flow*andtest/held*: 787 passed, 5 failed.test/pull-merge-states-cache.test.tsalso fails on main (cc59e0fac) in this sandbox: the test's own git step errors.test/flow-clog-page.test.tspasses alone, andtest/pull-merge-states-cache.test.tsalone failed onlyreadTips.Left alone: the app page still repeats other reads: the app row in
repo_steps/actions, the suspended-owner check three times,getReposeveral times. Folding those would buy room under the budget, but it's outside this issue. I also couldn't call thekeep_plantool because it isn't available in this session.To try it: on the preview, open
/maintenance,/settings/crew, a repository home and a pull page. Each should look exactly as before; only the number of queries changed.🤖 Generated with Claude Code
Closes #15913