Skip to content

Critical crashes and hangs with hierarchical branches & multiple adapters #135

@AnganSamadder

Description

@AnganSamadder

Description

Sidecar crashes or hangs immediately on startup when running in a repository with hierarchical branch names (e.g., feat/ui) or when multiple conversation adapters are enabled.

Symptoms

  1. Immediate Crash (Segfault or Panic):
    • panic: runtime error: invalid memory address in workspace plugin
    • fatal error: concurrent map writes in OpenCode adapter
  2. Infinite Hang:
    • Application freezes on startup "loading sessions..."
    • ps aux shows thousands of git processes (zombies or active)
  3. Resource Exhaustion:
    • syscall.forkExec failures due to file descriptor exhaustion

Root Cause Analysis

After deep investigation, we identified 5 distinct bugs contributing to this instability:

1. Worktree Path Construction Failure

Location: internal/plugins/workspace/worktree.go
Cause: When creating a worktree for a branch with slashes (e.g., feat/ui), the code used the raw branch name as the directory name.
filepath.Join(parent, "feat/ui") -> /path/to/parent/feat/ui.
Since the feat/ directory doesn't exist in the parent, the git worktree add command fails or causes internal logic to panic.

2. Concurrent Map Write in OpenCode Adapter

Location: internal/adapter/opencode/adapter.go
Cause: The sessionIndex map was being written to by multiple goroutines concurrently during parallel session loading.
Finding: This map was actually dead code—it was populated but never read.

3. Process Exhaustion in Default Branch Detection

Location: internal/plugins/workspace/diff.go
Cause: detectDefaultBranch spawns 1-3 git processes every time it's called. It is called frequently (e.g., on every update tick).
Effect: Spawns thousands of git processes per minute, exhausting file descriptors (syscall.forkExec fails).

4. Infinite Hangs (Missing Timeouts)

Locations: internal/plugins/gitstatus/tree.go, internal/plugins/conversations/plugin_loading.go
Cause:

  • git status commands can hang indefinitely on large repos.
  • Adapter Sessions() calls (e.g. Cursor) can hang indefinitely.
  • The loader waited on a WaitGroup without a timeout, causing a permanent freeze if any single adapter hung.

5. Cursor Adapter Malformed JSON Crash

Location: internal/adapter/cursor/adapter.go
Cause: json.Unmarshal panic/error when encountering malformed messages in Cursor chat history.

Fix

A comprehensive fix has been implemented in PR #136 which addresses all these issues:

  • Sanitizes worktree directory creation (ensures parent dirs exist)
  • Removes thread-unsafe dead code
  • Caches default branch detection
  • Adds timeouts to all external command execution
  • Adds defensive error handling for JSON parsing

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    Status

    Done

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions