sessions: a fork's copies of its parent's calls are counted once (Codex, ZCode)
Sky (skyhuang1994) on Discord: on ZCode, 10-31 showed ~0.70B GLM-5.3
tokens where ZCode's own model_usage had ~0.28B. A selection side chat
opened on 11-02 from a 10-31 session holds a copy of its 860 assistant
messages, with the 10-31 times and the same 421,041,276 tokens, and made
no calls. On Codex, a week of 2026-03 read 5,136,041,178 gpt-5.4 tokens,
where the machine had spent ~0.27B.
ZCode: ZCode 3.17's CLI copies a session's messages (gce, for a side
chat, a fork and a checkpoint restored) with a new id and session, the
original's time, model and tokens, and metadata.forkOrigin
{sessionId, messageId}. zcDB.copied says a message is a copy of one still
in the database, and readZCodeCalls and parseOpenCode (for ZCode) leave
it out. A copy of a copy names the copy it came from, so of each chain
one is counted. A copy whose original is gone is counted. ZCode's own
fork notices carry a forkOrigin with no messageId, and are not copies.
Codex: a fork (/fork, spawn_agent with the parent's context) writes every
line of the parent's rollout into its own first, token_count events too,
stamped at the fork's time (codex-rs 0.117 record_initial_history,
InitialHistory::Forked). Each copied checkpoint was booked as a call on
the fork's day. The fork's session_meta has forked_from_id. The parent's
rollout is found in the same Codex home: the UUIDv7 day of its id ±1
day, then every day, then archived_sessions. Its checkpoints, {total,
last}, are read once (8 parents kept), and a fork's checkpoint found among
them only advances the running total, on Usage (calls) and Sessions
(stats) both. A parent not found leaves the fork read as before.
callParseVersions and parseVersions raise codex and zcode to 1, so their
kept parses are read again once. The version tests (call_versions,
parse_versions, cache_decode) now hold the versions at none raised: they
test the mechanism, not the current numbers.
docs/subsystems/gateway-sessions.md says all of this. Filed #5072:
OpenCode's fork copies the same way and names no original, so it is
still counted twice.
Run at this head on mote (mote-run):
- gofmt -l internal: empty
- GOOS=linux go vet -tags nogui ./... ; GOOS=windows go vet ./... : ok
- go test -count=1 -timeout 45m ./internal/sessions ./internal/usage
./internal/tune ./internal/otlp ./internal/davsync ./internal/tui : ok
- go test -run 'Session|Usage|Calls|Ledger|Stats|ZCode|Codex'
./internal/gui ./internal/cli : ok
Broken by hand:
- zcDB.copied returning false: TestZCodeCopiesCountedOnce red. msg_c1 and
msg_d1 were counted as calls, and the Sessions page's 10-31 read
{1200 300 1800} for {400 100 600}.
- the copied() check in count() off: TestCodexForkCountsOnlyItsOwnCalls
red. 4 calls on the fork, {87984 5950 268416} for {45744 3550 179584}.
Not tried:
- a real ZCode database or side chat. There is none on this machine.
The copy shape was read from ZCode 3.17.2's zcode.cjs (gce).
- a real forked Codex rollout or one from 2026-03. ~/.codex/sessions here
spans 2026-07 to 11 and has no forks. The fixtures follow codex-rs
0.117's writer. Whether Sky's 5.1B week is all fork copies is not
known; a cumulative count read as per-turn in an older format was not
found in that source.
- newer rollouts' token_usage_record copies in a fork, and a parent in
another Codex home (WSL, CODEX_HOME).
- the whole gui and gateway suites. Another session's suite was running
on mote; gui and cli ran only the tests above.
This commit is contained in:
@@ -575,7 +575,27 @@ too ("usage" and omp's "model_usage" entries, a compaction's, a branch
|
||||
summary's and a tool result's usage, on the model and provider in use);
|
||||
the provider `magpie` (or `dial`) is magpie's entry, a failed call has no
|
||||
usage, and a fork's copy of its parent's entries (written before its
|
||||
header) is the parent's. The other agents the Sessions page reads (Cline,
|
||||
header) is the parent's. A Codex fork (/fork, a spawn_agent with the
|
||||
parent's context) writes every line of its parent's rollout into its own
|
||||
first, token_count events included, stamped at the fork's time; its
|
||||
session_meta names the parent (`forked_from_id`), and a checkpoint the
|
||||
parent's rollout holds (its total and last call alike) is the parent's,
|
||||
on Usage and Sessions both (`codexRolloutOf`, `codexCheckpointsOf` in
|
||||
[`codex_fork.go`](../../internal/sessions/codex_fork.go)). The parent is
|
||||
looked for in the same Codex home, by the UUIDv7 day of its id, then
|
||||
every day, then `archived_sessions`; one not found leaves the fork read
|
||||
as before. A ZCode side chat, fork or restored checkpoint copies its
|
||||
session's messages with new ids and the originals' times and tokens,
|
||||
each naming its original in `metadata.forkOrigin.messageId`; a copy
|
||||
whose original is still in the database is not counted (`zcDB.copied`
|
||||
in [`zcode.go`](../../internal/sessions/zcode.go)), one whose original
|
||||
is gone is. Both came from Sky (skyhuang1994): a ZCode side chat put a
|
||||
10-31 session's 0.42B tokens on 10-31 again, and a week of gpt-5.4 read
|
||||
5.1B tokens. Verification: `TestCodexForkCountsOnlyItsOwnCalls`,
|
||||
`TestCodexForkWithoutItsParentCountsTheCopies`,
|
||||
`TestZCodeCopiesCountedOnce`. OpenCode's fork copies the same way with
|
||||
no pointer to the original, and is still counted twice (#5072).
|
||||
The other agents the Sessions page reads (Cline,
|
||||
Qoder, Grok, Droid, Cursor, Hermes, Alma) have no reader yet (#1607). The
|
||||
Context page reads the gateway's own traces, so it shows none of these
|
||||
calls. Verification: `TestMiniMaxCodeCalls`, `TestKimiCode*` (the
|
||||
|
||||
@@ -13,9 +13,19 @@ import (
|
||||
"unsafe"
|
||||
)
|
||||
|
||||
// unraised holds parseVersions at none raised for a test of the kept
|
||||
// file's form, whatever the agents' versions are now: a file with no
|
||||
// versions in it is then as current as its parses.
|
||||
func unraised(t *testing.T) {
|
||||
kept := parseVersions
|
||||
parseVersions = map[string]int{}
|
||||
t.Cleanup(func() { parseVersions = kept })
|
||||
}
|
||||
|
||||
// The kept file decoded on a few goroutines is what one json.Unmarshal of
|
||||
// it was, and is refused where that was.
|
||||
func TestDecodeCacheIsUnmarshal(t *testing.T) {
|
||||
unraised(t)
|
||||
unmarshal := func(b []byte, zone string) (map[string]*state, bool) {
|
||||
var c cacheFile
|
||||
if json.Unmarshal(b, &c) != nil || c.Version != cacheVersion || c.Zone != zone || c.Files == nil {
|
||||
@@ -64,6 +74,7 @@ func TestDecodeCacheIsUnmarshal(t *testing.T) {
|
||||
// once a file: 23.7k sessions a script ran with one prompt held 11 MB of
|
||||
// copies of it.
|
||||
func TestDecodeCacheSharesRepeats(t *testing.T) {
|
||||
unraised(t)
|
||||
var b strings.Builder
|
||||
fmt.Fprintf(&b, `{"version":%d,"zone":"z","files":{`, cacheVersion)
|
||||
for i := range 2000 {
|
||||
@@ -99,6 +110,7 @@ func TestDecodeCacheSharesRepeats(t *testing.T) {
|
||||
// A file of one day holds that day's models once, and a parse of it, from
|
||||
// a clone, counts a call once in each: the kept state is as it was read.
|
||||
func TestDecodeCacheSharesOneDaysModels(t *testing.T) {
|
||||
unraised(t)
|
||||
m := `{"gpt-5.5":{"input":10,"output":2,"cache_read":0,"cache_write":0}}`
|
||||
b := fmt.Sprintf(`{"version":%d,"zone":"z","files":{"/one":{"size":1,"models":%s,"days":{"2026-10-24":{"m":%s,"a":5}}},"/other":{"size":1,"models":%s,"days":{"2026-10-24":{"m":{"o3":{"input":1,"output":0,"cache_read":0,"cache_write":0}}}}},"/two":{"size":1,"models":%s,"days":{"2026-10-23":{"m":%s},"2026-10-24":{"a":1}}}}}`, cacheVersion, m, m, m, m, m)
|
||||
files, ok := decodeCache([]byte(b), "z")
|
||||
|
||||
@@ -60,7 +60,9 @@ const callCacheVersion = "calls-v15"
|
||||
//
|
||||
// cindy 1: a call through magpie's link (provider "magpie-<8 hex>") is
|
||||
// the gateway's, and left out (cindyGatewayProvider).
|
||||
var callParseVersions = map[string]int{"cindy": 1}
|
||||
// codex 1, zcode 1: a fork's copies of its parent's calls are the
|
||||
// parent's (codex_fork.go, zcDB.copied).
|
||||
var callParseVersions = map[string]int{"cindy": 1, "codex": 1, "zcode": 1}
|
||||
|
||||
// CallCacheVersion is callCacheVersion and callParseVersions, for a cache
|
||||
// of what is made of the calls (usage's requests-v1.bin and heatmap): a
|
||||
|
||||
@@ -14,6 +14,10 @@ import (
|
||||
// once, and keeps every other agent's shards.
|
||||
func TestCallParseVersionRaiseReadsThatAgentAlone(t *testing.T) {
|
||||
d := setupCalls(t)
|
||||
// from a magpie whose agents' calls are all at 0, whatever they are now
|
||||
before := callParseVersions
|
||||
callParseVersions = map[string]int{}
|
||||
t.Cleanup(func() { callParseVersions = before })
|
||||
cc := filepath.Join(d.claude, "projects", "-work-app", "sess1.jsonl")
|
||||
writeLines(t, cc, claudeMsg("m1", "claude-opus-5-5", 100, 20, 5000, 1000, 1), claudeMsg("m2", "claude-opus-5-5", 7, 8, 0, 0, 2))
|
||||
cx := filepath.Join(d.codex, "sessions", "2026", "09", "20", "rollout-2026-09-20T10-00-00-0190aaaa-1111-7222-8333-444455556666.jsonl")
|
||||
|
||||
@@ -955,6 +955,7 @@ type cxCall struct {
|
||||
ID string `json:"id"`
|
||||
SessionID string `json:"session_id"`
|
||||
ThreadID string `json:"thread_id"`
|
||||
ForkedFrom string `json:"forked_from_id"`
|
||||
Upstream string `json:"model_provider"`
|
||||
AccountID string `json:"creator_account_id"`
|
||||
UserID string `json:"creator_user_id"`
|
||||
@@ -1040,6 +1041,7 @@ func codexCallLine(st *callFile, b []byte) {
|
||||
r.Upstream, r.AccountID, r.UserID = st.str(p.Upstream), st.str(p.AccountID), st.str(p.UserID)
|
||||
r.Usage.context(r.Session, "", "")
|
||||
r.Usage.beginSnapshot(tsAt(b, false), p.ID, p.cxHistorySnapshot)
|
||||
r.Usage.forkedFrom(st.Path, p.ForkedFrom)
|
||||
case l.Type == "turn_context":
|
||||
if p.Upstream != "" {
|
||||
r.Upstream = st.str(p.Upstream)
|
||||
|
||||
@@ -74,6 +74,7 @@ func readZCodeCalls(f file) (*callFile, bool) {
|
||||
path, sid := f.path[:i], f.path[i+1:]
|
||||
var info ocInfo
|
||||
var msgs [][]byte
|
||||
copies := map[string]bool{}
|
||||
if !withOCCallDB(path, func(db *sql.DB) {
|
||||
var store ocStore = zcDB{ocDB{db}}
|
||||
if ocHasTable(db, "session_v2") {
|
||||
@@ -84,6 +85,16 @@ func readZCodeCalls(f file) (*callFile, bool) {
|
||||
}
|
||||
info, _ = store.info(sid)
|
||||
msgs = store.messages(sid)
|
||||
// a copy of a message still in the database (zcDB.copied): the
|
||||
// original's session counts its call
|
||||
if z, ok := store.(zcDB); ok {
|
||||
for _, b := range msgs {
|
||||
var m ocMessage
|
||||
if json.Unmarshal(b, &m) == nil && m.Role == "assistant" && z.copied(m) {
|
||||
copies[m.ID] = true
|
||||
}
|
||||
}
|
||||
}
|
||||
}) {
|
||||
return st, false
|
||||
}
|
||||
@@ -92,7 +103,7 @@ func readZCodeCalls(f file) (*callFile, bool) {
|
||||
}
|
||||
for _, b := range msgs {
|
||||
var m ocMessage
|
||||
if json.Unmarshal(b, &m) != nil || m.Role != "assistant" || ocGatewayProvider(m.ProviderID) {
|
||||
if json.Unmarshal(b, &m) != nil || m.Role != "assistant" || ocGatewayProvider(m.ProviderID) || copies[m.ID] {
|
||||
continue
|
||||
}
|
||||
if c, ok := ocCall(st, m, info.Directory); ok {
|
||||
|
||||
@@ -27,6 +27,7 @@ type cxLine struct {
|
||||
SessionID string `json:"session_id"`
|
||||
ThreadID string `json:"thread_id"`
|
||||
ParentThreadID string `json:"parent_thread_id"`
|
||||
ForkedFrom string `json:"forked_from_id"`
|
||||
Source json.RawMessage `json:"source"`
|
||||
TurnID string `json:"turn_id"`
|
||||
ResponseID string `json:"response_id"`
|
||||
@@ -723,6 +724,7 @@ func codexBody(s *state, b []byte, main bool) {
|
||||
codexState(s).context(session, "", "")
|
||||
codexState(s).beginSnapshot(at, p.ID, p.cxHistorySnapshot)
|
||||
if s.ID == "" {
|
||||
codexState(s).forkedFrom(s.codexPath, p.ForkedFrom)
|
||||
s.ID = p.ID
|
||||
if s.Provider = p.ModelProvider; s.Provider == "" {
|
||||
s.Provider = "openai"
|
||||
|
||||
@@ -0,0 +1,159 @@
|
||||
package sessions
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"encoding/hex"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"strings"
|
||||
"sync"
|
||||
"time"
|
||||
)
|
||||
|
||||
// A Codex fork (the CLI's /fork, the app's fork, a spawn_agent with the
|
||||
// parent's context) starts a rollout of its own and writes every item of
|
||||
// its parent's into it first, token_count events included, as they were
|
||||
// (codex-rs record_initial_history, InitialHistory::Forked). Each copied
|
||||
// line is stamped when the fork wrote it, so a copied checkpoint is the
|
||||
// parent's call again, at the fork's time, and read as one it counted the
|
||||
// parent's whole history a second time on the day of the fork (Sky,
|
||||
// skyhuang1994: a week of 5.1B gpt-5.4 tokens where the machine had spent
|
||||
// ~0.27B). The fork's own session_meta names the parent (forked_from_id),
|
||||
// and a checkpoint the parent's rollout holds, its running total and its
|
||||
// last call alike, is a copy: the parent's file counts it. A fork of a fork
|
||||
// holds its grandparent's lines through its parent's file, which holds
|
||||
// them too. When the parent's rollout can't be found or read, the fork's
|
||||
// lines are read as before.
|
||||
|
||||
// cxCheckpoint is a token_count event's two counters, as written.
|
||||
type cxCheckpoint struct{ Total, Last cxUsage }
|
||||
|
||||
// forkedFrom notes, from the first session_meta of the rollout at path,
|
||||
// the parent the rollout was forked from, and reads that parent's
|
||||
// checkpoints.
|
||||
func (s *codexUsageState) forkedFrom(path, parent string) {
|
||||
if parent == "" || path == "" {
|
||||
return
|
||||
}
|
||||
if p := codexRolloutOf(path, parent); p != "" {
|
||||
s.Copied = codexCheckpointsOf(p)
|
||||
}
|
||||
}
|
||||
|
||||
// copied says whether a checkpoint is one of the parent's, copied in.
|
||||
func (s *codexUsageState) copied(total, last *cxUsage) bool {
|
||||
if len(s.Copied) == 0 || total == nil || last == nil {
|
||||
return false
|
||||
}
|
||||
return s.Copied[cxCheckpoint{*total, *last}]
|
||||
}
|
||||
|
||||
// codexForks keeps the checkpoints of the parents last read, by path,
|
||||
// size and time: forks a spawn_agent makes are of one parent, often many
|
||||
// at a time.
|
||||
var codexForks struct {
|
||||
sync.Mutex
|
||||
kept []codexForkParent
|
||||
}
|
||||
|
||||
type codexForkParent struct {
|
||||
path string
|
||||
size int64
|
||||
mod time.Time
|
||||
marks map[cxCheckpoint]bool
|
||||
}
|
||||
|
||||
const codexForksKept = 8
|
||||
|
||||
// codexCheckpointsOf are the token_count checkpoints of the rollout at
|
||||
// path; nil when it can't be read whole.
|
||||
func codexCheckpointsOf(path string) map[cxCheckpoint]bool {
|
||||
fi, err := os.Stat(path)
|
||||
if err != nil {
|
||||
return nil
|
||||
}
|
||||
codexForks.Lock()
|
||||
for _, k := range codexForks.kept {
|
||||
if k.path == path && k.size == fi.Size() && k.mod.Equal(fi.ModTime()) {
|
||||
codexForks.Unlock()
|
||||
return k.marks
|
||||
}
|
||||
}
|
||||
codexForks.Unlock()
|
||||
marks := map[cxCheckpoint]bool{}
|
||||
err = eachLine(path, func(b []byte) {
|
||||
h := b[:min(len(b), 1024)]
|
||||
if typeAfter(h, cxType) != "event_msg" || typeAfter(h, cxPayload) != "token_count" || bytes.Contains(h, cxInfo) {
|
||||
return
|
||||
}
|
||||
total, ok := cxUsageIn(b, cxTotal)
|
||||
if !ok {
|
||||
return
|
||||
}
|
||||
if last, ok := cxUsageIn(b, cxLast); ok {
|
||||
marks[cxCheckpoint{*total, *last}] = true
|
||||
}
|
||||
})
|
||||
if err != nil {
|
||||
return nil
|
||||
}
|
||||
codexForks.Lock()
|
||||
codexForks.kept = append(codexForks.kept, codexForkParent{path, fi.Size(), fi.ModTime(), marks})
|
||||
if n := len(codexForks.kept); n > codexForksKept {
|
||||
codexForks.kept = append([]codexForkParent(nil), codexForks.kept[n-codexForksKept:]...)
|
||||
}
|
||||
codexForks.Unlock()
|
||||
return marks
|
||||
}
|
||||
|
||||
// codexRolloutOf is the rollout of thread id in the Codex folder that
|
||||
// holds the rollout at path, "" when there is none. Codex files a rollout
|
||||
// under sessions/YYYY/MM/DD, the local day it began, and a thread id is a
|
||||
// UUIDv7, which carries that time: the days around it are looked in
|
||||
// first, then every day, then archived_sessions.
|
||||
func codexRolloutOf(path, id string) string {
|
||||
home := codexHomeOf(path)
|
||||
if home == "" || strings.ContainsAny(id, `/\*?[`) {
|
||||
return ""
|
||||
}
|
||||
name := "rollout-*-" + id + "*.jsonl*"
|
||||
match := func(pattern string) string {
|
||||
found, _ := filepath.Glob(pattern)
|
||||
for _, p := range found {
|
||||
if m := rolloutName.FindStringSubmatch(filepath.Base(p)); m != nil && m[1] == id && p != path {
|
||||
return p
|
||||
}
|
||||
}
|
||||
return ""
|
||||
}
|
||||
sessions := filepath.Join(home, "sessions")
|
||||
if at, ok := uuidV7Time(id); ok {
|
||||
for _, d := range []int{0, -1, 1} {
|
||||
day := at.AddDate(0, 0, d).Local()
|
||||
if p := match(filepath.Join(sessions, day.Format("2006"), day.Format("01"), day.Format("02"), name)); p != "" {
|
||||
return p
|
||||
}
|
||||
}
|
||||
}
|
||||
if p := match(filepath.Join(sessions, "*", "*", "*", name)); p != "" {
|
||||
return p
|
||||
}
|
||||
return match(filepath.Join(home, "archived_sessions", name))
|
||||
}
|
||||
|
||||
// uuidV7Time is the time a UUIDv7 was made, its first 48 bits.
|
||||
func uuidV7Time(id string) (time.Time, bool) {
|
||||
h := strings.ReplaceAll(id, "-", "")
|
||||
if len(h) != 32 || h[12] != '7' {
|
||||
return time.Time{}, false
|
||||
}
|
||||
b, err := hex.DecodeString(h[:12])
|
||||
if err != nil {
|
||||
return time.Time{}, false
|
||||
}
|
||||
var ms int64
|
||||
for _, c := range b {
|
||||
ms = ms<<8 | int64(c)
|
||||
}
|
||||
return time.UnixMilli(ms), true
|
||||
}
|
||||
@@ -0,0 +1,91 @@
|
||||
package sessions
|
||||
|
||||
import (
|
||||
"os"
|
||||
"path/filepath"
|
||||
"strings"
|
||||
"testing"
|
||||
"time"
|
||||
)
|
||||
|
||||
// A fork's rollout starts with every line of its parent's, token_count
|
||||
// events included, stamped when the fork wrote them (codex-rs 0.117's
|
||||
// InitialHistory::Forked). The fixtures are that shape: a gpt-5.4 parent of
|
||||
// 2026-03-23 with three calls (and one more after the fork), and a
|
||||
// spawn_agent fork of it on 03-24 that made one call of its own. The copies
|
||||
// are the parent's calls, which the parent's rollout counts; read as the
|
||||
// fork's, they put the parent's whole history on 03-24 again (Sky).
|
||||
func TestCodexForkCountsOnlyItsOwnCalls(t *testing.T) {
|
||||
d := setupCalls(t)
|
||||
const parent, fork = "019d186b-a100-7aaa-8bbb-cccdddeeefff", "019d1f2d-f9c0-7111-8222-333444555666"
|
||||
place := func(fixture, day, stamp, id string) {
|
||||
b, err := os.ReadFile(filepath.Join("testdata", fixture))
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
writeLines(t, filepath.Join(d.codex, "sessions", "2026", "03", day, "rollout-2026-03-"+day+"T"+stamp+"-"+id+".jsonl"), strings.TrimSpace(string(b)))
|
||||
}
|
||||
place("codex-fork-parent.jsonl", "23", "10-00-00", parent)
|
||||
place("codex-fork-child.jsonl", "24", "17-30-00", fork)
|
||||
|
||||
call := func(in, cached, out, reasoning int) Tokens {
|
||||
return Tokens{Input: in - cached, CacheRead: cached, Output: out}
|
||||
}
|
||||
own := map[string][]Tokens{
|
||||
parent: {call(41200, 3072, 812, 256), call(43680, 41088, 688, 144), call(46192, 44672, 900, 112), call(46928, 46080, 600, 88)},
|
||||
fork: {call(47328, 44672, 550, 48)},
|
||||
}
|
||||
var want Tokens
|
||||
for _, ts := range own {
|
||||
for _, v := range ts {
|
||||
want.add(v)
|
||||
}
|
||||
}
|
||||
got := map[string]int{}
|
||||
var total Tokens
|
||||
var onFork Tokens
|
||||
for _, c := range Calls(time.Time{}) {
|
||||
got[c.File]++
|
||||
total.add(c.Tokens)
|
||||
if strings.Contains(c.File, fork) {
|
||||
onFork.add(c.Tokens)
|
||||
}
|
||||
}
|
||||
if total != want {
|
||||
t.Fatalf("calls booked %+v, want %+v (calls per file %v)", total, want, got)
|
||||
}
|
||||
if onFork != own[fork][0] {
|
||||
t.Fatalf("the fork's calls are %+v, want its own one call %+v", onFork, own[fork][0])
|
||||
}
|
||||
var listed Tokens
|
||||
for _, s := range List(0) {
|
||||
listed.add(s.Tokens)
|
||||
}
|
||||
if listed != want {
|
||||
t.Fatalf("sessions booked %+v, want %+v", listed, want)
|
||||
}
|
||||
}
|
||||
|
||||
// With the parent's rollout gone, its calls are counted once, in the fork:
|
||||
// they were made, and nothing else counts them now.
|
||||
func TestCodexForkWithoutItsParentCountsTheCopies(t *testing.T) {
|
||||
d := setupCalls(t)
|
||||
b, err := os.ReadFile("testdata/codex-fork-child.jsonl")
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
writeLines(t, filepath.Join(d.codex, "sessions", "2026", "03", "24", "rollout-2026-03-24T17-30-00-019d1f2d-f9c0-7111-8222-333444555666.jsonl"), strings.TrimSpace(string(b)))
|
||||
if n := len(Calls(time.Time{})); n != 4 {
|
||||
t.Fatalf("%d calls, want the 3 copied and the fork's own", n)
|
||||
}
|
||||
}
|
||||
|
||||
func TestUUIDV7Time(t *testing.T) {
|
||||
at, ok := uuidV7Time("019d186b-a100-7aaa-8bbb-cccdddeeefff")
|
||||
if !ok || !at.Equal(time.Date(2026, 3, 23, 2, 0, 0, 0, time.UTC)) {
|
||||
t.Fatalf("%v %v", at, ok)
|
||||
}
|
||||
if _, ok := uuidV7Time("4f2c1a7e-0000-4000-8000-000000000000"); ok {
|
||||
t.Fatal("a v4 id has no time")
|
||||
}
|
||||
}
|
||||
@@ -31,6 +31,9 @@ type codexUsageState struct {
|
||||
SnapshotThread string
|
||||
SnapshotTotal *cxUsage
|
||||
SnapshotOffset *cxUsage
|
||||
// Copied are the checkpoints of the rollout this one was forked from,
|
||||
// which it holds copies of (codex_fork.go); never written to after.
|
||||
Copied map[cxCheckpoint]bool
|
||||
}
|
||||
|
||||
// A paginated subagent starts with a restored compaction and a zero-last
|
||||
@@ -498,6 +501,11 @@ func (s *codexUsageState) count(at time.Time, model string, total, last *cxUsage
|
||||
if total == nil || !total.valid() || total.Known&3 != 3 || at.IsZero() {
|
||||
return nil
|
||||
}
|
||||
if s.copied(total, last) {
|
||||
// the parent's call, which its own rollout counts
|
||||
s.advance(at, total)
|
||||
return nil
|
||||
}
|
||||
s.alignSnapshot(at, total, last)
|
||||
if last != nil && last.Known&3 != 3 {
|
||||
s.Conflicts++
|
||||
|
||||
@@ -117,6 +117,14 @@ type ocMessage struct {
|
||||
// OpenCode 2: the tools a reply called and the skills a message
|
||||
// brought in, as ocV2DB.messages reads them
|
||||
Calls []ocUse `json:"calls,omitempty"`
|
||||
// ZCode: where a message copied into another session came from
|
||||
// (zcDB.copied)
|
||||
Metadata *struct {
|
||||
ForkOrigin *struct {
|
||||
SessionID string `json:"sessionId"`
|
||||
MessageID string `json:"messageId"`
|
||||
} `json:"forkOrigin"`
|
||||
} `json:"metadata,omitempty"`
|
||||
}
|
||||
|
||||
// ocUse is a tool called, or a skill brought in with no tool (Name "").
|
||||
@@ -587,6 +595,9 @@ func parseOpenCode(f file) *state {
|
||||
if s.Cwd == "" && m.Path != nil {
|
||||
s.Cwd = m.Path.Cwd
|
||||
}
|
||||
if z, ok := f.m().oc.(zcDB); ok && z.copied(m) {
|
||||
continue // the original's session counts it
|
||||
}
|
||||
if t := m.Tokens; t != nil && m.ModelID != "" {
|
||||
u := Tokens{Input: t.Input, Output: t.Output + t.Reasoning, CacheRead: t.Cache.Read, CacheWrite: t.Cache.Write}
|
||||
if f.agent == "zcode" {
|
||||
|
||||
@@ -15,7 +15,7 @@ import (
|
||||
// (#2278: each raise of cacheVersion read a whole history again).
|
||||
func TestParseVersionRaiseReadsThatAgentAlone(t *testing.T) {
|
||||
setup(t)
|
||||
defer func(v map[string]int) { parseVersions = v }(parseVersions)
|
||||
unraised(t)
|
||||
var mu sync.Mutex
|
||||
read := map[string]int{}
|
||||
scanHook = func(p string, off int64) {
|
||||
|
||||
@@ -192,6 +192,7 @@ type state struct {
|
||||
// the agent whose file it is, for its parseVersions
|
||||
Agent string `json:"agent,omitempty"`
|
||||
Codex *codexUsageState `json:"-"`
|
||||
codexPath string // the rollout read, for its fork's parent
|
||||
Claude *claudeUsageState `json:"claude,omitempty"`
|
||||
DBRevision string `json:"db_revision,omitempty"`
|
||||
Head string `json:"head,omitempty"`
|
||||
@@ -1116,7 +1117,10 @@ const cacheVersion = 29
|
||||
// parseVersions is cacheVersion for one agent's parses, 0 when not listed:
|
||||
// raised, the parses of that agent's files kept by an older magpie are read
|
||||
// again, and the rest stand.
|
||||
var parseVersions = map[string]int{}
|
||||
//
|
||||
// codex 1, zcode 1: a fork's copies of its parent's usage are the
|
||||
// parent's (codex_fork.go, zcDB.copied).
|
||||
var parseVersions = map[string]int{"codex": 1, "zcode": 1}
|
||||
|
||||
type cacheFile struct {
|
||||
Version int `json:"version"`
|
||||
@@ -1966,6 +1970,7 @@ func parseWith(f file, old *state, calls *callsRide) *state {
|
||||
s.ContentHash = prefixHash(f.path, f.size)
|
||||
var head func([]byte) bool
|
||||
if f.agent == "codex" {
|
||||
s.codexPath = f.path
|
||||
head = func(b []byte) bool { return codexHead(s, b, f.main) }
|
||||
}
|
||||
line := func(b []byte, _, _ int64) bool {
|
||||
|
||||
@@ -0,0 +1,16 @@
|
||||
{"timestamp":"2026-03-24T09:30:00.500Z","type":"session_meta","payload":{"id":"019d1f2d-f9c0-7111-8222-333444555666","forked_from_id":"019d186b-a100-7aaa-8bbb-cccdddeeefff","timestamp":"2026-03-24T09:30:00.500Z","cwd":"/Users/sky/proj","originator":"codex_cli_rs","cli_version":"0.117.0","source":{"subagent":{"thread_spawn":{"parent_thread_id":"019d186b-a100-7aaa-8bbb-cccdddeeefff","depth":1}}},"model_provider":"openai","base_instructions":{"text":"You are Codex."}}}
|
||||
{"timestamp":"2026-03-24T09:30:00.512Z","type":"session_meta","payload":{"id":"019d186b-a100-7aaa-8bbb-cccdddeeefff","timestamp":"2026-03-23T02:00:00.120Z","cwd":"/Users/sky/proj","originator":"codex_cli_rs","cli_version":"0.117.0","source":"cli","model_provider":"openai","base_instructions":{"text":"You are Codex."}}}
|
||||
{"timestamp":"2026-03-24T09:30:00.512Z","type":"turn_context","payload":{"turn_id":"t1","cwd":"/Users/sky/proj","approval_policy":"on-request","sandbox_policy":{"type":"workspace-write"},"model":"gpt-5.4","effort":"high","summary":"auto"}}
|
||||
{"timestamp":"2026-03-24T09:30:00.512Z","type":"response_item","payload":{"type":"message","role":"user","content":[{"type":"input_text","text":"review the parser"}]}}
|
||||
{"timestamp":"2026-03-24T09:30:00.512Z","type":"event_msg","payload":{"type":"token_count","info":{"total_token_usage":{"input_tokens":41200,"cached_input_tokens":3072,"output_tokens":812,"reasoning_output_tokens":256,"total_tokens":42012},"last_token_usage":{"input_tokens":41200,"cached_input_tokens":3072,"output_tokens":812,"reasoning_output_tokens":256,"total_tokens":42012},"model_context_window":258400},"rate_limits":{"primary":{"used_percent":5.0,"window_minutes":300,"resets_in_seconds":1200},"secondary":{"used_percent":42.0,"window_minutes":10080,"resets_in_seconds":400000},"credits":null,"plan_type":"pro"}}}
|
||||
{"timestamp":"2026-03-24T09:30:00.512Z","type":"response_item","payload":{"type":"message","role":"assistant","content":[{"type":"output_text","text":"Looking."}]}}
|
||||
{"timestamp":"2026-03-24T09:30:00.512Z","type":"event_msg","payload":{"type":"token_count","info":{"total_token_usage":{"input_tokens":84880,"cached_input_tokens":44160,"output_tokens":1500,"reasoning_output_tokens":400,"total_tokens":86380},"last_token_usage":{"input_tokens":43680,"cached_input_tokens":41088,"output_tokens":688,"reasoning_output_tokens":144,"total_tokens":44368},"model_context_window":258400},"rate_limits":{"primary":{"used_percent":5.0,"window_minutes":300,"resets_in_seconds":1200},"secondary":{"used_percent":42.0,"window_minutes":10080,"resets_in_seconds":400000},"credits":null,"plan_type":"pro"}}}
|
||||
{"timestamp":"2026-03-24T09:30:00.512Z","type":"turn_context","payload":{"turn_id":"t2","cwd":"/Users/sky/proj","approval_policy":"on-request","sandbox_policy":{"type":"workspace-write"},"model":"gpt-5.4","effort":"high","summary":"auto"}}
|
||||
{"timestamp":"2026-03-24T09:30:00.512Z","type":"response_item","payload":{"type":"message","role":"user","content":[{"type":"input_text","text":"now fix it"}]}}
|
||||
{"timestamp":"2026-03-24T09:30:00.512Z","type":"event_msg","payload":{"type":"token_count","info":{"total_token_usage":{"input_tokens":131072,"cached_input_tokens":88832,"output_tokens":2400,"reasoning_output_tokens":512,"total_tokens":133472},"last_token_usage":{"input_tokens":46192,"cached_input_tokens":44672,"output_tokens":900,"reasoning_output_tokens":112,"total_tokens":47092},"model_context_window":258400},"rate_limits":{"primary":{"used_percent":5.0,"window_minutes":300,"resets_in_seconds":1200},"secondary":{"used_percent":42.0,"window_minutes":10080,"resets_in_seconds":400000},"credits":null,"plan_type":"pro"}}}
|
||||
{"timestamp":"2026-03-24T09:30:00.512Z","type":"response_item","payload":{"type":"message","role":"assistant","content":[{"type":"output_text","text":"Fixed."}]}}
|
||||
{"timestamp":"2026-03-24T09:30:00.512Z","type":"response_item","payload":{"type":"function_call_output","call_id":"call_fork1","output":"You are the newly spawned agent. The prior conversation history was forked from your parent agent. Treat the next user message as your new task, and use the forked history only as background context."}}
|
||||
{"timestamp":"2026-03-24T09:30:01.000Z","type":"turn_context","payload":{"turn_id":"t4","cwd":"/Users/sky/proj","approval_policy":"on-request","sandbox_policy":{"type":"workspace-write"},"model":"gpt-5.4","effort":"high","summary":"auto"}}
|
||||
{"timestamp":"2026-03-24T09:30:01.010Z","type":"response_item","payload":{"type":"message","role":"user","content":[{"type":"input_text","text":"check the docs"}]}}
|
||||
{"timestamp":"2026-03-24T09:30:12.000Z","type":"event_msg","payload":{"type":"token_count","info":{"total_token_usage":{"input_tokens":178400,"cached_input_tokens":133504,"output_tokens":2950,"reasoning_output_tokens":560,"total_tokens":181350},"last_token_usage":{"input_tokens":47328,"cached_input_tokens":44672,"output_tokens":550,"reasoning_output_tokens":48,"total_tokens":47878},"model_context_window":258400},"rate_limits":{"primary":{"used_percent":5.0,"window_minutes":300,"resets_in_seconds":1200},"secondary":{"used_percent":42.0,"window_minutes":10080,"resets_in_seconds":400000},"credits":null,"plan_type":"pro"}}}
|
||||
{"timestamp":"2026-03-24T09:30:12.100Z","type":"response_item","payload":{"type":"message","role":"assistant","content":[{"type":"output_text","text":"Docs ok."}]}}
|
||||
@@ -0,0 +1,13 @@
|
||||
{"timestamp":"2026-03-23T02:00:00.120Z","type":"session_meta","payload":{"id":"019d186b-a100-7aaa-8bbb-cccdddeeefff","timestamp":"2026-03-23T02:00:00.120Z","cwd":"/Users/sky/proj","originator":"codex_cli_rs","cli_version":"0.117.0","source":"cli","model_provider":"openai","base_instructions":{"text":"You are Codex."}}}
|
||||
{"timestamp":"2026-03-23T02:00:05.000Z","type":"turn_context","payload":{"turn_id":"t1","cwd":"/Users/sky/proj","approval_policy":"on-request","sandbox_policy":{"type":"workspace-write"},"model":"gpt-5.4","effort":"high","summary":"auto"}}
|
||||
{"timestamp":"2026-03-23T02:00:05.010Z","type":"response_item","payload":{"type":"message","role":"user","content":[{"type":"input_text","text":"review the parser"}]}}
|
||||
{"timestamp":"2026-03-23T02:00:20.000Z","type":"event_msg","payload":{"type":"token_count","info":{"total_token_usage":{"input_tokens":41200,"cached_input_tokens":3072,"output_tokens":812,"reasoning_output_tokens":256,"total_tokens":42012},"last_token_usage":{"input_tokens":41200,"cached_input_tokens":3072,"output_tokens":812,"reasoning_output_tokens":256,"total_tokens":42012},"model_context_window":258400},"rate_limits":{"primary":{"used_percent":5.0,"window_minutes":300,"resets_in_seconds":1200},"secondary":{"used_percent":42.0,"window_minutes":10080,"resets_in_seconds":400000},"credits":null,"plan_type":"pro"}}}
|
||||
{"timestamp":"2026-03-23T02:00:20.100Z","type":"response_item","payload":{"type":"message","role":"assistant","content":[{"type":"output_text","text":"Looking."}]}}
|
||||
{"timestamp":"2026-03-23T02:00:41.000Z","type":"event_msg","payload":{"type":"token_count","info":{"total_token_usage":{"input_tokens":84880,"cached_input_tokens":44160,"output_tokens":1500,"reasoning_output_tokens":400,"total_tokens":86380},"last_token_usage":{"input_tokens":43680,"cached_input_tokens":41088,"output_tokens":688,"reasoning_output_tokens":144,"total_tokens":44368},"model_context_window":258400},"rate_limits":{"primary":{"used_percent":5.0,"window_minutes":300,"resets_in_seconds":1200},"secondary":{"used_percent":42.0,"window_minutes":10080,"resets_in_seconds":400000},"credits":null,"plan_type":"pro"}}}
|
||||
{"timestamp":"2026-03-23T02:05:00.000Z","type":"turn_context","payload":{"turn_id":"t2","cwd":"/Users/sky/proj","approval_policy":"on-request","sandbox_policy":{"type":"workspace-write"},"model":"gpt-5.4","effort":"high","summary":"auto"}}
|
||||
{"timestamp":"2026-03-23T02:05:00.010Z","type":"response_item","payload":{"type":"message","role":"user","content":[{"type":"input_text","text":"now fix it"}]}}
|
||||
{"timestamp":"2026-03-23T02:05:30.000Z","type":"event_msg","payload":{"type":"token_count","info":{"total_token_usage":{"input_tokens":131072,"cached_input_tokens":88832,"output_tokens":2400,"reasoning_output_tokens":512,"total_tokens":133472},"last_token_usage":{"input_tokens":46192,"cached_input_tokens":44672,"output_tokens":900,"reasoning_output_tokens":112,"total_tokens":47092},"model_context_window":258400},"rate_limits":{"primary":{"used_percent":5.0,"window_minutes":300,"resets_in_seconds":1200},"secondary":{"used_percent":42.0,"window_minutes":10080,"resets_in_seconds":400000},"credits":null,"plan_type":"pro"}}}
|
||||
{"timestamp":"2026-03-23T02:05:30.100Z","type":"response_item","payload":{"type":"message","role":"assistant","content":[{"type":"output_text","text":"Fixed."}]}}
|
||||
{"timestamp":"2026-03-24T10:00:00.000Z","type":"turn_context","payload":{"turn_id":"t3","cwd":"/Users/sky/proj","approval_policy":"on-request","sandbox_policy":{"type":"workspace-write"},"model":"gpt-5.4","effort":"high","summary":"auto"}}
|
||||
{"timestamp":"2026-03-24T10:00:00.010Z","type":"response_item","payload":{"type":"message","role":"user","content":[{"type":"input_text","text":"and the tests"}]}}
|
||||
{"timestamp":"2026-03-24T10:00:20.000Z","type":"event_msg","payload":{"type":"token_count","info":{"total_token_usage":{"input_tokens":178000,"cached_input_tokens":134912,"output_tokens":3000,"reasoning_output_tokens":600,"total_tokens":181000},"last_token_usage":{"input_tokens":46928,"cached_input_tokens":46080,"output_tokens":600,"reasoning_output_tokens":88,"total_tokens":47528},"model_context_window":258400},"rate_limits":{"primary":{"used_percent":5.0,"window_minutes":300,"resets_in_seconds":1200},"secondary":{"used_percent":42.0,"window_minutes":10080,"resets_in_seconds":400000},"credits":null,"plan_type":"pro"}}}
|
||||
@@ -51,3 +51,29 @@ func (s zcDB) info(sid string) (ocInfo, bool) {
|
||||
}
|
||||
return i, err == nil
|
||||
}
|
||||
|
||||
// copied says whether a message is a copy of one still in the database.
|
||||
// ZCode copies a session's messages into another for a side chat on a
|
||||
// selection, a fork and a checkpoint restored (ZCode 3.17's CLI): each
|
||||
// copy gets an id and session of its own and keeps the original's time,
|
||||
// model and tokens, and its metadata.forkOrigin names the message it was
|
||||
// copied from, {sessionId, messageId}. The copy made no call, so its
|
||||
// tokens are the original's, and counting both counted the session again
|
||||
// on the day it ran (Sky, skyhuang1994: a side chat opened on 11-02 from a
|
||||
// session of 10-31 put 0.42B more GLM-5.3 tokens on 10-31, where ZCode's
|
||||
// own model_usage has none for it). A copy of a copy names the copy it
|
||||
// was made from, so one copy is counted only when what it came from is
|
||||
// gone: the session deleted, or never in this database. ZCode's own
|
||||
// notices of a fork carry a forkOrigin of another shape, with no
|
||||
// messageId, and are no copies.
|
||||
func (s zcDB) copied(m ocMessage) bool {
|
||||
if m.Metadata == nil || m.Metadata.ForkOrigin == nil {
|
||||
return false
|
||||
}
|
||||
id := m.Metadata.ForkOrigin.MessageID
|
||||
if id == "" || id == m.ID {
|
||||
return false
|
||||
}
|
||||
var n int
|
||||
return s.db.QueryRow(`SELECT COUNT(*) FROM message WHERE id = ?`, id).Scan(&n) == nil && n > 0
|
||||
}
|
||||
|
||||
@@ -0,0 +1,103 @@
|
||||
package sessions
|
||||
|
||||
import (
|
||||
"database/sql"
|
||||
"fmt"
|
||||
"path/filepath"
|
||||
"testing"
|
||||
"time"
|
||||
)
|
||||
|
||||
// zcForkDB adds to the ZCode database setupAgents made a session on
|
||||
// 2026-10-31, a selection side chat opened from it on 11-02, a side chat
|
||||
// opened from that one, and a fork whose parent is gone, each message as
|
||||
// ZCode 3.17's CLI copies it (gce): a new id and session, the original's
|
||||
// time, model and tokens, and metadata.forkOrigin {sessionId, messageId}.
|
||||
func zcForkDB(t *testing.T, home string) {
|
||||
t.Helper()
|
||||
db, err := sql.Open("sqlite", filepath.Join(home, ".zcode", "cli", "db", "db.sqlite"))
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
t.Cleanup(func() { db.Close() })
|
||||
day := func(d, h int) int64 { return time.Date(2026, 10, d, h, 0, 0, 0, time.UTC).UnixMilli() }
|
||||
for _, s := range []struct {
|
||||
id, title string
|
||||
at int64
|
||||
}{
|
||||
{"sess_main", "Port the parser", day(31, 0)},
|
||||
{"sess_side", "Selection side chat", day(33, 9)}, // 11-02
|
||||
{"sess_side2", "Selection side chat", day(33, 10)},
|
||||
{"sess_orphan", "Fork", day(30, 0)},
|
||||
} {
|
||||
if _, err := db.Exec("INSERT INTO session (id, project_id, parent_id, slug, directory, title, title_source, version, time_created, time_updated) VALUES (?, 'p', NULL, 's', '/work/zcf', ?, 'ai', '3.17.2', ?, ?)",
|
||||
s.id, s.title, s.at, s.at); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
}
|
||||
reply := func(id, parent string, created int64, in, out, read int, meta string) string {
|
||||
return fmt.Sprintf(`{"id":%q,"role":"assistant","parentID":%q,"modelId":"glm-5.3","providerID":"zai","tokens":{"total":%d,"input":%d,"output":%d,"reasoning":0,"cache":{"read":%d,"write":0}},"time":{"created":%d,"completed":%d}%s}`,
|
||||
id, parent, in+out, in, out, read, created, created+30000, meta)
|
||||
}
|
||||
origin := func(sid, mid string) string {
|
||||
return fmt.Sprintf(`,"metadata":{"forkOrigin":{"sessionId":%q,"messageId":%q}}`, sid, mid)
|
||||
}
|
||||
m1 := day(31, 1)
|
||||
for _, m := range []struct {
|
||||
sid, id string
|
||||
at int64
|
||||
data string
|
||||
}{
|
||||
{"sess_main", "msg_m0", m1 - 1000, `{"id":"msg_m0","role":"user","time":{"created":` + fmt.Sprint(m1-1000) + `},"semantics":{"origin":"real_user"}}`},
|
||||
{"sess_main", "msg_m1", m1, reply("msg_m1", "msg_m0", m1, 1000, 100, 600, "")},
|
||||
// the side chat: the main session copied in, then its own reply
|
||||
{"sess_side", "msg_c0", m1 - 1000, `{"id":"msg_c0","role":"user","time":{"created":` + fmt.Sprint(m1-1000) + `},"semantics":{"origin":"real_user"}` + origin("sess_main", "msg_m0") + `}`},
|
||||
{"sess_side", "msg_c1", m1, reply("msg_c1", "msg_c0", m1, 1000, 100, 600, origin("sess_main", "msg_m1"))},
|
||||
{"sess_side", "msg_cn", day(33, 9), `{"id":"msg_cn","role":"assistant","time":{"created":` + fmt.Sprint(day(33, 9)) + `},"metadata":{"forkOrigin":{"parentSessionId":"sess_main","targetMessageId":"msg_m1"}}}`},
|
||||
{"sess_side", "msg_c2", day(33, 9) + 5000, reply("msg_c2", "msg_c0", day(33, 9)+5000, 20, 2, 0, "")},
|
||||
// a side chat of the side chat: a copy of a copy
|
||||
{"sess_side2", "msg_d1", m1, reply("msg_d1", "", m1, 1000, 100, 600, origin("sess_side", "msg_c1"))},
|
||||
// a fork whose parent session was deleted: its copy is all there is
|
||||
{"sess_orphan", "msg_o1", day(30, 1), reply("msg_o1", "", day(30, 1), 300, 30, 0, origin("sess_gone", "msg_gone"))},
|
||||
} {
|
||||
ocInsert(t, db, m.sid, m.id, m.at, m.at+30000, m.data)
|
||||
}
|
||||
}
|
||||
|
||||
// A message ZCode copied into a side chat, a fork or a copy of one made no
|
||||
// call: the session it was copied from counts it, once (Sky, skyhuang1994:
|
||||
// a side chat opened on 11-02 put a 10-31 session's 0.42B tokens on 10-31
|
||||
// a second time).
|
||||
func TestZCodeCopiesCountedOnce(t *testing.T) {
|
||||
inZone(t, 0)
|
||||
zcForkDB(t, setupAgents(t))
|
||||
cs := zcodeCalls(t)
|
||||
for _, id := range []string{"msg_c1", "msg_d1"} {
|
||||
if c, ok := cs[id]; ok {
|
||||
t.Errorf("the copy %s was counted as a call: %+v", id, c)
|
||||
}
|
||||
}
|
||||
if c := cs["msg_m1"]; c.Session != "sess_main" || c.Tokens != (Tokens{400, 100, 600, 0, 0}) {
|
||||
t.Errorf("the original: %+v", c)
|
||||
}
|
||||
if c := cs["msg_c2"]; c.Session != "sess_side" || c.Tokens != (Tokens{20, 2, 0, 0, 0}) {
|
||||
t.Errorf("the side chat's own reply: %+v", c)
|
||||
}
|
||||
if c := cs["msg_o1"]; c.Session != "sess_orphan" || c.Tokens != (Tokens{300, 30, 0, 0, 0}) {
|
||||
t.Errorf("a copy whose original is gone: %+v", c)
|
||||
}
|
||||
|
||||
s := statsAt(0, time.Date(2026, 11, 3, 12, 0, 0, 0, time.UTC))
|
||||
for _, d := range []struct {
|
||||
date string
|
||||
want Tokens
|
||||
}{
|
||||
{"2026-10-31", Tokens{400, 100, 600, 0, 0}},
|
||||
{"2026-11-02", Tokens{20, 2, 0, 0, 0}},
|
||||
{"2026-10-30", Tokens{300, 30, 0, 0, 0}},
|
||||
} {
|
||||
if got, _ := usageOn(s, d.date, "/work/zcf"); got != d.want {
|
||||
t.Errorf("the Sessions page's %s: %+v, want %+v", d.date, got, d.want)
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user