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

0.7.283 did not boot: the flow-label dispatcher loads through import(), never require() (Bun refuses to require() a graph with a top-level await) #7436

Parked opened this
Closed without merging

steward/launch-no-tla → main 2 commits 3 threads · 3 unresolved

  • Closed without merging. Nothing was applied to main.

Review

Sign in to review this change.
2 files changed +52 −2
src/actions/issues.ts +23 −2
@@ -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,7 +81,22 @@ import {
8081 type WriteThroughError,
8182 } from "../origins/write-through.ts";
8283
outdated

The new block is inserted between the doc comment "A repo whose truth lives on an origin..." and export type MirrorError. That orphans the doc comment. Move the flowLabel loader above that comment, or below the type.

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 let flowLabel: typeof import("../crew/flow_label.ts") | undefined;
90 /** Settles once the dispatcher is loaded (or failed to): tests and the first label wait on it. */
91 export const flowLabelLoaded: Promise<void> = import("../crew/flow_label.ts").then(
92 (m) => {
93 flowLabel = m;
94 },
95 (e) => log.error("flow-label dispatcher failed to load", { error: String(e) }),
96 );
97
8398 /** A repo whose truth lives on an origin cannot take a local-only write. */
99
84100 export type MirrorError = "mirrored";
85101
86102 export function openIssue(
@@ -679,8 +695,13 @@ export function setIssueLabels(
679695 // FLOW ONLY held this assignment; the `flow` label lets it go now.
680696 // Loaded at the call: the crew's guard reaches this module through the brief,
681697 // 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);
698 if (issue.assigneeIsAgent && repo.flowOnly) {
699 if (flowLabel) flowLabel.dispatchFlowLabelled(app, repo, issue);
700 else
701 void flowLabelLoaded
702 .then(() => flowLabel?.dispatchFlowLabelled(app, repo, issue))
703 .catch((e) => log.error("flow label dispatch failed", { issue: issue.number, error: String(e) }));
704 }
684705 return ok(labelsFor(app.db, issue.id));
685706 }
686707
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 another 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");

The tests only grep the source for require() and check that the module imports. Nothing exercises setIssueLabels on a flowOnly repo with an agent assignee, which is the behaviour changed here. It needs a test that calls it and asserts the dispatch happens, both when the module has loaded and on the first-call fallback path. Without that test, deleting the dispatch would still pass.

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