Archilyzer · Source

archilyzer

Archilyzer
git clone https://archilyzer.pages.dev/source/archilyzer.git
Log | Files | Refs | README | LICENSE

commit 9f48ffffe8965b7eea833c0c1de0d262dcbadb4a
parent 61dc6263cafccb61bd17bc07cb1d5ee8fcd813b9
Author: I Mean I'm Just Saying <imeanimjustsaying@kiwifarms.st>
Date:   Wed, 14 Oct 2026 04:03:45 -0400

Merge r28/integration: release 28 smoke fix — a decision continues an auto research run

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>

Diffstat:
Mcommon/controller/researchAutoContinue.test.ts | 38++++++++++++++++++++++++++++++++++++++
Mcommon/controller/researchAutoContinue.ts | 15++++++++++++++-
Mcommon/controller/researchRuns.ts | 32+++++++++++++++++++++++++++++++-
3 files changed, 83 insertions(+), 2 deletions(-)

diff --git a/common/controller/researchAutoContinue.test.ts b/common/controller/researchAutoContinue.test.ts @@ -26,6 +26,7 @@ import { researchAutoContinueTick, UNBUILT_CHECK, } from "./researchAutoContinue"; +import { approveResearch } from "./researchRuns"; let tmp: string; let paths: Paths; @@ -198,6 +199,43 @@ test("the heartbeat and job ends racing continue once; a claim held elsewhere is assert.equal((await sweepsOf("synth-auto-stale", stale)).length, 1); }); +test("the operator's last decision settles an auto run, and it continues by itself — no job has to end (release 28 smoke)", async () => { + const article = "synth-auto-decided"; + const n = await makeRun(article, { + channels: ["synth-kitchen"], + proposals: [ + prop("p01", "import-video", { slug: "synth-kitchen", url: "https://video.example/v/5" }, "done", { doneAt: "2026-10-13T10:00:00.000Z" }), + prop("p02", "import-video", { slug: "synth-kitchen", url: "https://video.example/v/6" }, "proposed", { note: "past the run's caps" }), + ], + }); + assert.ok(armResearchAutoContinue(deps(), { bootScan: false, env: {} })); + const r = await approveResearch({ article, iteration: n, ids: ["p02"], approve: false, note: "too large" }, { paths, editor: {} as never }); + assert.ok(r.ok); + assert.equal(r.view.phase, "ready"); + const rec = await until(async () => { + const x = await recOf(article, n); + return x.autoContinue?.status === "continued" ? x : null; + }, "the continuation"); + const sweeps = await sweepsOf(article, n); + assert.equal(sweeps.length, 1); + assert.deepEqual(rec.continuedBy, [sweeps[0]!.n]); + await ended(sweeps[0]!.jobId!); + // A decision that leaves the run waiting fires nothing. + const other = "synth-auto-still-waiting"; + const m = await makeRun(other, { + channels: ["synth-kitchen"], + proposals: [ + prop("p01", "import-video", { slug: "synth-kitchen", url: "https://video.example/v/7" }, "proposed"), + prop("p02", "import-video", { slug: "synth-kitchen", url: "https://video.example/v/8" }, "proposed"), + ], + }); + const w = await approveResearch({ article: other, iteration: m, ids: ["p01"], approve: false }, { paths, editor: {} as never }); + assert.ok(w.ok); + assert.equal(w.view.phase, "wait"); + await new Promise((res) => setTimeout(res, 100)); + assert.equal((await sweepsOf(other, m)).length, 0); +}); + test("propose and limits never continue by themselves; a proposal waiting for approval holds an auto run", async () => { for (const autonomy of ["propose", "limits"] as const) { const article = `synth-auto-${autonomy}`; diff --git a/common/controller/researchAutoContinue.ts b/common/controller/researchAutoContinue.ts @@ -62,7 +62,7 @@ import { listCorpusBuilds } from "../lib/report/draft/tasks/corpusSource"; import { readResearchState, widenedChannels, type AutoContinueRecord, type ResearchRecord } from "../lib/report/draft/research/state"; import { dailyCapRefusal, dayUsage, utcDay } from "./generationUsage"; import { enqueueReportDraft, REPORT_DRAFT_JOB_KIND, type ReportDraftDeps } from "./reportDraft"; -import { markContinued, researchState, takeWatchedRun } from "./researchRuns"; +import { markContinued, onResearchSettled, researchState, takeWatchedRun } from "./researchRuns"; export const CLAIM_STALE_MS = 10 * 60_000; @@ -334,6 +334,19 @@ export function armResearchAutoContinue(deps: ReportDraftDeps, o: { log?: (line: void scanAutoContinue(state.deps, state.log).catch(() => {}); } }); + // The operator's last decision on a run's proposals (approve-research): the + // run may be ready with no job left to end. + const offJobs = state.off; + const offSettled = onResearchSettled((article, n) => { + void maybeAutoContinue(article, n, state.deps).then( + (r) => report(article, n, r, null, state.log), + (e) => state.log?.(`research auto-continue: ${article} i${n}: ${(e as Error).message}`), + ); + }); + state.off = () => { + offJobs(); + offSettled(); + }; globalThis.__yttResearchAutoContinue__ = state; if (o.bootScan !== false) void scanAutoContinue(deps, o.log).catch(() => {}); return true; diff --git a/common/controller/researchRuns.ts b/common/controller/researchRuns.ts @@ -203,6 +203,25 @@ export function parseResearchApproveBody(b: Record<string, unknown>): ResearchAp export type ResearchOutcome = { id: string; status?: Proposal["status"]; jobId?: string; note?: string; error?: string }; +// SETTLED: the operator's decisions left a run with nothing to wait for. The +// auto-continue (./researchAutoContinue.ts) listens: a decision is the trigger +// a job's end is for an acquisition, and nothing else would notice it while +// the heartbeat is off. On globalThis, as onJobEnd's listeners are, so every +// copy of this module the server bundles shares one set. +type SettledListener = (article: string, n: number) => void; +declare global { + // eslint-disable-next-line no-var + var __yttResearchSettled__: Set<SettledListener> | undefined; +} +const settledListeners = (): Set<SettledListener> => (globalThis.__yttResearchSettled__ ??= new Set()); + +export function onResearchSettled(l: SettledListener): () => void { + settledListeners().add(l); + return () => { + settledListeners().delete(l); + }; +} + // The operator's yes or no on a research run's proposals (no ids: its state). export async function approveResearch( raw: Record<string, unknown>, @@ -216,7 +235,7 @@ export async function approveResearch( } const jobOf = deps.jobOf ?? jobOfPaths(deps.paths); try { - return await serial(`${body.article}/${body.iteration}`, async () => { + const res = await serial(`${body.article}/${body.iteration}`, async () => { const { it, state } = await readRun(body.article, body.iteration, deps.paths); if (body.ids.length && (it.status === "queued" || it.status === "running")) { throw new ResearchInputError(`"${body.article}" i${it.n} is ${it.status}: its proposals are the run's until it ends`); @@ -238,6 +257,17 @@ export async function approveResearch( const now = (await readIteration(body.article, it.n, deps.paths)) ?? it; return { ok: true as const, view: viewOf(body.article, now, state, phase), outcomes }; }); + // Outside the run's lock: a listener may take it. + if (body.ids.length && res.view.phase === "ready") { + for (const l of settledListeners()) { + try { + l(body.article, body.iteration); + } catch { + // a listener's failure is its own + } + } + } + return res; } catch (e) { return { ok: false, error: (e as Error).message }; }