Skip to content

Sidebar USD spend decreases after compaction or revert #25023

Closed as not planned
Closed as not planned

Description

@lucaaamaral

Description

The "$X.XX spent" figure in the TUI sidebar drops after a context compaction event, and again after a revert + new prompt. Compute spend isn't reversible, once paid to the LLM provider, it can't be unspent, so the displayed figure should be monotonic.

The cost stored on each assistant message in the DB is correct. The TUI bug is in how the figure is summed: it reduces over the visible message cache (capped at 100). After compaction the new summary turn pushes older paid messages out of the window, so the total drops even though spend hasn't changed. Hard-revert (revert.cleanup deleting messages from the DB before a new prompt) reproduces the same drop.

Aditional Information

I have a working fix locally and can send a PR if this approach is welcome: add a monotonic cost column on the session record, server-bumped per LLM step (and rolled up the parentID chain so sub-agent spend lands on the parent), with a one-time backfill from existing message costs on first read. The TUI then reads session.cost instead of summing over the visible message cache.

Happy to discuss the shape before opening the PR.

Plugins

No response

OpenCode version

1.14.29

Steps to reproduce

  1. Open a session in the TUI that has accumulated >$0 spend across more than 100 messages, OR a session that's about to auto-compact.
  2. Note the sidebar "$X.XX spent" figure.
  3. Trigger /compact (or let auto-compaction fire).
  4. Watch the sidebar figure — it drops, sometimes near half.

For the revert variant:

  1. In a session with >$0 spend, revert to an earlier message.
  2. Send a new prompt (forces revert.cleanup, which hard-deletes the reverted assistant turns from the DB).
  3. The sidebar figure drops by the cost of the deleted turns.

Screenshot and/or share link

No response

Operating System

Ubuntu 24.04 (Linux 6.8.0)

Terminal

Konsole

Activity

  1. added
    coreAnything pertaining to core functionality of the application (opencode server stuff)
    on Apr 30, 2026
  2. removed
    bugSomething isn't working
    coreAnything pertaining to core functionality of the application (opencode server stuff)
    on May 3, 2026
  3. github-actions commented on Jul 3, 2026

    @github-actions
    Contributor

    To stay organized issues are automatically closed after 60 days of no activity. If the issue is still relevant please open a new one.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions