Repository navigation
Description
Summary
Suppose another bb process already holds bb-app-runtime.json and answers /health on the configured URL. bb-app start then prints "Another bb already runs on this data directory", but it still spawns a server child. That child opens the shared bb.db and runs the startup recovery sweep. It then logs Server listening, dies with EADDRINUSE, and bb-app exits 1. A service manager that restarts on failure repeats this every ~11 s for as long as the other bb runs.
Expected: bb-app start already knows another bb serves this data directory at this URL, so it should not spawn a server child.
Versions and environment
- bb-app 0.46.0 (npm; also the latest on npm today), Node 26.7.0, macOS (Darwin 27.0.0, arm64). bb desktop 0.46.0 uses the same
~/.bb. bb-app startruns under a user launchd agent withKeepAlive = { SuccessfulExit = false }. The plist is hand-written, not created by the machine installer. bb-app startup failures retry indefinitely and accumulate empty diagnostic files on disk failure #3340 describes a similar setup with systemdRestart=always.- The fix was tested against
mainat d011a88.
Steps to reproduce
d=$(mktemp -d)
export BB_DATA_DIR=$d BB_SERVER_PORT=49386 BB_HOST_DAEMON_PORT=49387 BB_TELEMETRY=false
bb-app start > /tmp/a.out 2>&1 & # A
until curl -sf http://127.0.0.1:49386/health; do sleep 1; done
/usr/bin/time -l bb-app start --no-in-app-updates; echo "exit=$?" # B
ls "$d/logs" | grep -c uncaughtException
bb-app stopExpected vs actual
Actual output of B (exit 1):
! Another bb already runs on this data directory
record: .../bb-app-runtime.json
Run `bb-app stop` to stop it.
○ Starting server
✗ Server failed to start
Server failed to become healthy: Process exited before becoming healthy: another server is already answering at http://127.0.0.1:49386/health
B's child writes "msg":"Server listening" to server.N.log even though it never binds. About 43 ms later it writes process-server-uncaughtException-*.json with listen EADDRINUSE: address already in use 127.0.0.1:49386.
Each version ran 3 times with the same flags (node dist/bb-app.js start --no-in-app-updates), measured with /usr/bin/time -l:
| B | wall | user+sys CPU | max RSS | new diagnostic files |
|---|---|---|---|---|
| 0.46.0 | 0.98–1.00 s | 0.90–0.91 s | 237–239 MB | 1 per run |
| 0.46.0 + proposed fix | 0.11–0.14 s | 0.12–0.14 s | 75 MB | 0 |
Against a copy of a real 413 MB bb.db, the unpatched cost is the same (0.99–1.08 s wall).
Evidence from a real install
~/Library/Logs/bb-server.log(launchd stdout) contains "Another bb already runs on this data directory" 6,836 times. It contains "Restarting server" (the in-process supervisor) only 2 times, and both restarts succeeded. Every cycle is therefore a freshbb-app startfrom launchd.~/.bb/logs/holds 6,888process-server-uncaughtException-*.jsonfiles, 6,846 of themEADDRINUSE. They take 27 MB and none were pruned.- Daily counts: 895 on 2026-09-29, 3,681 on 09-30, and 2,265 on 10-12 (00:54:30Z → 07:46:30Z).
- The median gap is 11.0 s: launchd's 10 s throttle plus ~1 s of doomed boot.
- During the 10-12 window, the doomed children log no plugin loads, only
Server listening. - Code at d011a88:
- the record is claimed, the warning is printed, startup continues: launcher.ts#L4120-L4132;
- the startup recovery sweep runs before listen: start-server.ts#L378, then the listener at #L390;
Server listeningis logged before the bind result is known: #L402.
Risk (code reading only, not reproduced)
runStartupRecoverySweep re-drives creating/provisioning environments and starting threads. For threads it skips only those where hasLiveThreadStartInFlight is true. That guard is an in-memory, process-local lock, so a doomed second server cannot see starts in flight in the live one. I have not observed any resulting damage.
Proposed fix
Commit: duizabojul@457cb56 (+10 lines in packages/bb-app/src/launcher.ts, on top of d011a88; branch duizabojul:fix/bb-app-start-skip-duplicate-server).
If the runtime record is held by another live process and isHealthyServerAnswering(<serverUrl>/health) returns true, the launcher logs ✗ bb already serves <url> from this data directory and exits 1 before spawning anything. I kept exit code 1 so that a restart-on-failure service still takes over once the other bb quits. Each retry then costs ~0.12 s of CPU and writes no file.
Verification:
- The table above for the duplicate case.
- A lone patched start with no other bb still reaches
bb is readyand exits 0 onbb-app stop. vitestinpackages/bb-app: 199 pass. 4 fail with or without the patch, at d011a88 too: the config restart-notice tests inindex.test.ts.
I can open the PR once I'm approved as a contributor.
What I ruled out
- Not bb-app supervisor retries forever after another server takes its port #2993 / Stop supervision when a healthy server replaces the managed child #2994. That fix covers the in-process supervisor after a child exits, and here the supervisor never restarts anything.
- Not bb-app startup failures retry indefinitely and accumulate empty diagnostic files on disk failure #3340. That issue covers an unrecoverable startup error with no other server. A retry budget inside
bb-app startwould not stop launchd/systemd from relaunching it.
Suggested priority
Low to medium. It only affects setups that run bb-app start under a restart-on-failure service next to another bb on the same data directory. While the loop lasts it costs about 9% of one core (0.96–0.99 s of CPU every 11 s through the npm shim, same /usr/bin/time -l method) plus one diagnostic file every 11 s. Workaround: run only one of the two. No data loss observed.
AGENT GENERATED
Activity
bb-slop-cop commentedon Oct 12, 2026
🚨 SLOP COP 🚨 ·
new-issue-autopilothost,cli.confirmed-repro.origin/maincheckouts.startup-runtime-record.test.tsfails before the fix and passes after; all 206 package tests and typecheck pass. Patched real-process startup creates no duplicate child or diagnostic and leaves the incumbent healthy.Prevent duplicate launchers from starting a second server (get-bb#5406)