Repository navigation
feat: add an agent git worktree API for isolated subagents - #81
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.
|
@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: bbda241312
ℹ️ 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".
…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.
|
@codex review |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 54f764178f
ℹ️ 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 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.
|
@codex review |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 7c76d15b3c
ℹ️ 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".
…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.
|
@codex review |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: c330452d9c
ℹ️ 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".
…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.
|
@codex review |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 9c816e5299
ℹ️ 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".
…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.
|
@codex review |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 1e6d2c2675
ℹ️ 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".
…quest deadline and widen the submodule commit check
|
@codex review |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: cf125aef95
ℹ️ 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".
…d before removing a worktree
|
@codex review |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: fe2dd23334
ℹ️ 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".
…eleted branch's config
|
@codex review |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 6ba292b86c
ℹ️ 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".
…rollback the request budget
|
@codex review |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: df86079813
ℹ️ 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".
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.
Adds the workspace agent API that chatd will use to give
worktree-isolated subagents their own git worktree. Nothing calls it yet: chatd starts using it in the next PR of this stack, behind experimentfork-subagent-isolation. The agent routes themselves are not experiment-gated, since agents do not know deployment experiments.Agent:
/api/v0/git/worktreesPOSTcreates a worktree at~/.coder/worktrees/<repo>/<name>on a new branch, starting atbase_ref(defaultHEADofrepo_path). It returns the path, branch, base commit and repo root with 201. Ifgit worktree addfails after checkout (for example a failingpost-checkouthook), the half-created worktree and branch are rolled back, on a detached context so a canceled request still cleans up, with the same 10 minute budget as the request. The root is created0700, and an existing root is tightened to0700. It rejects repositories that contain the worktree root, relative repo paths, unsafe names, invalid or existing branches, option-looking values, an existing target and any path that resolves outside the root.DELETEtakes the path and the branch that create returned. It removes a linked worktree exactly two levels below the root, then deletes that branch, and answers 204. It refuses with 409 and says why when HEAD is not on that branch (another branch or detached), when the tree has uncommitted or untracked changes (ignored files do not count, as withgit worktree remove). A clean worktree with initialized submodules is removed with--force, which git requires for it, unless a submodule has commits that are on no remote (409); this also covers submodules that were deinitialized but still have a repository under<gitdir>/modules, and commits that only a submodule reflog still holds, or when the branch tip or the worktree HEAD and branch reflogs have commits that no other local branch or remote-tracking ref holds ("unpushed", which includes commits areset --hardmoved away from). The branch is deleted withupdate-ref -dagainst the tip the unpushed check covered, so a tip that moves in between is kept, and itsbranch.<name>config (such as an upstream) is removed with it. That race window has no test: hitting it needs a commit landing between two git calls inside one request, which a test cannot schedule without an injection seam in production code. Missing paths get 404; anything outside the root, the root itself, a repo directory or a main working tree gets 400.Both routes extend the agent server's 20 second write deadline and bound the request to 10 minutes, so a large checkout can finish. The routes are mounted by one hook line in
agent/agentgit/api.go; the logic is inagent/agentgit/fork_worktrees.go.Client
codersdk/workspacesdk/fork_worktrees.goadds the wire types andForkWorktreeConn, implemented by*agentConn. Callers type-assert theirAgentConn, so theAgentConninterface and its mock are unchanged. Non-2xx answers come back as*codersdk.Errorwith the status code (an older agent answers 404).Tests
Real git in temp dirs: create defaults and explicit base, every rejection with its reason, two worktrees editing the same file on different branches with the parent checkout unchanged, and every delete outcome (clean, dirty, unpushed, held by another branch or remote, HEAD on another branch or detached, path checks), plus rollback after a failing
post-checkouthook, rollback with a canceled context, clean, dirty, deinitialized, reflog-only,refs-named andlibs/subsubmodule worktrees, a repository inside submodule metadata that must not be scanned, a pre-existing permissive root, and a checkout that outlasts the server's write timeout. The client success paths run over a stub tailnet, and the error mapping plus the hook line run through a real agent. Each new test was checked against a production break.Size: 585 production lines, 917 test lines.
UAT: per the lead, this PR has no UAT of its own; the next PR's dev-build UAT exercises this API end to end through chatd. Note that fork-ci's test job does not run
./codersdk/workspacesdk/or./agent/tests; those passed locally ingolang:1.26.10-bookworm.