Repository navigation
Description
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:
- Create a scratch workspace with
.bb-env-setup.shcontainingecho $$ > hook.pidfollowed byexec sleep 120. - In a separate Node process, import
apps/host-daemon/src/environment-lifecycle-script.tsusingnode --conditions=source --import tsxand awaitrunSetupScript({ workspacePath: <absolute scratch path>, timeoutMs: 900000 }). - Record that Node PID and the hook PID from
hook.pid. Send SIGKILL only to the recorded Node PID. - 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
- Detached hook spawn.
- In-memory hook operation registry.
- RuntimeManager setup path outside that registry.
- Source issue: Environment teardown retries forever after an interrupted hook, with no recovery path #5960.
What was ruled out
- A daemon restart does not inherently kill a detached hook: reproduced with the actual source hook runner.
- This is separate from bounded retry/manual recovery in Bound environment teardown retries and add guarded recovery #5961; it needs durable ownership and PID-reuse protection.
- The production environment from Environment teardown retries forever after an interrupted hook, with no recovery path #5960 was untouched.
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
terminationUnverifieduntil 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
bb-slop-cop commentedon Oct 21, 2026
🚨 SLOP COP 🚨 ·
new-issue-autopilotApplied 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.
Give everything the host daemon starts an owner that ends it