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
torque/forge:torque/7462-p0-releases-are-held-land-the-import-boo → main 3 commits fork 3 threads · 3 unresolved
3 files
changed +109
−6
src/actions/issues.ts +34 −5
| @@ -66,6 +66,7 @@ import { | ||
| 66 | 66 | importComments, |
| 67 | 67 | importIssue, |
| 68 | 68 | } from "../origins/import.ts"; |
| 69 | import { createLog } from "../kernel/log.ts"; | |
| 69 | 70 | import { err, ok, type Result } from "../kernel/result.ts"; |
| 70 | 71 | import { inheritPillar } from "./pillars.ts"; |
| 71 | 72 | import { |
| @@ -80,6 +81,29 @@ import { | ||
| 80 | 81 | type WriteThroughError, |
| 81 | 82 | } from "../origins/write-through.ts"; |
| 82 | 83 | |
| 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) => { | |
| 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 | ||
| 83 | 107 | /** A repo whose truth lives on an origin cannot take a local-only write. */ |
| 84 | 108 | export type MirrorError = "mirrored"; |
| 85 | 109 | |
| @@ -676,11 +700,16 @@ export function setIssueLabels( | ||
| 676 | 700 | actorId: writer.value.id, |
| 677 | 701 | payload: { number: issue.number, labels: resolved.map((l) => l.name) }, |
| 678 | 702 | }); |
| 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 | } | |
| 684 | 713 | return ok(labelsFor(app.db, issue.id)); |
| 685 | 714 | } |
| 686 | 715 |
test/flow-only-dispatch.test.ts +46 −1
| @@ -9,7 +9,8 @@ import { tmpdir } from "node:os"; | ||
| 9 | 9 | import { join } from "node:path"; |
| 10 | 10 | import { createApp, type App } from "../src/app.ts"; |
| 11 | 11 | 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"; | |
| 13 | 14 | import { createRepo, updateRepoSettings } from "../src/actions/repos.ts"; |
| 14 | 15 | import { getAgent } from "../src/core/agents.ts"; |
| 15 | 16 | import { getLabel, setIssueLabels, type Issue } from "../src/core/issues.ts"; |
| @@ -148,4 +149,48 @@ describe("flow only at the dispatcher", () => { | ||
| 148 | 149 | const after = await (await fetch(`${servers.url}/alice/svc/issues/${held.number}`, { headers: { cookie: `forge_session=${createSession(app.db, alice.id).token}` } })).text(); |
| 149 | 150 | expect(after).not.toContain('id="flow-only-queued"'); |
| 150 | 151 | }); |
| 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 | }); | |
| 151 | 196 | }); |
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 | }); |
new above
offline
Remove this added blank line: it separates the
/** A repo whose truth lives on an origin ... */doc comment fromexport type MirrorError, leaving the comment dangling.