Skip to content

fix(git-clone): clean up the half-built destination after a timeout - #2294

Closed
SeanLiu326 wants to merge 3 commits into
vastsa:mainfrom
SeanLiu326:fix/clone-timeout-cleanup
Closed

SeanLiu326 wants to merge 3 commits into
vastsa:mainfrom
SeanLiu326:fix/clone-timeout-cleanup

Conversation

@SeanLiu326

Copy link
Copy Markdown
Contributor

Fixes #2293.

What

A timed-out clone was killed with git inside its checkout, and the half-built destination stayed behind — every retry of the same name then hit CONFLICT: "<name>" already exists in that folder until the user found and deleted the residue by hand.

The change

The TIMEOUT path removes the destination before throwing: recursive delete for a real directory, plain unlink when it is a symlink (never recurse into a link target), and best-effort silence when git died before creating anything.

Tests

cloneGitRepository cleans up a half-built destination after a timeout: the injected run creates the checkout (as git would) and returns TIMEOUT; the assertion is the TIMEOUT rejection plus the destination being gone. Verified failing on unpatched source and passing after (13/13).

agentCompact's busy check went stale the moment it passed: between it and
the sidecar call sit the settings read, the session detail, and the
launch resolution, so a prompt submitted in that window started a turn
this compaction then ran against mid-stream. Hold the same session
operation the prompt and abort paths use, from before the check until
the call settles; the setup body moves to a helper so the handler reads
as guard -> work -> release.
sessionDelete had no running guard and held no session operation, so a
delete cascaded away the rows a live turn was still streaming into: every
later outbox append failed its foreign key, and the renderer kept
receiving events for a session that no longer existed. Fork already
refuses a running session; delete now does too, and holds the same
session operation so a turn starting between the check and the host call
cannot slip through either.
A timed-out clone was killed with git inside its checkout, and the
half-built destination stayed behind: every retry of the same name hit
CONFLICT ("already exists in that folder") until the user found and
deleted the residue by hand. The timeout path now removes the
destination — unlinking it instead of recursing when it is a symlink —
and the removal is best-effort for the case where git never created it.

@vastsa vastsa left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

This clone-timeout PR also contains the agentCompact/sessionDelete changes from #2292. In particular, session-ipc.ts is byte-identical (blob a89bde4a18a56ad18843dc51196f0b0d08ec34f6) to the #2292 head where the queued-start deletion race was independently reproduced: delete checks activeTurns before awaiting acquireSessionOperation, a pending prompt registers a live turn while holding that operation, then delete acquires it and deletes the running session without rechecking. See the production-handler/production-coordination diagnostic and requested regressions in #2292 (review) . This review reuses that executed evidence for identical code; it does not claim a fresh clone E2E run.

Please remove the unrelated IPC changes from this clone-specific PR (preferred minimal scope), or complete the authoritative activeTurns check inside the acquired lock and its behavioral regression coverage before landing. The clone cleanup itself still needs independent data-ownership/lifecycle validation; I have not accepted it merely from the added injected-run test.

@vastsa

vastsa commented Nov 13, 2026

Copy link
Copy Markdown
Owner

I checked this on macOS with real git 2.50: SIGTERM during git clone already removes the half-built directory itself (git's junk cleanup), so the residue reproduces where the kill bypasses git's handler — Windows, where Node's kill is TerminateProcess. There, runGitClone resolves at the timeout before git and its helpers (git-remote-https, index-pack) have exited, so removeIncompleteClone races live writers and open handles; EBUSY/ENOTEMPTY is swallowed and the residue remains. Please wait for the child to close (bounded) before cleaning, and only remove a destination this clone created (it was verified absent before spawning). Also, this branch carries the #2290 and #2292 changes; please drop them so the PR only touches the clone path.

@vastsa

vastsa commented Nov 15, 2026

Copy link
Copy Markdown
Owner

Thanks @SeanLiu326 — your clone-cleanup commit landed in #2357 with authorship preserved, together with the requested follow-ups (wait for the killed process tree to close before cleaning, only remove a destination this clone created, retry/log cleanup failures). The agentCompact/sessionDelete commits were left out; they remain under review in #2290/#2292. Closing as superseded.

@vastsa vastsa closed this Nov 15, 2026

This branch was previously deployed

1 inactive deployment
Preview — 36cd4475 Deployed Nov 12, 2026 by vercel[bot]
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.

git clone timeout leaves a half-built destination; every same-name retry hits CONFLICT

2 participants