FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

fix(opencode): v2 session cause dedupe project id, this fix it. by Eric-Guo · Pull Request #30705 · anomalyco/opencode · GitHub

fix(opencode): v2 session cause dedupe project id, this fix it. - #30705

Closed
Eric-Guo wants to merge 1 commit into
anomalyco:devfrom
Eric-Guo:fix_v2_session_migrate
Closed

fix(opencode): v2 session cause dedupe project id, this fix it.#30705
Eric-Guo wants to merge 1 commit into
anomalyco:devfrom
Eric-Guo:fix_v2_session_migrate

Conversation

Eric-Guo commented Jun 4, 2026
edited
Loading

Copy link
Copy Markdown
Contributor

Issue for this PR

Closes #30701, for #30632

Type of change

  • Bug fix
  • New feature
  • Refactor / code improvement
  • Documentation

What does this PR do?

Find back the dedupe project id, after https://github.com/ShamirSecret/auto-code-machine/commit/534842dc78f049d1a15f1b851c910a33cecc65eb

How did you verify your code works?

It works on my Mac!

Checklist

  • I have tested my changes locally
  • I have not included unrelated changes in this PR

Copilot AI review requested due to automatic review settings June 4, 2026 07:34

github-actions Bot commented Jun 4, 2026

Copy link
Copy Markdown
Contributor

Hey! Your PR title Fix v2 session migrate by setting correct seq and prevent dedupe project id doesn't follow conventional commit format.

Please update it to start with one of:

  • feat: or feat(scope): new feature
  • fix: or fix(scope): bug fix
  • docs: or docs(scope): documentation changes
  • chore: or chore(scope): maintenance tasks
  • refactor: or refactor(scope): code refactoring
  • test: or test(scope): adding or updating tests

Where scope is the package name (e.g., app, desktop, opencode).

See CONTRIBUTING.md for details.

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.

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

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 project rows sharing the same worktree into 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.seq backfill 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}
`)
Eric-Guo changed the title Fix v2 session migrate by setting correct seq and prevent dedupe project id fix(opencode): v2 session migrate by setting correct seq and prevent dedupe project id Jun 4, 2026
Eric-Guo force-pushed the fix_v2_session_migrate branch from 9d49fb1 to 776b683 Compare June 4, 2026 07:39
github-actions Bot mentioned this pull request Jun 4, 2026
6 tasks
Eric-Guo force-pushed the fix_v2_session_migrate branch from 776b683 to 664025a Compare June 5, 2026 04:46
Eric-Guo changed the title fix(opencode): v2 session migrate by setting correct seq and prevent dedupe project id fix(opencode): v2 session cause dedupe project id, this fix it. Jun 5, 2026
Eric-Guo force-pushed the fix_v2_session_migrate branch from 664025a to af529b0 Compare June 6, 2026 22:07

github-actions Bot commented Jul 4, 2026

Copy link
Copy Markdown
Contributor

Automated PR Cleanup

Thank you for contributing to opencode.

Due to the high volume of PRs from users and AI agents, we periodically close older PRs using automated criteria so maintainers can focus review time on the most active and community-supported contributions.

This PR was closed because it matched the following cleanup criteria:

  • The PR was created more than 1 month ago
  • The PR had fewer than 2 positive reactions
  • Positive reactions are counted as thumbs-up, heart, celebration, or rocket reactions on the PR

PRs created within the last month are not affected by this cleanup.

If you believe this PR was closed incorrectly, or if you are still actively working on it, please leave a comment explaining why it should be reopened. A maintainer can review and reopen it if appropriate.

Thanks again for taking the time to contribute.

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

After #30632 embedded v2 session runtime and tool foundation, the DB migrate break.

2 participants


Back | FazBrowse Home | New Git URL