Repository navigation
feat(coderd/x/chatd): remove subagent worktrees when their family is archived - #138
Conversation
|
@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: e03161c528
ℹ️ 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".
…the agent deadline
|
@codex review
|
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 93463b5817
ℹ️ 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. Can't wait for the next one! 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 ( |
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 and #135 (both merged), which give a
spawn_agentchild withisolation: worktreeits own git worktree and branch but never remove them.With experiment
fork-subagent-isolationon, archiving a chat family now cleans up the worktrees of its subagents:worktree /x has 2 uncommitted or untracked changes; commit or discard them first,agent unreachable, or that the agent is too old to remove worktrees. The server also logs one line per kept worktree.Both the archive API and the auto-archive worker go through
forkSetFamilyArchived, so both clean up. Unarchiving does nothing to worktrees. With the experiment off, nothing changes.Size: about 220 production lines and 180 test lines.
Code
coderd/x/chatd/fork_family_lock.go:forkSetFamilyArchivedwraps the lock-ordered family update (renamedsetFamilyArchivedInLockOrder) and schedules the cleanup when an archive succeeds.coderd/x/chatd/fork_isolation_cleanup.go:scheduleArchivedWorktreeCleanupruns the cleanup as tracked in-flight work, groups the worktree subagents by workspace agent, callsForkDeleteWorktreefor each, maps the result to a kept reason (worktreeKeptReason), and posts the notice.coderd/x/chatd/chatstate/fork_notice.go:Tx.ForkAppendNoticeinserts a user-visible system message throughChatMachine.Updatewithout changing the execution state or the archived flag, since every chat message write goes through a chatstate transition.coderd/x/chatd/ARCHITECTURE.md: a TODO for the cleanup and the new notice write.Tests
TestForkArchiveWorktreeCleanuparchives a root whose children have fake worktrees on a recording agent connection:RemovesCleanWorktreesAndListsKept: a clean worktree and an already-deleted one are removed and left out of the notice. A dirty worktree (409), an agent without the route (404Route not found.) and a delete that fails in transport are kept and listed with their reasons. Every delete sends the subagent's stored branch, asharedchild gets no delete, and the root stays archived in the same status.AgentUnreachable: with no agent connection, the worktree is listed asagent unreachableand no delete is sent.AgentDialTimesOut: a dial that waits until its context ends, as a dial to an offline agent does, gives up at the dial timeout, and the worktree is listed asagent unreachable.Negative controls, each reverted after the run: removing the schedule call, treating a 409 as removed, treating a transport error as removed, and dialing without the dial timeout each make
TestForkArchiveWorktreeCleanupfail.Known gaps
agent unreachableand listed in the notice.UAT
On a branch server at e03161c (before the dial fix), with workspace agent e03161c and a real model, a root spawned three worktree children. One child stayed clean, one left an untracked file, and one committed without pushing. Archiving the root through
PATCH /api/v2/chats/{id}returned 204. About 30 seconds later the clean child's worktree and branch were gone fromgit worktree listandgit branch -a. The other two were kept, and the root got one notice listing both with the agent's reasons (has 1 uncommitted or untracked changes,has 1 commits that are not on any other branch or remote). The root stayed archived and waiting, with no turn after the notice, and the main checkout stayed onmain.