Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions plugins/stewards/DESIGN.md
Original file line number Diff line number Diff line change
Expand Up @@ -628,7 +628,8 @@ tuning it against the BB and bithub stewards is a follow-up, not this design.

A worker is recognized by the `thread.created` handler by its lifecycle
owner or its parent — whichever the skill that spawned it set — and never as
a reviewer, which is a child of a worker. Before
a reviewer, which follows a worker as its lifecycle owner (BB-323) or its
parent. Before
the runaway guard, the handler compares the worker's provider, model,
reasoning level and environment provider with the playbook's `models.worker`
(or the binding's override) and the project's environment. On a mismatch it
Expand Down Expand Up @@ -1059,7 +1060,10 @@ deployment: # where a merge is confirmed live (BB-53); omi
--parent-self --parent-notifications off --lifecycle-owner-thread
"$BB_THREAD_ID" …`; the plugin recognizes them by
that owner or their parent, and a worker an older steward left with only the
owner is still recognized. `parentNotifications: off` keeps a worker's
owner is still recognized. A reviewer is started from its worker with that
worker as lifecycle owner and no parent (BB-323), because bb core refuses a
child for an active Pi parent; the plugin recognizes it by that owner or its
parent. `parentNotifications: off` keeps a worker's
finish from waking the steward: its final message arrives in the next wake,
which lists finished workers. The worker nests under its steward's row,
because bb's list trees by parent thread. A finished worker's thread is archived once the reconcile that
Expand Down
15 changes: 9 additions & 6 deletions plugins/stewards/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -232,10 +232,12 @@ bb. [DESIGN.md](DESIGN.md) is the design; this is how it is built and run.
you is left unread.
- **Workers** are children of their steward with their own checkout, one per
bounded task, spawned with `--parent-self --parent-notifications off
--lifecycle-owner-thread`. A reviewer is a child of the worker that started
it, one per review round. A worker nests under its steward's row and a
reviewer under its worker's, because bb's list trees by parent thread; the
parent is not woken on a child's turn. The plugin only ever archives a
--lifecycle-owner-thread`. A reviewer is started from the worker that
started it with that worker as its lifecycle owner and no parent (BB-323),
one per review round. A worker nests under its steward's row and a reviewer
under its worker's, because the sidebar trees a thread under its parent, or
under its lifecycle owner when it has none; the parent is not woken on a
child's turn. The plugin only ever archives a
steward, worker or reviewer, never deletes one: deleting a parent thread
deletes every descendant, archived ones included (get-bb/bb#6129), so
deleting the project steward row by hand takes every steward, worker and
Expand Down Expand Up @@ -316,8 +318,9 @@ bb. [DESIGN.md](DESIGN.md) is the design; this is how it is built and run.
wins, then the playbook, then nothing. `bb stewards spawn-flags --role
reviewer [<binding>]` prints the full `bb thread spawn` command for a
reviewer — hidden, full permissions, the reviewer model, started from the
worker thread that owns the pull request so `--parent-self` makes it that
worker's child — and fails clearly when no reviewer model is configured.
worker thread that owns the pull request with that worker as its lifecycle
owner and no parent (BB-323) — and fails clearly when no reviewer model is
configured.
The default role is `worker`, whose output is unchanged. `bb stewards gate
<owner/repo#N> [--json]` reads the pull request fresh and prints the same
verdict the page and the wake use (`prGate`): the lane, the latest
Expand Down
6 changes: 5 additions & 1 deletion plugins/stewards/read-counts.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,11 @@ describe("a reconcile pass over a fixed binding set (BB-297)", () => {
// second gate) because the reconcile hands it the one assessment it just
// built. The wake fell 16 → 15 for the same reason: `wakeInner` reads the
// assessment the reconcile passed in, not `projectApprovals` again.
expect(reconcile).toEqual({ storeReads: 183, sourceCalls: 12, reconciles: 4, bindings: 4 });
// BB-323 raised the reconcile reads 183 → 185: `archiveWorkers` asks
// `reviewersOf` for a finished worker's live reviewers as well as its
// descendants, so a parentless reviewer keeps the worker unarchived. That
// is the worker row and its binding, two store reads.
expect(reconcile).toEqual({ storeReads: 185, sourceCalls: 12, reconciles: 4, bindings: 4 });
expect(wake).toEqual({ storeReads: 15, sourceCalls: 0, wakes: 1 });
});

Expand Down
78 changes: 77 additions & 1 deletion plugins/stewards/server.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -947,6 +947,53 @@ describe("a Linear ticket steward", () => {
expect(result.bindings[0]!.reviewers).toBeUndefined();
});

// BB-323: the printed reviewer command drops `--parent-self`, so a reviewer
// has no parent and names only its worker as lifecycle owner. It is
// recognized from that owner, tagged, superseded and never validated as a
// worker; a steward-owned or steward-parented thread is still validated.
it("recognizes a parentless reviewer by its lifecycle owner, never validates it, and supersedes it", async () => {
const t = await setup();
t.entities.set("uuid-12", issue({ state: "In Progress", stateType: "started" }));
await t.ring("linear", "uuid-12");
const steward = t.spawns[1]!.id;
const binding = t.hooks.store.open("p1")[0]!.id;
const stopped = () => t.harness.sdk.callsTo("threads.stop").map(([args]) => (args as { threadId: string }).threadId);

await t.created("thr_w1", steward);
// The reviewer names only its lifecycle owner, with a model that
// validation would stop, so a missed recognition is visible.
await t.createdReviewer("thr_r1", "thr_w1", "Review round 1", { model: "claude-sonnet-5-5" });
expect(t.metadata.get("thr_r1")).toEqual({ threadBriefs: false });
expect(t.hooks.store.worker("thr_r1")).toBeNull();
expect(stopped()).not.toContain("thr_r1");

// A newer round supersedes the older parentless reviewer.
await t.createdReviewer("thr_r2", "thr_w1", "Review round 2");
expect(t.threads.get("thr_r1")!.archivedAt).not.toBeNull();
expect(t.threads.get("thr_r2")!.archivedAt).toBeNull();

// The parented form is unchanged: a newer child supersedes the parentless
// one, and is itself never validated.
await t.created("thr_r3", "thr_w1", "Review round 3", { model: "claude-sonnet-5-5" });
expect(t.threads.get("thr_r2")!.archivedAt).not.toBeNull();
expect(t.threads.get("thr_r3")!.archivedAt).toBeNull();
expect(t.hooks.store.worker("thr_r3")).toBeNull();

// A parentless thread whose lifecycle owner is a steward is still a worker,
// and a steward-parented thread on the wrong model is still stopped.
await t.createdOwned("thr_w2", steward);
expect(t.hooks.store.worker("thr_w2")).toMatchObject({ bindingId: binding, status: "running" });
await t.created("thr_bad", steward, "ENG-12: Implement", { model: "claude-sonnet-5-5" });
expect(t.hooks.store.worker("thr_bad")!.status).toBe("stopped");
expect(stopped()).toContain("thr_bad");

// A thread whose parent is a worker but whose lifecycle owner is the
// steward is still validated as a worker, not skipped as a reviewer.
await t.created("thr_weird", "thr_w1", "ENG-12: Implement", { lifecycleOwnerThreadId: steward, model: "claude-sonnet-5-5" });
expect(t.hooks.store.worker("thr_weird")!.status).toBe("stopped");
expect(stopped()).toContain("thr_weird");
});

it("keeps a running worker's own pull request activity for the next turn instead of waking for it", async () => {
const t = await setup();
const linked = { linkedPulls: [{ key: "acme/web#7", url: "https://github.com/acme/web/pull/7" }] };
Expand Down Expand Up @@ -4386,6 +4433,29 @@ describe("archiving finished workers and reviewers (BB-47)", () => {
expect(t.threads.get("thr_r2")!.archivedAt).toBeNull();
});

it("keeps a worker whose parentless reviewer is still unarchived, and archives it once the reviewer is (BB-323)", async () => {
const t = await setup();
t.entities.set("uuid-12", issue({ state: "In Progress", stateType: "started" }));
await t.ring("linear", "uuid-12");
const steward = t.spawns[1]!.id;
await t.created("thr_w1", steward);
await t.createdReviewer("thr_r1", "thr_w1", "Review round 1");

// The worker ends its turn without a waiting phrase while its parentless
// reviewer still runs: the reviewer is not a descendant, but it keeps the
// worker unarchived (bb would archive its lifecycle tree with it).
t.threads.get("thr_r1")!.status = "active";
await t.idle("thr_w1", "Spawned the reviewer.");
expect(t.threads.get("thr_r1")!.archivedAt).toBeNull();
expect(t.threads.get("thr_w1")!.archivedAt).toBeNull();

// The reviewer is consumed, and the worker's next turn ends: both leave.
t.threads.get("thr_r1")!.status = "idle";
await t.idle("thr_w1", "Addressed the review and pushed.");
expect(t.threads.get("thr_r1")!.archivedAt).not.toBeNull();
expect(t.threads.get("thr_w1")!.archivedAt).not.toBeNull();
});

it("archives a finished worker after the reconcile that consumed its report, unless it needs the user", async () => {
const t = await setup();
t.entities.set("uuid-12", issue({ state: "In Progress", stateType: "started" }));
Expand Down Expand Up @@ -13549,11 +13619,12 @@ describe("the reviewer role and the gate and merge commands (BB-133)", () => {
expect(missing.exitCode).toBe(1);
expect(missing.stderr).toMatch(/No reviewer model/u);

// The worker default is unchanged.
// The worker default is unchanged, and keeps `--parent-self`.
const worker = await t.harness.behavior.runCli(["spawn-flags", "ENG-12", "--project", "p1"]);
expect(worker.stdout).toContain("--model claude-opus-5-5");
expect(worker.stdout).not.toContain("--visibility hidden");
expect(worker.stdout).not.toContain("--permission-mode");
expect(worker.stdout).toContain("--parent-self");

// A playbook reviewer model, then a binding override, both read back.
t.files[playbookPath("linear-tickets")] = LINEAR_TICKETS.replace(" worker: claude/claude-opus-5-5/high", " worker: claude/claude-opus-5-5/high\n reviewer: pi/fireworks/accounts/fireworks/models/glm-5p3");
Expand All @@ -13563,6 +13634,10 @@ describe("the reviewer role and the gate and merge commands (BB-133)", () => {
expect(reviewer.stdout).toContain("--visibility hidden --permission-mode full");
expect(reviewer.stdout).toContain("--provider pi --model fireworks/accounts/fireworks/models/glm-5p3");
expect(reviewer.stdout).toContain('--title "Review ENG-12: <task>"');
// BB-323: the reviewer keeps the worker as lifecycle owner and has no
// parent, so it can run from an active worker.
expect(reviewer.stdout).toContain('--lifecycle-owner-thread "$BB_THREAD_ID"');
expect(reviewer.stdout).not.toContain("--parent-self");

const update = await t.tool("steward_update", { binding: "ENG-12", reviewerModel: "pi/fireworks/accounts/fireworks/models/other-reviewer" }, t.spawns[0]!.id);
expect(update.error, update.text).toBe(false);
Expand Down Expand Up @@ -13594,6 +13669,7 @@ describe("the reviewer role and the gate and merge commands (BB-133)", () => {
expect(out.exitCode).toBe(0);
expect(out.stdout).toContain('--title "Review ENG-12: <task>"');
expect(out.stdout).toContain("--visibility hidden --permission-mode full");
expect(out.stdout).not.toContain("--parent-self");
});

it("prints the gate verdict and exits 0 when met, 1 when not, with --json", async () => {
Expand Down
Loading
Loading