Skip to content

Isolate orchestration workers in their own git worktree - #50

Merged
currentbits merged 2 commits into
mainfrom
coder/orchestration-workers-share-the-project--a2f5ed
Aug 15, 2026
Merged

currentbits merged 2 commits into
mainfrom
coder/orchestration-workers-share-the-project--a2f5ed

Conversation

@currentbits

Copy link
Copy Markdown
Owner

Fixes #30.

Problem

thread_fork (the coder-threads MCP tool an orchestrator uses to spawn workers) copied provider, model and permissionMode from the source thread but never set up any isolation. runner.js resolves a run's cwd to thread.worktreePath || project.path, so every forked worker ran in the project checkout — N parallel workers editing one working copy. BRAINSTORM.md names this as the #1 agent disaster to prevent ("Isolation by default", "merge hell factory").

Change

thread_fork now marks the fork pendingWorktree: true alongside orchWorker: true. That reuses the existing lazy worktree path already used by threads:create — runner.materializePendingWorktree → worktrees.ensureWorktree creates the worktree + branch at first run start, so a fork that never runs still leaves nothing on disk. No new worktree machinery.

Two escape hatches, so this never turns a working fork into a failing one:

  • canHostWorktree() skips remote projects (same rule as threads:create) and directories that aren't git repos, where git worktree add would just fail the worker's run. Those forks share the project checkout exactly as before.
  • The tool accepts an optional worktree: false for workers that should deliberately run in the project checkout.

The tool description and server instructions now tell the orchestrator that workers are isolated and that a worker's branch needs merging when its work lands.

Verification

node --test electron/test/orch-server.test.js — tool-handler suite 13 pass, including a new test covering all four branches (default → pendingWorktree, worktree: false, remote project, non-repo). The 9 failures in the HTTP and provider-injection suites are pre-existing in this worktree (baseline before the change: 12 pass / 9 fail); they need @modelcontextprotocol/sdk, which isn't installed here.

Not included

Base-branch inheritance: a worker forked from a thread that is itself in a worktree branches off project HEAD, not the parent's branch. Worth adding if orchestrators routinely run inside worktrees themselves.

  • PR created by the Claude Code agent

Willem and others added 2 commits August 15, 2026 13:04
… Agents panel re-queries all threads' messages on every strea
thread_fork copied provider/model/permissionMode but never set up
isolation, so every worker edited the project checkout — N parallel
workers, one working copy. Mark the fork pendingWorktree so the runner
materializes a worktree + branch at first run, the same lazy path
threads:create uses.

Skipped when the project cannot host one (remote, or not a git repo) or
when the caller passes worktree:false, so those forks share the checkout
as before instead of failing the run.

Co-Authored-By: Claude Opus 5 <[email protected]>
@chatgpt-codex-connector

Copy link
Copy Markdown

You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard.

@currentbits
currentbits merged commit c082dbb into main Aug 15, 2026
1 check failed
@currentbits
currentbits deleted the coder/orchestration-workers-share-the-project--a2f5ed branch October 3, 2026 16:07
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.

Orchestration workers share the project checkout — no worktree isolation

1 participant