Skip to content

fix(band): book each turn's cost on the task, so a reload or /clear keeps the total right - #1402

Open
dev-tembang wants to merge 1 commit into
DietrichGebert:mainfrom
dev-tembang:fix/band-cost-per-turn
Open

dev-tembang wants to merge 1 commit into
DietrichGebert:mainfrom
dev-tembang:fix/band-cost-per-turn

Conversation

@dev-tembang

Copy link
Copy Markdown

Fixes #1343. Also fixes the "band shows $0 after a resume" part of #1188 (not the day bucketing, which is a separate change).

Problem

turn.complete set the task's cost to the engine's running total:

spent: usage.cost?.usd ?? b.spent + turn,

Because usage.cost.usd is always set, the per-turn fallback never ran. That total is wrong in two directions:

  • /clear: the engine total goes on, so a new task starts with every earlier task's cost (Task Cost Isolation Broken Across /clear via Nullish Coalescing Fallback #1343).
  • New process (an IDE reload, --resume): the engine total starts over at zero. resume() brought back agent time, tokens and the name from the ledger row, but not the cost. The band showed $0.00, and the next turn wrote the smaller number over the task's row. The board then lost the money the task had already cost.

Seen on Windows in the VS Code-style extension: a task with 11.62 in its row showed $0.00 next to its restored 33m 12s of agent time.

Fix

  • turn.complete: spent: b.spent + turn. Each turn adds its own share, the engine total minus the baseline, which already handles a total that drops.
  • resume(): also takes the cost back from the task's row (Math.max, like agent time).
  • start(): when the session id changes (/resume, /branch), the band resets the task counters before resume(). Until now the engine total covered this up, so the old session's cost doesn't carry over.

Tests

  • resume() test: checks the cost comes back, and that a band already ahead keeps its own number.
  • New table test with two cases: a task picked up in a new process (11.62 booked, engine 0 → 0.5, row shows 12.12), and a task after /clear (engine 0.5 → 0.55, no row, row shows 0.05). Both fail on main and pass here.
  • claude plugin test .: 27 pass, 7 fail. The same 7 also fail on main on this Windows machine (bodyColumns, /ponytail band, /clear / /resume / /branch level, transcript lookup), so they're unrelated to this change.
  • node scripts/check-rule-copies.js and node scripts/check-versions.js pass.
  • I didn't run npm test (the node --test suite). It doesn't touch hooks/band/.

🤖 Generated with Claude Code

…eeps the total right

The band set a task's cost to the engine's running total. That total goes on
across /clear, so a new task started with every earlier task's cost (DietrichGebert#1343),
and it starts over in a new process, so after an IDE reload the band showed
$0.00 and the next turn wrote the smaller number over the task's ledger row.

Each turn now adds its own share (the engine total minus the baseline) to the
task, a band that starts again takes the cost back from the task's row, and
/resume or /branch to another session starts that session's own counters.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
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.

Task Cost Isolation Broken Across /clear via Nullish Coalescing Fallback

2 participants