Skip to content

feat(coderd/x/chatd): archive one child subtree with archive_agent - #281

Merged
ibetitsmike merged 6 commits into
mainfrom
mike/issue-249-archive-child
Nov 13, 2026
Merged

ibetitsmike merged 6 commits into
mainfrom
mike/issue-249-archive-child

Conversation

@ibetitsmike

@ibetitsmike ibetitsmike commented Nov 13, 2026 •

Copy link
Copy Markdown
Owner

Coder Agents opened this PR on behalf of @ibetitsmike.

Closes #249

What changed

With fork-nested-subagents on, a chat that has interrupt_agent also gets archive_agent. It archives one direct child and all of that child's descendants for good, so a parent can retire a child subtree without archiving the root.

  • archive_agent takes the child's chat_id. Any chat that is not a direct child of the caller is refused with chat_id must be a direct child of this chat.
  • It interrupts the child (which cascades to its descendants) and waits up to 30 seconds, with the same settle loop the root archive uses (settleChatsForArchive, split out of forkArchiveActiveFamily).
  • One transaction locks the root FOR NO KEY UPDATE, then the child's descendants leaves first, then the child (lockSubtreeForArchive, split out of lockFamilyForArchive), and applies SetArchived(true) to each member not archived yet. A busy member fails the whole call and archives nothing. Wake-ups of archived chats are canceled with fork-chat-wakeups, as in a family archive.
  • With fork-subagent-isolation on, it reuses the root archive cleanup: cleanupArchivedSubagents is split into removeArchivedSubagentWorktrees and stopArchivedSubagentWorkspaces. The worktree removal runs before the tool returns and lists kept worktrees in kept_worktrees. Workspace stops run in the background. The root archive path still posts its notice.
  • Archived chats leave list_agents and the live subagent count, so a family at its live limit can spawn again. Only archiving and then unarchiving the root brings them back.
  • archive_agent is in unbilledSubagentToolNames, like the other subagent tools, so its wait is not billed.
  • archive_agent is part of the Task alias in custom agent tool policies.
  • No new experiment. No site change: the generic tool card renders the call.
  • Docs: docs/fork/pstack-adapter.md no longer says only a root archive cleans up, and coderd/x/chatd/ARCHITECTURE.md describes the subtree archive.

#278 (list descendants) merged first. This branch merges main after it, with a merge commit.

Tests

  • cd coderd/x/chatd && flock ~/.fork-go.lock go test -count=1 -run 'TestForkArchiveAgent' -v . passes:
    • ArchivesOneChildSubtree: root with two worktree children (one with a worktree grandchild) archives one child. The child and grandchild worktrees and branches are removed, the sibling and root stay unarchived, list_agents lists only the sibling, and no root notice is posted.
    • ReportsKeptWorktree: a dirty worktree is kept and reported with the agent's reason. A later root archive tries it again and lists it in the root notice.
    • StopsChildWorkspace: only the archived child's workspace is stopped.
    • OnlyDirectChildren: grandchild, sibling, parent, self and unknown IDs are refused. A child archives its own grandchild, and a later archive of the child skips it. Archiving and then unarchiving the root brings every chat back.
    • ExperimentOff: no archive_agent without fork-nested-subagents.
    • TestForkArchiveAgentFreesLiveLimit: with max_live_per_family 1, archiving a running child lets a second spawn succeed, and message_agent to the archived child fails.
  • TestUnbilledSubagentToolNamesMatchCatalog passes with archive_agent in the unbilled set.
  • After merging main (with feat(coderd/x/chatd): list a chat's descendants with list_agents #278): TestForkArchiveAgent|TestForkListAgentsDescendants|TestUnbilledSubagentToolNamesMatchCatalog|TestForkArchiveWorktreeCleanup|TestForkArchiveStopsSubagentWorkspaces|TestNestedArchiveActiveFamily|TestNestedInterruptCascade|TestCustomAgentToolPolicy|TestForkSetFamilyArchived|TestNestedSubagent pass, and go vet ./coderd/x/chatd/ is clean.
  • With the hook in fork_tools.go removed, 4 of these fail (ExperimentOff passes, as expected).
  • Regression: TestForkArchiveWorktreeCleanup|TestForkArchiveStopsSubagentWorkspaces|TestNestedArchiveActiveFamily|TestNestedInterruptCascade|Lock|TestCustomAgent|ToolPolicy|TestNestedSubagent and TestCustomAgentToolPolicy|TestForkSetFamilyArchived|TestAutoArchive|TestArchive|TestUnarchive pass.
  • golangci-lint run --fix=false ./coderd/x/chatd/ reports nothing in changed files. make lint/emdash, make lint/docs-html, make lint/architecture pass. markdownlint-cli2 is clean on pstack-adapter.md; ARCHITECTURE.md has the same 10 findings as main.

Not verified

  • No live chat in a deployed server, and no real workspace agent: the worktree and workspace paths use the test fakes.
  • No Vale run.

@ibetitsmike

Copy link
Copy Markdown
Owner Author

Coder Agents acted on behalf of @ibetitsmike.

@codex review

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 13, 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-13T22:21:54.064156Z 6fa9fda 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: 3a446d2c78

ℹ️ 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_archive_agent.go Resolved
@ibetitsmike

Copy link
Copy Markdown
Owner Author

Coder Agents acted on behalf of @ibetitsmike.

@codex review

@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: 72e229144f

ℹ️ 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_tools.go Resolved
@ibetitsmike

Copy link
Copy Markdown
Owner Author

Coder Agents acted on behalf of @ibetitsmike.

Merged main after #278 and fixed the unbilled tool finding. @codex review

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Nice work!

Reviewed commit: 6fa9fda2f7

ℹ️ 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
ibetitsmike merged commit db48523 into main Nov 13, 2026
10 checks passed
@ibetitsmike
ibetitsmike deleted the mike/issue-249-archive-child branch November 13, 2026 22:36
@ibetitsmike

Copy link
Copy Markdown
Owner Author

Coder Agents acted on behalf of @ibetitsmike.

Merged as db485236c5 (squash of 6fa9fda2f7) by the Coder Agents maintainer, after #278 (b1a5e2f442) was live on the daily server.

Gates checked on head 6fa9fda2f7a11dda3218580cb661fec8abed4e02:

  1. Head pinned with --match-head-commit; main asserted at b1a5e2f442 in the same script.
  2. Every check run on the head passed; fork-ci run 43518172128 on this head: success.
  3. Codex receipt on this head: feat(coderd/x/chatd): archive one child subtree with archive_agent #281 (comment)
  4. 0 unresolved review threads (2 Codex P2 threads, both fixed: the unarchive docs in 72e229144f and the billing regression in a6526b6b69).
  5. Behind main by 0.
  6. The maintainer ran go test -count=1 -v -run 'TestForkArchiveAgent|TestForkListAgentsDescendants|TestUnbilledSubagentToolNamesMatchCatalog|TestForkArchiveWorktreeCleanup|TestForkArchiveStopsSubagentWorkspaces|TestNestedArchiveActiveFamily|TestNestedInterruptCascade|TestForkSetFamilyArchived|TestAutoArchive|TestArchive|TestUnarchive' ./coderd/x/chatd/ on the exact head: all passed, including ArchivesOneChildSubtree, ReportsKeptWorktree, StopsChildWorkspace, OnlyDirectChildren and ExperimentOff.

Not exercised: a live chat calling archive_agent on the deployed server with a real worktree or workspace child. The tests use fakes. The diff is 586 lines, 269 of them tests.

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.

chatd: archive one child subtree and list descendants from a parent chat

1 participant