Skip to content

OpenCode runtime drops reasoning tokens from output and cached tokens from context size #4824

Backlog

Description

@pcbeingused333

_accumulate_usage in docker/base-image/agent_server/services/opencode_runtime.py assumes tokens.reasoning is a subset of tokens.output and tokens.cache.read a subset of tokens.input. In the pinned OpenCode 1.18.32, getUsage (packages/opencode/src/session/session.ts) emits disjoint buckets: input is the input count minus cache reads and writes, and output is the output count minus reasoning.

So thinking-model turns record fewer output tokens than they used, and a turn served mostly from the prompt cache reports a much smaller context than it occupies. For example, a step with input: 0, cache: {read: 900, write: 150} does not update the context size at all. Native cost is not affected.

This was found by reading the OpenCode and runtime code, not from a live run.

Activity

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

Metadata

Metadata

Assignees

No one assigned

    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