Avoid double counting Pi review cache tokens · Entire
Avoid double counting Pi review cache tokens
6699ec4→main·
dipree·2w ago·2 files·+13 added/-7 removed
Sessions
1b1a62d70f07View transcript
[?
Trail Finding and Pi Review Token DeduplicationPi·GPT-5.5·1 step](/content/gh/entireio/cli/session/019f1893-b810-7992-afb4-8c4bddc4ae3c#timeline-1b1a62d70f07/index.html)
Changes
2
cmd/entire/cli/agent/pi
Mreviewer.go+7/-1
Mreviewer_test.go+6/-6
189 unmodified lines
190
191
192
193
193
194
195
196
197
198
199
200
201
202
189 unmodified lines
if usage == nil {
return total
}
total.In += usage.Input + usage.CacheRead + usage.CacheWrite
// Pi's usage shape is normalized across providers. For OpenAI-shaped
// backends, cached input is reported as a subset of input tokens; summing
// cacheRead/cacheWrite into Tokens.In would therefore double-count. The
// review event contract has only aggregate input/output fields, so report
// the provider's top-level input total and leave cache detail to transcript
// token accounting, which stores cache fields separately.
total.In += usage.Input
total.Out += usage.Output
return total
}
Mcmd/entire/cli/agent/pi/reviewer.go+7/-1
87 unmodified lines
88
89
90
91
92
91
92
93
94
95
41 unmodified lines
137
138
139
140
141
140
141
142
143
144
143
144
145
146
147
87 unmodified lines
t.Fatalf("events[3] = %#v, want AssistantText{one}", events[3])
}
tokens, ok := events[4].(reviewtypes.Tokens)
if !ok || tokens.In != 15 || tokens.Out != 4 {
t.Fatalf("events[4] = %#v, want Tokens{In:15 Out:4}", events[4])
if !ok || tokens.In != 10 || tokens.Out != 4 {
t.Fatalf("events[4] = %#v, want Tokens{In:10 Out:4}", events[4])
}
finished, ok := events[5].(reviewtypes.Finished)
if !ok || !finished.Success {
41 unmodified lines
if len(tokens) != 2 {
t.Fatalf("token events = %d, want 2: %#v", len(tokens), events)
}
if got := tokens[0]; got.In != 115 || got.Out != 50 {
t.Fatalf("first Tokens = %#v, want In=115 Out=50", got)
if got := tokens[0]; got.In != 100 || got.Out != 50 {
t.Fatalf("first Tokens = %#v, want In=100 Out=50", got)
}
if got := tokens[1]; got.In != 315 || got.Out != 80 {
t.Fatalf("final Tokens = %#v, want In=315 Out=80", got)
if got := tokens[1]; got.In != 300 || got.Out != 80 {
t.Fatalf("final Tokens = %#v, want In=300 Out=80", got)
}
}
}
Mcmd/entire/cli/agent/pi/reviewer_test.go+6/-6