Repository navigation
outbox: a Send compacts the file to the rows it still holds - #1133
Merged
Merged
Conversation
Co-Authored-By: codeaf <[email protected]>
A file that is append-only carries a line for every row the outbox ever judged, so a long-lived run reads the whole of it back on every Send and every Pending and never shrinks. A Send now rewrites the file to exactly the pending rows when it has grown mostly into retired ones, through a temporary file renamed over the original, so no row is lost and no retired row returns. Co-Authored-By: codeaf <[email protected]>
Co-Authored-By: codeaf <[email protected]>
Co-Authored-By: Claude Fable 5.1 <[email protected]>
The outbox file (
<profile>/pool/outbox.jsonl) was append-only with nothing that ever rewrote it: a line for every row an install ever judged, and later the marker that retired it. EverySendand everyPendingread the whole file back, so a long-lived install's work per judgement grew with everything it had ever judged.What changed (
internal/pool/outbox/outbox.go): aSendwhose file has grown mostly into retired rows — more lines than twice the pending rows, past a floor of 1024 lines — rewrites it to exactly the pending rows (compactLocked): a temporary file in the same directory, fsynced, renamed over the original, then the handle reopened; never truncated in place. A crash before the rename leaves the old file whole, one after it leaves the same pending rows — no row lost, no retired row back to be sent twice. It runs undermuat the start ofSend, before its first POST, so noSendof the process is between a POST and its markers; a failed rewrite is not a failedSend. The one-writer-per-profile assumption the append-only file already rested on is now stated: a second process holding the old file writes to the unlinked inode.Tests first (
outbox_test.go): a file seeded past the floor with retired rows and two pending rows compacts to exactly those two, in order, onSend; rows appended after a compaction survive a reopen. Both failed onsantos/dev.Change note:
docs/changes/unreleased/1133-the-outbox-file-is-compacted.md.Testing
On Spark over ssh, fresh clone of this head (
b805c4538, rebased on09aecd2f1):~/src/trees/check-b805c4538.log— build, vet, gofmt;go test ./internal/pool/outbox -count=1 -raceok;go test ./internal/pool/... ./cmd/codeaf -run "Pool|Outbox|Judge|Push" -count=1all ok; EXIT 0.Follow-up from #1093's list (pool client hygiene), beside #1130.
🤖 Generated with Claude Code