Created
Jul 01, 16:04
Started
Jul 01, 16:09
Completed
Jul 01, 16:39
DevOps handoff
Type
Feature
Shape
backend
Worktree Slug
fresh-tokens-accurate-cost
Repositories
mcritchie-studio
Release Slug
—
Branch
feat/fresh-tokens-accurate-cost
Local URL
—
QA URL
—
Production URL
—
Acceptance Criteria
Expected Test Plan
Checks Run
Agent Context
Refine the just-shipped token/cost capture (capture-action-tokens-and-cost-2, now on prod). PROBLEM verified live: tokens_in = input + cache_creation + cache_read all LUMPED, so on a long session it's ~300K/action dominated by CACHE READS (re-read context), and cost prices ALL of tokens_in at full input rate -> cost overstated ~10x (a real turn showed 309313 tokens / $1.58; true cost ~$0.15). Operator decision: TOKENS column shows FRESH tokens (new spend, exclude cache reads); COST priced with correct cache tiers. CHANGES: (1) Hook bin/atomic-capture-hook : stop lumping. tokens_in = input_tokens + cache_creation_input_tokens (fresh input processed this turn); tokens_out = output_tokens; NEW column cache_read_tokens = cache_read_input_tokens (re-used context, for cost only). (2) Migration: add cache_read_tokens to atomic_actions (nullable default 0); controller permits it; cost stays SERVER-DERIVED (not caller-set). (3) Cost in app/models/atomic_action.rb cost_for: price per tier = tokens_in*in_rate + cache_read_tokens*(in_rate*0.10) + tokens_out*out_rate; keep NULL when no rate for the model. (cache_creation lumped into tokens_in at 1x is acceptable best-effort vs its true 1.25x — note it in a comment; or store separately if easy.) (4) Display: heartbeat TOKENS column + drawer = tokens_in + tokens_out (fresh, EXCLUDES cache_read). heartbeat_usage_totals sums fresh tokens_in/out + cost, STILL deduped by source_turn_uuid (unchanged); cache_read need not be displayed. Update heartbeat_helper + _trajectory_table + _event_table + _drawer as needed. (5) Tests: usage split (fresh vs cache_read), tiered cost (cache_read at 0.1x + null-when-no-rate), fresh-token display, dedupe unchanged. VERIFY against a real transcript: a long-session turn should show fresh ~1-8K tokens + cost ~cents, NOT 300K/$1.58. Files: bin/atomic-capture-hook, app/models/atomic_action.rb, migration, app/controllers/api/v1/atomic_actions_controller.rb, app/helpers/heartbeat_helper.rb, heartbeat views. Part of narrated-events epic — project_opsd_learning_layer, [[feedback_token_capture_fragility]]. NOTE: the hook usage-folding method is turn_usage in bin/atomic-capture-hook (that word was lost to a shell-quoting slip).
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)
SMALL
Dev
SMALL
Actual
XL
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.