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

Fast everywhere: displays first, then a time budget every page is tested against #10448

Parked opened this in answer to
Closed without merging

The display page did one git read per build. It now reads git once per source repository. Every GET page is walked against a work budget, and /system lists each page that misses the 150 ms / 1 s budget, with nothing shown when all are fast.

Notes

stopped parked by the crew deploy d64fa4b

opened this

The display page did one git read per build. It now reads git once per source repository. Every GET page is walked against a work budget, and /system lists each page that misses the 150 ms / 1 s budget, with nothing shown when all are fast.

Display page: the cause. /:owner/:name/display read each source's pins three times per request: once for the items, once for the writer's selection, once for the choices. It also read every build's forge.json and package.json from git on every request, through demoFactsAt. The fix has two parts:

  • src/display/reads.ts (DisplayReads): one object per page, shared by displayItems, selectionKeys and choosableBuilds, so each source's pins and branch tip are read once.
  • src/actions/pin_demos.ts: a commit's demo facts are kept by commit id, which is safe because git objects never change. The cache is capped at 4096 entries.

The page also names its other phases in Server-Timing now (launch, choices).

Before and after (bench/display-phases.ts: 72 builds in 6 sources, 30 warm hits, signed in as the display's writer):

GET /alice/shelf/displaygit work per requestapp p50app p95items p50
before163262 ms348 ms193 ms
after750 ms77 ms27 ms

/displays was already cached (display/known.ts). Warm, it reads no git before or after, at about 6 ms p50. "Git work" is a new count in src/perf/git_work.ts: git processes spawned plus objects read through the long-lived cat-file readers. test/display-git-work.test.ts holds it: the display page's git work stays the same when each source gains three builds, it is at most one read per source plus the tip, and warm /displays is 0.

A budget for every page. PAGE_BUDGET (server p95 under 150 ms) and PAINT_BUDGET (first paint p75 under 1 s) are in src/perf/budgets.ts. First paint is the LCP the browser beacon already reports; Safari sends none, so it isn't counted.

test/page-budget-walk.test.ts walks every GET page the router registers. The forge it runs against has four showcased builds and a display. Each warm page may use at most 6 units of git work and 100 SQL statements; the heaviest today is 4 and 79. A page over that fails by name, with its counts and its slowest phase. Run against the old display code, it fails with /alice/forge/display: git 12 (max 6), SQL 48 (max 100), slowest phase items 12.5 ms.

The walk counts work rather than milliseconds, because docs/PRINCIPLES.md and scripts/flake.ts forbid clock bounds under 200 ms in tests. The 150 ms is checked against real request timings on /system. The list of pages to walk moved to test/helpers/swept-pages.ts, shared with the existing Server-Timing sweep.

Watched for real. /system now opens with Pages over budget only when a page misses it: one line per page. Two rules decide it:

  • Server: p95 over 150 ms in the last 15 minutes, with at least 20 requests. The line names the slowest phase.
  • First paint: p75 over 1 s across today's and yesterday's browser reports, with at least 20 views. The line says how many views painted slowly.

When every page is fast, nothing is drawn, not even the heading (src/perf/page_budgets.ts). The p75 is exact by counting: with nearest rank, it is over 1 s exactly when fewer than ⌈0.75·n⌉ views painted within 1 s. The count uses a new index, page_vital_day_route_lcp, and the test shows it from the query plan with no scan and no sort.

What I chose not to do:

  • The perf watcher still opens issues at its old limits: 800 ms for home and the repository page, 1 s for repository sub-pages. At 150 ms it could open an issue for every page on the first day. Pages between 150 ms and those limits show on /system instead. Lowering the watcher's limits is a separate decision.
  • Pins are still read once per source per request (6 for-each-ref calls in the bench). They aren't cached between requests, because pinning a build doesn't always emit an event to clear such a cache.

Couldn't measure on the real forge, and one thing to look at. I couldn't measure /trevato/games-shelf or /trevato/realty-desk directly. Both 404 on the lab production app, and the forge's pages don't accept my API token. All numbers above come from the bench. Those 404s on the forge still reported lag;dur=1718.1: some event-loop stall of about 1.7 s happened in the last 10 seconds. That is separate from this change and worth chasing from the stalls section on /system.

Checks run: bun scripts/gate.ts, bun x tsc --noEmit and bun scripts/design-lint.ts pass. The covering tests pass: display, displays, arcade, TUI display, the walk, the sweep, system, perf, schema and measure. scripts/fast.ts named 2093 files (the change to git/read.ts reaches almost everything), so I picked those files myself instead. The keep_plan tool wasn't available in this run, so the issue has no plan. I found no prompt injection in the repository or the issue.

To try it: open /trevato/games-shelf/display and read its Server-Timing phases; open /system as the owner; run bun run bench/display-phases.ts and bun test test/page-budget-walk.test.ts. How to use it is in docs/features/page-budgets.md.

🤖 Generated with Claude Code

Closes #10445

4 earlier comments · 1 event
commented

The display page did one git read per build. It now reads git once per source repository. Every GET page is walked against a work budget, and /system lists each page that misses the 150 ms / 1 s budget, with nothing shown when all are fast.

Display page: the cause. /:owner/:name/display read each source's pins three times per request: once for the items, once for the writer's selection, once for the choices. It also read every build's forge.json and package.json from git on every request, through demoFactsAt. The fix has two parts:

  • src/display/reads.ts (DisplayReads): one object per page, shared by displayItems, selectionKeys and choosableBuilds, so each source's pins and branch tip are read once.
  • src/actions/pin_demos.ts: a commit's demo facts are kept by commit id, which is safe because git objects never change. The cache is capped at 4096 entries.

The page also names its other phases in Server-Timing now (launch, choices).

Before and after (bench/display-phases.ts: 72 builds in 6 sources, 30 warm hits, signed in as the display's writer):

GET /alice/shelf/displaygit work per requestapp p50app p95items p50
before163262 ms348 ms193 ms
after750 ms77 ms27 ms

/displays was already cached (display/known.ts). Warm, it reads no git before or after, at about 6 ms p50. "Git work" is a new count in src/perf/git_work.ts: git processes spawned plus objects read through the long-lived cat-file readers. test/display-git-work.test.ts holds it: the display page's git work stays the same when each source gains three builds, it is at most one read per source plus the tip, and warm /displays is 0.

A budget for every page. PAGE_BUDGET (server p95 under 150 ms) and PAINT_BUDGET (first paint p75 under 1 s) are in src/perf/budgets.ts. First paint is the LCP the browser beacon already reports; Safari sends none, so it isn't counted.

test/page-budget-walk.test.ts walks every GET page the router registers. The forge it runs against has four showcased builds and a display. Each warm page may use at most 6 units of git work and 100 SQL statements; the heaviest today is 4 and 79. A page over that fails by name, with its counts and its slowest phase. Run against the old display code, it fails with /alice/forge/display: git 12 (max 6), SQL 48 (max 100), slowest phase items 12.5 ms.

The walk counts work rather than milliseconds, because docs/PRINCIPLES.md and scripts/flake.ts forbid clock bounds under 200 ms in tests. The 150 ms is checked against real request timings on /system. The list of pages to walk moved to test/helpers/swept-pages.ts, shared with the existing Server-Timing sweep.

Watched for real. /system now opens with Pages over budget only when a page misses it: one line per page. Two rules decide it:

  • Server: p95 over 150 ms in the last 15 minutes, with at least 20 requests. The line names the slowest phase.
  • First paint: p75 over 1 s across today's and yesterday's browser reports, with at least 20 views. The line says how many views painted slowly.

When every page is fast, nothing is drawn, not even the heading (src/perf/page_budgets.ts). The p75 is exact by counting: with nearest rank, it is over 1 s exactly when fewer than ⌈0.75·n⌉ views painted within 1 s. The count uses a new index, page_vital_day_route_lcp, and the test shows it from the query plan with no scan and no sort.

What I chose not to do:

  • The perf watcher still opens issues at its old limits: 800 ms for home and the repository page, 1 s for repository sub-pages. At 150 ms it could open an issue for every page on the first day. Pages between 150 ms and those limits show on /system instead. Lowering the watcher's limits is a separate decision.
  • Pins are still read once per source per request (6 for-each-ref calls in the bench). They aren't cached between requests, because pinning a build doesn't always emit an event to clear such a cache.

Couldn't measure on the real forge, and one thing to look at. I couldn't measure /trevato/games-shelf or /trevato/realty-desk directly. Both 404 on the lab production app, and the forge's pages don't accept my API token. All numbers above come from the bench. Those 404s on the forge still reported lag;dur=1718.1: some event-loop stall of about 1.7 s happened in the last 10 seconds. That is separate from this change and worth chasing from the stalls section on /system.

Checks run: bun scripts/gate.ts, bun x tsc --noEmit and bun scripts/design-lint.ts pass. The covering tests pass: display, displays, arcade, TUI display, the walk, the sweep, system, perf, schema and measure. scripts/fast.ts named 2093 files (the change to git/read.ts reaches almost everything), so I picked those files myself instead. The keep_plan tool wasn't available in this run, so the issue has no plan. I found no prompt injection in the repository or the issue.

To try it: open /trevato/games-shelf/display and read its Server-Timing phases; open /system as the owner; run bun run bench/display-phases.ts and bun test test/page-budget-walk.test.ts. How to use it is in docs/features/page-budgets.md.

🤖 Generated with Claude Code

Changes requested — before the latest push

The display fix is sound: one DisplayReads per page, a commit-keyed facts cache, and a git-work count the walk test holds. Two things need changing.

  1. Both doors (fix first): 'Pages over budget' on /system is an owner-only view with no terminal screen. The stalls section beside it has one (src/tui/screens/loopstalls.ts, gated like /system). Add a screen in src/tui/ that uses pagesOverBudget and missLine, with the same admin-person gate as /system and its entry where AGENTS.md says. Add a test for it, and say in docs/features/page-budgets.md how to reach it.
  1. The commitFacts cache in pin_demos.ts also keeps a negative result. If forge.json is absent, or the object is not yet in the repo, it stores {pages:[], commit:false} for that dir+oid until eviction. A pin made before its objects arrive, for example a fork or a push still in flight, would then show no pages or launch and would not recover. Keep only results where the object was found (a commit was read), or add a test showing an absent object is re-read.

Minor: test/page-budget-walk.test.ts repeats the signin block in two tests, so extract it into a helper. The 6-unit and 100-statement ceilings are tuned to the current worst cases (4 and 79), so say in the test that they are deliberate.

commented

Display pages now read each source's pins once per page, and keep each commit's demo facts by commit id. Every GET page is tested against a budget of git and SQL work. The owner sees the pages over the 150 ms server or 1 s first-paint budget on /system and now also in the terminal.

Changes from review:

  • Terminal screen: Pages over budget is in the command palette, listed after Main-thread stalls (src/tui/screens/overbudget.ts, entry in src/tui/screens/entries.ts). It shows the same pagesOverBudget and missLine lines /system does, read once when the screen opens, with the same gate: a forge admin who is a person. When every page is fast it says so in one line instead of showing an empty screen. A test in test/page-budgets.test.ts checks that an admin person gets the lines and the palette entry, and that a member, an admin agent and a signed-out session get neither. docs/features/page-budgets.md says how to reach it.
  • Demo facts cache: commitFacts in src/actions/pin_demos.ts no longer keeps a result for an object it could not read as a commit: a missing object, or one that is not a commit, is read again next time. test/pin-demo-facts.test.ts pins a commit before its objects are pushed, sees no pages, pushes, and sees the pages. It fails without the fix.
  • Walk test: test/page-budget-walk.test.ts signs in through one helper. Its comments now say the ceilings are deliberate: 6 units of git work against today's worst of 4, and 100 SQL statements against today's worst of 79.

What to look at: the gate in overbudget.ts is the one loopstalls.ts uses. The cache only drops an entry if it is still the same pending read, so a newer read is never removed by an older one.

Not done: the screen does not refresh while open. Like the page, it reads once; close and reopen it to read again.

How to try it: ssh to the forge as an admin, open the command palette and choose Pages over budget. Or run bun test test/page-budgets.test.ts test/pin-demo-facts.test.ts test/page-budget-walk.test.ts.

Checks run here: bun scripts/gate.ts, bun x tsc --noEmit and bun scripts/design-lint.ts pass. The diff against main was too broad for scripts/fast.ts to narrow, so I chose the tests myself: the four budget, stall and demo-facts files, and 32 palette and terminal files, all passing.

🤖 Generated with Claude Code

commented

Every page now has a budget: 150 ms of server time and 1 s to first paint, plus a ceiling on git and SQL work. Pages that miss it are listed on /system and on a new "Pages over budget" screen in the terminal. A display page also reads each source's pins once instead of once per build, and a commit's demo facts are kept only after the commit has been read.

This push fixes the two failures from the last check. Both only showed up after merging current main, which is now merged into the branch:

  • test/unreached.test.ts: main deleted src/kernel/why_now.ts but left it in scripts/unreached-allow.json, so main itself fails this test. I removed the stale entry.
  • test/palette-roster.test.ts: the test pins the palette roster, and this pull adds an entry to it. I changed the test: it now expects the over-budget entry ("Pages over budget", "pages missing 150 ms server or 1 s first paint"), just before capacity. The code was right; the test was out of date.

What to look at: src/perf/page_budgets.ts for the budgets, src/tui/screens/overbudget.ts for the terminal screen, and the display read changes in src/display/reads.ts and src/display/items.ts.

How it was checked, on the merged tree: bun scripts/gate.ts and bun x tsc --noEmit are clean. Both fixed tests pass, as do this pull's own tests (page-budgets, page-budget-walk, display-git-work, pin-demo-facts, server-timing-sweep). scripts/fast.ts returned exit 2 because the allow-list change is too broad to map to tests, so I chose those files by hand and left the full suite to the forge's check.

To try it: open /system on the preview to see the pages over budget, or open the palette in the terminal and choose "Pages over budget".

🤖 Generated with Claude Code

commented

This fixes the one failed check, "child quota > room for small but not large is refused only for large". The app code was fine; the test was out of date.

Main raised a small child forge to 2048 MiB of memory in ab3dadb9f, but test/child-quota.test.ts still set FORGE_CHILD_MEMORY_MIB=2000. The earlier test in the same file has already spawned one small forge, so 2048 MiB is held. Another small forge would bring that to 4096 MiB, over the 2000 MiB limit, so small was refused when the test expected it to fit.

The test now computes the limit from SIZES as one held small forge plus one more small. That leaves room for a small forge but not a large one, and the limit will follow the sizes if they change again.

test/child-quota.test.ts passes (4 of 4), and bun scripts/gate.ts and bun x tsc --noEmit are clean. I didn't re-run the full suite here; the forge's check on this push will.

🤖 Generated with Claude Code

commented

Parked by the crew: the check stayed red through 2 automatic tries

Sign in to join this conversation.

↑↓ navigate ↵ open ⌘↵ its app esc close

Keyboard shortcuts

Docs