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
11 changes: 7 additions & 4 deletions plugins/stewards/DESIGN.md
Original file line number Diff line number Diff line change
Expand Up @@ -459,8 +459,11 @@ Plugin code. No model turn.
`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
question or its thread is gone (a binding following through still hears
the worker, since it waits on that result). BB-329: a worker says it is
waiting with the `worker_park` tool, not with prose; a finish without that
call is a plain finish, archived like any other, whatever its final text
says. 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.
Expand All @@ -478,8 +481,8 @@ Plugin code. No model turn.
grace. A worker finish that leaves such a
binding is loud at once, without the grace, because the worker's final
message is what the steward must read; a finish that leaves an open pull
request, a pending deployment or a message that says it is waiting stays
quiet as before. The wake fires once per idle period, not once per grace: a
request, a pending deployment or a worker that parked with `worker_park`
stays quiet as before. The wake fires once per idle period, not once per grace: a
worker ending, an own pull request closing or a deployment watch changing
starts a new period, and a steward that waits on something the plugin
cannot observe is not woken every fifteen minutes. `idleInActiveStage` in
Expand Down
2 changes: 1 addition & 1 deletion plugins/stewards/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ bb. [DESIGN.md](DESIGN.md) is the design; this is how it is built and run.
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
worker turn ending parked with `worker_park` (only a question 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
Expand Down
9 changes: 9 additions & 0 deletions plugins/stewards/assessment.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,15 @@ describe("the shadow assessment: the worker state (BB-266)", () => {
expect(assess(input({ workers: [{ ...parkedWorker(), status: "failed" }] })).worker.state).toBe("failed");
expect(assess(input({ workers: [{ ...parkedWorker(), status: "stopped" }] })).worker.state).toBe("stopped");
});

// BB-329: `parked` is driven by the worker's own `worker_park` call. A
// finished worker that did not park is a plain finish, whatever its text.
it("names a finished worker that did not call worker_park `finished`, not `parked`", () => {
const plain = assess(input({ workers: [{ ...parkedWorker(), parkedWaitingOn: null, result: "Waiting on the owner's approval of acme/web#7." }] })).worker;
expect(plain).toMatchObject({ state: "finished", parked: false, running: false });
const parked = assess(input({ workers: [parkedWorker()] })).worker;
expect(parked).toMatchObject({ state: "parked", parked: true });
});
});

describe("the shadow assessment: the merge gate inputs (BB-292 #2)", () => {
Expand Down
23 changes: 15 additions & 8 deletions plugins/stewards/assessment.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,12 +41,14 @@ export type AssessedGate = PrGate & {
};

/**
* The binding's worker state. `parked` is a `finished` worker between turns:
* still in flight, not running, and the state the boolean predicates collapse
* to either "busy" (`workerInFlight`) or "not mid-turn" (`runningWorkerReason`).
* The binding's worker state. `parked` is explicit: a worker that called its
* own `worker_park` tool and finished its turn, so it is kept unarchived until
* its next turn clears the park. A `finished` worker that did not park is a
* plain finish. `inFlight` is still running-or-finished (the wake quieting and
* lifecycle answer) and `reason` is `runningWorkerReason`'s text.
*/
export type AssessedWorker = {
state: "running" | "parked" | "failed" | "stopped" | "none";
state: "running" | "parked" | "finished" | "failed" | "stopped" | "none";
inFlight: boolean;
running: boolean;
parked: boolean;
Expand Down Expand Up @@ -160,12 +162,17 @@ export function ownPullEntities(observed: Observed, own: ReadonlySet<string>): E
return [observed.entity, ...observed.pulls].filter((e) => e.pull !== null && isOwn(e, own));
}

/** The worker state, with a parked `finished` worker distinct from a running one. */
/**
* The worker state. `parked` is driven by the worker's own `worker_park` call
* (BB-329): a `finished` worker that did not park is a plain finish, whatever
* its final text says, and is named `finished` rather than `parked`.
*/
export function assessWorker(workers: readonly Worker[]): AssessedWorker {
const running = workers.some((w) => w.status === "running");
const parked = !running && workers.some((w) => w.status === "finished");
const failed = !running && !parked && workers.some((w) => w.status === "failed");
const state: AssessedWorker["state"] = running ? "running" : parked ? "parked" : workers.length === 0 ? "none" : failed ? "failed" : "stopped";
const finished = !running && workers.some((w) => w.status === "finished");
const parked = !running && workers.some((w) => w.status === "finished" && w.parkedWaitingOn !== null);
const failed = !running && !finished && workers.some((w) => w.status === "failed");
const state: AssessedWorker["state"] = running ? "running" : parked ? "parked" : workers.length === 0 ? "none" : finished ? "finished" : failed ? "failed" : "stopped";
return { state, inFlight: anyWorkerInFlight(workers), running, parked, reason: runningWorkerReason(workers) };
}

Expand Down
19 changes: 0 additions & 19 deletions plugins/stewards/characterization.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@ import { isBusy } from "./sidebar.js";
import { readyStateSchema, type Worker } from "./store.js";
import { LINEAR_TICKETS } from "./templates.js";
import { hasLiveWakeSource, pullWatchCounts, type WakeSourceInput } from "./wake-source.js";
import { workerReportedError, workerWaiting } from "./wake.js";

const tickets: Playbook = (() => {
const p = parsePlaybook(LINEAR_TICKETS, "linear-tickets");
Expand Down Expand Up @@ -189,24 +188,6 @@ describe("the worker-busy predicates: workerInFlight vs runningWorkerReason", ()
expect(["idle", "finished", "failed"].some(isBusy)).toBe(false);
});

it("pins WAITING: workerWaiting fires on waiting/awaits/awaiting/parked/standing by", () => {
expect(workerWaiting("Waiting on the reviewer.")).toBe(true);
expect(workerWaiting("It awaits the owner's approval.")).toBe(true);
expect(workerWaiting("Parked until the build lands.")).toBe(true);
expect(workerWaiting("Standing by.")).toBe(true);
expect(workerWaiting("Done and verified.")).toBe(false);
expect(workerWaiting(null)).toBe(false);
});

it("pins ERROR_REPORT: workerReportedError fires on a line-leading error marker, not a mention", () => {
expect(workerReportedError("Error: the build refused the push")).toBe(true);
expect(workerReportedError("Unable to reach GitHub")).toBe(true);
expect(workerReportedError("I could not merge it")).toBe(true);
expect(workerReportedError("Fixed the error: the retry now backs off")).toBe(false);
expect(workerReportedError("No errors here.")).toBe(false);
expect(workerReportedError(null)).toBe(false);
});

it("pins unheardWait: a wait on the project steward or the user with no open escalation or need", () => {
const status = (waitingOn: string | null) => ({ phase: "In Progress", summary: "s", nextAction: "n", actor: "other" as const, waitingOn, requeueAfterMs: null, conditions: [], resources: { workers: [], pullRequests: [], children: [] }, at: 1 });
expect(unheardWait(status("the project steward's approval of the new spec"), [])).toMatch(/project steward/u);
Expand Down
4 changes: 3 additions & 1 deletion plugins/stewards/fixtures.ts
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,8 @@ export const comment = (over: Partial<SnapshotComment> = {}): SnapshotComment =>
/**
* A worker that has parked at the end of its turn, waiting on something that
* will wake it (the build-tickets merge gate, a review round). `finished` is
* the parked status, so it is still in flight for delivery (BB-279).
* the parked status and `parkedWaitingOn` is the explicit `worker_park` call
* (BB-329), so it is still in flight for delivery (BB-279).
*/
export const parkedWorker = (over: Partial<Worker> = {}): Worker => ({
threadId: "thr_worker",
Expand All @@ -110,6 +111,7 @@ export const parkedWorker = (over: Partial<Worker> = {}): Worker => ({
endedAt: 2,
modelCheckPending: false,
stopReason: null,
parkedWaitingOn: "the review",
...over,
});

Expand Down
3 changes: 2 additions & 1 deletion plugins/stewards/migrations.snapshot.json
Original file line number Diff line number Diff line change
Expand Up @@ -133,5 +133,6 @@
"3f683f67336499cdca7460d9106a2ab9f91a74e028a6f359e4ebb29a16bb8163",
"dac7694ca870936e15df9f4c6837973e8d1191b271743b386b1db36427577937",
"8a61e3594b695ff3b5f2f58573155bd59f7209142643e4f212fe3485a4ae80f9",
"c7dcc1c8ee819162947a9965a7fb0cb7129900a4d68f5f7f91a99184a225dea9"
"c7dcc1c8ee819162947a9965a7fb0cb7129900a4d68f5f7f91a99184a225dea9",
"ad2a7b244faee5792ca77b1f36cd80488de8f787360d03f1569e60c869845beb"
]
8 changes: 7 additions & 1 deletion plugins/stewards/read-counts.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,9 @@ describe("a reconcile pass over a fixed binding set (BB-297)", () => {
t.entities.set("acme/web#8", pull({ id: "acme/web#8", key: "acme/web#8", url: "https://github.com/acme/web/pull/8", state: "open" }, { head: "bb/eng-12-retry" }));
t.hooks.store.addWorker("thr_w1", b1.id, "ENG-12: implement");
t.hooks.store.setWorker("thr_w1", "finished", "Watching acme/web#7 and acme/web#8 for the review.");
// BB-329: the parked worker is explicit (its own `worker_park` call), so
// the merge gate treats it as owning the landing order.
t.hooks.store.parkWorker("thr_w1", "the review");

// Binding 2: a deployment watch. The merged own pull request opens the
// watch and the look reads GitHub for its deployment.
Expand Down Expand Up @@ -174,7 +177,10 @@ describe("a reconcile pass over a fixed binding set (BB-297)", () => {
// pull requests (web#7, web#8, web#9), two store reads each, and
// `syncPullApproval` reads the remembered set once per pull to forget a
// requester the owner withdrew without a review.
expect(reconcile).toEqual({ storeReads: 194, sourceCalls: 12, reconciles: 4, bindings: 4 });
// BB-329 lowered them 194 → 193: the merge gate's `parkedWorkerOwnsAnother`
// now reads the parked state from the one assessment the reconcile already
// built, instead of calling `store.workers(b.id)` a second time.
expect(reconcile).toEqual({ storeReads: 193, sourceCalls: 12, reconciles: 4, bindings: 4 });
expect(wake).toEqual({ storeReads: 15, sourceCalls: 0, wakes: 1 });
});

Expand Down
Loading
Loading