Skip to content

feat(coderd): report subagents waiting for a fork concurrency slot - #57

Merged
ibetitsmike merged 82 commits into
mainfrom
mike/nested-subagents-7-capacity-wait
Nov 9, 2026
Merged

ibetitsmike merged 82 commits into
mainfrom
mike/nested-subagents-7-capacity-wait

Conversation

@ibetitsmike

Copy link
Copy Markdown
Owner

Xum opened this PR on behalf of @ibetitsmike.

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

With fork-nested-subagents on, a subagent that a concurrency limit holds back now says so. With the experiment off, nothing changes.

  • Chat API. queued_for_capacity on a subagent chat now comes from the fork limiter, which owns subagent admission since feat: enforce subagent concurrency limits behind fork-nested-subagents #47. It is true when the subagent is running, no worker with a fresh heartbeat owns it, and the deployment, organization or family limit is full. The deployment limit includes upstream's subagent pool, counted without the subagent's ancestors, so the answer matches what the limiter admits. Root chats and the experiment-off path keep upstream's answer. This adds one hook statement to upstream's ChatQueuedForCapacity.
  • list_agents. Each listed child gets waiting_for_capacity: true while it waits for a slot. The field is omitted otherwise, and the output is unchanged when both fork-chat-todos and fork-nested-subagents are off. The existing forkListAgents hook in subagent.go now also passes the children.
  • Query. A new forkdb query GetChatAwaitingWorker uses the heartbeat predicate of upstream's GetChatQueuedForCapacity. It reads as chatd, with a dbauthz wrapper that checks chat read.
  • The cap comparison that admission uses moves into subagentCapacityFull and subagentPoolLimit, so admission and this report share it.
  • ARCHITECTURE.md gets only a TODO for the author.
Validation
  • Ran with real Postgres in Colima: the full go test ./coderd/x/chatd/, plus ./coderd/database/forkdb/..., ./coderd/database/dbauthz/, ./coderd/database/dbmetrics/ and ./coderd/database/migrations/chatdmig/.... forkdb/generate.sh leaves no diff.
  • New tests: TestGetChatAwaitingWorker (unowned, stale and fresh owners), TestForkQuerier/GetChatAwaitingWorker, TestForkChatQueuedForCapacity (only a running, unarchived, unowned subagent in a full family is queued; roots and the experiment-off server are not; slots free when owners go stale), TestForkChatQueuedForCapacityUpstreamPool (a child whose coordinator holds the only pool slot is not queued, where upstream would say it is; a subagent of another family is), and TestForkListAgentsWaitingForCapacity (the field appears only with fork-nested-subagents on). Each guarded condition was broken in turn and its test failed.
  • UAT at 75100dc in the disposable dev container: a family limit of 1, an organization limit of 1 across two families, and a deployment limit of 1 each held one child back with queued_for_capacity: true on the chat API and waiting_for_capacity: true in list_agents. Both cleared when the slot freed or the limit was raised, an interrupt cleared them, and with the experiment off nothing was reported. The later merge of feat: enforce the live subagent limit per family behind fork-nested-subagents #49 moved the upstream pool into the fork answer; a UAT round on the current head will follow in a comment.
  • fork-ci triggers only on PRs to main, so CI for this stacked PR runs through workflow_dispatch on the branch until it targets main.

…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.
…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
…' into mike/nested-subagents-7-capacity-wait
@ibetitsmike

Copy link
Copy Markdown
Owner Author

Xum commented on behalf of @ibetitsmike.

@codex review

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. 👍

Reviewed commit: 37959d5955

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

Xum commented on behalf of @ibetitsmike.

@codex review

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Keep it up!

Reviewed commit: de2b839de3

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

Xum commented on behalf of @ibetitsmike.

@codex review

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. More of your lovely PRs please.

Reviewed commit: ee92f26095

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

Resolved against #47's head 0e846e7 as the merge base, because main's
tree is exactly #47's merge with e2f73af.
@ibetitsmike

Copy link
Copy Markdown
Owner Author

Xum commented on behalf of @ibetitsmike.

@codex review

Base automatically changed from mike/nested-subagents-6-live-cap to main November 9, 2026 21:05
…ty-wait

Resolved against #49's head 86b7199 as the merge base, because main's
tree is exactly #49's head tree.
@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Already looking forward to the next diff.

Reviewed commit: 800ec50336

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

Xum commented on behalf of @ibetitsmike.

@codex review

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Already looking forward to the next diff.

Reviewed commit: 02af88abad

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

Xum (AI agent) closed and reopened this on behalf of @ibetitsmike.

Closing and reopening only to make GitHub recompute the merge ref against current main (20eb8dc198) and run fork-ci on it. The head is unchanged.

@ibetitsmike ibetitsmike closed this Nov 9, 2026
@ibetitsmike ibetitsmike reopened this Nov 9, 2026
@ibetitsmike

Copy link
Copy Markdown
Owner Author

Xum (AI agent) closed and reopened this again on behalf of @ibetitsmike.

The merge ref now points at current main (20eb8dc198), but the run started by the first reopen was queued against the old merge ref. This second reopen starts fork-ci on the recomputed merge. The head is unchanged.

@ibetitsmike ibetitsmike closed this Nov 9, 2026
@ibetitsmike ibetitsmike reopened this Nov 9, 2026
@ibetitsmike
ibetitsmike merged commit 0b00d9f into main Nov 9, 2026
20 of 27 checks passed
@ibetitsmike
ibetitsmike deleted the mike/nested-subagents-7-capacity-wait branch November 9, 2026 22:38
@ibetitsmike

Copy link
Copy Markdown
Owner Author

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

Merge evidence for head 02af88abad193a597689962a6ee1e8b485c888cf:

  • fork-ci pull_request run 42709955149 passed; its build job checked out Merge 02af88abad into 20eb8dc198 (current main, deployed and healthy at 22:36Z). All checks green.
  • Codex review on this exact head: no major issues. 0 unresolved review threads. Merge state CLEAN.
  • The patch is identical to the version that passed UAT round 2 (restack by merge, no rebase).

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