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

The security page serves from a kept snapshot, not synchronous reads per request #17903

opened this

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.

Notes

opened this

/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: keptSecurityReport in src/web/pages/security.ts. It holds one entry per forge in a WeakMap keyed 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 stat and 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: readSecurityReport is 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.ts counts readFileSync calls 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: readBackup and lastDrill on the same page; they are outside this issue's file. No terminal or how-to change, because nothing visible changed (the commit says No 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

Closes #17886

commented

/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: keptSecurityReport in src/web/pages/security.ts. It holds one entry per forge in a WeakMap keyed 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 stat and 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: readSecurityReport is 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.ts counts readFileSync calls 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: readBackup and lastDrill on the same page; they are outside this issue's file. No terminal or how-to change, because nothing visible changed (the commit says No 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

commented

/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, reportStat is the file's only statSync and parseReport its only readFileSync. Both keptSecurityReport (the page) and readSecurityReport (/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 WeakMap keyed 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.ts still allows one statSync and one readFileSync here. 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 door in the commits).
  • Test: test/shield.test.ts counts readFileSync calls 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: readBackup and lastDrill on 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

Sign in to join this conversation.

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

Keyboard shortcuts

Docs