Skip to content

feat(coderd): cascade interrupts and archive active nested subagent families - #42

Merged
ibetitsmike merged 26 commits into
mainfrom
mike/nested-subagents-3-cascade
Nov 9, 2026
Merged

ibetitsmike merged 26 commits into
mainfrom
mike/nested-subagents-3-cascade

Conversation

@ibetitsmike

Copy link
Copy Markdown
Owner

Xum opened this PR on behalf of @ibetitsmike.

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

With fork-nested-subagents on, stopping a chat stops its whole subtree, and archiving a root whose family is still working no longer fails. With the experiment off, interrupt and archive behave exactly as upstream: no fork queries, no cascade, and archiving an active family returns upstream's 409.

  • Interrupt cascade. InterruptChat (the Stop button, POST /chats/{chat}/interrupt, interrupt_agent) first interrupts every active descendant of the chat, leaves first, through the new forkdb query GetChatSubtreeIDs (recursive walk on parent_chat_id). Interrupting an idle chat whose descendants were running now succeeds instead of returning "transition not allowed". interrupt_agent on an idle child also stops that child's running descendants.
  • Archive of an active family. Before SetFamilyArchived, a root archive interrupts the family, waits up to 30 seconds until no member is running, interrupting or requires_action (state-update pubsub plus a fallback ticker), then archives every member in the one upstream SetFamilyArchived transaction, which keeps the root-first lock order. If the family does not settle in time, the archive fails with upstream's error. paused members keep upstream's refusal.
  • Upstream files get hook lines only (chat_mutations.go, one line in subagent_operations.go); the logic is in fork_cascade.go. ARCHITECTURE.md gets only a TODO for the author.
Validation
  • Full go test ./coderd/x/chatd/ with real Postgres (Colima), ./coderd/database/forkdb/..., TestForkQuerier, ./coderd/ -run 'TestArchiveChat|TestInterruptChat'; forkdb/generate.sh leaves no diff; chatdmig check.
  • New tests: TestGetChatSubtreeIDs, TestNestedInterruptCascade (subtree, idle interrupt_agent target, experiment off), TestNestedArchiveActiveFamily (a running, worker-owned grandchild settles and the family archives; a stuck family times out to upstream's error with nothing archived, on a mock clock; experiment off). Negative controls: removing each hook or experiment gate made the matching test fail.
  • UAT on a disposable dev deployment with a local model: stopping the root of a root, coordinator and worker family with a busy worker left every member idle; archiving a root while its grandchild ran returned success and archived all three; with the experiment off the same archive returned 409.
  • fork-ci triggers only on PRs to main, so CI for this stacked PR runs through workflow_dispatch on the branch until feat(coderd): give nested general subagents the subagent tools, direct children only #37 merges.

…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
@ibetitsmike

Copy link
Copy Markdown
Owner Author

@codex review

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 9, 2026 •

Copy link
Copy Markdown
Codex Review Summary: ✅ Completed

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-09T10:57:36.528047Z 18c26ed Manual request
ℹ️ 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" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 18c26edfed

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

Comment thread coderd/x/chatd/fork_cascade.go Resolved
Comment thread coderd/x/chatd/fork_cascade.go Resolved
Comment thread coderd/x/chatd/ARCHITECTURE.md Resolved
@chatgpt-codex-connector

Copy link
Copy Markdown

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

Reviewed commit: 18c26edfed

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

…-3-cascade

# Conflicts:
#	coderd/x/chatd/ARCHITECTURE.md
#	coderd/x/chatd/fork_tools_internal_test.go
@ibetitsmike
ibetitsmike merged commit f0e3940 into main Nov 9, 2026
9 checks passed
@ibetitsmike
ibetitsmike deleted the mike/nested-subagents-3-cascade branch November 9, 2026 13:46
@ibetitsmike

Copy link
Copy Markdown
Owner Author

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

Merge evidence at head 76cda6ff5f:

  • fork-ci pull_request run 42612744952 green on this head (all checks pass), MERGEABLE/CLEAN, 0 of 3 review threads unresolved.
  • Codex receipt clean on 18c26edfed. The only later change is a merge of main; git diff origin/main...76cda6ff5f matches the reviewed patch except for one blob index line, so the receipt and the UAT on that patch (stop cascade, archive with a running grandchild, experiment off 409) stand.
  • Lead review of the diff: the cascade and archive paths are gated on fork-nested-subagents; GetChatSubtreeIDs authorizes through the subtree's root chat.
  • Merged after f015332553 deployed healthy locally; merge-tree against current main was clean.

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