Skip to content

Serve subagent worktrees from one auto session, with a reviewer pool - #33

Merged
leonlee merged 4 commits into
mainfrom
feature/serve-worktrees
Nov 6, 2026
Merged

leonlee merged 4 commits into
mainfrom
feature/serve-worktrees

Conversation

@leonlee

@leonlee leonlee commented Nov 6, 2026

Copy link
Copy Markdown
Owner

An auto author can now delegate separate PRs to subagents in their own git worktrees, and each subagent runs its own review loop through the session's reviewer. Up to N reviews run at once.

pair start --as claude --serve-worktrees --reviewers 2

How it works

  • Opt-in: without --serve-worktrees, behavior is unchanged from 0.8.1.
  • Routing: the author's environment carries PAIR_AUTO_OWNER, which subagents inherit, so a subagent's pair send reaches the session's socket, the only one a Claude author's sandbox allows.
  • Enrollment happens on a worktree's first request, after validation:
    • the canonical top of a worktree of the same repository, listed by git worktree list;
    • no manual Codex session registered there;
    • its auto socket claimed (which keeps pair start and pair reset out);
    • the requested message is the pending one.
  • Queue: one FIFO across all worktrees, the session's own included, with at most one entry per worktree. Retries and disconnects attach to the existing entry. --reviewers N (1–8, default 1) runs up to N at once.
  • Identity: a worktree's path, inode and resolved git directory are re-checked at request, launch, every heartbeat while running, completion and retry. A removed or replaced worktree fails alone, and its reviewer is stopped.
  • Per worktree: failures, settings snapshots and reviewer sessions. pair reviewer --thread current works from a served worktree, and pair status there names the serving session. The root's resume record never changes from a subagent.
  • No writes into served worktrees: the reviewer's rules come in its prompt, and instruction refresh and pair init advice are skipped there.
  • Compatibility: no message-format change. A request without a root, from an older CLI, means the session's own worktree.

Review

  • Design: brainstorms 1887a1, 33039d and 86f267 (a session pool, not a global daemon).
  • Spec: docs/specs/serve-worktrees.md, approved in thread 399fea after 3 medium fixes.
  • Implementation: approved in 2dd5eb after 1 medium fix (identity must compare the current --absolute-git-dir).
  • Status follow-up: approved in a539d4.

Tests

npm test: 129 pass, 10 of them new:

  • opt-in off;
  • a scoped subagent loop with no writes (a stale tracked AGENTS.md stays byte-identical);
  • FIFO with N=1 and N=2;
  • retries, simultaneous first contact, and an older client;
  • per-worktree failure and its correction;
  • a worktree removed while queued or running;
  • a .git replaced while running;
  • stop, and socket cleanup when the owner is SIGKILLed;
  • enrollment refusals.

Live check (real Claude author, Codex reviewer)

  • Claude Code subagents with worktree isolation (under .claude/worktrees/agent-…) were enrolled and reviewed in their own worktrees.
  • With --reviewers 2, status showed running 2: two worktrees, two threads, two reviewer pids.
  • pair status in a subagent worktree named the serving session. It also advised pair init, which would write files there; fixed in d76d4e1.
  • Not checked live: the subagent worktrees were removed before their git status was captured. No-writes is covered by the scoped test.
  • Observed: Claude Code based the subagent worktrees on main (d4d856e), not the session's branch.

No release until the set is merged (planned as 0.9.0).

🤖 Generated with Claude Code

https://claude.ai/code/session_012Y3kg5hjT2zSZM9qUEEinM

leonlee and others added 4 commits November 6, 2026 18:46
pair start --serve-worktrees lets subagents in their own git worktrees
run review loops through the session's owner, enrolled on first
validated contact, with one FIFO and up to --reviewers N rounds at once.
Approved by Codex in thread 2026-11-06T09-43-24-681Z-399fea, after the
design brainstorms 1887a1, 33039d and 86f267.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_012Y3kg5hjT2zSZM9qUEEinM
pair start --serve-worktrees lets a subagent working in its own git
worktree of the repository run its own review loop through the
session's reviewer. The author's environment carries PAIR_AUTO_OWNER, so
a subagent's pair send reaches the session's socket. Its first request
enrolls the worktree after full validation (same repository, listed
worktree, no manual registration, its socket claimed). Rounds from every
worktree share one FIFO, and --reviewers N runs up to N at once.

Identity (path, inode, resolved git dir) is re-checked at request,
launch, every heartbeat while running, completion and retry; a removed
or replaced worktree fails alone and its reviewer is stopped. Failures,
sessions and settings are per worktree and thread, pair reviewer
--thread works from a served worktree, and nothing is written there:
the reviewer rules come with the prompt and instruction refresh is
skipped. A request without a root (an older CLI) means the session's
own worktree. Spec: docs/specs/serve-worktrees.md; reviewed by Codex in
thread 2026-11-06T13-15-24-578Z-2dd5eb.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_012Y3kg5hjT2zSZM9qUEEinM
A served subagent worktree doesn't need pair's instruction files: its
session passes the rules to its agents. pair status there now says so
instead of advising pair init, which would write files into the
subagent's PR. Found in the live check, which otherwise confirmed
enrollment, two reviewers running at once, and the child's status.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_012Y3kg5hjT2zSZM9qUEEinM
The guardian stops the whole session after 5s without a heartbeat, and
a synchronous git with a 10s timeout could block the owner that long.
Identity checks (request, launch, every heartbeat, completion, retry)
now read the worktree's .git pointer from the filesystem; enrollment
records git's --absolute-git-dir, requires the pointer to match it, and
runs its git commands asynchronously. A test delays enrollment's git by
7s while a sibling review runs: the author and the sibling survive.
Reviewed by Codex in thread 2026-11-06T13-54-12-248Z-b4be19.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_012Y3kg5hjT2zSZM9qUEEinM
@leonlee
leonlee merged commit bc9da9c into main Nov 6, 2026
2 checks passed
@leonlee
leonlee deleted the feature/serve-worktrees branch November 6, 2026 14:16
@leonlee leonlee mentioned this pull request Nov 6, 2026
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.

1 participant