Skip to content

fix: price PTY eval sessions from their transcripts - #3591

Closed
garrytan wants to merge 16 commits into
mainfrom
garrytan/gsta150-pty-billing
Closed

garrytan wants to merge 16 commits into
mainfrom
garrytan/gsta150-pty-billing

Conversation

@garrytan

@garrytan garrytan commented Oct 29, 2026 •

Copy link
Copy Markdown
Owner
{
  "schema_version": 1,
  "pr": 3591,
  "head": "eccaea13200fb7eeed15f5501f38a37340fc3f02",
  "version": "1.91.304.0",
  "base": "garrytan/gsta150-cost-attribution",
  "session_kind": "unattended",
  "thread": "GSTA-150",
  "queue_mode": "stamp-at-merge",
  "pregate": "requires-remote cleared @42fd6e9d10ce (1 checks, current for eccaea13200f)",
  "requires_remote": [
    "free-tests.yml/macos-named-regressions: https://github.com/garrytan/gstack/actions/runs/40822722668",
    "windows-free-tests.yml/windows-free-shard: https://github.com/garrytan/gstack/actions/runs/40822725850",
    "pregate.json/remote_gate: remote-gate tree=42fd6e9d10ce tests=11992"
  ],
  "issues": {
    "fixes": [],
    "refs": [],
    "flakes": []
  }
}

What changed

PR 3: PTY sessions are priced from their transcripts, so a focused run of three gate cases reports $2.36 known and 0 unknown

PR 3: PTY sessions are priced from their transcripts, so a focused run of three gate cases reports $2.36 known and 0 unknown.

Before/after as text
-$ paid report trial cost, focused run 2026-10-29 (PR 2)
+$ paid report trial cost, focused run 2026-10-29 (PR 2 + PR 3)
 context-save-writes-file     $0.10  known    (claude -p, label-named record in a 4-case shard)
-plan-mode-no-op                  ?  UNKNOWN  (PTY, 6 sessions)
+plan-mode-no-op              $2.04  known    (PTY, 6 sessions)
 auq-format-gate              $0.22  known    (Agent SDK, aborted after the question)
-headline: cost $0.32 known + 1 of 3 trial(s) cost unknown
+headline: cost $2.36 known, 0 unknown

Why

Garry asked for a cost and latency pass on paid evals (GSTA-150). PTY sessions printed no billing, so 8 gate cases (14 sessions, about 884 session-seconds a gate) were always "cost unknown". Claude Code writes every PTY session's transcript with per-message usage, so the report now prices them from that. Stacked on #3590.

Blast radius

The PTY launcher and both PTY ledger writers (launchClaudePty's close wrapper, runPtySession). The launcher adds no argument, so pinned argv contracts hold (test/plan-seed-submission.test.ts passes unchanged), and pricing never throws from a ledger writer (unreadable-transcript test). The native AskUserQuestion capture, which must never read model transcripts, opts out; test/auq-native-capture.test.ts passes unchanged. Evidence: remote free gate ran.

Approvals

Date Asked Exact words Outcome Covers Still pending
2026-10-29 Approve the plan "Paid evals: cut duplicate screen spend and price every gate case (GSTA-150)" (autoplan run GSTA-150-20261029033743, 4 decisions) “Garry: Do it” (Garry, relayed by agent:gstack-minder, relayed by agent:gstack-minder) approved the reviewed plan (sha256 b65a8610ce75), every recommendation taken none
2026-10-29 Approve the plan "Paid evals: cut duplicate screen spend and price every gate case (GSTA-150)" (autoplan run GSTA-150-20261029033743, 3 decisions) “Garry: Do it” (Garry, relayed by agent:gstack-minder, relayed by agent:gstack-minder) approved the reviewed plan (sha256 b65a8610ce75), every recommendation taken none

Source: gstack-approvals record for garrytan/gsta150-pty-billing (display only; not an approval citation).

Summary

  • Transcript pricing (test/helpers/pty/transcript-cost.ts): a session's projects/*/<id>.jsonl plus its subagents/*.jsonl, priced with lib/pricing.ts once per message id (cache writes at 1.25x and 2x). No transcript, no usage, an unpriced model or a read error leaves streamed_cost_usd absent, so the trial stays unknown, never $0.
  • Which transcript (test/helpers/pty/launch.ts): the caller's --session-id (either form), else the one top-level transcript that appeared during this launch for its cwd. Concurrent PTY tests share one hermetic config dir, so a launch never takes the whole directory; two new transcripts for one cwd stay unknown. Resumed and non-hermetic launches stay unknown. priceTranscript: false opts out (test/helpers/auq-native-capture.ts).
  • Plan deviation: the first build pinned a random --session-id on every hermetic launch. The remote free gate showed that breaks two pinned contracts, so the launcher now adds nothing and claims the new transcript instead.

Test Coverage

test/paid-report-cost.test.ts: transcript pricing with inline sidechains, subagent files, dedupe, <synthetic> and a foreign session; unknown for a missing, empty, unreadable or unpriced transcript; the new-transcript claim for one cwd, a concurrent cwd and an ambiguous pair. test/helpers/claude-pty-runner.launch.unit.test.ts: a real PTY launch of a fake CLI prices the transcript it wrote, adds no argument, and an opted-out launch prices nothing.
Coverage audit (pass 1): 80% value-weighted.
Tests ran: remote free gate (Ubicloud) 11992 tests, 0 failed on tree 42fd6e9d10ce. macOS named regressions and Windows free shard clear from CI.

Pre-Landing Review

Pass 1 (specialists, red team, adversarial, outside voice openai/gpt-6.1-sol): blocking fixed — a transcript read error could replace the verdict and skip close and cleanup; transcript-cost.ts was unpinned in scripts/harness-version.json. Fixed: --session-id= and --resume= forms. Pass 2 fix-check: no findings. Pass 3 fix-check of the redesign after the remote gate: no blocking; fixed a CHANGELOG file reference and two stale harness notes. Noted: two sessions in one cwd where only one writes a transcript would both claim it; a caller-pinned session that runs /clear is undercounted (no PTY test does either today); transcripts are priced just before close, so a message still streaming at teardown is missed.
REVIEW_LOOP: passes=3 converged.
Gate edits: none to thresholds, trials, samples, judges, kinds or quarantine; PTY ledger cost fields only, recorded non-behavioral at HARNESS_VERSION 6.

Eval Results

Focused paid run 2026-10-29 (pre-approved, under $10), Claude Code 2.1.312, claude-opus-5-5: plan-mode-no-op passed and its 6 PTY sessions logged streamed_cost_usd totalling $2.04. A live claude -p session with one Task subagent priced $0.090376 from its two transcripts, equal to its total_cost_usd. The run used the first build's --session-id pin; the redesign reads the same files.

Plan Completion

PR 3 items 1-2 DONE (item 1 CHANGED: transcript found by cwd claim, above). Live total_cost_usd check DONE.

Documentation

Updated (on top of #3590's docs): docs/TESTING_INTERNALS.md (session ledger: PTY transcript pricing and how the session is found; exercised-map lower-bound sentence), docs/troubleshooting.md (cost unknown: PTY is unknown only when its transcript does not price), docs/evals/census-red.md (table row). Runtime labels "unknown cost (PTY)" in scripts/test-pr-profile.ts and scripts/test-health-report.ts are left as they are (output only).

garrytan and others added 16 commits October 29, 2026 04:27
…me, price aborted SDK sessions from streamed usage, model-free cases cost $0

Co-authored-by: capy-ai[bot] <230910855+capy-ai[bot]@users.noreply.github.com>
… cost_known

Co-authored-by: capy-ai[bot] <230910855+capy-ai[bot]@users.noreply.github.com>
Co-authored-by: capy-ai[bot] <230910855+capy-ai[bot]@users.noreply.github.com>
Co-authored-by: capy-ai[bot] <230910855+capy-ai[bot]@users.noreply.github.com>
… case

Co-authored-by: capy-ai[bot] <230910855+capy-ai[bot]@users.noreply.github.com>
Co-authored-by: capy-ai[bot] <230910855+capy-ai[bot]@users.noreply.github.com>
…ut a 5m key

Co-authored-by: capy-ai[bot] <230910855+capy-ai[bot]@users.noreply.github.com>
Co-authored-by: capy-ai[bot] <230910855+capy-ai[bot]@users.noreply.github.com>
…session's and its subagents' usage into the ledger's streamed_cost_usd

Co-authored-by: capy-ai[bot] <230910855+capy-ai[bot]@users.noreply.github.com>
Co-authored-by: capy-ai[bot] <230910855+capy-ai[bot]@users.noreply.github.com>
Co-authored-by: capy-ai[bot] <230910855+capy-ai[bot]@users.noreply.github.com>
Co-authored-by: capy-ai[bot] <230910855+capy-ai[bot]@users.noreply.github.com>
Co-authored-by: capy-ai[bot] <230910855+capy-ai[bot]@users.noreply.github.com>
Co-authored-by: capy-ai[bot] <230910855+capy-ai[bot]@users.noreply.github.com>
…UQ capture opts out

Co-authored-by: capy-ai[bot] <230910855+capy-ai[bot]@users.noreply.github.com>
Co-authored-by: capy-ai[bot] <230910855+capy-ai[bot]@users.noreply.github.com>
@capy-ai
capy-ai Bot changed the base branch from garrytan/gsta150-cost-attribution to main November 2, 2026 08:27
@capy-ai

capy-ai Bot commented Nov 2, 2026

Copy link
Copy Markdown
Contributor

Retargeted to main by the docs wave integrator (GSTA-158): this PR's pin eccaea1 already contains #3590's pin ceba1f4, and #3590 merges into the same wave first, so the wave carries #3590 then #3591. Head unchanged.

@trunk-io

trunk-io Bot commented Nov 2, 2026

Copy link
Copy Markdown

Merging to main in this repository is managed by Trunk.

  • To merge this pull request, check the box to the left or comment /trunk merge below.

After your PR is submitted to the merge queue, this comment will be automatically updated with its status. If the PR fails, failure details will also be posted here

@capy-ai

capy-ai Bot commented Nov 2, 2026

Copy link
Copy Markdown
Contributor

Frozen in wave docs-21563262ae01 (branch wave/docs-21563262ae01) at eccaea1. Push nothing here: a moved head drops this PR from the wave. Fixes go on the wave branch through its integrator.

capy-ai Bot added a commit that referenced this pull request Nov 2, 2026
* Attribute every paid trial's cost: bind label-named records by testName, price aborted SDK sessions from streamed usage, model-free cases cost $0

Co-authored-by: capy-ai[bot] <230910855+capy-ai[bot]@users.noreply.github.com>

* fix: case cost adds streamed sessions to record sums and keeps record cost_known

Co-authored-by: capy-ai[bot] <230910855+capy-ai[bot]@users.noreply.github.com>

* fix: the paid report headline counts ledger-only session cost once

Co-authored-by: capy-ai[bot] <230910855+capy-ai[bot]@users.noreply.github.com>

* fix: a cost-only record never sets the trial model

Co-authored-by: capy-ai[bot] <230910855+capy-ai[bot]@users.noreply.github.com>

* test: recordE2E writes cost_case_id only for a registered label-named case

Co-authored-by: capy-ai[bot] <230910855+capy-ai[bot]@users.noreply.github.com>

* docs: CHANGELOG for paid-report cost attribution (Unreleased)

Co-authored-by: capy-ai[bot] <230910855+capy-ai[bot]@users.noreply.github.com>

* fix: the headline adds only streamed session cost; cache writes without a 5m key

Co-authored-by: capy-ai[bot] <230910855+capy-ai[bot]@users.noreply.github.com>

* docs: how the paid report prices a trial and what stays cost-unknown

Co-authored-by: capy-ai[bot] <230910855+capy-ai[bot]@users.noreply.github.com>

* Price PTY sessions from their transcripts: pin a session id, sum the session's and its subagents' usage into the ledger's streamed_cost_usd

Co-authored-by: capy-ai[bot] <230910855+capy-ai[bot]@users.noreply.github.com>

* fix: transcript pricing never throws from a PTY ledger writer

Co-authored-by: capy-ai[bot] <230910855+capy-ai[bot]@users.noreply.github.com>

* chore: pin transcript-cost.ts as non-behavioral at HARNESS_VERSION 6

Co-authored-by: capy-ai[bot] <230910855+capy-ai[bot]@users.noreply.github.com>

* fix: recognise --session-id= and --resume= forms

Co-authored-by: capy-ai[bot] <230910855+capy-ai[bot]@users.noreply.github.com>

* docs: CHANGELOG for PTY transcript pricing (Unreleased)

Co-authored-by: capy-ai[bot] <230910855+capy-ai[bot]@users.noreply.github.com>

* docs: PTY sessions priced from their transcripts

Co-authored-by: capy-ai[bot] <230910855+capy-ai[bot]@users.noreply.github.com>

* fix: price PTY transcripts without adding a launch argument; native AUQ capture opts out

Co-authored-by: capy-ai[bot] <230910855+capy-ai[bot]@users.noreply.github.com>

* docs: harness notes and CHANGELOG match the transcript claim

Co-authored-by: capy-ai[bot] <230910855+capy-ai[bot]@users.noreply.github.com>

* feat(flaky): gstack-flaky run reruns a failed JUnit test once and ledgers the flake (GSTA-158)

Co-authored-by: capy-ai[bot] <230910855+capy-ai[bot]@users.noreply.github.com>

* fix(flaky): stream output, keep unreported runner failures red, fail-closed duplicates and nonzero reruns

Co-authored-by: capy-ai[bot] <230910855+capy-ai[bot]@users.noreply.github.com>

* fix: pre-landing review fixes

gstack-flaky never greens an incomplete run: a targeted rerun needs the
runner's summary proving the first run complete, otherwise (and always for
generic runners) the rerun repeats the whole command. A rerun clears a test
only when it exits 0 and the test passes once on its first attempt. Killed
runners exit 3 (FLAKY_COMMAND_KILLED) and signals are forwarded. The first
report is restored at --junit with reruns kept beside it; ids are redacted at
every output; the ledger gets its own GSTACK_FLAKE_LEDGER_JUNIT; fixtures are
registered in FREE_FIXTURES.

Co-authored-by: capy-ai[bot] <230910855+capy-ai[bot]@users.noreply.github.com>

* fix: latch cancellation and check whole-command rerun reports

A cancel forwarded to a runner that traps the signal now counts as killed for
every later attempt, so a cancelled job is never rerun or greened. A
whole-command rerun clears nothing when its report has a failed test, misses a
first-run test, or its runner counted failures outside the report.

Co-authored-by: capy-ai[bot] <230910855+capy-ai[bot]@users.noreply.github.com>

* fix: whole-command rerun when coverage or runner-flaky tests can fail the run

A coverage threshold or a fail-on-flaky policy fails a run for a reason a
narrowed rerun cannot reproduce, so either forces a whole-command rerun.
--junit refuses an existing file that is not a JUnit report instead of
deleting it.

Co-authored-by: capy-ai[bot] <230910855+capy-ai[bot]@users.noreply.github.com>

* feat(flaky): rerun the whole command by default; targeted rerun is opt-in

A rerun counts only on the runner's own full green verdict: exit 0, no failed
or missing test, nothing counted outside the report. That covers every way a
run can fail, which a narrowed rerun cannot (a coverage threshold with an lcov
reporter, a fail-on-flaky policy, a test never reached). --rerun-scope test
reruns the failed test alone, with its preconditions documented and the
complete-run checks kept as a safety net. An unreadable existing --junit file
is a usage error, not a crash.

Co-authored-by: capy-ai[bot] <230910855+capy-ai[bot]@users.noreply.github.com>

* docs: gstack-flaky CHANGELOG entry and standalone-binaries row (GSTA-158)

Co-authored-by: capy-ai[bot] <230910855+capy-ai[bot]@users.noreply.github.com>

* feat(flaky): quarantine registry for repeat flakes (GSTA-158 P2)

Co-authored-by: capy-ai[bot] <230910855+capy-ai[bot]@users.noreply.github.com>

* fix(flaky): bound renewal dates; match non-ASCII paths in check --base

Co-authored-by: capy-ai[bot] <230910855+capy-ai[bot]@users.noreply.github.com>

* fix(flaky): reword the FLAKY_QUARANTINE_BASE hint so the egress scanner does not read it as a network op

Co-authored-by: capy-ai[bot] <230910855+capy-ai[bot]@users.noreply.github.com>

* test(agent-sdk): every SDK caller passes the claude_code preset or names why not

The SDK's default system prompt is a bare stub that drops the line telling the
model to run /skill through the Skill tool. runAgentSdkTest now refuses a
missing, empty or bare-string prompt; non-preset callers name a reason; a free
tripwire scans test/ and scripts/ for the same mistake.

Co-authored-by: capy-ai[bot] <230910855+capy-ai[bot]@users.noreply.github.com>

* test: record the SDK prompt guard as a non-behavioral harness change and baseline its tripwire

harness-version: runAgentSdkTest validates systemPrompt before starting; every
live caller already passed the claude_code preset, so no verdict can change.
test-of-test ratchet: the tripwire's subject is the eval harness by design.

Co-authored-by: capy-ai[bot] <230910855+capy-ai[bot]@users.noreply.github.com>

* docs: name the preset literal callers pass and the unnamed-prompt refusal

Co-authored-by: capy-ai[bot] <230910855+capy-ai[bot]@users.noreply.github.com>

* feat(eval-plan): frontier models under test (R54)

Haiku and Sonnet are not models under test. dry-run refuses a plan whose every
arm is Haiku or Sonnet unless --tier-question names what it asks about that
tier, warns on a mix, and re-costs the plan on Opus 5.5 and GPT-6.1 Sol.

Co-authored-by: capy-ai[bot] <230910855+capy-ai[bot]@users.noreply.github.com>

* fix(eval-plan): trim R54 skill prose and raise the eval-plan context ceiling

The R54 paragraph and CHECK: frontier bullet were cut to the minimum; the
exemptions and verdict rule stay in docs/TESTING_INTERNALS.md. The remaining
growth is the feature, so only the eval-plan eager ceiling moves (4887 -> 5458,
the capture helper's value); other skills' ceilings are left as they were.

Co-authored-by: capy-ai[bot] <230910855+capy-ai[bot]@users.noreply.github.com>

* fix(eval-plan): pilot start keeps the R54 refusal; --tier-question rejects a flag

Review pass 1 (full depth) found the frontier refusal could be skipped by
starting a pilot on Haiku or Sonnet arms behind a dry run made on other arms,
or behind a dry-run.json written before the check existed. startPilot now
refuses a pilot whose every arm is Haiku or Sonnet unless its dry run recorded
a tier question. dry-run --tier-question no longer takes the next flag as its
answer. The testing doc now says the frontier re-cost is printed for
comparison with the brief cap, not enforced.

Co-authored-by: capy-ai[bot] <230910855+capy-ai[bot]@users.noreply.github.com>

* docs(support-tiers): Windows CI in the present tense now that windows-smoke is required (#3806)

Co-authored-by: capy-ai[bot] <230910855+capy-ai[bot]@users.noreply.github.com>

* chore: empty commit for a clean check set at the same tree (cancelled orphan free-suite check at 97487df)

Co-authored-by: capy-ai[bot] <230910855+capy-ai[bot]@users.noreply.github.com>

* docs(skills): /eval-plan entry names the R54 frontier check

Co-authored-by: capy-ai[bot] <230910855+capy-ai[bot]@users.noreply.github.com>

---------

Co-authored-by: capy-ai[bot] <230910855+capy-ai[bot]@users.noreply.github.com>
@capy-ai

capy-ai Bot commented Nov 2, 2026

Copy link
Copy Markdown
Contributor

Landed in wave #3847 as v1.93.10.0 (daf6613), merged from this PR's pin eccaea1. Integrator changes touching this PR's files: c1c8161 (merge of #3591, resolved by hand: scripts/harness-version.json), ba30ee0 (merge of #3819, resolved by hand: scripts/harness-version.json, test/helpers/agent-sdk-runner.ts).

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