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
37 changes: 37 additions & 0 deletions plugins/stewards/server.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -439,6 +439,43 @@ describe("a Linear ticket steward", () => {
expect(interest.find((c) => c.pluginId === "github-watcher")?.input).toEqual({ units: ["acme/web"], entities: [], dependabot: [], deployment: [] });
});

it("retries a lost adoption wake: a binding left with no thread is woken as adopted on the next reconcile (BB-92)", async () => {
const t = await setup({ timing: { debounceMs: 1, nightlyStaggerMs: 0, configTtlMs: 0 } });
// Let the startup sweep finish before counting config reads, so the only
// reads are the ring's adoption and its first reconcile.
await t.flush();
t.entities.set("uuid-12", issue());
// The first reconcile after adoption reads the config as missing (the
// transient read behind BB-90): adoption still creates the binding, but
// the forced wake exits before the steward thread is spawned.
let projectFile = t.files[PROJECT_FILE];
let reads = 0;
Object.defineProperty(t.files, PROJECT_FILE, {
configurable: true,
get() {
reads += 1;
// Read 1 is the ring's stewardedProjects; read 2 is the forced
// adoption reconcile, which must find nothing and exit silently.
return reads === 2 ? null : projectFile;
},
set(value: string | null) {
projectFile = value;
},
});
await t.ring("linear", "uuid-12");
// Adopted, but the wake was lost: no thread at all (the project steward is
// spawned lazily with the first steward), and no wake recorded.
expect(t.spawns).toEqual([]);
expect(await t.list()).toMatchObject([{ key: "ENG-12", threadId: null }]);
expect(t.hooks.store.find("ENG-12", "p1")!.wokeAt).toBeNull();

// A plain reconcile (force null) retries the adoption wake on its own.
await t.ring("linear", "uuid-12");
expect(await t.list()).toMatchObject([{ key: "ENG-12", threadId: t.spawns[1]!.id }]);
expect(t.spawns[1]).toMatchObject({ parentThreadId: t.spawns[0]!.id, parentNotifications: "off" });
expect(t.hooks.store.find("ENG-12", "p1")!.wokeAt).not.toBeNull();
});

it("ignores unlabelled tickets, other teams, and rings from anyone but a source plugin", async () => {
const t = await setup();
t.entities.set("u1", issue({ id: "u1", key: "ENG-1", labels: [] }));
Expand Down
14 changes: 12 additions & 2 deletions plugins/stewards/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1925,7 +1925,14 @@ export function createStewardsPlugin(deps: StewardsDeps): (bb: BbPluginApi) => P
let b = store.binding(bindingId);
if (b === null) return;
const config = await loadConfig(b.projectId);
if (config === null) return;
if (config === null) {
// The first reconcile after adoption forces the wake, but a transient
// read can exit here before it; leaving the binding un-threaded for
// the next sweep to retry, which the wake-reason fallback below makes
// sure it does (BB-92).
bb.log.debug(`stewards: could not read the configuration of project ${b.projectId} while reconciling ${b.entityKey}; leaving it for the next sweep`);
return;
}
const playbook = bindingPlaybook(config, b);
if (playbook === null) {
// A dependency bot's pull request runs under deps-prs only. With the
Expand Down Expand Up @@ -1998,7 +2005,10 @@ export function createStewardsPlugin(deps: StewardsDeps): (bb: BbPluginApi) => P
const awaitingDeploy = deployTarget !== null && Object.values(deployments).some((w) => w.state === "merged" || w.state === "deploying");

const life = lifecycle(b, playbook, entity, config.file.label, { labelRequired: b.playbook !== depsPrsPlaybookName(config.file) });
let reason: WakeReason | null = force;
// A binding with no steward thread is still awaiting adoption: a first
// wake lost to a transient read is retried on the next reconcile, as the
// ops, deps and sentry paths already do (BB-92).
let reason: WakeReason | null = force ?? (b.threadId === null ? "adopted" : null);
if (life.kind === "stay-ended") {
const labelled = b.kind === "review" || b.playbook === depsPrsPlaybookName(config.file) || hasLabel(entity, config.file.label);
store.patch(b.id, { lastSnapshot: observed, ...(b.manualDetach && !labelled ? { manualDetach: false } : {}) });
Expand Down
Loading