Files
magpie/internal
forever 43214976f2 gateway: a routing history over 200 MB drops a day whole, not just a late route's file beside the day's .gz (waitingsnow) (#1110)
A route done after its day was gzipped goes to a new <day>.jsonl, and
the next prune adds it to the day's .gz (#1057, 90960edc). When it
can't, the file stays beside the .gz for a later prune: the file or the
.gz can't be read (left by magpie run as another user, say), or the .tmp
can't be written (a full disk) or renamed over the .gz (on Windows,
while something holds it open). pruneHistory dropped the oldest files,
not days, until the history fit historyBytes (200 MB), and historyFiles
lists a day's .jsonl before its .gz. When removing that small file was
enough to fit, the .gz was kept until a later prune over the size. With
a .gz that reads, the Routing view meanwhile listed the day without its
late route. A .gz that can't be read isn't listed either way.

A day now goes whole, all its files, as it does once the late file is in
the .gz and the day is one file. Where removing the late file alone
would have been enough, the .gz now goes with it, sooner than before,
also when the Routing view couldn't read the late file anyway. Days
older than historyDays, today and the oldest-first order are unchanged.
A file that can't be removed (on Windows, while a reader has it open)
stays, and its day keeps that file's routes, as before.

Verified under a temporary HOME with Go's caches pinned, every test run
with -tags nogui. TestHistoryDropsADayWhole (pinned historyClock) makes
the day's .gz unreadable for the prune, which leaves the late file
beside it, and readable again before the history is read: a .gz that
reads, beside a file left by a full disk. With upstream/main 290c60a3's
history.go it fails:
  kept [2026-09-28.jsonl.gz 2026-09-29.jsonl.gz], days [{Day:2026-09-28
  Requests:1}], routes [1]; want [2026-09-29.jsonl.gz] alone: the day
  dropped whole
With the change it passes. Broken on purpose one way at a time, the
change fails a test each time: not setting the day being dropped,
declaring it inside the loop, or setting it only while still over the
size (the message above); never removing a day's .jsonl ("kept
[2026-09-28.jsonl 2026-09-29.jsonl.gz], ... routes [2]"); dropping every
file after the first ("kept []", and TestHistoryKeepsDaysAndDropsOld
fails too).

On a copy of a real routing directory, a scratch test left a late route
beside a day's .gz (569,134 bytes, 5,481 routes) the same way, and
filled today until the history was over the size by that file's 138
bytes. Upstream kept the .gz; this drops the day. The next day keeps
its 1,459 routes either way.

gofmt -l prints nothing for internal/gateway. go vet ./..., go build
./..., GOOS=linux go build -tags nogui ./..., GOOS=windows go build
./... and GOOS=windows go vet -tags nogui ./internal/gateway/ pass. go
test -tags nogui ./...: 43 of 43 packages with tests pass. -race
-count=20 and -shuffle=on -count=5 of TestHistory and TestRouteUsage
pass.

Not run: Windows itself. The test skips where a file at mode 0 still
reads (root, Windows); CI runs it on Linux and macOS.
2026-10-13 09:47:15 +08:00
..
…
…