Skip to content

fix(git): time out hung worktree-creation git processes#3054

Merged
jonathanlab merged 3 commits into
mainfrom
posthog-code/timeout-worktree-creation
Jul 1, 2026
Merged

fix(git): time out hung worktree-creation git processes#3054
jonathanlab merged 3 commits into
mainfrom
posthog-code/timeout-worktree-creation

Conversation

@jonathanlab

@jonathanlab jonathanlab commented Jul 1, 2026

Copy link
Copy Markdown
Contributor

Adds a 2 min timeout to git worktree add and 5 min timeout to the post-checkout hook.

On failure, the prompt is recovered with the changes made in #3053


Created with PostHog Code

`git worktree add` and the post-checkout hook were spawned with no
timeout, so a wedged git process (lock wait, credential prompt, slow
network smudge, a hanging hook) would hang worktree creation forever —
the task never leaves its pending state and the user's prompt is stranded.

Bound both spawns: on timeout, SIGTERM the process, escalate to SIGKILL
after a grace period, and reject/return a timeout error. The rejection
propagates through createWorkspace, whose finally clears the dedup-map
entry, so a retry isn't stuck awaiting the dead promise either.

- git worktree add: 120s
- post-checkout hook: 300s (installs can be legitimately slow)

Generated-By: PostHog Code
Task-Id: bb024b86-4ac5-4ec6-87af-3d8809d28466
@github-actions

github-actions Bot commented Jul 1, 2026

Copy link
Copy Markdown

React Doctor found no issues in the changed files. 🎉

Reviewed by React Doctor for commit 6bbf836.

@greptile-apps

greptile-apps Bot commented Jul 1, 2026

Copy link
Copy Markdown
Contributor

Reviews (1): Last reviewed commit: "fix(git): time out and kill hung worktre..." | Re-trigger Greptile

Comment thread packages/git/src/worktree.test.ts Outdated
Co-authored-by: greptile-apps[bot] <165735046+greptile-apps[bot]@users.noreply.github.com>
The worktree test referenced KILL_GRACE_MS but it was module-private in worktree.ts, causing a TS2304 "Cannot find name" error. Export the constant and import it in the test.

Generated-By: PostHog Code
Task-Id: 6fc04ebf-82c4-44cb-a06c-4d4d37c6de14
@jonathanlab jonathanlab merged commit 15397d0 into main Jul 1, 2026
23 checks passed
@jonathanlab jonathanlab deleted the posthog-code/timeout-worktree-creation branch July 1, 2026 13:06
frankh added a commit that referenced this pull request Jul 1, 2026
#3054 added kill-timeouts to `git worktree add` and the post-checkout hook,
and #3053 restructured the saga to clear the provisioning spinner and keep the
task for retry when provisioning fails. Both landed on main and supersede the
worktree-add/hook-timeout and spinner-clearing parts of this PR, so those are
dropped here.

The one hang path neither covered is the `git fetch` that precedes worktree
creation — the trigger both fixes cited. It still runs unbounded inside the
per-repo write lock, so a blocked fetch (network stall, unreachable remote)
never settles, the lock is never released, and every later worktree creation
for that repo queues behind it forever.

Bound the two fetch call sites (resolveFreshBaseRef and
createWorktreeForRemoteBranch) with a timeout. The fetch runs through
simple-git rather than a raw spawn, so it can't use armProcessTimeout; instead
it aborts via the AbortSignal executeWrite already forwards to its scoped git
client, which kills the fetch subprocess and releases the write lock. On
timeout the trunk path degrades to the local ref and the remote-branch path
fails with a retryable error, rather than hanging.
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.

3 participants