Skip to content

fix(core): import previous V2 history without legacy tables - #56773

Open
zonemeen wants to merge 1 commit into
anomalyco:devfrom
zonemeen:fix/previous-v2-import
Open

zonemeen wants to merge 1 commit into
anomalyco:devfrom
zonemeen:fix/previous-v2-import

Conversation

@zonemeen

Copy link
Copy Markdown

Issue for this PR

Closes #56732

Type of change

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

What does this PR do?

Fresh databases without a legacy session table incorrectly reported migration as completed and skipped importing opencode-next.db.

Check for previous V2 sessions independently of legacy tables, and record completion after import. Only run V1 backfill and event cleanup when legacy tables exist, preserving current events during a V2-only import.

How did you verify your code works?

  • Confirmed the fresh-target regression fails before the fix.
  • Database suites: 59 tests passed on macOS; 60 passed in Docker Linux x86_64 with Bun 1.4.2.
  • Coverage includes source discovery, completion status, existing data and event preservation, idempotency, and unchanged source files.
  • bun run check passed.

Screenshots / recordings

N/A — no UI changes.

Checklist

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

@github-actions

Copy link
Copy Markdown
Contributor

The following comment was made by an LLM, it may be inaccurate:

@opencode-agent opencode-agent 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.

This fixes the skipped opencode-next.db import. I ran the reproduction from #56732: on the base, a target without legacy tables imports nothing and reports completed. With this PR, the session and message are imported and {"phase":"completed"} is written to kv. The empty-legacy-tables case still works. v1-migration and permission tests pass, and core and server type-check cleanly.

Public API: unchanged. migration.v1.status keeps the same response shape. It now reports required when there is an opencode-next.db to import, even without legacy tables.

One thing to fix: the branch also contains the unrelated commit a169e190c ("dismiss interrupted permission prompts" in permission.ts and permission.test.ts). That change is already proposed in #55977, so please drop it from this PR and keep it to the migration fix.

For maintainers: V2 users whose opencode.db has no legacy tables but who still have an opencode-next.db will get it imported once on their next start after upgrading. That is the intent of #56732, but sessions they had not seen in the current database may appear.

Comment thread packages/core/src/permission.ts Outdated
// WITH feedback (CorrectedError) intentionally stays typed so the leaf can turn
// it into ToolFailure and the model continues.
Effect.catchTag("Permission.DeclinedError", (error) => Effect.die(error)),
Effect.onInterrupt(() =>

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.

This change (and its test in permission.test.ts) comes from the separate commit a169e190c. It isn't related to the migration fix and duplicates #55977. Please remove it from this branch so each change can be reviewed on its own.

@zonemeen
zonemeen force-pushed the fix/previous-v2-import branch from 8d1c276 to ef47a71 Compare October 18, 2026 12:11

This branch has not been deployed

No deployments
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.

core: previous V2 import is skipped when a fresh target has no legacy session table

1 participant