Skip to content

Let a project choose the environment its new threads start in - #6055

Closed
alexandre-vl wants to merge 11 commits into
get-bb:mainfrom
alexandre-vl:bb/project-default-environment
Closed

alexandre-vl wants to merge 11 commits into
get-bb:mainfrom
alexandre-vl:bb/project-default-environment

Conversation

@alexandre-vl

@alexandre-vl alexandre-vl commented Oct 21, 2026 •

Copy link
Copy Markdown
Contributor

Human comments

What was wrong

A project had no default environment that a user could see or set. Three places each decided on their own:

  • The root composer opened in the environment last picked in that browser, stored per project in bb.promptbox.environment in localStorage. Two browsers could disagree.
  • A thread created without an environment always got a new worktree on the primary host (thread-default-policy.ts), whatever the composer showed. That covers automations, Tasks presets and bb thread spawn with no environment flag.
  • Automations showed "Project default" with nothing behind it to see or change.

So nobody could send a project's background threads to a laptop or to a sandbox provider such as berth.

Builds on #6054, which starts Automatic threads on the project's machine and is now merged. This branch still contains that commit, so review only 44e31b5. e72c271 and the merges of main, 86a35a4 and 5c1ae3a, bring in main and move the SDK version. a22c9f3 passes projectDefaultEnvironment to the failed-run story main added in #6005.

What changed

  • Storage: a project_default_environments table (migration 0147, project-default-environments.ts).
    • A row is deleted with its project.
    • The migration uses CREATE TABLE IF NOT EXISTS, as 0146 does, because the migration tests rewind the ledger and run it again.
  • API: PATCH /projects/:id accepts defaultEnvironment: a provider environment, or null for Automatic. Project responses add defaultEnvironment and defaultEnvironmentProblem ({reason, message}).
  • Server policy:
    • Saving checks that:
      • the provider or composition exists;
      • a plain provider names an existing, persistent, non-removing machine with a checkout of the project;
      • a composition's project has a Git remote;
      • the provider accepts empty inputs.
    • A project-default thread starts in the stored default.
      • A Project checkout default gives each such thread its own worktree on that machine, and wakes the machine if it is suspended.
      • A child of a live thread still gets a worktree on its parent's machine.
    • An unusable default refuses creation with 409 project_default_environment_unavailable. The message says how to change or reset the default. There is never a silent fallback. Project responses run the same check, so Settings, the CLI and Automations all show the problem.
  • App:
    • Project settings → Thread defaults has an Environment row (ProjectDefaultEnvironmentSetting.tsx). It uses the composer's EnvironmentPickerUI, adds Reset to Automatic, and shows the server's problem.
    • The root composer starts in a usable default. A pick lasts for that tab's draft and clears after a send. Without a default, browser memory applies as before.
  • CLI:
  • Plugins: Automations shows Project default · <environment> or the unavailable state, and routes its model picker to the default's machine. Tasks explains what a project-default preset does.
  • Docs:
    • bb guide projects, threads, json and environments;
    • the bb-cli skill and its command index;
    • the Tasks delegation reference;
    • docs/api_to_audit.md.
  • SDK: @get-bb/plugin-sdk 0.6.68. The SDK's bundled declarations include the project schemas, which gain defaultEnvironment and defaultEnvironmentProblem.
  • No server/daemon wire change, so no HOST_DAEMON_PROTOCOL_VERSION bump.

How you verified

  • Server tests: public-projects.default-environment.test.ts, 20 tests on the real server and SQLite. They cover:
    • set, keep and reset, and each refusal;
    • root, child and composition threads;
    • a Project checkout default isolated in a worktree, and a Worktree default passed through;
    • a suspended default machine woken;
    • a provider that starts needing inputs: GET reports it and thread creation refuses it.
  • App tests: useThreadCreationOptions, root-compose-environment-selection, PluginNewThreadComposer and ProjectDetailSettingsView. The last one covers:
    • no write when a machine is only clicked;
    • compositions, and a missing Git remote;
    • an unusable default with Reset;
    • clearing the tab's draft.
  • CLI and plugin tests: project-default-environment.test.ts (17 tests) and 2 in thread-spawn.test.ts for the CLI. The Automations summary, detail and overview, and the Tasks dialog hint, for the plugins.
  • pnpm exec turbo run typecheck lint test --continue over @bb/server @bb/db @bb/server-contract @bb/sdk @bb/app @bb/cli @bb/templates @bb/demo-server bb-plugin-automations bb-plugin-tasks:
    • typecheck and lint passed;
    • tests passed: @bb/app 6254, @bb/cli 900, @bb/db 632, bb-plugin-tasks 409, @bb/sdk 124, @bb/server-contract 78, @bb/templates 46, @bb/demo-server 15;
    • @bb/server passed 3647 and bb-plugin-automations 150, with 5 and 1 failures that were timeouts and timing checks in unrelated suites under full-run load (install script, plugin loading and install jobs, timeline windows, the automations detail recipe). Rerun alone, they passed: 117 and 17.
  • SDK version: after pnpm exec turbo run build --filter=@get-bb/plugin-sdk, I ran node packages/plugin-sdk/scripts/check-npm-version-guard.mjs.
    • On 44e31b5 it failed as CI did: bundled-types/bb-plugin-sdk-app.d.ts and bb-plugin-sdk.d.ts differ from the published 0.6.65. Diffing them against npm pack @get-bb/[email protected] shows only the new defaultEnvironment and defaultEnvironmentProblem fields.
    • After merging main, at 0.6.74, it printed npm version guard: PASS — @get-bb/[email protected] is not on npm yet. The publish job will ship this version.
    • Also after the merge, on a22c9f3:
      • pnpm exec turbo run typecheck lint over the 13 packages this PR touches passed (23 tasks);
      • tests passed: @bb/app 6338, @bb/server 3694, @bb/cli 898, @bb/db 633, bb-plugin-tasks 410, @get-bb/plugin-sdk 398, @bb/domain 259, bb-plugin-automations 158, @bb/sdk 123, @bb/server-contract 78, @bb/templates 46, @bb/demo-server 15, bb-plugin-bb-guide 7;
      • one @bb/server test failed on my machine: bb-official-generator.test.ts expects git log --format=%cI to print 2026-01-02T03:04:05Z, and git 2.43 prints 2026-01-02T03:04:05+00:00. This PR does not touch that test or its script.
  • Live, on 44e31b5: a fresh pnpm dev with one machine (david), project "Shop", headless Chrome.
    • Settings → Thread defaults → Environment → Worktree showed david · Worktree with Reset, and kept it after a reload.
    • bb project default-environment show and bb project show both printed Default environment: Worktree on david.
    • A fresh browser's root composer opened on Worktree · Branch from: main. On main, it opened on Project checkout.
    • The automation set to Project default read Project default · Worktree on david. On main, it read Project default.
  • Review: an independent review found 8 issues; 6 are fixed here:
    • a suspended default machine is woken;
    • responses report a provider's inputs problem;
    • a Worktree default stays a worktree;
    • Settings disables compositions when the project has no Git remote;
    • responses reuse the sources already loaded;
    • changing the default clears the tab's composer draft.
  • Not done:
    • The composer gives no warning for an unusable default; it falls back to the last choice it displays. A follow-up that adds a "Default" marker to the picker will add the warning.
    • With the Worktree plugin disabled, a Project checkout default fails background threads with the existing 409 environment_provider_rejected, as Automatic does today.

Before / after

Before: main at b143a2286 · After: 44e31b5. Each side ran on a fresh pnpm dev with the same project "Shop" (one machine, david), in headless Chrome at 1280×860, cropped.

Before After
Project settings → Thread defaults Before: Thread defaults has no Environment row After: an Environment row, Automatic, with its picker open
Default set to Worktree on david, after a reload No setting After: david · Worktree with Reset
Root composer for Shop, fresh browser Before: opens on Project checkout from browser memory After: opens on the project's default, Worktree
Automation on Project default Before: Project default, nothing behind it After: Project default · Worktree on david

AGENT GENERATED

…ry host has no source

A project-default thread always resolved on the primary host, so a project
whose only source lives on another machine failed with 404 "Project has no
local-path source for host". When the primary host has no source of the
project, use the persistent machine that holds its default source, or its
oldest source on a persistent machine. Projects with a source on the primary
host keep today's placement; an offline project machine fails with 502
instead of moving the thread.

Fixes get-bb#4446
A project had no default environment. The root composer remembered the last
environment per browser, while threads created without one (automations,
tasks presets, `bb thread spawn` with no environment flag) always got a
worktree on the primary host, so "Project default" matched neither.

Store a per-project default environment, set from Project settings, the CLI
(`bb project default-environment`) or the API. The composer starts in it; a
pick made in the composer lasts for that tab's draft. Threads created
without an environment start in it too, a Project checkout default giving
each its own worktree on that machine. An unusable default refuses thread
creation with 409 and is reported on the project, instead of silently
falling back.
The SDK's bundled declarations include the project schemas, which now carry
defaultEnvironment and defaultEnvironmentProblem. 0.6.65 is already on npm,
so the npm version guard refused to republish it with different types.
alexandre-vl added a commit to alexandre-vl/bb that referenced this pull request Oct 21, 2026
alexandre-vl added a commit to alexandre-vl/bb that referenced this pull request Oct 21, 2026
get-bb#6055 now ships 0.6.66 with the project default environment types, so the
composer props this branch adds need the next version, and the automations
plugin that uses them requires it.
Main moved the SDK to 0.6.67 (get-bb#6048, get-bb#6051), so this branch's own type
changes need the next version.
alexandre-vl added a commit to alexandre-vl/bb that referenced this pull request Oct 21, 2026
get-bb#6055 now carries main and ships 0.6.68, so the composer props this branch
adds need 0.6.69, and the automations plugin that uses them requires it.
alexandre-vl added a commit to alexandre-vl/bb that referenced this pull request Oct 21, 2026
Tests (plugins) failed in plugins/connect-next/src/frp-e2e.test.ts:394,
which this branch does not touch: frpc reported "read: connection reset by
peer" where the test only accepts connection refused, EOF or dial. The same
code passed on main and on get-bb#6055, and three local runs pass.
Main already carries "Start project-default threads on the project's
machine when the primary host has no source" (get-bb#6054) and "Show why an
automation failed" (get-bb#6005); the merge keeps their code and adds this
branch's project default environment on top. The project default
environment entry in docs/api_to_audit.md follows main's new entries.
Main's failed-run story (get-bb#6005) renders AutomationDetailView, which now
requires projectDefaultEnvironment.
alexandre-vl added a commit to alexandre-vl/bb that referenced this pull request Oct 23, 2026
…nment-composer

Pick up get-bb#6055 and get-bb#6056 merged with main, with the plugin SDK at 0.6.75.
@github-actions github-actions Bot closed this Nov 5, 2026
@github-actions

github-actions Bot commented Nov 5, 2026

Copy link
Copy Markdown
Contributor

This is an automated message. We have closed this pull request because it has been open for more than two weeks.

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