Repository navigation
feat(coderd/x/chatd): bind isolated subagents to their worktree - #135
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
…agent-isolation-3-child-binding
…agent-isolation-3-child-binding
…agent-isolation-3-child-binding
…s do not share a map
…agent-isolation-3-child-binding
…on-2-spawn-worktree # Conflicts: # coderd/x/chatd/fork_tools.go
…mputer use spawn overrides
…agent-isolation-3-child-binding
…on-3-child-binding # Conflicts: # coderd/x/chatd/ARCHITECTURE.md # coderd/x/chatd/fork_isolation.go # coderd/x/chatd/fork_isolation_internal_test.go # coderd/x/chatd/fork_subagents.go # coderd/x/chatd/fork_tools.go
@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: 609e4bd8cb
ℹ️ 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: Didn't find any major issues. 🚀 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 #108 (merged), which creates a worktree for
spawn_agentwithisolation: worktreebut leaves the child working in the shared checkout.With experiment
fork-subagent-isolationon, a child spawned withisolation: worktreenow works inside its worktree, and so does everyshareddescendant below it:read_file,write_file,edit_files,attach_file) resolve relative paths against the worktree, andexecuteruns there when the call names noworkdir. Absolute paths are left alone.worktreegrandchild spawned withoutrepo_pathbranches from its parent's worktree instead of the agent directory.A
sharedchild of a chat outside any worktree is unchanged. With the experiment off, nothing changes.Size: about 250 production lines and 210 test lines.
Code
coderd/x/chatd/fork_isolation_binding.go:chatWorktreefinds the worktree a chat works in (its own, or the nearest ancestor's acrosssharedlinks),worktreeBoundToolrewrites relative paths and the defaultexecutedirectory,withSubagentWorktreePromptadds the system message, andforkWorktreeAgentsets the agent directory for the workspace context.coderd/x/chatd/fork_subagents.go,fork_isolation.go,fork_tools.go,turn_environment.go: one call each into the file above.Only the bound tools treat paths in chatd, so only they needed Windows path handling. The spawn code from #108 sends
repo_path, the parent worktree and the agent directory to the agent unchanged (coderd/x/chatd/fork_isolation.go:172-206), and the agent checks and joins them with nativefilepath(agent/agentgit/fork_worktrees.go:148,:220-221).Tests
TestForkWorktreeBindingToolsruns each bound tool throughappendForkToolsagainst a recording fake. It covers relative and absolute paths for every file tool,edit_fileswith several files,executewith no, null, relative and absoluteworkdir, a tool that is not bound, the workspace context directory, and asharedchild of the root that stays unbound.TestForkWorktreeBoundToolWindowsPathscovers a Windows worktree path: relative paths join with a backslash, and drive, UNC and rooted paths stay as they are.TestForkWorktreeBindingPromptcovers a worktree child's own system message, asharedgrandchild that inherits the worktree, aworktreegrandchild that branches from its parent's worktree, and asharedchild of the root with no message.Each was checked against a production break.
UAT
Dev build of this head (
609e4bd8cb, rerun after merging main) on a branch server with a real workspace agent and GLM, five cases:executeand noworkdir. Itspwdwas the worktree, the commit landed on its agent branch, and the parent checkout stayed clean.README.mdand committed. Each commit landed on its own branch, and the parent'sREADME.mdwas untouched.sharedgrandchild of a worktree child worked in the child's worktree.worktreegrandchild withoutrepo_pathbranched from the child's worktree.sharedchild of the root still worked in the agent directory.All passed. Not covered live: the workspace context working directory header (needs pinned context files) and the relative paths of
edit_files,read_fileandattach_file; unit tests cover them.