Skip to content

Consolidate environment provisioning into one durable lifecycle - #3443

Merged
ymichael merged 6 commits into
mainfrom
bb/apply-one-host-row-design-elsewhere-thr_crci7kz3hu
Sep 10, 2026
Merged

ymichael merged 6 commits into
mainfrom
bb/apply-one-host-row-design-elsewhere-thr_crci7kz3hu

Conversation

@ymichael

@ymichael ymichael commented Sep 10, 2026 •

Copy link
Copy Markdown
Collaborator

Human comments

What was wrong

Workspace creation was split between an environment_launches row, an environment row, and in-memory thread provisioning contexts. Separate provider and daemon orchestration paths handed the same lifecycle between them, making restart recovery, cancellation, and retries depend on duplicated state. A provisioning sweep could fail a workspace while its provider was still creating it.

What changed

  • Reserve one environment row before provider creation. One engine and operation registry advance it through creating, daemon attachment/setup (provisioning), and ready, and handle cancellation, cleanup, and retirement.
  • Persist thread startup requests in threads.startup_context; derive provisioning stage from rows and resolve placement directly into the environment reservation.
  • Retain five creation fields: owner_thread_id, attempt, status_message, pending_log, and claim_path. Attachment clears ownership atomically with the thread's environment binding. Creation failures are terminal; explicit retries reuse the row with a new attempt. Remove duplicate phase/attachment flags and the transient-create retry ladder.
  • Keep exclusive path claims, shared-checkout identity, restart recovery, and retirement. Retry failed attached setup on the existing environment, and wait for daemon reconnection before recovering setup.
  • Cancelling a preparing thread that has claimed an existing shared workspace leaves that workspace ready for its other threads. Defer the error status until removal actually starts; keep provider logging in one reporter path and use an explicit path-admission assertion.
  • Add migration 0116_majestic_swordsman.sql and its Drizzle-generated snapshot. It transfers unfinished allocations and startup requests, then drops environment_launches.
  • Update the environment-provider SDK failure result and Plugin Guide to describe terminal creation failures. Existing CLI/SDK environment status exposes creating; daemon wire payloads are unchanged, so no protocol bump is needed.

How you verified

  • Full Turbo typecheck: 94 tasks passed after merging main. Server/db typechecks passed again after the final review fixes.
  • Latest full server/db suites with --maxWorkers=4: server 2,400 passed / 1 skipped; db 483 passed. The default-worker run hit the previously observed five-second provider-discovery timeout.
  • Full app and CLI suites passed before the later server fixes and main merge: app 4,216 passed / 3 skipped; CLI 558 passed.
  • Recovery/shared-environment integration tests: 10 passed; built-in environment-provider tests: 74 passed.
  • Added regression coverage for cancelling a preparing owner of a shared ready workspace, including transcript finalization, and exactly-once provider log delivery. Updated deletion API assertions to preserve status until removal starts.
  • Added regression coverage for recovery while the daemon is disconnected and changed setup-retry coverage to exercise turn dispatch, which exposed the allocation regression missed by direct engine tests.
  • Ran the worktree server and drove the matching bb CLI against a disposable Git project with real Codex and Cursor providers. Verified file reads and final assistant responses, fresh worktree creation, checkout/shared-environment reuse, setup failure and same-row retry, server restart during setup, cancellation before and after attachment, retirement/unarchive, and directory removal. The live run found the setup-retry and reconnect fixes, then passed their repeated scenarios. It preceded the final shared-workspace cancellation review fix. Claude authentication was expired, so its agent-execution check was blocked.

Commands included pnpm exec turbo run typecheck, pnpm exec turbo run test --filter=@bb/server --filter=@bb/app --filter=@bb/db --filter=@bb/cli --continue --force, pnpm exec turbo run typecheck lint test --filter=@bb/server --filter=@bb/db, and the final suite rerun pnpm exec turbo run test --filter=@bb/server --filter=@bb/db -- --maxWorkers=4. Neither server nor db defines a lint task.

AGENT GENERATED

@ymichael
ymichael merged commit 5f28a66 into main Sep 10, 2026
16 checks passed
@ymichael
ymichael deleted the bb/apply-one-host-row-design-elsewhere-thr_crci7kz3hu branch September 10, 2026 23:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant