Skip to content

Add seeding props to experimental_NewThreadComposer - #916

Merged
SawyerHood merged 2 commits into
mainfrom
bb/fix-seed-initial-values-in-experimental-newthrea-thr_y7z4fynxdi
Jul 31, 2026
Merged

SawyerHood merged 2 commits into
mainfrom
bb/fix-seed-initial-values-in-experimental-newthrea-thr_y7z4fynxdi

Conversation

@SawyerHood

Copy link
Copy Markdown
Collaborator

The bug

experimental_NewThreadComposer exposed only defaultProjectId and initialPrompt as seeds. A plugin that stores the submitted NewThreadRequest and re-opens it for editing (e.g. bb-plugin-slopcop's RuleEditor, where the composer's submit IS the save) got a composer reset to project defaults on every mount — so re-saving after an unrelated edit silently overwrote the stored provider, model, permission mode, and environment. No warning, no diff.

The fix

Additive, optional seed props on NewThreadComposerProps:

  • defaultProviderId, defaultModel, defaultReasoningLevel, defaultServiceTier, defaultPermissionMode — fed into useThreadCreationOptions as initial values, taking precedence over the project's remembered defaults and falling back to today's behavior when omitted.
  • defaultEnvironment — a new pure mapping (new-thread-environment-seed.ts) inverts resolveRootComposeThreadEnvironment: args → encoded environment-picker selection + branch pick, including the managed-worktree base branch and unmanaged existing/new branch specs. Unrepresentable variants are documented on the prop (project-default seeds nothing; personal without hostId and an unmanaged non-null path cannot be encoded).

Semantics (documented in the prop doc comments): they are seeds, not controlled values; the props are value-compared each render, and any change re-seeds every selection — including user-touched ones — via the creation-options resetKey, following the established defaultProjectId re-seed-during-render pattern. So switching between two saved records in one mounted composer reloads that record's values.

Supporting fix in useThreadCreationOptions: a resetKey change cleared touched fields in a layout effect after the render's executionInputSources had been computed, so the reset render reported stale explicit provenance. The provenance memo now treats a pending reset as "nothing touched", mirroring the render-time rule renderedThreadSelections already applies.

RootComposeView is untouched. The SDK testing harness's fake composer now echoes the seeds back on submit so plugin tests can cover store-then-restore.

Round-trip test

The property that prevents the data loss: feeding a submitted request back in as the default* props and submitting untouched must reproduce an equivalent request.

  • new-thread-environment-seed.test.ts — pure round trip of every environment variant (reuse, managed worktree named/default base, unmanaged existing/new/no branch) plus the documented unrepresentable cases.
  • PluginNewThreadComposer.test.tsx — renders the real composer (prompt box + query hooks mocked) and asserts: (1) a seeded, untouched submit toEquals the stored request; (2) after a user touches the model, swapping in a second record's seeds re-seeds everything and submits that record exactly; (3) with no seed props, behavior is unchanged (project defaults).

Also

  • Bundled type declarations regenerated via the repo scripts (build-bundled-dts.mjs, generate-templates.mjs).
  • bb-plugin-authoring skill: new props + store-then-restore pattern documented.
  • docs/api_to_audit.md: audit entry [codex] Update sidebar manager row presentation #6 for the seeding props.

turbo lint/typecheck clean for app, plugin-sdk, server, templates; full @bb/app (2197 tests) and @bb/plugin-sdk suites pass.

🤖 Generated with Claude Code

A plugin that stores a NewThreadRequest and re-opens it for editing had no
way to seed the composer's provider, model, reasoning level, service tier,
permission mode, or environment — every mount reset to project defaults, so
saving an unrelated edit silently overwrote the stored configuration.

Adds optional defaultProviderId / defaultModel / defaultReasoningLevel /
defaultServiceTier / defaultPermissionMode / defaultEnvironment seed props:
uncontrolled seeds that take precedence over project defaults, value-compared
so a seed change after mount re-seeds even user-touched selections.
defaultEnvironment maps CreateThreadEnvironmentArgs back to picker selections
(including the managed-worktree base branch); unrepresentable variants are
documented on the prop. Round-trip covered by tests: submitting a seeded,
untouched composer reproduces the stored request.

Co-Authored-By: Claude Fable 5 <[email protected]>

@SawyerHood SawyerHood left a comment •

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🚨 SLOP COP 🚨 · review

I am SlopCop. I will review this pull request for security, code quality, and performance. I will also test the user flow.

@SawyerHood SawyerHood left a comment •

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🚨 SLOP COP 🚨 · review

Security review complete. I found no injection path, secret exposure, authorization bypass, or unsafe trust change.

The composer checks host and reuse seeds against current project data. The existing submission resolver still controls the final environment request.

@SawyerHood SawyerHood left a comment •

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🚨 SLOP COP 🚨 · review

Performance review complete. I found no material performance issue.

The new render work processes six small seed values and one fixed-shape environment value. It does not add a large loop or repeated request.

// fresh `defaultEnvironment` object each render. A signature change means
// the caller switched records: it re-seeds every selection (via the
// creation-options resetKey below), including ones the user had touched.
const seedSignature = JSON.stringify([

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🚨 slopcop/review — Include the project seed in the branch reset identity

This signature does not include defaultProjectId. A project change can reset selections but keep branchSeedOverridden from the prior record.

The second record then loses its branch seed when all other seed values match. Please include the project seed in this identity.

initialServiceTier: projectDefaults?.serviceTier,
initialReasoningLevel: projectDefaults?.reasoningLevel,
initialPermissionMode: projectDefaults?.permissionMode,
initialProviderId: defaultProviderId ?? projectDefaults?.providerId,

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🚨 slopcop/review — Preserve the execution source data for seeded values

This prop overrides project defaults in the UI. However, the hook treats the value as an untouched default and returns empty executionInputSources.

The server ignores providerId and model when their source keys are absent. It can replace these visible seeds with project defaults.

Please accept and restore the saved source map, or mark each provided seed as explicit. Add a round-trip test with explicit sources.

@SawyerHood SawyerHood left a comment •

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🚨 SLOP COP 🚨 · review

Code quality review complete. I found one blocking correctness issue and two branch seed defects.

The blocking issue loses execution source data. The server can then replace visible provider and model seeds with project defaults.

I added three inline comments with the exact failure paths and test requests.

// seed were absent.
const selectedBranch =
pickedBranch ??
(!branchSeedOverridden &&

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🚨 slopcop/review — Stop the old branch seed after an environment change

This callback changes the environment without setting branchSeedOverridden. If the user changes away and returns, the old branch seed becomes active again.

Please wrap environment and reuse changes to clear the seed. Add a test for the away-and-return path.

@SawyerHood SawyerHood left a comment •

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🚨 SLOP COP 🚨 · review

End-to-end smoke test complete on commit e6236780.

I installed the Cascade example in a fresh development instance. I opened its host composer, entered a prompt, and submitted it.

The composer created a second thread. The route showed the new thread and no alert.

This test covers the basic route. It does not cover the blocking execution source round trip.

@SawyerHood SawyerHood left a comment •

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🚨 SLOP COP 🚨 · review

Request changes.

The seed props discard the saved executionInputSources. The server can then replace visible provider and model seeds with project defaults.

I also found two branch seed defects:

  • A project change can keep the prior branch override state.
  • An environment change can restore an old branch seed after the user returns.

Security and performance reviews found no issues.

The 12 focused tests pass. The app and plugin SDK typechecks pass. The live Cascade composer smoke test also passes.

The current tests use empty source data. Add explicit source data to the round-trip test and fix all three inline findings.

- Seeded execution fields now report caller-explicit provenance. The server
  discards a requested providerId/model whose source key is absent and
  re-derives it from the project's stored defaults, which silently undid the
  seeds. component-local scope never reports a providerId source at all, so
  the composer's provider could never survive spawn.
- Include defaultProjectId in the seed identity, so a record that differs only
  by project clears the previous record's branch override.
- Retire the branch seed when the user changes environment, so leaving and
  returning no longer resurrects it. The host-driven worktree-unavailable
  fallback keeps the raw setter, since it is not a user pick.

Each fix is covered by a test verified to fail without it.

Co-Authored-By: Claude Fable 5 <[email protected]>
@SawyerHood

Copy link
Copy Markdown
Collaborator Author

Addressed all three findings. Each fix has a test I verified fails without it.

1. Seeded values discarded by the server (blocking). Confirmed against resolveRequestedCreateExecutionValue in apps/server/src/services/threads/project-execution-defaults.ts: when sources is present but a field's key is absent, the requested value is dropped and re-derived from the project's stored defaults. The composer always sent executionInputSources (possibly {}), so seeded providerId/model were silently replaced — exactly the data loss this PR exists to fix. Worse, buildExecutionInputSources never emits a providerId source for component-local scope at all (the standing gap in audit item #2), so the composer's provider could never survive spawn.

Fix: each seeded field now reports "explicit" provenance in the submitted request. "explicit" is correct whether or not the user then changed the value — either way it is a concrete choice the composer displayed, not a default the server should re-derive. Unseeded fields keep the hook's own provenance, so a caller passing no seed props sends exactly what it sent before. The round-trip test now asserts the full source map rather than {}.

2. Branch reset identity missing the project. Fixed — defaultProjectId is now part of the seed signature. New test: clear the branch on record one, switch to a record differing only by project, and the second record keeps its own seeded base branch.

3. Stale branch seed after an environment round trip. Fixed — user environment changes (including the worktree picker, which routes through the same setter) retire the seed permanently. New test covers away-and-return: back in worktree mode the base branch falls to { kind: "default" } instead of the retired release seed.

One deliberate exception: the host-driven "managed worktree unavailable → fall back to local" effect keeps the raw setter. It is a system correction, not a user pick, so it should not retire the seed.

Also updated the defaultProviderId doc comment to state the provenance guarantee, since it is load-bearing for anyone relying on the round trip.

Full suites green: 2199 @bb/app tests, 75 @bb/plugin-sdk; lint and typecheck clean across app, plugin-sdk, server, templates.

@SawyerHood
SawyerHood merged commit 070c8c6 into main Jul 31, 2026
10 checks passed
@SawyerHood
SawyerHood deleted the bb/fix-seed-initial-values-in-experimental-newthrea-thr_y7z4fynxdi branch July 31, 2026 02:55
SawyerHood pushed a commit to SawyerHood/bb-slop-cop that referenced this pull request Jul 31, 2026
The composer previously seeded only project and prompt, so re-opening a
rule showed project defaults for model, reasoning, service tier,
permission mode, and machine. Because the composer's submit IS the save,
editing an unrelated field silently overwrote all of them.

BB's experimental_NewThreadComposer now takes default* seeding props
(get-bb/bb#916), so replay the rule's stored NewThreadRequest into
them. Editing a rule is non-destructive again.

Also refreshes the vendored plugin-SDK type declarations, which are a
scaffold-time snapshot and did not yet know about the new props.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
amadad pushed a commit to amadad/bb that referenced this pull request Aug 14, 2026
## The bug

`experimental_NewThreadComposer` exposed only `defaultProjectId` and
`initialPrompt` as seeds. A plugin that stores the submitted
`NewThreadRequest` and re-opens it for editing (e.g. bb-plugin-slopcop's
`RuleEditor`, where the composer's submit IS the save) got a composer
reset to project defaults on every mount — so re-saving after an
unrelated edit silently overwrote the stored provider, model, permission
mode, and environment. No warning, no diff.

## The fix

Additive, optional seed props on `NewThreadComposerProps`:

- `defaultProviderId`, `defaultModel`, `defaultReasoningLevel`,
`defaultServiceTier`, `defaultPermissionMode` — fed into
`useThreadCreationOptions` as initial values, taking precedence over the
project's remembered defaults and falling back to today's behavior when
omitted.
- `defaultEnvironment` — a new pure mapping
(`new-thread-environment-seed.ts`) inverts
`resolveRootComposeThreadEnvironment`: args → encoded environment-picker
selection + branch pick, including the managed-worktree base branch and
unmanaged existing/new branch specs. Unrepresentable variants are
documented on the prop (`project-default` seeds nothing; `personal`
without `hostId` and an `unmanaged` non-null `path` cannot be encoded).

Semantics (documented in the prop doc comments): they are seeds, not
controlled values; the props are value-compared each render, and any
change re-seeds every selection — including user-touched ones — via the
creation-options `resetKey`, following the established
`defaultProjectId` re-seed-during-render pattern. So switching between
two saved records in one mounted composer reloads that record's values.

Supporting fix in `useThreadCreationOptions`: a `resetKey` change
cleared touched fields in a layout effect *after* the render's
`executionInputSources` had been computed, so the reset render reported
stale `explicit` provenance. The provenance memo now treats a pending
reset as "nothing touched", mirroring the render-time rule
`renderedThreadSelections` already applies.

`RootComposeView` is untouched. The SDK testing harness's fake composer
now echoes the seeds back on submit so plugin tests can cover
store-then-restore.

## Round-trip test

The property that prevents the data loss: feeding a submitted request
back in as the `default*` props and submitting untouched must reproduce
an equivalent request.

- `new-thread-environment-seed.test.ts` — pure round trip of every
environment variant (reuse, managed worktree named/default base,
unmanaged existing/new/no branch) plus the documented unrepresentable
cases.
- `PluginNewThreadComposer.test.tsx` — renders the real composer (prompt
box + query hooks mocked) and asserts: (1) a seeded, untouched submit
`toEqual`s the stored request; (2) after a user touches the model,
swapping in a second record's seeds re-seeds everything and submits that
record exactly; (3) with no seed props, behavior is unchanged (project
defaults).

## Also

- Bundled type declarations regenerated via the repo scripts
(`build-bundled-dts.mjs`, `generate-templates.mjs`).
- bb-plugin-authoring skill: new props + store-then-restore pattern
documented.
- `docs/api_to_audit.md`: audit entry get-bb#6 for the seeding props.

`turbo lint`/`typecheck` clean for app, plugin-sdk, server, templates;
full `@bb/app` (2197 tests) and `@bb/plugin-sdk` suites pass.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

---------

Co-authored-by: Claude Fable 5 <[email protected]>
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