Repository navigation
fix(coderd/x/chatd): spawn each child once when a tool batch is replayed - #280
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: def544736d
ℹ️ 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. Hooray! 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". |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 38d0b4d193
ℹ️ 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 |
# Conflicts: # coderd/x/chatd/fork_tools.go
|
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 7bd806209c
ℹ️ 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".
…ce child with its start
@codex review |
|
Codex Review: Didn't find any major issues. Another round soon, 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". |
|
$> Coder Agents acted on behalf of @ibetitsmike.\n\nMerged main 607a95b (#279) with a merge commit. The merge was clean. |
|
Codex Review: Didn't find any major issues. Breezy! 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". |
Merged as 5c34d7e (squash, Gates on head 3898c2d:
Not exercised: a real server restart during a live spawn_agent batch on the deployed server. Replay is covered by the DB-backed tests above. |
Part of #252
Problem
When chatd stops while a tool batch runs, the next worker runs the whole batch again with the same tool call IDs. A
spawn_agentcall in that batch then creates a second child. The restart test of #279 showed it: a quick worker spawned in the same batch as three blockingwait_agentcalls existed twice after the restart.Fix
Behind
fork-nested-subagents:fork_spawn_replay.gowraps everyspawn_agenttool. With a tool call ID in the context, it derives candidate child IDs:id0 = uuid.NewSHA1(callID, "spawn_agent"), thenid(n+1) = uuid.NewSHA1(id(n), "spawn_agent"), at most 4 per call.forkChildChatID(ctx)(the existing hook increateChildSubagentChatWithOptions) uses it. A workflow step ID still wins.ForkCreateWorktree, flagged by one hook line increateSubagentWorktree), the next ID is tried, so the replay gets a fresh branch.createSubagentChatWithIDcallsforkCheckSpawnOwnerfirst in its transaction (one hook line). It takes a share lock on the root and the parent and refuses the child when the parent'sworker_idorrunner_iddiffers from the turn's. So a run that a takeover replaced, and that still goes on, creates no child after the new run moved past its 409. The share lock makes a new acquire of the parent wait until a child of the old run commits, so the replay then sees that child.discardSubagentUnlesswith a check that runs under the child's lock and keeps the child when its workspace was recorded meanwhile.createSubagentWorkspacerefuses to record a workspace or send the prompt to an archived child.discardSubagentnow also stops the bound workspace of a child that was archived already, so a run that bound a workspace after a replay archived its child still stops that workspace.ARCHITECTURE.mddescribes the replay safe spawn and that a graceful shutdown replays a cut batch.Tests
TestForkSpawnAgentReplay: two runs with one tool call ID, from a root and from a child, give one child each. A new call ID gives a new child. A derived ID owned by another parent fails.TestForkSpawnAgentReplayRetiredChild(Archived, UnstartedWorkspace): the replay skips the retired child and creates a new one.TestForkSpawnAgentReplayWorktreeConflict: a 409 on the first worktree makes the replay use the next ID.TestForkSpawnAgentReplayConcurrentRun: an inner error after a concurrent insert returns the existing child.TestForkSpawnAgentReplayTakenOver: a turn with a runner ID other than the chat's creates no child, and a turn of the current runner does. It fails without theforkCheckSpawnOwnerline (verified by removing it).TestForkSpawnAgentReplayRetiredWhileStarting: ArchivedBeforeBind retires the child while the original run creates its workspace; the spawn fails, the child gets no prompt and its workspace is stopped. KeepsStarted keeps a child whose workspace was recorded. Each of the three parts (the archived check, the stop of an already archived child, the keep check) was removed in turn, and the test failed each time.flock ~/.fork-go.lock go test ./coderd/x/chatd -run 'TestForkSpawnAgentReplay' -count=1: ok.flock ~/.fork-go.lock go test ./coderd/x/chatd -run '(?i)spawn|subagent|workflow|isolation|computeruse|agentdefinition' -count=1: ok.TestChatFamilyRestartReplaysSpawnAgentOnceandTestChatFamilySurvivesRestartpassed twice each (-count=2). Without this fix the probe fails with 4 children expected and 5 found. The probe is not committed here. It lands with the harness after test(coderd/x/chatd): prove a busy chat family survives a chatd restart #279.golangci-lint run --fix=false ./coderd/x/chatd/...: no new findings.Not covered
TestForkSpawnAgentReplayConcurrentRunuses a stub inner tool, not a real race between two workers.