Skip to content

outbox: a Send compacts the file to the rows it still holds - #1133

Merged
santoshkumarradha merged 4 commits into
santos/devfrom
fix/outbox-file-compacted
Sep 18, 2026
Merged

santoshkumarradha merged 4 commits into
santos/devfrom
fix/outbox-file-compacted

Conversation

@santoshkumarradha

@santoshkumarradha santoshkumarradha commented Sep 18, 2026 •

Copy link
Copy Markdown
Member

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. Every Send and every Pending read 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): a Send whose 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 under mu at the start of Send, before its first POST, so no Send of the process is between a POST and its markers; a failed rewrite is not a failed Send. 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, on Send; rows appended after a compaction survive a reopen. Both failed on santos/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 on 09aecd2f1): ~/src/trees/check-b805c4538.log — build, vet, gofmt; go test ./internal/pool/outbox -count=1 -race ok; go test ./internal/pool/... ./cmd/codeaf -run "Pool|Outbox|Judge|Push" -count=1 all ok; EXIT 0.

Follow-up from #1093's list (pool client hygiene), beside #1130.

🤖 Generated with Claude Code

santoshkumarradha and others added 4 commits September 17, 2026 22:26
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]>
@santoshkumarradha
santoshkumarradha merged commit ae7c05d into santos/dev Sep 18, 2026
1 check passed