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
41 changes: 32 additions & 9 deletions plugins/stewards/DESIGN.md
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,8 @@ These were settled while designing; each changes what gets built.
Stewards pin nothing and create no sidebar sections. A finished steward
says so in its last turn and the plugin archives it when the binding ends;
a later wake brings it back. A steward waiting on someone else is
hidden between wakes too (§5, "Waiting"). thread-briefs is asked,
hidden between wakes too, and its finished workers and their reviewers are
hidden with it (§5, "Waiting"). thread-briefs is asked,
through each thread's metadata, not to archive or rename stewards and not
to group the project steward: between wakes a steward reads done while
its entity is still open, and its title carries the entity key. (This
Expand Down Expand Up @@ -270,10 +271,12 @@ plugins.
stays addressable, and the next wake reaches it. It is made visible again
when it needs the user — the report puts the user next, an escalation is
open, a question is unanswered, or a needs item is on the Stewards page —
and stays hidden across "nothing changed" wakes. Hiding does not cascade to
the workers, so a worker in flight is no reason to keep the steward
visible; the open-escalation rule stays. A report that needs nobody is also
marked read (`threads.markRead`), so the unread dot means "needs you";
and stays hidden across "nothing changed" wakes. Hiding cascades to the
steward's finished workers and their reviewers, so a row is not left
behind without its steward; a running worker is unaffected, and showing the
steward again shows them. The open-escalation rule stays. A report that
needs nobody is also marked read (`threads.markRead`), so the unread dot
means "needs you";
binding end still archives the thread. Workers stay lifecycle-owned: they
are the steward's children in bb, and the plugin stops them explicitly only
when the binding ends (a detach, or a terminal state without
Expand All @@ -283,6 +286,18 @@ plugins.
anything else; a worker archived since it asked is brought back on that
wake so the tell reaches it, and a worker whose thread is gone is reported
as gone, needing a fresh one.
- **Finished workers and reviewers.** A worker's turn ending marks it
`finished`; once the reconcile that consumed its report has woken the
steward, its thread is archived, so the sidebar keeps only work in flight.
A worker that ended with a question for the steward stays visible until it
is answered, and so does a worker whose binding needs the user. A reviewer
is archived once its round is consumed — the worker's next turn ends, or a
newer round reviewer is spawned for the same worker — and the newest
reviewer for a worker is never archived while that worker is in flight.
Messaging an archived worker from the plugin unarchives it first (`sendTo`),
and it shows under its effort again; the steward's own `bb thread tell`
refuses an archived thread, so it brings the worker back with
`bb thread unarchive` first, or starts a fresh worker.
- **Parent ends first.** Promoted sub-issues still open are re-parented to the
next managed ancestor, or the project steward.

Expand Down Expand Up @@ -513,6 +528,9 @@ gets a review steward.
- **Rounds.** For each round the review steward starts a review worker on the
pull request head with fresh context and the playbook's review instructions.
The worker returns findings; the steward posts them as your review, signed.
A reviewer thread is archived once its round is consumed — the worker's
next turn ends, or a newer round reviewer is spawned for the same worker —
so six rounds do not leave six rows in the sidebar (§5).
- **Later rounds** — new pushes after your review, or a re-request — cover only
what changed since your last review.
- **Reviews post without asking, approvals included.** The review steward
Expand Down Expand Up @@ -743,13 +761,18 @@ follow-through: 6h # how long a terminal binding may be kept open
owner. Whether it should tree by lifecycle owner too is a core question,
not worked around here. The `thread.created` handler files any unsectioned
worker or reviewer into the owner's project section, so a skill that
builds its own spawn command lands there too.
builds its own spawn command lands there too. A finished worker's thread is
archived once the reconcile that consumed its report has woken the steward,
and a reviewer once its round is consumed, so a long-running binding does
not leave its finished rows loose (§5).
- Whether a steward is waiting on you, waiting on someone else, or done is
thread-briefs' judgment from its transcript. A steward waiting on someone
else is hidden (`threads.update { visibility: "hidden" }`), not archived,
so it leaves the sidebar but stays addressable; a wake that needs you makes
it visible again, and the unread dot is cleared after a report that needs
nobody. Ended bindings are archived by this plugin, not by thread-briefs.
so it leaves the sidebar but stays addressable; its finished workers and
their reviewers are hidden with it, and a wake that needs you makes them
visible again. A running worker is not hidden. The unread dot is cleared
after a report that needs nobody. Ended bindings are archived by this
plugin, not by thread-briefs.

## 16. Architecture

Expand Down
24 changes: 20 additions & 4 deletions plugins/stewards/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -138,8 +138,20 @@ bb. [DESIGN.md](DESIGN.md) is the design; this is how it is built and run.
stays addressable, so a later wake can reach it. It is made visible again
when it needs you (the report puts you next, an escalation is open, or a
question is unanswered) and stays hidden across "nothing changed" wakes.
Hiding does not cascade to its workers, so a worker in flight is no reason
to keep it visible; binding end still archives.
Hiding cascades to its finished workers and their reviewers, so no row is
left behind without its steward; a running worker is unaffected, and
showing the steward again shows them. Binding end still archives.
- **Finished workers and reviewers.** A worker whose turn ends is marked
`finished`; once the reconcile that consumed its report has woken the
steward, its thread is archived, so the sidebar keeps only work in flight.
A worker that ended with a question for the steward stays visible until it
is answered. A reviewer is archived once its round is consumed — the
worker's next turn ends, or a newer round reviewer is spawned for the same
worker — and the newest reviewer for a worker is never archived while that
worker is in flight. A later message to an archived worker unarchives it,
and it shows under its effort again; the steward's own `bb thread tell`
refuses an archived thread, so it runs `bb thread unarchive <id>` first, or
starts a fresh worker.
- **thread-briefs.** Every steward, the project steward included, is
spawned with `threadBriefs: { rename: false, group: false, archive: false }`
in this plugin's metadata namespace (see thread-briefs' "Threads a plugin
Expand All @@ -157,12 +169,16 @@ bb. [DESIGN.md](DESIGN.md) is the design; this is how it is built and run.
that, a project steward renamed by hand keeps its name.
- **The sidebar and the unread dot.** A steward is put in its project's
section when it is spawned, and a worker or reviewer the plugin did not
place is filed there by the `thread.created` handler. The unread dot
place is filed there by the `thread.created` handler. A finished worker
leaves the sidebar once its report is consumed, and a consumed reviewer
once its round is; a waiting steward's finished workers and their reviewers
hide with it and come back when it does. The unread dot
means "needs you": a report that waits on someone else, with no
escalation, question or needs item, is marked read. A report that needs
you is left unread.
- **Workers** are top-level threads with their own checkout, one per bounded
task, owned by their steward through `--lifecycle-owner-thread`. They do
task, owned by their steward through `--lifecycle-owner-thread`. A reviewer
is a child of the worker that started it, one per review round. Workers do
not nest under their steward's sidebar row: bb's list trees by parent
thread, not by lifecycle owner, so they show loose; whether it should tree
by lifecycle owner too is a core question. A runaway guard stops a
Expand Down
151 changes: 148 additions & 3 deletions plugins/stewards/server.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -339,13 +339,13 @@ async function setup(extra: Partial<StewardsDeps> = {}, settings: Record<string,
const model = over.model === undefined ? "claude-opus-5-5" : over.model;
const reasoningLevel = over.reasoningLevel === undefined ? "high" : over.reasoningLevel;
const environmentProviderId = over.environmentProviderId === undefined ? "multi-repo-workspace" : over.environmentProviderId;
w.threads.set(id, { status: "active", archivedAt: null, parentThreadId: parent, sectionId: over.sectionId ?? null, providerId, ...(model === null ? {} : { model }), ...(reasoningLevel === null ? {} : { reasoningLevel }), environmentProviderId });
w.threads.set(id, { status: "active", archivedAt: null, visibility: "visible", parentThreadId: parent, sectionId: over.sectionId ?? null, providerId, ...(model === null ? {} : { model }), ...(reasoningLevel === null ? {} : { reasoningLevel }), environmentProviderId });
await harness.behavior.emitThreadEvent("thread.created", { thread: makeThreadResponse({ id, parentThreadId: parent, lifecycleOwnerThreadId: parent, title, originPluginId: null, providerId, sectionId: over.sectionId ?? null }) });
await flush();
};
/** A top-level worker a steward started with only `--lifecycle-owner-thread`: no parent. */
const createdOwned = async (id: string, owner: string, title = "Implement", sectionId: string | null = null) => {
w.threads.set(id, { status: "active", archivedAt: null, parentThreadId: null, sectionId, providerId: "claude-code", model: "claude-opus-5-5", reasoningLevel: "high", environmentProviderId: "multi-repo-workspace" });
w.threads.set(id, { status: "active", archivedAt: null, visibility: "visible", parentThreadId: null, sectionId, providerId: "claude-code", model: "claude-opus-5-5", reasoningLevel: "high", environmentProviderId: "multi-repo-workspace" });
await harness.behavior.emitThreadEvent("thread.created", { thread: makeThreadResponse({ id, parentThreadId: null, lifecycleOwnerThreadId: owner, title, originPluginId: null, providerId: "claude-code", sectionId }) });
await flush();
};
Expand Down Expand Up @@ -1414,7 +1414,9 @@ describe("terminal states and follow-through", () => {
await t.idle(t.steward);
expect((await t.list())[0]).toMatchObject({ ended: true });
expect(t.stops()).toEqual(["thr_w1", "thr_w2"]);
expect(t.archives()).toEqual([t.steward]);
// thr_w1 finished and its report was consumed by the follow-through wake,
// so it was archived then; the steward archives at the binding's end.
expect(t.archives()).toEqual(["thr_w1", t.steward]);
});

it("ends a follow-through that runs out, stopping its workers and telling the project steward", async () => {
Expand Down Expand Up @@ -1890,6 +1892,149 @@ describe("stewards waiting on others", () => {
});
});

describe("archiving finished workers and reviewers (BB-47)", () => {
it("archives a reviewer once its worker's next turn ends, and keeps the worker until the round is consumed", 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.created("thr_r1", "thr_w1", "Review round 1");

// The worker ends its turn to wait on the reviewer, which is still
// running: neither is archived (archiving the worker would clear the
// reviewer's parent in bb and stall the review loop).
t.threads.get("thr_r1")!.status = "active";
await t.idle("thr_w1", "Waiting on the reviewer.");
expect(t.threads.get("thr_r1")!.archivedAt).toBeNull();
expect(t.threads.get("thr_w1")!.archivedAt).toBeNull();

// The reviewer has finished and the worker's next turn ends: the round is
// consumed, so the reviewer leaves the sidebar, and now the worker does.
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 the older reviewer when a newer round is spawned, and never the newest while its worker is in flight", 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.created("thr_r1", "thr_w1", "Review round 1");
expect(t.threads.get("thr_w1")!.status).toBe("active");
await t.created("thr_r2", "thr_w1", "Review round 2");
expect(t.threads.get("thr_r1")!.archivedAt).not.toBeNull();
expect(t.threads.get("thr_r2")!.archivedAt).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" }));
await t.ring("linear", "uuid-12");
const steward = t.spawns[1]!.id;
await t.created("thr_w1", steward);
await t.idle("thr_w1", "Implemented the fix.");
expect(t.hooks.store.worker("thr_w1")!.status).toBe("finished");
expect(t.threads.get("thr_w1")!.archivedAt).not.toBeNull();

// A worker that ended with a question for the steward stays, so the
// steward can answer it.
await t.created("thr_w2", steward);
await t.idle("thr_w2", "Should I file a follow-up?");
expect(t.threads.get("thr_w2")!.archivedAt).toBeNull();
});

it("unarchives a finished worker when the plugin messages it, so it shows under its effort again", 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.idle("thr_w1", "Implemented the fix.");
expect(t.threads.get("thr_w1")!.archivedAt).not.toBeNull();

// The escalation is raised after the archive to exercise sendTo's
// unarchive directly; a real worker with an open escalation would keep
// needsUser true and not be archived in the first place.
const b = t.hooks.store.find("ENG-12")!;
const x = t.hooks.store.escalate({ bindingId: b.id, kind: "decision", question: "Which approach?", meanwhile: "Wait.", route: "me", recommendation: null, projectId: "p1", origin: { threadId: "thr_w1", bindingId: b.id, chain: [] } });
t.hooks.store.resolve(x.id, "The second one.", "user");
await t.hooks.sweep();
await t.flush();
expect(t.threads.get("thr_w1")!.archivedAt).toBeNull();
expect(t.sends.find((s) => s.threadId === "thr_w1")!.text).toMatch(/The second one\./u);
});

it("hides a waiting steward's finished workers and their reviewers with it, and shows them again", 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.created("thr_w2", steward);
await t.created("thr_w3", steward);
await t.created("thr_r1", "thr_w1", "Review round 1");
// thr_w1 is finished (it asked a question, so it stays visible), its
// reviewer is still running, thr_w2 runs, and thr_w3's reviewer is a
// build-tickets hidden spawn (a running worker's reviewer is not hidden
// by the cascade and must stay hidden when the steward comes back).
await t.created("thr_r2", "thr_w3", "Review round 1");
t.threads.get("thr_r2")!.visibility = "hidden";
await t.idle("thr_w1", "Should I keep the reviewer open?");

await t.tool("steward_report", { phase: "In Progress", summary: "Implemented.", nextAction: "Wait for the worker", actor: "other", blockedOn: "the worker" }, steward);
await t.idle(steward);
expect(t.threads.get(steward)!.visibility).toBe("hidden");
expect(t.threads.get("thr_w1")!.visibility).toBe("hidden");
expect(t.threads.get("thr_r1")!.visibility).toBe("hidden");
// A running worker is unaffected, and neither is its hidden reviewer.
expect(t.threads.get("thr_w2")!.visibility).toBe("visible");
expect(t.threads.get("thr_r2")!.visibility).toBe("hidden");

// A wake that needs the user brings the steward back, and them with it.
const b = t.hooks.store.byThread(steward)!;
t.hooks.store.patch(b.id, { status: { ...b.status!, actor: "me" } });
t.entities.set("uuid-12", issue({ state: "In Progress", stateType: "started", comments: [comment({ createdAt: "2026-10-14T16:00:00Z" })] }));
await t.ring("linear", "uuid-12");
expect(t.threads.get(steward)!.visibility).toBe("visible");
expect(t.threads.get("thr_w1")!.visibility).toBe("visible");
expect(t.threads.get("thr_r1")!.visibility).toBe("visible");
expect(t.threads.get("thr_w2")!.visibility).toBe("visible");
// The show cascade is symmetric: it does not flip a running worker's
// hidden reviewer into the sidebar.
expect(t.threads.get("thr_r2")!.visibility).toBe("hidden");
});

it("does not archive a finished worker when the reviewer listing fails, so a reviewer is never orphaned", 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);
// "Unknown" is not "no reviewers": the worker waits for a listing that works.
t.harness.sdk.stub("threads.list", async () => {
throw new Error("listing is down");
});
await t.idle("thr_w1", "Implemented the fix.");
expect(t.threads.get("thr_w1")!.archivedAt).toBeNull();
});

it("shows a worker the waiting cascade hid once it is woken again", 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);
t.threads.get("thr_w1")!.visibility = "hidden";
await t.harness.behavior.emitThreadEvent("thread.active", { thread: makeThreadResponse({ id: "thr_w1", visibility: "hidden" }) });
await t.flush();
expect(t.threads.get("thr_w1")!.visibility).toBe("visible");
});
});

describe("passes", () => {
it("adopts at most perPass per sweep, oldest first", async () => {
const t = await setup();
Expand Down
Loading
Loading