Repository navigation
v0.7.1
v0.7.1 — Session-state lifecycle: cursor/watermark correctness
Fixes a usage-accounting edge where a pruned or reverted message history could cause prompt-cache usage to be double-counted after the message id cursor reset behind an already-counted message.
Changes:
- The
lastProcessedAttime watermark is now an absolute "already processed" floor applied on every scan path. Previously it was only applied when the cursor id was missing, so a revert that reset the id cursor behind a counted message re-counted history on restore. - Minimal, backward-compatible change in
src/cache-usage-core.mjs; no provider behaviour, request mutation, cache identity, TTL, telemetry schema, or public export changed. - Conservative by design: a same-millisecond timestamp tie now undercounts rather than double-counting.
Documentation
- Implementation plan §2B.9 records the full session-state lifecycle contract: state ownership/lifetime (in-memory, per-session, not persisted), message selection/ordering, cursor advancement (non-transactional; normal-scan duplicate prevention vs. no durable exactly-once), pruned/reverted handling, missing/incomplete data, and idempotency/concurrency — plus the remaining unknowns.
Tests (+3; suite 281 → 284)
- Table-driven watermark-floor cases (tie skipped; below-watermark skipped; no-watermark → position decides; missing cursor + no watermark → nothing).
- Composed cursor+watermark prune/revert/restore lifecycle (each message counted exactly once; watermark monotonic).
- Adapter-level
session.idlerevert/restore probe (no duplicate usage record; forward progress recovers).
Detailed changelog:
- fix(usage): apply the time watermark floor on the located-cursor path
- test: cover the v0.7.1 cursor/watermark revert-restore lifecycle
- docs: record the v0.7.1 session-state lifecycle contract
Full Changelog: v0.7.0...v0.7.1
Provider-aware prompt-cache optimization and observability for OpenCode.
opencode-cache-engine is an OpenCode npm plugin with two targets:
- Server target — the actual cache-engine runtime and provider policies.
- TUI target — registration with OpenCode's TUI plugin manager.
CacheEngine is an OpenCode plugin designed for long-running agent sessions where prompt-cache efficiency affects both latency and cost. It keeps the harness conservative for providers whose cache behavior is already automatic, while applying provider-specific optimizations where the provider exposes useful cache controls or where prompt structure can be safely improved.
The plugin currently has eleven cache-policy families:
- DeepSeek — passive cache observability; request structure is preserved.
- GPT-5.6 and later — documented cache-key/options metadata, with prompt text unchanged. GPT-6 and future 5.6+/6+/7+ versions resolve through the same documented boundary.
- GLM-5.3 and later — GLM implicit-cache baseline and diagnostics; GLM-5.3 additionally uses a narrow, content-preserving
<env>relocation overlay. - MiMo V2.6 and later — MiMo implicit-cache baseline and diagnostics; MiMo V2.6 Flash/Pro additionally use a narrow content-preserving
<env>relocation overlay. - Kimi — passive Moonshot/Kimi implicit-cache observability; the request is left unchanged. The Anthropic-compatible
cache_controlroute is not implemented. - Claude (Anthropic) — passive classification and accounting; the request is left unchanged because OpenCode itself applies Anthropic
cache_controlbreakpoints. - Google Gemini — passive classification and accounting; Gemini 2.5+ provider-managed implicit caching is left untouched. CacheEngine creates no
CachedContentresources and injects no Gemini cache-control field. - Alibaba Qwen — passive classification and accounting; Qwen's provider-managed implicit caching is left untouched on every route. CacheEngine places no explicit block-level cache_control marker and adds no affinity, because the V1 hook cannot reach message content blocks and OpenCode already applies breakpoints on the Qwen Messages routes.
- xAI Grok — passive classification and accounting. Grok caching is automatic on all Grok language models, and direct xAI already receives a stable conversation affinity key from OpenCode itself, so CacheEngine injects no header or key and rewrites nothing.
- Meta Muse — passive classification and accounting. Muse caching is automatic positional prefix caching; Meta's
prompt_cache_keymust be an application-stable routing hint (never per-session) andprompt_cache_retentionis a request-level policy, so CacheEngine injects neither and rewrites nothing. - MiniMax — passive classification and accounting, route-aware. MiniMax caching is automatic; M2.x additionally supports explicit Anthropic
cache_control(M3 does not), but OpenCode already owns those breakpoints on the Anthropic-compatible routes, so CacheEngine injects nothing.
Initial models were personally chosen for their performance in max programming task completed per dollar. More models can be added based on newer releases or updates.
Future releases will be based on newer versions of models from the above providers, as well as any model that performs optimally over the Pareto distribution on OpenRouter as well as on personal discretion. Since cache stability policy doesn't change much for the providers, there's no need for a code rebase.
Quick Installation (TUI):
opencode plugin opencode-cache-engine --global
Best complemented with agents for the particular models configured at AlexJoaquimPereira/opencode-agent-config