opencode icon indicating copy to clipboard operation
opencode copied to clipboard

fix: add persistent cost to prevent under-reporting spent value

Open IdrisGit opened this issue 3 days ago • 2 comments

What does this PR do?

This PR adds a persistent cost field to sessions to fix incorrect cost reporting in the sidebar when sessions exceed 100 messages. Previously, cost was calculated from the last 100 messages only, causing under-reporting for long sessions.

Key changes:

  • Added cost field to Session schema
  • Sessions now accumulate cost incrementally when assistant messages complete
  • Sidebar reads cost directly from session metadata instead of summing messages
  • Forked sessions inherit parent's accumulated cost
  • Added startup migration to backfill existing sessions

How did you verify your code works?

Verified with before/after testing on the same long session:

  • v1.1.12: Sidebar showed $0.12 (incorrect - last 100 messages only)
  • Local build: Sidebar shows $1.61 (correct - accumulated total cost)
  • Used local build to work on an issue in the same session, cost is being accumulated correctly.
OpenCode v1.1.12
image
OpenCode local
image

Fixes #7767 #6989

IdrisGit avatar Jan 11 '26 08:01 IdrisGit