Skip to content

fix(pm-dispatch): run dispatched sessions in their own worktree, never the primary clone - #12214

Merged
dezren39 merged 1 commit into
mainfrom
claude/project-thread-fh1gl2
Nov 21, 2026
Merged

dezren39 merged 1 commit into
mainfrom
claude/project-thread-fh1gl2

Conversation

@dezren39

@dezren39 dezren39 commented Nov 21, 2026 •

Copy link
Copy Markdown
Member

Before: a session launched through pm-dispatch ran in the repo's primary clone on the laptop (~/git/code for this repo). On Nov 21 the Scheduled Bolt and Scheduled Palette sessions branched and committed there, which left the deploy clone on palette/add-tag-title and stopped pm-git-sync from pulling main.

After: every launch gets its own detached worktree at the remote default branch under ~/git/fleet/dispatch-<repo>-<task>, and the prompt tells the session that the primary clone is off limits. The primary's branch, HEAD and working tree are never touched.

How: src/worktree.ts fetches origin (best effort), resolves origin/HEAD → origin/main → origin/master, and runs git worktree add --detach. A requested subdirectory of the primary maps to the same subdirectory in the worktree. Any failure fails the launch before a session exists, so nothing falls back to the primary. PM_DISPATCH_WORKTREE_ROOT sets the root, and off restores the old behaviour. The Nix wrapper now puts git on PATH. New tests in test/worktree.test.ts use real temp repos (238/238 pass).

Worktrees are not cleaned up yet; that is a follow-up once we see how long sessions keep them.

Closes #12213


Generated by Claude Code


Get evidence
Open in [code]smith · Need help on this PR? Tag @codesmith-bot with what you need.

…r the primary clone

A dispatched OpenCode session defaulted to the repo's primary clone
(~/git/code for developing-today/code). Scheduled Bolt and Palette
sessions branched and committed there on Nov 21, leaving the deploy
clone off main and stalling pm-git-sync.

Each launch now gets a detached worktree at the remote default branch
under PM_DISPATCH_WORKTREE_ROOT (default ~/git/fleet; "off" restores
the old behaviour), and the prompt tells the session the primary clone
is off limits. A failed worktree fails the launch instead of falling
back to the primary. The package wrapper now puts git on PATH.

Closes #12213

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@coderabbitai

coderabbitai Bot commented Nov 21, 2026 •

Copy link
Copy Markdown

Warning

Review limit reached

You've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository.

Next included review available in 51 minutes.

Check out review usage here.

View limit details

Limit details: You’ve used the included review currently available.

Learn how review limits work.

Review configuration:

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: defaults
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 394e40b7-3385-4b8c-b8c6-f3ff452a1d62
Commits

Reviewing files that changed from the base of the PR and between 48c34e1 and d1979f4.

Files selected for processing: 5

  • pkgs/pm-dispatch/package.nix
  • pm-stack/dispatch/src/config.ts
  • pm-stack/dispatch/src/server.ts
  • pm-stack/dispatch/src/worktree.ts
  • pm-stack/dispatch/test/worktree.test.ts
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

Share

@dezren39
dezren39 marked this pull request as ready for review November 21, 2026 08:14
@dezren39
dezren39 requested a review from a team as a code owner November 21, 2026 08:14
@dezren39
dezren39 merged commit 34cae29 into main Nov 21, 2026
1 check passed
@dezren39
dezren39 deleted the claude/project-thread-fh1gl2 branch November 21, 2026 08:14
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 21, 2026 •

Copy link
Copy Markdown
Codex Review Summary: ✅ Completed

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-21T08:18:18.378441Z d1979f4 Draft marked ready
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: d1979f4e5b

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment on lines +205 to 207
const prefix = `[dispatch] Queue task #${task.id} · Issue ${issue ? issue.url : "none"} · Repo ${req.repo}${notice}`;
await withCreatedSession(session.id, failureContext, async () => {
await opencode.sendPrompt(session.id, `${prefix}\n\n${req.prompt}`);

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Update bundled prompts to match the new worktree context

For launches using the bundled Bolt, Palette, Suggestions, or CI-fix prompts, req.prompt still explicitly says the session is running in the primary laptop checkout and instructs it to “Work there”; Bolt and Palette additionally label those instructions as overriding conflicting guidance. Appending that unchanged prompt after the new worktree notice gives dispatched agents contradictory working-directory instructions and can direct them back into the deploy clone this change is intended to protect. Update .github/actions/pm-dispatch-task/prompts/{bolt,palette,suggestions,ci-fix}.md alongside the launch change so they consistently require working in the assigned worktree.

AGENTS.md reference: AGENTS.md:L126-L127

Useful? React with 👍 / 👎.

if (existsSync(worktree)) {
throw new WorktreeError(`dispatch worktree ${worktree} already exists; refusing to reuse it`);
}
await git(["-C", args.primary, "fetch", "--quiet", "origin"]);

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Bound the pre-launch fetch with a subprocess timeout

If the remote connection stalls during this fetch, every affected launch remains blocked before session creation: runGit awaits the output streams and proc.exited without any deadline or cancellation. Consequently, the advertised best-effort fetch never reaches its cached-ref fallback while the child remains stuck; wait:true requests cannot return a launch result, and wait:false launches leave queued tasks without sessions. Unlike the bounded outbound requests in src/fetchTimeout.ts, this newly introduced network operation has no application-level time limit. Add a timeout that terminates the child and lets the fetch failure proceed to cached-ref resolution.

Useful? React with 👍 / 👎.

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.

pm-dispatch sessions run in the primary clone and leave ~/git/code on their PR branches

2 participants