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: <nil>"), and TestFeedExpiresACursorOlderThanItsTombstones at
-count=3 (2 of 3, "must be refused, not skipped over: <nil>"). 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: <nil>"), 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.
This commit is contained in:
yetone
2026-11-15 21:58:28 +08:00
parent 30de93e9e9
commit e99307fb86
2 changed files with 6 additions and 1 deletions
+3
View File
@@ -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
+3 -1
View File
@@ -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 {