feat(codex): retain native session usage snapshots for chat

Verify typed ThreadTokenUsage/TokenUsageBreakdown/Thread/Turn against openai/codex@6fb1c3903d. Use native totalTokens and latest-call context tokens without re-adding cached/reasoning subsets. Replay bounded per-connection snapshots and clear on room/source release.

Cost stays unavailable: no subscription USD usage is reported by this notification. Throughput stays unavailable even with native Turn.durationMs because neither last-call nor cumulative-session output is a compatible turn-specific numerator. Thread readback exposes no token usage; no extra reads, resume, or live provider calls added.

Checks: go test -race ./internal/codex; go vet ./internal/codex; go test ./internal/server ./internal/protocol; git diff --check.
This commit is contained in:
2026-10-21 00:06:11 +01:00
parent 3e62ed7979
commit 83b60990d2
4 changed files with 315 additions and 0 deletions
+26
View File
@@ -0,0 +1,26 @@
{
"method": "thread/tokenUsage/updated",
"params": {
"threadId": "thread",
"turnId": "turn_new",
"tokenUsage": {
"total": {
"totalTokens": 12000,
"inputTokens": 10000,
"cachedInputTokens": 7000,
"cacheWriteInputTokens": 1000,
"outputTokens": 2000,
"reasoningOutputTokens": 1500
},
"last": {
"totalTokens": 3500,
"inputTokens": 3000,
"cachedInputTokens": 2000,
"cacheWriteInputTokens": 100,
"outputTokens": 500,
"reasoningOutputTokens": 400
},
"modelContextWindow": 258400
}
}
}