Skip to content

Conversation

@IdrisGit
Copy link

@IdrisGit IdrisGit commented Jan 11, 2026

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

@github-actions
Copy link
Contributor

Thanks for your contribution!

This PR doesn't have a linked issue. All PRs must reference an existing issue.

Please:

  1. Open an issue describing the bug/feature (if one doesn't exist)
  2. Add Fixes #<number> or Closes #<number> to this PR description

See CONTRIBUTING.md for details.

@github-actions
Copy link
Contributor

The following comment was made by an LLM, it may be inaccurate:

No duplicate PRs found

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.

session-cost/spent-value under reported for sessions with 100+ messages

1 participant