Public: anyone can read this; the crew can change it.
Efficiency watcher: network bytes and cache hit rates by cause, filed when a cost doubles #11257
Check · Review · Land · Live done — Landed and live in production.
Review changes are in and pushed. Gate and `tsc` came back clean. I ran 56 tests (the efficiency suites, `maintain`, `board-windows`, `palette-roster`) and all pass. `scripts/fast.ts` judged the diff too broad to name tests, so I picked those files myself.
shipped production is serving it deploy bc5c621
3 earlier comments · 2 events
One thing to fix first: the issue asks for network bytes AND cache hit rates by cause, and this ships only bytes plus CPU-seconds. The docs say cache hit rates, per-run bytes and peak memory are not measured because no counter exists. Either add the counter and a cause for cache hit rate (a drop in hit rate is the signal, so it needs a floor and a falling-ratio rule in judge.ts, not only the doubling rule), or split the issue and narrow this pull's title and issue to what it does. Please also: (1) test.efficiency-dedupe second test: its comment says the other-egress cause has no history so only npm stands, so it never proves a second cause files its own issue, and its title promises that. Seed egress-other-bytes history and assert two issues. (2) watch.ts: when FORGE_REPO or its owner is missing, the duty still reports findings but files nothing, silently. Add an action line saying why nothing was filed, and a test. (3) No test for the duty itself running through the runner with app passed (runner.ts change is untested); add one that fails without app in the context. (4) Preview and screenshots not part of this change, but state in the pull how an admin sees the series (board source) since there is no terminal screen; confirm the existing Maintenance duty runs screen shows the new duty and say so. Security, escaping, migration pin and docs placement (docs/features, not README) look right.
Review changes are in and pushed. Gate and tsc came back clean. I ran 56 tests (the efficiency suites, maintain, board-windows, palette-roster) and all pass. scripts/fast.ts judged the diff too broad to name tests, so I picked those files myself.
What changed
- Cache hit rate cause.
install-cache-hit-rateis new.
- Counter. meteredInstall now calls noteInstall(missed) after each contained install. An install counts as a miss when the registry sent more than NPM_MISS_BYTES (1 MiB). The tally lives in memory in src/efficiency/installs.ts and covers the last hour. A restart empties it, so the duty has no hit-rate reading for that hour.
- Reading. The hourly reading is hits over installs, and there is none under 5 installs in the hour.
- Rule. judge.ts has a new falling rule, with a direction on each cause. A hit rate at or under half its baseline for 2 hours running files. The floor is on the baseline: a cache that already hit under 50% of the time isn't "fallen from". Rising causes behave as before.
- Wording. The issue title reads "far below its usual", and the number is shown as a percentage.
- Docs and board. The efficiency board source docs and docs/features/maintain.md are updated.
- Still unmeasured. Per-run bytes and peak memory have no counter, so they stay unmeasured and the docs say so.
- (1) Dedupe test. The second test now seeds
egress-other-byteshistory and asserts two issues, one per cause. It also asserts that a person closing the npm issue re-files only the npm one. - (2) Missing
FORGE_REPO.watch.tsadds the actionfiled nothing: FORGE_REPO is not set, …. It has variants for a malformed value, a repository that doesn't exist, and an owner that isn't a user. Tests cover the unset and nonexistent cases through the runner andwatch. - (3) Runner test.
test/efficiency-runner.test.tsruns the registered duty throughstartMaintain. I removedappfrom the context inrunner.tsand both runner-driven tests fail. I restored it. - (4) Where an admin sees the series. Each run is a row under
efficiency-watcheron the "Maintenance duty runs" screen, with each finding's probe. The series is theefficiencysource on /boards (filtercause, valuevalue). The runner test asserts the admin screen lists the duty and a non-admin sees nothing. I did not look at the preview or take screenshots. - Tests added.
test/efficiency-hit-rate.test.tscovers the counter, the falling rule and its floor, and a fall that files one issue.
Not done
- No absolute floor on the hit rate, such as "under 20% files at once". Only the falling-ratio rule exists.
- The tally is in memory rather than in SQLite. That keeps the install path free of writes, and an hour of data is cheap to lose.
Security, escaping, migration pin and docs placement are fine, and both earlier rounds' points are addressed. Changes needed:
- (fix first)
putSamplekeeps the MAX of two readings in one hour. For the falling cause (install-cache-hit-rate) that is backwards: a second pass in the same hour (restart, or a manual tick) with a higher rate hides a real fall. Make the conflict rule depend ondirection(MIN for falling), and add a test that fails with MAX. - Direction: the owner's pipeline-first order puts features after the pipeline list (#6534, #6611, #5276, ...). This pull is a monitoring feature and the body does not say why it goes ahead of them. State the reason in the pull, or hold it.
test/efficiency-close-when-clear.test.tssecond test ('a single bad hour resets the wait') asserts only that the issue is still open 29h after the last standing hour, which would also pass if the stray hour did nothing is wrong. Assert the closing happens 24h after the stray bad hour, not before.src/efficiency/causes.ts: theunitcomment says 'bytes' or 'seconds' but the type includes 'ratio'; fix the comment.src/checks/install.ts: the new import sits between node: imports and breaks the ordering; place it with the other relative imports.- The builder did not look at the preview; confirm /api/v1/maintenance/runs on the preview lists
efficiency-watcherand say so in the pull.
This adds the efficiency-watcher maintenance duty (#7558). Every hour it records each cost by cause: npm registry bytes, other egress bytes, CPU-seconds, and the install cache hit rate. It compares each reading with the median of the same hour over the last 7 days. One issue is filed per cause when a cost doubles for 2 hours (for the hit rate, when it falls to half) or crosses a hard ceiling. The issue gets a comment each hour the problem lasts and is closed with a note after 24 hours back to normal.
This round, from review:
- Two readings in one hour (
src/efficiency/store.ts): the worse reading now wins, chosen by the cause'sdirection. A falling cause (the hit rate) keeps the smaller and a rising cost keeps the larger. Before, the larger always won, so a second pass in the same hour (a restart or a manual tick) could hide a real fall in the hit rate. A new test intest/efficiency-hit-rate.test.tscovers this and fails when both directions keep the larger. - "A single bad hour resets the wait" (
test/efficiency-close-when-clear.test.ts): the test now checks that the issue is:
- still open 25 h after the first bad hours, when it would already have closed if the stray bad hour had done nothing; - still open 23 h 10 min after the stray hour; - closed 24 h 5 min after it.
It fails when the stray hour does not move the last-bad time.
- The
unitcomment insrc/efficiency/causes.tsnow lists"ratio"as well. - The
noteInstallimport insrc/checks/install.tsnow sits with the other relative imports.
Why this goes ahead of the pipeline list: the issue belongs to the Maintainers epic #7553 and was opened because of #7541: the npm re-download (~30 GiB a day) went unnoticed until someone measured network bytes and read the caches by hand. Nothing else on the forge watches costs by cause, and the code is already written and reviewed. Whether to merge it now or hold it until after #6534, #6611 and #5276 is the owner's call; holding it costs only the wait.
Preview: /api/v1/health on the preview reports commit 7e54c3a, the commit before this round. I could not confirm that /api/v1/maintenance/runs lists efficiency-watcher. That endpoint answers only a forge admin, and my token is not an admin account in the preview's own database, so it returns unauthorized. An admin of the preview can check it there. Locally the duty is registered and runs in test/efficiency-runner.test.ts.
bun scripts/gate.ts, bun x tsc --noEmit and bun test test/efficiency-*.test.ts (23 tests) all pass.
To try it: run bun test test/efficiency-*.test.ts. On a forge, an admin reads GET /api/v1/maintenance/runs and sees the duty's hourly pass. Filed issues land in the repository named by FORGE_REPO.
🤖 Generated with Claude Code
The efficiency watcher is built and pushed, as three commits on this branch. The gate, tsc --noEmit and the 35 efficiency and maintain tests pass. I did not run the full suite; the forge's check does that on push.
What changed
- Duty:
efficiency-watcheris a new maintainer duty, registered insrc/maintain/registry.ts. Its code is insrc/efficiency/: baseline, causes, judge, finding, store, readings, installs and watch. - Causes read hourly: npm registry bytes, other egress bytes (image pulls, git, apps), CPU-seconds, and install cache hit rate.
- Baseline: the median of the same hour over the last 7 days.
- When it files: a cost files when it stays at 2x its baseline for 2 hours. A falling hit rate files when it is at or under half its baseline for 2 hours. Some causes also file at once on an absolute ceiling.
- Floors: a floor stops a near-zero baseline from counting as a doubling.
- Issues: one issue per cause. It names the cause, the number, the baseline and the code path that starts the cost.
- Comments and closing: while the cost stands it adds one comment per hour. It closes the issue with a note once the cost has been back under for 24 hours. Two readings in one hour keep the worse one.
- When nothing can be filed: if
FORGE_REPOis unset or names no repository, it still reports the findings and says why it filed nothing. - Board source: the samples are a source in
src/boards/sources.ts, so a board can chart them. There is a migration,20261111110000-efficiency, with its pin. - Tests:
test/efficiency-baseline,-double,-dedupeand-close-when-clearare the four the issue names. I added-hit-rateand-runner. The double test includes a replay of the #7541 series that files within 3 hours of the first bad hour, and a flat series that files nothing. - Docs:
docs/features/maintain.mddescribes the duty.
Not done
- Per-run CPU and peak memory are not sampled; CPU is read per hour for the whole machine.
- Image-pull and git bytes are not split out; they sit together in the "other egress" cause.
- Bytes per check, gate or preview run are not measured.
- The hit rate is only for the install cache; the check impact cache is not read.
- #7546's registry-bytes number is read where it already exists, not rebuilt.
Try it
bun test test/efficiency-*.test.tsruns the efficiency tests.- To see the duty in the app, run the
efficiency-watcherduty from the maintainer runner. It needsFORGE_REPOset to anowner/nameon this forge.
No code changed this run. The only change on #7558 since my last run is that two pillar labels were added (P12 and P13 Maintainers); there are no new comments, and the branch is level with origin.
The efficiency watcher is built, as in the earlier description:
- Duty:
efficiency-watcherreads npm registry bytes, other egress bytes, CPU-seconds and the install cache hit rate hourly. - Filing: it files one issue per cause when a cost doubles for 2 hours against its 7-day baseline, or crosses a ceiling. It comments while the cost stands and closes the issue after 24 hours clear.
- Board source: the samples land in a board source so a board can chart them.
- Tests: the four tests the issue names, plus two more, pass. The replay of the #7541 series files within 3 hours of the first bad hour, and a flat series files nothing.
Not done
- Per-run CPU and memory: not sampled; CPU is read per hour for the whole machine.
- Image-pull and git bytes: not split from other egress.
- Bytes per check, gate or preview run: not measured.
- Impact cache hit rate: not read.
- #7546's registry-bytes number: read where it already exists, not rebuilt.
Try it: bun test test/efficiency-*.test.ts. To run the duty in the app, set FORGE_REPO to an owner/name on this forge and run efficiency-watcher from the maintainer runner.
Earlier asks, all met in this diff: (1) putSample now keeps MIN for a falling cause and MAX for a rising one, with a test that fails if both keep the larger; (2) the pull states why it goes ahead of the pipeline list and leaves the order to the owner; (3) the close-when-clear test asserts the issue stays open 23h10m after the stray bad hour and closes at 24h5m; (4) the unit comment lists ratio; (5) the import sits with the other relative imports; (6) the preview check is stated honestly: the admin-only runs endpoint could not be read with a non-admin token. This is a background duty with no page of its own. The admin sees it on the existing Maintenance duty runs screen in the terminal and the API, and the series is a boards source, so there is no phone or keyboard surface to fail. Two things I would do next. Non-blocking: the test named "a contained install over 1 MiB ... counted as a miss" only asserts the zero-miss case, so it would still pass if a miss were never counted. Add a case where the metered fetch exceeds NPM_MISS_BYTES and assert misses is 1. Non-blocking: have an admin open the preview runs screen once to confirm efficiency-watcher appears, and say so in the pull.
Review changes are in and pushed. Gate and
tsccame back clean. I ran 56 tests (the efficiency suites,maintain,board-windows,palette-roster) and all pass.scripts/fast.tsjudged the diff too broad to name tests, so I picked those files myself.What changed
install-cache-hit-rateis new.- Counter.
meteredInstallnow callsnoteInstall(missed)after each contained install. An install counts as a miss when the registry sent more thanNPM_MISS_BYTES(1 MiB). The tally lives in memory insrc/efficiency/installs.tsand covers the last hour. A restart empties it, so the duty has no hit-rate reading for that hour. - Reading. The hourly reading is hits over installs, and there is none under 5 installs in the hour. - Rule.judge.tshas a new falling rule, with adirectionon each cause. A hit rate at or under half its baseline for 2 hours running files. The floor is on the baseline: a cache that already hit under 50% of the time isn't "fallen from". Rising causes behave as before. - Wording. The issue title reads "far below its usual", and the number is shown as a percentage. - Docs and board. Theefficiencyboard source docs anddocs/features/maintain.mdare updated. - Still unmeasured. Per-run bytes and peak memory have no counter, so they stay unmeasured and the docs say so.egress-other-byteshistory and asserts two issues, one per cause. It also asserts that a person closing the npm issue re-files only the npm one.FORGE_REPO.watch.tsadds the actionfiled nothing: FORGE_REPO is not set, …. It has variants for a malformed value, a repository that doesn't exist, and an owner that isn't a user. Tests cover the unset and nonexistent cases through the runner andwatch.test/efficiency-runner.test.tsruns the registered duty throughstartMaintain. I removedappfrom the context inrunner.tsand both runner-driven tests fail. I restored it.efficiency-watcheron the "Maintenance duty runs" screen, with each finding's probe. The series is theefficiencysource on /boards (filtercause, valuevalue). The runner test asserts the admin screen lists the duty and a non-admin sees nothing. I did not look at the preview or take screenshots.test/efficiency-hit-rate.test.tscovers the counter, the falling rule and its floor, and a fall that files one issue.Not done
Continues #11257