fix(opencode): v2 session migrate by setting correct seq and prevent dedupe project id#30705
Open
Eric-Guo wants to merge 2 commits into
Open
fix(opencode): v2 session migrate by setting correct seq and prevent dedupe project id#30705Eric-Guo wants to merge 2 commits into
Eric-Guo wants to merge 2 commits into
Conversation
Contributor
|
Hey! Your PR title Please update it to start with one of:
Where See CONTRIBUTING.md for details. |
Contributor
There was a problem hiding this comment.
Pull request overview
Note
Copilot was unable to run its full agentic suite in this review.
This PR improves project ID/worktree deduplication and makes the session_message.seq migration resilient when durable event rows are missing.
Changes:
- Add logic to migrate data from multiple
projectrows sharing the sameworktreeinto the canonical project ID. - Add a new DB migration to dedupe projects with identical worktrees and update related tables (
session,workspace,project_directory). - Update the
session_message.seqbackfill to fall back to projected ordering when durable events are absent; update tests accordingly.
Reviewed changes
Copilot reviewed 8 out of 8 changed files in this pull request and generated 3 comments.
Show a summary per file
| File | Description |
|---|---|
| packages/opencode/test/project/project.test.ts | Adds a live test asserting worktree-based project ID migration also rewrites project_directory. |
| packages/opencode/src/project/project.ts | Adds runtime worktree dedupe migration logic and migrates project_directory rows during project ID migration. |
| packages/core/test/database-migration.test.ts | Updates projection-order migration test semantics and adds coverage for worktree dedupe migration. |
| packages/core/src/database/migration/20260604120000_dedupe_project_worktrees.ts | Introduces a migration to canonicalize duplicate worktree projects and rewire dependent rows. |
| packages/core/src/database/migration/20260603040000_session_message_projection_order.ts | Changes backfill strategy to use durable event seq when available, otherwise derive an order from projections. |
| packages/core/src/database/migration.gen.ts | Registers the new dedupe-worktrees migration. |
| packages/core/migration/20260604120000_dedupe_project_worktrees/migration.sql | SQL artifact for the new worktree dedupe migration. |
| packages/core/migration/20260603040000_session_message_projection_order/migration.sql | Updates SQL artifact for the new seq backfill behavior. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Comment on lines
1
to
+17
| ALTER TABLE `session_message` ADD `seq` integer NOT NULL;--> statement-breakpoint | ||
| UPDATE `session_message` | ||
| SET `seq` = COALESCE( | ||
| (SELECT `seq` FROM `event` WHERE `event`.`id` = `session_message`.`id`), | ||
| ( | ||
| SELECT COUNT(*) - 1 | ||
| FROM `session_message` AS `ordered` | ||
| WHERE `ordered`.`session_id` = `session_message`.`session_id` | ||
| AND ( | ||
| `ordered`.`time_created` < `session_message`.`time_created` | ||
| OR ( | ||
| `ordered`.`time_created` = `session_message`.`time_created` | ||
| AND `ordered`.`id` <= `session_message`.`id` | ||
| ) | ||
| ) | ||
| ) | ||
| );--> statement-breakpoint |
Comment on lines
+10
to
+25
| `UPDATE \`session_message\` | ||
| SET \`seq\` = COALESCE( | ||
| (SELECT \`seq\` FROM \`event\` WHERE \`event\`.\`id\` = \`session_message\`.\`id\`), | ||
| ( | ||
| SELECT COUNT(*) - 1 | ||
| FROM \`session_message\` AS \`ordered\` | ||
| WHERE \`ordered\`.\`session_id\` = \`session_message\`.\`session_id\` | ||
| AND ( | ||
| \`ordered\`.\`time_created\` < \`session_message\`.\`time_created\` | ||
| OR ( | ||
| \`ordered\`.\`time_created\` = \`session_message\`.\`time_created\` | ||
| AND \`ordered\`.\`id\` <= \`session_message\`.\`id\` | ||
| ) | ||
| ) | ||
| ) | ||
| );`, |
Comment on lines
+212
to
+221
| yield* d.run(sql` | ||
| INSERT OR IGNORE INTO project_directory (project_id, directory, type, time_created) | ||
| SELECT | ||
| ${newID}, | ||
| directory, | ||
| type, | ||
| time_created | ||
| FROM project_directory | ||
| WHERE project_id = ${oldID} | ||
| `) |
9d49fb1 to
776b683
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Issue for this PR
Closes #30701, for #30632
Type of change
What does this PR do?
Fix session_message seq order and prevent dedupe project id by worktree introduced at #30632
How did you verify your code works?
It works on my Mac!
Checklist