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.
17 lines
5.2 KiB
JSON
17 lines
5.2 KiB
JSON
{"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."}]}}
|