Skip to content

fix(opencode): use cross-platform data directory - #10362

Merged
OrcaWin merged 4 commits into
stablyai:mainfrom
OnlyYu1996:codex/issue-10332-opencode-windows-data-dir
Jul 29, 2026
Merged

OrcaWin merged 4 commits into
stablyai:mainfrom
OnlyYu1996:codex/issue-10332-opencode-windows-data-dir

Conversation

@OnlyYu1996

@OnlyYu1996 OnlyYu1996 commented Jul 24, 2026 •

Copy link
Copy Markdown
Contributor

Summary

  • Resolve OpenCode data from XDG_DATA_HOME when set, otherwise ~/.local/share/opencode on every platform.
  • Use the same data-directory contract for SQLite usage scanning and legacy Session History storage.
  • Keep relative OPENCODE_DB paths rooted in the OpenCode data directory.

Closes #10332

Screenshots

No visual change.

Testing

  • pnpm lint
  • pnpm typecheck
  • pnpm test (local full-suite run: 35,486 passed, 61 skipped, and 16 failures outside this change in PowerShell PTY, sparse-checkout, runtime-retirement, zsh lookup, and relay/SSH timing tests)
  • pnpm build
  • Added or updated high-quality tests that would catch regressions, or explained why tests were not needed

Targeted regression tests: 18 passed across the OpenCode data-directory, Session History source, and usage scanner suites.

AI Review Report

Reviewed data-directory resolution, both scanner call sites, environment precedence, relative OPENCODE_DB handling, and regression coverage. Cross-platform review confirmed the fallback uses runtime path utilities and the home directory on macOS, Linux, and Windows; explicit WSL/SSH home discovery remains unchanged. No shortcut, label, shell, or Electron-specific behavior changed.

Security Audit

Reviewed environment and path handling. Values are only used to locate local OpenCode data, with no command execution, IPC, auth, secret, dependency, or network changes. Existing filesystem error handling remains non-throwing; no follow-up is required.

Notes

  • Windows now scans %USERPROFILE%\.local\share\opencode, matching OpenCode.
  • XDG_DATA_HOME and OPENCODE_DB overrides remain supported.

ELI5

OpenCode data paths were wrong on some platforms. Orca now uses XDG_DATA_HOME or ~/.local/share/opencode everywhere so usage stats and session history find the real OpenCode database.

@coderabbitai

coderabbitai Bot commented Jul 24, 2026 •

Copy link
Copy Markdown
Contributor

Review Change Stack

Note

Reviews paused

It looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the reviews.auto_review.auto_pause_after_reviewed_commits setting.

Use the following commands to manage reviews:

  • @coderabbitai resume to resume automatic reviews.
  • @coderabbitai review to trigger a single review.

Use the checkboxes below for quick actions:

  • ▶️ Resume reviews
  • 🔍 Trigger review

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro Plus

Run ID: 301b2e7e-ccb2-4dbe-86c8-dc5b0fed1606

📥 Commits

Reviewing files that changed from the base of the PR and between c69b9e997680e9f4d630dcca7ebdb46c7208f553 and 9132871.

📒 Files selected for processing (7)
  • src/main/ai-vault/session-scanner-opencode-sources.test.ts
  • src/main/ai-vault/session-scanner-opencode-sources.ts
  • src/main/opencode-usage/scanner-windows-data-directory.test.ts
  • src/main/opencode-usage/scanner.test.ts
  • src/main/opencode-usage/scanner.ts
  • src/main/opencode/opencode-data-directory.test.ts
  • src/main/opencode/opencode-data-directory.ts
🚧 Files skipped from review as they are similar to previous changes (6)
  • src/main/opencode/opencode-data-directory.ts
  • src/main/opencode-usage/scanner.ts
  • src/main/opencode-usage/scanner.test.ts
  • src/main/opencode/opencode-data-directory.test.ts
  • src/main/ai-vault/session-scanner-opencode-sources.test.ts
  • src/main/ai-vault/session-scanner-opencode-sources.ts

📝 Walkthrough

Walkthrough

Introduces shared helpers for resolving OpenCode data and storage directories. Updates database discovery to resolve configured and scanned database paths from the shared data directory, including relative OPENCODE_DB values. Updates AI Vault session discovery to use the shared storage resolver and adds tests covering directory resolution, database path resolution, Windows path behavior, and session discovery arguments.

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly and concisely summarizes the main change: fixing OpenCode data-directory resolution cross-platform.
Description check ✅ Passed The description matches the required template and includes summary, screenshots, testing, AI review, security audit, and notes.
Linked Issues check ✅ Passed The changes address #10332 by using the cross-platform OpenCode data path on Windows while preserving override handling and adding regressions tests.
Out of Scope Changes check ✅ Passed The diff stays focused on OpenCode path resolution, scanner behavior, and targeted tests without unrelated feature changes.

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
Contributor

Choose a reason for hiding this comment

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

Actionable comments posted: 1


ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro Plus

Run ID: 23dcaf33-5346-4c70-a471-729799e37363

📥 Commits

Reviewing files that changed from the base of the PR and between 1bd36ce and 3864748a13c9e8fe592f7315f7db81a11c92339b.

📒 Files selected for processing (6)
  • src/main/ai-vault/session-scanner-opencode-sources.test.ts
  • src/main/ai-vault/session-scanner-opencode-sources.ts
  • src/main/opencode-usage/scanner.test.ts
  • src/main/opencode-usage/scanner.ts
  • src/main/opencode/opencode-data-directory.test.ts
  • src/main/opencode/opencode-data-directory.ts

Comment thread src/main/opencode-usage/scanner.ts Resolved
@itisvincent

Copy link
Copy Markdown
Contributor

reviewed and approved, please merge to master and release the fix.

thanks

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Actionable comments posted: 1


ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro Plus

Run ID: 0aa0cdde-8ff3-46d3-857c-83161ddb9f2f

📥 Commits

Reviewing files that changed from the base of the PR and between 3864748a13c9e8fe592f7315f7db81a11c92339b and 065998fa5ad1f2b8baf40e28eee3258d7bd522e8.

📒 Files selected for processing (2)
  • src/main/opencode-usage/scanner.test.ts
  • src/main/opencode-usage/scanner.ts
🚧 Files skipped from review as they are similar to previous changes (1)
  • src/main/opencode-usage/scanner.test.ts

Comment thread src/main/opencode-usage/scanner.ts Resolved
@OrcaWin

OrcaWin commented Jul 25, 2026

Copy link
Copy Markdown
Collaborator

Taking a look!

@nwparker nwparker added the bug Something isn't working label Jul 27, 2026
@OrcaWin

OrcaWin commented Jul 28, 2026

Copy link
Copy Markdown
Collaborator

Review summary for b3322640c (CI: 22/22 jobs green):

  • Approach/back-compat: sound; no migration is needed. Native OpenCode 1.17.13 and 1.18.3 both report C:\Users<user>.local\share\opencode, the real database/session exists there, and neither AppData candidate exists. This changes Orca's scanner location; it does not move OpenCode data.
  • Changes: scanner.ts:100 now accepts an OPENCODE_DB override only when it is a regular file, covered at scanner.test.ts:433. opencode-data-directory.test.ts:25 now forces win32/darwin/linux so Linux CI catches a restored Windows AppData branch. I removed the new relative-override test because it still passed against the pre-PR source and was vacuous.
  • Windows 11 runtime A/B: built and launched the Electron app against the real OpenCode database. With the fix, IPC found one native session at the cross-platform path and Agent Session History visibly rendered its OpenCode row; with the scanner sources reverted, the same app profile/database returned zero native OpenCode sessions. OpenCode also confirmed OPENCODE_CONFIG_DIR is additive: default XDG config and the extra directory were both loaded.
  • WSL runtime: native OpenCode 1.18.4 reports /root/.local/share/opencode and reads one session. Orca reached that UNC database but SQLite returned "database is locked"; WSL path handling is unchanged here, so I left this as a documented residual rather than expanding the PR.
  • Verification: 21 targeted tests, Node typecheck, targeted lint/format, max-lines ratchet, and all PR Checks passed. Source-revert controls failed the Windows-path, Session History source, in-memory DB, and directory-override cases as intended. SSH was not exercised because this local scanner change is not used by remote-session scanning.
  • CodeRabbit: the in-memory finding was already fixed; the directory-valued override is fixed in b3322640c; the latest review has no actionable comments. I declined the generic docstring-coverage warning because these small TypeScript resolvers are self-describing and repository style calls for comments only where they add non-obvious rationale.

Status: READY TO MERGE.

@greptile-apps

greptile-apps Bot commented Jul 29, 2026

Copy link
Copy Markdown

Greptile Summary

This PR centralizes OpenCode data-directory resolution into a new opencode-data-directory.ts module that consistently uses XDG_DATA_HOME when set, and falls back to ~/.local/share/opencode on every platform — removing the previous Windows-specific LOCALAPPDATA/APPDATA lookup that diverged from where OpenCode actually stores its data.

  • scanner.ts: migrates from an inline getXdgDataHome() to the shared helper, and replaces existsSync with stat().isFile() — correctly rejecting a directory path supplied via OPENCODE_DB (previously would have been passed to SQLite and failed at open time).
  • session-scanner-opencode-sources.ts: replaces the module-level OPENCODE_STORAGE_DIR constant (evaluated once at load time, and incorrectly anchored to OPENCODE_CONFIG_DIR) with a per-call resolveOpenCodeStorageDirectory().
  • Tests: seven new/updated test files cover the XDG override, all three platforms, the :memory: and directory-as-path edge cases, and an end-to-end Windows integration scenario.

Confidence Score: 5/5

The change narrows a path-resolution inconsistency and fixes a real edge case where a directory passed as OPENCODE_DB would have reached SQLite; no regressions expected.

All three callsites now use a single, well-tested helper. The existsSync → stat().isFile() replacement closes a real edge case without introducing new branches. The test suite covers all three platforms, both env-override paths, and an end-to-end Windows scenario. The intentional behavior change on Windows (dropping LOCALAPPDATA in favour of ~/.local/share) is documented and verified by integration tests.

Files Needing Attention: No files require special attention; the new opencode-data-directory.ts and its callers are straightforward and well covered by tests.

Important Files Changed

Filename Overview
src/main/opencode/opencode-data-directory.ts New module centralizing OpenCode data-directory resolution; uses XDG_DATA_HOME or ~/.local/share/opencode on all platforms; no logic issues found
src/main/opencode-usage/scanner.ts Refactored to use shared resolveOpenCodeDataDirectory(); replaced synchronous existsSync with async stat().isFile() to correctly reject directories passed as OPENCODE_DB; differentiated :memory: from unconfigured states
src/main/ai-vault/session-scanner-opencode-sources.ts Replaced module-level OPENCODE_STORAGE_DIR constant (evaluated at load time) with a call-time resolveOpenCodeStorageDirectory(); drops the incorrect OPENCODE_CONFIG_DIR fallback
src/main/opencode/opencode-data-directory.test.ts Unit tests for the new directory-resolution module; covers XDG override, all three platforms, and storage sub-directory derivation
src/main/opencode-usage/scanner-windows-data-directory.test.ts Integration test that fakes win32 platform and validates end-to-end DB discovery at ~/.local/share/opencode instead of AppData directories
src/main/opencode-usage/scanner.test.ts Added two regression tests: :memory: override returns empty list, and a directory-as-OPENCODE_DB returns empty list
src/main/ai-vault/session-scanner-opencode-sources.test.ts New test verifying that opencodeDiscoveries passes the correct XDG-derived storage directory to the discovery function

Flowchart

%%{init: {'theme': 'neutral'}}%%
flowchart TD
    A[listOpenCodeDatabases / opencodeDiscoveries] --> B[resolveOpenCodeDataDirectory]
    B --> C{XDG_DATA_HOME set?}
    C -- yes --> D[join XDG_DATA_HOME opencode]
    C -- no --> E[join homedir .local share opencode]
    D --> F[dataDirectory]
    E --> F
    F --> G[getOpenCodeDatabaseOverride]
    G --> H{OPENCODE_DB set?}
    H -- not set --> I[readdir dataDirectory for opencode files]
    H -- memory --> J[return empty]
    H -- relative path --> K[join dataDirectory OPENCODE_DB]
    H -- absolute path --> L[OPENCODE_DB as-is]
    K --> M{stat isFile?}
    L --> M
    M -- yes --> N[return path]
    M -- no or error --> J
Loading

Reviews (1): Last reviewed commit: "test(opencode): reproduce Windows sessio..." | Re-trigger Greptile

@OrcaWin
OrcaWin merged commit c6c6c71 into stablyai:main Jul 29, 2026
47 of 49 checks passed
@OnlyYu1996
OnlyYu1996 deleted the codex/issue-10332-opencode-windows-data-dir branch July 29, 2026 03:39
enrick-dev pushed a commit to enrick-dev/orca that referenced this pull request Oct 15, 2026
* fix(opencode): use cross-platform data directory

* fix(opencode): honor in-memory database override

* fix(opencode): harden database discovery coverage

* test(opencode): reproduce Windows session discovery

---------

Co-authored-by: OrcaWin <[email protected]>
Co-authored-by: OrcaWin <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: OpenCode sessions missing from Agent Session History on Windows — getXdgDataHome() returns %LOCALAPPDATA% instead of ~/.local/share

5 participants