Skip to content

fix(opencode): canonicalize sqlite path identity - #29641

Closed
Hona wants to merge 6 commits into
anomalyco:devfrom
Hona:fix/path-normalization-db
Closed

Hona wants to merge 6 commits into
anomalyco:devfrom
Hona:fix/path-normalization-db

Conversation

@Hona

@Hona Hona commented May 28, 2026 •

Copy link
Copy Markdown
Member
  • Fixes Windows sessions sometimes not being returned in web/desktop due path slash/case mismatches.
  • Store Windows DB paths as C:/x/y, not C:\x\y.
  • Return native paths to app code.
  • Query paths with Windows-tolerant slash/case matching.
  • Migrate existing SQLite path fields.
  • Normalize persisted sync event path payloads too.
  • Split helpers by use:
    • storage: writes/migration
    • query: SQL filters
    • native: row-to-app output
  • Added tests for migration, filters, legacy rows, and sync event replay.

@Hona
Hona requested a review from adamdotdevin as a code owner May 28, 2026 01:03
Copilot AI review requested due to automatic review settings May 28, 2026 01:03

Copilot AI 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.

Pull request overview

This PR standardizes how SQLite path identity is stored and compared (especially on Windows) by introducing a canonical “storage path” format and a migration to rewrite existing rows, while ensuring APIs return native absolute paths at row boundaries. It also updates session filtering logic to use the new canonical path comparisons and adds targeted Windows-focused tests, plus a few small app-side UI/state tweaks.

Changes:

  • Add PathIdentity utilities and apply them across project/session/workspace persistence, session list filtering, and worktree canonicalization.
  • Add a data migration (normalize_paths_to_forward_slashes) to rewrite existing DB rows (including embedded event JSON fields) into the canonical storage format.
  • Add/adjust tests for Windows path matching + migration behavior, and refine app global-sync loading status plus a helper for v2 new-session layout gating.

Reviewed changes

Copilot reviewed 19 out of 19 changed files in this pull request and generated 3 comments.

Show a summary per file
File Description
packages/opencode/test/storage/path-normalization-migration.test.ts New test validating Windows path normalization migration rewrites persisted rows correctly.
packages/opencode/test/server/session-list.test.ts Adds Windows-specific session.list filtering tests for canonical directory/path matching.
packages/opencode/src/worktree/index.ts Switches worktree path canonicalization/comparison to PathIdentity keys.
packages/opencode/src/v2/session.ts Normalizes path output and uses PathIdentity SQL helpers for directory/path filters.
packages/opencode/src/util/path-identity.ts Introduces canonical path normalization + SQL comparison helpers.
packages/opencode/src/session/session.ts Uses PathIdentity at row boundaries and for list filters (directory/path).
packages/opencode/src/session/projectors.ts Ensures projector writes persist normalized storage paths.
packages/opencode/src/server/routes/instance/httpapi/handlers/v2/session.ts Makes cursor mismatch detection use canonical path identity keys.
packages/opencode/src/project/project.ts Normalizes persisted worktree/sandboxes and compares sandboxes via canonical keys.
packages/opencode/src/data-migration.ts Adds and wires a migration to normalize stored paths across tables and event JSON.
packages/opencode/src/control-plane/workspace.ts Normalizes workspace directory persisted/returned paths via PathIdentity.
packages/app/src/pages/session/new-session-layout.ts New helper to decide whether to use v2 new-session layout.
packages/app/src/pages/session/new-session-layout.test.ts Tests for the new v2 new-session layout gating helper.
packages/app/src/pages/session.tsx Uses the new layout gating helper instead of inline env/id logic.
packages/app/src/pages/home.tsx Refactors legacy home UI layout and removes unused state.
packages/app/src/context/global-sync/child-store.ts Initializes new child stores as loading instead of complete.
packages/app/src/context/global-sync/child-store.test.ts Updates tests to accommodate loading-first child store behavior and adds coverage.
packages/app/src/context/global-sync/bootstrap.ts Sets status to partial while bootstrapping and complete on successful bootstrap.
packages/app/src/context/global-sync/bootstrap.test.ts New test verifying loading -> partial -> complete bootstrap status transitions.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +100 to +102
Effect.gen(function* () {
const created = yield* withSession({ title: "windows-directory" })
yield* Effect.sync(() =>
Comment on lines +161 to +164
Effect.gen(function* () {
const created = yield* withSession({ title: "windows-path" })
yield* Effect.sync(() =>
Database.use((db) =>
Comment on lines +26 to +39
function realWindowsPath(value: string) {
const native = value.replaceAll("/", "\\")
try {
return normalize(realpathSync.native(native))
} catch {
const parent = path.win32.dirname(native)
if (!parent || parent === native) return value
try {
return normalize(path.win32.join(realpathSync.native(parent), path.win32.basename(native)))
} catch {
return value
}
}
}
@Hona
Hona force-pushed the fix/path-normalization-db branch from c6557e7 to a783985 Compare May 28, 2026 01:10
@Hona
Hona force-pushed the fix/path-normalization-db branch from a783985 to b6af39d Compare May 28, 2026 01:23
@Hona
Hona marked this pull request as draft May 28, 2026 02:01
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.

2 participants