Skip to content

fix(worktree): verify exited PTYs before blocking deletion - #10106

Merged
nwparker merged 1 commit into
mainfrom
nwparker/woktree-rm-bug
Jul 23, 2026
Merged

nwparker merged 1 commit into
mainfrom
nwparker/woktree-rm-bug

Conversation

@nwparker

Copy link
Copy Markdown
Contributor

Description

On Windows, deleting a worktree could fail forever with:

Failed to physically stop every PTY for worktree

The failure occurred when the daemon had already killed the ConPTY, but one stop path lost/timed out on the acknowledgement and the duplicate fallback received Session not found. Teardown permanently latched those negative stop results even though the authoritative process inventory was already empty.

This change uses the existing teardown RPC margin for a fresh provider inventory when any stop reports failure:

  • deletion continues only when every failed exact PTY ID is confirmed absent;
  • stale runtime/provider/registry state is cleared only after that proof;
  • a still-live PTY, rejected inventory, or timed-out inventory continues to block deletion.

The behavior applies to local daemon PTYs and connection-scoped SSH providers without changing path matching, persistence, or the worktree removal API.

ELI5

Orca asks several systems to stop a terminal before deleting its folder. Sometimes Windows stops the terminal successfully, but one system misses the confirmation and says “I couldn't stop it.” Orca used to trust that stale answer forever.

Now Orca checks the live terminal roster one final time. If the terminal is definitely gone, deletion proceeds. If it is still there—or Orca cannot check safely—deletion remains blocked.

Evidence of fix

Reproduction first

  • Used Orca CLI against the awin Windows environment to create disposable worktrees and exercise deletion with a live PowerShell PTY and a long-running child process. Those baseline cases succeeded, narrowing the bug to stale/failed acknowledgement state rather than Windows paths or ordinary live processes.
  • Added a native-Windows regression with the same PTY represented across runtime, daemon inventory, and local registry.
  • Before the production change, the regression failed with the reported error:
AssertionError: promise rejected "Error: Failed to physically stop every PT…" instead of resolving
Caused by: Error: Failed to physically stop every PTY for worktree: repo-1::C:/Users/User/orca/workspaces/repo/feature
  • After the change, the same regression passes and requires a second authoritative inventory before deletion.

Automated verification

27/27  worktree teardown + Windows worktree-removal tests
199/199 worktree-removal IPC tests
226/226 targeted tests total

Also passed:

  • pnpm run typecheck:node
  • focused oxlint
  • focused oxfmt --check
  • pnpm run check:max-lines-ratchet
  • git diff --check

Adversarial review loop

  • First pass verified fail-closed behavior, cleanup ordering, concurrency, Windows daemon authority, SSH scoping, and unchanged macOS/Linux behavior.
  • Second pass found one P2 test-fidelity gap: the regression had disabled the local registry and therefore resembled SSH more than native Windows.
  • The test was corrected to include the same PTY in runtime, provider inventory, and local registry.
  • Re-review found no remaining issues.

User-facing regression list

Known user-facing regressions: none.

Explicitly checked:

  • Truly live PTYs still block destructive deletion.
  • Inventory errors and timeouts still fail closed.
  • One live PTY among several still blocks the whole removal.
  • SSH checks remain scoped to the target connection's provider.
  • macOS and Linux behavior is unchanged except for the same safety recheck after a reported stop failure.
  • No UI, schema, persistence, Git command, or keyboard behavior changed.

@coderabbitai

coderabbitai Bot commented Jul 23, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro Plus

Run ID: d84e2c4a-1446-4407-823a-88717888d0bf

📥 Commits

Reviewing files that changed from the base of the PR and between c445f26 and 52716ac.

📒 Files selected for processing (2)
  • src/main/runtime/worktree-teardown.test.ts
  • src/main/runtime/worktree-teardown.ts

📝 Walkthrough

Walkthrough

Worktree teardown now collects unsuccessful PTY stop attempts and rechecks provider inventory before declaring physical teardown failure. The verification uses the remaining deadline and treats query failures or unavailable sessions as unsuccessful verification. A Windows-specific test covers provider shutdown rejection followed by an empty PTY inventory and verifies zero teardown counts.

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Description check ⚠️ Warning The description is useful, but it doesn't follow the required template and omits Summary, Screenshots, Testing checklist, AI Review Report, Security Audit, and Notes. Rewrite the PR description using the repo template and add the missing sections, including screenshots/no visual change, testing checkboxes, AI review, security audit, and notes.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly describes the core change: rechecking PTY exit status before blocking worktree deletion.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@nwparker
nwparker merged commit c3620f0 into main Jul 23, 2026
1 of 2 checks passed
nwparker added a commit that referenced this pull request Jul 23, 2026
#10115)

- orca-runtime: 'stop cannot be proven' now requires the fresh PTY inventory
  to still show the pty live (empty inventory proves exit post-#10106).
- git-common-watch: swap worktrees dir->file synchronously so no poll tick
  observes the transient ENOENT window and fabricates a delete.


(cherry picked from commit e11736d7e170982eeebe09256eb549446a4f4f7b)

Co-authored-by: Orca <help@stably.ai>
enrick-dev pushed a commit to enrick-dev/orca that referenced this pull request Oct 15, 2026
enrick-dev pushed a commit to enrick-dev/orca that referenced this pull request Oct 15, 2026
stablyai#10115)

- orca-runtime: 'stop cannot be proven' now requires the fresh PTY inventory
  to still show the pty live (empty inventory proves exit post-stablyai#10106).
- git-common-watch: swap worktrees dir->file synchronously so no poll tick
  observes the transient ENOENT window and fabricates a delete.


(cherry picked from commit e11736d7e170982eeebe09256eb549446a4f4f7b)

Co-authored-by: Orca <help@stably.ai>
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