From e99307fb860c18dc0dba4f9ea46489d13a199b61 Mon Sep 17 00:00:00 2001 From: yetone Date: Sun, 15 Nov 2026 21:58:28 +0800 Subject: [PATCH] usage: a file read anew forgets when the last one was written or pruned (#6760) TestWholeKeptAcrossReset was red on main at -count=5 (4 of 5, "after a restart: "), and TestFeedExpiresACursorOlderThanItsTombstones at -count=3 (2 of 3, "must be refused, not skipped over: "). Both had the same cause. A package-level "last done at" outlived the file it was about: - carryLoad reset the window-holds map and dirty bit for a new path, but not wroteAt. carrySave then waited 30s from the last file's write, or from a held clock later than this one, and wrote nothing. - feedLoad reset everything but pruned, so a journal read anew wasn't pruned for an hour after another one was. In the app it matters when the config dir changes (MAGPIE_CONFIG_DIR, a sandbox HOME) without a restart, or when the clock moves back. Each reset is now done where its sibling fields already were. Run on mote at origin/main 30de93e9e plus this commit: - red before, on the unchanged files: TestWholeKeptAcrossReset -count=5 FAIL ("after a restart: "), and TestFeedExpiresACursorOlderThanItsTombstones -count=3 FAIL; - after: go test -count=3 ./internal/usage/ ok (126s); - go vet ./internal/usage/, plus GOOS=linux -tags nogui and GOOS=windows: ok. gofmt clean. Not run: the full suite. Both mote and mica were busy with other sessions' full suites under suite.lock (mica at load 63). The change is two field resets in internal/usage, and nothing outside the package reads carry or feed. --- internal/usage/feed.go | 3 +++ internal/usage/window_holds_carry.go | 4 +++- 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/internal/usage/feed.go b/internal/usage/feed.go index c726d6271..a7f402088 100644 --- a/internal/usage/feed.go +++ b/internal/usage/feed.go @@ -482,6 +482,9 @@ func feedLoad() { feed.entries = map[string]*feedEntry{} feed.seq, feed.floor, feed.lines, feed.memo = 0, 0, 0, nil feed.failure = nil + // a journal read anew hasn't been pruned: when the last one was is + // another journal's, and a clock behind it would hold this one's prune off + feed.pruned = time.Time{} fresh := func() { feed.entries = map[string]*feedEntry{} feed.seq, feed.floor, feed.lines = 0, 0, 0 diff --git a/internal/usage/window_holds_carry.go b/internal/usage/window_holds_carry.go index 8d4ecde3b..d6751dc51 100644 --- a/internal/usage/window_holds_carry.go +++ b/internal/usage/window_holds_carry.go @@ -38,7 +38,9 @@ func carryPath() string { return filepath.Join(filepath.Dir(provider.Path()), "w // (they are only a fallback), and is written over when the next is told. func carryLoad() map[string]carried { if p := carryPath(); carry.m == nil || carry.path != p { - carry.path, carry.m, carry.dirty = p, map[string]carried{}, false + // a new file has never been written: what was last written went to + // the old one, so the next save mustn't wait on it + carry.path, carry.m, carry.dirty, carry.wroteAt = p, map[string]carried{}, false, time.Time{} if b, err := os.ReadFile(p); err == nil { var m map[string]carried if json.Unmarshal(b, &m) == nil && m != nil {