Skip to content

feat: record nested subagent depth and enforce a maximum behind fork-nested-subagents - #33

Merged
ibetitsmike merged 9 commits into
mainfrom
mike/nested-subagents-1-depth
Nov 9, 2026
Merged

ibetitsmike merged 9 commits into
mainfrom
mike/nested-subagents-1-depth

Conversation

@ibetitsmike

@ibetitsmike ibetitsmike commented Nov 9, 2026 •

Copy link
Copy Markdown
Owner

Note

Xum opened this PR for Mike.

Part of #8 (W2 nested subagents, PR 1 of the stack).

Records each subagent's depth and enforces a deployment-wide maximum, behind the new fork-nested-subagents experiment. With the experiment off, spawning behaves exactly like upstream: same errors, no forkdb calls, no chat_subagents row.

With the experiment on:

  • Spawning a child writes its chatd.chat_subagents row (depth = parent depth + 1) in the same transaction as the chat insert. Chat publishes go through a PublishBuffer, so subscribers see nothing until the transaction commits. The depth check runs again inside the transaction.
  • A spawn past the limit fails with cannot create a child agent: this chat is at subagent depth N and the maximum subagent depth is M.
  • Explore and computer use chats stay leaves.
  • A child without a chat_subagents row predates depth tracking, when only roots could spawn, so it counts as depth 1.

New option: --chat-max-subagent-depth / CODER_CHAT_MAX_SUBAGENT_DEPTH, default 2, minimum 1. It lives in codersdk/fork_chat_config.go and hooks into upstream's ChatConfig and Options with one line each.

Non-root chats do not get the spawn tools yet. That comes in the next PR, so the grandchild path is covered by unit tests here.

Shared seam: createSubagentChatWithID in coderd/x/chatd/fork_subagents.go is the spawn-time chat_subagents write. W1 (custom agent types) sets agent_type and W4 extends the same function rather than adding another hook.

Upstream chatd internal tests now default to the upstream experiment list (upstreamExperimentsKnown()), so fork experiments do not change upstream test behavior.

Validation
  • go test ./coderd/x/chatd/ (full package, real Postgres in Colima), ./coderd/database/forkdb/..., ./codersdk/
  • TestCommandHelp, TestServerYAML, TestEnterpriseCommandHelp against regenerated goldens
  • chatdmig check; no changes to dump.sql, queries.sql.go, querier.go or dbmock
  • typesGenerated.ts matches scripts/apitypings output
  • Each new test fails under a targeted mutation: CU leaf check removed, limit off by one, depth not incremented, experiment gate ignored
  • UAT on a disposable dev deployment, experiment on and off: child rows have depth 1, flag validation rejects 0, experiment off writes no row
  • docs/reference/api regenerated with scripts/apidocgen in a Linux container

@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-09T09:22:22.485161Z 3454d7e 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: 6b8a2bad38

ℹ️ 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/subagent_operations.go Resolved
Comment thread coderd/x/chatd/subagent_operations.go Resolved
Comment thread coderd/x/chatd/subagent_operations.go Resolved
Comment thread coderd/x/chatd/subagent_operations.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: 761a5847aa

ℹ️ 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 codersdk/fork_chat_config.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: 803ce475be

ℹ️ 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 codersdk/deployment.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: 41d1d9386a

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

@codex review

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Keep them coming!

Reviewed commit: 58cdadfb6a

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

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Chef's kiss.

Reviewed commit: 3454d7e1b9

ℹ️ 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
ibetitsmike merged commit 2b543cf into main Nov 9, 2026
9 checks passed
@ibetitsmike
ibetitsmike deleted the mike/nested-subagents-1-depth branch November 9, 2026 09:51
@ibetitsmike

Copy link
Copy Markdown
Owner Author

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

Gates checked on head 3454d7e1b9:

  • fork-ci: all jobs green on this head (run 42592454232).
  • Codex: "Didn't find any major issues" with reviewed commit 3454d7e1b9; 0 unresolved review threads.
  • UAT: PASS on the disposable dev deployment at d25ed44a20 (flag validation) and a8463f994b (depth-2 family root, coordinator, worker; depths 1 and 2 recorded). Changes after UAT are the depth flag range check (1 to 16, now also on the YAML path, unit-tested), regenerated docs, an ARCHITECTURE.md TODO for the owner, and a merge of main; the default (2) passes the new check on the daily server.

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