Uh oh!
There was an error while loading. Please reload this page.
fix(opencode): handle stale session.directory when project moves - #35492
fix(opencode): handle stale session.directory when project moves#35492enihcam 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)
Thanks for updating your PR! It now meets our contributing guidelines. 👍 |
Automated PR Cleanup Thank you for contributing to opencode. Due to the high volume of PRs from users and AI agents, we periodically close older PRs using automated criteria so maintainers can focus review time on the most active and community-supported contributions. This PR was closed because it matched the following cleanup criteria:
PRs created within the last month are not affected by this cleanup. If you believe this PR was closed incorrectly, or if you are still actively working on it, please leave a comment explaining why it should be reopened. A maintainer can review and reopen it if appropriate. Thanks again for taking the time to contribute. |
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