Skip to content

fix(session): resolve a rekeyed project before creating a session - #48539

Open
DeputyFifeofMayberry wants to merge 1 commit into
anomalyco:devfrom
DeputyFifeofMayberry:fix/session-create-stale-project-id
Open

fix(session): resolve a rekeyed project before creating a session#48539
DeputyFifeofMayberry wants to merge 1 commit into
anomalyco:devfrom
DeputyFifeofMayberry:fix/session-create-stale-project-id

Conversation

@DeputyFifeofMayberry

Copy link
Copy Markdown

Issue for this PR

Closes #42734

Type of change

  • Bug fix

What does this PR do?

Session.createNext used the project id cached on the instance context. When another opencode process rekeys a project (a git remote is added or changed), Project.fromDirectory migrates rows to the new id and deletes the previous project row. The still-running instance keeps the deleted id, so the projected session.created insert fails the session.project_id foreign key with FOREIGN KEY constraint failed.

This checks that the cached project row still exists and re-resolves the session directory through Project.fromDirectory when 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, calls fromDirectory) 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 typecheck in packages/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 fail

Checklist

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

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

session.create can use a deleted project ID and fail with a SQLite foreign-key error

1 participant