Skip to content

feat: let agent definitions set the default subagent isolation - #151

Merged
ibetitsmike merged 3 commits into
mainfrom
mike/subagent-isolation-8-definition-default
Nov 10, 2026
Merged

ibetitsmike merged 3 commits into
mainfrom
mike/subagent-isolation-8-definition-default

Conversation

@ibetitsmike

@ibetitsmike ibetitsmike commented Nov 10, 2026 •

Copy link
Copy Markdown
Owner

Xum opened this PR on behalf of @ibetitsmike.

Part of #9. Today a caller picks a subagent's isolation per call, with the isolation argument of spawn_agent. An agent type that should always work on its own branch, such as a fixer, needs every caller to remember that argument.

With experiment fork-subagent-isolation on, a custom agent definition can now set isolation: shared | worktree | workspace in its front matter. spawn_agent uses that value when the call sets no isolation.

  1. An explicit isolation on the call wins, shared included.
  2. repo_path and base_branch work with a worktree from either the call or the definition. A definition default without them creates the worktree from the chat's workspace directory and its current branch, as a call with isolation: worktree and no other options does. With any other resulting isolation they fail with repo_path and base_branch need isolation worktree.
  3. With the experiment off, the definition's isolation is ignored and every spawn is shared.
  4. The parser rejects any other value, the same way it rejects an unknown base_type.

The spawn_agent description gets one sentence that says a custom agent type can set the isolation.

Limits

  • A stored definition, or a workspace agent file, that already has an isolation key with another value now fails to parse, so its agent type can't be spawned until the key is fixed. Before this change the key was unknown and only produced a warning.

  • coderd/x/chatd/ARCHITECTURE.md gets a TODO(ibetitsmike) for the definition default instead of final text, per the chatd rule that the human author writes that document. Codex flagged it on 08a2dcb3b2; not changed.

Code

  • codersdk/workspacesdk/fork_agentdefinition.go: AgentDefinition.Isolation and the isolation key with its validation.
  • coderd/x/chatd/fork_isolation.go: subagentIsolationOf replaces subagentIsolationFromContext, falls back to the definition, and checks repo_path and base_branch against the resulting isolation. The spawn_agent wrapper passes no isolation when the call sets none, so the definition applies, and adds isolation, branch and worktree_path (or the workspace name) to the result whenever the child's row isn't shared.
  • coderd/x/chatd/fork_subagents.go: the call site.
  • coderd/x/chatd/ARCHITECTURE.md: a TODO for the default.

Tests

  • TestForkSpawnIsolationDefinitionDefault (chatd, real database, fake worktree agent), with a personal definition fixer that sets isolation: worktree:
    • NoIsolationArg: a spawn of personal/fixer without isolation creates one worktree, stores worktree on the child's row and returns its branch.
    • RepoPathWithoutIsolationArg: the same spawn with repo_path and no isolation creates the worktree from that repo_path. It failed before 08a2dcb3b2 with repo_path and base_branch need isolation worktree, which UAT found.
    • ExplicitShared: isolation: shared creates no worktree and stores shared.
    • IsolationExperimentOff: without the experiment, the spawn is shared.
  • TestParseAgentDefinition/CoderKeys parses isolation: worktree, and TestParseAgentDefinitionErrors/BadIsolation rejects isolation: container.

Negative controls, each reverted after the run, each make a named case fail: ignoring the definition (NoIsolationArg), letting the definition win over an explicit shared (ExplicitShared), dropping the experiment check (IsolationExperimentOff), and dropping the parser validation (BadIsolation).

go vet and gofmt pass on both packages, and go test ./coderd/x/chatd/... and the TestParseAgentDefinition tests pass.

UAT

Ran on 2026-11-10 on the :3200 fork branch server built at this head (v2.39.1-devel+08a2dcb3b2, fork-subagent-isolation on), as a member user, in real chats on a Docker workspace whose agent has no directory set. A personal definition fixer set isolation: worktree.

  • spawn_agent with type: personal/fixer, repo_path: /home/coder/proj and no isolation: the result has isolation: worktree, branch agent/fixer-by-default-7de358fd and a worktree under /home/coder/.coder/worktrees/proj/. The child committed a file there, and wait_agent returned diff_summary.commits: 1. On the previous head (90e67455c6) this same call failed with repo_path and base_branch need isolation worktree, which is the bug 08a2dcb3b2 fixes. Without repo_path, the earlier head already failed only with the workspace agent has no directory; set repo_path ..., which shows the definition default was applied.
  • spawn_agent with type: personal/fixer and isolation: shared: the result has no isolation fields, and the child ran in /home/coder with /home/coder/proj still on main.

The definition was deleted and the chats archived afterwards.

A custom agent's front matter can set isolation: shared, worktree or
workspace. spawn_agent uses it when the call sets no isolation; an
explicit isolation, shared included, wins. It applies only with the
fork-subagent-isolation experiment.
@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-10T18:53:02.652948Z 08a2dcb 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

@codex review

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. What shall we delve into next?

Reviewed commit: 90e67455c6

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

@codex review

Xum posted this on behalf of @ibetitsmike.

@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: 08a2dcb3b2

ℹ️ 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
@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 (6b1757fb92) 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 (6b1757fb92), 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 14d31fa into main Nov 10, 2026
23 of 30 checks passed
@ibetitsmike
ibetitsmike deleted the mike/subagent-isolation-8-definition-default branch November 10, 2026 23:50
@ibetitsmike

Copy link
Copy Markdown
Owner Author

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

Merge evidence for head 08a2dcb3b234ce9532d6b6aca4cf0516933b9e49:

  • fork-ci pull_request run 42919667720 passed; its build job checked out Merge 08a2dcb3b2 into 6b1757fb92 (current main). Run 42879027776 had also passed on this head. All checks green.
  • Codex reviewed this exact head (comment 6774292602): its only finding was the ARCHITECTURE.md TODO, which was declined because the human author writes that document. 0 of 1 review threads unresolved. The earlier head 90e67455c6 had no major issues.
  • UAT on :3200 at this head with a real model passed, as a member user with a personal definition fixer that sets isolation: worktree: a spawn with repo_path and no isolation created a worktree on its own branch, the child committed there, and wait_agent reported one commit; a spawn with isolation: shared created no worktree. The definition and chats were cleaned up.
  • Red/green: 4 negative controls, each failing a named case.
  • No migration.

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