GeezerVison is showing github.com — fix(core): attribute migrated V1 sessions to the project of their directory by argszero · Pull Request #51935 · anomalyco/opencode
Conversation
argszero
commented
Sep 28, 2026
•
edited
Loading
Uh oh!
There was an error while loading. Please reload this page.
Issue for this PR
Closes #51176
Type of change
What does this PR do?
The V1 to V2 migration copies legacy sessions as they are, and parks a session under the global pseudo-project whenever its project_id is not in the destination project table. V1 showed sessions by directory, so those rows stayed reachable there; V2 lists sessions per project, so after the migration they disappear from the directory that owns them. The transcript is intact, only the attribution is wrong.
The runtime already knows how to re-own such a row: SessionProjector adopts a session whose project is global (or the directory's previous identity) when Worktree.Event.Resolved fires for its directory. The migration never did the same, so a session copied after its directory had already been resolved stayed under global for good.
The migration now attributes a global session to the most specific known project directory containing it, using project.worktree together with the directories in the worktree table, and stores the subpath that directory implies. A session whose directory no project owns still falls back to global exactly as before, and the existing warning for a missing project is unchanged.
A database whose migration already completed is repaired the same way on the next start, so an existing install recovers without the session move workaround from the report.
The repair only touches rows this migration parked: a row whose project was already corrected by hand is left alone, including one that stays hidden because its path was never filled in. That state is only reachable by editing the database directly, so it is a note rather than a code path — SELECT id, project_id, directory, path FROM session_v2 WHERE path IS NULL lists the rows and they need the subpath their project implies ('' at the project root; NULL does not match) or a session move.
How did you verify your code works?
packages/core/test/v1-migration.test.ts gains two cases, both going through the real migration entry point (V1Migration.run), not a helper:
- a legacy session under
global whose directory belongs to a project is attributed to that project, with the longest matching directory winning and the recorded subpath following the matched directory; a session whose directory no project owns still lands under global
- a database already at
{"phase":"completed"} with a stranded global row has that row attributed
The existing reassignment test (missing project and no owner directory, so global) passes unchanged. bun run test in packages/core: 5566 tests, the new ones pass, and the failures are the same set as on a clean checkout of this base (shell, ripgrep, watcher, and two Session.create adoption tests that need a real git environment). bun run typecheck (tsgo) and oxlint are clean.
Screenshots / recordings
Not a UI change.
Checklist
- I have tested my changes locally
- I have not included unrelated changes in this PR
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
V1 listed sessions by directory and left the ones without a registered
project under the `global` pseudo-project. V2 lists per project, so a
migrated row that keeps `global` never shows up in the directory V1 showed
it in, even though its transcript migrated intact.
The runtime already re-owns such a row once the directory's project is
known: SessionProjector adopts sessions whose project is `global` or the
directory's previous identity when Worktree.Event.Resolved fires. The
migration never applied that ownership, so a session copied after its
directory was already resolved stayed under `global` forever.
Attribute a `global` session to the most specific known project directory
containing it (project worktrees and the worktree directory table), with
the matching subpath, and keep `global` only when no project owns the
directory. Rows an earlier migration already wrote are attributed the same
way on the next start, so existing databases recover without the
session move workaround.
|
Thanks for your contribution!
This PR doesn't have a linked issue. All PRs must reference an existing issue.
Please:
- Open an issue describing the bug/feature (if one doesn't exist)
- Add
Fixes #<number> or Closes #<number> to this PR description
See CONTRIBUTING.md for details.
|
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
|
The following comment was made by an LLM, it may be inaccurate:
|
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
|
Thanks for updating your PR! It now meets our contributing guidelines. 👍
|
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
This was referenced Oct 9, 2026
This was referenced Oct 11, 2026
This was referenced Oct 12, 2026
|
Confirming this fixes the reported case on 2.0.25, plus one edge worth deciding on.
The subpath handling is correct: target === root ? "" : target.slice(root.length + 1) produces exactly what the listing expects, and a root session landing on path = "" matches the rows that already exist in git-backed projects. That value is load-bearing — I first repaired by hand with path = NULL, and the sessions stayed hidden despite having the correct project_id, because subpath='' does not match NULL.
The edge: attributeDirectories selects WHERE project_id = 'global'. An install where a user has already hand-repaired rows off global (following a workaround for this bug) no longer matches that filter, so those rows are never re-attributed and stay hidden if their path is missing or NULL. Untouched installs are repaired correctly on the next start; partially repaired ones are not.
That may not be worth handling in code, since hand-editing the database is not a supported path — but it seems like a note worth carrying wherever the workaround is documented.
Numbers if they are useful: 225 stranded rows in one non-git directory and 87 in another, in a 373-session database. After correcting project_id and path, the UI filter project=<p>&subpath= returned 112 and 39 root sessions, against 1 and 0 before.
|
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
|
Thanks for taking the time to run it on 2.0.25 — and for the numbers, they are the most useful part of this. "225 and 87 stranded rows in a 373-session database" against "1 and 0 root sessions before, 112 and 39 after" is a much better argument for the change than the test suite is.
On the edge: I agree it should not be handled in code, and I would rather not widen the repair.
attributeDirectories deliberately only touches rows this migration parked — SELECT ... FROM session_v2 WHERE project_id = 'global' AND workspace_id IS NULL. A row that a user has already moved to a real project has been claimed by that project; re-attributing it would mean rewriting rows the migration never wrote, on every start, for a state that only a hand-edited database can be in. Keying the repair on path IS NULL instead is not a safe substitute: path is nullable for V2-native sessions too (pathColumn() is not notNull, and the projector writes event.data.subpath, which is absent for a session created at the project root), so that selector would drag in rows that are perfectly correct as they are. A hand-repaired database stays hand-repaired.
For anyone reading this in the same partially-repaired state, the affected rows are the ones still hidden:
SELECT id, project_id, directory, path FROM session_v2 WHERE path IS NULL;
Those need path set to the subpath their project implies — '' at the project root, since as you found NULL does not match — or a session move for the directory, which is the supported path.
I will carry the note in the PR description so it travels with the change rather than living only here.
|
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
This was referenced Oct 13, 2026
This was referenced Oct 15, 2026
This was referenced Oct 17, 2026
|
Closing this to stay within GitHub's 3-open-pull-request limit for contributors without write access, which currently blocks every new pull request here. The branch remains on my fork, so I can reopen it on request.
|
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Assignees
No one assigned
Milestone
No milestone
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.
|