Skip to content

Windows: Process did not exit after termination: <pid> on thread stop / idle runtime shutdown; the 1s wait is shorter than Windows teardown of bb.exe children #4866

Open

Description

@ElijahFitzgeraldTuttle

Environment. bb 0.45.0 desktop, Windows 11 Pro (10.0.26200), local host daemon.

Symptom. Stopping a thread sometimes fails with Process did not exit after termination: <pid>. In one afternoon host-daemon-stdio.log has it about 20 times. Most come from Failed to shut down idle provider maintenance runtime; one came from online host RPC failed {type: "thread.stop"}. The stack is the waitForRootExit timer. Every reported PID (provider-bridge workers, bb.exe … bb-provider-bridge-worker.mjs) exited on its own shortly after. Nothing is actually left running, but the stop is reported as failed.

Cause. stopWindowsProcessTree runs taskkill /T /F (capped at 2 s), then child.kill("SIGKILL"). waitForRootExit then allows 1 s for Node's 'exit', and createProcessStop throws if exitCode/signalCode are still null. On Windows, the exit code is set as soon as TerminateProcess lands. The process object is only signaled, and libuv only emits 'exit', once the kernel has finished tearing the process down. For bb.exe children (Electron with ELECTRON_RUN_AS_NODE), that teardown sometimes takes seconds on this machine.

Measurements. The child is an idle script (setInterval(() => {}, 1000)) run under bb.exe with ELECTRON_RUN_AS_NODE=1. process.kill(pid, 0) was polled every 10 ms to see when the kill landed:

  • child.kill("SIGKILL"): the kill landed within ~15 ms in every run; 'exit' arrived after 4707, 3788, 1066 and 69 ms.
  • BB's sequence (taskkill /T /F, then the 'exit' wait): taskkill returned in 0.3–1.9 s; 'exit' arrived 0.7–40 s after that (4 runs).
  • When the machine was calmer, most runs finished in ~0.35 s, but one still took 1.33 s. That run would have thrown.

Suggested fix. When the root-exit wait times out on win32, check whether the process has already been terminated (process.kill(pid, 0) throwing ESRCH, i.e. GetExitCodeProcess != STILL_ACTIVE). If it has, treat the stop as confirmed; throw only if the process is still running. Node keeps the process handle open until 'exit', so the PID can't be reused during this check. The alternative is a longer wait once termination is confirmed.

I'm running this as a local hotfix on 0.45.0, applied in the waitForRootExit timeout and in createProcessStop's final check. In a replay of the stop sequence, the 1.33 s run resolved instead of throwing:

function isTerminatedOnWindows(child) {
  if (process.platform !== "win32" || child.pid === undefined) return false;
  try {
    process.kill(child.pid, 0);
    return false;
  } catch (error) {
    return error?.code === "ESRCH";
  }
}

Side observation, not verified: in some runs taskkill /T /F itself took 19–124 s. BB cuts it off at 2 s and kills only the root, so in those cases a provider's descendant processes might never get the tree kill.

Activity

  1. added theissue type on Oct 4, 2026
  2. added
    host
    partial-repro
    on Oct 4, 2026
  3. bb-slop-cop commented on Oct 4, 2026

    @bb-slop-cop
    Contributor

    🚨 SLOP COP 🚨 · new-issue-autopilot

    Classification: Bug · Priority: Medium · Effort: Medium · host.

    Report: Reproduction and root-cause report.

    Verdict: PARTIALLY REPRODUCED · Confidence: medium · Reproduction label: partial-repro.

    Evidence: windows-delayed-exit-repro.test.ts fails in two clean trusted-main checkouts using a Linux model of delayed Windows exit notification. Both controls pass; 11 existing process-tree tests pass. Native Windows/Electron timing remains unverified.

    Root cause: The one-second Windows exit wait rejects pending notification, and the managed-stop final check also requires exit metadata; neither recognizes a terminated-but-not-yet-notified root.

    No PR: The native Windows failure was not directly reproduced, so the automatic-fix reproduction gate is not met.

    AGENT GENERATED

  4. SawyerHood commented on Oct 19, 2026

    @SawyerHood
    Collaborator

    Consolidated Windows teardown report, with separate CLI-crash follow-up

    Consolidating #5195 into this canonical tracker at the maintainer's request following the open-issue duplicate sweep.

    #5195 supplies another trigger for the demonstrated teardown race: submitting the next turn while the previous turn finishes, on bb 0.45.0 / Windows 11 x64 / Node 24.14.1. It reports turn.submit failed: Process did not exit after termination: <pid>; a retry recovers.

    The reproduction report https://get-bb.github.io/reports/issues/5195.html verifies a delayed-exit-notification model: the root PID is already gone but the one-second helper wait rejects, and the managed-stop wrapper also requires exit metadata. Native Windows submission remains unverified.

    Explicit remaining work imported with this consolidation:

    • Cover the back-to-back turn.submit trigger as well as stop/idle teardown.
    • Independently investigate the companion UV_HANDLE_CLOSING assertion from src\win\async.c:76 after CLI output. The command can take effect and then exit nonzero (for example plugin reload).
    • Verify that CLI assertion on Windows; it is not established to share the termination race's root cause. A teardown fix alone must not be treated as resolving that symptom. Split it into a linked follow-up if investigation confirms a separate cause.

    Full original reproduction and errors remain in #5195. Its closure records consolidation, not a fix.

    AGENT GENERATED

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    hostpartial-repro

    Type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions