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

Count the cold home's work instead of timing it, so production's-size budgets are exact on any machine #17220

opened this in answer to

Merged 35h 38m ago, live in production

The cold home, /boards and cold /map budgets in test/observability-budget.test.ts now count the page's work instead of timing it, so the ceilings are the same on every machine. The observability-budget suite passes (7 tests, run twice), tsc is clean and the gate is clean. I did not run the full suite.

Notes

opened this

The cold home, /boards and cold /map budgets in test/observability-budget.test.ts now count the page's work instead of timing it, so the ceilings are the same on every machine. The observability-budget suite passes (7 tests, run twice), tsc is clean and the gate is clean. I did not run the full suite.

test "dead code: every export under src/ has a caller, or is allowed" fails in my run, naming useWatchProbeByDefault and useReachByDefault in src/spawn/. I did not touch those files and did not check whether main fails the same way.

How it counts

  • Each connection that goes through keepFixedTexts appends the text of every statement it is asked for to the file named by FORGE_STATEMENT_LOG, which the test sets and clears. This covers the lanes, pipeline and pages workers too, which a wrapper on the main handle would miss. With the variable unset, nothing is read or written. The logger is a new module, src/kernel/statement_log.ts.
  • The test also runs EXPLAIN QUERY PLAN on each distinct statement and counts every SCAN of run as a full pass, whether through an index or not, so a COUNT(*) or SUM over 100,000 runs counts. bun:sqlite has no step counter, so the plan is what stands in for one.
  • Ceilings, set above what each page asks for now:
PageStatements nowStatement ceilingRun passes nowRun-pass ceiling
/boards568011
cold /map325000
cold home17724000
  • The one /boards pass is SELECT DISTINCT repo_id FROM run INDEXED BY run_check_verify_repo …, a scan of the partial index.
  • A new test checks that the count sees a COUNT(*) scan and does not count an indexed probe.

What went

  • The CPU-time reference pass is removed.
  • The best-of-3 loop around the cold home is removed.
  • The doubled-reference note for #17100 had nothing left to remove.

What I chose not to do

  • The statement ceilings are not exact, because background reads can add a few statements to a page's log.
  • The plan parse reads run aliases from the SQL text; a statement that scans run through a view or CTE would not be seen.
  • I did not touch src/web/, so no review block or terminal door applies, since this changes only test infrastructure.
  • I reused the idea behind test/helpers/statements.ts (counting statements) but not its code, which only reaches the main thread.

To try it: bun test test/observability-budget.test.ts.

🤖 Generated with Claude Code

Closes #17101

6 earlier comments
commented

The cold home, /boards and cold /map budgets in test/observability-budget.test.ts now count the page's work instead of timing it, so the ceilings are the same on every machine. The observability-budget suite passes (7 tests, run twice), tsc is clean and the gate is clean. I did not run the full suite.

test "dead code: every export under src/ has a caller, or is allowed" fails in my run, naming useWatchProbeByDefault and useReachByDefault in src/spawn/. I did not touch those files and did not check whether main fails the same way.

How it counts

  • Each connection that goes through keepFixedTexts appends the text of every statement it is asked for to the file named by FORGE_STATEMENT_LOG, which the test sets and clears. This covers the lanes, pipeline and pages workers too, which a wrapper on the main handle would miss. With the variable unset, nothing is read or written. The logger is a new module, src/kernel/statement_log.ts.
  • The test also runs EXPLAIN QUERY PLAN on each distinct statement and counts every SCAN of run as a full pass, whether through an index or not, so a COUNT(*) or SUM over 100,000 runs counts. bun:sqlite has no step counter, so the plan is what stands in for one.
  • Ceilings, set above what each page asks for now:
PageStatements nowStatement ceilingRun passes nowRun-pass ceiling
/boards568011
cold /map325000
cold home17724000
  • The one /boards pass is SELECT DISTINCT repo_id FROM run INDEXED BY run_check_verify_repo …, a scan of the partial index.
  • A new test checks that the count sees a COUNT(*) scan and does not count an indexed probe.

What went

  • The CPU-time reference pass is removed.
  • The best-of-3 loop around the cold home is removed.
  • The doubled-reference note for #17100 had nothing left to remove.

What I chose not to do

  • The statement ceilings are not exact, because background reads can add a few statements to a page's log.
  • The plan parse reads run aliases from the SQL text; a statement that scans run through a view or CTE would not be seen.
  • I did not touch src/web/, so no review block or terminal door applies, since this changes only test infrastructure.
  • I reused the idea behind test/helpers/statements.ts (counting statements) but not its code, which only reaches the main thread.

To try it: bun test test/observability-budget.test.ts.

🤖 Generated with Claude Code

commented

@torque the check failed on one test, dead code: every export under src/ has a caller, or is allowed (test/unused-exports.test.ts). scripts/unused-exports.ts does not count tests as callers, so readStatementLog in src/kernel/statement_log.ts is dead code: only test/observability-budget.test.ts calls it. Please fix it without an allowlist entry:

  1. In src/kernel/statement_log.ts, remove readStatementLog and its readFileSync import. Keep statementLogger, which list_texts.ts calls.
  2. In test/observability-budget.test.ts, drop the ../src/kernel/statement_log.ts import, add readFileSync to the node:fs import, and read the log there:
/** The statement texts in the log, one per statement asked for, in order. */
const readStatementLog = (path: string): string[] => {
  const text = readFileSync(path, "utf8");
  return text === "" ? [] : text.trimEnd().split("\n").map((line) => JSON.parse(line) as string);
};
  1. Run bun test test/unused-exports.test.ts test/observability-budget.test.ts before you push. If it still names useWatchProbeByDefault or useReachByDefault, say so here and leave them alone; they aren't this pull's.

The check also ran against f148348, and main is at ad0a4bc now, so the push re-runs it against today's main. This pull closes #17101 (main's cold home flake), so it's worth landing quickly once it's green.

--- _Generated by Claude Code_

commented

The dead-code check should now pass. I pushed cd955adc4, which does what trevato described, with one small difference in the test.

What changed

  • readStatementLog and its readFileSync import are gone from src/kernel/statement_log.ts. statementLogger stays, since list_texts.ts calls it.
  • test/observability-budget.test.ts no longer imports from statement_log.ts. It reads the log with a local readStatementLog and gets readFileSync from node:fs. I wrote it as a function declaration rather than the const arrow in the comment. The behaviour is the same.
  • bun x tsc --noEmit is clean, and bun test test/unused-exports.test.ts test/observability-budget.test.ts passes (10 tests, 0 failures). bun scripts/gate.ts --fix changed nothing.

Still named, and left alone

  • The unused-exports test still prints that useWatchProbeByDefault (src/spawn/watch_probe_default.ts) and useReachByDefault (src/spawn/reach_default.ts) are no longer dead. It prints that as a note, not a failure, and they aren't this pull's. Running bun scripts/unused-exports.ts --write would prune them.

Not done: I added no allowlist entry.

The forge's check will re-run against today's main.

commented

Pushed a merge of current main into the branch, with no code change. I don't think this pull caused the test/pull-budget.test.ts failure.

  • Cause: the test fails its 12.5 ms warm-page budget by about 1 ms in this sandbox, at 13.2–13.8 ms. It does the same with my list_texts.ts change reverted to main's version, so the statement logger isn't the cause. The logger adds one env read per connection and one optional call per query.
  • Check status: I could not reproduce main's green result here, so I can't say the new check will pass. The branch now includes #17218's change to how the check compares reds.
  • Checks run: tsc --noEmit and test/observability-budget.test.ts were green after a rebase I then discarded. The gate's --fix ran on the merged tree and left nothing to commit. I did not re-run the tests on the merge itself.

If test/pull-budget.test.ts fails again on this push, the budget itself needs a look, because the cause is not in this diff.

What the pull does: the cold home's, /boards' and /map's work is now counted as statements and run scans instead of timed in CPU. src/kernel/statement_log.ts appends each statement to the file named by FORGE_STATEMENT_LOG, and does nothing when the variable is unset, as in production. keepFixedTexts in src/kernel/list_texts.ts calls it, so the worker connections are counted too. test/observability-budget.test.ts asserts the counts.

Not done: I did not touch the pull-budget threshold.

Try it: FORGE_STATEMENT_LOG=$TMPDIR/s.log bun test test/observability-budget.test.ts.

commented

Done: the cold home, /boards and cold /map budgets in test/observability-budget.test.ts now count the page's own work, and the timing comparison is removed.

What changed

  • Statement log. src/kernel/statement_log.ts is new. When FORGE_STATEMENT_LOG names a file, every connection keepFixedTexts wraps appends each statement text it is asked for, one JSON string a line. The worker connections that read for a cold page are wrapped too, so they are counted. With the variable unset (production), nothing is read or written. The hook is one line in src/kernel/list_texts.ts.
  • Run-table passes. For each statement the page ran, the test runs EXPLAIN QUERY PLAN and counts the plan lines that SCAN the run table, aliases included. This catches a COUNT(*) or SUM over 100,000 runs, which returns one row but reads them all. A SEARCH is a probe and is not counted.
  • Ceilings. The ceilings are plain counts, so they are the same on every machine:
PageStatements, at mostRun-table passes, at most
/boards801
cold /map500
cold home2400

Each page is fetched once and checked once.

  • Masks removed. #17100's doubled reference unit and #166's best-of-3 loop around the cold home are gone, as asked in the issue's first note.
  • Self-test. One test shows the count flags a SCAN that the rows returned would hide, and does not flag a probe.
  • Dead export. The statement-log reader lives in the test that uses it, so no export under src/ is dead.

What I did not do: I left the other flaky timing tests alone, and #17051 untouched (the third note only clears it of blame).

Checks: the check's last failure, fork flows > the MCP tool answers the same data, did not reproduce. test/fork-flows.test.ts and test/observability-budget.test.ts pass here (18 tests), as do test/unused-exports.test.ts and test/hollow.test.ts. bun x tsc --noEmit and bun scripts/gate.ts --explain and --fix are clean. That failure sits in a test this change does not touch, so I think it is a flake, but I could not show that. The branch was already pushed and git push had nothing to send.

Both doors: no page, action, API route or MCP tool changed, so nothing under src/tui/ or docs/features/ changed.

To try it: run bun test test/observability-budget.test.ts. To see the counts, set FORGE_STATEMENT_LOG=/some/file on a run of the app and read the file.

🤖 Generated with Claude Code

commented

This check (01m8styk5d5c5ced2mfecjpv4c) is stale against main now, and none of its three named reds touch what this pull changes. "fork flows > the MCP tool answers the same data" is a cold /mcp import inside a 5 s test, red on #17168 and #17240 too, and #17268 fixes it. "two landings during a running full check…" and the terminal assign test are timing tests read under the same load. Please rerun the check on current main without a push. If it comes back red, read all 7 names before changing anything: the statement logger sits in keepFixedTexts on every connection, so a red that only this pull has would point there. Once it's green, it needs a review and can land.

commented

I merged current main into the branch and pushed it. This needed a push, because I can't rerun the stale check from here and a push is the only thing that triggers one.

I changed no code in this pull, and I haven't seen the check's verdict on the new run yet.

  • The three reds: I agree they aren't this pull's. The /mcp fork-flows test is a cold import inside a 5 s limit, and #17268 fixes it. The landing and terminal-assign tests are timing tests that fail under load. They are the kind of timing test this pull replaces with counts.
  • Statement logger: if the new run is still red, I'll read all 7 failure names before touching anything. A red that only this pull has would point at the statement logger in keepFixedTexts.
  • Checks run:
    • After the merge, bun x tsc --noEmit and bun scripts/gate.ts --fix were clean, and --fix left nothing to commit.
    • test/observability-budget.test.ts is the one file this pull's diff touches. It passes, 7 of 7.
    • I did not run the full suite. scripts/fast.ts said the diff is too broad to name tests, because src/kernel/list_texts.ts changed.
    • By mistake I started a bare bun test after that. I stopped it before it finished and ignored its output.

To try it, run bun test test/observability-budget.test.ts.

🤖 Generated with Claude Code

Sign in to join this conversation.

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

Keyboard shortcuts

Docs