fix(session): resolve a rekeyed project before creating a session - #48539
Open
DeputyFifeofMayberry wants to merge 1 commit into
Open
fix(session): resolve a rekeyed project before creating a session#48539DeputyFifeofMayberry wants to merge 1 commit into
DeputyFifeofMayberry wants to merge 1 commit into
Conversation
Session.createNext used the project id cached on the instance context. Another opencode process can rekey a project (git remote change) and delete the previous project row, so the session insert failed the session.project_id foreign key. Verify the cached row and re-resolve the directory when it is gone. Fixes anomalyco#42734
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 #42734
Type of change
What does this PR do?
Session.createNextused the project id cached on the instance context. When another opencode process rekeys a project (a git remote is added or changed),Project.fromDirectorymigrates rows to the new id and deletes the previous project row. The still-running instance keeps the deleted id, so the projectedsession.createdinsert fails thesession.project_idforeign key withFOREIGN KEY constraint failed.This checks that the cached project row still exists and re-resolves the session directory through
Project.fromDirectorywhen it does not, before publishing the event. The normal path is unchanged apart from one indexed lookup.How did you verify your code works?
Added a regression test in
packages/opencode/test/session/session.test.ts: it rekeys a temp git repo (adds a remote, callsfromDirectory) and then creates a session from the stale instance. Before the change the test fails with the issue's exact FK insert error; after, it passes.Also ran:
bun run typecheckinpackages/opencode(clean)bun test test/session/session.test.ts test/project/project.test.ts test/project/project-directory.test.ts test/effect/instance-state.test.ts test/server/httpapi-session.test.ts test/server/global-session-list.test.ts— 89 pass, 0 failChecklist