Repository navigation
feat: report subagent credit usage alongside elapsed time - #14913
Conversation
Design Review (Fable 5) — ✅ PASSDesign-level review of Design-Verdict: PASS Verify one live-provider run's displayed credit total — every backend test mocks the billing surface, and the description itself defers live billing verification to maintainers. [DESIGN-REVIEWED] 4fc1b57 Description read[DESCRIPTION-READ] 27294a02bdce60fed33ac125df424a3f3ec0bfb53855fe10b10577e6340be669 That sha256 names everything this verdict read: the PR description, plus the 1 evidence file(s) the workflow collected from it and handed this review. It covers that evidence because the media strip replaces every attachment URL with the same placeholder, so an edit swapping one attachment for another would leave the description's captured text identical while what this review judged changed. Recompute it with |
First Principles Review (Fable 5) — 🟡 CONCERNSPremise-level review of First-Principles-Verdict: CONCERNS Two mechanisms this PR needs already exist — Not justified as shipped
What this change shipsInventory (9 items) — 6 justifiedIntent: Show the credits each managed subagent consumed alongside its terminal elapsed time (implements linked issue #4721) — ADDITION.
[FIRST-PRINCIPLES-REVIEWED] 4fc1b57 Description read[DESCRIPTION-READ] 073b8e7a5477815c66cb1f67e589e4a6146b11023bdd32a3d68b1ecabb961815 That sha256 names the PR description this verdict read. Recompute it with |
GPT 5.6 Review — ✅ no blocking findingsGPT 5.6 completed its review of This comment is updated in place on each push. Review detailsNo findings. False positive or not applicable? A repository writer can comment: |
d54bb58 to
5cd0764
Compare
UX Review (Fable 5) — 🟡 CONCERNSUX-level review of UX-Verdict: CONCERNS "Credit usage not reported" is ambiguous — the blind reader could not tell whether the run was free, unknown, or the counting broke. Watch
Suggestions
[UX-REVIEWED] 4fc1b57 Description read[DESCRIPTION-READ] 38eb2ae65e23664f6d65ba34d8e9e259bd05efc0355b0956d74123b3d1fea76b That sha256 names everything this verdict read: the PR description, plus the 5 evidence file(s) the workflow collected from it and handed this review. It covers that evidence because the media strip replaces every attachment URL with the same placeholder, so an edit swapping one attachment for another would leave the description's captured text identical while what this review judged changed. Recompute it with |
Opus 5 Review — ✅ no blocking findingsReviewed Verdict parsed from the review's SHA-scoped output markers for commit False positive or not applicable? A repository writer can comment: |
Attribute reported credits to managed subagent runs, including failed and
cancelled attempts, so users and parent agents can compare their costs.
Reuse shared turn billing, preserve terminal usage in delivery/failure
tombstones, and show it across completion events, status queries, and
dashboard cards without delaying parent delivery.
Finalize the run's elapsed time once, before any abnormal-exit tombstone
write, so the persisted record and the terminal subagent_done event carry
the same value. Every abnormal arm (timeout, cancel, reap, error) wrote the
tombstone before elapsed was finalized in _run's finally / the reaper, so
sampling the wall clock inline at write time made a replayed spawn_status
disagree with the terminal event. _write_tombstone now finalizes and
persists info.elapsed; the run finally and the reaper set it before/instead
of re-sampling. In the reap-race test, delegate unrecognized
asyncio.to_thread calls to the real implementation so the process-wide
patch stays scoped to the state-writer seam it drives.
In the delivery-ledger test, the ledger's move from bare id strings to
SubagentDelivery objects forced the whole-dict assertions to change; assert
against a whole-ledger {key: [agent_id]} map (_pending_map) rather than the
ids under a single key, so the "exactly one key" pin the successor-dequeue
race depends on is preserved (debt parked under a second key still fails).
Co-authored-by: Vadym Velykoivanenko <5074317+welikoiwanenko@users.noreply.github.com>
5cd0764 to
4fc1b57
Compare
In-repo replacement for #8003 (fork
welikoiwanenko:codex/subagent-credit-usage), rebased onto freshmainso a clean CI wave fires. The author's commit is cherry-picked with authorship preserved. Supersedes #8003.Problem / Motivation
Goal: Show the credits consumed by each managed subagent alongside its terminal elapsed time.
Managed subagent completion reports elapsed time but not the credits consumed by that run. Parents and users cannot attribute the cost of a successful, failed, or stopped subagent without comparing noisy account-level totals.
For maintainer approval: cumulative positive reported credits appear in expanded Subagents activity cards, with elapsed time retained in compact headers and usage included in completion messages and
spawn_status.Why it matters
A failed or stopped attempt can consume credits even when it produces no final answer. Per-run attribution makes those costs visible, including billed transient retries, without relying on unrelated activity in the same account.
Not a goal
What changed (motivation → approach → change)
TurnUsagerepresentation per attempted provider turn. Completion events supply usage on success; the shared billing resolver supplies fresh usage on interrupted or failed attempts. Each attempt settles once, including cancellation during event handling and force-reaping.spawn_statusresponses. Parent delivery does not wait for a new post-completion state write.subagent_doneframes so dashboard reconnects retain terminal usage. Legacy retained records remain readable without invented fields.Used … credits. Compact headers continue to show elapsed time. Backend summaries switch to minutes and seconds at 60 seconds and retain the existing credit precision.No dependency, configuration, schema migration, model-default, or changelog changes. Native harness subagents remain unattributed because they share the parent's billed turn. Providers that do not report credit billing return zero; displays omit that credit label rather than claim the run was free. This feature does not estimate charges or add dollar billing. Run totals are completion summaries, not additional billing-ledger entries; failed-attempt credits can make them larger than successful-turn records alone.
Backwards compatibility
Compatible: existing providers and retained records without credit data continue to render elapsed time without inventing usage.
Tests
format_subagent_usagetest locks in credit precision, minute formatting, and omission of unreported/zero credits.Used … creditscopy.Manual verification
N/A — the author's manual verification (fixture-rendered
ActivityViewerexpanded successful/failed/stopped cards in dark and light themes, credit-only expanded copy, elapsed-only compact headers, minute formatting) carries over unchanged; this replacement makes no code change to the feature. Live provider billing verification remains for maintainers.Screenshots / video
Fixture data rendered by the current component; each card shows its own terminal usage.
Related Issues
Implements the credit-attribution request in #4721. Supersedes #8003.
Fixes #4721
Checklist
feat|fix|docs|style|refactor|perf|test|chore|ci|build|revert: ...)