Skip to content

feat(coderd): give nested general subagents the subagent tools, direct children only - #37

Merged
ibetitsmike merged 21 commits into
mainfrom
mike/nested-subagents-2-tools
Nov 9, 2026
Merged

ibetitsmike merged 21 commits into
mainfrom
mike/nested-subagents-2-tools

Conversation

@ibetitsmike

Copy link
Copy Markdown
Owner

Note

Xum opened this PR for Mike.

Part of #8 (W2 nested subagents, PR 2 of the stack). Stacked on #33: review only the commits after it.

With fork-nested-subagents on, a general subagent below the maximum depth (--chat-max-subagent-depth, default 2) now gets the subagent tools, so a root, coordinator and worker family works end to end. With the experiment off, tool lists, prompts, descriptions and target rules stay upstream's.

  • Tools for non-root chats. appendForkTools now takes the model config and returns an error. It appends spawn_agent, list_subagent_models, list_agents, wait_agent, message_agent and interrupt_agent for a non-root chat that can spawn: not explore or computer use, and depth + 1 <= max.
  • Direct children only. wait_agent, message_agent, interrupt_agent and list_agents act only on the caller's direct children. A root can no longer reach its grandchild. Upstream lets a chat target any descendant, and that rule still applies with the experiment off.
  • Prompt and description. Children that can still spawn keep the subagent orchestration prompt block. The spawn_agent description names the depth limit.
  • Ancestor chain. The Coder-Ancestor-Chat-Ids header now carries the whole parent chain up to the root, for agent connections and workspace-file uploads. Without it, a grandchild's touched paths never reached the root's git watch (Codex P1 on feat: record nested subagent depth and enforce a maximum behind fork-nested-subagents #33). chatd.AncestorChatIDs does no extra reads with the experiment off.
  • ARCHITECTURE.md gets only a TODO for the author.

Shared seam: W1 (custom agent types) and W4 (todos) can extend nestedSubagentTools and the list_agents output instead of adding new hooks.

Validation
  • Full go test ./coderd/x/chatd/ with real Postgres (Colima), TestPostChatWorkspaceFile, ./codersdk/, CLI help goldens
  • New tests: TestNestedSubagentFamilyCompletes (three-level family against a fake OpenAI server; the worker's result reaches the root), TestNestedSubagentTools, TestNestedSubagentTargets (all four call sites and list_agents), TestNestedSubagentOrchestrationPrompt, TestNestedSubagentSpawnDescription, TestAncestorChatIDs. A test audit broke each covered behavior and saw the test fail.
  • UAT on a disposable dev deployment with a local model:
    • Experiment on: a coordinator spawned a worker, chat_subagents recorded depths 1 and 2, and the root could not target its grandchild.
    • At max depth: a worker has no spawn_agent.
    • Experiment off: a child has no spawn_agent.
  • fork-ci triggers only on PRs to main, so CI for this stacked PR runs through workflow_dispatch on the branch.

…s, direct children only

With fork-nested-subagents on, a general subagent below the maximum depth
gets spawn_agent and the other subagent tools, keeps the orchestration
prompt, and the subagent tools act only on the caller's direct children.
With the experiment off, tools, prompts and target rules stay upstream's.
…nd spawn description

Assert that wait, message and interrupt reject a grandchild, that list_agents works on a delegated chat and lists direct children only, that the spawn_agent description rewrite applies with the configured depth, and that appendForkTools leaves delegated chats untouched with fork experiments off.
The Coder-Ancestor-Chat-Ids header carried only the immediate parent, so a
grandchild's file edits and commands were never attributed to the family root's
path store and the root's git watch and diff omitted that work.

Resolve the chain with a new chatd helper: nil for a root, the parent alone when
fork-nested-subagents is off (upstream behavior, no extra queries), and the full
chain nearest ancestor first up to the root when it is on. A failed lookup warns
and keeps the ancestors found so far.
@ibetitsmike

Copy link
Copy Markdown
Owner Author

@codex review

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 9, 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-09T10:01:59.202943Z 2933ad4 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: a202b75306

ℹ️ 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
Comment thread coderd/x/chatd/fork_subagents.go Resolved
Comment thread coderd/x/chatd/fork_ancestors.go Resolved
Comment thread coderd/x/chatd/fork_subagents.go Resolved
@ibetitsmike

Copy link
Copy Markdown
Owner Author

@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: b248122ef5

ℹ️ 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/subagent_operations.go Resolved
Comment thread coderd/x/chatd/fork_ancestors.go Resolved
Base automatically changed from mike/nested-subagents-1-depth to main November 9, 2026 09:51
…-2-tools

# Conflicts:
#	coderd/x/chatd/fork_subagents.go
#	coderd/x/chatd/fork_subagents_internal_test.go
@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: 2933ad4104

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

…-2-tools

# Conflicts:
#	coderd/x/chatd/ARCHITECTURE.md
@ibetitsmike
ibetitsmike merged commit 36205eb into main Nov 9, 2026
9 checks passed
@ibetitsmike
ibetitsmike deleted the mike/nested-subagents-2-tools branch November 9, 2026 11:53
@ibetitsmike

Copy link
Copy Markdown
Owner Author

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

Merge evidence at head f5b5941261:

  • fork-ci pull_request run 42609965021 green on this head (all checks pass), MERGEABLE/CLEAN, 0 unresolved review threads.
  • Codex receipt clean on 2933ad4104. The only change after it is a merge of main; git diff origin/main f5b5941261 matches the reviewed patch except for one unchanged context line in an ARCHITECTURE.md TODO comment and its blob index line, so the receipt and the UAT on 2933ad4104 stand.
  • Merged after the previous main commit 1c8be7b31b deployed healthy locally (buildinfo, migrations 640 clean, no new-process errors).

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