Skip to content

Fix clone abort cleanup ownership - #2981

Merged
Jinwoo-H merged 3 commits into
mainfrom
Jinwoo-H/bug-clone-abort-can-recursively-delete-an-unowne
May 28, 2026
Merged

Jinwoo-H merged 3 commits into
mainfrom
Jinwoo-H/bug-clone-abort-can-recursively-delete-an-unowne

Conversation

@Jinwoo-H

@Jinwoo-H Jinwoo-H commented May 28, 2026 •

Copy link
Copy Markdown
Contributor

Summary

  • Fixes [Bug]: Clone abort can recursively delete an unowned destination path #2929.
  • Adds a shared clone-path helper that validates URL-derived clone names, rejects unsafe dot/parent names, validates host-absolute destinations, and provides WSL-aware comparison keys.
  • Claims fresh clone targets before spawning git and only removes operation-owned targets after failed/aborted clones, preserving pre-existing or replaced user-owned paths.
  • Serializes same-target clone attempts in IPC and runtime paths so abort/retry and concurrent clone races cannot delete or strand a newer clone.

Design / Review Evidence

  • Scratch design doc: design-docs/clone-abort-ownership.md (ignored, not included in product diff).
  • Design review outcome: auto-design-review-fix completed 2 iterations; direction confirmed; no unresolved P0/P1 findings. The design changed from direct abort-handler deletion to atomic target ownership plus close/failure-path cleanup.
  • Implementation deviations: extended the reviewed design to also cover runtime cloneRepo, normal git failures, spawn errors/sync throws, same-target clone serialization, and WSL-aware dedupe keys after review findings.
  • Completeness verification: initial verifier found Windows backslash validation and test-coverage gaps; these were fixed with posix.basename, host-absolute destination validation, and focused tests.

Review Loop

  • Code-review rounds ran two reviewers at a time until clean.
  • Earlier rounds found and fixed: retry races, newer-success deletion, runtime validation parity, untracked helper, WSL UNC alias/case/trailing-slash keying, failed-clone cleanup, spawn-error cleanup, abort-success retry ordering, non-Windows UNC destination validation, and same-target serialization.
  • Final round 11: both reviewers returned no actionable findings.
  • Post-CI hardening: clone target identity now includes birthtimeMs so fast remove/recreate cycles cannot be mistaken for the operation-owned directory even if an inode pair is reused.

Brennan Test Changes

  • Result: land.
  • Evidence: staged/unstaged state inspected, only intended files changed; focused IPC/runtime/helper tests exercised controlled process close/error/abort events with real temp filesystem assertions for owned vs unowned cleanup.

Electron Validation

  • macOS Electron dev app launched from this PR worktree with CDP on 127.0.0.1:9335 and renderer on 127.0.0.1:5174.
  • window.api.app.getIdentity() confirmed branch Jinwoo-H/bug-clone-abort-can-recursively-delete-an-unowne and the expected worktree root.
  • Through real renderer-to-main IPC, window.api.repos.clone({ url: 'file:///tmp/.../source/.', destination }) rejected with Invalid repository name derived from URL; the pre-existing destination sentinel remained intact and no clone directory was created.
  • Through the same IPC path, a normal local clone from file:///tmp/.../source succeeded, created destination/source/README.md, and added the repo to app state.
  • Screenshot evidence captured locally at /tmp/orca-pr-2981-electron.png; the branch-specific Dock tile was also visible via macOS Accessibility.

Tests

  • pnpm vitest run --config config/vitest.config.ts src/main/git/repo-clone-path.test.ts src/main/ipc/repos-remote.test.ts src/main/runtime/orca-runtime.test.ts
  • pnpm run typecheck
  • pnpm run lint
  • git diff --check --cached
  • git diff --check
  • GitHub PR verify check: passed on run 26562823598.

Note: local commands emitted the existing engine warning because this shell is Node v26 while the repo wants Node 24. A local full pnpm test run failed one unrelated local-pty-shell-ready zsh environment assertion in this Orca-hosted shell; the PR's GitHub verify full test run passed on Node 24.

Made with Orca 🐋

@Jinwoo-H
Jinwoo-H merged commit 8f172f5 into main May 28, 2026
1 check passed
@Jinwoo-H
Jinwoo-H deleted the Jinwoo-H/bug-clone-abort-can-recursively-delete-an-unowne branch May 28, 2026 08:17
nwparker added a commit to AmoabaKelvin/orca that referenced this pull request Oct 6, 2026
A clone of a repository with no commits leaves HEAD unborn, which
`rev-parse --verify HEAD` rejects exactly like the `refs/heads/.invalid`
HEAD a killed clone leaves. The saved-project check read both as "not a
finished clone", so cloning a brand-new empty repo a second time — a
double-clicked Clone, a re-run `orca project setup-clone`, or stablyai#2981's
queued retry — fell through to git and died on "destination path already
exists and is not an empty directory".

Ask the two questions apart when `--verify` fails: `symbolic-ref HEAD`
resolves an unborn branch but not a killed clone's HEAD. It is already on
the relay's read-only allowlist. Probes also short-circuit once the clone
is cancelled, so no probe after Cancel spawns git.
nwparker added a commit that referenced this pull request Oct 6, 2026
* fix(repos): reuse a saved project only when git shows it's this clone

A saved project outlived its folder, so Clone reported success without running git.

Fixes #23563

* fix(repos): let a repeat clone of an empty repository reuse its project

A clone of a repository with no commits leaves HEAD unborn, which
`rev-parse --verify HEAD` rejects exactly like the `refs/heads/.invalid`
HEAD a killed clone leaves. The saved-project check read both as "not a
finished clone", so cloning a brand-new empty repo a second time — a
double-clicked Clone, a re-run `orca project setup-clone`, or #2981's
queued retry — fell through to git and died on "destination path already
exists and is not an empty directory".

Ask the two questions apart when `--verify` fails: `symbolic-ref HEAD`
resolves an unborn branch but not a killed clone's HEAD. It is already on
the relay's read-only allowlist. Probes also short-circuit once the clone
is cancelled, so no probe after Cancel spawns git.

* fix(repos): prepare the worktree root after re-cloning a project's folder

The branch that re-clones into a saved project's folder returned the
project without the two steps every sibling branch runs: the worktree
root that vanished with the deleted folder is never re-created, and the
authorized-roots cache keeps the answers it cached while the folder was
missing. Creating a worktree or reading files in the recovered project
then fails on a root that is not there.

* fix(ssh): register the root after re-cloning a saved project's folder

`addRemoteRepoFromPath` returns an existing project before it notifies
`session.registerRoot`, which was unreachable before the saved-project
check could re-clone into a project's own path. The relay therefore never
learned the folder came back, so sessions under it stayed unregistered.
Notify from the clone, mirroring the folder-to-git upgrade beside it.

* fix(repos): say which reason refused a clone over a saved project

One message covered both "that project holds a different repository" and
"Orca has no record of what that project held", which need different
things from the user. Name the recorded URL when there is one, and say
plainly that there is no record when there isn't — the second is the case
a project predating remote-identity enrichment lands in, and the user
cannot act on it without being told why.

Also drops the `upstream` remote-name check into a named binding: `origin`
is the only stored remote that names a project's own repo, because
`Repo.upstream` and the GitHub avatar derived from it both name the repo a
fork came from.

* fix(repos): bound saved-clone probes and prove empty clone completion

* fix(repos): keep clone validation host-scoped and locale independent

---------

Co-authored-by: Neil <[email protected]>
Co-authored-by: Neil <[email protected]>
enrick-dev pushed a commit to enrick-dev/orca that referenced this pull request Oct 15, 2026
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.

[Bug]: Clone abort can recursively delete an unowned destination path

1 participant