Skip to content

feat: record token usage and duration for eval runs - #270

Merged
mattrossman merged 7 commits into
mainfrom
mattrossman/ai-971-surface-eval-run-performance-metrics
Sep 8, 2026
Merged

mattrossman merged 7 commits into
mainfrom
mattrossman/ai-971-surface-eval-run-performance-metrics

Conversation

@mattrossman

@mattrossman mattrossman commented Sep 7, 2026 •

Copy link
Copy Markdown
Collaborator

Records usage and durationMs on each result so we can see what a run costs in tokens and how long the agent took. Usage tracks input, cache read, cache write, and output tokens, inspired by OTel GenAI conventions where the cache buckets are subsets of input. All four harnesses report these fields, and from them we can price a run (the two cache buckets each have their own rate, and input minus both is the fresh input billed at the base rate), see OpenAI or Claude pricing.

// result.json
{
  // ...,
  "usage": [
    {
      "model": "gpt-5.6-sol",
      "inputTokens": 267028,
      "cacheReadInputTokens": 230032,
      "cacheWriteInputTokens": 36957,
      "outputTokens": 1971
    }
  ],
  "durationMs": 61877
}

Usage is a list because runs can potentially use multiple models, e.g. by default Claude Code incurs a small amount of Haiku usage for title renames (thread), but we could also see runs that spawn subagents.

Aside: based on that finding, I took the opportunity to disable background traffic (Claude Code nonessential traffic + session title, codex analytics, opencode auto-update) to prevent unexpected token usage or other run interference. E.g. CLAUDE_CODE_DISABLE_NONESSENTIAL_TRAFFIC and CLAUDE_CODE_DISABLE_TERMINAL_TITLE per docs.

The UI details for a run now shows duration and a one-line token total (Preview deep link)

CleanShot 2026-09-07 at 17 49 24@2x

Sanity checked every bucket against raw CLI output for all three sandbox harnesses plus direct OpenAI API calls, and ran one eval per harness end to end. After merge, we can let performance metrics trickle in from nightly regression runs, and optionally trigger a full benchmark refresh when it's convenient.

Closes AI-971

@vercel

vercel Bot commented Sep 7, 2026 •

Copy link
Copy Markdown

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

1 Skipped Deployment
Project Deployment Actions Updated
evals Ignored Ignored Preview Sep 8, 2026 2:24pm UTC

Request Review

@mattrossman

Copy link
Copy Markdown
Collaborator Author

Dispatching a sample run of one eval per benchmark experiment to demo what the data and UI looks like.

@mattrossman

mattrossman commented Sep 7, 2026 •

Copy link
Copy Markdown
Collaborator Author

Realizing that the current shape deviates slightly from OTel GenAI conventions, gonna align more closely to that. Same data ultimtately just different derivation.

(Edit: pushed that change and kicking off new run)

@mattrossman
mattrossman marked this pull request as ready for review September 7, 2026 23:39
@mattrossman
mattrossman requested a review from a team September 7, 2026 23:39

@Rodriguespn Rodriguespn left a comment •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Approved - token/duration usage wiring is solid across all four harnesses (inclusive OTel-style buckets, real fixture-tested math).

Small nits: ai-sdk lacks an usage-extraction test the other three have, and the shipped inclusive inputTokens naming diverges from the plan doc's disjoint design without a reconciliation note. IIRC, we're not running any ai-sdk experiment anymore but for consistency sake, should we also add a test for this to the ai-sdk?

@mattrossman

Copy link
Copy Markdown
Collaborator Author

Thanks @Rodriguespn , I've added the AI SDK usage extraction test in ebff956. And yes, the inputTokens part I added when prepping this PR for review as I realized it's probably better to align w/ the OTel GenAI conventions. Previously my implementation plan took parts of it as inspo but only half aligned.

@mattrossman
mattrossman merged commit 4ccdd96 into main Sep 8, 2026
7 checks passed
mattrossman added a commit that referenced this pull request Sep 11, 2026
) (#241)

This is stacked on #240. Review that first; this diff is against it. No
results are touched.

## Problem

We wrote our own system prompt into every eval run, for all four agents:

> You are an agent solving a Supabase eval task in a Linux workspace.
Use the provided tools to inspect and modify the workspace and run
commands. When you are done, end your turn with a short summary of what
you did.

- Claude Code, Codex and OpenCode ship their own system prompt. Ours was
layered on top, and Codex and OpenCode have no system-prompt flag, so
for them it went onto the user prompt.
- It described `bash` and `files_read`, which only the in-process
`ai-sdk` agent has.
- "End your turn with a short summary" shapes `agentReport`, which the
LLM judge reads. That is a scoring change.
- It says Supabase, and "project". An agent that would otherwise pick a
database has been handed the answer (#164).

## Changes

| Agent | Before | After |
|---|---|---|
| `ai-sdk` | framing + tool list + skills list | one neutral line + tool
list + skills list |
| `claude-code` | ours appended to its own | nothing |
| `codex` | ours prepended to the user prompt | nothing |
| `opencode` | ours prepended to the user prompt | nothing |

- CLI agents take no system prompt at all. `createCliAgent` no longer
stages a system-prompt file or passes a path to the runner;
`--append-system-prompt-file` and the Codex/OpenCode prepend are gone. A
non-empty `systemPrompt` for a CLI agent throws.
- The `ai-sdk` base prompt is now `You are an agent. Use the provided
tools to complete the task.` It is the same in both modes. No Supabase,
no project, no stopping instructions.
- `buildToolSurfaceAddendum` and `buildSkillsPrompt` return `''` for
every CLI agent. The bare sandbox no longer takes an `agent` or returns
a `promptAddendum`.
- Prompt assembly moves out of `run-eval.ts` into `system-prompt.ts` so
it can be unit tested.
- `run-eval.ts` only starts a run when it is the entry point. It used to
call `main()` on import, which the harness unit tests now trigger.
- Each run records `systemPrompt` in its raw `result.json`.
`export-results` drops it, so nothing reaches the site.

Since the first review: the system-prompt-file plumbing for CLI agents
is deleted rather than made optional, and the ai-sdk base prompt is
rewritten for #164. The branch is re-applied on the current #240 (the
retry loop is gone there), so the commits are new. #240 now has `main`
merged in, which brings the usage and duration fields from #270.

## Testing

- `pnpm --filter @supabase-evals/core test`, `pnpm --filter
@supabase-evals/sandbox test`, `pnpm --filter @supabase-evals/framework
test`, `pnpm --filter @supabase-evals/web test`: all pass locally.
- `typecheck` for framework, sandbox and web passes. `biome check .` is
clean.
- Unverified against real CLIs since the deletion. The earlier sandbox
runs (Claude Code
[32785480269](https://github.com/supabase/evals/actions/runs/32785480269),
Codex
[32880822811](https://github.com/supabase/evals/actions/runs/32880822811),
OpenCode
[32880839623](https://github.com/supabase/evals/actions/runs/32880839623))
recorded an empty prompt and still loaded the Supabase skills, and the
path they exercised (no flag, task alone) is the one that remains.

## Score movement

Full benchmark on both branches before this revision, artifact only,
nothing published. Both used `runs=2`.

| | #240, no prompt change | #241, prompt removed | |
|---|---|---|---|
| all pairs | 86.0% | 84.7% | 21 flips, 12 down 9 up |
| `claude-code` | 92.3% | 92.3% | no change |
| `codex` | 81.5% | 75.0% | down 6.5 points |
| `opencode` | 82.6% | 89.1% | up 6.5 points |

This looks like run-to-run variability. Once #229 lands and scores
average across runs, the numbers should settle.

## Follow-ups

- Re-run the benchmark comparison once #229 lands and the numbers can
carry attribution.
- Drop the "end your turn with a short summary" line from
`evals/resolve-performance-001-slow-query-cpu-spike/PROMPT.md:15`, the
last one left. It sits in the task text so it hits every agent equally,
and removing it invalidates that eval's recorded results, so it should
be a separate change.

Ref AI-1034

---------

Co-authored-by: Matt Rossman <[email protected]>
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.

2 participants