Created
Jul 01, 15:02
Started
Jul 01, 15:03
Completed
Jul 01, 15:46
DevOps handoff
Type
Feature
Shape
backend
Worktree Slug
capture-action-tokens-and-cost-2
Repositories
mcritchie-studio
Release Slug
—
Branch
feat/capture-action-tokens-and-cost-2
Local URL
—
QA URL
—
Production URL
—
Acceptance Criteria
Expected Test Plan
Checks Run
Agent Context
The heartbeat's TOKENS and COST columns are always '—' because the Claude Code PostToolUse payload carries NO usage data (same gap MODEL had — model was solved by reading the transcript JSONL tail in bin/atomic-capture-hook via resolve_model/read_model_from_transcript). Do the SAME for usage: from the assistant turn line in the transcript tail (the one that carries message.model), also read message.usage {input_tokens, output_tokens, cache_creation_input_tokens, cache_read_input_tokens} and the line's 'uuid' (the assistant turn id). Stamp AtomicAction.tokens_in (input+cache) + tokens_out (output) + a NEW nullable column source_turn_uuid (migration; best-effort, indexed). COST = (tokens_in*in_rate + tokens_out*out_rate) from a configurable model->rate map (a small Ruby constant or ENV/Studio::Enumeral); if no rate for the model, leave cost NULL (NEVER fabricate a price). PARALLEL-TOOL-CALL CAVEAT: one assistant turn can fire N tool calls (N actions), all sharing that turn's usage — so per-action stamping duplicates. The heartbeat SPAN + SESSION aggregation (heartbeat_helper heartbeat_event_totals + the session-total, and grade/counts if relevant) MUST dedupe by source_turn_uuid (sum usage over DISTINCT turns), else totals multi-count. Per-action drawer can show the turn's usage as-is. All best-effort + never raise (mirror the model path). Tests: unit for usage extraction from a sample transcript line + cost calc + null-when-no-rate; integration/helper for dedupe-by-turn span totals. Files: bin/atomic-capture-hook, app/models/atomic_action.rb, a migration, app/helpers/heartbeat_helper.rb (aggregation), maybe app/controllers/api/v1/atomic_actions_controller.rb (permit tokens/source_turn_uuid). Part of narrated-events epic — project_opsd_learning_layer, [[feedback_token_capture_fragility]].
Stage Timeline
Who handled each stage, the time it took (measured), and the model / tokens / cost reported (best-effort) — plus who's on it right now. — means the agent didn't report that metric.
Conversation
QA review feedback, agent handoffs, and follow-up notes for this task.
No task feedback has been recorded yet.
Sealed-bid sizing
Edit →Alex (PM)
—
Avi (PO)
MEDIUM
Dev
MEDIUM
Actual
LARGE
We emailed a one-tap sign-in link to . It expires shortly and can only be used once.
No email? Check spam, or close this and try again.