usage: a probe's chunk among the settled days no longer drops the heatmap's disk cache
heatSettledKey gave up whenever a settled chunk had no serial. A probe's
chunk (MCP and search calls) is made again for each query, so it never
has one. When a user had no tool call in the last two days, that chunk
fell among the settled days, the settled count was never kept on disk,
and every Usage refresh paired and counted every day again.
The loop below already names such a chunk by its rows (hashRows), the
same rows give the same key, and pairSerials already allows one unnamed
chunk. So the early return goes; the doc comment says what false means
now.
Ran (mote, at this head):
- TestHeatSettledKeyNamesAProbeChunk: green; red with the early return
put back ("a probe's chunk left the settled days unnamed").
- go test -count=1 ./internal/usage ok; go vet for darwin, linux and
windows ok; gofmt clean.
Not tried: timing a real Usage page with no recent tool calls.
Reported-by: gua2100 (Discord #feedback)
This commit is contained in:
@@ -99,8 +99,7 @@ func heatDiskWrite(key string, cut, since time.Time, days []Day) error {
|
||||
// heatSettledKey names what the days before cut were counted of: each
|
||||
// chunk by its rows (a session file's through sourceDigest) under the
|
||||
// same root and meta, and the counting by the call shards' version and
|
||||
// settledCountVersion. False: the chunks
|
||||
// can't be named so (a probe's chunk made again for each query).
|
||||
// settledCountVersion. False: no disk to keep the count on.
|
||||
func heatSettledKey(d heatDiskRef, cut, since time.Time, f Filter, identities map[string]sessions.CodexIdentity, settled [3][]*rowChunk, before heatSum) (string, bool) {
|
||||
if d.root == "" {
|
||||
return "", false
|
||||
@@ -126,9 +125,8 @@ func heatSettledKey(d heatDiskRef, cut, since time.Time, f Filter, identities ma
|
||||
return strings.Compare(a.Source.Path, b.Source.Path)
|
||||
})
|
||||
for _, c := range set {
|
||||
if c.serial == 0 {
|
||||
return "", false
|
||||
}
|
||||
// a chunk without a serial (a probe's, made again for each
|
||||
// query) is named by its rows below, as pairSerials allows
|
||||
b = fmt.Appendf(b[:0], "\x01%d\x00%s\x00%d\x00%d\x00%s\x00", k, c.Computer, c.Count, c.Latest.UnixNano(), c.Source.Path)
|
||||
h.Write(b)
|
||||
if c.Source.Path != "" {
|
||||
|
||||
@@ -406,3 +406,35 @@ func TestHeatSettledKeyNamesTheZone(t *testing.T) {
|
||||
t.Fatal("another zone, the same key")
|
||||
}
|
||||
}
|
||||
|
||||
// A probe's chunk (MCP and search calls) is made again for each query and
|
||||
// has no serial. When it is among the settled days the count is still kept
|
||||
// on disk, named by its rows, or every refresh counts the days again.
|
||||
func TestHeatSettledKeyNamesAProbeChunk(t *testing.T) {
|
||||
cut := time.Date(2026, 9, 28, 0, 0, 0, 0, time.UTC)
|
||||
d := heatDiskRef{root: "r", meta: "m"}
|
||||
probe := func(input int) *rowChunk {
|
||||
c := &rowChunk{}
|
||||
for i := 1; i <= 3; i++ {
|
||||
c.add(Row{Record: Record{Time: cut.Add(-time.Duration(i) * time.Hour), Agent: "claude", Model: "m", Input: i * input}}, fmt.Sprint("msg", i), int64(i), false)
|
||||
}
|
||||
return c
|
||||
}
|
||||
key := func(c *rowChunk) string {
|
||||
if c.serial != 0 {
|
||||
t.Fatalf("serial %d, want a probe's 0", c.serial)
|
||||
}
|
||||
k, ok := heatSettledKey(d, cut, time.Time{}, Filter{}, nil, [3][]*rowChunk{{c}}, heatSum{})
|
||||
if !ok {
|
||||
t.Fatal("a probe's chunk left the settled days unnamed")
|
||||
}
|
||||
return k
|
||||
}
|
||||
a, b := key(probe(10)), key(probe(10))
|
||||
if a != b {
|
||||
t.Fatalf("the same rows, two keys: %s, %s", a, b)
|
||||
}
|
||||
if key(probe(11)) == a {
|
||||
t.Fatal("other rows, the same key")
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user