Skip to content

[BUG] Negative amount of tokens used in session #15293

Closed as not planned
Closed as not planned

Description

@old-mikser

Description

There is an issue in sessions index.ts where there is a possibility to get negative amount of tokens, as code assumes that input tokens have cached in it. And if cached amount is more than input amount - we got negative. Nothing prevents it.

This can cause issues on analytics tools which are using sessions data assuming tokens always positive.

Plugins

superpowers, DCP

OpenCode version

1.2.15

Steps to reproduce

I faced it with minimax-m2.5 on nanoGPT I believe, if you want to reproduce. At least according to my agent ;) As I used 4 different models within that session, and not completely sure.

Screenshot and/or share link

No response

Operating System

WSL (ubuntu 20.04)

Terminal

No response

Activity

  1. added
    coreAnything pertaining to core functionality of the application (opencode server stuff)
    on Feb 26, 2026
  2. github-actions commented on Feb 26, 2026

    @github-actions
    Contributor

    This issue might be a duplicate of existing issues. Please check:

  3. rothnic commented on Apr 2, 2026

    @rothnic

    Adding one more confirming data point from a separate investigation.

    While analyzing long delayed turns in a session tree, we also observed negative input-token values on some turns, including turns that otherwise appeared to have cache reads recorded. For example:

    Class Input tokens Cache read Result
    Primary -423 84,160 tool-calls
    Secondary -132 57,664 tool-calls

    We did not rely on those negative values semantically, but they made the cache / token evidence harder to interpret. This seems consistent with the accounting bug described here rather than with a literal negative prompt size.

    Related issue with the fuller anonymized slowdown/cache analysis: #20565

  4. assigned and unassigned on Apr 26, 2026
  5. removed
    bugSomething isn't working
    coreAnything pertaining to core functionality of the application (opencode server stuff)
    on May 3, 2026
  6. 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