Skip to content

pstack W2: nested subagents #8

Closed

Description

@ibetitsmike

Xum created this issue on behalf of @ibetitsmike.

Part of #4.

Workspace brief from the pstack parity plan (local plan page "Running pstack on the Coder Agents Fork"; the PRD is local to Mike's Mac and not reproduced here). Claim numbers such as 1.3 or shared.2 refer to the plan page.

W2 · Nested subagents · mike/nested-subagents

Task. Let general and custom children spawn children (PRD 6.3) and make capacity configurable (R2.6).

Background. Three server checks and one UI assumption stop nesting: validateSubagentSpawnParent (subagent_catalog.go:254-262), a second copy in createChildSubagentChatWithOptions (subagent_operations.go:317-319), spawn tools only in appendRootChatTools (turn_environment.go:724, :2607), and the sidebar tree at depth 1 (chatTree.ts:40-43). Archive from the root already covers every depth: GetChatFamilyIDsByRootID uses root_chat_id (chats.sql:368). Archive of a non-root chat returns ErrArchiveRequiresRootChat (chat_mutations.go:519-521). SetArchived is allowed only from waiting and error states (chatstate/transition.go:59-76), and an interrupted chat returns to waiting only after FinishInterruption (transition.go:134-138), so interrupt then archive cannot be one transaction. Interrupt acts on one chat (chat_mutations.go:870). isSubagentDescendant (subagent_operations.go:671) lets a parent reach any descendant, which R3.3 narrows to direct children.

Scope.

  1. Depth: store depth in chat_subagents; default max 2, deployment option and organization setting; the error names the limit; explore and computer_use stay leaves.
  2. Tools for non-root chats under the max depth; list_agents, wait_agent, message_agent, interrupt_agent act on direct children (R3.3).
  3. Interrupt cascade from any chat to its subtree, leaves first, through a forkdb GetChatSubtreeIDs query on parent_chat_id. Archive stays root-only, as today: it interrupts the family, waits (bounded) for every interrupt to finish, then calls SetFamilyArchived (family.go:58) once.
  4. Capacity: organization and family caps beside the deployment defaults (agentadmission.go:11-13; Enterprise unlock enterprise/coderd/coderd.go:226). Upstream GetChatQueuedForCapacity (chats.sql:3205-3240, called at chatd.go:1571) counts only deployment-wide pools, so W2 adds a forkdb count query run inside Admit (agentadmission.go:28) through the W0 transaction accessor. R3.2 live-descendant cap. list_agents shows "waiting for capacity".
  5. UI tree for depth above 1. R3.7 is done upstream (chathooks/trigger.go:58-69 sets ParentChatID and RootChatID): add a test for a depth-2 payload only.
  6. After W0's question-stack merge (no wait for upstream): R8.2 descendant questions surface in the root; R8.3 secret answers.

Acceptance (PRD 6.3).

  • A depth-2 family (root, coordinator, worker) completes; the worker's result reaches the root through the coordinator.
  • A spawn at the limit fails with an error that names the limit.
  • Archiving the root while a grandchild runs interrupts the family, then archives every member in one SetFamilyArchived transaction.
  • Interrupting the coordinator interrupts its workers and leaves the root running.
  • A child over capacity shows "waiting for capacity" in list_agents.

Constraints. Experiment fork-nested-subagents. Keep root-first lock order. Check that memoryIndexMessage skipping children (memory.go:88) still meets R3.6; if not, resolve memory from the root.


Rules for every workspace

Topic Rule
Runner One Xum workspace per brief (W0 runs as W0a and W0b), started from fork main at its wave start. Every implementation runs implement-flow with the workstream issue as its input and the brief as the plan.
Branches mike/<topic> for the workspace; stacked PR branches mike/<topic>-<n>-<slug>. Local name equals remote name. Never push to main.
PR size 500 changed lines at most per PR, generated code excepted (reviewer-friendly-pr). Stack with gh stack; the extension is not installed on the Mac today (gh extension install github/gh-stack), else use explicit-base PRs.
Schema Fork tables are chatd graph nodes: go run ./coderd/database/migrations/chatdmig/cmd/chatdmig new <name> -requires <node or upstream:name>. Never edit a node that ran. No edits to dump.sql, queries.sql.go, querier.go, dbmock or numbered migrations.
Queries coderd/database/forkdb only (created by W0). Every method goes through the forkdb authz wrapper. A forkdb write that belongs with an upstream write runs in the same transaction, through the W0 accessor (database.Store exposes only InTx, coderd/database/db.go:22-31).
Authorization Chat-owned rows authorize through the owning chat (dbauthz.go:6513-6522 pattern). Agent and plugin rows reuse the skill RBAC objects. No new RBAC resources, no new API key scopes. Tools run as the chatd subject, which can read and update every chat (dbauthz.go:807-817): a tool that touches a chat other than its own runs as the owner (asOwner, chattool/listtemplates.go:437-443).
Upstream files One hook line per hot file (plan shared.2). Logic lives in new fork files. Hot files: turn_environment.go, chatd.go, subagent*.go, codersdk/chats.go, deployment.go, dbauthz.go, chat_routes.go, AgentChatInput, AgentChatPageView.
Open upstream PRs If a workspace needs an open coder/coder PR, W0 or W7 merges its branch into the fork with a merge commit. Its migrations go through chatdmig route into the chatd schema. Sync conflicts are solved later (Mike, 2026-11-08).
Flags Each feature is behind its fork-* experiment in codersdk/fork_experiments.go. With the flag off, tool lists, routes and UI match upstream.
API Swagger annotations on new public endpoints. Audited types update enterprise/audit/table.go.
chatd docs coderd/x/chatd/ARCHITECTURE.md gets TODO lines only. Mike writes the text.
Validation Go suites run in Colima: a postgres:17 container, plus golang:<go.mod version>-bookworm --network container:<pg> with volumes coder-gen-gomod and coder-gen-gocache and postgresql-client-17 from PGDG. chatdmig tests use CHATDMIG_TEST_DATABASE_URL='postgres://[email protected]:5432/postgres?sslmode=disable'. Never create a postgres role on the live Postgres. Frontend: site/AGENTS.md commands plus frontend-deep-review for any site/ diff.
Review implement-flow ends with codex-review-loop; Codex is installed (2026-11-08). If @codex review gets no reply within 30 minutes, tell the lead and run code-quality-review with Opus until Codex answers. Mike (2026-11-09): fix real defects in the PR's own change; drop scope creep and defensive bikeshedding with a one-line reply and a resolved thread, no follow-up issue. Upstream is only a sync source: never report or file anything upstream.
UAT coder-agents-uat through Coder MCP on the local deployment (http://127.0.0.1:3000, templates devcontainer or docker, RUNBOOK "Running a branch in a dev container workspace"). The remote agent runs scripts/develop.sh for the branch inside its workspace (plan decision uat). Never coder-local use a branch build: that replaces Mike's daily server.
Ready When a PR meets the merge bar, send the lead (task_send_message to 8ac7791132) READY #<pr> <head sha> with the CI, Codex, UAT and open-thread evidence, then wait. Never merge yourself.
Merge The lead merges (Mike, 2026-11-08). Merge bar: green fork-ci on the exact head, a clean Codex verdict, or Codex findings that were all fixed or dropped under the scope rule (the lead confirms each drop), no unresolved threads, UAT PASS on the head or on a SHA whose later commits only answer review, and a lead review of the diff against the brief. Squash, except sync and upstream stack PRs, which take a merge commit. A merge to fork main deploys Mike's daily server through autodeploy within about 5 minutes plus a drain of up to 30 minutes, so the lead merges one PR at a time and waits until Fork ops reports the deploy healthy. Experiments stay off on that server until Mike enables them.
Follow-ups A defect in merged code or on the daily server becomes an issue in ibetitsmike/coder with label followup. Fork ops triages it; an accepted one gets its own workspace running implement-flow.

Activity

  1. added
    pstack-parity
    on Nov 8, 2026
  2. ibetitsmike commented on Nov 9, 2026

    @ibetitsmike
    OwnerAuthor

    Note

    Xum posted this for Mike.

    PR 1 (depth and limit) is open: #33. Next: spawn tools for non-root chats and direct-children narrowing.

  3. ibetitsmike commented on Nov 9, 2026

    @ibetitsmike
    OwnerAuthor

    Note

    Xum posted this for Mike.

    PR 2 (spawn tools for non-root chats, direct-children targeting, full ancestor chain) is open: #37, stacked on #33.

  4. ibetitsmike commented on Nov 9, 2026

    @ibetitsmike
    OwnerAuthor

    Xum posted this on behalf of @ibetitsmike.

    W2 status: READY sent for #33 (depth + limit) at 3454d7e. #37 (tools for non-root chats) green on dispatched fork-ci; READY follows once #33 merges and #37 targets main.

  5. ibetitsmike commented on Nov 9, 2026

    @ibetitsmike
    OwnerAuthor

    Xum posted this on behalf of @ibetitsmike.

    W2 status: opened #42 (PR 3, interrupt cascade + archive of an active family), stacked on #37. #33 merged.

  6. ibetitsmike commented on Nov 9, 2026

    @ibetitsmike
    OwnerAuthor

    Xum posted this on behalf of @ibetitsmike.

    W2 status: READY sent for #37 (tools for non-root chats) at 2933ad4.

  7. ibetitsmike commented on Nov 9, 2026

    @ibetitsmike
    OwnerAuthor

    Xum commented on behalf of @ibetitsmike.

    W2 status: opened #45 (PR 4, organization subagent limits; enforces the org max_depth), stacked on #42 and #37. #37 is READY and waiting in the merge queue. #42 stays stacked until #37 merges. Next is PR 5, which enforces the capacity limits.

  8. ibetitsmike commented on Nov 9, 2026

    @ibetitsmike
    OwnerAuthor

    Xum commented on behalf of @ibetitsmike.

    W2 status: opened #47 (PR 5, subagent concurrency limits per deployment, organization and family), stacked on #45. #37 merged main after #38 and is re-running CI. Next is PR 6, which enforces max_live_per_family.

  9. ibetitsmike commented on Nov 9, 2026

    @ibetitsmike
    OwnerAuthor

    Xum commented on behalf of @ibetitsmike.

    W2 status: #37 merged main after #38 (head f5b5941, fork-ci green, patch unchanged apart from one ARCHITECTURE.md TODO context line). READY re-sent.

  10. ibetitsmike commented on Nov 9, 2026

    @ibetitsmike
    OwnerAuthor

    Xum commented on behalf of @ibetitsmike.

    W2 status: opened #49 (PR 6, live subagent limit per family, refused at spawn), stacked on #47. Next: the waiting_for_capacity state in list_agents.

  11. ibetitsmike commented on Nov 9, 2026

    @ibetitsmike
    OwnerAuthor

    Xum commented on behalf of @ibetitsmike.

    W2 status: #37 merged. Restacked onto main: READY sent for #42 at 76cda6f; #45 is current at 22f0565 with a clean Codex review; #47 got a fix for a subagent pool deadlock (10e310a), and #49 now also checks the live limit on message_agent resume.

  12. ibetitsmike commented on Nov 9, 2026

    @ibetitsmike
    OwnerAuthor

    Xum commented on behalf of @ibetitsmike.

    W2 status: #42 merged. #57 (PR 7, report subagents waiting for a concurrency slot) opened, stacked on #49.

  13. ibetitsmike commented on Nov 9, 2026

    @ibetitsmike
    OwnerAuthor

    Xum commented on behalf of @ibetitsmike.

    #45 (PR 4, org subagent limits) READY at 97544ab: Codex clean, fork-ci green.

  14. ibetitsmike commented on Nov 9, 2026

    @ibetitsmike
    OwnerAuthor

    Xum commented on behalf of @ibetitsmike.

    #47 (PR 5, subagent concurrency caps) READY at 390011f: Codex clean, fork-ci green, UAT round 2 passed.

  15. ibetitsmike commented on Nov 9, 2026

    @ibetitsmike
    OwnerAuthor

    Xum commented on behalf of @ibetitsmike.

    #47 (fair subagent capacity acquisition) READY at 0e846e7: CI green, Codex clean.

  16. 8 remaining items

  17. ibetitsmike commented on Nov 10, 2026

    @ibetitsmike
    OwnerAuthor

    Xum commented on behalf of @ibetitsmike.

    W2: #99 (nested descendants in chat list/GET) READY at 83e25a4. Merge after #104.

  18. ibetitsmike commented on Nov 10, 2026

    @ibetitsmike
    OwnerAuthor

    Xum commented on behalf of @ibetitsmike.

    W2: #104 (agent tree for depth>1 in the sidebar) READY at ab7392f. Merge before #99.

  19. ibetitsmike commented on Nov 10, 2026

    @ibetitsmike
    OwnerAuthor

    Xum commented on behalf of @ibetitsmike.

    W2: #109 opened (item 5b server half: family capacity endpoint for the sidebar badges).

  20. ibetitsmike commented on Nov 10, 2026

    @ibetitsmike
    OwnerAuthor

    Xum commented on behalf of @ibetitsmike.

    W2: #104 (agent tree for depth>1 in the sidebar) merged as 4b124f4. #99 next.

  21. ibetitsmike commented on Nov 10, 2026

    @ibetitsmike
    OwnerAuthor

    Xum commented on behalf of @ibetitsmike.

    W2: #99 (nested descendants in chat list/GET) merged as 26c1e02. #109 next.

  22. ibetitsmike commented on Nov 10, 2026

    @ibetitsmike
    OwnerAuthor

    Xum commented on behalf of @ibetitsmike.

    W2: #109 (family capacity endpoint) READY at d32bb19.

  23. ibetitsmike commented on Nov 10, 2026

    @ibetitsmike
    OwnerAuthor

    W2: #109 (family capacity endpoint) merged as bfac64b.

    Xum commented on behalf of @ibetitsmike.

  24. ibetitsmike commented on Nov 10, 2026

    @ibetitsmike
    OwnerAuthor

    W2: opened #116 (sidebar family capacity markers, 5b-2 UI).

    Xum commented on behalf of @ibetitsmike.

  25. ibetitsmike commented on Nov 10, 2026

    @ibetitsmike
    OwnerAuthor

    W2: #116 (sidebar family capacity markers) READY at b26b7d5.

    Xum commented on behalf of @ibetitsmike.

  26. ibetitsmike commented on Nov 10, 2026

    @ibetitsmike
    OwnerAuthor

    W2: #116 (sidebar family capacity markers) merged as 4c0cf8c.

    Xum commented on behalf of @ibetitsmike.

  27. ibetitsmike commented on Nov 10, 2026

    @ibetitsmike
    OwnerAuthor

    W2: opened #127 (child chat top bar: waiting for a subagent slot).

    Xum commented on behalf of @ibetitsmike.

  28. ibetitsmike commented on Nov 10, 2026

    @ibetitsmike
    OwnerAuthor

    W2: #127 (child chat top bar: waiting for a subagent slot) READY at e6dbd96.

    Xum commented on behalf of @ibetitsmike.

  29. ibetitsmike commented on Nov 10, 2026

    @ibetitsmike
    OwnerAuthor

    W2: #127 (child chat top bar: waiting for a subagent slot) merged as 7161027.

    Xum commented on behalf of @ibetitsmike.

  30. ibetitsmike commented on Nov 15, 2026

    @ibetitsmike
    OwnerAuthor

    Coder Agents acted on behalf of @ibetitsmike.

    Closing as done, per Mike's decision on #219 (2026-11-15). Every PR this issue lists is merged; evidence: #4 (comment)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    pstack-parity

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions