[PR #13645] fix(app): prevent crash when opening files instead of directories #14752

Open
opened 2026-02-16 18:19:31 -05:00 by yindo · 0 comments
Owner

Original Pull Request: https://github.com/anomalyco/opencode/pull/13645

State: open
Merged: No


What does this PR do?

Added guard in server.projects.open() to prevent saving undefined directory, which was causing corrupt entries with shape {expanded: true} but no worktree.

Added migration effect that auto-cleans existing corrupt data on startup by filtering out projects without worktree property from all origins.

This fixes crashes from:

  • TypeError: undefined is not an object (evaluating 'projects.map')
  • TypeError: undefined is not an object (evaluating 'dir.slice')

Added comprehensive tests for migration logic and guard behavior.

If you paste a large clearly AI generated description here your PR may be IGNORED or CLOSED!

How did you verify your code works?

My local development environment was completely broken—every app launch crashed with TypeError: undefined is not an object (evaluating 'projects.map') and TypeError: undefined is not an object (evaluating 'dir.slice'). The corruption persisted across cache clears because it was stored in localStorage, not Vite's cache.

I systematically debugged by:

  1. Adding logging to trace where undefined was coming from
  2. Discovering corrupt entries {expanded: true} without worktree in opencode.global.dat
  3. Identifying the root cause: server.projects.open(undefined) when opening files instead of directories
  4. Implementing the guard and migration fix

Verification: After applying the fix, my app finally launched successfully without crashes. The auto-migration cleaned the existing corrupt data on startup, and the guard prevented new corruption. Once the fix was confirmed working, I added comprehensive tests to prevent regression.

Closes #13642

**Original Pull Request:** https://github.com/anomalyco/opencode/pull/13645 **State:** open **Merged:** No --- ### What does this PR do? Added guard in server.projects.open() to prevent saving undefined directory, which was causing corrupt entries with shape {expanded: true} but no worktree. Added migration effect that auto-cleans existing corrupt data on startup by filtering out projects without worktree property from all origins. This fixes crashes from: - TypeError: undefined is not an object (evaluating 'projects.map') - TypeError: undefined is not an object (evaluating 'dir.slice') Added comprehensive tests for migration logic and guard behavior. **If you paste a large clearly AI generated description here your PR may be IGNORED or CLOSED!** ### How did you verify your code works? My local development environment was completely broken—every app launch crashed with TypeError: undefined is not an object (evaluating 'projects.map') and TypeError: undefined is not an object (evaluating 'dir.slice'). The corruption persisted across cache clears because it was stored in localStorage, not Vite's cache. I systematically debugged by: 1. Adding logging to trace where undefined was coming from 2. Discovering corrupt entries {expanded: true} without worktree in opencode.global.dat 3. Identifying the root cause: server.projects.open(undefined) when opening files instead of directories 4. Implementing the guard and migration fix Verification: After applying the fix, my app finally launched successfully without crashes. The auto-migration cleaned the existing corrupt data on startup, and the guard prevented new corruption. Once the fix was confirmed working, I added comprehensive tests to prevent regression. Closes #13642
yindo added the pull-request label 2026-02-16 18:19:31 -05:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: anomalyco/opencode#14752