Skip to content

Conversation

@AnganSamadder
Copy link

@AnganSamadder AnganSamadder commented Feb 11, 2026

Summary

Fixes #135

Resolves a series of critical crashes and hangs when working in repositories with hierarchical branch names (e.g., feat/ui, fix/bug-123) and multiple conversation adapters.

This PR addresses multiple root causes discovered during deep investigation:

  1. Worktree Crash: When creating worktrees for branches with slashes (e.g. feat/ui), sidecar attempted to create a directory .../feat/ui without ensuring the parent feat/ directory existed, causing a crash.
  2. OpenCode Adapter Crash (Concurrent Map Write): The OpenCode adapter had a sessionIndex map that was written to concurrently by multiple goroutines during parallel loading. This map was actually dead code (never read), so I removed it to fix the race condition.
  3. Process Exhaustion: detectDefaultBranch was spawning new git processes on every update tick without caching, leading to syscall.forkExec errors (file descriptor exhaustion) in active repositories.
  4. Infinite Hangs:
    • git status commands could hang indefinitely on large repos/slow disks.
    • Conversation adapters (like Cursor) could hang indefinitely during Sessions() loading, causing the app to freeze on startup.
  5. Adapter Crash: The Cursor adapter would crash if it encountered malformed JSON in chat history files.

Changes

  • internal/plugins/workspace/worktree.go: Use os.MkdirAll to ensure parent directories exist when creating worktrees for hierarchical branches.
  • internal/adapter/opencode/adapter.go: Removed unused sessionIndex map that was causing fatal error: concurrent map writes.
  • internal/plugins/workspace/diff.go: Added simple in-memory caching to detectDefaultBranch to prevent spawning thousands of git processes.
  • internal/plugins/gitstatus/tree.go: Added 10s timeout to git status commands.
  • internal/plugins/conversations/plugin_loading.go: Added timeouts (5s per worktree, 30s total) to adapter loading to prevent infinite startup hangs.
  • internal/adapter/cursor/adapter.go: Added defensive JSON parsing to skip malformed messages instead of crashing.

Testing

Verified manually in a repository with:

  • Multiple hierarchical branches (feat/a, fix/b)
  • Large commit history
  • Cursor chat history present
  • OpenCode adapter enabled

Before this fix, sidecar would crash immediately on startup (either segfault or concurrent map write). After these fixes, it launches successfully and handles all branch operations correctly.

…tory paths

When creating worktrees for branches with slashes (e.g., feat/ui), the directory
name would contain slashes which created invalid filesystem paths. This caused
crashes when sidecar tried to create worktree directories.

Replace slashes with hyphens in directory names while keeping branch names intact
for git operations.

Fixes marcus#135
1. Fix worktree creation for branches with slashes (e.g. feat/ui) by ensuring parent directories exist
2. Fix process exhaustion in default branch detection by caching results
3. Fix concurrent map write crash in OpenCode adapter by removing dead code (sessionIndex)
4. Add timeouts to git status commands to prevent infinite hangs
5. Add timeouts to conversation adapter loading to prevent startup hangs
6. Skip malformed JSON in cursor adapter instead of crashing
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.

Critical crashes and hangs with hierarchical branches & multiple adapters

1 participant