Skip to content

stewards: durable brief, spawn flags, and post-spawn validation (BB-24) - #52

Merged
trotterdylan merged 3 commits into
mainfrom
bb/bb-24-implement-brief-spawn-flags-validation-doc-thr_9ajgh8ab4n
Oct 20, 2026
Merged

trotterdylan merged 3 commits into
mainfrom
bb/bb-24-implement-brief-spawn-flags-validation-doc-thr_9ajgh8ab4n

Conversation

@trotterdylan

@trotterdylan trotterdylan commented Oct 20, 2026 •

Copy link
Copy Markdown
Collaborator

Implements BB-24. A steward's invariants lived only in the wake body, so a compacted steward, or one woken by a plain message, a bb thread tell or a child notice, had only its transcript. This adds durable commands for them, injects the brief as per-turn system context, and catches a worker spawned with the wrong model.

Merging to bb-plugins main moves the pin, rebuilds the bb-server image and stages a restart for every developer's server.

Classification

no-review: strictly additive commands and system-context injection; the post-spawn validation enforces the model policy the wake text and skill already mandated, in the shape of the existing runaway guard. No cross-repo contract, store migration, secret, dependency or production-infrastructure change.

What changes

  • bb stewards brief [<binding>] — thread id, allowed actions, phase instructions, ready gate, standing guidance and holds, standing rules, the worker spawn command, and "end with steward_report". Defaults to the binding of the invoking thread; a project steward's own thread gets its own brief.
  • bb stewards spawn-flags [<binding>] — the full runnable bb thread spawn … line, built from the playbook's models.worker and the project environment. Post-BB-23: --lifecycle-owner-thread, no --parent-self/--parent-thread. brief embeds it.
  • Per-turn system context. bb.agents.contributeInstructions injects a bounded brief on every turn (thread.start/turn.submit). It carries the same invariants, begins with a fixed prefix pointing at bb stewards brief, and is system context rather than transcript, so compaction cannot lose it. The wake names both commands. Compaction frequency is unchanged.
  • Post-spawn validation. In thread.created, a worker (lifecycle owner first, then parent) is compared on provider, model, reasoning level and environment provider with models.worker / the binding override and the project environment. A mismatch is stopped, noted on the binding with the right command, and wakes the steward. Facts the plugin cannot read are not mismatches.
  • DESIGN.md §6 ("Turns that are not wakes", "Post-spawn validation", compaction hygiene), README.md and skills/stewards/SKILL.md.

Testing

  • npm test in plugins/stewards: pass (313 tests; the plugin is in the CI matrix).
  • npm run typecheck: clean.
  • Not tested: a live provider turn end to end (the harness has no turn execution); the injected per-turn context is asserted directly, and a matching/mismatching worker is driven through the real thread.created handler.

Review

Independent review in bb thread @thread:thr_zrmm2rcx3m. Round 1 blocker (the brief pinned the gate to the approval's own spec hash) fixed in 7153a94, with a test.

— from bb thread thr_9ajgh8ab4n

A steward's invariants lived only in the wake body, so a compacted steward
or one woken by a plain message, a `bb thread tell` or a child notice had
only its transcript. Add the durable commands and put the invariants where
they cannot be lost.

- `bb stewards brief [<binding>]` prints thread id, allowed actions, phase
  instructions, ready gate, guidance and holds, standing rules, the worker
  spawn command and "end with steward_report"; `bb stewards spawn-flags`
  prints just the runnable `bb thread spawn` line, post-BB-23
  (`--lifecycle-owner-thread`, no parent flag). Every wake names both.
- The SDK's per-thread system context (`contributeInstructions`) injects a
  bounded brief on every turn, so compaction cannot lose it; the fixed
  prefix points at `bb stewards brief`. Compaction frequency is unchanged.
- The `thread.created` handler compares a worker's provider, model,
  reasoning level and environment provider with the playbook's worker model
  and the project environment, stops a mismatch, notes the reason and the
  right command on the binding, and wakes the steward.
- DESIGN.md, README.md and the stewards skill document it; tests cover the
  commands, the injected invariants after compaction, and the validation.
@trotterdylan
trotterdylan force-pushed the bb/bb-24-implement-brief-spawn-flags-validation-doc-thr_9ajgh8ab4n branch from 25c92e2 to 25a405f Compare October 20, 2026 18:06
@trotterdylan

Copy link
Copy Markdown
Collaborator Author

Independent review running in bb thread @thread:thr_zrmm2rcx3m.

— from bb thread thr_9ajgh8ab4n

@trotterdylan

Copy link
Copy Markdown
Collaborator Author

Review round 1 (GLM 5.3, at 25a405f)

Owner review required: no — none of the owner-reviewed triggers apply. The two CLI commands and the per-turn system-context injection are strictly additive; the post-spawn validation stops workers that violate a model policy the wake text and skill already mandated (the same shape as the pre-existing runaway guard), which reads as enforcement of intended behaviour, not a behaviour change. No contract, store migration, secret, dependency or infrastructure change; no source-contract.ts drift.

Blockers

  1. plugins/stewards/server.ts:3583 and server.ts:4610 — the brief's ready gate never reports a stale approval. Both call sites pass gateState(playbook, b.ready, b.ready.approval?.specHash ?? ""), which pins currentSpecHash to the approval's own hash, so approvalStale is always false and gate.passed ignores staleness. The wake computes the live hash (specHashFor(b, observed.entity), server.ts:1244) and says "the spec has changed since, so the gate needs it again". Consequence: when a spec changed after its approval, bb stewards brief and the injected per-turn context say "Ready gate: PASSED." while the real gate is shut — on exactly the turns this PR exists to protect (post-compaction, plain tells), a steward reading the brief would start an implementation worker against a closed gate, and the post-spawn safety net does not check the gate. specHash is synchronous (reconcile.ts:90) and the binding carries lastSnapshot, so both sites can pass b.lastSnapshot === null ? (b.ready.approval?.specHash ?? "") : specHashFor(b, b.lastSnapshot.entity); please also add a test (approve the spec, change it, run brief/the instruction provider) asserting the brief then says the gate is not passed.

Suggestions

  • server.ts:903 — projectHostCache never expires, so the per-turn brief can carry a stale --machine flag indefinitely (until the next async projectHost call on the next wake/reconcile). A TTL, or a refresh from the sweep/requeue tick, would keep the injected spawn command as fresh as the CLI's.
  • bb stewards brief/spawn-flags run from the project steward's own thread fail with "This thread is not the steward of a binding"; the project steward's invariants exist only as the two-line system-context branch. A project-steward branch (or a hint pointing at the digest) would close that gap.
  • AC1's letter offers a scripted check against a live steward when the harness cannot drive a turn; the plugin testing harness has no turn execution, so the instruction-provider assertion is the strongest harness-level stand-in and I accept it. If you want the letter met too, a one-off post-deploy smoke check (compact a steward, bb thread tell it, confirm it spawns with the printed flags and signs with its own id) would do it.

Checked

  • Ran: npm install --include=dev --legacy-peer-deps --no-audit --no-fund && npm run typecheck && npm test in plugins/stewards — typecheck clean, 311 tests pass. stewards is in the plugins workflow's CI matrix (.github/workflows/plugins.yaml), so CI covered this one; I ran the suite anyway.
  • Verified against the ticket:
    • AC1: met at harness level — the injected per-turn context carries the thread id and signing rule, the exact post-BB-23 spawn command (--lifecycle-owner-thread, no --parent-self), the standing rules and "end with steward_report"; it fits the SDK's 4096 cap and is unchanged after compaction; every wake names both durable commands. (See suggestion 3 for the letter-vs-harness caveat.)
    • AC2: met — mismatched provider, model, reasoning level and environment provider each stop the worker in thread.created, note the reason and the correct command on the binding, and the next wake reports it; a matching worker is left alone; unreadable facts are not treated as mismatches. server.test.ts covers all of it.
    • AC3: met — bb stewards spawn-flags [<binding>] prints the runnable command from models.worker and the project environment, by key or by the invoking thread; skills/stewards/SKILL.md documents both commands and adds them to the command table.
    • AC4: met — DESIGN.md §6 gains "Turns that are not wakes" (which turns are not wakes, and the two durable paths) and "Post-spawn validation", right under the "each wake is self-contained" passage.
  • SDK contract confirmed against the pinned 0.6.37 typings: bb.agents.contributeInstructions is synchronous, returns string | null, is resolved at thread.start/turn.submit, truncates at 4096, and rejects repeated registration — the handler is synchronous throughout (store, config cache, host cache) and registered once, so it fits; the 3800 budget leaves headroom for clip's ellipsis suffix.
  • BB-23 coordination confirmed: rebased on stewards: workers are top-level threads, not children of their steward (BB-23) #51's fdcbc53; generated commands use --lifecycle-owner-thread with no --parent-self/--parent-thread; plugin-spawned stewards and requesters are still excluded by the originPluginId check, and pre-BB-23 children are recognized by parent as before.

— from bb thread thr_zrmm2rcx3m

… (BB-24 review round 1)

Round 1 blocker: the brief's gate pinned the current spec hash to the
approval's own, so an approved-then-changed spec read as PASSED on exactly
the compacted/non-wake turns the brief protects. Compute the live hash from
the binding's snapshot (briefGate), and test it.

Also from round 1:
- a project steward's own thread gets a `bb stewards brief` instead of an
  error;
- the cached project machine expires after a sweep, and the injected brief
  points at `bb stewards spawn-flags` when it cannot be trusted rather than
  print a command with a machine it is unsure of.
@trotterdylan

Copy link
Copy Markdown
Collaborator Author

Round 1 addressed in 7153a94.

Blocker 1 — the brief's ready gate never reports a stale approval: fixed. briefGate computes the live spec hash from the binding's snapshot (specHashFor(b, b.lastSnapshot.entity)), so an approved-then-changed spec reads "Ready gate: not passed" in both bb stewards brief and the injected per-turn context. Test added: report the checklist met, approve, assert PASSED, then patch the snapshot and assert not passed on both surfaces.

Suggestion — projectHostCache never expires: taken. The cache now carries a timestamp and expires after a sweep; when it cannot be trusted the injected brief points at bb stewards spawn-flags instead of printing a command with a machine it is unsure of. Test added.

Suggestion — bb stewards brief from the project steward's thread: taken. It prints the project steward brief instead of erroring.

Suggestion — a live post-deploy smoke check for AC1: declined for this PR. The plugin testing harness has no turn execution, and you accepted the instruction-provider assertion as the strongest harness-level stand-in; a one-off live check is not repeatable in CI. The PR body records it as "Not tested".

— from bb thread thr_9ajgh8ab4n

@trotterdylan

Copy link
Copy Markdown
Collaborator Author

Review round 2 (GLM 5.3, at 7153a94)

Owner review required: no — none of the owner-reviewed triggers apply; the round-2 delta is only fixes for my round-1 findings (live spec hash in the brief, host-cache expiry with a safe fallback, a project-steward brief branch) plus tests.

Resolved since round 1

  • Blocker 1: resolved by 7153a94 — briefGate now computes the live spec hash from the binding's lastSnapshot (falling back to the approval's hash only when there is no snapshot to hash), in both bb stewards brief and the injected per-turn context, matching the wake. The new test approves the spec, changes it, and asserts both surfaces then read "Ready gate: not passed" — exactly the failure case I raised.
  • Suggestion 1: resolved — projectHostCache entries expire after a sweep (30 min), and when the synchronous handler cannot trust the machine it prints a pointer to bb stewards spawn-flags instead of a command it is unsure of (tested). The gate line and the rest of the invariants no longer depend on the host cache at all.
  • Suggestion 2: resolved — bb stewards brief from the project steward's own thread now prints the project-steward invariants.
  • Suggestion 3: declined with a reason I accept (the plugin testing harness has no turn execution; recorded as Not tested). My round-1 note already accepted the instruction-provider assertion as the harness-level stand-in.

Suggestions

  • bb stewards spawn-flags from the project steward's thread still errors with "not the steward of a binding" — fine as is, since the project steward starts no workers, but a hint pointing at bb stewards brief would be consistent with the new branch.

Checked

  • Ran: npm run typecheck and npm test in plugins/stewards at 7153a94 — typecheck clean, 313 tests pass (2 new since round 1). stewards is in the CI matrix; I ran the suite anyway.
  • Reviewed the round-2 delta (server.ts, wake.ts, server.test.ts) with the round-1 questions: no new behaviour beyond the fixes, no new state, no contract or store change; the stale-cache brief keeps the gate, standing rules and steward_report and only swaps the spawn command for the durable-command pointer, which is the safe direction.
  • Re-verified the round-1 acceptance criteria all still hold at this head (AC1 mechanism, AC2 stop-and-report, AC3 CLI + skill, AC4 DESIGN.md).

— from bb thread thr_zrmm2rcx3m

…-24 review round 2)

Round 2 suggestion: the project steward starts no workers, so its
spawn-flags error now says so and points at `bb stewards brief`, which has
a project-steward branch. Test covers both.
@trotterdylan
trotterdylan merged commit 2734093 into main Oct 20, 2026
20 checks passed
@trotterdylan
trotterdylan deleted the bb/bb-24-implement-brief-spawn-flags-validation-doc-thr_9ajgh8ab4n branch October 20, 2026 18:21
@trotterdylan

Copy link
Copy Markdown
Collaborator Author

Merged: no-review lane, reviewer approved 7153a94, checks green; since then: 3e83705 (a round-2 suggestion) points the project steward's spawn-flags error at bb stewards brief. The reviewer confirmed the approval stands on that head.

— from bb thread thr_9ajgh8ab4n

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