Skip to content

Fill OpenCode Go v2 local history gaps (port of upstream #4587) - #993

Merged
Finesssee merged 1 commit into
mainfrom
port/opencodego-v2-history
Oct 23, 2026
Merged

Finesssee merged 1 commit into
mainfrom
port/opencodego-v2-history

Conversation

@Finesssee

@Finesssee Finesssee commented Oct 23, 2026 •

Copy link
Copy Markdown
Collaborator

Branch: port/opencodego-v2-history
Worktree: W:\wcb-wt\p083-opencodego-v2
Commit: a780076f4 (Fill OpenCode Go v2 local history gaps)
Upstream: steipete/CodexBar b59003932 (steipete#4587)

Summary

The Windows OpenCode Go local reader (rust/src/providers/opencodego/local.rs) had three gaps that upstream closed in steipete#4587:

  1. v2-only databases failed to read. When opencode.db had no legacy message table, the reader still referenced it and the whole read failed. Such databases now read from session_message alone, with or without auth.json.
  2. Unusable legacy copies hid valid v2 requests. A v2 session_message row was dropped whenever any legacy message row had the same id, even if that legacy row had a negative or non-finite cost, or no usable timestamp. Now a v2 row is skipped only when a usable legacy copy exists (positive timestamp, finite non-negative cost). Migrated requests with a valid legacy copy still count once.
  3. Compaction requests were not counted. v2 session_message rows with type = 'compaction' now count with their request cost and tokens, alongside assistant rows.

The legacy arm is now a shared CTE (legacy_usage, NOT MATERIALIZED) that the v2 arm anti-joins against by message id. The legacy arms carry a messageID column for that join. The opencode-go provider filter, the cost and finite checks in read_rows, and the idle-WAL read-only open are unchanged. Idle-WAL handling already matched upstream (steipete#2544 path via core::open_readonly_sqlite_connection), so no change was needed there.

Behavior is unchanged for databases where every v2 row either has no legacy copy or has a usable one.

Not ported (no Windows equivalent or macOS-only): the Swift refactors (lazy minimum, month-bounds fallback, history-day clamp), the ProviderArchitectureGatekeeperTests entry, the upstream CHANGELOG line, and the macOS docs/opencode.md. The Windows docs/PROVIDERS.md OpenCode Go paragraph is updated to describe the v2 rules.

Files changed

  • rust/src/providers/opencodego/local.rs: legacy arms with messageID, shared legacy_usage CTE, usable-copy anti-join, compaction type, v2-only table detection.
  • rust/src/providers/opencodego/local/test_db.rs: insert_session_message_raw fixture helper (any type, raw or malformed payload).
  • rust/src/providers/opencodego/local/tests.rs: six new cases (below).
  • docs/PROVIDERS.md: OpenCode Go local reader paragraph.

Tests added

All use synthetic SQLite fixtures in temp directories (example model ids, no real data), mirroring upstream OpenCodeGoV2LocalUsageReaderTests.swift:

  • v2_only_database_without_message_table_reads_requests: v2-only DB, no auth.json, no message table. Upstream "reads v2 Go requests without a legacy auth file or message table".
  • legacy_copies_count_once_and_new_v2_turns_are_added (both has_parts values): migrated copies counted once, step-finish parts take precedence. Upstream "keeps legacy requests and counts migrated messages once".
  • invalid_legacy_copies_do_not_hide_valid_v2_requests (both has_legacy values): negative legacy copy does not hide the v2 request; zero-cost and malformed/unrelated v2 rows handled as upstream. Upstream "ignores malformed and unrelated v2 requests while retaining known zero costs".
  • legacy_copy_with_unusable_timestamp_does_not_hide_valid_v2_request: legacy time_created 0 with no time.created (createdMs 0). Windows-specific case for the timestamp half of the upstream fix.
  • idle_v2_wal_history_reads_without_changing_the_database_or_creating_sidecars (both has_legacy values): idle WAL, checkpointed, sidecars parked; reader does not modify the DB or create -wal/-shm. Upstream "reads idle v2 WAL history without changing the database or creating sidecars".
  • v2_compaction_requests_count_with_their_cost_and_tokens: compaction row counted with cost 2 and total tokens 3. Upstream "includes v2 Go compaction request costs".

Checks

  • cargo fmt --all: run; only the four files above changed.
  • cargo test --manifest-path rust/Cargo.toml opencodego (focused): 95 passed, 0 failed.
  • cargo test --manifest-path rust/Cargo.toml (full, after cargo build --example fake_grok_acp): 5285 passed, 0 failed, 2 ignored; plus 1 passed and 0 passed in the other targets.
  • cargo clippy --manifest-path rust/Cargo.toml --all-targets -- -D warnings: clean (exit 0).
  • Tauri manifest: not run. No shared rust type used by the Tauri crate changed.

Not done

  • CLI proof (codexbar cost --provider opencodego on a synthetic DB): not run. The planned fixture script was blocked by the delete guard (its Python os.remove call). The run needs a synthetic opencode.db under a temp home, with USERPROFILE, HOME and LOCALAPPDATA pointed at that home for the CLI process only. The candidate paths in local.rs::candidate_paths read those variables.
  • CHANGELOG entry not added (Windows changelog batches are handled separately).
  • Query performance on large histories not measured.
  • The new tests were reasoned, not run against pre-fix code. The two upstream-derived cases that exercise the anti-join (invalid legacy copies, unusable timestamp) would hide the v2 row under the old NOT EXISTS (SELECT 1 FROM message ...) predicate.

Suggested desktop proof data (synthetic)

Write %TEMP%\p083-proof-home\.local\share\opencode\opencode.db with timestamps within the last few hours:

  • message table: m_legacy (opencode-go assistant, cost 1.5), m_migrated (cost 2.0), m_bad (cost -4).
  • session_message table: m_migrated assistant (cost 2.0, same id, dedupe), m_bad assistant (cost 3.0, kept), v2_new assistant (cost 2.5), c1 compaction (cost 1.0), other assistant with providerID other-provider (ignored), u1 user (ignored).

Expected local total: 1.5 + 2.0 + 3.0 + 2.5 + 1.0 = 10.0 USD over 5 requests. Point the app at it with USERPROFILE set to %TEMP%\p083-proof-home in the launch environment, and confirm the OpenCode Go local estimate is non-zero and no provider other than opencodego shows these rows.

Summary by CodeRabbit

  • New Features
    • Usage reporting now supports OpenCode Go v2 session history, including assistant requests and compaction activity.
    • OpenCode Go usage can be read from v2-only databases, including those without authentication data.
  • Bug Fixes
    • Migrated history is counted once when valid legacy and v2 records overlap, while v2 usage remains available when legacy data is incomplete or invalid.
    • Improved handling of step-finish costs and malformed or unrelated history records.

@coderabbitai

coderabbitai Bot commented Oct 23, 2026 •

Copy link
Copy Markdown

Review in Change Stack →

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration
📥 Commits

Reviewing files that changed from the base of the PR and between 96d5531 and a780076.

📒 Files selected for processing: 4
  • docs/PROVIDERS.md
  • rust/src/providers/opencodego/local.rs
  • rust/src/providers/opencodego/local/test_db.rs
  • rust/src/providers/opencodego/local/tests.rs

Included review availability: This review used your included allowance. Your plan provides up to 4 included reviews per hour; 3 remain after this review.

📝 Walkthrough

The OpenCode Go local SQLite reader now reads legacy messages and v2 session messages, including compaction records. It handles migrated duplicates and legacy cost precedence. Tests and provider documentation cover the updated behavior.

Changes: OpenCode Go local usage

Layer / File(s) Summary
Read and merge legacy and v2 records
rust/src/providers/opencodego/local.rs
The reader handles databases with either or both message tables. It includes message IDs in legacy results, applies part-based cost precedence, and filters duplicate v2 records using legacy timestamps and costs.
Validate and document v2 history
rust/src/providers/opencodego/local/test_db.rs, rust/src/providers/opencodego/local/tests.rs, docs/PROVIDERS.md
Tests cover v2-only reads, migrated copies, filtering, WAL behavior, and compaction usage. The provider documentation describes supported records and duplicate handling.

Priority: ➖ Normal

Estimated code review effort: 3 (Moderate) | ~20 minutes

Change: Bug fix

Merge Risk: ⚪ Minimal · up to a7800

No merge-blocking issue was established; the change is ready for normal merge checks.

Pre-merge checks: Passed 8
Check name Status Explanation
Description Check Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check Passed The title uses a short imperative summary and clearly describes the OpenCode Go v2 local history changes.
Linked Issues check Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check Passed Check skipped because no linked issues were found for this pull request.
Provider Data Stays Siloed Passed The pull request changes only rust/src/providers/opencodego/ and provider documentation. The reader filters legacy and v2 rows to opencode-go within the allowed provider-specific directory and rea…
Secrets Handled Safely Passed The pull request adds only SQLite query logic, synthetic test fixtures, and documentation. The changed reader extracts timestamps, costs, model IDs, and token counts; it does not log or return auth va…
No Unapproved Dependencies Passed The pull request changes only documentation and Rust source/test files. It does not modify any Cargo.toml or package.json, add an npm/yarn lockfile, or change a pinned pnpm packageManager version.
Ui Changes Include Windows Proof Passed PASS: The pull request changes only OpenCode Go provider code, tests, and documentation. It does not change files under apps/desktop-tauri/src, rust/src/tray, the float bar, settings, or window ch…
Full details: Provider Data Stays Siloed

Explanation

The pull request changes only rust/src/providers/opencodego/ and provider documentation. The reader filters legacy and v2 rows to opencode-go within the allowed provider-specific directory and reads only usage fields such as cost, model, and tokens. It adds no identity, plan, account label, or email transfer, logging, persistence, or payload behavior. No shared code outside the allowed paths changes provider-specific branching.

Full details: Secrets Handled Safely

Explanation

The pull request adds only SQLite query logic, synthetic test fixtures, and documentation. The changed reader extracts timestamps, costs, model IDs, and token counts; it does not log or return auth values. No tracing, println, console logging, credential-bearing error, snapshot, or credential-file/keyring overwrite was introduced. Test fixtures use non-secret placeholders and temporary files only.

Full details: Ui Changes Include Windows Proof

Explanation

PASS: The pull request changes only OpenCode Go provider code, tests, and documentation. It does not change files under apps/desktop-tauri/src, rust/src/tray, the float bar, settings, or window chrome. Therefore the Windows proof requirement does not apply.

✨ Finishing Touches
📝 Generate docstrings
  • Commit to this branch
  • Create a new PR
🧪 Generate unit tests (beta)
  • Commit to this branch
  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@Finesssee

Copy link
Copy Markdown
Collaborator Author

@coderabbitai review

@coderabbitai

coderabbitai Bot commented Oct 23, 2026 •

Copy link
Copy Markdown
⚠️ Action not completed

Review rate limited.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

@Finesssee

Copy link
Copy Markdown
Collaborator Author

@coderabbitai review

@coderabbitai

coderabbitai Bot commented Oct 23, 2026 •

Copy link
Copy Markdown
✅ Action performed

Review finished.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

@Finesssee
Finesssee merged commit d14ae1c into main Oct 23, 2026
4 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant