Skip to content

feat: summarize isolated subagent worktrees in wait_agent - #141

Merged
ibetitsmike merged 7 commits into
mainfrom
mike/subagent-isolation-5-wait-report
Nov 10, 2026
Merged

ibetitsmike merged 7 commits into
mainfrom
mike/subagent-isolation-5-wait-report

Conversation

@ibetitsmike

@ibetitsmike ibetitsmike commented Nov 10, 2026 •

Copy link
Copy Markdown
Owner

Xum opened this PR on behalf of @ibetitsmike.

Part of #9. Builds on #108 and #135 (both merged), which give a spawn_agent child with isolation: worktree its own git worktree and branch. Until now the parent had to inspect that branch itself to learn what the child did.

With experiment fork-subagent-isolation on, wait_agent on a worktree child now adds:

  • isolation, branch and worktree_path from the child's chat_subagents row, as spawn_agent already returns them.
  • diff_summary: commits, files_changed, insertions, deletions and uncommitted_changes, read from the child's workspace agent.
  • diff_summary_error instead, with the agent's reason, when the agent cannot be reached or refuses, for example summarize worktree: worktree /x does not exist or a dial failure.

A wait that times out reports the first three fields but skips the summary, since the child may still be changing its worktree. Shared children, and results that are errors, are unchanged. With the experiment off, nothing changes.

The summary is one request per wait_agent call, bounded at 30 seconds with the dial capped at the chatd dial timeout. There are no retries or fallbacks.

What the numbers mean

  • commits: commits on the worktree's HEAD that are on no other branch or remote, the same set the delete endpoint (feat: add worktree isolation to spawn_agent #108) refuses to drop.
  • files_changed, insertions, deletions: git diff --numstat from the parent of the oldest such commit (or HEAD without one, or the empty tree when that commit is a root) to the working tree. Uncommitted edits to tracked files count; untracked files do not. Binary files count as changed with no lines. Submodule changes count even when the repository's config ignores them, as in the status count. --numstat is used because --shortstat output is localized.
  • uncommitted_changes: paths in git status --porcelain, untracked files included.

The agent answers 409 when the worktree is not on the requested branch, since commits on another branch are not this branch's work.

Size: about 360 added production lines, 47 of them moved out of delete, and 255 test lines.

Code

  • agent/agentgit/fork_worktree_summary.go: POST /api/v0/git/worktrees/summary.
  • agent/agentgit/fork_worktrees.go: the linked-worktree path checks and the on-branch check of delete move into checkLinkedWorktree and onBranch, which summary also uses. Delete's responses are unchanged.
  • codersdk/workspacesdk/fork_worktrees.go: ForkWorktreeSummary, its request, and ForkWorktreeSummaryConn, a separate interface so older connection types still satisfy ForkWorktreeConn.
  • coderd/x/chatd/fork_isolation_report.go: wraps wait_agent, enabled from appendForkTools.
  • coderd/x/chatd/ARCHITECTURE.md: a TODO for the report.

Tests

  • TestForkWorktreeSummary (agent, real git): a clean worktree is all zeros; two commits plus an uncommitted edit, a binary file and an untracked file give the expected counts; commits that another branch holds count as zero; a root commit diffs against the empty tree.
  • TestForkWorktreeSummarySubmoduleIgnoredByConfig: a committed submodule bump counts as one changed file when submodule.sub.ignore is all.
  • TestForkWorktreeSummaryRejects: a removed worktree is 404 and a worktree on another branch is 409.
  • TestForkIsolationWaitAgentReport (chatd, fake agent connection): a worktree child gets the fields and the summary for its stored path and branch; an agent error becomes diff_summary_error with the agent's message; a wait that times out on a running child gets the fields but no summary request; a shared child that has a chat_subagents row gets nothing and no agent call.

Negative controls, each reverted after the run, each make a named test fail: dropping the empty-tree fallback, dropping the branch --exclude, diffing to HEAD instead of the working tree, dropping the on-branch check, dropping --ignore-submodules=none from the diff, not wiring the wrapper, returning the raw SDK error, and dropping the isolation check, and requesting the summary on a timed-out wait.

UAT

On the :3200 branch server and workspace agent at 61c288e, with a real model, a root chat spawned a worktree child and a shared child. The worktree child committed a two-line file and left an untracked file. wait_agent on it returned its branch and worktree path and diff_summary {commits: 1, files_changed: 1, insertions: 2, deletions: 0, uncommitted_changes: 1}, which matches git rev-list, git diff --numstat and git status run in that worktree. wait_agent on the shared child returned none of the new fields. The main checkout stayed on main and clean. The later fixes (a diff flag for submodules, and skipping the summary on a timed-out wait) are covered by their tests.

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 10, 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-10T13:15:28.607158Z a6235c5 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.

@ibetitsmike

Copy link
Copy Markdown
Owner Author

@codex review

Xum posted this on behalf of @ibetitsmike.

@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: 61c288ebd0

ℹ️ 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/ARCHITECTURE.md Resolved
Comment thread agent/agentgit/fork_worktree_summary.go Resolved
@ibetitsmike

Copy link
Copy Markdown
Owner Author

@codex review

Xum posted this on behalf of @ibetitsmike.

@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: f68de5628f

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

Copy link
Copy Markdown
Owner Author

@codex review

Xum posted this on behalf of @ibetitsmike.

@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: a6235c57c5

ℹ️ 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 agent/agentgit/fork_worktree_summary.go Resolved
@ibetitsmike

Copy link
Copy Markdown
Owner Author

@codex review

Xum posted this on behalf of @ibetitsmike.

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. You're on a roll.

Reviewed commit: a6235c57c5

ℹ️ 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 (69f04bdfdf) and run fork-ci on it. The head is unchanged.

@ibetitsmike ibetitsmike reopened this Nov 10, 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 (69f04bdfdf), 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 reopened this Nov 10, 2026
@ibetitsmike
ibetitsmike merged commit 64965c9 into main Nov 10, 2026
27 of 35 checks passed
@ibetitsmike
ibetitsmike deleted the mike/subagent-isolation-5-wait-report branch November 10, 2026 14:49
@ibetitsmike

Copy link
Copy Markdown
Owner Author

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

Merge evidence for head a6235c57c5eeb7414637cbb6dff7c72a5e1595a6:

  • fork-ci pull_request run 42835445717 passed; its build job checked out Merge a6235c57c5 into 69f04bdfdf (current main). All checks green.
  • Codex on this exact head: no major issues (comment 6768302730). 0 unresolved review threads. Round 1 P1 (ARCHITECTURE.md TODO) and round 3 P2 (BaseCommit anchoring, needs an abnormal ref state or a concurrent rewrite plus a schema change) were dropped with replies; the submodule and timed-out wait P2s were fixed with regression tests.
  • UAT on :3200 at 61c288e passed: the worktree child's diff_summary (1 commit, 1 file, +2/-0, 1 uncommitted) matched git in that worktree, the shared child got no new fields, and cleanup was verified. The later commits are the two narrow fixes above, each with a test that fails without it.
  • Red/green: 7 negative controls on the initial diff, plus the submodule flag and timed-out skip controls.
  • No migration.

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