Skip to content

fix(core): 'opencode run' hangs indefinitely on 'project copy refresh started' due to unhandled child process close in GitWorktree.list #55037

Closed as not planned

Description

@Steven0917

Summary

When executing opencode run "<message>" inside a Git repository (Linux, OpenCode v1.19.0), the process hangs indefinitely immediately following:

message="project copy refresh started" projectID=...

The prompt is never dispatched to the LLM agent (message=process is never scheduled), and the CLI never exits or makes forward progress.

Inspection reveals that the OpenCode process is stuck in kernel futex_wait_queue, leaving a zombie process [git] <defunct> under its process tree.


Environment

  • OpenCode Version: 1.19.0 (Linux x86_64 ELF binary compiled with Bun)
  • OS: Linux 6.6.137+
  • Command Executed:
    opencode run "hi" --pure --print-logs --log-level DEBUG

Root Cause & Decompiled Trace

  1. Reproduction & Comparison:

    • In a non-git directory or fresh empty directory where projectID=global, ProjectCopy.refresh executes in 1ms:
      message="project copy refresh started" projectID=global
      message="project copy refresh done" projectID=global updated=[] removed=[]
      
      The session immediately proceeds and MiniMax-M3 responds within seconds.
    • Inside an existing Git repository with tracked worktrees or registered projects, opencode.db (project_directory table) contains the repository root with strategy = NULL.
  2. Trigger Path in OpenCode (packages/core/src/project/copy.ts & copy-strategies.ts):

    • During Location Services initialization, ProjectCopy.refresh filters for directories where strategy === undefined:
      J = Y.filter((V) => V.strategy === void 0 && V.exists).map((V) => V.directory)
    • For each directory, it invokes registered strategies (GitWorktree.list):
      ProjectCopy.GitWorktree.list -> Git.worktree.list(repo)
    • Git.worktree.list invokes:
      git worktree list --porcelain
      via AppProcess (v1.make("git", ["worktree", "list", "--porcelain"], { cwd, extendEnv: true, stdin: "ignore" })).
  3. Process Hang & Defunct Child:
    Checking the process tree during the freeze:

    steven  480021  0.6  1.9  ...  opencode run hi --pure --print-logs --log-level DEBUG
    steven  480158  480021  0  ...  [git] <defunct>
    

    /proc/480021/wchan reveals:

    futex_wait_queue
    

    The git child process finished execution immediately, but in Bun's node:child_process wrapper / stream handler, the parent process did not reap the child or resolve the promise waiting for 'close' / stream EOF.

    Because Git.worktree.list hangs indefinitely, ProjectCopy.refresh never resolves, Location Services boot never finishes, and the user prompt dispatch loop (message=process) is never scheduled.


Related Issues


Suggested Fixes

  1. Subprocess Timeout: Add a strict timeout (e.g. 5–10s) to Git.worktree.list and all AppProcess invocations so that a stalling child process or unhandled close event does not permanently deadlock the CLI boot sequence.
  2. Proper Child Process Reaping: Ensure Bun's child process handler correctly listens for exit / close and calls waitpid / drains stdout pipes even when detached: true or stdin is "ignore".
  3. Non-blocking Refresh: Run ProjectCopy.refresh out-of-band without gating interactive CLI message execution if no worktree copies are actively requested.

Activity

  1. opencode-agent commented on Oct 13, 2026

    @opencode-agent
    Contributor

    Thanks for the detailed trace, @Steven0917.

    This is about OpenCode 1.19.0, which is v1. Development has moved to OpenCode 2.x, and v1 now only gets fixes for critical bugs, so this is unlikely to be fixed in v1.

    The code path you traced (ProjectCopy.refresh → GitWorktree.list) no longer exists in v2: project copies and the copy-strategy registry were replaced by a separate worktree service. Please try upgrading to v2 (opencode upgrade --major, notes: https://anoma.ly/notes/opencode-2-0) and see whether opencode run still hangs.

    The same v1 hang (zombie git child, log stopping at project copy refresh started) was reported before:

    If it also happens on v2, or you think this is critical in v1, please reply here with your opencode --version and the log output, and we'll take another look.

  2. opencode-agent commented on Oct 14, 2026

    @opencode-agent
    Contributor

    Closing this as not planned. It was reported against OpenCode 1.19.0 (v1), which only gets critical fixes, and we haven't heard back about whether it also happens on v2. In v2 the ProjectCopy / GitWorktree.list startup path has been replaced by a separate worktree service.

    If opencode run still hangs after upgrading (opencode upgrade --major), please open a new issue with your 2.x opencode --version and the --print-logs output. Thanks again for the detailed trace.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions