Repository navigation
feat: enforce subagent concurrency limits behind fork-nested-subagents - #47
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
…-5-capacity Also states in the concurrency cap docs that a subagent's own ancestors do not count against it.
@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". |
…on and family A capped organization or family whose refused subagents rank oldest filled the bounded candidate batch on every pass, so other organizations and families never got admitted until that backlog drained. Rank subagent candidates by organization, then family, then age. Roots keep age order.
@codex review |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: b32b951fbf
ℹ️ 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".
…d order without the experiment Interleaving only within each status let a capped family's unowned interrupting subagents fill the batch ahead of every running subagent. Ranking every unowned subagent also gave up the indexed age-order limit for roots and for deployments without fork-nested-subagents, so only the experiment's subagent branch ranks rows now.
@codex review |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: d319ad0ba6
ℹ️ 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".
…ir family A coordinator that holds its family's last slot while it waits in wait_agent can only make progress through its own child, which excludes it from the family count. Older queued siblings, which cannot fit, kept that child out of the bounded candidates.
@codex review |
|
Codex Review: Didn't find any major issues. Delightful! 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". |
@codex review |
|
Codex Review: Didn't find any major issues. Breezy! 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". |
The head is unchanged ( |
What I checked before merging head
|
Part of #8 (W2 nested subagents, PR 5 of the stack).
With
fork-nested-subagentson, chatd caps how many subagent chats run at once: across the deployment, per organization and per family (one root chat and its descendants). With the experiment off, the wrapper passes every decision to upstream's limiter.--chat-max-concurrent-subagentsand--chat-max-concurrent-subagents-per-family(CODER_CHAT_MAX_CONCURRENT_SUBAGENTS,CODER_CHAT_MAX_CONCURRENT_SUBAGENTS_PER_FAMILY). Both default to 0, which means no limit, and reject negative values.max_concurrentandmax_concurrent_per_familyvalues that feat: store organization subagent limits and enforce max_depth behind fork-nested-subagents #45 stores now apply. Each lowers the deployment value; when the deployment has no limit, the organization value is the limit. The deployment flag counts subagents in every organization, and the organization value counts only its own.forkCapacityLimiterwraps upstream'sAgentCapacityLimiter. With the experiment on, it admits subagents itself: it takes the capacity admission lock and counts subagents that a worker owns with a fresh heartbeat, the same rule as upstream's pool count. It also applies upstream's subagent pool cap (10 unless Enterprise unlocks it) with that count. Root chats, and every chat with the experiment off, go to upstream's limiter unchanged.wait_agentholds a slot, so its children must still be admitted. Upstream's own pool count would include the coordinators, so ten waiting coordinators would block every child.errSkipAcquire, which skips only that chat. A plain refusal makes the worker skip every subagent in the batch, so one full family would block every other family.maxSubagentDepthbecomessubagentLimits, which returns depth and capacity limits from one organization read.max_live_per_familyis still stored but not enforced. The next PR enforces it.ARCHITECTURE.mdgets only a TODO for the author.About 550 hand-written lines, about half of them tests.
Validation
go test ./coderd/x/chatd/, plus./coderd/database/forkdb/...,./coderd/database/dbauthz/,./codersdk/, the CLI help and YAML goldens (OSS and enterprise) and the swagger annotation tests.forkdb/generate.shand thetypesGenerated.tsregeneration leave no diff.TestCountActiveSubagentsForCapacity(the query skips roots, stale heartbeats and the candidate's lineage, and counts deployment, organization and family separately),TestForkCapacityAdmission(the deployment limit spans organizations, ancestors do not count against the fork limits or the upstream pool, roots are not capped, experiment off),TestForkCapacityFullFamilyDoesNotBlockOtherFamilies(worker-level: a full family does not keep another family's subagent from starting) andTestForkChatSubagentCapacityOptions(flag defaults and validation).mainand reword the cap docs.