From 478c90001568240c44fc8c9da24909ac746cd34d Mon Sep 17 00:00:00 2001 From: Dylan Trotter Date: Tue, 27 Oct 2026 19:38:28 +0000 Subject: [PATCH] stewards: retry a lost adoption wake for an unthreaded binding (BB-92) --- plugins/stewards/server.test.ts | 37 +++++++++++++++++++++++++++++++++ plugins/stewards/server.ts | 14 +++++++++++-- 2 files changed, 49 insertions(+), 2 deletions(-) diff --git a/plugins/stewards/server.test.ts b/plugins/stewards/server.test.ts index b2a626cb..ea562b99 100644 --- a/plugins/stewards/server.test.ts +++ b/plugins/stewards/server.test.ts @@ -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: [] })); diff --git a/plugins/stewards/server.ts b/plugins/stewards/server.ts index ac0c1123..8e0cc4e3 100644 --- a/plugins/stewards/server.ts +++ b/plugins/stewards/server.ts @@ -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 @@ -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 } : {}) });