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
34 changes: 25 additions & 9 deletions plugins/stewards/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -117,14 +117,24 @@ bb. [DESIGN.md](DESIGN.md) is the design; this is how it is built and run.
or lets it start (guidance + resolve, not asked again until a new overlap
appears). A hold placed `behind` lifts itself once every binding named
has merged its pull requests or ended: the held steward is woken with a
note to rebase, and the project steward is told. A binding reaching a
terminal state, or detached, releases what waits behind it as its ending
begins, so a steward that follows through for hours holds nobody up. A
hold that would form a cycle is refused. Work whose pull requests have all
merged no longer counts as in flight; a ticket whose gate has passed with
nothing holding or scheduling it counts as in flight already, so two
tickets going ready in the same minute schedule against each other rather
than racing to In Progress. `bb stewards show` prints
note to rebase. The project steward is told only when the work waited on
is not finished — its ticket not terminal and its steward not reporting
`steward_report { noMorePulls: true }` after every linked pull request
merged; a finished-work lift is a note on the held binding and the
project steward's next digest, and starts no turn. When one lift frees
two waiters that overlap each other, the first by priority then age is
released and the rest are held behind it. A binding reaching a terminal
state, or detached, releases what waits behind it as its ending begins,
so a steward that follows through for hours holds nobody up. A hold that
would form a cycle is refused. Work whose pull requests have all merged
and whose steward reported no more are coming no longer counts as in
flight; merged with no such report is still at work, because the next
pull request would conflict. Before filing a request the plugin re-reads
the conflicting bindings' pull requests from GitHub, and a ticket past
its ready gate that links a new pull request re-runs the check. A ticket
whose gate has passed with nothing holding or scheduling it counts as in
flight already, so two tickets going ready in the same minute schedule
against each other rather than racing to In Progress. `bb stewards show` prints
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
Expand Down Expand Up @@ -218,7 +228,13 @@ bb. [DESIGN.md](DESIGN.md) is the design; this is how it is built and run.
the approver declines is not made again until the spec changes, and while
one is open the steward is told not to ask the user again: the request is
on the Stewards page, and a report that asks anyway shows as a playbook
violation in `bb stewards show`. When the entity changes while one of its
violation in `bb stewards show`. The project file's optional
`standingRules` list is shown in the approval wake, so the project
steward adds only the limits a change needs, in at most three points,
instead of restating rules that already bind every pull request. A
decline's objections are carried to the ticket steward as a checklist;
the same objection declined twice is forwarded to the user rather than a
third round. When the entity changes while one of its
escalations is with you, the project steward is woken with the change too,
since you may have answered on the ticket rather than in its thread. A
status blocked on the project steward or the user with no open
Expand Down
11 changes: 11 additions & 0 deletions plugins/stewards/config.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,17 @@ describe("the project file", () => {
expect(badDuration).toMatchObject({ ok: false });
if (!badDuration.ok) expect(badDuration.error).toMatch(/deps\.sla\.high/u);
});

it("takes the standing-rules list, and rejects an unknown key (BB-54)", () => {
const defaults = parseProjectFile(JSON.stringify({ version: 1 }));
if (!defaults.ok) throw new Error(defaults.error);
expect(defaults.value.standingRules).toEqual([]);
const withRules = parseProjectFile(JSON.stringify({ version: 1, standingRules: ["Migrations are append-only.", "No secrets in logs."] }));
if (!withRules.ok) throw new Error(withRules.error);
expect(withRules.value.standingRules).toEqual(["Migrations are append-only.", "No secrets in logs."]);
expect(parseProjectFile(JSON.stringify({ version: 1, standingRule: ["typo"] }))).toMatchObject({ ok: false });
expect(parseProjectFile(JSON.stringify({ version: 1, standingRules: [""] }))).toMatchObject({ ok: false });
});
});

describe("ops in the project file", () => {
Expand Down
6 changes: 6 additions & 0 deletions plugins/stewards/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -250,6 +250,12 @@ export const projectFileSchema = z
* stewards and the project steward, from the project's own guidance.
*/
bigDecisions: z.array(decideEntrySchema).max(60).default(() => defaultDecideList()),
/**
* The limits that already bind every pull request in this project, shown
* in an approval wake so the project steward adds only what they do not
* cover. Short rule lines; the plugin hard-codes none.
*/
standingRules: z.array(z.string().trim().min(1).max(400)).max(40).default([]),
/**
* Production to watch: one ops binding per target, which files a Linear
* ticket for each problem it finds and escalates it to the project
Expand Down
8 changes: 6 additions & 2 deletions plugins/stewards/schedule.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,19 +40,23 @@ describe("conflicts", () => {
const held = s.patch(bind("ENG-13", { touches: ["web/src"] }).id, { hold: "Later." });
bind("ENG-14", { stage: "spec", touches: ["web/src"] });
bind("ENG-15", { touches: ["api"] });
const landed = s.patch(bind("ENG-16", { touches: ["web/src"] }).id, { lastSnapshot: { entity: issue({ linkedPulls: [{ key: "acme/web#7", url: "u" }] }), pulls: [pull({ state: "merged" }, { merged: true })] } });
const landed = s.patch(bind("ENG-16", { touches: ["web/src"] }).id, { noMorePulls: true, lastSnapshot: { entity: issue({ linkedPulls: [{ key: "acme/web#7", url: "u" }] }), pulls: [pull({ state: "merged" }, { merged: true })] } });
// Merged but not reported finished: a next pull request may still come, so it is still at work (BB-54).
const landedNoReport = s.patch(bind("ENG-21", { touches: ["web/src"] }).id, { lastSnapshot: { entity: issue({ linkedPulls: [{ key: "acme/web#8", url: "u" }] }), pulls: [pull({ state: "merged" }, { merged: true })] } });
const child = bind("ENG-17", { touches: ["web/src"], parent: me.id });
bind("ENG-18", { touches: ["web/src"], project: "p2" });
const ended = s.patch(bind("ENG-19", { touches: ["web/src"] }).id, { endedAt: T, endReason: "terminal" });
expect(atWork(held)).toBe(false);
expect(atWork(landed)).toBe(false);
expect(atWork(landedNoReport)).toBe(true);
expect(atWork(ended)).toBe(false);
expect(atWork(child)).toBe(true);
expect(conflictsOf(me, s.open()).map((c) => [c.with.entityKey, c.on])).toEqual([
["ENG-11", ["web/src/login"]],
["ENG-12", ["web/src/signup"]],
["ENG-21", ["web/src"]],
]);
expect(conflictsOf(building, s.open()).map((c) => c.with.entityKey)).toEqual(["ENG-17"]);
expect(conflictsOf(building, s.open()).map((c) => c.with.entityKey)).toEqual(["ENG-21", "ENG-17"]);
expect(conflictsOf(s.patch(me.id, { touches: [] }), s.open())).toEqual([]);
});

Expand Down
48 changes: 38 additions & 10 deletions plugins/stewards/schedule.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,39 +35,67 @@ export function touchesOverlap(a: readonly string[], b: readonly string[]): stri
return [...hits].sort();
}

/**
* Whether a binding's work is finished: every pull request it links has
* merged, and either the entity reached a terminal state or its steward
* reported no more are coming. A merged pull request is the whole work for a
* `pr` binding. Unreported means not finished, so the project steward is
* woken rather than a hold lifting silently.
*/
export function finished(b: Binding, observed: Observed): boolean {
if (!allPullsMerged(b, observed)) return false;
if (b.kind === "pr") return true;
return b.endedAt !== null || b.ending === "terminal" || b.noMorePulls === true;
}

/** What a caller knows beyond the binding's last snapshot: whether a worker is still running. */
export type AtWorkOptions = { runningWorker?: boolean };

/**
* Whether a binding is at work on its touches: being built or reviewed, or
* cleared to start (its gate passed, nothing holds or schedules it: the
* steward is moving it and starting a worker, and Linear's state reaches the
* plugin a look later); not held, not ending, not ended, and its pull
* requests not all merged yet (work that has landed is what the next ticket
* rebases onto, not a conflict).
* plugin a look later); not held, not ending, not ended, and not finished
* with no worker still running. A ticket whose pull requests have merged but
* whose steward has not reported that no more are coming is still at work:
* the next pull request is a conflict, not a rebase.
*/
export const atWork = (b: Binding): boolean =>
export const atWork = (b: Binding, opts: AtWorkOptions = {}): boolean =>
b.endedAt === null &&
b.ending === null &&
b.hold === null &&
(b.stage === "build" || b.stage === "review" || b.clearedToStart) &&
b.touches.length > 0 &&
!(b.lastSnapshot !== null && allPullsMerged(b, b.lastSnapshot));
!(b.lastSnapshot !== null && finished(b, b.lastSnapshot) && opts.runningWorker !== true);

export type Conflict = { with: Binding; on: string[] };

/**
* The open bindings of the same project already at work on what `b` touches,
* oldest first. `b` itself, its ancestors and descendants are left out: a
* promoted sub-issue shares its parent's paths by design.
* The open bindings of the same project whose touches overlap `b`'s, oldest
* first, without judging whether they are at work. `b` itself, its ancestors
* and descendants are left out: a promoted sub-issue shares its parent's
* paths by design. The server filters these with a fresh GitHub read before
* filing a schedule request.
*/
export function conflictsOf(b: Binding, open: readonly Binding[]): Conflict[] {
export function overlapping(b: Binding, open: readonly Binding[]): Conflict[] {
if (b.touches.length === 0) return [];
const related = (other: Binding) => other.id === b.id || other.parentBindingId === b.id || b.parentBindingId === other.id;
return open
.filter((other) => other.projectId === b.projectId && !related(other) && atWork(other))
.filter((other) => other.projectId === b.projectId && !related(other))
.map((other) => ({ with: other, on: touchesOverlap(b.touches, other.touches) }))
.filter((c) => c.on.length > 0)
.sort((x, y) => x.with.createdAt - y.with.createdAt);
}

/**
* The open bindings of the same project already at work on what `b` touches,
* oldest first, judged from the last snapshot alone. Rendering and tests use
* this; the schedule request path re-reads GitHub first (BB-54).
*/
export function conflictsOf(b: Binding, open: readonly Binding[]): Conflict[] {
return overlapping(b, open).filter((c) => atWork(c.with));
}

/**
* Whether a binding's pull requests have all merged: at least one is
* observed, and every one is merged. A ticket with no pull request yet is not
Expand Down
Loading
Loading