Skip to content

fix(import): assign imported session to current project and directory#15826

Open
Juhwa-Lee1023 wants to merge 3 commits intoanomalyco:devfrom
Juhwa-Lee1023:fix/import-session-project-assignment
Open

fix(import): assign imported session to current project and directory#15826
Juhwa-Lee1023 wants to merge 3 commits intoanomalyco:devfrom
Juhwa-Lee1023:fix/import-session-project-assignment

Conversation

@Juhwa-Lee1023
Copy link
Copy Markdown

@Juhwa-Lee1023 Juhwa-Lee1023 commented Mar 3, 2026

Issue for this PR

Closes #15797

Type of change

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

What does this PR do?

opencode import runs inside bootstrap(process.cwd(), ...), which sets up the Instance context for the current directory. However, the imported session row was built entirely from the exported session data via Session.toRow(exportData.info), which preserves the original session's directory. That means the session ends up pointing at wherever it was exported from, not the current project.

Two fixes in one line each:

  1. Override directory with Instance.worktree (the resolved worktree of the current project) so the imported session is associated with the correct project directory.
  2. Add directory to the onConflictDoUpdate set so that re-importing an already-present session also updates its directory, not just project_id.

How did you verify your code works?

  • Ran the existing unit tests: bun test test/cli/import.test.ts → 4 pass, 0 fail.
  • Traced the call path: bootstrap(process.cwd(), cb)Instance.provide({ directory: process.cwd(), ... }) → inside cb, Instance.worktree resolves to the current project's worktree. Confirmed Instance.worktree is the correct field to use (it is what Session.create uses when creating new sessions in the same context).

Screenshots / recordings

N/A — no UI changes.

Checklist

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

When importing a session, override both project_id and directory with
the current project context (Instance.project.id and Instance.worktree)
instead of preserving the original session's project binding.

Also include directory in onConflictDoUpdate so that re-importing a
session correctly updates the directory to the current project.

Fixes anomalyco#15797
@github-actions github-actions bot added needs:compliance This means the issue will auto-close after 2 hours. and removed needs:compliance This means the issue will auto-close after 2 hours. labels Mar 3, 2026
@github-actions
Copy link
Copy Markdown
Contributor

github-actions bot commented Mar 3, 2026

Thanks for updating your PR! It now meets our contributing guidelines. 👍

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.

[BUG] opencode import always assigns session to global project, ignoring current working directory

1 participant