#7563 · Daemon startup after an unclean shutdown
Verdict: NOT REPRODUCED · Root-cause confidence: low
1. TL;DR
The report describes a desktop startup failure after a laptop lost power, followed by a successful second launch. On current trusted main, a 25-minute-old orphaned daemon lock was reclaimed immediately, and a real process killed with SIGKILL left a fresh lock that was reclaimed by the first acquisition after about 11 seconds. A live-owner control correctly rejected the competing acquisition instead of stealing its lock. These results repeated in a second clean checkout of the same commit. The supplied launcher output does not itself establish a lock-acquisition error: the launcher prints the daemon lock path for every daemon startup failure. No macOS power-loss reproduction was possible on this Linux host, so the original incident and its underlying cause remain unverified.
2. Claims vs findings
| Claim | Status | Evidence |
|---|---|---|
| An unclean shutdown necessarily prevents the next daemon startup through a stale lock. | Not reproduced in tested model | Old orphan and fresh SIGKILL orphan both recovered on the first acquisition, in both checkouts. |
| The displayed lock path identifies the cause of this particular startup failure. | Not established by that output | The launcher's daemon-failure diagnostic prints the lock path unconditionally, independent of the child failure reason. |
| Two older startup diagnostics contain ELOCKED. | Reported; original artifacts unavailable | Those excerpts concern earlier events, not a captured child error from the reported power-loss startup. |
| Quitting and reopening resolved the actual incident. | Unverified | No original system, desktop process, or macOS reboot was available. |
| The daemon waits for an orphaned lock to become stale. | Verified on trusted main | Real filesystem and real proper-lockfile: 10-second staleness threshold; 13 retries at one-second intervals. |
3. Environment
- Target repository: public
get-bb/bb; main commitda3e60b81d560e114a2bec724bb59c997aaaae7f. Remote main was checked again after testing and was unchanged. - Linux 4.19.0-gvisor, x86_64; Node v22.19.0; pnpm 9.15.0; Vitest 4.1.12; proper-lockfile 4.1.2 from the frozen repository lockfile.
- Two detached trusted worktrees, identified here as
/tmp/bb-7563-baseand/tmp/bb-7563-verify. These are normalized display names, not the random local directory IDs. - Every test creates and removes a fresh OS temporary data directory. No real bb runtime data, host credentials, provider process, Connect connection, HTTP server, or listening port was used.
- Reporter platform and desktop release were not executed. SIGKILL models owner death without exit handlers; it does not model APFS recovery, macOS clock correction, boot-time services, or Electron launch sequencing.
4. Minimal reproduction attempt
- Obtain trusted source and pin the investigated commit:
git clone https://github.com/get-bb/bb.git /tmp/bb-7563-base cd /tmp/bb-7563-base git checkout --detach da3e60b81d560e114a2bec724bb59c997aaaae7f pnpm install --frozen-lockfile --prefer-offline pnpm exec turbo run build:types --filter=@get-bb/plugin-sdk pnpm exec turbo run build --filter=@get-bb/plugin-sdk pnpm exec turbo run build
- Save the complete test below as
apps/host-daemon/test/issue-7563-lock.test.ts. - Run it together with the existing lock recovery suite:
pnpm exec turbo run test --filter=@bb/host-daemon -- test/issue-7563-lock.test.ts src/lock.test.ts --silent=false
- The old-orphan case creates only the abandoned lock directory and gives it a heartbeat time 25 minutes in the past. The fresh-orphan case starts a separate Node process using the actual acquisition function, waits for its acquired-lock IPC message, kills it with SIGKILL, confirms the directory survives, and calls the production function once with default settings. The live-owner control leaves that real process alive while another acquisition exhausts its retry budget.
Expected if the stale-lock hypothesis reproduced: the first call for an ownerless lock would reject with ELOCKED and require another acquisition. Actual: both ownerless cases succeeded on their first call; only a currently live owner produced ELOCKED. The test is an investigation harness, not a demonstrated fail-before regression for the reported incident.
Complete investigation test
import { spawn, type ChildProcess } from "node:child_process";
import { once } from "node:events";
import fs from "node:fs/promises";
import os from "node:os";
import path from "node:path";
import { fileURLToPath } from "node:url";
import { afterEach, beforeEach, describe, expect, it } from "vitest";
import { acquireDaemonLock } from "../src/lock.js";
describe("issue 7563 daemon startup after an unclean owner exit", () => {
let dataDir: string;
let owner: ChildProcess | undefined;
let release: (() => Promise<void>) | undefined;
beforeEach(async () => {
dataDir = await fs.mkdtemp(path.join(os.tmpdir(), "bb-7563-lock-"));
});
afterEach(async () => {
await release?.();
release = undefined;
if (owner && owner.exitCode === null && owner.signalCode === null) {
const exited = once(owner, "exit");
owner.kill("SIGKILL");
await exited;
}
owner = undefined;
await fs.rm(dataDir, { recursive: true, force: true });
});
async function startOwner(): Promise<ChildProcess> {
const lockModule = new URL("../src/lock.ts", import.meta.url).href;
const child = spawn(
process.execPath,
[
"--import",
"tsx",
"--input-type=module",
"--eval",
`import { acquireDaemonLock } from ${JSON.stringify(lockModule)};
await acquireDaemonLock(${JSON.stringify(dataDir)});
process.send("ready");
setInterval(() => {}, 1000);`,
],
{
cwd: fileURLToPath(new URL("..", import.meta.url)),
stdio: ["ignore", "ignore", "inherit", "ipc"],
},
);
owner = child;
await once(child, "message");
return child;
}
it("reclaims an old orphan on the first acquisition", async () => {
const lockDir = path.join(dataDir, "daemon.lock.lock");
await fs.mkdir(lockDir);
const lastHeartbeat = new Date(Date.now() - 25 * 60_000);
await fs.utimes(lockDir, lastHeartbeat, lastHeartbeat);
const startedAt = Date.now();
release = await acquireDaemonLock(dataDir);
console.log(
`Old orphan: acquired on first call in ${Date.now() - startedAt}ms`,
);
expect((await fs.stat(lockDir)).mtimeMs).toBeGreaterThan(
lastHeartbeat.getTime(),
);
expect(Date.now() - startedAt).toBeLessThan(5_000);
});
it("reclaims a SIGKILL owner's fresh lock without a second launch", async () => {
const child = await startOwner();
const exited = once(child, "exit");
child.kill("SIGKILL");
const [, signal] = await exited;
expect(signal).toBe("SIGKILL");
const lockDir = path.join(dataDir, "daemon.lock.lock");
const orphan = await fs.stat(lockDir);
const startedAt = Date.now();
release = await acquireDaemonLock(dataDir);
console.log(
`Fresh SIGKILL orphan: acquired on first call in ${Date.now() - startedAt}ms`,
);
expect((await fs.stat(lockDir)).mtimeMs).toBeGreaterThan(orphan.mtimeMs);
expect(Date.now() - startedAt).toBeLessThan(20_000);
}, 30_000);
it("does not steal a live owner's heartbeat-refreshed lock", async () => {
const child = await startOwner();
const startedAt = Date.now();
await expect(acquireDaemonLock(dataDir)).rejects.toMatchObject({
code: "ELOCKED",
});
console.log(
`Live owner: correctly rejected with ELOCKED after ${Date.now() - startedAt}ms`,
);
expect(child.exitCode).toBeNull();
expect(child.signalCode).toBeNull();
expect(child.connected).toBe(true);
}, 30_000);
});
Source and output are embedded here rather than linked as downloadable artifacts, in accordance with the reports repository's self-contained-report policy.
5. Root cause
The original failure's root cause is not established. The ordinary stale-lock mechanism behaves as intended in the tested environment. The actual acquisition happens at the start of startHostDaemon, before authentication and daemon application construction. Default lock timing is:
const DAEMON_LOCK_STALE_MS = 10_000; const DAEMON_LOCK_RETRY_INTERVAL_MS = 1_000; const DAEMON_LOCK_ACQUIRE_RETRIES = 13;
The production acquisition passes the staleness threshold and fixed-interval retries to proper-lockfile. Inspection of the installed dependency confirms it compares the lock directory modification time against wall-clock time minus the stale interval, removes an old empty directory, and retries acquisition. The old-orphan test exercises immediate removal; the SIGKILL test exercises waiting out the remaining heartbeat lifetime. The existing compromise suite additionally covers reacquisition and yielding to a live contender.
A separate, verified diagnostic limitation explains why the supplied output is insufficient to identify this cause. The initial warning checks only whether a lock directory exists. The startup catch handles any daemon startup failure and calls the generic failure-context printer, which always emits the daemon lock path for a daemon failure:
log(" ", dim(`lock: ${args.context.daemonLockDir}`));
log(" ", dim(`logs: ${args.context.logDir}/`));
That is not proof that lock acquisition was the failing operation. The earlier ELOCKED excerpts are not contemporaneous evidence for this specific startup. A wall-clock discrepancy or another startup contender could change the outcome, but neither was observed here and neither is presented as the cause.
6. Proposed fix or next experiment
No speculative lock-removal fix. Preserving exclusivity is important: deleting a live daemon's lock would allow concurrent owners of a data directory. The control test demonstrates that the existing refusal is intentional.
On a controlled macOS reproduction, capture the startup-failure diagnostic from the same failed launch, reduced to the exception name/code/message/stack and launch timestamps. Record the lock directory modification time relative to wall-clock time and any other daemon or service starting during boot. Do not publish environment-variable objects, credentials, private paths, or unrelated runtime data. This would distinguish an actual ELOCKED failure from another child-startup error and test clock or competing-process hypotheses. Only then choose a focused regression and repair.
No open pull request was linked through the issue timeline or returned by the open-PR search for this issue number at investigation time. No fix branch or pull request was created: no fail-before reproduction of the reported bug was demonstrated on trusted main, so the simple-fix gate was not met.
7. Related issues
Repository search found other daemon-lock and startup reports, but none establishes the cause of this fresh-boot incident. They were not treated as a shared reproduction or proof of a duplicate.
8. Verification
The same agent repeated the experiment, not an independent reviewer. A second clean detached worktree was created directly at da3e60b81d560e114a2bec724bb59c997aaaae7f. It received its own frozen dependency install, SDK types/runtime build, full monorepo build, and the unchanged investigation test. Build-generated web route ordering was restored before running the test; the production daemon lock and startup files had no changes. New temporary data directories and new owner processes were created by the repeated tests; no ports were required.
| Check | First checkout | Second checkout |
|---|---|---|
| Full build after SDK prerequisites | 74 tasks successful | 74 tasks successful |
| Investigation harness plus existing lock suite | 6 tests passed in 2 files; uncached test execution | 6 tests passed in 2 files; uncached test execution |
| Old orphan | First-call acquisition passed the under-5-second assertion | 2 ms; first-call acquisition |
| Fresh killed-owner orphan | First-call recovery; test including child setup: 11,186 ms | 11,017 ms measured acquisition; 11,172 ms including child setup |
| Live-owner control | ELOCKED rejection with owner still alive | ELOCKED after 13,017 ms with owner still alive |
The first run used the same Turbo command without --silent=false; the second enabled console output to expose measured acquisition durations. No report correction was needed after the second run. High confidence applies to these Linux observations and the generic diagnostic code path, not to a macOS incident diagnosis; root-cause confidence for that incident remains low.
9. Appendix: exact focused test output
Only temporary checkout paths have been normalized. No reporter log or runtime data is included.
First checkout
@bb/host-daemon:test: cache miss, executing 35e54f7ba57b0333 @bb/host-daemon:test: @bb/host-daemon:test: > @bb/host-daemon@0.0.1 test /tmp/bb-7563-base/apps/host-daemon @bb/host-daemon:test: > vitest run --config vitest.config.ts "test/issue-7563-lock.test.ts" "src/lock.test.ts" @bb/host-daemon:test: @bb/host-daemon:test: @bb/host-daemon:test: RUN v4.1.12 /tmp/bb-7563-base/apps/host-daemon @bb/host-daemon:test: @bb/host-daemon:test: ✓ |@bb/host-daemon| src/lock.test.ts (3 tests) 4875ms @bb/host-daemon:test: ✓ re-acquires a compromised lock instead of crashing the daemon 1020ms @bb/host-daemon:test: ✓ re-acquires when the lock dir survives the compromise and must age past stale 2536ms @bb/host-daemon:test: ✓ yields the data dir when another live process holds the lock 1317ms @bb/host-daemon:test: ✓ |@bb/host-daemon| test/issue-7563-lock.test.ts (3 tests) 24657ms @bb/host-daemon:test: ✓ reclaims a SIGKILL owner's fresh lock without a second launch 11186ms @bb/host-daemon:test: ✓ does not steal a live owner's heartbeat-refreshed lock 13463ms @bb/host-daemon:test: @bb/host-daemon:test: Test Files 2 passed (2) @bb/host-daemon:test: Tests 6 passed (6) @bb/host-daemon:test: Start at 13:33:11 @bb/host-daemon:test: Duration 24.88s (transform 32ms, setup 0ms, import 78ms, tests 29.53s, environment 0ms) @bb/host-daemon:test:
Second checkout
@bb/host-daemon:test: cache miss, executing 4ee19215ea4b9f66 @bb/host-daemon:test: @bb/host-daemon:test: > @bb/host-daemon@0.0.1 test /tmp/bb-7563-verify/apps/host-daemon @bb/host-daemon:test: > vitest run --config vitest.config.ts "test/issue-7563-lock.test.ts" "src/lock.test.ts" "--silent=false" @bb/host-daemon:test: @bb/host-daemon:test: @bb/host-daemon:test: RUN v4.1.12 /tmp/bb-7563-verify/apps/host-daemon @bb/host-daemon:test: @bb/host-daemon:test: stdout | test/issue-7563-lock.test.ts > issue 7563 daemon startup after an unclean owner exit > reclaims an old orphan on the first acquisition @bb/host-daemon:test: Old orphan: acquired on first call in 2ms @bb/host-daemon:test: @bb/host-daemon:test: ✓ |@bb/host-daemon| src/lock.test.ts (3 tests) 4871ms @bb/host-daemon:test: ✓ re-acquires a compromised lock instead of crashing the daemon 1021ms @bb/host-daemon:test: ✓ re-acquires when the lock dir survives the compromise and must age past stale 2533ms @bb/host-daemon:test: ✓ yields the data dir when another live process holds the lock 1315ms @bb/host-daemon:test: stdout | test/issue-7563-lock.test.ts > issue 7563 daemon startup after an unclean owner exit > reclaims a SIGKILL owner's fresh lock without a second launch @bb/host-daemon:test: Fresh SIGKILL orphan: acquired on first call in 11017ms @bb/host-daemon:test: @bb/host-daemon:test: stdout | test/issue-7563-lock.test.ts > issue 7563 daemon startup after an unclean owner exit > does not steal a live owner's heartbeat-refreshed lock @bb/host-daemon:test: Live owner: correctly rejected with ELOCKED after 13017ms @bb/host-daemon:test: @bb/host-daemon:test: ✓ |@bb/host-daemon| test/issue-7563-lock.test.ts (3 tests) 24336ms @bb/host-daemon:test: ✓ reclaims a SIGKILL owner's fresh lock without a second launch 11172ms @bb/host-daemon:test: ✓ does not steal a live owner's heartbeat-refreshed lock 13155ms @bb/host-daemon:test: @bb/host-daemon:test: Test Files 2 passed (2) @bb/host-daemon:test: Tests 6 passed (6) @bb/host-daemon:test: Start at 13:34:56 @bb/host-daemon:test: Duration 24.57s (transform 29ms, setup 0ms, import 76ms, tests 29.21s, environment 0ms) @bb/host-daemon:test:
Build and source checks
The first full build initially failed because a plugin SDK host export had not been built. Building SDK types and runtime with the commands above resolved that local prerequisite; both final monorepo builds completed with 74 successful tasks. No dependency was added. There were pre-existing bundler warnings, but no remaining build failure.
git worktree add --detach <first-checkout> da3e60b81d560e114a2bec724bb59c997aaaae7f git worktree add --detach <second-checkout> da3e60b81d560e114a2bec724bb59c997aaaae7f git diff --exit-code -- apps/host-daemon/src/lock.ts apps/host-daemon/src/start-host-daemon.ts sha256sum apps/host-daemon/src/lock.ts 43891d1d6828560d966e849fb1190d1215350c98045892a15043a71fab40493e
Source links were checked against the pinned commit. GitHub metadata reads established public visibility, classification, the absence of comments before the summary, and no linked open PR. No live instance was started, so there are no app processes, browser sessions, or listening ports to stop.
Untrusted-data boundary: issue text was used only as a set of claims to investigate; no supplied issue script, patch, command, external link, or pull-request branch was executed.