Commit Graph
1 Commits
Author SHA1 Message Date
yetone 4b1f3eca4a usage: a ZCode call magpie routed is not counted again as a local session's (nori_tsukiji on X)
With ZCode on the same computer as magpie, the Usage page's local session
calls came out equal to the calls magpie had routed: each was counted twice.

Cause: a ZCode request names its session without the sess_ prefix ZCode's
database gives it (zcodeBareID; GatewayKeys, Titles and the Sessions list
already knew). The Usage page pairs a gateway record with a session file's
call by session, tokens and end time (matchedBlocks), and the calls read
from ZCode's database kept sess_<id> / sess_subagent_agent_<id>, so they
never shared a session with the gateway's records and were never paired.
Leaving out calls whose providerID is "magpie" (ocGatewayProvider) only
helps when ZCode writes that id beside a reply; with any other id the call
was listed twice.

Fix: readZCodeCalls gives each call the bare session id; zcode's call parse
version is 3, so cached shards are read again. Claude Code, Codex, Pi,
OpenCode, Kimi, dsh, grok, minimax, agy and WorkBuddy name their sessions as
their requests do (raft.go's requestIDs has ZCode alone); not changed.

Run on mote: go test ./internal/usage ./internal/sessions (ok; the zcode
fork test's expected session ids are now the bare ones), gui and cli with
-run 'ZCode|Zcode|Usage|Session' (ok), go vet darwin/linux/windows (clean),
gofmt -l clean. TestZCodeCallsPairWithTheGatewaysRecords (a session, a
provider id of ZCode's own, a subagent) was red on the old code: 4 rows for
2 routed calls, the local ones Session sess_7c1f against the gateway's 7c1f.
Not tried: a real ZCode database (this computer has none, only the app's
tasks index) and the full suite.
2026-11-12 00:42:50 +08:00