anomalyco / anomalyco/opencode
Native context auto-compaction never fires (session_context_epoch always 0), causing runaway token/credit consumption on GitHub Copilot
@kitlangton is already working on this.
Since Aug 26, 2026.
- Dominant language
- TypeScript
- Stars
- 209k
- Forks
- 27.5k
- PR merge metrics
- PR metrics pending
Description
Description
opencode version(s) affected: 1.18.18, 1.18.20, 1.18.21 (possibly the entire ≥1.18.15 range)
Provider / model: GitHub Copilot (github-copilot), claude-sonnet-5
OS: Windows
Third-party plugins: none (specifically, no @tarquinen/opencode-dcp — see "Relation to other issues" below)
Summary
Over 6 days of a single long-running session (multiple subagents, normal tool-call usage), opencode's native context auto-compaction never fired even once. Because the transcript was never compacted, every assistant call resent the full accumulated context, and token/credit consumption grew at a near-quadratic rate until the entire monthly GitHub Copilot credit quota was exhausted.
- Session lifetime: 2026-08-19 09:51 UTC → 2026-08-25 07:33 UTC (~6 days)
- Total messages: 516 (437 assistant / 79 user)
- Cumulative tokens: ~212M (
tokens_cache_read+tokens_cache_write+tokens_inputon the session row) - Peak single day (Aug 21): ~148.5M tokens across 253 assistant messages
session_context_epochrows for this session: 0, for the entire lifetime- Provider returned
Payment Requiredon 2026-08-24 at 12:24:51 and 12:27:02 UTC - The only 3
agent=compactionlog lines in the whole session occurred after those errors (15:57–15:59 UTC that same day), and even then no compaction checkpoint was ever recorded
Why this isn't already-known / already-fixed
- Not #8030 (
X-Initiatorpremium-request misclassification) — that was fixed in 1.4.7, long before the versions used here (1.18.18-1.18.21). - Related to #43764 (DCP compress cosmetic,
session_context_epochstuck at 0) but not the same root cause: that issue's repro depends on the@tarquinen/opencode-dcpplugin. This environment has no such plugin installed (verified: nodcp/tarquinenreferences in either the project or globalopencode.json), and the same "compaction inert" symptom still reproduces. This suggests native compaction itself is broken independently of that plugin, or shares an underlying root cause with #43764 that isn't plugin-specific.
Steps to reproduce
- Use opencode ≥1.18.15 with default compaction settings (no
compaction/autocompactoverride, no compaction-related plugins). - Configure
github-copilotprovider with a premium model (e.g.claude-sonnet-5). - Run one continuous session across several days with multiple subagents/tool calls, accumulating hundreds of messages, without restarting the session.
- Query the local
opencode.db:
→ staysSELECT count(*) FROM session_context_epoch WHERE session_id='<id>';0indefinitely regardless of how largetokens_cache_readgrows on thesessionrow. - Per-message
tokens.cache.read(see attached growth-curve CSV) grows monotonically with no drop-off — the signature of compaction never actually shrinking the resent context.
Impact
- Full monthly credit quota exhausted under a usage pattern (one long session, multiple subagents) that is common and not a misuse of the tool.
- No warning before the quota ran out — compaction fails silently, and opencode's own local cost estimate (
session.cost≈ $102) does not reflect the real quota impact on the provider side.
Evidence (attached)
01-tokens-per-day.csv— all-sessions daily token aggregation, showing the Aug 21 peak.02-sessions-epochs.csv— every local session, all withcontext_epochs=0.03-token-growth-incident-session.csv— per-message token growth for the affected session (attach as file).04-relevant-log-errors-and-events.txt— ERROR lines,Payment Requiredtimestamps, and the only 3compactionlog lines (attach as file).- Environment/version details below.
01-tokens-per-day.csv
day,msgs,total_tokens,input_tokens,output_tokens,reasoning_tokens,cache_read_tokens,cache_write_tokens
2026-07-23,17,450393,107376,2176,971,339870,0
2026-08-07,8,150138,18993,873,787,129485,0
2026-08-13,5,173494,36739,1062,618,135075,0
2026-08-19,114,8186886,359936,77487,6416,6646538,1096509
2026-08-20,102,26087543,204,106660,0,21198409,4782270
2026-08-21,253,148523952,504,197776,0,137869008,10456664
2026-08-24,57,28662368,1053054,46707,6797,18859349,8696461
2026-08-25,20,1157815,270800,2428,3051,881536,0
02-sessions-epochs.csv (all local sessions — context_epochs is 0 for every one)
session_id,agent,tokens_cache_read,tokens_cache_write,tokens_input,cost,context_epochs,msgs,time_created,time_updated
ses_fe690b97dffe3SprdtbN3Gu6ZL,gentle-orchestrator,180881631,24823651,1258757,102.03251409999994,0,516,1787133118082,1787643218265
ses_fe513908cffeHL7FyHCotpO2i3,general,951861,50786,48,0.4327832,0,25,1787158097780,1787158313669
ses_fcb7eceb1ffeOmCNrIeVLrhMjl,general,679936,0,80530,0.0,0,14,1787587277135,1787587634852
ses_fe6900a43ffeAx0UwXhdDEQbuO,general,602429,0,73145,0.40627679999999994,0,14,1787133162940,1787133335809
ses_fdf8e9140ffeQPv05H9KFJV02e,general,598196,70844,26,0.5321912,0,14,1787250699967,1787250965816
ses_fe64d8e7fffet6kNA4xitK9X3y,general,551943,0,65928,0.36612659999999997,0,13,1787137520000,1787137720118
ses_fc82cf1aafferjYRwuJseZYEJz,gentle-orchestrator,457600,0,160506,0.0,0,17,1787642973781,1787647364498
ses_fe68d3f5bffex0SECtQgYuudct,general,362630,0,43398,0.22608999999999999,0,11,1787133345956,1787133436426
ses_fdb91296affeTpmG368HiitWCx,gentle-orchestrator,278644,55617,10,0.2159413,0,6,1787317638805,1787317680529
ses_07148f9a6ffe9bsrikB74TcfLm,gentle-orchestrator,182894,0,85228,0.343307875,0,9,1784805787225,1784808008678
ses_071785f30ffeURXLyGsmADP6fc,build,156976,0,22148,0.12438275,0,13,1784802681040,1784803048714
ses_0046eda82ffeMOLmLxcii7Z9Br,gentle-orchestrator,135075,0,36739,0.139015,0,9,1786632021373,1786632317060
ses_023be63ebffepRE9NhAnlVbGwI,build,129485,0,18993,0.0932875,0,12,1786106715156,1786107106608
ses_fe50ff0ccffe9810xOYvh8PSda,review-resilience,57278,31006,6,0.1700026,0,4,1787158335283,1787158434313
ses_fe641d688ffeUyLX68ggtZ1y9R,general,32692,0,2144,0.0157594,0,4,1787138287991,1787138299842
Environment / version history
OS: Windows
Terminal: PowerShell 7 / Windows Terminal
Third-party compaction plugins: none installed (no "dcp"/"tarquinen" in project or global opencode.json)
opencode version by date (from `message=created ... version=` in the log):
2026-07-23 -> 1.18.4
2026-08-07 -> 1.18.15
2026-08-13 -> 1.18.18
2026-08-19 -> 1.18.18 (incident session created)
2026-08-21 -> 1.18.20
2026-08-24 -> 1.18.21
2026-08-25 -> 1.18.21
Provider/model used in the incident session:
github-copilot / claude-sonnet-5 (400 of 437 assistant messages)
github-copilot / gpt-5.6-terra (18 messages)
openai / gpt-5.6-terra (19 messages, agent=compaction — only compaction attempts,
all on Aug 24, after quota exhaustion)
Compaction config: no `compaction`/`autocompact` key in project or global opencode.json (defaults in effect).
Request to maintainers
- Confirm whether native auto-compaction has a defect (race condition, miscalculated trigger threshold, etc.) preventing it from firing on long sessions with
github-copilot/claude-sonnet-5, in the ≥1.18.15 range. - Clarify the relationship with #43764 — same root cause, or independent?
- Consider a visible warning (TUI/cost counter) when a session crosses a context-size threshold without ever compacting, instead of failing silently until the provider returns
Payment Required.
Full report with SQL queries and the causal-mechanism writeup: see the linked local report (available on request / in the reporting repo's issues/opencode-compaction-bug-report/ folder).
Plugins
https://github.com/Gentleman-Programming/gentle-ai
OpenCode version
1.18.18 - 1.18.21
Steps to reproduce
No response
Screenshot and/or share link
No response
Operating System
Windows 11
Terminal
not sure: opencode vscode extension
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Assessment
This issue has not been assessed yet.