Public: anyone can read this; the crew can change it.
The security page serves from a kept snapshot, not synchronous reads per request #17903
Merged 22h 19m ago, live in production
/settings/security now keeps the security report it last parsed and reads security-report.json again only when the file's mtime or size changes. Before the fix, three requests made three reads of the file; now they make one. An unchanged file costs one stat per request instead of a read and a JSON parse.
-
Reviews
ApprovedClean. The admin security page keeps the parsed report per forge (WeakMap on the app) keyed by mtime and size, and reads the file again only when the key moves. A missing file shows Not run at once, and a change between the stat and the read is re-read on the next request. The size cap is kept, the page's words are untouched, and readSecurityReport still serves the controls page. The request-path allowance is updated with its reasons, and the new test counts reads over three requests (1, where it was 3), then a rewrite (2), then a deletion. No door change is needed because nothing visible changed. I read the diff and did not exercise the preview.
-
Checks
shipped production is serving it deploy 5ce50ab
-
History
- Speed: the security report has one stat for both readers, so the request-path list holds (#17886) 8565e3d
- Merge remote-tracking branch 'origin/main' into scout/17886-the-security-page-serves-from-a-kept-sna 14d5605
- An app whose run names a build output is built once per commit before it starts (#17899) da85963
- Speed: /settings/security keeps the parsed security report by mtime and size, read once per change (#17886) f40b60d
- Bring the green pulls that are conflicted up to date: 17820, 17815, 17782, 17614, 16846 (#17896) 838ce00
- A test names every synchronous file or process call on a request path, and the list only shrinks (#17895) 0d820b8
- The planner is asked when the reserve runs short, not only when a person writes on the direction (#17882) 4ab714b
- Full suite red: test/flows-actions.test.ts (#17880) 9d6fa9d
- Full suite red: test/looks-owner.test.ts (#17878) ba55044
- The checkouts sweep leaves a running check's own TMPDIR (<run>.tmp) alone (su… (#17876) 8e4596d
- Flaky test: a jar is checked and in place before the up, readable, and the old AutoStopper is aside (#17874) 9c0dc23
- family-words reads src/ once, not once per sentence, and leaves SLOW (#17872) 49845bf
- Full suite red: test/security-floor-routes.test.ts (#17870) 27f5834
- An awaited Modrinth lookup waits for the one a sync already began, not "Mods:… (#17868) a544da9
- Full suite red: 3 files in check run 01m8xkn7yvvjtbd07e5qhk1rk4 (#17866) c4333e8
- Sentinel: snapshot-failed was degraded 33 minutes today: The last snapshot failed: list chunks/ failed after 5 attempts: an unexpected error has occurred. The newest that lande… (#17863) 5fa2c54
- Sentinel: cloud-watch:digitalocean/prod was degraded 39 minutes today: The forge could not read digitalocean/prod to check it for stray machines (no answer in time); it is not known to be cl… (#17861) de6ec9b
- Cloud account digitalocean/prod shows more than the forge made (#17857) 137546a
- Cloud account hetzner/prod shows more than the forge made (#17856) be9fa4e
- A repository can have its own account order, tried there without reordering the forge (#17843) 14bd626
/settings/security now keeps the security report it last parsed and reads security-report.json again only when the file's mtime or size changes. Before the fix, three requests made three reads of the file; now they make one. An unchanged file costs one stat per request instead of a read and a JSON parse.
The public /security page reads no files (it renders from constants in src/view/security.ts), so nothing changed there. The synchronous read the issue means is readSecurityReport in src/web/pages/security.ts, used by the admin page /settings/security.
- What to look at:
keptSecurityReportinsrc/web/pages/security.ts. It holds one entry per forge in aWeakMapkeyed by the app, so it passes the module-state rule (#12569) and two forges in one process never share a report. - Correctness: rewriting the report (new mtime or size) makes it read again; deleting it makes the row say "Not run" right away. If the file changes between the
statand the read, the newer content is kept under the older key, so the next request sees the key has moved and reads again. A stale finding is never shown as fresh. - Reused, not changed:
readSecurityReportis the same plain reader as before, and/settings/security/controls(src/checks/controls.ts) still calls it. - Unchanged: the page's words and findings.
- Test: a new test in
test/shield.test.tscountsreadFileSynccalls on the report over three requests. It failed against the old code (3 reads) and passes now (1). It then rewrites the report and expects one more read with the new count, then deletes it and expects "Not run". - Left out:
readBackupandlastDrillon the same page; they are outside this issue's file. No terminal or how-to change, because nothing visible changed (the commit saysNo door).
Checks: bun x tsc --noEmit is clean, and the gate reads 0 fail with 2 notes, both answered in the commit message by No look: and Try: lines. These test files pass: shield, security-controls, module-state, global-spies-restored, test-honesty, unused-exports, page-budget, hollow and dupes. bun scripts/fast.ts named 197 files for this change, estimated at over nine minutes, so I ran the ones above rather than all of them; the forge's check runs the full suite on this push.
Try it: open /settings/security as an admin on the preview and reload a few times; the "Secret scan and self-test" row reads the same each time.
🤖 Generated with Claude Code
/settings/security keeps the security report it last parsed and reads security-report.json again only when the file's mtime or size changes. Three requests now make one read of the file where they used to make three, and an unchanged file costs one stat per request. The public /security page reads no files (it renders from constants in src/view/security.ts), so it is unchanged. The synchronous read the issue means is in the admin page in src/web/pages/security.ts.
- What to look at: in
src/web/pages/security.ts,reportStatis the file's onlystatSyncandparseReportits onlyreadFileSync. BothkeptSecurityReport(the page) andreadSecurityReport(/settings/security/controls) go through them. On a miss the page parses using the size it already stat'd, so a miss costs one stat and one read, the same as before the change. - Per forge: the kept report lives in a
WeakMapkeyed by the app, so two forges in one process never share one, and the module-state rule (#12569) holds. - Never stale: a rewrite (new mtime or size) is read on the next request; a removed file shows "Not run" at once. If the file changes between the stat and the read, the newer content is kept under the older key, so the next request reads again.
- Request-path rule: after merging
main,test/request-path-sync.test.tsstill allows onestatSyncand onereadFileSynchere. Only the two reasons changed, to say the read is kept by mtime and size. - Unchanged: the page's words and findings. Terminal and how-to are untouched because nothing visible changed (
No doorin the commits). - Test:
test/shield.test.tscountsreadFileSynccalls on the report over three requests. It failed against the old code (3 reads) and passes now (1). It also covers a rewrite being read again and a deletion showing "Not run". - Left out:
readBackupandlastDrillon the same page, which are outside this issue.
Checks: after the merge, bun x tsc --noEmit is clean and the gate reads 0 fail with 1 note: a comment line over 100 columns, which the nightly rewrap fixes. These test files pass: request-path-sync, shield, security-controls, module-state, unused-exports and dupes. I did not run all 197 files bun scripts/fast.ts named, so the forge's check on this push runs the rest.
Try it: open /settings/security as an admin on the preview and reload it; the "Secret scan and self-test" row reads the same each time.
🤖 Generated with Claude Code
/settings/securitynow keeps the security report it last parsed and readssecurity-report.jsonagain only when the file's mtime or size changes. Before the fix, three requests made three reads of the file; now they make one. An unchanged file costs onestatper request instead of a read and a JSON parse.The public
/securitypage reads no files (it renders from constants insrc/view/security.ts), so nothing changed there. The synchronous read the issue means isreadSecurityReportinsrc/web/pages/security.ts, used by the admin page/settings/security.keptSecurityReportinsrc/web/pages/security.ts. It holds one entry per forge in aWeakMapkeyed by the app, so it passes the module-state rule (#12569) and two forges in one process never share a report.statand the read, the newer content is kept under the older key, so the next request sees the key has moved and reads again. A stale finding is never shown as fresh.readSecurityReportis the same plain reader as before, and/settings/security/controls(src/checks/controls.ts) still calls it.test/shield.test.tscountsreadFileSynccalls on the report over three requests. It failed against the old code (3 reads) and passes now (1). It then rewrites the report and expects one more read with the new count, then deletes it and expects "Not run".readBackupandlastDrillon the same page; they are outside this issue's file. No terminal or how-to change, because nothing visible changed (the commit saysNo door).Checks:
bun x tsc --noEmitis clean, and the gate reads 0 fail with 2 notes, both answered in the commit message byNo look:andTry:lines. These test files pass: shield, security-controls, module-state, global-spies-restored, test-honesty, unused-exports, page-budget, hollow and dupes.bun scripts/fast.tsnamed 197 files for this change, estimated at over nine minutes, so I ran the ones above rather than all of them; the forge's check runs the full suite on this push.Try it: open
/settings/securityas an admin on the preview and reload a few times; the "Secret scan and self-test" row reads the same each time.🤖 Generated with Claude Code
Closes #17886