Public: anyone can read this; the crew can change it.
The access log's rotate and prune leave the serving thread #17901
Merged 21h 45m ago, live in production
Before this change, pruning the access log and shedding a full day's file ran on the serving thread inside the flush. They now run as a background job (access-keep) that hands the thread back between file calls.
-
Reviews
ApprovedClean. Prune and shed now run as the
access-keepbackground job, one file call a tick, queued behind the pass in flight. The append stays synchronous. The shed's last chunk and its rename share one tick, so no line is lost or doubled. ENOENT is tolerated, the tmp file is cleaned up on failure, and the new tests would fail on the old code. The rule tests (UNTIMED, the sync-call counts) are updated, and no door or README change is needed. Non-blocking:access-flushnow awaits the whole keeping chain becauseflushAccessreturns it, so that job stays open for the length of a shed. -
Checks
shipped production is serving it deploy 5ce50ab
-
History
- The access log's keeping meets the rule tests: no module Set, its job named, its sync calls counted (#17884) dcbb2dc
- Merge remote-tracking branch 'origin/main' into torque/17884-the-access-log-s-rotate-and-prune-leave 1c3dec6
- An app whose run names a build output is built once per commit before it starts (#17899) da85963
- Bring the green pulls that are conflicted up to date: 17820, 17815, 17782, 17614, 16846 (#17896) 838ce00
- Each flush's keeping queues behind the pass in flight, not skipped while it runs (#17884) 5773590
- The access log test pauses on breathe, not a fixed timer (#17884) bc8ca4b
- A test names every synchronous file or process call on a request path, and the list only shrinks (#17895) 0d820b8
- The access log's prune and shed run as a background pass that yields between file calls (#17884) 1aa2cab
- 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
Before this change, pruning the access log and shedding a full day's file ran on the serving thread inside the flush. They now run as a background job (access-keep) that hands the thread back between file calls. The append in flushAccess stays synchronous and unchanged; the function now returns a promise that settles when its keeping work is done, and it never rejects.
pruneis now async. It makes one file call per tick: thereaddirSync, then eachunlinkSyncorstatSync. Forty day files take dozens of short ticks instead of one long one. A file another process already deleted counts as done.- Shedding copies the newest half of the file into
<file>.tmp, 1 MB per tick. The tick that reaches the end of the file copies the rest and renames over the original without yielding. Lines this process appends during the copy go onto the old file and are carried over, and since nothing can be appended between that last copy and the rename, no line is lost or written twice. As before, a line another process appends in that same instant can still be lost. - Ordering: each flush's work queues behind the job already running instead of being skipped. A shed is queued at most once per file, so two jobs never cut the same file.
Tests (test/access-log.test.ts):
- 40 day files plus a full 16 MB current file: the file calls are counted between pauses. No tick makes more than 6, over more than 40 ticks. Before the change, a single tick made about 60 calls, including a 16 MB read and an 8 MB write. The test also checks that 14 files are left and the shed file starts on a whole line.
- Lines during a shed: a line is recorded and flushed at every pause of the shed. The file ends up with each line exactly once, in order.
Both new tests fail against the old code. I changed three existing tests from that file because they assumed keeping finished inside the flush; they now await prune and flushAccess. Those tests were wrong under the new behaviour, not the code.
Not done: I didn't move this to a worker thread. Short slices already meet the bound, and a worker would need its own file locking. I also didn't change how readers or the settings page read the log.
Checks: the gate passes, apart from a note about one comment line over 100 columns that the nightly rewrap handles. bun x tsc --noEmit passes. I ran the access log, vitals, tui-access, client-abort, spawn-host, timers-named, kernel-boundary, test-honesty, boot-no-stall, perf-loop-jobs and unused-exports suites: all pass. scripts/fast.ts named 2,818 files, too many to run here, so I picked these; the forge's check runs the full suite on the push.
Try it: send a few requests to the preview, then open /settings/access; the lines still show.
No door: no page, API route or tool changes; the log's readers get the same lines.
🤖 Generated with Claude Code
The access log no longer prunes or sheds on the serving thread. That work now runs in a background job (access-keep) that makes a few file calls and then yields with breathe(). The append in flushAccess is unchanged and still synchronous. flushAccess now returns a promise that settles when the work it queued is done, and it never rejects.
- Prune (
src/http/access_log.ts): it is now async and makes one file call per tick: thereaddirSync, then eachunlinkSyncorstatSync. A file another process already deleted counts as done. - Shed: the newest half of a full file is copied into
<file>.tmp, 1 MB per tick. The tick that reaches the end copies the rest and renames over the file without yielding. Lines appended meanwhile land on the old file and are carried over, so none is lost or written twice. A line another process appends in that same instant can still be lost, as before. - Ordering: each flush's work queues behind the job already running, so two jobs never cut one file. A shed first re-reads the file's size and stops if an earlier job already cut it, so no module-level set is needed.
Tests:
- New, in
test/access-log.test.ts: 40 day files plus a full 16 MB current file are handled in more than 40 ticks of at most 6 file calls each. Before, one tick made about 60 calls, including a 16 MB read. Separately, lines recorded at every pause of a shed end up in the file once each, in order. Both tests fail against the old code. - Changed: three existing tests now
awaitpruneandflushAccess, because they assumed the work finished inside the flush. The tests were wrong under the new behaviour, not the code. - Rule tests:
access-keepis named inUNTIMEDintest/job-slices.test.tswith its reason. The access log's row intest/request-path-sync.test.tsdropswriteFileSync, since the shed no longer calls it;statSyncstays at 4, with reasons updated. That test arrived on main after I branched, so I mergedorigin/mainto get it.
Passing here: the gate, bun x tsc --noEmit, and the three rule tests that failed the check. Also passing: the access-log, timers-named, unused-exports, vitals, tui-access and test-honesty suites, with access-log green three runs in a row. scripts/fast.ts named 2,818 files, so I picked these; the forge runs the full suite on this push.
Not done: no worker thread, since short ticks already keep each step to a few calls. No change to how readers or the settings page read the log.
Try: send a few requests to the preview, then open /settings/access; the lines still show.
No door: no page, API route or tool changes.
🤖 Generated with Claude Code
Before this change, pruning the access log and shedding a full day's file ran on the serving thread inside the flush. They now run as a background job (
access-keep) that hands the thread back between file calls. The append influshAccessstays synchronous and unchanged; the function now returns a promise that settles when its keeping work is done, and it never rejects.pruneis now async. It makes one file call per tick: thereaddirSync, then eachunlinkSyncorstatSync. Forty day files take dozens of short ticks instead of one long one. A file another process already deleted counts as done.<file>.tmp, 1 MB per tick. The tick that reaches the end of the file copies the rest and renames over the original without yielding. Lines this process appends during the copy go onto the old file and are carried over, and since nothing can be appended between that last copy and the rename, no line is lost or written twice. As before, a line another process appends in that same instant can still be lost.Tests (
test/access-log.test.ts):Both new tests fail against the old code. I changed three existing tests from that file because they assumed keeping finished inside the flush; they now
awaitpruneandflushAccess. Those tests were wrong under the new behaviour, not the code.Not done: I didn't move this to a worker thread. Short slices already meet the bound, and a worker would need its own file locking. I also didn't change how readers or the settings page read the log.
Checks: the gate passes, apart from a note about one comment line over 100 columns that the nightly rewrap handles.
bun x tsc --noEmitpasses. I ran the access log, vitals,tui-access,client-abort,spawn-host,timers-named,kernel-boundary,test-honesty,boot-no-stall,perf-loop-jobsandunused-exportssuites: all pass.scripts/fast.tsnamed 2,818 files, too many to run here, so I picked these; the forge's check runs the full suite on the push.Try it: send a few requests to the preview, then open
/settings/access; the lines still show.No door: no page, API route or tool changes; the log's readers get the same lines.
🤖 Generated with Claude Code
Closes #17884