#5204 · Personal child placement overrides an explicit machine
Trusted base: f135a001e72942cee9118d2693208ec0725e2f18 · Verdict: REPRODUCED · Root-cause confidence: high
1. TL;DR
A personal child thread can select a different execution machine yet still receive its parent's environment. The server's personal-child default policy returns a reuse decision before examining the requested machine. Both the host/personal request used by the CLI and an explicit personal-workspace provider request lose their machine selection. A regression at the owning server-policy boundary fails in the same three scenarios in two clean checkouts of main. This investigation verifies the placement decision, not an actual macOS-to-Windows agent session.
2. Claims vs findings
| Claim | Status | Evidence |
|---|---|---|
| Personal children ignore a different machine when choosing a personal workspace. | Verified | The host/personal and provider/existing-machine cases both return reuse of the parent environment instead of retaining host-2. |
| Default personal placement and explicit personal workspace placement take the same faulty path. | Verified at the server boundary | Trusted CLI source maps both forms to host/personal requests; the predicate also accepts the provider form. |
| Parent environment reuse is appropriate without machine selection or on the same machine. | Verified control | Five reuse controls pass before and after the fix, covering project-default, host/personal, and provider forms. |
| The new-machine provider variant also discards placement. | Verified additional failure | The new-machine request returns reuse in both clean base runs. |
| A particular release, operating-system pair, and real provider session demonstrate the same symptom. | Not exercised | No real machine enrollment, provider turn, or production runtime was used. The result is reproduced on main's server policy independently of operating system. |
| Removing an inherited environment variable does not solve the issue. | CLI experiment not repeated | The failing unit reproduction sets no inherited agent environment ID. The defect needs only typed request data and a stored parent environment. |
3. Environment
- Public repository get-bb/bb, trusted origin/main commit
f135a001e72942cee9118d2693208ec0725e2f18; bb package version 0.45.0. - Linux x86_64; Node v22.19.0; pnpm 9.15.0; Turbo 2.10.12; Vitest 4.1.1.
- Each clean checkout completed
pnpm install --frozen-lockfile --prefer-offlineandpnpm exec turbo run build(65 tasks successful). - Existing test harness uses a real migrated in-memory SQLite database. All hosts, paths, and thread/environment records in the regression are synthetic fixtures; no real provider was invoked.
- No development app or externally exposed server was started. No browser screenshots are required for this nonvisual server-policy bug. New temporary checkouts and fresh in-memory databases were used for each reproduction run.
4. Minimal reproduction
The regression extends the policy's existing table rather than adding a test-only production export or a duplicate transport test. It seeds a real parent environment on synthetic host-1, then checks eight placement requests. A different existing machine or a new-machine request must survive policy resolution; omitted or matching selection must reuse the parent.
- Obtain a clean trusted checkout and build its normal dependencies:
git clone https://github.com/get-bb/bb.git bb-policy-repro cd bb-policy-repro git checkout --detach f135a001e72942cee9118d2693208ec0725e2f18 pnpm install --frozen-lockfile --prefer-offline pnpm exec turbo run build
- Save the patch below as
regression.patchoutside the checkout, apply it to the existing test, then run:git apply ../regression.patch pnpm exec turbo run test --filter=@bb/server -- test/threads/thread-default-policy.test.ts
- On unchanged production code, the command exits 1 with three intended assertion failures. Expected: the different-host and new-machine requests remain intact. Actual: all three are changed to the parent reuse decision.
First clean checkout: Tests 3 failed | 40 passed (43) Second clean checkout: Tests 3 failed | 40 passed (43) Both commands exited 1.
Representative observed diff, with the generated environment ID replaced by env_PARENT:
- { "type": "host", "hostId": "host-2", "workspace": { "type": "personal" } }
+ { "type": "reuse", "environmentId": "env_PARENT" }
Copy-paste regression patch
diff --git a/apps/server/test/threads/thread-default-policy.test.ts b/apps/server/test/threads/thread-default-policy.test.ts
index 45d3a30fe..033f52afa 100644
--- a/apps/server/test/threads/thread-default-policy.test.ts
+++ b/apps/server/test/threads/thread-default-policy.test.ts
@@ -382,6 +382,7 @@ describe("resolveCreateThreadEnvironment", () => {
it.each([
{
name: "the personal workspace sugar",
+ reuseParent: true,
requestedEnvironment: {
type: "host" as const,
workspace: { type: "personal" as const },
@@ -389,6 +390,7 @@ describe("resolveCreateThreadEnvironment", () => {
},
{
name: "a selection of the personal provider",
+ reuseParent: true,
requestedEnvironment: {
type: "provider" as const,
environmentProviderId: "personal-workspace",
@@ -398,26 +400,88 @@ describe("resolveCreateThreadEnvironment", () => {
},
{
name: "no environment at all",
+ reuseParent: true,
requestedEnvironment: { type: "project-default" as const },
},
+ {
+ name: "the personal workspace on the parent's machine",
+ reuseParent: true,
+ requestedEnvironment: {
+ type: "host" as const,
+ hostId: "host-1",
+ workspace: { type: "personal" as const },
+ },
+ },
+ {
+ name: "the personal provider without a machine",
+ reuseParent: true,
+ requestedEnvironment: {
+ type: "provider" as const,
+ environmentProviderId: "personal-workspace",
+ inputs: null,
+ },
+ },
+ {
+ name: "the personal workspace on another machine",
+ reuseParent: false,
+ requestedEnvironment: {
+ type: "host" as const,
+ hostId: "host-2",
+ workspace: { type: "personal" as const },
+ },
+ },
+ {
+ name: "the personal provider on another machine",
+ reuseParent: false,
+ requestedEnvironment: {
+ type: "provider" as const,
+ environmentProviderId: "personal-workspace",
+ machine: { type: "existing" as const, hostId: "host-2" },
+ inputs: null,
+ },
+ },
+ {
+ name: "the personal provider on a new machine",
+ reuseParent: false,
+ requestedEnvironment: {
+ type: "provider" as const,
+ environmentProviderId: "personal-workspace",
+ machine: {
+ type: "new" as const,
+ machineProviderId: "test-machine-provider",
+ inputs: null,
+ },
+ inputs: null,
+ },
+ },
])(
- "shares personal child threads from $name",
- async ({ requestedEnvironment }) => {
+ "respects placement for personal child threads from $name",
+ async ({ requestedEnvironment, reuseParent }) => {
await withTestHarness(async (harness) => {
installFakeGitWorktreeProvider();
+ const { host } = seedHostSession(harness.deps, { id: "host-1" });
+ const parentEnvironment = createEnvironment(harness.db, harness.hub, {
+ projectId: PERSONAL_PROJECT_ID,
+ hostId: host.id,
+ path: "/tmp/personal-child-parent",
+ providerOwnsPath: true,
+ status: "ready",
+ environmentProvider: null,
+ });
await expect(
resolveCreateThreadEnvironment(harness.deps, {
parentThread: makeParentThread({
- environmentId: "env-personal-parent",
+ environmentId: parentEnvironment.id,
projectId: PERSONAL_PROJECT_ID,
}),
projectId: PERSONAL_PROJECT_ID,
requestedEnvironment,
}),
- ).resolves.toEqual({
- type: "reuse",
- environmentId: "env-personal-parent",
- });
+ ).resolves.toEqual(
+ reuseParent
+ ? { type: "reuse", environmentId: parentEnvironment.id }
+ : requestedEnvironment,
+ );
});
},
);
Complete reproduction test file (replace apps/server/test/threads/thread-default-policy.test.ts)
import {
installFakeGitWorktreeProvider,
installFakePersonalWorkspaceProvider,
} from "../helpers/environment-provider.js";
import {
PERSONAL_PROJECT_ID,
type GitSourceInspection,
type ProjectExecutionDefaults,
type Thread,
} from "@bb/domain";
import { createEnvironment } from "@bb/db";
import { describe, expect, it } from "vitest";
import {
resolveCreateThreadEnvironment,
resolveCreateThreadExecutionDefaults,
resolveProjectDefaultThreadEnvironment,
resolveThreadDefaultPermissionMode,
resolveThreadExecutionPermissionMode,
} from "../../src/services/threads/thread-default-policy.js";
import { createProviderRegistryService } from "../../src/services/providers/provider-registry.js";
import {
createTestProviderRegistry,
registerFirstPartyProviders,
} from "../helpers/provider-registry.js";
import { registerHostRpcResponder } from "../helpers/host-rpc.js";
import {
seedHostSession,
seedPrimaryHost,
seedProjectWithSource,
} from "../helpers/seed.js";
import { withTestHarness } from "../helpers/test-app.js";
const registry = await createTestProviderRegistry();
type PolicyTestThread = Pick<
Thread,
"originKind" | "parentThreadId" | "projectId" | "providerId"
>;
type PolicyTestParentThread = Pick<
Thread,
| "archivedAt"
| "deletedAt"
| "environmentId"
| "id"
| "parentThreadId"
| "projectId"
>;
function makeThread(
overrides: Partial<PolicyTestThread> = {},
): PolicyTestThread {
return {
originKind: null,
parentThreadId: null,
projectId: "proj-1",
providerId: "codex",
...overrides,
};
}
function makeDefaults(
overrides: Partial<ProjectExecutionDefaults> = {},
): ProjectExecutionDefaults {
return {
model: "gpt-5",
permissionMode: "full",
providerId: "codex",
reasoningLevel: "medium",
serviceTier: "default",
...overrides,
};
}
function makeParentThread(
overrides: Partial<PolicyTestParentThread> = {},
): PolicyTestParentThread {
return {
archivedAt: null,
deletedAt: null,
environmentId: "env-parent-1",
id: "thr-parent-1",
parentThreadId: null,
projectId: "proj-1",
...overrides,
};
}
describe("resolveCreateThreadExecutionDefaults", () => {
it("uses the picker's first provider without pinning a model", () => {
expect(registry.list()[0]?.info.id).toBe("codex");
expect(
resolveCreateThreadExecutionDefaults(registry, {
storedDefaults: null,
}),
).toEqual({
providerId: "codex",
executionDefaults: null,
providerFallbackCandidates: [
"claude-code",
"pi",
"acp-cursor",
"acp-opencode",
"acp-omp",
"acp-grok",
"acp-hermes-agent",
],
});
});
it("honors the user's default provider and picker order", async () => {
const preferences = {
providerOrder: ["pi", "claude-code"],
defaultProviderId: null as string | null,
};
const userRegistry = createProviderRegistryService({
readUserProviderPreferences: () => preferences,
});
await registerFirstPartyProviders(userRegistry);
expect(userRegistry.list().map((entry) => entry.info.id)).toEqual([
"pi",
"claude-code",
"codex",
"acp-cursor",
"acp-opencode",
"acp-omp",
"acp-grok",
"acp-hermes-agent",
]);
expect(
resolveCreateThreadExecutionDefaults(userRegistry, {
storedDefaults: null,
}).providerId,
).toBe("pi");
preferences.defaultProviderId = "codex";
expect(
resolveCreateThreadExecutionDefaults(userRegistry, {
storedDefaults: null,
}).providerId,
).toBe("codex");
preferences.defaultProviderId = "not-installed";
expect(
resolveCreateThreadExecutionDefaults(userRegistry, {
storedDefaults: null,
}).providerId,
).toBe("pi");
});
it("orders fallback candidates behind the chosen default, preferred provider first", async () => {
const preferences = {
providerOrder: ["pi", "claude-code"],
defaultProviderId: "codex" as string | null,
};
const userRegistry = createProviderRegistryService({
readUserProviderPreferences: () => preferences,
});
await registerFirstPartyProviders(userRegistry);
expect(
resolveCreateThreadExecutionDefaults(userRegistry, {
storedDefaults: null,
}).providerFallbackCandidates,
).toEqual([
"pi",
"claude-code",
"acp-cursor",
"acp-opencode",
"acp-omp",
"acp-grok",
"acp-hermes-agent",
]);
});
it("has no fallback candidates when a provider was explicitly requested", () => {
expect(
resolveCreateThreadExecutionDefaults(registry, {
requestedProviderId: "codex",
storedDefaults: null,
}).providerFallbackCandidates,
).toEqual([]);
});
it("has no fallback candidates when a stored default provider is used", () => {
expect(
resolveCreateThreadExecutionDefaults(registry, {
storedDefaults: makeDefaults({ providerId: "codex" }),
}).providerFallbackCandidates,
).toEqual([]);
});
it("discards stored defaults when the resolved provider changes", () => {
expect(
resolveCreateThreadExecutionDefaults(registry, {
requestedProviderId: "pi",
storedDefaults: makeDefaults({
providerId: "codex",
model: "gpt-5.5",
}),
}),
).toEqual({
providerId: "pi",
executionDefaults: null,
providerFallbackCandidates: [],
});
});
it("reuses matching stored defaults", () => {
const storedDefaults = makeDefaults({
model: "gpt-5.1",
permissionMode: "accept-edits",
});
expect(
resolveCreateThreadExecutionDefaults(registry, {
storedDefaults,
}),
).toEqual({
providerId: "codex",
executionDefaults: storedDefaults,
providerFallbackCandidates: [],
});
});
it("skips unavailable providers when choosing the product default", async () => {
const degradedRegistry = createProviderRegistryService();
await registerFirstPartyProviders(degradedRegistry, {
unavailablePluginIds: ["provider-codex"],
});
expect(
resolveCreateThreadExecutionDefaults(degradedRegistry, {
storedDefaults: null,
}),
).toEqual({
providerId: "claude-code",
executionDefaults: null,
providerFallbackCandidates: [
"pi",
"acp-cursor",
"acp-opencode",
"acp-omp",
"acp-grok",
"acp-hermes-agent",
],
});
});
it("rejects an explicitly selected unavailable provider", async () => {
const degradedRegistry = createProviderRegistryService();
await registerFirstPartyProviders(degradedRegistry, {
unavailablePluginIds: ["provider-codex"],
});
expect(() =>
resolveCreateThreadExecutionDefaults(degradedRegistry, {
requestedProviderId: "codex",
storedDefaults: null,
}),
).toThrow(/Codex is unavailable because its provider plugin failed/u);
});
});
describe("resolveCreateThreadEnvironment", () => {
async function resolveEnvironment(
args: Parameters<typeof resolveCreateThreadEnvironment>[1],
) {
return withTestHarness((harness) => {
installFakeGitWorktreeProvider();
return resolveCreateThreadEnvironment(harness.deps, args);
});
}
it("defaults implicit child host environments to the worktree provider", async () => {
await expect(
resolveEnvironment({
parentThread: makeParentThread(),
projectId: "proj-1",
requestedEnvironment: {
type: "host",
hostId: "host-1",
workspace: { type: "unmanaged", path: null },
},
}),
).resolves.toEqual({
type: "provider",
environmentProviderId: "git-worktree",
machine: { type: "existing" as const, hostId: "host-1" },
inputs: { branch: { kind: "default" } },
});
});
it("defaults a child under a parent from another project to the worktree provider", async () => {
await expect(
resolveEnvironment({
parentThread: makeParentThread({ projectId: "proj-2" }),
projectId: "proj-1",
requestedEnvironment: {
type: "host",
hostId: "host-1",
workspace: { type: "unmanaged", path: null },
},
}),
).resolves.toEqual({
type: "provider",
environmentProviderId: "git-worktree",
machine: { type: "existing" as const, hostId: "host-1" },
inputs: { branch: { kind: "default" } },
});
});
it("keeps explicit same-environment reuse for child threads", async () => {
await expect(
resolveEnvironment({
parentThread: makeParentThread(),
projectId: "proj-1",
requestedEnvironment: {
type: "reuse",
environmentId: "env-1",
},
}),
).resolves.toEqual({
type: "reuse",
environmentId: "env-1",
});
});
it("uses a fresh worktree on the parent's machine for a project child", async () => {
await withTestHarness(async (harness) => {
installFakeGitWorktreeProvider();
const { host } = seedHostSession(harness.deps, {
id: "host-project-child",
});
const { project } = seedProjectWithSource(harness.deps, {
hostId: host.id,
path: "/tmp/project-child-source",
});
const parentEnvironment = createEnvironment(harness.db, harness.hub, {
projectId: project.id,
hostId: host.id,
path: "/tmp/project-child-parent",
providerOwnsPath: true,
status: "ready",
environmentProvider: null,
});
await expect(
resolveCreateThreadEnvironment(harness.deps, {
parentThread: makeParentThread({
projectId: project.id,
environmentId: parentEnvironment.id,
}),
projectId: project.id,
requestedEnvironment: { type: "project-default" },
}),
).resolves.toEqual({
type: "provider",
environmentProviderId: "git-worktree",
machine: { type: "existing", hostId: host.id },
inputs: { branch: { kind: "default" } },
});
});
});
it("does not reuse a personal parent environment from another project", async () => {
const requestedEnvironment = {
type: "host",
workspace: { type: "personal" },
} as const;
await expect(
resolveEnvironment({
parentThread: makeParentThread({
environmentId: "env-other-project-parent",
projectId: "proj-other",
}),
projectId: PERSONAL_PROJECT_ID,
requestedEnvironment,
}),
).resolves.toEqual(requestedEnvironment);
});
it.each([
{
name: "the personal workspace sugar",
reuseParent: true,
requestedEnvironment: {
type: "host" as const,
workspace: { type: "personal" as const },
},
},
{
name: "a selection of the personal provider",
reuseParent: true,
requestedEnvironment: {
type: "provider" as const,
environmentProviderId: "personal-workspace",
machine: { type: "existing" as const, hostId: "host-1" },
inputs: null,
},
},
{
name: "no environment at all",
reuseParent: true,
requestedEnvironment: { type: "project-default" as const },
},
{
name: "the personal workspace on the parent's machine",
reuseParent: true,
requestedEnvironment: {
type: "host" as const,
hostId: "host-1",
workspace: { type: "personal" as const },
},
},
{
name: "the personal provider without a machine",
reuseParent: true,
requestedEnvironment: {
type: "provider" as const,
environmentProviderId: "personal-workspace",
inputs: null,
},
},
{
name: "the personal workspace on another machine",
reuseParent: false,
requestedEnvironment: {
type: "host" as const,
hostId: "host-2",
workspace: { type: "personal" as const },
},
},
{
name: "the personal provider on another machine",
reuseParent: false,
requestedEnvironment: {
type: "provider" as const,
environmentProviderId: "personal-workspace",
machine: { type: "existing" as const, hostId: "host-2" },
inputs: null,
},
},
{
name: "the personal provider on a new machine",
reuseParent: false,
requestedEnvironment: {
type: "provider" as const,
environmentProviderId: "personal-workspace",
machine: {
type: "new" as const,
machineProviderId: "test-machine-provider",
inputs: null,
},
inputs: null,
},
},
])(
"respects placement for personal child threads from $name",
async ({ requestedEnvironment, reuseParent }) => {
await withTestHarness(async (harness) => {
installFakeGitWorktreeProvider();
const { host } = seedHostSession(harness.deps, { id: "host-1" });
const parentEnvironment = createEnvironment(harness.db, harness.hub, {
projectId: PERSONAL_PROJECT_ID,
hostId: host.id,
path: "/tmp/personal-child-parent",
providerOwnsPath: true,
status: "ready",
environmentProvider: null,
});
await expect(
resolveCreateThreadEnvironment(harness.deps, {
parentThread: makeParentThread({
environmentId: parentEnvironment.id,
projectId: PERSONAL_PROJECT_ID,
}),
projectId: PERSONAL_PROJECT_ID,
requestedEnvironment,
}),
).resolves.toEqual(
reuseParent
? { type: "reuse", environmentId: parentEnvironment.id }
: requestedEnvironment,
);
});
},
);
it.each([
{
args: {
parentThread: null,
projectId: "proj-1",
requestedEnvironment: {
type: "host" as const,
hostId: "host-1",
workspace: { type: "unmanaged" as const, path: null },
},
},
name: "requests without a parent thread",
},
{
args: {
parentThread: makeParentThread({
deletedAt: 1,
}),
projectId: "proj-1",
requestedEnvironment: {
type: "host" as const,
hostId: "host-1",
workspace: { type: "unmanaged" as const, path: null },
},
},
name: "deleted parents",
},
{
args: {
parentThread: makeParentThread(),
projectId: "proj-1",
requestedEnvironment: {
type: "host" as const,
hostId: "host-1",
workspace: { type: "unmanaged" as const, path: "/tmp/existing" },
},
},
name: "explicit unmanaged paths",
},
])("passes through $name", async ({ args }) => {
await expect(resolveEnvironment(args)).resolves.toEqual(
args.requestedEnvironment,
);
});
it("gives a sub-thread of a project with no commits a worktree of the source", async () => {
await withTestHarness(async (harness) => {
installFakeGitWorktreeProvider();
const { host, session } = seedHostSession(harness.deps, {
id: "host-default-order",
});
seedPrimaryHost(harness.deps, host.id);
const { project } = seedProjectWithSource(harness.deps, {
hostId: host.id,
path: "/tmp/default-order-source",
});
const parentEnvironment = createEnvironment(harness.db, harness.hub, {
projectId: project.id,
hostId: host.id,
path: "/tmp/parent-environment",
providerOwnsPath: true,
status: "ready",
environmentProvider: null,
});
registerHostRpcResponder(harness, {
hostId: host.id,
sessionId: session.id,
handle: () => ({
ok: true,
result: {
checkout: { kind: "unborn" as const, branchName: "main" },
defaultBranch: null,
defaultBranchRelation: null,
isWorktree: false,
hasUncommittedChanges: false,
operation: { kind: "none" as const },
originDefaultBranch: null,
} satisfies GitSourceInspection,
}),
});
await expect(
resolveCreateThreadEnvironment(harness.deps, {
parentThread: makeParentThread({
projectId: project.id,
environmentId: parentEnvironment.id,
}),
projectId: project.id,
requestedEnvironment: { type: "project-default" },
}),
).resolves.toEqual({
type: "provider",
environmentProviderId: "git-worktree",
machine: { type: "existing", hostId: host.id },
inputs: { branch: { kind: "default" } },
});
});
});
});
describe("resolveProjectDefaultThreadEnvironment", () => {
it("uses a worktree for a Git project", async () => {
await withTestHarness(async (harness) => {
installFakeGitWorktreeProvider();
const { host, session } = seedHostSession(harness.deps, {
id: "host-git-default",
});
seedPrimaryHost(harness.deps, host.id);
const { project } = seedProjectWithSource(harness.deps, {
hostId: host.id,
path: "/tmp/git-default-source",
});
registerHostRpcResponder(harness, {
hostId: host.id,
sessionId: session.id,
handle: () => ({
ok: true,
result: {
checkout: {
kind: "branch" as const,
branchName: "feature",
headSha: "abc123",
},
defaultBranch: "main",
defaultBranchRelation: null,
isWorktree: false,
hasUncommittedChanges: false,
operation: { kind: "none" as const },
originDefaultBranch: null,
} satisfies GitSourceInspection,
}),
});
await expect(
resolveProjectDefaultThreadEnvironment(harness.deps, {
projectId: project.id,
}),
).resolves.toEqual({
type: "provider",
environmentProviderId: "git-worktree",
machine: { type: "existing", hostId: host.id },
inputs: { branch: { kind: "named", name: "main" } },
});
});
});
it("uses the project checkout for a non-Git project", async () => {
await withTestHarness(async (harness) => {
const { host, session } = seedHostSession(harness.deps, {
id: "host-non-git-default",
});
seedPrimaryHost(harness.deps, host.id);
const { project } = seedProjectWithSource(harness.deps, {
hostId: host.id,
path: "/tmp/non-git-default-source",
});
registerHostRpcResponder(harness, {
hostId: host.id,
sessionId: session.id,
handle: () => ({
ok: true,
result: {
checkout: { kind: "unborn" as const, branchName: "main" },
defaultBranch: null,
defaultBranchRelation: null,
isWorktree: false,
hasUncommittedChanges: false,
operation: { kind: "none" as const },
originDefaultBranch: null,
} satisfies GitSourceInspection,
}),
});
await expect(
resolveProjectDefaultThreadEnvironment(harness.deps, {
projectId: project.id,
}),
).resolves.toEqual({
type: "provider",
environmentProviderId: "project-checkout",
machine: { type: "existing", hostId: host.id },
inputs: { path: "/tmp/non-git-default-source" },
});
});
});
it("uses the personal workspace with no project", async () => {
await withTestHarness(async (harness) => {
installFakePersonalWorkspaceProvider();
const { host } = seedHostSession(harness.deps, {
id: "host-personal-default",
});
seedPrimaryHost(harness.deps, host.id);
await expect(
resolveProjectDefaultThreadEnvironment(harness.deps, {
projectId: PERSONAL_PROJECT_ID,
}),
).resolves.toEqual({
type: "provider",
environmentProviderId: "personal-workspace",
machine: { type: "existing", hostId: host.id },
inputs: null,
});
});
});
});
describe("resolveThreadDefaultPermissionMode", () => {
it("uses the auto permission default for non-agent providers", () => {
expect(
resolveThreadDefaultPermissionMode(registry, {
thread: makeThread({
parentThreadId: "thr-parent-1",
providerId: "custom-provider",
}),
}),
).toBe("auto");
});
it("uses full for Pi threads", () => {
expect(
resolveThreadDefaultPermissionMode(registry, {
thread: makeThread({
parentThreadId: "thr-parent-1",
providerId: "pi",
}),
}),
).toBe("full");
});
it("uses full for ACP threads when the Auto default is unsupported", () => {
expect(
resolveThreadDefaultPermissionMode(registry, {
thread: makeThread({
parentThreadId: "thr-parent-1",
providerId: "acp-cursor",
}),
}),
).toBe("full");
});
it("uses auto for Codex threads", () => {
expect(
resolveThreadDefaultPermissionMode(registry, {
thread: makeThread({
parentThreadId: "thr-other-project-parent-1",
providerId: "codex",
}),
}),
).toBe("auto");
});
});
describe("resolveThreadExecutionPermissionMode", () => {
it("prefers requested permission modes over every fallback", () => {
expect(
resolveThreadExecutionPermissionMode(registry, {
requestedPermissionMode: "auto",
lastExecutionPermissionMode: "workspace-write",
projectExecutionPermissionMode: "full",
thread: makeThread(),
}),
).toBe("auto");
});
it("maps a legacy readonly execution to Accept Edits for future work", () => {
expect(
resolveThreadExecutionPermissionMode(registry, {
lastExecutionPermissionMode: "readonly",
projectExecutionPermissionMode: "full",
thread: makeThread(),
}),
).toBe("accept-edits");
});
it("maps a legacy readonly parent execution before inheriting it", () => {
expect(
resolveThreadExecutionPermissionMode(registry, {
parentThread: makeParentThread(),
parentThreadExecutionPermissionMode: "readonly",
projectExecutionPermissionMode: "full",
thread: makeThread({
parentThreadId: "thr-parent-1",
providerId: "codex",
}),
}),
).toBe("accept-edits");
});
it("uses project permission defaults for child threads without parent execution history", () => {
expect(
resolveThreadExecutionPermissionMode(registry, {
parentThread: makeParentThread(),
projectExecutionPermissionMode: "full",
thread: makeThread({
parentThreadId: "thr-parent-1",
providerId: "codex",
}),
}),
).toBe("full");
});
it("resolves an inherited mode to the child provider supported mode", () => {
expect(
resolveThreadExecutionPermissionMode(registry, {
parentThread: makeParentThread(),
parentThreadExecutionPermissionMode: "workspace-write",
projectExecutionPermissionMode: "accept-edits",
thread: makeThread({
parentThreadId: "thr-parent-1",
providerId: "pi",
}),
}),
).toBe("full");
});
it("honors an explicitly requested mode above the parent's mode", () => {
expect(
resolveThreadExecutionPermissionMode(registry, {
requestedPermissionMode: "full",
parentThread: makeParentThread(),
parentThreadExecutionPermissionMode: "auto",
thread: makeThread({
parentThreadId: "thr-parent-1",
providerId: "codex",
}),
}),
).toBe("full");
});
it("preserves the child's recorded mode above the parent's current mode", () => {
expect(
resolveThreadExecutionPermissionMode(registry, {
lastExecutionPermissionMode: "full",
parentThread: makeParentThread(),
parentThreadExecutionPermissionMode: "auto",
thread: makeThread({
parentThreadId: "thr-parent-1",
providerId: "codex",
}),
}),
).toBe("full");
});
it("allows a child to run below its parent's mode", () => {
expect(
resolveThreadExecutionPermissionMode(registry, {
requestedPermissionMode: "accept-edits",
parentThread: makeParentThread(),
parentThreadExecutionPermissionMode: "full",
thread: makeThread({
parentThreadId: "thr-parent-1",
providerId: "codex",
}),
}),
).toBe("accept-edits");
});
it("uses root-thread defaults when the parent reference is not live", () => {
expect(
resolveThreadExecutionPermissionMode(registry, {
parentThread: makeParentThread({
deletedAt: Date.now(),
}),
projectExecutionPermissionMode: "accept-edits",
thread: makeThread({
parentThreadId: "thr-deleted-parent-1",
providerId: "codex",
}),
}),
).toBe("accept-edits");
});
it("still uses project permission defaults for root threads", () => {
expect(
resolveThreadExecutionPermissionMode(registry, {
projectExecutionPermissionMode: "accept-edits",
thread: makeThread(),
}),
).toBe("accept-edits");
});
});
Raw evidence remains outside the reports repository. The test and output are inline here, as required by the public report repository's artifact policy.
5. Root cause
apps/server/src/services/threads/thread-default-policy.ts:133 recognizes project-default, host/personal, and personal-workspace provider requests without considering their machine selection:
function isPersonalWorkspaceEnvironment(
environment: CreateThreadEnvironment,
): boolean {
return (
environment.type === "project-default" ||
(environment.type === "host" &&
environment.workspace.type === "personal") ||
(environment.type === "provider" &&
environment.environmentProviderId ===
DEFAULT_ENVIRONMENT_PROVIDER_ID.personalWorkspace)
);
}
apps/server/src/services/threads/thread-default-policy.ts:314 unconditionally replaces those requests with reuse when parent and child are live Personal-project threads:
export async function resolveCreateThreadEnvironment(
deps: WorkSessionDeps,
args: ResolveCreateThreadEnvironmentArgs,
): Promise<ResolvedCreateThreadEnvironment> {
const parentThread = args.parentThread;
const hasLiveParent = isLiveParentThread({ parentThread });
if (
hasLiveParent &&
parentThread?.projectId === PERSONAL_PROJECT_ID &&
args.projectId === PERSONAL_PROJECT_ID &&
isPersonalWorkspaceEnvironment(args.requestedEnvironment)
) {
if (!parentThread.environmentId) {
throw new Error("Personal parent thread is missing an environment");
}
return { type: "reuse", environmentId: parentThread.environmentId };
}
The parent environment's host is never looked up or compared. This is not a host-daemon or provider execution failure: the placement intent has already lost the machine by the time it reaches those layers.
- apps/cli/src/commands/thread/spawn.ts:149 shows how a personal host request carries hostId; apps/cli/src/commands/thread/spawn.ts:512 shows machine resolution and request construction.
- apps/server/src/services/threads/thread-create.ts:645 routes actual thread creation through this policy.
- apps/server/src/services/threads/thread-request-eligibility.ts:120 resolves an unreplaced personal host request to its selected host.
- apps/server/src/services/threads/thread-environment-placement.ts:583 provisions a personal workspace using that resolved host. The existing provider path preserves its supplied machine selection.
Repository history attributes the current shared predicate and personal reuse block to commit 5f558957aa (September 8, 2026). This is supporting history only; the two failures on the current trusted base establish the defect.
6. Proposed fix (first principles)
Normalize only the requested machine selection inside the existing personal-child reuse block. Reuse when the request has no machine selection, or selects an existing host equal to the stored parent environment's hostId. Otherwise, including a request to create a new machine, fall through to the existing placement implementation. No CLI flags, public schemas, database storage, provider API, or server/daemon wire fields need to change.
The focused regression covers the credible risk: machine choice being silently discarded during default resolution. The existing coverage only tested reuse with a nonexistent environment ID and did not seed a parent environment on a distinct host. Updating that table with a real stored environment is sufficient; no production seam is needed.
Local fixed-code verification: Tests 137 passed (137). See the pull request for final verification commands and the change count; the report verdict itself is based on unchanged production code.
7. Verification
The same agent performed both runs; this is not an independent-agent review. Checkout A was a fresh clone of get-bb/bb at the recorded base. Checkout B was a separate clean clone at the exact same commit, using local Git object sharing only; its node_modules were installed separately and its build and test execution were repeated. git status --porcelain was empty in B after the normal build and before applying the test-only patch.
The second run used the identical regression patch and Turbo command, but unchanged production source and new in-memory test databases. It executed the tests (not a cached successful result): the host/personal, provider/existing different-host, and provider/new-machine assertions failed identically. No correction to the root-cause finding was necessary. Fresh runtime ports were not applicable because no dev instance or real daemon was started.
8. Related issues and pull requests
At investigation time, GitHub cross-reference metadata contained no linked pull request, and an open pull-request search for issue 5204 returned no results. No linked code was checked out or executed. This report investigates only the named issue and does not adjudicate other issues.
9. Appendix
The following output is the actual test-process output, with temporary checkout paths normalized to TEMP_ROOT and generated environment IDs to env_PARENT. These are privacy redactions, not synthetic test results.
First reproduction output
cache miss, executing 9341a1e622510d8d
> @bb/server@0.0.1 test TEMP_ROOT/base/apps/server
> vitest run --config vitest.config.ts "test/threads/thread-default-policy.test.ts"
RUN v4.1.1 TEMP_ROOT/base/apps/server
(node:7229) ExperimentalWarning: SQLite is an experimental feature and might change at any time
(Use `node --trace-warnings ...` to show where the warning was created)
❯ |@bb/server| test/threads/thread-default-policy.test.ts (43 tests | 3 failed) 1210ms
✓ uses the picker's first provider without pinning a model 2ms
✓ honors the user's default provider and picker order 27ms
✓ orders fallback candidates behind the chosen default, preferred provider first 21ms
✓ has no fallback candidates when a provider was explicitly requested 0ms
✓ has no fallback candidates when a stored default provider is used 0ms
✓ discards stored defaults when the resolved provider changes 0ms
✓ reuses matching stored defaults 0ms
✓ skips unavailable providers when choosing the product default 15ms
✓ rejects an explicitly selected unavailable provider 19ms
✓ defaults implicit child host environments to the worktree provider 38ms
✓ defaults a child under a parent from another project to the worktree provider 39ms
✓ keeps explicit same-environment reuse for child threads 34ms
✓ uses a fresh worktree on the parent's machine for a project child 46ms
✓ does not reuse a personal parent environment from another project 38ms
✓ respects placement for personal child threads from 'the personal workspace sugar' 40ms
✓ respects placement for personal child threads from 'a selection of the personal provider' 45ms
✓ respects placement for personal child threads from 'no environment at all' 57ms
✓ respects placement for personal child threads from 'the personal workspace on the parent\…' 36ms
✓ respects placement for personal child threads from 'the personal provider without a machi…' 35ms
× respects placement for personal child threads from 'the personal workspace on another mac…' 40ms
× respects placement for personal child threads from 'the personal provider on another mach…' 37ms
× respects placement for personal child threads from 'the personal provider on a new machine' 40ms
✓ passes through 'requests without a parent thread' 29ms
✓ passes through 'deleted parents' 33ms
✓ passes through 'explicit unmanaged paths' 33ms
✓ gives a sub-thread of a project with no commits a worktree of the source 44ms
✓ uses a worktree for a Git project 65ms
✓ uses the project checkout for a non-Git project 41ms
✓ uses the personal workspace with no project 35ms
✓ uses the auto permission default for non-agent providers 0ms
✓ uses full for Pi threads 0ms
✓ uses full for ACP threads when the Auto default is unsupported 0ms
✓ uses auto for Codex threads 0ms
✓ prefers requested permission modes over every fallback 0ms
✓ maps a legacy readonly execution to Accept Edits for future work 0ms
✓ maps a legacy readonly parent execution before inheriting it 0ms
✓ uses project permission defaults for child threads without parent execution history 0ms
✓ resolves an inherited mode to the child provider supported mode 0ms
✓ honors an explicitly requested mode above the parent's mode 0ms
✓ preserves the child's recorded mode above the parent's current mode 0ms
✓ allows a child to run below its parent's mode 0ms
✓ uses root-thread defaults when the parent reference is not live 0ms
✓ still uses project permission defaults for root threads 0ms
⎯⎯⎯⎯⎯⎯⎯ Failed Tests 3 ⎯⎯⎯⎯⎯⎯⎯
FAIL |@bb/server| test/threads/thread-default-policy.test.ts > resolveCreateThreadEnvironment > respects placement for personal child threads from 'the personal workspace on another mac…'
AssertionError: expected { type: 'reuse', …(1) } to deeply equal { Object (type, hostId, ...) }
- Expected
+ Received
{
- "hostId": "host-2",
- "type": "host",
- "workspace": {
- "type": "personal",
- },
+ "environmentId": "env_PARENT",
+ "type": "reuse",
}
❯ test/threads/thread-default-policy.test.ts:480:10
478| requestedEnvironment,
479| }),
480| ).resolves.toEqual(
| ^
481| reuseParent
482| ? { type: "reuse", environmentId: parentEnvironment.id }
❯ withTestHarness test/helpers/test-app.ts:372:18
❯ test/threads/thread-default-policy.test.ts:460:7
⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯[1/3]⎯
FAIL |@bb/server| test/threads/thread-default-policy.test.ts > resolveCreateThreadEnvironment > respects placement for personal child threads from 'the personal provider on another mach…'
AssertionError: expected { type: 'reuse', …(1) } to deeply equal { type: 'provider', …(3) }
- Expected
+ Received
{
- "environmentProviderId": "personal-workspace",
- "inputs": null,
- "machine": {
- "hostId": "host-2",
- "type": "existing",
- },
- "type": "provider",
+ "environmentId": "env_PARENT",
+ "type": "reuse",
}
❯ test/threads/thread-default-policy.test.ts:480:10
478| requestedEnvironment,
479| }),
480| ).resolves.toEqual(
| ^
481| reuseParent
482| ? { type: "reuse", environmentId: parentEnvironment.id }
❯ withTestHarness test/helpers/test-app.ts:372:18
❯ test/threads/thread-default-policy.test.ts:460:7
⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯[2/3]⎯
FAIL |@bb/server| test/threads/thread-default-policy.test.ts > resolveCreateThreadEnvironment > respects placement for personal child threads from 'the personal provider on a new machine'
AssertionError: expected { type: 'reuse', …(1) } to deeply equal { type: 'provider', …(3) }
- Expected
+ Received
{
- "environmentProviderId": "personal-workspace",
- "inputs": null,
- "machine": {
- "inputs": null,
- "machineProviderId": "test-machine-provider",
- "type": "new",
- },
- "type": "provider",
+ "environmentId": "env_PARENT",
+ "type": "reuse",
}
❯ test/threads/thread-default-policy.test.ts:480:10
478| requestedEnvironment,
479| }),
480| ).resolves.toEqual(
| ^
481| reuseParent
482| ? { type: "reuse", environmentId: parentEnvironment.id }
❯ withTestHarness test/helpers/test-app.ts:372:18
❯ test/threads/thread-default-policy.test.ts:460:7
⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯[3/3]⎯
Test Files 1 failed (1)
Tests 3 failed | 40 passed (43)
Start at 12:35:51
Duration 13.73s (transform 7.91s, setup 1.91s, import 10.41s, tests 1.21s, environment 0ms)
ELIFECYCLE Test failed. See above for more details.Second clean reproduction output
cache miss, executing 9341a1e622510d8d
> @bb/server@0.0.1 test TEMP_ROOT/verify/apps/server
> vitest run --config vitest.config.ts "test/threads/thread-default-policy.test.ts"
RUN v4.1.1 TEMP_ROOT/verify/apps/server
(node:12294) ExperimentalWarning: SQLite is an experimental feature and might change at any time
(Use `node --trace-warnings ...` to show where the warning was created)
❯ |@bb/server| test/threads/thread-default-policy.test.ts (43 tests | 3 failed) 1054ms
✓ uses the picker's first provider without pinning a model 2ms
✓ honors the user's default provider and picker order 21ms
✓ orders fallback candidates behind the chosen default, preferred provider first 15ms
✓ has no fallback candidates when a provider was explicitly requested 0ms
✓ has no fallback candidates when a stored default provider is used 0ms
✓ discards stored defaults when the resolved provider changes 0ms
✓ reuses matching stored defaults 0ms
✓ skips unavailable providers when choosing the product default 13ms
✓ rejects an explicitly selected unavailable provider 15ms
✓ defaults implicit child host environments to the worktree provider 32ms
✓ defaults a child under a parent from another project to the worktree provider 33ms
✓ keeps explicit same-environment reuse for child threads 31ms
✓ uses a fresh worktree on the parent's machine for a project child 44ms
✓ does not reuse a personal parent environment from another project 39ms
✓ respects placement for personal child threads from 'the personal workspace sugar' 39ms
✓ respects placement for personal child threads from 'a selection of the personal provider' 36ms
✓ respects placement for personal child threads from 'no environment at all' 42ms
✓ respects placement for personal child threads from 'the personal workspace on the parent\…' 36ms
✓ respects placement for personal child threads from 'the personal provider without a machi…' 32ms
× respects placement for personal child threads from 'the personal workspace on another mac…' 44ms
× respects placement for personal child threads from 'the personal provider on another mach…' 38ms
× respects placement for personal child threads from 'the personal provider on a new machine' 35ms
✓ passes through 'requests without a parent thread' 35ms
✓ passes through 'deleted parents' 35ms
✓ passes through 'explicit unmanaged paths' 32ms
✓ gives a sub-thread of a project with no commits a worktree of the source 37ms
✓ uses a worktree for a Git project 46ms
✓ uses the project checkout for a non-Git project 38ms
✓ uses the personal workspace with no project 35ms
✓ uses the auto permission default for non-agent providers 0ms
✓ uses full for Pi threads 0ms
✓ uses full for ACP threads when the Auto default is unsupported 0ms
✓ uses auto for Codex threads 0ms
✓ prefers requested permission modes over every fallback 0ms
✓ maps a legacy readonly execution to Accept Edits for future work 0ms
✓ maps a legacy readonly parent execution before inheriting it 0ms
✓ uses project permission defaults for child threads without parent execution history 0ms
✓ resolves an inherited mode to the child provider supported mode 0ms
✓ honors an explicitly requested mode above the parent's mode 0ms
✓ preserves the child's recorded mode above the parent's current mode 0ms
✓ allows a child to run below its parent's mode 0ms
✓ uses root-thread defaults when the parent reference is not live 0ms
✓ still uses project permission defaults for root threads 0ms
⎯⎯⎯⎯⎯⎯⎯ Failed Tests 3 ⎯⎯⎯⎯⎯⎯⎯
FAIL |@bb/server| test/threads/thread-default-policy.test.ts > resolveCreateThreadEnvironment > respects placement for personal child threads from 'the personal workspace on another mac…'
AssertionError: expected { type: 'reuse', …(1) } to deeply equal { Object (type, hostId, ...) }
- Expected
+ Received
{
- "hostId": "host-2",
- "type": "host",
- "workspace": {
- "type": "personal",
- },
+ "environmentId": "env_PARENT",
+ "type": "reuse",
}
❯ test/threads/thread-default-policy.test.ts:480:10
478| requestedEnvironment,
479| }),
480| ).resolves.toEqual(
| ^
481| reuseParent
482| ? { type: "reuse", environmentId: parentEnvironment.id }
❯ withTestHarness test/helpers/test-app.ts:372:18
❯ test/threads/thread-default-policy.test.ts:460:7
⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯[1/3]⎯
FAIL |@bb/server| test/threads/thread-default-policy.test.ts > resolveCreateThreadEnvironment > respects placement for personal child threads from 'the personal provider on another mach…'
AssertionError: expected { type: 'reuse', …(1) } to deeply equal { type: 'provider', …(3) }
- Expected
+ Received
{
- "environmentProviderId": "personal-workspace",
- "inputs": null,
- "machine": {
- "hostId": "host-2",
- "type": "existing",
- },
- "type": "provider",
+ "environmentId": "env_PARENT",
+ "type": "reuse",
}
❯ test/threads/thread-default-policy.test.ts:480:10
478| requestedEnvironment,
479| }),
480| ).resolves.toEqual(
| ^
481| reuseParent
482| ? { type: "reuse", environmentId: parentEnvironment.id }
❯ withTestHarness test/helpers/test-app.ts:372:18
❯ test/threads/thread-default-policy.test.ts:460:7
⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯[2/3]⎯
FAIL |@bb/server| test/threads/thread-default-policy.test.ts > resolveCreateThreadEnvironment > respects placement for personal child threads from 'the personal provider on a new machine'
AssertionError: expected { type: 'reuse', …(1) } to deeply equal { type: 'provider', …(3) }
- Expected
+ Received
{
- "environmentProviderId": "personal-workspace",
- "inputs": null,
- "machine": {
- "inputs": null,
- "machineProviderId": "test-machine-provider",
- "type": "new",
- },
- "type": "provider",
+ "environmentId": "env_PARENT",
+ "type": "reuse",
}
❯ test/threads/thread-default-policy.test.ts:480:10
478| requestedEnvironment,
479| }),
480| ).resolves.toEqual(
| ^
481| reuseParent
482| ? { type: "reuse", environmentId: parentEnvironment.id }
❯ withTestHarness test/helpers/test-app.ts:372:18
❯ test/threads/thread-default-policy.test.ts:460:7
⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯[3/3]⎯
Test Files 1 failed (1)
Tests 3 failed | 40 passed (43)
Start at 12:37:48
Duration 7.81s (transform 4.74s, setup 1.49s, import 5.08s, tests 1.05s, environment 0ms)
ELIFECYCLE Test failed. See above for more details.Relevant commands: trusted clone and origin/main fetch; frozen pnpm install; Turbo build in both checkouts; test-only patch application; the focused Turbo test in both checkouts; local git show, git log, and git blame for the linked policy; GitHub issue property, label, cross-reference and open-PR reads. Issue content was treated as untrusted claims only; none of its commands, links, proposed patches, or instructions was executed or fetched.