Skip to content

fix(opencode): enforce storage path invariants#29666

Open
Hona wants to merge 7 commits into
anomalyco:devfrom
Hona:fix/path-storage-value-object
Open

fix(opencode): enforce storage path invariants#29666
Hona wants to merge 7 commits into
anomalyco:devfrom
Hona:fix/path-storage-value-object

Conversation

@Hona
Copy link
Copy Markdown
Member

@Hona Hona commented May 28, 2026

Summary

  • add PathStorage value object for DB-stored absolute/relative path invariants
  • brand active session/project storage columns and parse DB write/query seams
  • migrate existing SQLite path rows and persisted session event JSON to forward-slash storage form

Tests

  • bun typecheck
  • bun test test/session/session-row.test.ts test/session/session-event-storage.test.ts test/storage/path-storage-migration.test.ts test/storage/json-migration.test.ts test/util/path-storage.test.ts --timeout 30000
  • bun test test/project/migrate-global.test.ts test/project/project.test.ts test/control-plane/workspace.test.ts --timeout 30000
  • bun test test/server/session-list.test.ts test/sync/index.test.ts --timeout 30000

@Hona Hona marked this pull request as ready for review May 28, 2026 05:12
Copilot AI review requested due to automatic review settings May 28, 2026 05:12
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

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 introduces a dedicated PathStorage value object to enforce invariants for paths stored in SQLite (absolute vs relative, and forward-slash normalization on Windows), and wires it through the DB read/write seams plus a data migration to normalize existing rows and persisted event JSON.

Changes:

  • Add PathStorage branded types/utilities and apply them to session/project storage columns and query filters.
  • Add a data migration to normalize existing stored paths (including event JSON payloads) into the storage form.
  • Add/adjust tests covering path invariants, row/event persistence, and migrations.

Reviewed changes

Copilot reviewed 18 out of 18 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
packages/opencode/src/util/path-storage.ts Introduces branded absolute/relative storage path helpers and platform conversion.
packages/opencode/src/project/project.sql.ts Brands project.worktree and project.sandboxes columns with PathStorage.AbsolutePath.
packages/opencode/src/session/session.sql.ts Brands session.directory and session.path columns with PathStorage types.
packages/opencode/src/project/project.ts Normalizes project worktree/sandboxes at DB write boundaries; converts storage paths back to platform form when reading.
packages/opencode/src/session/session.ts Normalizes session directory/path at DB boundaries; normalizes filters; converts storage directory back to platform form when reading.
packages/opencode/src/v2/session.ts Normalizes directory/path filters when querying sessions.
packages/opencode/src/sync/index.ts Adds persistEvent hook to normalize event payloads before persisting.
packages/opencode/src/server/projectors.ts Uses persistEvent to ensure session event payload paths conform to storage invariants.
packages/opencode/src/data-migration.ts Adds migration to normalize existing project/session rows and event JSON path fields.
packages/opencode/src/cli/cmd/import.ts Ensures imported session path is stored as a PathStorage.RelativePath.
packages/opencode/test/util/path-storage.test.ts Adds unit tests for PathStorage behavior across platforms and Windows specifics.
packages/opencode/test/storage/path-storage-migration.test.ts Adds a migration test validating Windows path normalization without alias resolution.
packages/opencode/test/storage/json-migration.test.ts Updates assertions to account for branded/converted path storage types.
packages/opencode/test/session/session-row.test.ts Verifies Session.toRow persists directory/path with storage invariants.
packages/opencode/test/session/session-event-storage.test.ts Verifies persisted session event JSON uses storage-form paths.
packages/opencode/test/project/project.test.ts Updates test setup to use PathStorage.absolute for session directory rows.
packages/opencode/test/project/migrate-global.test.ts Adjusts legacy seeding to satisfy new storage invariants.
packages/opencode/test/control-plane/workspace.test.ts Updates project insertion to store worktree as PathStorage.AbsolutePath.

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

Comment thread packages/opencode/src/v2/session.ts Outdated
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