Skip to content

fix(codex): capture per-turn tokens + model from JSONL#23

Merged
janfaris merged 1 commit into
mainfrom
fix/codex-token-capture
May 26, 2026
Merged

fix(codex): capture per-turn tokens + model from JSONL#23
janfaris merged 1 commit into
mainfrom
fix/codex-token-capture

Conversation

@janfaris
Copy link
Copy Markdown
Owner

Parser was ignoring token_count and turn_context events, so every Codex upload had null tokens/model/cost. This wires up:

  • packages/parsers/src/codex.ts — read last_token_usage per turn, attach to most recent completion; track model from turn_context.payload.model
  • apps/web/app/api/sessions/upload/route.ts — prefer per-event model over LLM-inferred ai.models
  • apps/web/scripts/seed-model-prices.ts — add gpt-5.5 ($5 in / $30 out / $0.50 cached)

Verified locally: real codex session 019e5f53 now parses 38 completions with tokens, totaling 4.63M in / 15.8K out / 4.41M cached, model=gpt-5.5. All 42 parser tests pass.

Parser now handles token_count events (last_token_usage -> per-completion
inputTokens/outputTokens/cacheReadInputTokens) and turn_context events
(model = e.g. gpt-5.5). Upload route prefers per-event model over
LLM-inferred ai.models. Seed gpt-5.5 OpenAI pricing (5/30/0.50).

Without this, every Codex session uploaded to gettrail.vercel.app had
inputTokens/outputTokens/cachedTokens/estimatedCostUsd all NULL, even
though the raw JSONL contained full usage data. End result: the
cost-per-PR dashboard was empty for everyone using Codex.
@vercel
Copy link
Copy Markdown

vercel Bot commented May 26, 2026

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
trail Building Building Preview, Comment May 26, 2026 4:31pm

Request Review

@janfaris janfaris merged commit 2926936 into main May 26, 2026
1 of 2 checks passed
@janfaris janfaris deleted the fix/codex-token-capture branch May 26, 2026 16:31
janfaris added a commit that referenced this pull request May 27, 2026
Parser now handles token_count events (last_token_usage -> per-completion
inputTokens/outputTokens/cacheReadInputTokens) and turn_context events
(model = e.g. gpt-5.5). Upload route prefers per-event model over
LLM-inferred ai.models. Seed gpt-5.5 OpenAI pricing (5/30/0.50).

Without this, every Codex session uploaded to gettrail.vercel.app had
inputTokens/outputTokens/cachedTokens/estimatedCostUsd all NULL, even
though the raw JSONL contained full usage data. End result: the
cost-per-PR dashboard was empty for everyone using Codex.
janfaris added a commit that referenced this pull request May 27, 2026
Macrostructure: 04 Stat-Led. The real verified cost from session 161blsz1
($3.77, gpt-5.5, PR #23) becomes the hero — no fake metrics, no mockups,
no Bento Grid SaaS template.

- Hero: 200px Fraunces display tabular-num $3.77, italic qualifier underneath
- Breakdown: hairline table decomposing the number into in/out/cached
- How: three numbered steps (Install / Work / Ship), code-led
- Coverage: tier table with honest Primary/Partial labels — Copilot called
  out for having no per-user token API instead of pretending otherwise
- Final CTA strip + Ft7 one-line footer

660 lines → 290 lines. Both CTAs (npm install + Sign in) given equal weight
in hero. Anti-slop disciplines applied: tabular-nums everywhere, no
re-drawn chrome, ≤3 fonts (Geist + Fraunces + Geist Mono), real numbers
only, hairline-rule rhythm. Slop test 69/69.
janfaris added a commit that referenced this pull request May 31, 2026
Recenter the landing on the receipt as a proof object: real $ cost as a
credibility anchor, the linked public PR as the third-party-provable fact,
and the Verified Builder badge shown locked/pending until GitHub confirms a
merge. Keeps a strict line between "GitHub confirmed it" and "Trail measured
it" — claims only what's independently true (real cost, Codex/gpt-5.5, 295
turns, genuinely-merged public PR #23) and never presents a session as
merge-verified when it isn't.

Adds the social/distribution surfaces (profile, discover, feed, tools,
frameworks) framed as an aspirational empty-state, and an honest coverage
section. Signed-in users still redirect to /dashboard/cost.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant