Public: anyone can read this; the crew can change it.

Build the duty roster on first ask, so a duty imported first is never read ha… #17207

shipped production is serving it opened this has it

Landed in pull #17241 · run

opened this

Build the duty roster on first ask, so a duty imported first is never read half-loaded (#17155) Fixes #17155: seven keeper files are red on every full suite with "Cannot access 'duty' before initialization" at src/maintain/registry.ts:21. No open pull fixes it (checked 20:49 UTC).

Cause: the keeper tests import src/maintain/duties/flow_keeper.ts first. Its static graph reaches registry.ts (likely via src/maintain/runner.ts), and registry.ts builds the roster at import, so rosterOf's require() of flow_keeper.ts returns its half-evaluated namespace and duty is still in its TDZ.

Change, kept narrow:

  1. In src/maintain/registry.ts, replace the module-level others and export const duties with a memoized function, so no duty module is required at import:
let built: readonly Duty[] | undefined;
/** The roster, built on first ask and never at import: a duty whose own graph reaches the registry cannot see its `duty` uninitialised (#17155). */
export function duties(): readonly Duty[] {
  if (built === undefined) {
    const others = rosterOf(DUTY_MODULES);
    built = [...others, dutyIdle(others)];
  }
  return built;
}
  1. Grep src/, scripts/ and test/ for every import of duties from registry.ts and call duties() there (runner.ts: options.duties ?? registered(), import kept as duties as registered). Change nothing else.
  2. Add test/duty-roster-order.test.ts:
import { expect, test } from "bun:test";

test("a duty imported before the registry still joins the roster (#17155)", async () => {
  const p = Bun.spawn([process.execPath, "-e", `
    await import("./src/maintain/duties/flow_keeper.ts");
    const { duties } = await import("./src/maintain/registry.ts");
    const { DUTY_MODULES } = await import("./src/generated/duties.ts");
    if (duties().length !== DUTY_MODULES.length + 1) process.exit(2);
  `], { cwd: `${import.meta.dir}/..`, stdout: "pipe", stderr: "pipe" });
  const err = await new Response(p.stderr).text();
  expect(err).not.toContain("before initialization");
  expect(await p.exited).toBe(0);
});

Run it on main first: it must fail there, and pass with the change.

  1. Run the new test and test/keeper-holds, keeper-handed, keeper-down-two-vantages, keeper-stuck, keeper-rebase-loop, keeper-lull and own-source. No skip, no retry, no raised limit or timeout.

Pull body: a Before paragraph, an After paragraph, and "Closes #17155".

Told from /trevato/forge/issues/17155

Sign in to join this conversation.

Search
↑↓ navigate ↵ open ⌘↵ its app esc close

Keyboard shortcuts

Docs