Skip to content

Self-hosted, Self-Improving, Federated Everything App — dev management, agent orchestration, persistent mind, digital twin, second brain, and creative pipeline from a single dashboard over Tailscale to port the user into the OS

address review (claude): bucket a model-less Codex rollout under UNKNOWN_MODEL

[._.]/ Adam Eivyb622fd391483
diff --git a/server/lib/providerTranscriptUsage.js b/server/lib/providerTranscriptUsage.js
index b98a66ccad..3c8fa2a9e3 100644
--- a/server/lib/providerTranscriptUsage.js
+++ b/server/lib/providerTranscriptUsage.js
@@ -378,8 +378,14 @@ export function parseCodexRollout(jsonlText, { from = null, to = null } = {}) {
models: model ? [model] : [],
// Codex reports one model per rollout (no mid-session switch in the format),
// so the whole delta is that model's — mirrored into `byModel` for shape
- // parity with the Claude parser so callers need no per-family branch.
- byModel: model ? { [model]: { ...totals } } : {},
+ // parity with the Claude parser so callers need no per-family branch. A
+ // model-less rollout (no session_meta.model, no turn_context.model) still
+ // gets its own UNKNOWN_MODEL bucket rather than an empty byModel — an
+ // empty map here made readMeasuredUsage's fold() drop this rollout's
+ // tokens entirely whenever a run's window also picked up a NAMED-model
+ // rollout: reconcileRunUsage's `perModel.length > 0` branch only bills
+ // from byModel, so a model-less rollout invisible to it billed nothing.
+ byModel: { [model || UNKNOWN_MODEL]: { ...totals } },
...totals,
firstTs,
lastTs
diff --git a/server/lib/providerTranscriptUsage.test.js b/server/lib/providerTranscriptUsage.test.js
index 93247b65b5..838ba07092 100644
--- a/server/lib/providerTranscriptUsage.test.js
+++ b/server/lib/providerTranscriptUsage.test.js
@@ -404,6 +404,27 @@ describe('no billable tokens are dropped from byModel', () => {
expect(sum('cacheReadTokens')).toBe(result.cacheReadTokens);
expect(sum('messages')).toBe(result.messages);
});
+
+ // A Codex rollout whose session_meta/turn_context never named a model used
+ // to return byModel: {} despite nonzero totals — invisible to
+ // reconcileRunUsage's per-model billing path once a NAMED-model rollout
+ // shared the same run window, silently dropping this rollout's tokens.
+ it('buckets a model-less Codex rollout under UNKNOWN_MODEL instead of an empty byModel', () => {
+ const metaNoModel = JSON.stringify({
+ timestamp: '2026-07-01T10:00:00.000Z',
+ type: 'session_meta',
+ payload: { id: 'rollout-no-model', cwd: '/work/example-repo', cli_version: '0.0.0' }
+ });
+ const text = [
+ metaNoModel,
+ codexTokenCount({ timestamp: '2026-07-01T10:00:01.000Z', input: 3000, cached: 2400, output: 250 })
+ ].join('\n');
+
+ const result = parseCodexRollout(text);
+ expect(result.model).toBeNull();
+ expect(Object.keys(result.byModel)).toEqual([UNKNOWN_MODEL]);
+ expect(result.byModel[UNKNOWN_MODEL]).toMatchObject({ tokensOut: 250, cacheReadTokens: 2400 });
+ });
});
describe('Codex message count under a window', () => {