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
23 changes: 14 additions & 9 deletions plugins/stewards/DESIGN.md
Original file line number Diff line number Diff line change
Expand Up @@ -299,11 +299,16 @@ Plugin code. No model turn.
- guidance changed, an escalation resolved, an approval given or voided;
- the spec changed (description edited, spec comment added);
- `requeueAfter` came due.
While one of the steward's workers is running, its own work on a pull
request is not actionable: checks finishing, description edits, and
pushes and comments from the developer's account, which the worker and
the reviewers it starts post as, often unsigned. People, merges and
closes still are.
While any worker of the binding is in flight — from its spawn until it is
stopped, failed or archived, across the idle between its turns — its own
work on a pull request is not actionable: checks finishing, description
edits, and pushes and comments from the developer's account, which the
worker and the reviewers it starts post as, often unsigned, and the
reviewer's `bb-review` markers, whichever account posts them. A round
that changes the lane does wake it. A first marker, with no earlier round
to change from, does not: the worker's own turn ending carries it, and
waking on every first review would put back the wake the ticket removes.
People, merges and closes still do.
4. Otherwise the snapshot is recorded and the ring ends. Most rings end here:
the steward's own comments, label churn, its workers at work. What
changed is kept as a quiet note and shown with the next turn something
Expand All @@ -321,10 +326,10 @@ The steward is woken with one message in a fixed form:

Each wake is self-contained, so compaction can be aggressive, and it is: after
a steward's or the project steward's turn the plugin compacts its context once
it holds more than a setting (120,000 tokens by default). Left to the provider,
compaction comes near the window's end, and every turn before then reads the
whole transcript. A wake too long to send is cut in its snapshot, never in
what changed. The steward acts and must end its turn with `steward_report`,
it holds more than a setting (120,000 tokens by default), and before a wake
that would push it over. Left to the provider, compaction comes near the
window's end, and every turn before then reads the whole transcript. A wake
too long to send is cut in its snapshot, never in what changed. The steward acts and must end its turn with `steward_report`,
which writes the status record:

| Field | Holds |
Expand Down
17 changes: 10 additions & 7 deletions plugins/stewards/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,20 +23,23 @@ bb. [DESIGN.md](DESIGN.md) is the design; this is how it is built and run.
the last observation, and the steward is woken only for an actionable
change: a phase change, a human comment, a review, checks finishing,
someone else's push, a worker finishing, guidance, an approval, a spec
change, or its requeue time. While one of its workers is running, the
worker's own work on a pull request — checks finishing, description
edits, pushes and comments from your account, which every thread posts
as — is not a reason to wake. Everything not actionable is kept as a
quiet note and shown in "What changed" at the next turn something else
makes due.
change, or its requeue time. While any worker of the binding is in flight
— from its spawn until it is stopped, failed or archived, across the idle
between its turns — the worker's own work on a pull request (checks
finishing, description edits, pushes and comments from your account, which
every thread posts as, and the reviewer's `bb-review` markers) is not a
reason to wake; a reviewer round that changes the lane is. Everything not
actionable is kept as a quiet note and shown in "What changed" at the next
turn something else makes due.
- **Wakes are self-contained**: playbook instructions for the phase, the
ready gate, guidance and holds, the snapshot, and what changed. Each
woken turn ends with `steward_report`, the status record. A wake past
30,000 characters is cut in its snapshot, never in what changed. Because
a wake carries what the steward needs, its transcript can go: after a
steward's or the project steward's turn, the plugin compacts its context
once it holds more than **Compact a steward above this many context
tokens** (120,000 by default; 0 leaves it to the provider).
tokens** (120,000 by default; 0 leaves it to the provider), and before a
wake that would push it over.
- **Two tools.** `steward_report` ends a turn with the status record and,
when needed, an escalation; `steward_update` steers a binding (guidance,
deciding or forwarding escalations, priority, holds, models, approving a
Expand Down
74 changes: 71 additions & 3 deletions plugins/stewards/reconcile.test.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { describe, expect, it } from "vitest";
import { parsePlaybook } from "./config.js";
import { comment, issue, pull } from "./fixtures.js";
import { approvalWanted, diffObserved, endingDeadline, followingThrough, gateKnownUnmet, gateState, isCommentNews, lifecycle, resolveChecklistItem, specHash, stuckDue, unheardWait } from "./reconcile.js";
import { approvalWanted, anyWorkerInFlight, compactDue, diffObserved, endingDeadline, followingThrough, gateKnownUnmet, gateState, isCommentNews, lifecycle, markerLaneChange, resolveChecklistItem, reviewMarker, specHash, stuckDue, unheardWait, workerInFlight } from "./reconcile.js";
import { readyStateSchema } from "./store.js";
import { GITHUB_REVIEWS, LINEAR_TICKETS } from "./templates.js";

Expand All @@ -16,7 +16,7 @@ const reviews = (() => {
return p.value;
})();

const ctx = { own: new Set(["thr_s", "thr_w"]), stewardThreadId: "thr_s", approved: false, cursor: "2026-10-01T12:00:00Z", workerRunning: false };
const ctx = { own: new Set(["thr_s", "thr_w"]), stewardThreadId: "thr_s", approved: false, cursor: "2026-10-01T12:00:00Z", workerInFlight: false };
const actionable = (cs: Array<{ text: string; actionable: boolean }>) => cs.filter((c) => c.actionable).map((c) => c.text);

describe("what changed", () => {
Expand Down Expand Up @@ -63,7 +63,7 @@ describe("what changed", () => {
it("while a worker runs, its own work on a pull request is not news, and people still are", () => {
// HUB-183 on bithub: the worker pushes, edits the description, posts as
// the viewer (unsigned, and its reviewer too) and waits for checks.
const running = { ...ctx, workerRunning: true };
const running = { ...ctx, workerInFlight: true };
const before = { entity: issue(), pulls: [pull({ author: "jane" }, { headAuthor: "jane" })] };
const busy = {
entity: issue(),
Expand Down Expand Up @@ -107,6 +107,74 @@ describe("what changed", () => {
});
});

describe("a worker in flight between its turns (BB-11)", () => {
const worker = (status: "running" | "finished" | "failed" | "stopped") => ({ status });

it("counts a worker in flight from spawn until it is stopped, failed or archived", () => {
expect(workerInFlight(worker("running"))).toBe(true);
// Its turn ending is a pause, not a finish: it is woken again to push.
expect(workerInFlight(worker("finished"))).toBe(true);
expect(workerInFlight(worker("failed"))).toBe(false);
expect(workerInFlight(worker("stopped"))).toBe(false);
expect(anyWorkerInFlight([worker("stopped"), worker("finished")])).toBe(true);
expect(anyWorkerInFlight([worker("stopped"), worker("failed")])).toBe(false);
expect(anyWorkerInFlight([])).toBe(false);
});

it("keeps the reviewer's marker comments for the worker, and wakes on a lane change", () => {
const marker = (round: number, lane: string) => comment({ id: `m${round}`, author: "jane", body: `<!-- bb-review round=${round} sha=abc${round} verdict=approved lane=${lane} -->\n\nLGTM.`, createdAt: `2026-10-02T0${round}:00:00Z` });
expect(reviewMarker(marker(1, "no-review").body)).toEqual({ round: 1, sha: "abc1", verdict: "approved", lane: "no-review" });
expect(reviewMarker("just a comment")).toBeNull();
// A marker is a marker only on the first line.
expect(reviewMarker("Hello\n<!-- bb-review round=1 sha=abc verdict=approved lane=no-review -->")).toBeNull();

const before = { entity: pull({ author: "jane" }), pulls: [] };
const after = { entity: pull({ author: "jane", comments: [marker(1, "no-review")] }), pulls: [] };
// In flight, the round is the worker's business.
expect(actionable(diffObserved(before, after, { ...ctx, workerInFlight: true }))).toEqual([]);
// A round that changes the lane is not.
const changed = { entity: pull({ author: "jane", comments: [marker(1, "no-review"), marker(2, "owner-reviewed")] }), pulls: [] };
expect(actionable(diffObserved(after, changed, { ...ctx, workerInFlight: true }))).toEqual(["Review lane: no-review → owner-reviewed"]);
expect(markerLaneChange(after.entity.comments, changed.entity.comments)).toEqual({ from: "no-review", to: "owner-reviewed" });
// Once no worker is in flight, the same markers are ordinary comment news.
expect(actionable(diffObserved(before, after, ctx))).toEqual(["1 new comment from jane"]);
});

it("covers the BB-11 sequence: a worker's own PR activity stays quiet until it finishes", () => {
// Worker spawns, goes idle waiting (still in flight), the reviewer posts,
// checks finish, the worker pushes; only the finish is actionable.
const linked = { linkedPulls: [{ key: "acme/web#7", url: "https://github.com/acme/web/pull/7" }] };
const before = { entity: issue({ state: "In Progress", stateType: "started", ...linked }), pulls: [pull({ author: "jane" }, { headAuthor: "jane" })] };
// Its turn ended to wait, so its status is `finished`; it is still in flight.
expect(anyWorkerInFlight([worker("finished")])).toBe(true);
const reviewed = {
entity: issue({ state: "In Progress", stateType: "started", ...linked }),
pulls: [pull({ author: "jane", comments: [comment({ id: "r1", author: "jane", body: "<!-- bb-review round=1 sha=aaaaaaa verdict=approved lane=no-review -->", createdAt: "2026-10-02T00:00:00Z" })] }, { headAuthor: "jane", checks: { state: "success", failing: [] } })],
};
expect(actionable(diffObserved(before, reviewed, { ...ctx, workerInFlight: true }))).toEqual([]);
// The worker pushes (woken again), still in flight.
const pushed = { entity: reviewed.entity, pulls: [pull({ author: "jane", comments: reviewed.pulls[0]!.comments }, { headSha: "bbbbbbb2", headAuthor: "jane", checks: { state: "success", failing: [] } })] };
expect(actionable(diffObserved(reviewed, pushed, { ...ctx, workerInFlight: true }))).toEqual([]);
// Nothing was actionable while it was in flight, so the steward is woken
// once, at the finish, with all of it as quiet notes.
const changes = diffObserved(before, pushed, { ...ctx, workerInFlight: anyWorkerInFlight([worker("stopped")]) });
expect(actionable(changes)).toEqual(["acme/web#7: Checks finished: success", "acme/web#7: 1 new comment from jane"]);
expect(changes.map((c) => c.text)).toContain("acme/web#7: Pushed bbbbbbb by jane");
});

it("compacts when the transcript is over the limit or the wake would push it over", () => {
expect(compactDue(null, 120_000, 0)).toBe(false);
expect(compactDue(90_000, 120_000, 0)).toBe(false);
expect(compactDue(121_000, 120_000, 0)).toBe(true);
// A 115k-token steward and a 30k-character wake (the wake cap) overshoot.
expect(compactDue(115_000, 120_000, 30_000)).toBe(true);
expect(compactDue(90_000, 120_000, 30_000)).toBe(false);
expect(compactDue(90_000, 120_000, 1_000)).toBe(false);
// 0 leaves compaction to the provider.
expect(compactDue(1_000_000, 0, 1_000_000)).toBe(false);
});
});

describe("waits nobody hears", () => {
const status = (blockedOn: string | null) => ({ phase: "Todo", summary: "s", nextAction: "n", actor: "other" as const, blockedOn, requeueAfterMs: null, conditions: [], resources: { workers: [], pullRequests: [], children: [] }, at: 1 });
const open = [{ id: "esc_1", bindingId: "b", kind: "decision" as const, question: "q", meanwhile: "m", route: "project" as const, recommendation: null, status: "open" as const, resolution: null, createdAt: 1, resolvedAt: null, deliveredAt: null }];
Expand Down
Loading
Loading