gstack icon indicating copy to clipboard operation
gstack copied to clipboard

Stop hook times out on Windows: detached --repair child keeps the hook's process tree alive

Open DanCanadian opened this issue 3 weeks ago • 1 comments

Summary

On Windows, the timeline Stop hook intermittently fails with:

Hook failed: bash /c/Users/<user>/.claude/skills/gstack/hosts/claude/hooks/timeline-stop-hook (stop): timed out after 14s

The hook itself is fast (~0.2s warm) and fail-open by design, so the timeout cannot come from the foreground path. The cause is the detached --repair child that spawnRepair() launches on a slug-cache miss.

Root cause

spawnRepair() (hosts/claude/hooks/timeline-stop-hook.ts) spawns:

spawn(process.execPath, [...bunIsolationArgs(), file, '--repair', cwd], {
  detached: true, stdio: 'ignore', windowsHide: true,
})

The child runs backgroundRepair() → runBin('gstack-slug', ..., { timeout: REPAIR_SLUG_TIMEOUT_MS /* 30s */ }) through Git Bash, then repairs.

Claude Code on Windows waits for the entire process tree of a hook, not just the direct child — detached: true does not remove the grandchild from that tree (same class of bug as anthropics/claude-code#24206, "Stop hook timeout does not kill child process tree", and the Windows orphan/suspended-process reports #77078, #100399).

So every slug-cache miss keeps the Stop hook's tree alive for the child's full lifetime:

  • typical gstack-slug through Git Bash: ~1–3s (borderline vs. the 5s hook budget once bash+ bun startup is counted),
  • degraded cases: up to the 30s REPAIR_SLUG_TIMEOUT_MS.

~/.gstack/hook-errors.log on this machine shows real gstack-slug: ETIMEDOUT repair failures, i.e. the slow path is exercised in practice. Miss markers are per-cwd with a 5-minute TTL, so every new working directory re-arms the spawn.

Reproduction

  1. Windows, Git Bash hook shell, bun on PATH.
  2. In Claude Code, stop a session whose cwd has no versioned slug-cache entry (any fresh directory works).
  3. The hook returns immediately, but the detached bun --repair child keeps the hook's process tree alive until gstack-slug exits; with a slow/failed resolve this exceeds the hook timeout and Claude Code reports Hook failed: ... timed out.

Verified locally: with the spawn skipped on process.platform === 'win32', the miss path completes in ~0.13s with zero lingering bun processes; the cache-hit path is unchanged at ~0.16s.

Suggested fixes (any one)

  1. Skip spawnRepair on win32 — the inline path already repairs every cache hit; a miss just retries next Stop. Cheapest and matches the hook's fail-open contract. Trade-off: uncached directories never get background slug resolution on Windows.
  2. Spawn through a tree-escaping mechanism on Windows — e.g. WMI Win32_Process.Create or Start-Process, so the repair child is not a descendant Claude Code waits on. Preserves the feature fully.
  3. Bound the child's worst case harder on win32 — e.g. a much smaller slug timeout; reduces but does not eliminate the timeout window.

What I run locally

Option 1 as a two-line guard plus a test seam:

if (process.platform === 'win32' && process.env.GSTACK_TIMELINE_REPAIR_CHILD !== '1') return;

and test/timeline-stop-hook-slug.test.ts sets GSTACK_TIMELINE_REPAIR_CHILD=1 in the hook env so the miss→child→repair path stays covered on every platform (all 4 slug tests + 2 stdin tests pass on Windows; the 4 pre-existing timeline-stop-hook wiring failures reproduce on unmodified HEAD and are unrelated).

Happy to open a PR with this if the direction looks right.

Environment

  • Windows 11, Git Bash (OSTYPE=msys), bun 1.4.4
  • Claude Code 2.1.293
  • gstack main @ a58e6e27c (2026-11-09)

DanCanadian avatar Nov 09 '26 22:11 DanCanadian

Thanks for the clear root cause and the fix in #4253. Windows gets minimal support in gstack (docs/support-tiers.md): we keep install, startup and the core workflows working, and we're not taking changes beyond that. This Stop hook fails open, and the timeout only shows an error message when a session ends in a new directory, so it doesn't break a workflow. I'm closing it as won't-fix. If it starts blocking sessions or losing timeline data, please reopen with the log.

capy-ai[bot] avatar Nov 10 '26 16:11 capy-ai[bot]