Skip to content

OpenCode usage rows never pruned: OpenCode

Quick fix

Fix sync logic so the OpenCode session cursor advances despite incomplete messages, preventing historical records from being reinserted after pruning.

Error output
usage_daily_rollups numbers for historical days are 12–16× inflated vs the actual opencode.db data (double-counting, growing on every startup).

When an OpenCode session has no cursor or its cursor has expired, and scanning finds incomplete messages without `time.completed`, the `session_has_incomplete_usage` path skips cursor updates. Each later sync then rescans the entire historical session.

After `rollup_and_prune(30)` removes `proxy_request_logs` beyond the retention period, rescanning reinserts those deleted records and aggregates them again. Historical `usage_daily_rollups` therefore continue accumulating duplicates. Existing inflated rollups will not recover automatically after the cursor fix; OpenCode usage data must be rebuilt.

  1. In `src-tauri/src/services/session_usage_opencode.rs`, adjust `session_has_incomplete_usage` handling: even if a session contains incomplete messages, advance the cursor to the watermark of the fully processed portion to avoid rescanning processed history.

  2. Alternatively, advance the cursor to `session.time_updated` and rescan the session only when `session.time_updated` changes.

  3. Provide a rebuild path for affected installations: clear `opencode_session` details and corresponding rollups, then reimport from `opencode.db`.

ToolOpenCode
VersionUnknown
PlatformsLinux

(No FAQ yet)

This is an unofficial community wiki with no affiliation to the cc-switch authors or the project itself. Its content is compiled from the project's public GitHub issues. This site distributes no software.