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
16 changes: 16 additions & 0 deletions plugins/stewards/DESIGN.md
Original file line number Diff line number Diff line change
Expand Up @@ -339,6 +339,22 @@ Plugin code. No model turn.
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.

BB-52 narrows that to the worker's own pull request, and quiets three more
causes. A pull request is the worker's own when its head branch is one of
the binding's worker threads' branches, or a worker named its URL in its
final message; anything else — a teammate's pull request, a link the
plugin cannot tie to a worker — wakes the steward on the link ("Pull
request linked (not this ticket's worker)") and keeps its checks, pushes
and comments actionable. A state move between the playbook's `build` and
`review` stages (In Progress ↔ In Review) is the worker's own loop, a
quiet note; a move to any other stage, or a terminal state, still wakes. A
worker's turn ending is a quiet note unless its final message asks a
question, reports an error, or its thread is gone (a binding following
through still hears the worker, since it waits on that result). And a
terminal state the steward's own last report already named ends the
binding from the mechanical tier, with the wrap-up written from that
report and no wrap-up wake; a terminal state someone else set still wakes.
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 Down
12 changes: 10 additions & 2 deletions plugins/stewards/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -66,9 +66,17 @@ bb. [DESIGN.md](DESIGN.md) is the design; this is how it is built and run.
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
reason to wake; a reviewer round that changes the lane is. BB-52 scopes
that to the worker's own pull request — its head branch is one of the
binding's worker threads' branches, or a worker named its URL — and quiets
three more causes: a state move between the build and review stages, a
worker turn ending to wait (only a question, an error report or a gone
thread wakes), and a terminal state the steward's own last report already
named (the binding ends from the mechanical tier). A foreign pull request
wakes on its link and keeps its activity actionable. Everything not
actionable is kept as a quiet note and shown in "What changed" at the next
turn something else makes due.
turn something else makes due, and `bb stewards show` lists it as a pending
note.
- **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
Expand Down
78 changes: 70 additions & 8 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 { parsePlaybook, phaseOf } from "./config.js";
import { comment, issue, pull } from "./fixtures.js";
import { approvalWanted, answerDiffers, anyWorkerInFlight, asksForOpenApproval, classifyApproval, commentDiffersFromRecommendation, compactDue, diffObserved, endingDeadline, followingThrough, gateKnownUnmet, gateState, isCommentNews, lifecycle, markerLaneChange, namesUserAsBlocker, ownerApproval, prGate, resolveChecklistItem, reviewMarker, specHash, stuckDue, unheardWait, workerInFlight } from "./reconcile.js";
import { approvalWanted, answerDiffers, anyWorkerInFlight, asksForOpenApproval, classifyApproval, commentDiffersFromRecommendation, compactDue, diffObserved, endingDeadline, followingThrough, gateKnownUnmet, gateState, isCommentNews, isOwnStageMove, lifecycle, markerLaneChange, namesUserAsBlocker, ownerApproval, prGate, resolveChecklistItem, reviewMarker, specHash, stuckDue, unheardWait, workerInFlight, workerReportedTerminal } from "./reconcile.js";
import { readyStateSchema } from "./store.js";
import { GITHUB_REVIEWS, LINEAR_TICKETS } from "./templates.js";

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, workerInFlight: true };
const running = { ...ctx, workerInFlight: true, ownPulls: new Set(["acme/web#7"]) };
const before = { entity: issue(), pulls: [pull({ author: "jane" }, { headAuthor: "jane" })] };
const busy = {
entity: issue(),
Expand Down Expand Up @@ -107,6 +107,68 @@ describe("what changed", () => {
});
});

describe("the worker's own pull requests and state moves (BB-52)", () => {
const stageOf = (state: string) => phaseOf(tickets, state)?.stage ?? null;
const linked = { linkedPulls: [{ key: "acme/web#7", url: "https://github.com/acme/web/pull/7" }] };
const running = { ...ctx, workerInFlight: true, stageOf };
const ownPulls = new Set(["acme/web#7"]);

it("quiets the worker's own pull request activity, and treats an unknown pull request as foreign", () => {
const before = { entity: issue({ ...linked }), pulls: [pull({ author: "jane" }, { headAuthor: "jane" })] };
const busy = { entity: issue({ ...linked }), pulls: [pull({ author: "jane", comments: [comment({ id: "r1", author: "jane" })] }, { headSha: "bbbbbbb2", headAuthor: "jane", checks: { state: "success", failing: [] } })] };
expect(actionable(diffObserved(before, busy, { ...running, ownPulls }))).toEqual([]);
// Ownership the plugin cannot establish is foreign: the same activity wakes.
expect(actionable(diffObserved(before, busy, { ...running, ownPulls: new Set() }))).toEqual(["acme/web#7: Checks finished: success", "acme/web#7: 1 new comment from jane"]);
});

it("wakes for a foreign pull request linked while a worker is in flight, and keeps its activity actionable", () => {
const before = { entity: issue({ state: "In Progress", stateType: "started" }), pulls: [] };
const after = { entity: issue({ state: "In Progress", stateType: "started", ...linked }), pulls: [pull({ author: "sam" }, { headAuthor: "sam" })] };
const foreign = actionable(diffObserved(before, after, { ...running, ownPulls: new Set() }));
expect(foreign).toContain("Pull request linked (not this ticket's worker): acme/web#7");
expect(foreign).toContain("acme/web#7: now followed (open)");
// The worker's own link is a quiet note, as the BB-17 quieting always was.
expect(actionable(diffObserved(before, after, { ...running, ownPulls }))).toEqual([]);
});

it("quiets a build/review state move while a worker is in flight, and wakes for any other", () => {
const before = { entity: issue({ state: "In Progress", stateType: "started" }), pulls: [] };
const review = { entity: issue({ state: "In Review", stateType: "started" }), pulls: [] };
expect(actionable(diffObserved(before, review, running))).toEqual([]);
expect(actionable(diffObserved(review, before, running))).toEqual([]);
// A move outside the build/review pair wakes: a non-owner move to another stage.
const backlog = { entity: issue({ state: "Backlog", stateType: "backlog" }), pulls: [] };
expect(actionable(diffObserved(before, backlog, running))).toEqual(["State: In Progress → Backlog"]);
// With no worker in flight the same build/review move wakes.
expect(actionable(diffObserved(before, review, ctx))).toEqual(["State: In Progress → In Review"]);
});

it("names the build/review move, so the server can hand the playbook's stages in", () => {
expect(isOwnStageMove(stageOf, "In Progress", "In Review")).toBe(true);
expect(isOwnStageMove(stageOf, "In Review", "In Progress")).toBe(true);
expect(isOwnStageMove(stageOf, "In Progress", "Backlog")).toBe(false);
expect(isOwnStageMove(stageOf, "Todo", "In Progress")).toBe(false);
expect(isOwnStageMove(undefined, "In Progress", "In Review")).toBe(false);
});

it("keeps a linked pull request quiet when no worker is in flight, as before", () => {
const before = { entity: issue({ state: "In Progress", stateType: "started" }), pulls: [] };
const after = { entity: issue({ state: "In Progress", stateType: "started", ...linked }), pulls: [pull({ author: "sam" }, { headAuthor: "sam" })] };
expect(actionable(diffObserved(before, after, { ...ctx, stageOf }))).toEqual([]);
});

it("reads a worker's final message that moved the entity to a terminal state", () => {
expect(workerReportedTerminal("Merged acme/web#7 and set ENG-12 to Done.", "ENG-12", tickets)).toBe(true);
expect(workerReportedTerminal("Set ENG-12 to Done", "ENG-12", tickets)).toBe(true);
expect(workerReportedTerminal("ENG-12: Done", "ENG-12", tickets)).toBe(true);
expect(workerReportedTerminal("ENG-12 is still In Review.", "ENG-12", tickets)).toBe(false);
// A prediction is not a report that the state was set.
expect(workerReportedTerminal("ENG-12 should be Done once the rollout lands.", "ENG-12", tickets)).toBe(false);
expect(workerReportedTerminal("Done for OPS-9.", "ENG-12", tickets)).toBe(false);
expect(workerReportedTerminal(null, "ENG-12", tickets)).toBe(false);
});
});

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

Expand All @@ -131,10 +193,10 @@ describe("a worker in flight between its turns (BB-11)", () => {
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([]);
expect(actionable(diffObserved(before, after, { ...ctx, workerInFlight: true, ownPulls: new Set(["acme/web#7"]) }))).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(actionable(diffObserved(after, changed, { ...ctx, workerInFlight: true, ownPulls: new Set(["acme/web#7"]) }))).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"]);
Expand All @@ -151,13 +213,13 @@ describe("a worker in flight between its turns (BB-11)", () => {
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([]);
expect(actionable(diffObserved(before, reviewed, { ...ctx, workerInFlight: true, ownPulls: new Set(["acme/web#7"]) }))).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([]);
expect(actionable(diffObserved(reviewed, pushed, { ...ctx, workerInFlight: true, ownPulls: new Set(["acme/web#7"]) }))).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")]) });
const changes = diffObserved(before, pushed, { ...ctx, workerInFlight: anyWorkerInFlight([worker("stopped")]), ownPulls: new Set(["acme/web#7"]) });
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");
});
Expand Down
Loading
Loading