Repository navigation
fix(ai-vault): handle live OpenCode database contention - #15671
brennanb2025 wants to merge 3 commits into
Conversation
Agent Session History opened the user's opencode.db in place, so a live writer made the scan fail immediately as "database is locked" and skip the transcript. Snapshot the db+WAL instead of waiting, and surface a retryable unavailable notice when even the snapshot cannot be read. Supersedes #14134. Fixes #14133. STA-4078. Co-authored-by: Bing.Z <zzb@gxsmjx.com>
📝 WalkthroughWalkthroughThe change adds a shared live SQLite read-only opener with lock detection, snapshot fallback, cleanup, and error classification. OpenCode, Hermes, Codex, and usage scanners now use this opener. SQLite availability failures become standardized notice issues. Session parsing uses centralized issue conversion. Shared scan-state helpers use a local view type. Mobile history displays notices and skipped-transcript details through a dedicated banner component. Tests cover locking, recovery, cleanup, classification, and presentation state. 🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✨ Finishing Touches 💡 1📝 Generate docstrings 💡
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. Comment |
There was a problem hiding this comment.
Actionable comments posted: 3
ℹ️ Review info
⚙️ Run configuration
Configuration used: Repository UI
Review profile: CHILL
Plan: Pro Plus
Run ID: e6067501-f825-4861-b3a0-4d21ff6d7c0e
📒 Files selected for processing (17)
config/tsconfig.cli.jsonmobile/src/agent-history/MobileAgentSessionHistoryPanel.tsxmobile/src/agent-history/mobile-agent-history-scan-banners.tsxsrc/main/ai-vault/session-scan-issues.test.tssrc/main/ai-vault/session-scan-issues.tssrc/main/ai-vault/session-scanner-opencode-sqlite-list.tssrc/main/ai-vault/session-scanner-opencode-sqlite-lock.test.tssrc/main/ai-vault/session-scanner-opencode-sqlite.tssrc/main/ai-vault/session-scanner.tssrc/main/automations/hermes-cron-output.tssrc/main/codex/codex-state-db.tssrc/main/opencode-usage/scanner.tssrc/main/sqlite/live-sqlite-readonly.test.tssrc/main/sqlite/live-sqlite-readonly.tssrc/renderer/src/components/right-sidebar/AiVaultScanIssueBanners.tsxsrc/shared/ai-vault-scan-issue-state.test.tssrc/shared/ai-vault-scan-issue-state.ts
Included review availability: Your plan provides up to 10 included reviews per hour; 0 remain after this review.
A named node:fs import binds at module evaluation, so every suite that partially mocks fs failed the moment this module entered its graph - 33 CI shards that never touch sqlite. A namespace import defers resolution to call time. Also reverts the Hermes cron reader to its previous direct open: that path is a sibling of this fix, not part of it, and routing it through the snapshot broke its test because the suite mocks sync-database rather than creating a real state.db.
|
Revised this from scratch around the safe SQLite concurrency boundary. What changed:
Acceptance non-vacuity was re-proven by setting the production timeout to zero: After restoring the implementation, that file passed 2/2. Final verification: 6 affected test files passed 50/50 tests; |
|
OpenCode history reads now wait briefly for database contention, close safely, and report a retryable source notice, with further bounds in #25292. This earlier implementation can be closed. |
…ripts (#38626) * Show source scan notices accurately in mobile Agent History Reuse the existing desktop presentation policy in shared code, keep host failures and source notices separate from skipped transcript files, and retain their scanner-authored messages. Adapted from the remaining mobile presentation in original PR #15671. Rebased onto main: the classifier now lives in src/shared/ai-vault/scanning/, desktop keeps its translated skip reasons, and mobile reuses its existing skipped-transcript notice. Co-authored-by: Brennan Benson <79079362+brennanb2025@users.noreply.github.com> * refactor(ai-vault): share the scan issue row key between desktop and mobile --------- Co-authored-by: Neil <neil@stably.ai> Co-authored-by: Brennan Benson <79079362+brennanb2025@users.noreply.github.com>
ELI5
OpenCode normally lets Orca read session history while OpenCode is writing, but a brief exclusive database lock could make Orca fail immediately and show
database is locked. Agent Session History now waits for that short lock in its background scanner. If a lock outlives the five-second bound, Orca shows a temporary-unavailability notice and retries on the next scan instead of reporting a skipped transcript or risking an inconsistent file copy.What Changed
query_only, a first-read probe, and deterministic handle cleanup.kind: 'notice'scan issue with no raw SQLite lock text.Why
OpenCode uses WAL mode, where ordinary readers and writers coexist. A bounded busy timeout handles exceptional short lock transitions without blocking the UI because these reads run in the session-scanner worker. A genuinely persistent whole-file lock cannot be read safely through an ad hoc filesystem copy, so the accurate fallback is a retryable notice rather than stale, corrupt, or uncommitted session data.
This revision adopts the bounded read-only design also proposed in #14134 while retaining this PR's retryable notice behavior and desktop/mobile classification. #14134 can be closed once this lands.
Linked Issue
Fixes #14133
STA-4078
Visual Proof
N/A — the behavioral change is background SQLite contention handling plus scanner-authored banner classification. The Windows reporter box remains unavailable, so real-Windows reproduction is still pending.
Testing
Actual local platform: macOS, Node 26.5.0.
session-scanner-opencode-sqlite-lock.test.tsfailed 2/2. Listing returned the temporary-unavailability notice, and parsing threwdatabase is locked.pnpm typecheck— passed.node config/scripts/check-changed-code-quality.mjs— passed with 0 findings.node config/scripts/check-react-doctor-changed.mjs— passed with 0 issues.AI Disclosure
Codex implemented and verified the revision after independent plan reviews.
Review
query_only; Orca never checkpoints, copies, deletes, or mutates the user's database or sidecars.kind: 'notice'.Agent skill upstream boundary
docs/reference/agent-skill-sharing-upstream-boundary.mdand copies or mechanically translates no upstream skill-installer source, tests, fixtures, registry entries, path tables, comments, or documentation.Checklist
N/Awith reasonpnpm lint,pnpm typecheck,pnpm test, andpnpm buildpass (or CI will cover; local preferred)Targeted tests, changed-code quality, React Doctor, and typecheck pass; full test/build remain for CI.
Author