Skip to content

bb-app can enroll a host against the wrong server after its server child fails with EADDRINUSE #1558

Closed

Description

@markasoftware-tc

(heads up: this whole issue is ai-written but i believe it's a real issue and ran into it myself. I got gpt-5.6-sol to debug and write up this issue)

When two bb-app launchers use different data directories but the same server and daemon ports, the second
launcher can mistake the first launcher's server for its own.

If the second server child fails with EADDRINUSE, bb-app may still consider startup successful because its
health check receives a successful response from the existing server. It then requests a host enrollment key from
that existing server while saving the resulting host credentials in the second data directory.

After the existing server stops, the second launcher's host daemon connects to the server backed by its own
database. That database does not contain the enrolled host, resulting in INVALID_API_KEY or a 401 response
saying that the host is not registered.

Environment

  • bb-app: 0.35.1
  • Node.js: 26.5.1
  • npm/npx: 11.17.0
  • OS: Linux x86_64

Reproduction

In one terminal, start bb with a separate data directory:

BB_DATA_DIR=/tmp/bb-one npx bb-app@latest

In another terminal, start bb using another data directory but the same default ports:

BB_DATA_DIR=/tmp/bb-two npx bb-app@latest

The second server child cannot bind port 38886 and exits with:

listen EADDRINUSE: address already in use :::38886

However, the launcher's health request to http://127.0.0.1:38886 can be answered by the first server. The second
launcher may consequently report:

✓ Server listening on http://127.0.0.1:38886

It then requests an enrollment key from the first server and writes the resulting host identity to /tmp/bb-two/
auth.json.

After stopping the first launcher and starting the second one again, the host daemon fails with errors such as:

Server rejected host credentials — this host is not registered with the server.

or:

INVALID_API_KEY

The host ID from /tmp/bb-two/auth.json is present in /tmp/bb-one/bb.db, but absent from /tmp/bb-two/bb.db.

## Expected behavior

If the managed server child fails to bind its port, the launcher should fail startup and should not create or
modify host authentication state.

A health response from another process should not satisfy the managed child’s startup check.

## Actual behavior

The health check accepts a successful response from an unrelated server on the configured port. The launcher then
enrolls a host against that server while persisting the resulting credentials in a different data directory.

This leaves valid credentials associated with the wrong database and produces a misleading API-key error on
subsequent launches.

## Suspected cause

waitForHealth() checks whether the child process has exited and polls the configured health URL. There appears to
be a race where the unrelated server responds successfully before the failed child’s exit is observed.

More generally, an HTTP 2xx response only proves that a server is listening, not that it is the child process just
spawned by this launcher.

## Suggested fix

Give each managed launch a unique nonce or identity:

1. Generate a random startup nonce in the launcher.
2. Pass it to the server child.
3. Require the health endpoint to return that nonce.
4. Accept health only when it matches.

Alternatively, the health response could expose and verify an immutable launch identity that includes the expected
data directory.

The launcher should also stop immediately if its managed child exits during startup, even if the configured port
independently becomes healthy.

## Error-message improvement

INVALID_API_KEY is misleading here because this is bb’s internal daemon-host credential, not an inference-provider
API key.

A more actionable message would be:

> The saved host credential is not registered with this bb server. It may have been created by another server or
> data directory. Remove auth.json to re-enroll this host.

Unrecoverable host-authentication failures should also stop the restart loop and print recovery instructions.

## Workaround

Stop all bb instances, remove or move the mismatched host credential, and restart:

mv /tmp/bb-two/auth.json /tmp/bb-two/auth.json.invalid
BB_DATA_DIR=/tmp/bb-two npx bb-app@latest

This causes the host to enroll against the correct server database.

Activity

  1. added theissue type on Aug 13, 2026
  2. added
    desktop
    connect
    on Aug 18, 2026
  3. SawyerHood commented on Aug 18, 2026

    @SawyerHood
    Collaborator

    Reproduction & root-cause report: https://get-bb.github.io/reports/issues/1558.html

    • Verdict: REPRODUCED · root-cause confidence: high
    • Root cause (short): bb-app's waitForHealth() accepts any 200 from /health on the configured port (a constant {ok:true}) with no identity check, so a foreign bb server on the same port satisfies the probe on the first poll before the launcher's own server child dies with EADDRINUSE; the launcher then mints an enroll key from that foreign server and its daemon persists the resulting host key into the wrong data dir (before binding its own port), which the correct server later rejects with 401/INVALID_API_KEY.
    • Proposed fix: Make the launcher's server readiness probe prove identity, not liveness: generate a per-launch id (e.g. BB_SERVER_LAUNCH_ID=randomUUID()) in startFullStackServerProcess, pass it to the server child env, have the server echo it on /health (or a loopback-only /internal/launch-identity), and have waitForHealth accept only a 200 whose id matches (mirroring waitForHostDaemonStatus, which already checks hostId/serverUrl). A foreign server then never satisfies the probe, the child's EADDRINUSE exit surfaces as 'Process exited before becoming healthy', and maybeAddAutoJoinEnv/enrollment is never reach…
    • Caveats: Repro used the built packages/bb-app/dist/bb-app.js from the worktree on ports 45886/45887 (not npx bb-app@latest on 38886) to avoid touching the user's real instance; the launcher code is byte-identical to tag desktop-v0.35.1 and 0.38.0. Worktree HEAD was a108fa7 (ahead of base 16ceb3a) but the diff for all involved files vs base is empty. The unit repro requires a one-line export on the pr…

    The report has copy-paste repro steps, screenshots where the bug is visual, code permalinks at 16ceb3a54, and repro artifacts. It was independently re-run by a second agent (see its Verification section).

    AGENT GENERATED: by Claude Opus 5

  4. added
    confirmed-repro
    on Aug 18, 2026
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

    confirmed-reproconnectdesktop

    Type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions