Repository navigation
fix(pm-dispatch): run dispatched sessions in their own worktree, never the primary clone - #12214
Conversation
…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>
|
Warning Review limit reachedYou'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. View limit details
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. |
Codex Review Summary: ✅ CompletedThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
There was a problem hiding this comment.
💡 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".
| 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}`); |
There was a problem hiding this comment.
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"]); |
There was a problem hiding this comment.
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 👍 / 👎.
Before: a session launched through pm-dispatch ran in the repo's primary clone on the laptop (
~/git/codefor this repo). On Nov 21 the Scheduled Bolt and Scheduled Palette sessions branched and committed there, which left the deploy clone onpalette/add-tag-titleand 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.tsfetches origin (best effort), resolvesorigin/HEAD→origin/main→origin/master, and runsgit 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_ROOTsets the root, andoffrestores the old behaviour. The Nix wrapper now putsgiton PATH. New tests intest/worktree.test.tsuse 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
Open in [code]smith · Need help on this PR? Tag
@codesmith-botwith what you need.