Description
Sessions with >100 messages silently return truncated data via api.state.session.messages(). Plugins (cache-hit, etc.) see incorrect statistics because the API only returns the last 100 messages.
The root cause is in packages/opencode/src/cli/cmd/tui/context/sync.tsx:
// line 559
sdk.client.session.messages({ sessionID, limit: 100 }),
// lines 580-581
const removed = infos.slice(0, -100)
const visible = infos.slice(-100)
This hardcoded window means any session exceeding 100 messages is silently truncated.
Concrete example — a real opus-4-6 session with 284 messages (234 assistant + 50 user):
|
Full (DB session table) |
API (messages(), last 100) |
Loss |
tokens_cache_read |
138,989,149 |
59,585,432 |
−57% |
tokens_input |
329 |
118 |
−64% |
tokens_output |
91,895 |
32,749 |
−64% |
cost |
$80.61 |
$31.17 |
−61% |
The cache-hit plugin correctly aggregates whatever the API returns — the data is simply incomplete.
Related issues:
Plugins
opencode-cache-hit
Steps to reproduce
- Run a long session that accumulates >100 messages
- Compare
session table aggregate (tokens_cache_read, cost) with what api.state.session.messages() returns
- Cache-hit sidebar will show ~43% of actual values
OpenCode version
1.16.0
Operating System
Linux
Description
Sessions with >100 messages silently return truncated data via
api.state.session.messages(). Plugins (cache-hit, etc.) see incorrect statistics because the API only returns the last 100 messages.The root cause is in
packages/opencode/src/cli/cmd/tui/context/sync.tsx:This hardcoded window means any session exceeding 100 messages is silently truncated.
Concrete example — a real opus-4-6 session with 284 messages (234 assistant + 50 user):
sessiontable)messages(), last 100)tokens_cache_readtokens_inputtokens_outputcostThe cache-hit plugin correctly aggregates whatever the API returns — the data is simply incomplete.
Related issues:
tokens.cache.readPlugins
opencode-cache-hit
Steps to reproduce
sessiontable aggregate (tokens_cache_read,cost) with whatapi.state.session.messages()returnsOpenCode version
1.16.0
Operating System
Linux