Repository navigation
feat: report the subagent capacity of a nested chat family - #109
Conversation
Adds GET /api/v2/chats/fork/{chat}/family behind fork-nested-subagents. For a
root chat it returns the family's live subagent count and live limit, and the
running subagents that wait for a concurrency slot.
@codex review |
Codex Review Summary: ✅ CompletedThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: f565c968ed
ℹ️ 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".
…escendants GetFamilySubagentsAwaitingWorker now returns the capacity counts of every waiting subagent, so the family endpoint makes one query instead of one per waiting chat. The route uses Chat.IsSubChat so a descendant whose parent was purged is not treated as a root.
|
@codex review
|
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: dd21f532e4
ℹ️ 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".
…each chat's lineage GetFamilySubagentsAwaitingWorker joined every waiting subagent with every active subagent. It now counts the deployment, organization and family totals once and subtracts each waiting chat's own active ancestors.
|
@codex review
|
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: cb34d8e97b
ℹ️ 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. Nice work! 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". |
UAT: family capacity endpointDev server in the W2 UAT container, Run on cb34d8e (the query fix; d32bb19 only merges main, which changes generated doc text for What this shows:
The same lifecycle passed on dd21f53 (the earlier query shape), and on f565c96 for the waiting state and the 400. In that run the waiting worker also had |
Closing and reopening only to make GitHub recompute the merge ref against current main ( |
The merge ref now points at current main ( |
Merge evidence for head
|
Part of #8 (W2 nested subagents, item 5b: family capacity in the sidebar). This is the server half. The sidebar badges follow in a separate PR that stacks on #104.
With
fork-nested-subagentson,GET /api/v2/chats/fork/{chat}/familyreturns the subagent capacity of the family under a root chat:{ "live_subagents": 3, "max_live_subagents": 6, "waiting_for_capacity": ["<chat id>"] }With the experiment off, the route answers 403 like the other fork routes.
Why. The sidebar needs two facts that no chat response carries. The first is whether a running subagent waits for a concurrency slot. Today only
list_agentsand a single-chat GET (queued_for_capacity) report that, one chat at a time. The second is whether the family is at its live subagent limit, which makes the next spawn ormessage_agentresume fail. Computing either for every descendant on every sidebar list call would cost several queries per chat, so the sidebar asks once per family instead.Change.
Server.ForkChatFamilyCapacity(newcoderd/x/chatd/fork_family.go) reuses the admission rules. It reads the organization's effective limits (subagentLimits, upstream pool cap throughsubagentPoolLimit), counts live subagents withCountLiveSubagentsInFamily, and runsCountActiveSubagentsForCapacityplussubagentCapacityFullper candidate. That is the same checkforkChatQueuedForCapacitymakes for one chat.GetFamilySubagentsAwaitingWorker, prefilters the candidates: the unarchived running subagents of the family that no worker with a fresh heartbeat owns, with the heartbeat predicate ofGetChatAwaitingWorker. Only those get the per-chat count. With no concurrency limit set, the method skips both queries. The dbauthz wrapper authorizes through the root chat, likeCountLiveSubagentsInFamily, and dbmetrics gets its timing wrapper.coderd/fork_chat_family.go, one route infork_chat_routes.go) reads the chat throughExtractChatParam, so only callers who can read the root get an answer. A child chat gets 400. The counts run as chatd because they span other users' chats.codersdk.ForkChatFamilyCapacityand the client method, plus the generated TypeScript type and swagger. The endpoint isx-apidocgenskip like the other fork chat routes. Onlyschemas.mdgains the type, and the generated enum-order drift thatcheck-apidoc.shignores is left out.Validation
TestForkChatFamilyCapacity(chatd, real Postgres in Colima): a family whose only per-family slot is held by a worker-owned subagent reportslive_subagents: 2,max_live_subagents: 5and the unowned running sibling as waiting. After the holder's heartbeat is gone, nothing waits.TestForkChatFamilyCapacity(coderd):Enabledreturns the live count and the deployment live limit for a root with one paused and one finished subagent, 400 for a child, and 404 for another member.Disabledreturns 403.TestForkQueriercovers the new dbauthz wrapper.TestForkChatRoutes,EndpointsDocumented|TestSwagger,.github/fork/check-apidoc.sh,forkdb/generate.sh(no diff) andgo veton the touched packages also pass.