Skip to content

fix(subagents): surface worktree cleanup failures - #258

Merged
somewan820 merged 4 commits into
openpi-dev:mainfrom
627150795:fix/issue-73-worktree-cleanup
Aug 29, 2026
Merged

somewan820 merged 4 commits into
openpi-dev:mainfrom
627150795:fix/issue-73-worktree-cleanup

Conversation

@627150795

@627150795 627150795 commented Aug 28, 2026 •

Copy link
Copy Markdown
Contributor

Problem

When a Subagent spawn aborts after creating an isolated worktree, cleanup failures were swallowed. The user could see the original spawn error but not that a checkout or branch remained for recovery.

Value

A failed spawn now preserves the original error while exposing the cleanup warning or failure and the recovery location. This prevents orphaned work from becoming silent state.

Approach

Format every incomplete WorktreeCleanup result into a visible warning, including a retained branch when no textual cleanup reason is available; report thrown cleanup failures without hiding the spawn error; and add focused tests for preserved checkouts, leftover branches, and complete cleanup. The change covers only this cleanup-observability slice of #73.

Validation

  • git diff --check: passed
  • bun run lint: passed
  • bun run typecheck: passed
  • formatWorktreeCleanupWarning self-check: passed
  • worktree test suite with core.autocrlf=false: 25 passed, 0 failed
  • default Windows core.autocrlf=true: 24 passed, 1 existing line-ending assertion mismatch (the unchanged test expects LF but checkout returns CRLF)
  • bun run format:check: existing repository-wide CRLF normalization failures; no formatting-only changes included

Impact

  • User-visible behavior: failed spawn errors now include cleanup/recovery information.
  • Model-visible context/tools: no schema change.
  • Runtime/lifecycle: cleanup failures are observable; normal cleanup behavior is unchanged.
  • Persisted config/data: none.
  • Compatibility/risk: narrow error-path change; the original spawn failure remains the primary cause.

Part of #73

@627150795

Copy link
Copy Markdown
Contributor Author

行为复核更新(2026-08-29):发现并修复一个真实漏报路径。worktree 已删除但子代理在自己的分支上产生了提交时,清理结果可能是 removed=true、branchDeleted=false、reason 为空;之前的提示函数会返回空,导致用户看不到仍需恢复的分支。现在只要未同时完成 checkout 和 branch 清理,就会明确提示保留位置/分支。

本地验证:

  • 新增无 reason 的 retained-branch 回归用例
  • worktree 测试:关闭 Windows 行尾转换后 25/25 通过
  • bun run lint:通过
  • bun run typecheck:通过
  • git diff --check:通过

修复已同步到 PR #258,最新提交 3dfe2b5;原有 dirty/ignored/detached 保留语义没有改变。

@627150795

Copy link
Copy Markdown
Contributor Author

最终验证:最新提交 a4445cd 已通过远端 CI——Node 22.19.0、Node 24、Windows Background terminals 全部通过。之前的格式阶段失败来自文件末尾缺少换行,已修正;worktree 清理漏报修复仍由 3dfe2b5 保留。

@627150795
627150795 requested review from a team and tt-a1i as code owners August 29, 2026 04:57
@627150795
627150795 force-pushed the fix/issue-73-worktree-cleanup branch from 6cbfc92 to fec084b Compare August 29, 2026 05:01
@627150795

Copy link
Copy Markdown
Contributor Author

代码审计补丁已追加到本 PR:

  • 发现 removed: false 同时覆盖“checkout 脏而保留”和“无法确认 checkout 状态”,旧提示会把未知状态误称为 checkout preserved。
  • 现在改为 checkout was not confirmed removed; inspect ...,不会给出错误的存在性结论;已有提交分支仍明确报告 branch ... remains。
  • 远程提交:fec084b。
  • 验证:worktree 定向测试 26/26 通过;远程 PR 文件差异已核对为原来的 3 个文件,Node 22、Node 24、Windows CI 正在运行。

@somewan820 somewan820 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

已完成静态审查。cleanup failure/warning 会保留原始 spawn error 的 cause,并明确指出 preserved checkout 或残留 branch;formatWorktreeCleanupWarning 有实际调用和覆盖测试。未发现 P0-P2 或死代码问题。P3:建议后续补充真实 spawn failure 与跨平台 git 输出的集成覆盖。未运行测试。

@somewan820
somewan820 force-pushed the fix/issue-73-worktree-cleanup branch from fec084b to b386a7a Compare August 29, 2026 12:35
@somewan820
somewan820 merged commit 6c43f92 into openpi-dev:main Aug 29, 2026
3 checks passed
agnitum2009 pushed a commit to agnitum2009/openpi that referenced this pull request Aug 29, 2026
* fix(subagents): surface worktree cleanup failures

* fix(worktree): report retained branches without reason

* style(subagents): terminate index file

* fix(worktree): avoid claiming unknown checkouts remain

(cherry picked from commit 6c43f92)
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.

2 participants