Skip to content

feat(server): isolate remotely delegated tasks in worktrees - #754

Merged
lastobelus merged 6 commits into
lastcode/mainfrom
lastcode/remote-delegate-worktrees
Nov 19, 2026
Merged

lastobelus merged 6 commits into
lastcode/mainfrom
lastcode/remote-delegate-worktrees

Conversation

@lastobelus

@lastobelus lastobelus commented Nov 19, 2026 •

Copy link
Copy Markdown
Owner

Part of #751

What changes

  • Base commit. The child starts at the exact HEAD of the initiating checkout, whether that is the parent thread’s worktree or the project root. Uncommitted edits stay out. With an explicit destination project, the source checkout can lack a Git remote.
  • Fetching. The destination uses only its project’s configured Git remotes. If a remote refuses the object ID but advertises a branch that contains it, the destination fetches the branch and verifies that it contains the pinned commit. The child still starts at the pin.
  • Failure. When the commit is unavailable, the task fails before the provider starts and tells the caller to push the branch or omit isolation. There is no fallback checkout. A fetch timeout gives a retry message.
  • Capability. The destination must report features.remoteWorktreeIsolationVersion: 1. An older peer refuses isolation before creating a thread. The source also checks that the prepared delegation confirms the exact commit before activating it.
  • Ownership. Activation records the run and schedules the existing worktree preparation. Git fetches run outside the peer request. The destination thread owns the checkout, and existing cleanup and subagent suspension rules apply. Setup honors the destination project's blocking or asynchronous configuration.
  • Project selection. Automatic selection still matches repository identity and refuses missing or ambiguous matches. Callers can select a destination project explicitly.

Verification

  • Quick CI passed at a557612845747a4833b532abc1d2a038f21f15e4. Server typechecking, targeted lint, 38 focused helper and integration tests, and both context-budget tests passed for the refactor. After rebasing over the thread-ownership changes on main, 17 focused suspension, helper, and budget tests passed. The tool context increase remains 142 bytes.
  • Real Git fixtures verified an exact checkout, an absent commit, and a detached commit reachable through an advertised non-default branch. The isolated two-environment MCP fixtures covered the older-peer refusal, explicit targeting from a source without a remote, and completion or preparation failure on the owned-task path.
  • Relay endpoint resolution and cloud authorization passed in 18 fixture tests. A preparation test held the destination fetch for 101 simulated seconds after scheduling, beyond the relay idle limit. Tunnel routing uses the same authenticated peer MCP path. Deployed relay and tunnel runs were not exercised.
  • The trimmed tool text scored 2/3 on remote worktree guidance, up from 0/3 on the old tool text. One sample invented a baseRef argument. The shared-checkout control and local worktree delegation case each passed 3/3. The full run with the earlier wording scored 91% across 594 samples, with both remote delegation cases passing 2/2.
  • The serialized MCP tool list grew from 84,660 to 84,802 bytes (+142) after removing duplicated guidance. The growth covers the exact-commit field and the capability and isolation rules.

Local review: 4 rounds Terra xhigh; churn-gate substituted by one confirming round (judge model unavailable)

The confirming round verified the four earlier fixes. Its setup-script finding describes the existing asynchronous mode shared by local and remote tasks. The existing test explicitly checks that this mode releases the provider while its setup script is running.

One additional Terra xhigh round approved the fork-owned refactor.

Upstream-owned files

Parent HEAD resolution and destination validation now live in remoteWorktreeDelegation.ts. Activation mode is selected by a pure function in remoteOwnership.ts. Destination validation checks conflicting launch options before dispatch, then checks Scratch after project selection so it preserves accepted-launch replay. New helper tests are fork-owned.

Line counts compare the PR with its LastCode base. Ownership is checked against origin/main.

File Lines changed
apps/server/src/git/GitWorkflowService.ts +13 / −0
apps/server/src/mcp/OrchestratorMcpService.ts +6 / −0
apps/server/src/mcp/toolkits/project/handlers.ts +13 / −0
apps/server/src/mcp/toolkits/project/tools.ts +3 / −0
apps/server/src/orchestration-v2/Orchestrator.ts +11 / −4
apps/server/src/orchestration-v2/ThreadLaunchService.test.ts +95 / −0
apps/server/src/orchestration-v2/ThreadLaunchService.ts +19 / −3
apps/server/src/peer/RemoteDelegation.test.ts +97 / −28
apps/server/src/peer/RemoteDelegation.ts +24 / −11
apps/server/src/provider/agentContextBudget.json +1 / −1
apps/server/src/vcs/GitVcsDriverCore.ts +1 / −1
evals/README.md +1 / −1
evals/mcp-tool-use/cases/orchestration.ndjson +2 / −0
packages/contracts/src/orchestrationV2.ts +7 / −0
packages/contracts/src/orchestratorMcp.ts +2 / −1

Follow-up

Consider using an already-present commit when a destination Git remote is unreachable. An unconditional local lookup could also accept a commit that the remote no longer serves, so this PR keeps the publication check.

Built by GPT-6.2 Sol in Codex.

@lastobelus
lastobelus marked this pull request as ready for review November 19, 2026 22:29
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 19, 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-19T23:42:10.619436Z a557612 Manual request
ℹ️ 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.

@lastobelus

Copy link
Copy Markdown
Owner Author

@codex review

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. What shall we delve into next?

Reviewed commit: 67bfab714d

ℹ️ 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".

@lastobelus

Copy link
Copy Markdown
Owner Author

@codex review

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. More of your lovely PRs please.

Reviewed commit: 89907b9c94

ℹ️ 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".

@lastobelus

Copy link
Copy Markdown
Owner Author

@codex review

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. What shall we delve into next?

Reviewed commit: 43321c6adc

ℹ️ 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".

@lastobelus lastobelus added the agent-context-increase Intentional agent context growth approved by a maintainer label Nov 19, 2026
@lastobelus
lastobelus force-pushed the lastcode/remote-delegate-worktrees branch from 43321c6 to 02c3d85 Compare November 19, 2026 23:03
@lastobelus

Copy link
Copy Markdown
Owner Author

@codex review

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Bravo.

Reviewed commit: 02c3d852de

ℹ️ 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".

Remote tasks that need a separate checkout previously had to launch a top-level thread. Fetch the parent commit on the destination and prepare the worktree before starting the owned task.

Built by GPT-6.2 Sol in Codex.

Carry-Group: incubator
Carry-Fix: #751
Carry-Observation: Keep the wire capability, durable launch intent, worktree preparation, and its tests together.
Some Git servers refuse requests for older object IDs. Fetch the initiating branch when needed, verify it contains the pinned commit, and use the normal worktree fetch timeout.

Built by GPT-6.2 Sol in Codex.

Carry-Group: incubator
Carry-Fix: #751
Run fetches in the destination’s owned preparation run so an idle peer request cannot lose the checkout. Find a containing published branch for a detached base that the remote refuses to serve by object ID.

Built by GPT-6.2 Sol in Codex.

Carry-Group: incubator
Carry-Fix: #751
A source checkout can have a published HEAD without its own Git remote. Resolve HEAD on the source and leave fetchability to the explicitly selected destination.

Built by GPT-6.2 Sol in Codex.

Carry-Group: incubator
Carry-Fix: #751
Keep the remote worktree requirement in the isolation field and put recovery guidance in the refusal. Regenerate the tool budget.

Built by GPT-6.2 Sol in Codex.

Carry-Group: incubator
Carry-Fix: #751
Resolve the parent HEAD, validate the new destination, and choose the activation mode in fork-owned helpers. Keep the existing preparation and failure order.

Built by GPT-6.2 Sol in Codex.

Carry-Group: incubator
Carry-Fix: #751
@lastobelus
lastobelus force-pushed the lastcode/remote-delegate-worktrees branch from 02c3d85 to a557612 Compare November 19, 2026 23:39
@lastobelus

Copy link
Copy Markdown
Owner Author

@codex review

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Bravo.

Reviewed commit: a557612845

ℹ️ 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".

@lastobelus
lastobelus merged commit 3ed52aa into lastcode/main Nov 19, 2026
32 checks passed
@lastobelus
lastobelus deleted the lastcode/remote-delegate-worktrees branch November 19, 2026 23:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

agent-context-increase Intentional agent context growth approved by a maintainer

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant