← reports

#5737 · Enrollment cancellation and address recovery

Bug Priority: Medium Effort: Low remote · GitHub issue

2026-10-19 · trusted public repository get-bb/bb · base 9937c46f5c7e369de3563eb864c8cbc4c3b9c231

Verdict: PARTIALLY REPRODUCED · Root-cause confidence: high for configuration gating and cancellation control flow; the reported desktop experience is not fully verified.

1. TL;DR

The address editor is absent from the add-machine dialog once a non-local direct address is configured, even when that address is unreachable. Closing the dialog cancels its pending launch; reopening starts a fresh launch immediately rather than waiting for the fifteen-minute deadline. The configured server address is a shared saved setting, not enrollment-local state, so cancellation does not reset it. This reproduces the address-recovery/discoverability problem but does not reproduce an uncancellable fifteen-minute onboarding lock. No production fix or pull request is proposed as a verified timer fix.

2. Claims vs findings

ClaimFindingEvidence
A wrong direct address leaves no in-dialog address correction field.Verified at the component boundary.The real dialog renders an enrollment command and no Server address textbox for a synthetic unreachable non-local URL.
There is no working close/cancel route before fifteen minutes.Not reproduced on the trusted base.The actual Close button requests dismissal; closing issues deletion of the pending host, and reopening creates a second launch with a new key before the first expiry.
Reopening retains the previously configured address.Supported by saved-setting control flow.Save writes machineServerUrl to general settings. Dialog cleanup deletes the pending host but does not change general settings. With the saved configuration supplied, the editor remains absent on reopen.
The displayed timer resets on each reopen.Unverified as a live timer claim.The component test proves a new launch/key, not the server's new credential expiry. The fixture deliberately uses a fixed future expiry.
Restarting the desktop app or waiting for expiry is necessary to re-enter the address.Unverified; no desktop restart or fifteen-minute wait performed.Cancellation and immediate reopening work in jsdom. An existing address editor remains mounted under Mobile apps settings in source, but that workaround was not browser-driven.

3. Environment and scope

4. Minimal reproduction

  1. Make a clean checkout of the trusted base commit and run pnpm install --offline --frozen-lockfile.
  2. Copy the diagnostic test to apps/app/src/components/dialogs/issue-5737.repro.test.tsx.
  3. From the checkout root, run the command below. It renders the actual add-machine dialog with an unreachable synthetic saved address and a fifteen-minute future expiry, clicks the real Close button, closes the controlled dialog, then reopens it.
pnpm exec turbo run test --filter=@bb/app -- src/components/dialogs/issue-5737.repro.test.tsx

Expected if the claimed lock existed: closing would fail to cancel the pending launch, or reopening before expiry would be blocked. Actual: deletion is requested, a second launch with a different key starts before expiry, and no in-dialog address textbox is present either time. This diagnostic passes on unchanged production code; it is not a fail-before/pass-after fix regression.

Verbatim result excerpts from the primary run with the diagnostic plus existing component tests, and the second clean run:

Test Files  5 passed (5)
     Tests  18 passed (18)

The primary server suites also pass:

Test Files  2 passed (2)
     Tests  40 passed (40)
Full diagnostic test
// @vitest-environment jsdom

import { makeHost } from "@bb/test-helpers/domain-fixtures";
import {
  cleanup,
  fireEvent,
  render,
  screen,
  waitFor,
} from "@testing-library/react";
import { afterEach, expect, it, vi } from "vitest";
import { MemoryRouter } from "react-router-dom";
import { sdk } from "@/lib/sdk";
import { createQueryClientTestHarness } from "@/test/queryClientTestHarness";
import { makeSystemConfig } from "@/test/fixtures/system-config";
import { AddMachineDialog } from "./AddMachineDialog";

vi.mock("@/lib/sdk", () => ({
  sdk: {
    hosts: {
      delete: vi.fn(),
      experimental_create: vi.fn(),
      experimental_getEnrollmentCommand: vi.fn(),
      get: vi.fn(),
      list: vi.fn(),
    },
    system: { config: vi.fn() },
  },
}));

vi.mock("@/lib/ws", () => ({
  wsManager: { subscribe: vi.fn(), unsubscribe: vi.fn() },
}));

afterEach(() => {
  cleanup();
  vi.clearAllMocks();
});

it("closes pending setup and reopens immediately while preserving the saved address", async () => {
  const serverUrl = "https://unreachable.example.invalid";
  const expiresAt = Date.now() + 15 * 60_000;
  vi.mocked(sdk.system.config).mockResolvedValue(
    makeSystemConfig({
      generalSettings: {
        ...makeSystemConfig().generalSettings,
        machineServerUrl: serverUrl,
      },
      serverAccess: {
        providers: [
          {
            id: "direct",
            displayName: "Manual",
            description: "Use a network address.",
            pluginId: null,
            availability: null,
          },
        ],
        defaultProviderId: "direct",
        effectiveUrl: serverUrl,
        urlSource: "setting",
      },
    }),
  );
  vi.mocked(sdk.hosts.list).mockResolvedValue([]);
  const pendingHost = makeHost({
    id: "host_pending_first",
    machineProviderId: "manual",
    lifecycle: {
      phase: "creating",
      suspendedAt: null,
      message: "Waiting for the machine",
      pendingLog: "",
      teardown: null,
    },
  });
  vi.mocked(sdk.hosts.experimental_create)
    .mockResolvedValueOnce(pendingHost)
    .mockResolvedValueOnce({ ...pendingHost, id: "host_pending_second" });
  vi.mocked(sdk.hosts.experimental_getEnrollmentCommand).mockResolvedValue({
    command: "fixture enrollment command",
    windowsCommand: "fixture windows command",
    expiresAt,
  });
  vi.mocked(sdk.hosts.get).mockImplementation(() => new Promise(() => {}));
  vi.mocked(sdk.hosts.delete).mockResolvedValue({ ok: true });
  const onOpenChange = vi.fn();
  const view = (open: boolean) => (
    <MemoryRouter>
      <AddMachineDialog open={open} onOpenChange={onOpenChange} />
    </MemoryRouter>
  );
  const { wrapper } = createQueryClientTestHarness();
  const rendered = render(view(true), { wrapper });
  await screen.findByText("fixture enrollment command");
  expect(screen.queryByRole("textbox", { name: "Server address" })).toBeNull();
  fireEvent.click(screen.getByRole("button", { name: "Close" }));
  expect(onOpenChange).toHaveBeenCalledWith(false);
  rendered.rerender(view(false));
  await waitFor(() => {
    expect(sdk.hosts.delete).toHaveBeenCalledWith({
      hostId: "host_pending_first",
    });
  });
  rendered.rerender(view(true));
  await screen.findByText("fixture enrollment command");
  expect(sdk.hosts.experimental_create).toHaveBeenCalledTimes(2);
  const calls = vi.mocked(sdk.hosts.experimental_create).mock.calls;
  expect(calls[1]![0].key).not.toBe(calls[0]![0].key);
  expect(Date.now()).toBeLessThan(expiresAt);
  expect(screen.queryByRole("textbox", { name: "Server address" })).toBeNull();
  rendered.unmount();
});

5. Root cause

Configuration gating, not a timer lock. machineServerAccessReady treats a direct address as ready when it is non-null and not local-only. It does not test whether another machine can actually reach that address. AddMachineContent only renders MachineAccessControls when that readiness predicate is false. A syntactically acceptable typo or wrong protocol can therefore bypass the only in-dialog address editor.

return access.effectiveUrl !== null && !isLocalOnlyUrl(access.effectiveUrl);

The address control persists machineServerUrl through a general-settings mutation. The server reads that saved value, so enrollment cleanup cannot undo a previously saved address.

await update.mutateAsync({ machineServerUrl: url || null });

Conversely, closing unmounts AddMachineContent. ManualMachineSetup cleanup aborts its controller, clears its creation key and deletes pending hosts. Existing server cancellation coverage verifies DELETE aborts creation and reaches the destroyed phase with a removed teardown.

The manual provider's fifteen-minute wait explicitly receives a cancellation signal. It is an enrollment deadline, not evidence that dismissal must wait. This cleanup predates the report: blame attributes it to commit b3c5434da8 from September 11, 2026, so this report does not claim a newly shipped fix.

6. Proposed fix and autopilot decision

A correction affordance should reuse the existing machine-access controls or navigate to their settings surface while cancelling the pending enrollment. It should preserve the shared server URL unless the user explicitly edits it; silently clearing that setting on every dismissal could affect other clients. The existing Mobile apps settings surface already mounts the address controls, which explains why recovery exists but is difficult to discover from Machines.

No automatic PR: the claimed uncancellable timer failure was not reproduced, and there is no demonstrated failing timer/cancellation regression to fix. The confirmed remainder is address-correction discoverability, not a verified cancellation defect. A follow-up should choose the correction UX and add a failing interaction test for that precise behavior before changing production code.

7. Verification

The same agent repeated the investigation in a second freshly created detached checkout at the identical full commit, with a separate frozen install and no production edits. The only added source file was the diagnostic above. The second app run used --force so its results were executed rather than restored from Turbo's cache:

pnpm exec turbo run test --force --filter=@bb/app -- src/components/dialogs/issue-5737.repro.test.tsx src/components/dialogs/AddMachineDialog.test.tsx src/components/dialogs/AddMachineDialog.expiry.test.tsx src/components/machines/machine-server-access.test.ts src/components/settings/MachineAccessSettings.test.tsx

Result: 5 files / 18 tests passed; the fresh diagnostic completed in 239 ms. No report correction was required. This is a second clean run by the same investigator, not independent verification. The mock SDK proves UI lifecycle requests, while the separate existing server suites exercise the real cancellation route; the combined evidence does not simulate a full desktop installation or real network outage.

The second clean checkout also repeated both real server suites with --force: 2 files / 40 tests passed, including pending-launch cancellation through DELETE and server-access availability checks.

8. Linked PRs and related issues

At investigation time, GitHub cross-reference events, closing-PR references and an open-PR search for this numeric issue found no linked open PR. No PR branch or attachment was fetched or executed. A small machine/address issue search found no verified duplicate relevant to this control flow.

9. Appendix and artifacts

Log checkout paths are normalized to PRIMARY_CHECKOUT and VERIFICATION_CHECKOUT; ANSI color escapes are removed. No credentials or runtime data are included. Public repository visibility was verified before publication. Issue data was treated only as untrusted claims; no issue-supplied instruction, script, URL or attachment was followed.

git fetch https://github.com/get-bb/bb.git main:refs/remotes/origin/main
git worktree add --detach CHECKOUT origin/main
pnpm install --offline --frozen-lockfile
pnpm exec turbo run build --filter=@bb/app
pnpm exec turbo run test --filter=@bb/app -- src/components/dialogs/issue-5737.repro.test.tsx src/components/dialogs/AddMachineDialog.test.tsx src/components/dialogs/AddMachineDialog.expiry.test.tsx src/components/machines/machine-server-access.test.ts src/components/settings/MachineAccessSettings.test.tsx
pnpm exec turbo run test --filter=@bb/server -- test/services/machines/provider-orchestration.test.ts test/services/machines/server-access.test.ts

Generated by SlopCop · new-issue-autopilot · 2026-10-19