Skip to content

feat(coderd/x/chatd): stop the workspaces of workspace subagents when their family is archived - #147

Merged
ibetitsmike merged 18 commits into
mainfrom
mike/subagent-isolation-6b-archive-stops-workspace
Nov 10, 2026
Merged

ibetitsmike merged 18 commits into
mainfrom
mike/subagent-isolation-6b-archive-stops-workspace

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 #144 (open), which spawns a subagent into its own workspace with isolation: workspace. In #144, archiving the family leaves that workspace running, and it keeps using compute until someone stops it.

With experiment fork-subagent-isolation on, archiving a family now also stops the workspace of each workspace subagent. Worktree subagents already get their worktree removed after the archive commits (#138). After that removal, and after the notice of kept worktrees, the same background task now stops workspaces. A worktree grandchild of a workspace subagent lives in that subagent's workspace, so the worktree has to go first.

  1. For each family chat whose chat_subagents row has isolation = workspace and a workspace_id, and whose chat is still bound to that workspace, the task runs the existing stop_workspace tool as the chat owner. This is the same helper feat(coderd): spawn subagents into their own workspace with isolation workspace #144 uses when a spawn fails.
  2. The tool waits for any active build first. If the workspace is already stopped, it does nothing.
  3. A failed stop is logged and doesn't affect the archive or the worktree cleanup.

With the experiment off, nothing changes.

Limits

  • Unarchiving the family doesn't start the workspace again.
  • The task stops workspaces one at a time and waits for each stop build.
  • A workspace subagent whose chat was bound to another workspace keeps its own workspace running.
  • A deleted workspace isn't stopped; the tool's error is logged.

Code

  • coderd/x/chatd/fork_isolation_cleanup.go: the workspace branch of the cleanup loop. scheduleArchivedWorktreeCleanup and cleanupArchivedWorktrees are renamed to scheduleArchivedSubagentCleanup and cleanupArchivedSubagents.
  • coderd/x/chatd/fork_family_lock.go: the call site of the rename.
  • coderd/x/chatd/ARCHITECTURE.md: a TODO for the stop.

Tests

  • TestForkArchiveStopsSubagentWorkspaces (chatd, fake workspace stop on a real database, where a stop makes the agent unreachable):
    • StopsRunningWorkspaces: a family with two workspace children and one shared child is archived. The running child's workspace is stopped. The child whose workspace is already stopped isn't stopped again, and neither is the shared child.
    • AfterWorktreeRemoval: the worktree of a worktree grandchild inside a workspace child is removed before that workspace stops.
    • SkipsReboundChild: a workspace child that was bound to the root's workspace stops nothing.

Negative controls, each reverted after the run, each make a named case fail: skipping the stop, stopping without the tool (which also stops the already-stopped workspace), stopping during the worktree collection (AfterWorktreeRemoval), and dropping the binding check (SkipsReboundChild).

go vet, gofmt and go test ./coderd/x/chatd/... pass.

UAT

On the :3200 branch server at 0989048, with a real model and experiment fork-subagent-isolation on, a root chat in workspace uat3200-iso1 spawned one child with isolation: workspace, into workspace uat3200-docker-a6e2. The child's execute printed that hostname, and wait_agent returned its report. The family was then archived. In the same second, the child's workspace got a stop build (initiator: the chat owner), and it was stopped 20 seconds later. The root's own workspace, uat3200-iso1, kept running.

…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.
…on-6-workspace-mode

# Conflicts:
#	coderd/x/chatd/ARCHITECTURE.md
#	coderd/x/chatd/fork_isolation_report.go
…agent-isolation-6b-archive-stops-workspace

# Conflicts:
#	coderd/x/chatd/fork_isolation_workspace.go
@ibetitsmike

Copy link
Copy Markdown
Owner Author

Xum posted this on behalf of @ibetitsmike.

@codex review

@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:12:20.762171Z 0989048 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.

@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: 034001080b

ℹ️ 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/ARCHITECTURE.md Resolved
… removal

A worktree grandchild of a workspace subagent lives in that subagent's
workspace, so stopping the workspace first left its worktree behind. The
cleanup now stops workspaces after it removes the worktrees, and skips a
subagent whose chat is now bound to another workspace, which the stop
tool would otherwise stop.
@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. Nice work!

Reviewed commit: 0989048175

ℹ️ 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-6-workspace-mode to main November 10, 2026 17:14
…on-6b-archive-stops-workspace

# Conflicts:
#	coderd/x/chatd/fork_isolation_workspace_internal_test.go
@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 (d1bb658aa3) 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 (d1bb658aa3), 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 bef9c59 into main Nov 10, 2026
20 of 27 checks passed
@ibetitsmike
ibetitsmike deleted the mike/subagent-isolation-6b-archive-stops-workspace branch November 10, 2026 19:51
@ibetitsmike

Copy link
Copy Markdown
Owner Author

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

Merge evidence for head ca6e91af6a2fa2fb2df4e570aa51d44bbec85fae:

  • fork-ci pull_request run 42884971008 passed; its build job checked out Merge ca6e91af6a into d1bb658aa3 (current main). Run 42863178400 had also passed on this head against 5f6b636911. All checks green.
  • Codex: no major issues on 0989048175 (comment 6771037222). This head only merges main after feat(coderd): spawn subagents into their own workspace with isolation workspace #144's squash; its own diff is identical to 0989048175's (same patch ID). 0 of 3 review threads unresolved. The earlier round fixed the stop after worktree removal and skipped children rebound to another workspace; the ARCHITECTURE.md TODO finding was dropped.
  • UAT on :3200 at 0989048175 with a real model passed: archiving the root stopped the child's own workspace within 20 seconds (build reason initiator), and the root's own workspace kept running. Cleanup was verified.
  • Red/green: 4 negative controls, each failing a named case.
  • No migration.

ibetitsmike added a commit that referenced this pull request Nov 10, 2026
…space stop in the pstack adapter (#154)

* docs: map notify_user and the daily wake-up limits in the pstack adapter

* docs: check the pstack adapter against main at d1bb658

* docs: re-pin pstack adapter cites that #115 and #136 moved

* docs: re-pin pstack adapter cites that #136 moved

* docs: say that a root archive stops the workspaces of workspace subagents

* docs: re-pin pstack adapter cites that #147 moved

* docs: qualify the wake-up limits, pause notices, inbox, and workspace autostop

* docs: condition the archive cleanup of isolated subagents on the experiment

* docs(docs/fork): qualify notification limits and the archive workspace stop

* docs(docs/fork): qualify notify_user availability, limit, and silent drops
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