Skip to content

feat(coderd): spawn subagents into their own workspace with isolation workspace - #144

Merged
ibetitsmike merged 12 commits into
mainfrom
mike/subagent-isolation-6-workspace-mode
Nov 10, 2026
Merged

ibetitsmike merged 12 commits into
mainfrom
mike/subagent-isolation-6-workspace-mode

Conversation

@ibetitsmike

@ibetitsmike ibetitsmike commented Nov 10, 2026 •

Copy link
Copy Markdown
Owner

Xum opened this PR on behalf of @ibetitsmike.

Part of #9. Builds on #141 (merged), which adds the wait_agent report for worktree children. A worktree child (#108, #135) shares its parent's workspace, so it shares its CPU, memory, ports and running processes. Some tasks need a machine of their own.

With experiment fork-subagent-isolation on, spawn_agent now accepts isolation: workspace. The child gets its own new workspace, built from the template of the parent's workspace with the parameters of the parent's latest build. The spawn waits until the build succeeds, the agent is ready and its startup scripts finish, so the child's first turn can use the workspace.

  1. createSubagentChatWithID creates the child waiting, with no workspace and without its prompt, and records isolation = workspace on its chat_subagents row in the same transaction as before.
  2. After that transaction, chatd runs the existing create_workspace tool for the child. That tool names the workspace, creates it as the chat owner, binds it to the child, and waits for the build and the agent. Its result counts as success only if it reports created: true and reports no agent_status or startup_scripts problem.
  3. In one transaction, chatd then records workspace_id on the child's chat_subagents row and sends the child its prompt, so the first turn starts there.

If step 2 or 3 fails, the child is archived. Any workspace it got is stopped in the background with the stop_workspace tool, which first waits for an active build (best effort). The spawn then returns the error, for example create the child's workspace: workspace quota exceeded.

spawn_agent and wait_agent report isolation: workspace and the child's workspace_name, or workspace_error when the name cannot be read. repo_path and base_branch are refused with isolation: workspace. With the experiment off, nothing changes.

Limits

  • The child uses the template's active version, not the version of the parent's build.
  • The spawn blocks for the whole build. A slow template makes spawn_agent slow.
  • Computer use agents cannot use isolation: workspace.
  • The live-subagent family cap counts a workspace child only once its prompt is sent, so parallel spawns can exceed it.
  • While its workspace builds, the child is waiting and accepts a message sent to it directly, which would run before its prompt.
  • With agent hooks configured, the child's UserPromptSubmit hook names the parent's workspace, not the child's.
  • A spawn that fails because the server is shutting down archives the child but doesn't stop its workspace.
  • Archiving the family does not stop the child's workspace yet. That is the next PR in this stack.

Size: 293 added production lines (218 in fork_isolation_workspace.go) and 272 test lines.

Code

  • coderd/x/chatd/fork_isolation_workspace.go: the workspace source, the deferred prompt, startSubagentWorkspace and discardSubagent, and the workspace name for tool results.
  • coderd/x/chatd/fork_subagents.go: the isolation: workspace branch of createSubagentChatWithID.
  • coderd/x/chatd/fork_isolation.go, fork_isolation_report.go: the new enum value and the result fields.
  • coderd/database/forkdb/queries/chat_subagents.sql: UpdateChatSubagentWorkspaceID, generated with forkdb/generate.sh, with dbauthz (update on the chat) and dbmetrics wrappers.
  • coderd/x/chatd/ARCHITECTURE.md: a TODO for the mode.

Tests

  • TestForkSpawnIsolationWorkspace (chatd, fake workspace creation on a real database): the child's workspace is created from the parent's template with the parent's build parameter, it is bound and recorded, the child's only user message is the prompt, and spawn_agent and wait_agent report the workspace name. A failed creation archives the child and stops nothing; a failed build, a workspace without an agent, or failed startup scripts archive the child and stop its workspace in the background; a parent without a workspace is refused before any child exists.
  • TestForkQuerier/UpdateChatSubagentWorkspaceID: dbauthz checks update on the chat.
  • TestForkSpawnIsolationErrors: the enum message, and repo_path with isolation: workspace.

Negative controls, each reverted after the run, each make a named test fail: dropping the build parameters, skipping the archive on failure, skipping the stop, recording no workspace, skipping the prompt, ignoring created: false, ignoring agent_status (NoAgent fails), and ignoring startup_scripts (StartupScriptsFail fails).

UAT

On the :3200 branch server and workspace agent at bb356f7, with a real model, a root chat in workspace uat3200-iso1 spawned one child with isolation: workspace. The spawn took about 4 seconds and returned workspace_name: uat3200-docker-1623. The child's execute printed that hostname and CODER_WORKSPACE_NAME, and wait_agent reported the same workspace name.

Checked outside the model: the new workspace is owned by the chat owner and uses the parent's template at its active version. Its start build succeeded and its agent was ready. The child chat is bound to it, its chat_subagents row has isolation = workspace and that workspace_id, and the child's only user message is the prompt, created after the agent was ready. Archiving the family left the child's workspace running, as listed under Limits. The failure paths were not run on the server, because the template has no parameter that can make a build fail. The tests cover them. The readiness checks and the background stop came after the UAT, at b60c5ef, and are covered by tests and negative controls.

I ran the happy path again on the :3200 branch server at 0989048 (#147, which contains this PR's head 01aa038). It spawned one child into workspace uat3200-docker-a6e2, owned by the chat owner, using the parent's template. Its start build succeeded and its agent was ready. The child's execute printed that hostname, and wait_agent returned the report with isolation: workspace and that workspace name.

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 10, 2026 •

Copy link
Copy Markdown
Codex Review Summary: ✅ Completed

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-10T15:14:58.011064Z 01aa038 Manual request
ℹ️ 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" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@ibetitsmike

Copy link
Copy Markdown
Owner Author

Xum posted this on behalf of @ibetitsmike.

@codex review

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: bb356f74a1

ℹ️ 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".

Comment thread coderd/x/chatd/fork_subagents.go Resolved
Comment thread coderd/x/chatd/ARCHITECTURE.md Resolved
…m in the background

A created workspace whose agent is missing or not ready, or whose startup
scripts did not finish, now fails the spawn. A failed spawn stops the
child's workspace with the stop_workspace tool, in the background, so
the stop waits for the create build instead of failing against it.
@ibetitsmike

Copy link
Copy Markdown
Owner Author

Xum posted this on behalf of @ibetitsmike.

@codex review

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. 🚀

Reviewed commit: b60c5eff68

ℹ️ 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".

Base automatically changed from mike/subagent-isolation-5-wait-report to main November 10, 2026 14:49
…on-6-workspace-mode

# Conflicts:
#	coderd/x/chatd/ARCHITECTURE.md
#	coderd/x/chatd/fork_isolation_report.go
@ibetitsmike

Copy link
Copy Markdown
Owner Author

Xum posted this on behalf of @ibetitsmike.

@codex review

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 01aa038a26

ℹ️ 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".

Comment thread coderd/x/chatd/fork_isolation.go Resolved
@ibetitsmike

Copy link
Copy Markdown
Owner Author

Xum posted this on behalf of @ibetitsmike.

@codex review

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 01aa038a26

ℹ️ 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".

@ibetitsmike

Copy link
Copy Markdown
Owner Author

Xum posted this on behalf of @ibetitsmike.

@codex review

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Another round soon, please!

Reviewed commit: 01aa038a26

ℹ️ 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".

@ibetitsmike

Copy link
Copy Markdown
Owner Author

Xum (AI agent) closed and reopened this on behalf of @ibetitsmike.

Closing and reopening only to make GitHub recompute the merge ref against current main (df22c722f3) and run fork-ci on it. The head is unchanged.

@ibetitsmike ibetitsmike reopened this Nov 10, 2026
@ibetitsmike

Copy link
Copy Markdown
Owner Author

Xum (AI agent) closed and reopened this again on behalf of @ibetitsmike.

The merge ref now points at current main (df22c722f3), but the run started by the first reopen was queued against the old merge ref. This second reopen starts fork-ci on the recomputed merge. The head is unchanged.

@ibetitsmike ibetitsmike reopened this Nov 10, 2026
@ibetitsmike
ibetitsmike merged commit 9705e5a into main Nov 10, 2026
27 of 31 checks passed
@ibetitsmike

Copy link
Copy Markdown
Owner Author

Xum (AI agent) merged this on behalf of @ibetitsmike.

Merge evidence for head 01aa038a260ffca89186030c3916af1f47670a4b:

  • fork-ci pull_request run 42853087208 passed; its build job checked out Merge 01aa038a26 into df22c722f3 (current main). Run 42838205243 had also passed on this head against e44a0a2f97. All checks green.
  • Codex on this exact head: no major issues (comment 6771102095). 0 of 8 review threads unresolved. Earlier rounds fixed readiness (agent status and startup scripts) and the background stop path; 6 drops were replied to and resolved (pubsub flush failure, ARCHITECTURE.md TODO, family cap under parallel spawns, a direct message during the child's build, the hook naming the parent workspace, shutdown during spawn).
  • UAT on :3200 at 0989048 (feat(coderd/x/chatd): stop the workspaces of workspace subagents when their family is archived #147, contains this head) with a real model passed: a root chat spawned a child with isolation=workspace, the child got its own workspace from the parent's template version, its agent was ready, its execute ran in that workspace, and wait_agent returned the report with the workspace name. Cleanup was verified.
  • Red/green: 8 negative controls, each failing a named test.
  • No migration; one new forkdb query (UpdateChatSubagentWorkspaceID).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant