Repository navigation
feat: add worktree isolation to spawn_agent - #108
Conversation
Assert the error message in worktree create and delete rejection cases so each case proves the guard it names instead of any 400. Move the outside root delete case beside the root so it exercises the parent directory check, and add relative path and clean detached HEAD delete cases. Add a client test for the 201 create and 204 delete success paths, which agent tests cannot reach because the agent roots worktrees at HOME.
…he created branch A post-checkout hook failure makes git worktree add exit nonzero after creating the worktree and branch, so create now discards both before answering 500. Delete requires the branch create returned, refuses worktrees whose HEAD is on another branch or detached, and deletes the branch with update-ref guarded by the tip the unpushed check covered.
…s with submodules discardWorktree now runs its git commands on a context that outlives a canceled request so a failed worktree add is still rolled back. Delete passes --force when the worktree has initialized submodules; the status check has already proven the tree clean.
…re removing a worktree A submodule with ignore=all hid its edits from the clean check, and the forced removal of a worktree with initialized submodules then deleted them.
…rmissions safe Delete now refuses worktrees whose initialized submodules hold commits not on any remote before the forced removal. Create rejects repositories that contain the worktree root, which git would happily nest inside the source tree, and creates the root with 0700 permissions.
…spawn's worktree The agent delete endpoint now requires the branch create returned.
…e a forced worktree removal git submodule foreach skips deinitialized submodules, but their repositories stay under the worktree's modules directory and --force deletes them, so count local-only commits by walking that directory.
…tree create errors
…quest deadline and widen the submodule commit check
…d before removing a worktree
…eleted branch's config
…rollback the request budget
…agent-isolation-2-spawn-worktree
…on-2-spawn-worktree # Conflicts: # coderd/apidoc/docs.go # coderd/apidoc/swagger.json # coderd/x/chatd/fork_tools.go # codersdk/fork_experiments.go # docs/reference/api/schemas.md
@codex review |
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: a79e3e51c0
ℹ️ 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".
@codex review |
@codex review |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: f4e3ccd2b3
ℹ️ 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".
…s do not share a map
@codex review |
|
Codex Review: Didn't find any major issues. More of your lovely PRs please. Reviewed commit: ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
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". |
…on-2-spawn-worktree # Conflicts: # coderd/x/chatd/fork_tools.go
…mputer use spawn overrides
@codex review |
|
Codex Review: Didn't find any major issues. Chef's kiss. Reviewed commit: ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
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". |
Closing and reopening only to make GitHub recompute the merge ref against current main ( |
The merge ref now points at current main ( |
Merge evidence for head
|
Part of #9. Builds on #81 (merged), which added the agent worktree API this PR calls.
Behind experiment
fork-subagent-isolation,spawn_agenttakes three new optional arguments:isolation:shared(default, today's behavior) orworktree.repo_path: the git repository to branch from. Defaults to the workspace agent's directory.base_branch: the branch or commit the child's branch starts from. Defaults to the repository's current HEAD.With
worktree, chatd asks the parent chat's workspace agent to create a worktree at~/.coder/worktrees/<repo>/<child chat id>on a new branchagent/<title slug>-<first 8 hex of the child chat id>, before the child chat transaction. The child'schat_subagentsrow recordsisolation,worktree_pathandbranch, and the tool result returns the same three fields. If the transaction fails, the worktree is removed again on a detached context. The child does not yet work inside its worktree; binding its working directory is the next PR.Errors reach the model as tool errors:
repo_pathorbase_branchwithoutworktree, a chat with no workspace, a computer use child, an agent with no directory and norepo_path, an agent older than the server (404, with a hint to restart the workspace or useshared), and any rejection from the agent API with its reason.With the experiment off, the tool schema and behavior are unchanged.
Size: about 300 production lines and 430 test lines; the rest is generated.
Code
coderd/x/chatd/fork_isolation.go: wrapsspawn_agent(schema, argument checks, result fields), creates and cleans up the worktree, builds the branch name.coderd/x/chatd/fork_subagents.go:createSubagentChatWithIDwrites thechat_subagentsrow for isolated spawns and removes the worktree when the transaction does not commit.codersdk/fork_experiments.go: the experiment. The remaining generated files follow from it.Tests
TestForkSpawnIsolation*run the real tool against a database with a fake agent connection: the worktree request (default directory, explicit repo and base), the row and result fields, every error above except the agent with no directory (covered by UAT), an unreachable agent, the experiment off, and worktree removal when the chat insert fails.TestForkWorktreeBranchcovers the branch name. Each was checked against a production break.UAT
Dev build on a branch server with a real workspace agent and GLM: worktree spawn (worktree at the expected path on the expected branch, parent checkout untouched, root
0700),base_branch,sharedwithrepo_path, a non-gitrepo_path, no agent directory, an unknown isolation value, and the default shared spawn. All passed; the children answered. UAT found one cosmetic issue (a doubled.:in agent errors), fixed here.