Skip to content

Orchestrator never lands a finished worker's work: thread_merge #600

Closed

Description

@currentbits

Symptom

Workers finish, get archived, and their work is never merged. Measured on the live store (2026-08-20): 195 orchWorker threads, 190 finished ones still holding an unmerged worktree (0 unarchived — thread archiving works fine, the work is what never lands). At the ~709 MB median worktree that is over 100 GB of stranded commits.

Root cause

The orchestrator had no way to merge. mergeWorktree was reachable only from the renderer (git:mergeWorktree IPC / Git tab); the coder-threads MCP surface exposed fork/send/status but nothing to land a branch. The server instructions even told the lead to "merge a worker's branch when its work lands" — with no tool to do it.

Second defect found while fixing: mergeWorktree always squashed into project.path. A lead running in its own worktree (the normal case) would have had its workers' code squashed onto main, not onto the lead's branch — invisible to the lead and landed on main without review.

Fix

  • mergeWorktree({ intoPath }) — optional merge target checkout, defaults to project.path so the Git tab is unchanged. mergeInto now takes the target path instead of the project.
  • New MCP tool thread_merge({ threadId, projectId, workerThreadId }): squash-merges the worker's branch into the caller's working tree, commits, then removes the worker's worktree and branch. Guards: same project, must be a worker the caller forked, refuses while the worker is running (removing a live worker's cwd), reports "nothing to merge" for worktree:false workers. Conflicts reuse the existing replay-in-the-worktree path, so the lead can thread_send the worker to resolve and retry.
  • Worker-finished wake-up notice now names the branch and tells the lead to call thread_merge.
  • Server instructions updated: a crew you never merge produced nothing.
  • Tests: electron/test/orch-merge.test.js (4 cases, incl. lands-on-lead's-branch-not-main).

Not in scope

The ~190 already-stranded worktrees. worktreeRetention is unset on every project so enforceRetention has never run (see #563).

Activity

  1. added
    plan:doing
    plan:done
    and removed
    plan:doing
    on Aug 20, 2026
  2. currentbits commented on Aug 20, 2026

    @currentbits
    OwnerAuthor

    Landed as 11efa5d on coder/when-we-have-workers-and-they-are-done-t-ea550e.

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    plan:done

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions