fix(opencode): handle stale session.directory when project moves#35492
Open
enihcam wants to merge 2 commits into
Open
fix(opencode): handle stale session.directory when project moves#35492enihcam wants to merge 2 commits into
enihcam wants to merge 2 commits into
Conversation
Fixes three related issues caused by stale session.directory values stored in the database after a project directory is moved or deleted: - anomalyco#35427: HTTP 500 from POST /session/{id}/command when session.directory points to a missing directory. SystemPrompt.environment() propagated a Die defect that bypassed the BadRequest handler. - anomalyco#33909: CLI opencode run --session <id> --dir <new-path> hangs at 'loop step=0'. The --dir flag was ignored because session loading always used session.directory from the DB. - anomalyco#23248: Sessions under project_id=global with old directory paths become orphaned when the project directory is renamed. Changes: - session/system.ts: wrap references computation in catchCause so a failing location layer (ENOENT) degrades to empty references instead of crashing - project/project.ts: add relinkStaleSessions in fromDirectory() that updates session.directory for sessions under the same project whose stored directory no longer exists on disk - handlers/session.ts: add directory existence check in requireSession that returns BadRequest for sessions with stale directories - groups/session.ts: add HttpApiError.BadRequest to share/unshare error schemas - Add regression tests in test/session/system.test.ts (catchCause), test/project/migrate-global.test.ts (relinkStaleSessions), and test/server/httpapi-session.test.ts (requireSession BadRequest)
Contributor
|
Thanks for updating your PR! It now meets our contributing guidelines. 👍 |
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 #35427
Type of change
What does this PR do?
Three bug fixes addressing the same root cause: stale session.directory in the database never updates when the project directory moves or is deleted.
Fix 1 (system.ts) — catches location layer boot failures so ENOENT degrades to empty references instead of propagating a Die defect that bypasses handler error mapping.
Fix 2 (project.ts fromDirectory) — new relinkStaleSessions helper auto-relinks sessions under the current project_id whose stored directory no longer exists on disk.
Fix 3 (handlers/session.ts requireSession) — fail-fast with 400 BadRequest when the session directory doesn't exist, instead of hanging or 500-ing downstream.
How did you verify your code works?
Screenshots / recordings
N/A — backend-only changes.
Checklist