Skip to content

Persist hook process ownership for safe recovery after daemon restart #5962

Open

Description

@brsbl

Summary

Environment hooks can outlive the daemon that launched them. Persist process ownership and termination evidence so a restarted daemon can safely reconcile interrupted setup/teardown operations and allow automatic environment removal. This is the deferred automatic-recovery portion of #5960; #5961 keeps ambiguous operations blocked and adds guarded manual recovery.

Versions and environment

Source at 405592c0b71b1655a6ab2e1cc7498b5beeb78caa (current main when reproduced), Linux. The reproduction ran in an isolated fixture, with no production changes.

Steps to reproduce

In a source checkout with dependencies and generated source artifacts available:

  1. Create a scratch workspace with .bb-env-setup.sh containing echo $$ > hook.pid followed by exec sleep 120.
  2. In a separate Node process, import apps/host-daemon/src/environment-lifecycle-script.ts using node --conditions=source --import tsx and await runSetupScript({ workspacePath: <absolute scratch path>, timeoutMs: 900000 }).
  3. Record that Node PID and the hook PID from hook.pid. Send SIGKILL only to the recorded Node PID.
  4. Read /proc/<hook PID>/status; the hook remains sleeping after its owner exits. Clean up only the recorded fixture hook PID.

Expected vs actual

Expected: persisted ownership allows the next daemon to determine whether the interrupted operation still has live processes, stop only verified owned processes if appropriate, and record a trustworthy outcome.

Actual:

{"runnerPid":3346871,"hookPid":3346908}
CONFIRMED: actual runSetupScript process remains alive after its owner exits
Name: sleep
State: S (sleeping)
Pid: 3346908
PPid: 3346740

A daemon boot ID or start time cannot establish hook termination. The new daemon loses the in-memory hook registry and returns unknown.

Evidence

What was ruled out

Acceptance criteria

  • Reconcile both hook RPC and RuntimeManager setup paths after graceful restart and forced exit.
  • Use durable identities that cannot target a reused PID or unrelated process.
  • Preserve terminationUnverified until real termination evidence exists; handle legacy operations conservatively.
  • Never infer process use from shared inode identity. Include descendants, PID reuse, missing records, and old/new daemon compatibility tests.
  • Cover the real interrupted-hook flow in an isolated daemon restart e2e.

AGENT GENERATED

Activity

  1. added theissue type on Oct 21, 2026
  2. added
    host
    workspaces
    on Oct 21, 2026
  3. bb-slop-cop commented on Oct 21, 2026

    @bb-slop-cop
    Contributor

    🚨 SLOP COP 🚨 · new-issue-autopilot

    Applied Type: Task · Priority: Medium · Effort: High and labels host, workspaces. All classifications were previously unset; no existing values were replaced.

    This tracks the deferred implementation of durable hook ownership and automatic restart recovery, separate from the interrupted-cleanup defect. Medium priority reflects the limited restart/interruption scope and guarded manual-recovery path; High effort reflects durable process identity, descendant reconciliation, and compatibility work.

    Final Type re-read: Task. Reproduction report and automatic fix skipped under the non-Bug rule; no pull request opened.

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

    hostworkspaces

    Type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions