Skip to content

Cache OpenCode Go scans and discover browser sessions in Auto - #888

Merged
Finesssee merged 4 commits into
mainfrom
feat/opencodego-scan-cache
Oct 15, 2026
Merged

Finesssee merged 4 commits into
mainfrom
feat/opencodego-scan-cache

Conversation

@Finesssee

@Finesssee Finesssee commented Oct 15, 2026 •

Copy link
Copy Markdown
Collaborator

Summary

Ports upstream CodexBar v0.75.0 OpenCode Go changes (steipete#4410, steipete#4445; commits 8770f85, 976d8a0, 79b212d).

  • Local scan cache: one cached scan keyed by the opencode.db path plus size and modification time of the database and its -wal file (upstream's key). The fingerprint is checked before and after each scan, so a scan that overlaps a commit is not cached. One entry, at most 4 MiB. Errors and a missing database are never cached. The provider fetch and the cost-history scans share the cache.
  • Auto session discovery: when Auto is not scoped and there's no API result, the provider uses a stored or account cookie, or else a browser session from the shared browser order, and overlays Console quota (local+web, authoritative). If the session is rejected, the local estimate is kept. Other web errors keep the estimate and still try the Zen balance. With an API result, discovery is only used for the Zen balance (upstream). OpenCode Go now owns browser cookie resolution, so the shell no longer reads browsers every refresh.
  • Cookie source Off: the shell sets the missing-cookie flag for OpenCode Go, and the provider treats it as "no browser reads". This also fixes Off still reading browsers for the Zen balance.
  • Adding the Zen balance to a local estimate no longer resets pace_authoritative to true.

Skipped: macOS cookie cache/Keychain/Safe Storage gates (no Windows equivalent); the upstream SQLite metadata refactor (internal only).

Tests

  • cargo test --manifest-path rust/Cargo.toml: 4625 passed, 0 failed (after merging main)
  • cargo test --manifest-path apps/desktop-tauri/src-tauri/Cargo.toml: 729 passed
  • clippy -D warnings on both manifests: clean
  • New tests: scan cache hit/miss on database/WAL changes, change during scan, error and size limits, a live WAL-mode SQLite database, overlay/discovery order, Off forbids discovery (shell test).

No UI change, so no CUA proof. Live browser discovery is covered only through injectable test seams.

Summary by CodeRabbit

  • New Features
    • OpenCode Go can now reuse unchanged local usage data, helping repeated refreshes complete faster.
    • In Auto mode, Console quota can be added to local estimates using a saved or automatically discovered browser session.
  • Bug Fixes
    • When browser-cookie access is turned off, OpenCode Go no longer attempts browser-session discovery. Auto mode can still use a configured API key; otherwise, it falls back to CLI usage.

@coderabbitai

coderabbitai Bot commented Oct 15, 2026 •

Copy link
Copy Markdown

Review in Change Stack →

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration
  • Configuration used: Repository: nesszer/Win-CodexBar/.coderabbit.yaml
  • Review profile: ASSERTIVE
  • Plan: Advanced
  • Run ID: 437fb511-04b1-414c-98e7-9b9766ea9fcf
📥 Commits

Reviewing files that changed from the base of the PR and between a5cfe43 and 6c2827e.

📒 Files selected for processing: 7
  • CHANGELOG.md
  • apps/desktop-tauri/src-tauri/src/commands/providers.rs
  • apps/desktop-tauri/src-tauri/src/commands/tests.rs
  • rust/src/providers/opencodego/local.rs
  • rust/src/providers/opencodego/local/scan_cache.rs
  • rust/src/providers/opencodego/mod.rs
  • rust/src/providers/opencodego/session_overlay.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

OpenCode Go now caches local SQLite usage scans and can overlay Console quota from a stored or discovered browser session in Auto mode. Cookie-source settings control browser discovery and web-fetch behavior. Tests cover cache invalidation, session enrichment, and fetch-context selection.

Changes: OpenCode Go usage

Layer / File(s) Summary
Cache local usage scans
rust/src/providers/opencodego/local.rs, rust/src/providers/opencodego/local/scan_cache.rs
Local scans use a single-entry cache keyed by database and WAL fingerprints. Automatic fetches share the process cache; explicit-path fetches use a private cache. Tests cover reuse, invalidation, scan errors, and the payload limit.
Enrich local estimates with session quota
rust/src/providers/opencodego/mod.rs, rust/src/providers/opencodego/session_overlay.rs, CHANGELOG.md
Auto-mode local fetching can overlay Console quota from a resolved session. The provider retains the local estimate when quota enrichment does not succeed and can attach Zen balance when credits are requested.
Apply cookie-source rules
apps/desktop-tauri/src-tauri/src/commands/providers.rs, apps/desktop-tauri/src-tauri/src/commands/tests.rs, rust/src/providers/opencodego/mod.rs
Cookie source Off sets the missing-manual-cookie flag and avoids browser discovery. Web fetching returns AuthRequired when that flag is set. Tests cover Auto and Cli selection.

Priority: ➖ Normal

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

Change: Feature

Sequence Diagram(s)

sequenceDiagram
  participant OpenCodeGoProvider
  participant local
  participant ScanCache
  participant session_overlay
  participant BrowserCookieLookup
  participant Console
  OpenCodeGoProvider->>local: Fetch local usage
  local->>ScanCache: Read rows for database fingerprint
  ScanCache-->>local: Return cached or scanned rows
  OpenCodeGoProvider->>session_overlay: Enrich local estimate
  session_overlay->>BrowserCookieLookup: Resolve browser cookie when allowed
  BrowserCookieLookup-->>session_overlay: Return session cookie or no session
  session_overlay->>Console: Fetch quota when a session is available
  Console-->>session_overlay: Return quota or error
  session_overlay-->>OpenCodeGoProvider: Return enriched or retained estimate
Loading
Merge Risk: ⚪ Minimal · up to 6c282

The change adds a local scan cache and a browser-session quota overlay for OpenCode Go in Auto mode. No concrete merge-blocking issue was identified.

Caution

Pre-merge checks failed

Please resolve all errors before merging. Addressing warnings is optional.

  • Ignore

Failed Failed checks: 1 error

Check name Status Explanation Resolution
Provider Data Stays Siloed Error The pull request adds provider-specific branching in shared code. In apps/desktop-tauri/src-tauri/src/commands/providers.rs, the changed build_fetch_context match arm checks `id == ProviderId::Ope… Remove the direct ProviderId::OpenCodeGo check from shared build_fetch_context. Add a provider-owned, generic policy method to the Provider trait and implement the cookie-source-Off routing in rust/src/providers/opencodego/mod.rs; h…
Passed Passed checks: 7 passed
Check name Status Explanation
Description Check Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check Passed The title clearly and concisely summarizes the main changes: caching OpenCode Go scans and discovering browser sessions in Auto mode.
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.
Secrets Handled Safely Passed No changed production path sends a secret to a log, user error, snapshot, or plaintext file. The new logs contain only ProviderError text; the relevant browser errors are status, parsing, I/O, or fi…
No Unapproved Dependencies Passed The pull-request diff changes no Cargo.toml, package.json, npm/yarn lockfile, or pnpm lockfile. It also does not change the pinned pnpm version. Therefore, the explicit dependency and package-manager …
Ui Changes Include Windows Proof Passed The pull request changes no UI files. The authoritative diff contains only CHANGELOG.md, Tauri backend command files under src-tauri, and Rust provider files. It does not modify apps/desktop-tauri/src…
Full details: Provider Data Stays Siloed

Explanation

The pull request adds provider-specific branching in shared code. In apps/desktop-tauri/src-tauri/src/commands/providers.rs, the changed build_fetch_context match arm checks id == ProviderId::OpenCodeGo and applies OpenCode Go routing (SourceMode::Auto/Cli) and manual_cookie_missing. This file is outside rust/src/providers/<name>/ and rust/src/core/provider_factory.rs, so it matches the explicit cross-provider branching failure condition.

Resolution

Remove the direct ProviderId::OpenCodeGo check from shared build_fetch_context. Add a provider-owned, generic policy method to the Provider trait and implement the cookie-source-Off routing in rust/src/providers/opencodego/mod.rs; have shared code call that method without matching a specific ProviderId. Update the context tests to verify the generic policy.

  • Fix all pre-merge checks with AI
✨ 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.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pre-merge checks failed. Please resolve the failing checks before merging.

@Finesssee
Finesssee merged commit 34353ff into main Oct 15, 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