[PR #7763] fix: add persistent cost to prevent under-reporting spent value #12506

Open
opened 2026-02-16 18:17:24 -05:00 by yindo · 0 comments
Owner

Original Pull Request: https://github.com/anomalyco/opencode/pull/7763

State: open
Merged: No


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

**Original Pull Request:** https://github.com/anomalyco/opencode/pull/7763 **State:** open **Merged:** No --- ### 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 <img width="1261" height="1390" alt="image" src="https://github.com/user-attachments/assets/cf43e852-f03a-4c83-aaff-7067b5819a64" /> ##### OpenCode local <img width="1261" height="1390" alt="image" src="https://github.com/user-attachments/assets/04b72575-6881-414f-862c-d9491b4fa92d" /> Fixes #7767 #6989
yindo added the pull-request label 2026-02-16 18:17:24 -05:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: anomalyco/opencode#12506