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
20 changes: 12 additions & 8 deletions plugins/stewards/DESIGN.md
Original file line number Diff line number Diff line change
Expand Up @@ -642,14 +642,18 @@ follow-through: 6h # how long a terminal binding may be kept open
done. thread-briefs only moves threads in and out of its own sections, so
it leaves the project section alone. The project steward is titled
"<project name> project steward".
- Workers are visible children of their steward, started by the steward
with `bb thread spawn --project … --parent-self --lifecycle-owner-thread
…` and recognized by the plugin as children of a steward thread. bb's list
builds the parent tree before it files trees into sections, so a worker
shows under its steward's row in the project section whatever section
thread-briefs gives the worker itself, and collapses with that row
(`collapsedThreads`). Workers are not tagged for thread-briefs: their
briefs, renames and auto-archiving are thread-briefs' as for any thread.
- Workers are top-level threads, owned by their steward through
`--lifecycle-owner-thread` and started with `bb thread spawn --project …
--lifecycle-owner-thread "$BB_THREAD_ID" …`; the plugin recognizes them by
that owner, and still recognizes a worker an older steward made a child by
its parent. A worker is no thread's child, so finishing a turn does not
wake the steward: its final message arrives in the next wake, which lists
finished workers. The sidebar loss is accepted: a worker no longer nests
under its steward's row in the project section, because bb's list trees by
parent thread and not by lifecycle owner. Whether it should tree by
lifecycle owner too is a core question, not worked around here. Workers are
not tagged for thread-briefs: their briefs, renames and auto-archiving are
thread-briefs' as for any thread.
- Whether a steward is waiting on you, waiting on someone else, or done is
thread-briefs' judgment from its transcript. Ended bindings are archived
by this plugin, not by thread-briefs.
Expand Down
16 changes: 9 additions & 7 deletions plugins/stewards/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ bb. [DESIGN.md](DESIGN.md) is the design; this is how it is built and run.
project's **project steward**, through its binding — not as a child
thread: bb wakes a parent thread every time a child finishes a turn, and
on bithub that was 88 of the project steward's 96 turns. A project's
stewards share one sidebar section, named after the project, with each
steward's workers nested under it; see DESIGN.md §15.
stewards share one sidebar section, named after the project; see
DESIGN.md §15.
- **Ops stewards.** Each target in the project file's `ops.targets` (a
Kubernetes namespace or a Sentry project) gets an `ops` steward, reporting to the project
steward, for as long as it is listed. The plugin looks at the target with
Expand Down Expand Up @@ -106,7 +106,7 @@ bb. [DESIGN.md](DESIGN.md) is the design; this is how it is built and run.
what a binding touches and overlaps; the project steward's wake lists
both for every binding. Everything else is the tools every thread has: `linear_*`, `gh`,
and `bb thread spawn` / `tell` for workers, which stewards recognizes as
children of a steward thread.
workers by their lifecycle owner.
- **Lifecycle.** A terminal state gets a wrap-up turn with its workers
still running. The steward either ends the binding there, or keeps it open
to follow through (`steward_report { followThrough }`) on what the state
Expand Down Expand Up @@ -135,10 +135,12 @@ bb. [DESIGN.md](DESIGN.md) is the design; this is how it is built and run.
spawned before this, lets go of stewards an earlier version made children
of another steward, and renames an older project steward once. After
that, a project steward renamed by hand keeps its name.
- **Workers** are child threads with their own checkout, one per bounded
task, owned by their steward. They show nested under their steward's
sidebar row, which collapses them like any parent. A runaway guard stops a steward's
workers past a per-hour limit.
- **Workers** are top-level threads with their own checkout, one per bounded
task, owned by their steward through `--lifecycle-owner-thread`. They 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
steward's workers past a per-hour limit.
- **Decisions stay with the agents.** Escalations are conditions on the
status record, routed to the parent steward, then the project steward,
which decides from the project's guidance (AGENTS.md, design docs). Only
Expand Down
49 changes: 46 additions & 3 deletions plugins/stewards/server.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -226,13 +226,19 @@ async function setup(extra: Partial<StewardsDeps> = {}, settings: Record<string,
await harness.behavior.emitThreadEvent("thread.idle", { thread: makeThreadResponse({ id: threadId }), lastAssistantText });
await flush();
};
/** A thread a steward started with `bb thread spawn --parent-self`. */
/** A thread an older steward started as a child: `bb thread spawn --parent-self`. */
const created = async (id: string, parent: string, title = "Implement") => {
w.threads.set(id, { status: "active", archivedAt: null, parentThreadId: parent });
await harness.behavior.emitThreadEvent("thread.created", { thread: makeThreadResponse({ id, parentThreadId: parent, lifecycleOwnerThreadId: parent, title, originPluginId: null }) });
await flush();
};
return { ...w, bb, harness, hooks, flush, ring, tool, list, idle, created };
/** A top-level worker a steward started with only `--lifecycle-owner-thread`: no parent. */
const createdOwned = async (id: string, owner: string, title = "Implement") => {
w.threads.set(id, { status: "active", archivedAt: null, parentThreadId: null });
await harness.behavior.emitThreadEvent("thread.created", { thread: makeThreadResponse({ id, parentThreadId: null, lifecycleOwnerThreadId: owner, title, originPluginId: null }) });
await flush();
};
return { ...w, bb, harness, hooks, flush, ring, tool, list, idle, created, createdOwned };
}

describe("a Linear ticket steward", () => {
Expand Down Expand Up @@ -263,7 +269,10 @@ describe("a Linear ticket steward", () => {
expect(prompt).toMatch(/given by the project steward/u);
// The first wake is the spawn prompt, before the thread has an id.
expect(prompt).toMatch(/Your thread id is in `\$BB_THREAD_ID`/u);
expect(prompt).toContain(`bb thread spawn --project p1 --parent-self --lifecycle-owner-thread "$BB_THREAD_ID" --environment-provider multi-repo-workspace --machine host_on --provider claude-code --model claude-opus-5-5 --reasoning-level high --title "ENG-12: <task>" --prompt-file - <<'EOF'\n <the whole task>\n EOF`);
expect(prompt).toContain(`bb thread spawn --project p1 --lifecycle-owner-thread "$BB_THREAD_ID" --environment-provider multi-repo-workspace --machine host_on --provider claude-code --model claude-opus-5-5 --reasoning-level high --title "ENG-12: <task>" --prompt-file - <<'EOF'\n <the whole task>\n EOF`);
expect(prompt).not.toContain("--parent-self");
expect(prompt).not.toContain("--parent-thread");
expect(prompt).toContain("A worker finishing starts no turn of yours");
expect(await t.list()).toMatchObject([{ key: "ENG-12", kind: "ticket", threadId: steward!.id, ended: false }]);

const interest = t.rpcCalls.filter((c) => c.method === "sourceSetInterest");
Expand Down Expand Up @@ -639,6 +648,40 @@ describe("a Linear ticket steward", () => {
expect(wake).toMatch(/Opened acme\/web#7\./u);
});

// BB-23: a worker is a top-level thread owned only through its lifecycle
// owner. It must still be tracked, guarded and reported, and its finish must
// not start a turn of its own.
it("recognizes a top-level worker by its lifecycle owner, guards it, and reports its finish in the next wake", 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;

// Spawned with only --lifecycle-owner-thread: no parent thread at all
// (`createdOwned` sets parentThreadId null).
await t.createdOwned("thr_w1", steward, "ENG-12: Implement");
expect(t.hooks.store.workers(binding)).toMatchObject([{ threadId: "thr_w1", bindingId: binding, status: "running" }]);
expect(t.sends).toEqual([]);

// Its finish is the wake: the Workers section carries its final text.
await t.idle("thr_w1", "Opened acme/web#7.");
const wake = t.sends.at(-1)!.text;
const workers = wake.slice(wake.indexOf("### Workers"));
expect(workers).toMatch(/ENG-12: Implement \(thread thr_w1\): finished/u);
expect(workers).toMatch(/Opened acme\/web#7\./u);

// A top-level worker counts toward the runaway guard exactly as a child did.
for (let i = 2; i <= 7; i++) await t.createdOwned(`thr_w${i}`, steward);
expect(t.harness.sdk.callsTo("threads.stop")).toEqual([[{ threadId: "thr_w7" }]]);

// The template the steward acts from names no parent flag.
expect(String(t.spawns[1]!.prompt)).not.toContain("--parent-self");
expect(String(t.spawns[1]!.prompt)).not.toContain("--parent-thread");
expect(t.sends.at(-1)!.text).not.toContain("--parent-self");
expect(t.sends.at(-1)!.text).not.toContain("--parent-thread");
});

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
7 changes: 4 additions & 3 deletions plugins/stewards/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2692,9 +2692,10 @@ export function createStewardsPlugin(deps: StewardsDeps): (bb: BbPluginApi) => P

// ---- thread events ---------------------------------------------------------------------------
//
// Workers are started by stewards with `bb thread spawn --parent-self`, so
// they are recognized here, as children of a steward thread, rather than
// through a tool of their own.
// Workers are started by stewards as top-level threads with
// `--lifecycle-owner-thread`, so they are recognized here through their
// lifecycle owner rather than a tool of their own. A thread an older
// steward made a child is still recognized by its parent.

bb.events.on("thread.created", async ({ thread }) => {
// Stewards this plugin spawned (a promoted child under its parent) are not workers.
Expand Down
11 changes: 6 additions & 5 deletions plugins/stewards/skills/stewards/SKILL.md
Original file line number Diff line number Diff line change
Expand Up @@ -74,9 +74,10 @@ Two tools are yours; everything else you do with the tools every thread has.
every later wake. With a child steward, it also decides its escalations,
sets priority and holds, and overrides models.
- **You decide and delegate; you do not write code.** Start a worker for one
bounded task with the `bb thread spawn --parent-self …` command the wake
shows; write the task so the worker needs nothing else. Follow up with
`bb thread tell`. You are woken when it finishes, with its final message.
bounded task with the `bb thread spawn … --lifecycle-owner-thread` command
the wake shows; write the task so the worker needs nothing else. Follow up
with `bb thread tell`. A worker finishing starts no turn of yours: its
final message arrives in your next wake, under Workers.
While it runs you are not woken for its own work on its pull request
(checks, pushes, its comments and its reviewer's, posted as the user);
that shows under "What changed" at your next turn. Other people's
Expand Down Expand Up @@ -318,5 +319,5 @@ above which a steward is compacted after its turn.
chronologically (`bb thread-list prefs get organizationMode`). A steward
is placed there once and never moved back; one dragged out stays out. A
section deleted by hand is not recreated: `bb thread section create
"<project name>"` brings it back for new stewards. Workers sit under their
steward's row; collapse that row to hide them.
"<project name>"` brings it back for new stewards. Workers are top-level
threads owned by their steward, so they do not nest under its row.
4 changes: 2 additions & 2 deletions plugins/stewards/wake.ts
Original file line number Diff line number Diff line change
Expand Up @@ -281,11 +281,11 @@ export function formatWake(input: WakeInput): string {
"",
"Start a worker for one bounded task with:",
"",
` bb thread spawn --project ${binding.projectId} --parent-self --lifecycle-owner-thread "$BB_THREAD_ID" ${input.workerFlags} --title "${e.key}: <task>" --prompt-file - <<'EOF'`,
` bb thread spawn --project ${binding.projectId} --lifecycle-owner-thread "$BB_THREAD_ID" ${input.workerFlags} --title "${e.key}: <task>" --prompt-file - <<'EOF'`,
" <the whole task>",
" EOF",
"",
"Follow it up with `bb thread tell <id> <message>`. You are woken when a worker finishes, with its final message.",
"Follow it up with `bb thread tell <id> <message>`. A worker finishing starts no turn of yours: its final message arrives in your next wake, which lists it under Workers.",
"Those `--provider`/`--model`/`--reasoning-level` flags are your workers' and reviewers' models, from the playbook or the project. They are not yours to choose: never ask the user for a model.",
"",
"**Standing rules.**",
Expand Down
Loading