diff --git a/internal/usage/request_disk.go b/internal/usage/request_disk.go index b6dc2e596..ea9ec8a2d 100644 --- a/internal/usage/request_disk.go +++ b/internal/usage/request_disk.go @@ -123,7 +123,15 @@ func diskEntry(b []byte, c *rowChunk) []byte { put(uint64(s.Size)) put(uint64(s.Modified.UnixNano())) put(uint64(c.Count)) - put(uint64(c.Latest.UnixNano())) + // a chunk without calls has no Latest: the zero time's UnixNano is + // another time, read back as a call long ago, and such a chunk was + // settled after a read where it wasn't after a build (heatSplit), so a + // new version paired its whole history on two starts, not one (#2278) + latest := int64(0) + if !c.Latest.IsZero() { + latest = c.Latest.UnixNano() + } + put(uint64(latest)) put(uint64(len(locations))) for _, loc := range locations { name, offset := time.Unix(0, 0).In(loc).Zone() @@ -180,7 +188,9 @@ func readDiskEntry(b []byte) (*rowChunk, error) { c.Source.Size = int64(take()) c.Source.Modified = time.Unix(0, int64(take())) c.Count = int(take()) - c.Latest = time.Unix(0, int64(take())).In(time.Local) + if latest := int64(take()); latest != 0 { + c.Latest = time.Unix(0, latest).In(time.Local) + } n := take() if b == nil || n > uint64(len(b)) { return nil, errDiskEntry diff --git a/internal/usage/request_disk_entry_test.go b/internal/usage/request_disk_entry_test.go index fc6d42bc1..6180ca32d 100644 --- a/internal/usage/request_disk_entry_test.go +++ b/internal/usage/request_disk_entry_test.go @@ -77,3 +77,22 @@ func TestDiskEntryAllocatesOnce(t *testing.T) { t.Errorf("reading an entry's archive allocated %v times", n) } } + +// A chunk without calls reads back without a Latest, as it was built: read +// as a call long ago, it was settled after a read and not after a build, +// and the heatmap's and effort's kept days were counted again (#2278). +func TestDiskEntryKeepsNoLatest(t *testing.T) { + for _, latest := range []time.Time{{}, time.Unix(1790000100, 5)} { + chunk := &rowChunk{ + Source: sessions.CallSource{Path: "/s/rollout.jsonl", Key: "k", Agent: "codex", Size: 1, Modified: time.Unix(1790000000, 0)}, + Latest: latest, Archive: []byte{1}, + } + got, err := readDiskEntry(diskEntry(nil, chunk)) + if err != nil { + t.Fatal(err) + } + if got.Latest.IsZero() != latest.IsZero() || !got.Latest.Equal(latest) { + t.Errorf("Latest %v read back as %v", latest, got.Latest) + } + } +}