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

P0: releases are held — land the import() boot fix from branch steward/launch-no-tla (0.7.283 failed its boot proof) #7468

Parked opened this in answer to
Closed without merging

torque/forge:torque/7462-p0-releases-are-held-land-the-import-boo → main 3 commits fork 3 threads · 3 unresolved

  • Closed without merging. Nothing was applied to main.

Review

Sign in to review this change.
3 files changed +109 −6
src/actions/issues.ts +34 −5
@@ -66,6 +66,7 @@ import {
6666 importComments,
6767 importIssue,
6868 } from "../origins/import.ts";
69 import { createLog } from "../kernel/log.ts";
6970 import { err, ok, type Result } from "../kernel/result.ts";
7071 import { inheritPillar } from "./pillars.ts";
7172 import {
@@ -80,6 +81,29 @@ import {
8081 type WriteThroughError,
8182 } from "../origins/write-through.ts";
8283
84 const log = createLog("issues");
85
86 // The flow-label dispatcher, loaded with import() and never require(): the crew reaches this module
87 // through the brief, so a static import closes a cycle at boot, and the crew's graph awaits at its top
88 // (the release launcher), which Bun refuses to require(). 0.7.283 failed to boot on real data that way.
89 /**
90 * The dispatcher as loaded so far: `mod` once `ready` settles, undefined before or when the load failed.
91 * Mutable so a test can hold it back or fail it.
92 */
93 export const flowLabelDispatcher: {
94 mod?: typeof import("../crew/flow_label.ts") | undefined;
95 ready: Promise<void>;
96 } = {
97 ready: import("../crew/flow_label.ts").then(
98 (m) => {
outdated

Remove this added blank line: it separates the /** A repo whose truth lives on an origin ... */ doc comment from export type MirrorError, leaving the comment dangling.

99 flowLabelDispatcher.mod = m;
100 },
101 (e) => log.error("flow-label dispatcher failed to load", { error: String(e) }),
102 ),
103 };
104 /** Settles once the dispatcher is loaded (or failed to): tests and the first label wait on it. */
105 export const flowLabelLoaded: Promise<void> = flowLabelDispatcher.ready;
106
83107 /** A repo whose truth lives on an origin cannot take a local-only write. */
84108 export type MirrorError = "mirrored";
85109
@@ -676,11 +700,16 @@ export function setIssueLabels(
676700 actorId: writer.value.id,
677701 payload: { number: issue.number, labels: resolved.map((l) => l.name) },
678702 });
679 // FLOW ONLY held this assignment; the `flow` label lets it go now.
680 // Loaded at the call: the crew's guard reaches this module through the brief,
681 // so a static import of the dispatcher would close a cycle at boot.
682 if (issue.assigneeIsAgent && repo.flowOnly)
683 (require("../crew/flow_label.ts") as typeof import("../crew/flow_label.ts")).dispatchFlowLabelled(app, repo, issue);
703 // FLOW ONLY held this assignment; the `flow` label lets it go now: at once when the
704 // dispatcher has loaded, else when it settles, logging a failure rather than throwing it.
705 if (issue.assigneeIsAgent && repo.flowOnly) {
706 const d = flowLabelDispatcher;
707 if (d.mod) d.mod.dispatchFlowLabelled(app, repo, issue);
708 else
709 void d.ready
710 .then(() => d.mod?.dispatchFlowLabelled(app, repo, issue))
711 .catch((e) => log.error("flow label dispatch failed", { issue: issue.number, error: String(e) }));
712 }
684713 return ok(labelsFor(app.db, issue.id));
685714 }
686715
test/flow-only-dispatch.test.ts +46 −1
@@ -9,7 +9,8 @@ import { tmpdir } from "node:os";
99 import { join } from "node:path";
1010 import { createApp, type App } from "../src/app.ts";
1111 import { addToCrew, createAgent } from "../src/actions/crew.ts";
12 import { assignIssue, openIssue, setIssueLabels as labelIssue } from "../src/actions/issues.ts";
12 import { assignIssue, flowLabelDispatcher, openIssue, setIssueLabels as labelIssue } from "../src/actions/issues.ts";
13 import { recentErrors } from "../src/kernel/log.ts";
1314 import { createRepo, updateRepoSettings } from "../src/actions/repos.ts";
1415 import { getAgent } from "../src/core/agents.ts";
1516 import { getLabel, setIssueLabels, type Issue } from "../src/core/issues.ts";
@@ -148,4 +149,48 @@ describe("flow only at the dispatcher", () => {
148149 const after = await (await fetch(`${servers.url}/alice/svc/issues/${held.number}`, { headers: { cookie: `forge_session=${createSession(app.db, alice.id).token}` } })).text();
149150 expect(after).not.toContain('id="flow-only-queued"');
150151 });
152
153 test("a flow label set before the dispatcher has loaded dispatches once it settles", async () => {
154 await flow(true);
155 const held = assign(open("Early"));
156 sweepAssigned(app);
157 expect(runsOn(held)).toBe(0);
158 const d = flowLabelDispatcher;
159 const { mod, ready } = d;
160 let settle!: () => void;
161 d.mod = undefined;
162 d.ready = new Promise<void>((r) => (settle = r));
163 try {
164 expect(labelIssue(app, alice, fresh(), held, ["flow"]).ok).toBe(true);
165 expect(runsOn(held)).toBe(0);
166 d.mod = mod;
167 settle();
168 await d.ready;
169 await Promise.resolve();
170 expect(runsOn(held)).toBe(1);
171 } finally {
172 Object.assign(d, { mod, ready });
173 }
174 });
175
176 test("a dispatcher that failed to load logs the label's dispatch failure, never throws it", async () => {
177 await flow(true);
178 const held = assign(open("Failed"));
179 sweepAssigned(app);
180 const d = flowLabelDispatcher;
181 const { mod, ready } = d;
182 d.mod = undefined;
183 d.ready = Promise.reject(new Error("dispatcher missing"));
184 try {
185 expect(labelIssue(app, alice, fresh(), held, ["flow"]).ok).toBe(true);
186 await d.ready.catch(() => {});
187 await Promise.resolve();
188 expect(runsOn(held)).toBe(0);
189 const line = recentErrors(100).latest.find((l) => l.message.includes("flow label dispatch failed"));
190 expect(line?.message).toContain("dispatcher missing");
191 expect(line?.message).toContain(`issue=${held.number}`);
192 } finally {
193 Object.assign(d, { mod, ready });
194 }
195 });
151196 });
test/launch-no-tla.test.ts added +29
@@ -0,0 +1,29 @@
1 /**
2 * 0.7.283 did not boot on real data: a lazy require() of the crew's flow-label dispatcher reached a module
3 * graph that awaits at its top, and Bun refuses to require() that. Lazy loads in src/ use import(), never require().
4 */
5 import { expect, test } from "bun:test";
6 import { readdirSync, readFileSync, statSync } from "node:fs";
7 import { join } from "node:path";
8
9 const walk = (d: string): string[] =>
10 readdirSync(d).flatMap((n) => {
11 const p = join(d, n);
12 return statSync(p).isDirectory() ? walk(p) : p.endsWith(".ts") ? [p] : [];
13 });
14
15 test("no module in src/ loads a relative path (./ or ../) with require(): a graph with a top-level await refuses it at runtime", () => {
16 const root = join(import.meta.dir, "..", "src");
17 const offenders = walk(root).filter((f) => /\brequire\(\s*["'`]\.\.?\//.test(readFileSync(f, "utf8")));
18 expect(offenders.map((f) => f.slice(root.length + 1))).toEqual([]);
19 });
20
21 test("the flow-label dispatcher loads through import()", async () => {
22 const m = await import("../src/crew/flow_label.ts");
23 expect(typeof m.dispatchFlowLabelled).toBe("function");
24 });
25
26 test("actions/issues.ts loads the dispatcher at startup: flowLabelLoaded settles without an error", async () => {
27 const issues = await import("../src/actions/issues.ts");
28 await expect(issues.flowLabelLoaded).resolves.toBeUndefined();
29 });

↑↓ navigate ↵ open ⌘↵ its app esc close

Keyboard shortcuts

Docs