Skip to content

Spawning onto a project checkout destroys its existing environment when that environment was created with a new-branch input ("Environment is destroyed") #4186

Closed

Description

@Tiberriver256

Summary

Starting a new thread on a project checkout destroys that checkout's existing environment if the environment was first created with a branch: { kind: "new" } input. The new thread fails about 1–3 s after spawn with Provisioning thread failed / Environment is destroyed. The files on disk are untouched, because project-checkout remove() is a no-op, but the environment row is gone for good. Starting the same thread again succeeds and creates a new environment. Expected: the new thread adopts the idle environment and starts.

Versions and environment

  • bb 0.43.4 (npx bb-app@latest, server version endpoint reports currentVersion: 0.43.4), Linux (WSL2) server
  • Host daemons 0.43.4 on 8 enrolled Ubuntu machines (manual provider), --auto-update
  • claude-code provider; not provider-specific (failure happens before any turn)
  • project-checkout environment provider, long-lived user-maintained checkouts (one per machine per project)

Steps to reproduce

Observed three times today on 0.43.4: twice from the desktop new-thread composer (Project checkout on a machine) and once from the CLI. I have not yet repeated it on a scratch project. The steps below are the smallest sequence that the evidence and code point to:

  1. Create a thread on a project checkout with a new-branch input, so that environment_provider_selection.inputs.branch is stored on the environment:
    bb thread spawn --project <proj> --machine <host> \
      --environment-provider project-checkout \
      --environment-inputs '{"branch":{"kind":"new","baseBranch":"develop"}}' \
      --prompt "Reply only with ok."
  2. Archive it once it is idle: bb thread archive <thr>. The environment stays ready, lifecycle.phase: active, retireAt: null, since project-checkout has retireGraceMs: null.
  3. Start a new thread on the same checkout without a branch input:
    bb thread spawn --project <proj> --machine <host> \
      --environment /home/<user>/repos/<repo> --prompt "Reply only with ok."
  4. bb thread log <new-thr> → provisioning fails within ~3 s; bb environment show <old-env> → destroyed.

Did not reproduce with: checkout environments whose stored selection has no branch input ({"machine":…,"inputs":{"path":…}}). Two of those were adopted normally by a path spawn today (env_5u2r9k57wk, env_2gzwgkvvgf). A spawn with --environment <env_id> (reuse intent) was also fine.

Expected vs actual

Actual (bb thread log, all three occurrences identical):

── Provisioning thread failed ──────────────────────────────
  Preparing workspace
  Preparing Project checkout…
  Provisioning thread failed (3s)

── Error ───────────────────────────────────────────────────
  Provisioning thread failed
  Environment is destroyed
$ bb environment show env_jn7khv32fh
  Status: destroyed
  Lifecycle: destroyed
  Teardown: removed (attempt 1)
  Provider: project-checkout

Expected: the new thread adopts the idle checkout environment, or gets a fresh one, and starts. An environment with no live threads under a provider with retireGraceMs: null should not be torn down just because a new thread arrived with a different selection.

Evidence

Timeline (UTC). "Destroyed" is the environment row's updated_at:

environment last live thread archived new thread created env destroyed Δ
env_znwxv5e7d4 thr_rs997aha8t 2026-09-23T15:21:34Z thr_gvbisidxfg 15:29:36.41Z 15:29:39.65Z 3.2 s
env_ixkm7i2drg thr_y9j4z9e2is 2026-09-23T01:07:44Z thr_629c8wyqei 15:29:06.42Z 15:29:09.78Z 3.4 s
env_jn7khv32fh thr_g7u2kjezsf 2026-09-22T18:32:51Z thr_bx6zmkj9c2 16:02:16.27Z 16:02:17.24Z 1.0 s

The time since archive ranges from 8 minutes to 21 hours, so this is not a grace-period expiry. Each environment was destroyed about 1–3 s after a spawn.

Rows after the failure (read-only query of bb.db). All three have the same shape: owner_thread_id is the new thread, and the stored selection carries the old thread's branch: new input:

env_jn7khv32fh status=destroyed teardown_status=removed teardown_attempt=1 retire_at=NULL
  owner_thread_id=thr_bx6zmkj9c2 (the new, failed thread)
  environment_provider_instance_key=thr_g7u2kjezsf (the original thread)
  environment_provider_selection={"machine":{"type":"existing","hostId":"host_xqsevvg7y6"},
    "inputs":{"path":"/home/<user>/repos/<repo>","branch":{"kind":"new","baseBranch":"develop"}}}

The environments that were adopted correctly have inputs: {"path": …} with no branch.

My reading of the path at desktop-v0.43.4 (9b8c1d3). This is inferred from code, not traced with a debugger:

  1. The path spawn reserves a fresh row. The project-checkout create attaches and returns the existing checkout path, and bindEnvironmentPath (called from environment-engine.ts#L421) adopts the existing row. It moves ownerThreadId to the new thread but keeps environmentProviderSelection: existing.environmentProviderSelection (L577), which is the old branch: new selection.
  2. On the next provisioning pass, prepareProviderEnvironment compares that stored selection with the new request's {machine, inputs}. changed is true, so it calls cancelProviderEnvironmentCreation.
  3. cancelProviderEnvironmentCreation sets teardownStatus: "running". In sweepProviderEnvironmentInSlot, cancelled is then true and there are no live threads, so retireAt = now. That bypasses the provider's retireGraceMs: null (checkout plugin L148). Removal runs, the no-op remove() returns removed, and destroy.recorded is applied.
  4. startThreadIfEnvironmentReady then sees status: destroyed → Environment is destroyed.

So the cancel meant for the new thread's own abandoned reservation ends up tearing down a shared, adopted environment. Possible fixes (maintainers' call): have bindEnvironmentPath take the current selection when it adopts a row, or have the placement changed check skip teardown for an adopted environment that has no pending creation.

What you ruled out

Suggested priority and effort

Medium: any project-checkout user who ever spawned with a new-branch input hits it on their next thread on that checkout, from both the composer and the CLI. You can't see it coming: the environment looks ready / active right up to the spawn. No data is lost and retrying the spawn works. The fix looks local to adoption or the selection comparison.

  • Reproduced on the latest release: three live occurrences on 0.43.4. Not yet repeated on a scratch project.
  • Searched open and closed issues for the same problem.
  • Agent-written. The investigation ran in a Claude Code session outside bb, so there is no bb thread to link. The thread and environment ids above are from that install.

AGENT GENERATED

Activity

  1. added theissue type on Sep 23, 2026
  2. added
    workspaces
    confirmed-repro
    on Sep 23, 2026
  3. bb-slop-cop commented on Sep 23, 2026

    @bb-slop-cop
    Contributor

    🚨 SLOP COP 🚨 · new-issue-autopilot

    Bug · Priority: Medium · Effort: Medium. Applied workspaces and confirmed-repro.

    REPRODUCED · High confidence. Adoption preserves the old provider selection; the next preparation pass mistakes it for a changed request and cancels the ready environment. A focused regression reproduced the resulting destroyed state in two clean trusted-main checkouts using migrated SQLite and an in-process provider. Live CLI/UI attachment was not exercised.

    Reproduction and root-cause report · Fix PR #4187

    The regression fails before the fix and passes afterward. All 83 relevant tests and server typecheck pass. The ready, unmerged PR changes 46 text lines across two files.

  4. added a commit that references this issue on Sep 24, 2026
    384666f
  5. alanagoyal commented on Oct 14, 2026

    @alanagoyal
    Contributor

    Additional production occurrence from the reporter’s bb logs, investigated on 2026-10-13. This appears to be the same adoption/selection-mismatch bug on desktop 0.43.4, with a useful variant: no new-branch input is present. The old selection contains inputs.path, while the new reservation contains inputs: {}.

    Versions and environment

    • macOS 26.6.2 (25G83), installed /Applications/bb.app; both CFBundleShortVersionString and bundled bb-app/package.json report 0.43.4. bb --version also reports 0.43.4.
    • Project checkout on local host host_6tasqdyqm3, project proj_5xhs8fecxp (investor-update-emails), standard ~/.bb data directory; Connect requests are present in the server log.
    • Requested provider: Codex, model gpt-6.1-sol, high reasoning. No provider session started in the failed thread. Installed Codex currently reports codex-cli 0.162.1; its version at the incident was not captured.
    • Investigation checkout: 98706229e4e088b46f1b676280c891f224d4a071; this is not the commit of the installed app. No fresh reproduction or fix verification was performed; this evidence comes from the retained production event log and read-only database queries.

    Observed workflow / reproduction status

    The user started “Add the linked X post” in the investor-update-emails project with:

    https://x.com/induction_labs/status/2110059300651679969?s=20
    
    add this as a portfolio update for october
    

    The thread failed during checkout preparation. The screenshot shows Provisioning thread failed, Environment is destroyed, and the composer’s Environment archived state. The failed thread was subsequently archived, over an hour after the failure; archive was not the trigger.

    Faithful candidate reproduction (not independently rerun): use a 0.43.4 project-checkout environment whose recorded selection has inputs: {path: <checkout>}, archive its existing threads, then start a new thread through the project’s default checkout selection (inputs: {}). Expected: adopt the existing checkout and start. Actual retained occurrence: adoption is followed immediately by teardown and provisioning failure.

    Thread event evidence

    Affected thread: thr_8i5qrh33m2; provisioning ID: tpv_xscvjw6tan; request ID: creq_98bkw23vf4.

    UTC timeline reconstructed from bb thread log thr_8i5qrh33m2 --all --json and environment row timestamps:

    Time (2026-10-13 UTC) Observation
    12:21:20.607 Thread created
    12:21:23.829 New environment reservation env_cyfx4rbmk9 created
    12:21:23.830 Preparing Project checkout… on env_cyfx4rbmk9
    12:21:23.937 Reservation marked destroyed/removed, attempt 0 teardown; consistent with adoption
    12:21:23.938 Checkout preparation completed on existing env_dmgbpvbpup
    12:21:24.071 Existing environment updated to destroyed/removed, teardown attempt 1
    12:21:29.055 system/error: provisioning failed
    13:45:45.437 Failed thread archived

    Verbatim error event payload (seq 8):

    {
      "code": "thread_provisioning_failed",
      "message": "Provisioning thread failed",
      "detail": "Environment is destroyed"
    }

    bb thread log thr_8i5qrh33m2 --all ends with:

    ── Error ───────────────────────────────────────────────────
      Provisioning thread failed
      Environment is destroyed
    

    Read-only database evidence

    env_cyfx4rbmk9:
      status=destroyed teardown_status=removed teardown_attempt=0
      owner_thread_id=NULL environment_provider_instance_key=thr_8i5qrh33m2
      environment_provider_selection={"machine":{"type":"existing","hostId":"host_6tasqdyqm3"},"inputs":{}}
    
    env_dmgbpvbpup:
      status=destroyed teardown_status=removed teardown_attempt=1
      owner_thread_id=thr_8i5qrh33m2
      environment_provider_instance_key=thr_76sv5u8k6e
      provider_owns_path=0 path=NULL retire_at=NULL
      environment_provider_selection={"machine":{"type":"existing","hostId":"host_6tasqdyqm3"},"inputs":{"path":"/Users/alanagoyal/Developer/investor-update-emails"}}
    

    The old environment was created on October 1. Its two preceding threads (thr_76sv5u8k6e, thr_en9adqjthv) were both archived that day. The earlier thread’s retained provisioning events show successful workspace preparation on main; its later agent error was an unsupported model, a separate failure.

    Relevant ~/.bb/logs/server.21.log entries confirm the failed thread was served successfully through Connect, rather than failing to load:

    {"level":30,"time":1791919280886,"component":"server","msg":"[plugin:connect] bb connect thread load path=/api/v1/threads/thr_8i5qrh33m2/timeline status=200 originTtfbMs=3.8 originBodyMs=0.1 totalMs=3.8 responseBytes=765 contentEncoding=br"}
    {"level":30,"time":1791919281108,"component":"server","msg":"[plugin:connect] bb connect thread load path=/api/v1/threads/thr_8i5qrh33m2/conversation-outline status=200 originTtfbMs=6.4 originBodyMs=0.2 totalMs=6.7 responseBytes=213 contentEncoding=identity"}

    No matching thread/environment diagnostic was found in host-daemon.21.log; the decisive error is persisted in the thread event log. The precise teardown caller was not traced, so the selection-mismatch diagnosis remains an inference from the matching sequence and stored selections.

    Relationship to the fix / ruled out

    Investigation thread: thr_rip7xgkudz (“Find errored thread and open issue”); original affected thread: thr_8i5qrh33m2 (“Add the linked X post”).

    AGENT GENERATED

  6. alanagoyal commented on Oct 14, 2026

    @alanagoyal
    Contributor

    Follow-up after the reporter clarified that this happened today (2026-10-13): verified the actual installed server code, rather than relying on its version label.

    The installed desktop app’s source map at /Applications/bb.app/Contents/Resources/app.asar.unpacked/node_modules/bb-app/server/dist/start-server.js.map, source ../src/services/threads/thread-environment-placement.ts, contains:

      const changed =
        row !== null &&
        (row.environmentProviderId !== record.provider.id ||
          JSON.stringify(row.environmentProviderSelection) !==
            JSON.stringify(selected));

    This does not contain the row.status !== "ready" selection guard added by #4187. The installed artifact therefore still contains the faulty comparison, despite the fix having merged in the repository. The explicit-path versus default-input mismatch in today’s environment rows hits that comparison.

    Correction to the interpretation of the preceding report: this is a current, user-visible failure on the installed 0.43.4 desktop artifact, not a resolved experience for this user. A merged source fix does not establish that their installed release includes it. Whether a newer published desktop release includes the fix has not been checked. No fresh spawn was performed and no claim is made that the running process was independently fingerprinted; the retained incident and the installed artifact both support the original defect.

    Investigation: thr_rip7xgkudz; affected thread: thr_8i5qrh33m2.

    AGENT GENERATED

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-reproworkspaces

    Type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions