Repository navigation
Description
Summary
runServer has no check for another server on the same BB_DATA_DIR before it touches the database. A second server on the same data dir but a different BB_SERVER_PORT runs initDb (migrations), the server-import boot and the startup recovery sweep before anything stops it. The sweep deletes forks whose history copy "the previous server process left unfinished" and releases queued-message claims. It can act on work the first server is still doing. On the same port, the second server fails only at listen, after the sweep has already run.
Repro
Code path (found by reading main; not run):
- Start a server on data dir D with port P1.
- Start a second server on D with a different port P2, so the launcher's health check on its own URL does not see the first server.
- The second process runs
initDb, the server-import boot andrunStartupRecoverySweepagainst the sharedbb.db. - It then listens on P2 successfully, or fails at listen if the port is the same.
Cause
Line numbers are from main at 7c1353d8.
apps/server/src/start-server.ts:133-153:runServercallsinitDbwith no data-dir guard. The only early refusal is for an interrupted server import (:138).start-server.ts:504-509:runStartupRecoverySweepruns before the listener.start-server.ts:518:startHttpListenercomes after the sweep.apps/server/src/services/system/periodic-sweeps.ts:881-910: the sweep steps, includinginterrupted-fork-history-copiesandrelease-queued-message-claims.packages/bb-app/src/launcher.ts:4206-4215(the guard added for bb-app start boots a server against the shared database when another bb already serves the data directory #5404) exits only when another server answers/healthat this process's own URL. A different port, or a server started without the launcher, is not caught.
Suggested fix
Make the data dir exclusive for the life of a server, and check that before any database work. Two generic ways:
- A lock file in
BB_DATA_DIR, taken at the start ofrunServer, beforeinitDb, and held until exit. A second server fails at once with a clear message such as "Another server is using this data directory". - A cheaper early probe: before
initDb, read the runtime record in the data dir and refuse to start if the process it names is alive.
Keep the existing launcher check. This covers the cases it cannot see.
export async function runServer(serverConfig: ServerConfig): Promise<void> {
const release = await acquireDataDirLock(serverConfig.BB_DATA_DIR); // throws if held
// ... initDb, import boot, recovery sweep, listener
}
Activity
bb-slop-cop commentedon Nov 10, 2026
🚨 SLOP COP 🚨 ·
new-issue-autopilothost.confirmed-repro.