opencode
opencode copied to clipboard
fix: add persistent cost to prevent under-reporting spent value
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
OpenCode local
Fixes #7767 #6989