Repository navigation
feat: store organization subagent limits and enforce max_depth behind fork-nested-subagents - #45
Conversation
…ind fork-nested-subagents
…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.
…en and the depth flag
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.
…for subagent depth
…nto mike/nested-subagents-2-tools # Conflicts: # coderd/x/chatd/ARCHITECTURE.md # coderd/x/chatd/fork_tools.go
…-2-tools # Conflicts: # coderd/x/chatd/fork_subagents.go # coderd/x/chatd/fork_subagents_internal_test.go
…nto mike/nested-subagents-3-cascade # Conflicts: # coderd/database/dbauthz/fork_forkdb.go # coderd/database/dbauthz/fork_forkdb_test.go # coderd/database/dbmetrics/fork_forkdb.go # coderd/database/forkdb/forkdbmock/forkdbmock.go # coderd/database/forkdb/querier.go
…description cannot read organization limits
…d spawn pre-check
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 887d20c7b8
ℹ️ 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".
@codex review |
|
To use Codex here, create an environment for this repo. |
…-3-cascade # Conflicts: # coderd/x/chatd/ARCHITECTURE.md # coderd/x/chatd/fork_tools_internal_test.go
… into mike/nested-subagents-4-org-limits # Conflicts: # coderd/fork_chat_routes.go
@codex review |
|
Codex Review: Didn't find any major issues. Keep them coming! Reviewed commit: ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
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". |
…-4-org-limits # Conflicts: # coderd/x/chatd/ARCHITECTURE.md # coderd/x/chatd/fork_subagents.go
@codex review |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: cc38d735ae
ℹ️ 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".
…-4-org-limits # Conflicts: # coderd/apidoc/docs.go # coderd/apidoc/swagger.json
@codex review |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 10431b8988
ℹ️ 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".
@codex review |
|
Codex Review: Didn't find any major issues. 🚀 Reviewed commit: ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
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". |
Merge evidence for head
|
Part of #8 (W2 nested subagents, PR 4 of the stack).
With
fork-nested-subagentson, an organization admin can store subagent limits for their organization, and chatd enforces the organization'smax_depth. With the experiment off, nothing reads the new table and the new routes answer 403.chatd.chat_organization_subagent_limits, keyed byorganization_id(cascade delete). It has four nullable limits:max_depth(1 to 16),max_concurrent,max_concurrent_per_familyandmax_live_per_family(each at least 1). NULL means "use the deployment value", and a set value can only lower it.GETandPUT /api/v2/chats/fork/organizations/{organization}/subagent-limits, withcodersdkclient methods. An unset limit is omitted from the JSON. Access follows the organization system prompt: reading needs read on the org's chat model config (other callers get 404), and writing needs update (403 when the caller can read but not update, 404 otherwise). Invalid values get 400 with per-field validations. APUTreplaces all four values.fork_subagents.gouses the effective value: the deployment--chat-max-subagent-depth, lowered by the org'smax_depth. That covers the spawn pre-check, the transactional recheck, the spawn tools, the orchestration prompt and thespawn_agentdescription (one line insubagent_catalog.go). If the description cannot read the org row, it states the deployment depth instead of failing the turn. Spawning still enforces the effective depth.ARCHITECTURE.mdgets only a TODO for the author.Validation
go test ./coderd/x/chatd/, plus./coderd/database/forkdb/...,TestForkQuerier,./coderd/ -run 'TestForkChatOrganizationSubagentLimits|TestForkChatRoutes', the swagger annotation tests (EndpointsDocumented|TestSwagger, OSS and enterprise) and./coderd/database/migrations/chatdmig/....forkdb/generate.shand thetypesGenerated.tsregeneration leave no diff, andchatdmig checkpasses.TestUpsertChatOrganizationSubagentLimits,TestForkQueriercases,TestForkChatOrganizationSubagentLimits(round trip, validation, member and auditor access, experiment off) andTestNestedSubagentOrganizationMaxDepth(an org value lowers the depth at every call site; a higher org value does not raise the deployment ceiling). Negative controls: 18 single-line production breaks each made a test fail.main, let update-only callers write, and omit unset limits from the JSON; they are covered by the tests above. Results: the API round trip, validation and access rules passed. With orgmax_depth1, the coordinator had nospawn_agentand no grandchild existed. With no orgmax_depth, a depth-2 family completed. With org 16 above a deployment value of 2, a depth-2 worker could not spawn. With the experiment off, the routes returned 403 and spawning behaved as upstream.