toolroll 0.9.130 → 0.9.131
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +20 -0
- package/dist/agent-state.js +1 -1
- package/dist/browser/manifest.json +14 -14
- package/dist/browser/{terminal.2a682d0b91a35288271c73b7ee253e524cca0917d17fbaf6733e80b7a767a37c.js → terminal.8978c8cbb268e1006f4b0be371c2401b58078e6d9f1380f4a5c2a12da843909f.js} +1 -1
- package/dist/browser/terminal.8978c8cbb268e1006f4b0be371c2401b58078e6d9f1380f4a5c2a12da843909f.js.br +0 -0
- package/dist/browser/{terminal.2a682d0b91a35288271c73b7ee253e524cca0917d17fbaf6733e80b7a767a37c.js.gz → terminal.8978c8cbb268e1006f4b0be371c2401b58078e6d9f1380f4a5c2a12da843909f.js.gz} +0 -0
- package/dist/browser/{workspace.9bd1db81d3c897045a5d82d4804e374e41e78b1b2cfd05d37b982a4ea0d02626.js → workspace.4f5935dc80574baadf1adafd39a08c567fb1fac1323052ca355546622f9b06d2.js} +1 -1
- package/dist/browser/workspace.4f5935dc80574baadf1adafd39a08c567fb1fac1323052ca355546622f9b06d2.js.br +0 -0
- package/dist/browser/workspace.4f5935dc80574baadf1adafd39a08c567fb1fac1323052ca355546622f9b06d2.js.gz +0 -0
- package/dist/builder-restart.js +13 -4
- package/dist/builder.js +4 -1
- package/dist/central-recovery-stage.js +2 -2
- package/dist/chat-follow.js +4 -0
- package/dist/db-tuning.js +16 -0
- package/dist/discord.js +9 -3
- package/dist/dispatch.js +32 -4
- package/dist/doctor.js +30 -0
- package/dist/evidence.js +49 -3
- package/dist/exec.js +3 -0
- package/dist/git-views.js +7 -1
- package/dist/invoke.js +12 -2
- package/dist/lead-queue-runtime.js +8 -5
- package/dist/lead-status.js +3 -3
- package/dist/loop-recovery.js +40 -0
- package/dist/maintenance.js +29 -1
- package/dist/needs-you.js +2 -0
- package/dist/operate.js +376 -52
- package/dist/planner.js +4 -1
- package/dist/query-index-schema.js +10 -0
- package/dist/read-executor-worker.js +9 -7
- package/dist/read-executor.js +18 -1
- package/dist/read-worker-connection.js +7 -0
- package/dist/release-adapters.js +51 -6
- package/dist/release-cli.js +24 -11
- package/dist/release-next.js +1 -1
- package/dist/release-stops.js +71 -0
- package/dist/release-supersede.js +125 -0
- package/dist/release-supervise.js +90 -0
- package/dist/release.js +252 -40
- package/dist/runner.js +36 -1
- package/dist/scout.js +4 -1
- package/dist/serve.js +92 -6
- package/dist/shutdown-proof.js +29 -0
- package/dist/slack.js +9 -3
- package/dist/sqlite-telemetry.js +26 -14
- package/dist/statement-cache.js +137 -0
- package/dist/store.js +70 -13
- package/dist/task-status.js +1 -1
- package/dist/teams.js +9 -3
- package/dist/teardown-git.js +10 -1
- package/dist/telegram.js +4 -1
- package/dist/up-processes.js +16 -1
- package/dist/up-role-child.js +2 -0
- package/dist/wake-hub.js +15 -6
- package/dist/work-index.js +101 -44
- package/dist/work-reads.js +53 -9
- package/dist/work-snapshots.js +185 -0
- package/dist/worker-statement-cache.js +83 -0
- package/dist/workspace-revision.js +145 -21
- package/package.json +1 -1
- package/dist/browser/terminal.2a682d0b91a35288271c73b7ee253e524cca0917d17fbaf6733e80b7a767a37c.js.br +0 -0
- package/dist/browser/workspace.9bd1db81d3c897045a5d82d4804e374e41e78b1b2cfd05d37b982a4ea0d02626.js.br +0 -0
- package/dist/browser/workspace.9bd1db81d3c897045a5d82d4804e374e41e78b1b2cfd05d37b982a4ea0d02626.js.gz +0 -0
package/dist/release.js
CHANGED
|
@@ -5,6 +5,8 @@ import { dirname, join } from "node:path";
|
|
|
5
5
|
import { personProof } from "./person-proof.js";
|
|
6
6
|
import { RELEASE_CI_RUNNING_WORDS as CI_RUNNING_WORDS } from "./release-ci-hold.js";
|
|
7
7
|
import { transientFailure } from "./release-net.js";
|
|
8
|
+
import { CheckoutBusy } from "./git-views.js";
|
|
9
|
+
import { NotYetPublished } from "./release-stops.js";
|
|
8
10
|
import { changelogHas, harnessChanges, mainJournalFile, mainResumeCommand, releaseBranchFor, sameRelease, VERSION_PATTERN } from "./release-main.js";
|
|
9
11
|
export const REQUIRED_PR_CHECKS = [
|
|
10
12
|
"node 24 · ubuntu-latest",
|
|
@@ -64,15 +66,19 @@ export const RELEASE_TAG_WORKFLOW = ".github/workflows/publish.yml";
|
|
|
64
66
|
export const RELEASE_STEPS = ["gate", "approval", "check", "complete", "quiet", "deploy", "link", "ci", "merge", "tree", "tag", "publish", "homebrew", "done"];
|
|
65
67
|
export const RELEASE_LIMITS = { gate: 60, approval: 24 * 60, check: 360, quiet: 60, deploy: 30, ci: 60, publish: 45, homebrew: 45 };
|
|
66
68
|
const POLL_MS = 15_000;
|
|
69
|
+
const RELINK_TRIES = 3;
|
|
70
|
+
const RELINK_PAUSE_MS = 15_000;
|
|
67
71
|
export const INFRA_RERUNS_PER_INCIDENT = 1;
|
|
68
72
|
export const INFRA_RERUNS_PER_CANDIDATE = 2;
|
|
69
73
|
class Stop extends Error {
|
|
70
74
|
reason;
|
|
71
75
|
build;
|
|
72
|
-
|
|
76
|
+
waited;
|
|
77
|
+
constructor(reason, message, build = false, waited = null) {
|
|
73
78
|
super(message);
|
|
74
79
|
this.reason = reason;
|
|
75
80
|
this.build = build;
|
|
81
|
+
this.waited = waited;
|
|
76
82
|
}
|
|
77
83
|
}
|
|
78
84
|
class HomebrewFailed extends Error {
|
|
@@ -206,30 +212,43 @@ export async function runRelease(options, adapters) {
|
|
|
206
212
|
delete j.intents.deploy;
|
|
207
213
|
save();
|
|
208
214
|
};
|
|
209
|
-
const waitFor = async (at, what, probe) => {
|
|
215
|
+
const waitFor = async (at, what, probe, atLimit) => {
|
|
210
216
|
const deadline = adapters.now().getTime() + limits[at] * 60_000;
|
|
211
|
-
let said = false, unreachable = null;
|
|
217
|
+
let said = false, unreachable = null, busy = false;
|
|
212
218
|
for (;;) {
|
|
213
219
|
let answer;
|
|
214
220
|
try {
|
|
215
221
|
answer = await probe();
|
|
216
222
|
unreachable = null;
|
|
223
|
+
busy = false;
|
|
217
224
|
}
|
|
218
225
|
catch (error) {
|
|
219
|
-
if (
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
226
|
+
if (error instanceof CheckoutBusy) {
|
|
227
|
+
if (!busy)
|
|
228
|
+
say(" waiting for Toolroll's own git on this checkout (another of its git commands is still running)");
|
|
229
|
+
busy = true;
|
|
230
|
+
answer = null;
|
|
231
|
+
}
|
|
232
|
+
else {
|
|
233
|
+
if (!transientNetworkError(error))
|
|
234
|
+
throw error;
|
|
235
|
+
if (unreachable === null)
|
|
236
|
+
say(` GitHub didn't answer in time (${networkWords(error)}); asking again`);
|
|
237
|
+
unreachable = networkWords(error);
|
|
238
|
+
answer = null;
|
|
239
|
+
}
|
|
225
240
|
}
|
|
226
241
|
if (answer !== null) {
|
|
227
242
|
if (said && journal !== null)
|
|
228
243
|
mark(journal.step, "running");
|
|
229
244
|
return answer;
|
|
230
245
|
}
|
|
231
|
-
if (adapters.now().getTime() >= deadline)
|
|
232
|
-
|
|
246
|
+
if (adapters.now().getTime() >= deadline) {
|
|
247
|
+
const instead = atLimit?.() ?? null;
|
|
248
|
+
if (instead !== null)
|
|
249
|
+
throw instead;
|
|
250
|
+
throw new Stop("timeout", `Still waiting for ${what} after ${limits[at]} minutes${unreachable === null ? busy ? " (Toolroll's own git on this checkout was still busy)" : "" : ` (GitHub last didn't answer: ${unreachable})`}.`, false, at);
|
|
251
|
+
}
|
|
233
252
|
if (!said) {
|
|
234
253
|
say(` waiting for ${what} (up to ${limits[at]} min)`);
|
|
235
254
|
said = true;
|
|
@@ -239,20 +258,90 @@ export async function runRelease(options, adapters) {
|
|
|
239
258
|
await adapters.sleep(pollMs);
|
|
240
259
|
}
|
|
241
260
|
};
|
|
261
|
+
const writeTruth = async (what, read) => {
|
|
262
|
+
say(` GitHub's answer to ${what} was lost: reading GitHub's record of it`);
|
|
263
|
+
let looks = 0;
|
|
264
|
+
try {
|
|
265
|
+
return await waitFor("ci", `GitHub's record of ${what}`, async () => { const seen = await read(); return seen !== null ? { seen } : ++looks >= 2 ? { seen: null } : null; }).then(found => found.seen);
|
|
266
|
+
}
|
|
267
|
+
catch (error) {
|
|
268
|
+
if (error instanceof Stop && error.reason === "timeout")
|
|
269
|
+
return null;
|
|
270
|
+
throw error;
|
|
271
|
+
}
|
|
272
|
+
};
|
|
273
|
+
const supersede = async (old) => {
|
|
274
|
+
const plane = adapters.release;
|
|
275
|
+
if (plane?.supersede === undefined)
|
|
276
|
+
return;
|
|
277
|
+
const keep = () => { old.updatedAt = adapters.now().toISOString(); writeJournal(file, old); };
|
|
278
|
+
if (old.superseding == null) {
|
|
279
|
+
old.superseding = { at: adapters.now().toISOString(), task: old.task.id, scopeDigest: old.task.scopeDigest, authority: old.authority ?? null,
|
|
280
|
+
apart: old.needsApproval === true || old.stopped?.reason === "check-failed" ? true : null, steps: [], done: null };
|
|
281
|
+
keep();
|
|
282
|
+
}
|
|
283
|
+
const record = old.superseding;
|
|
284
|
+
if (record.done !== null)
|
|
285
|
+
return;
|
|
286
|
+
if (record.apart === null) {
|
|
287
|
+
const head = old.mode === "main" ? old.candidate.sha : (await waitFor("quiet", `${old.branch}'s head on GitHub`, async () => ({ head: await adapters.repo.remoteHead(old.branch) }))).head;
|
|
288
|
+
record.apart = head !== old.candidate.sha;
|
|
289
|
+
keep();
|
|
290
|
+
}
|
|
291
|
+
if (!record.apart) {
|
|
292
|
+
record.done = adapters.now().toISOString();
|
|
293
|
+
keep();
|
|
294
|
+
return;
|
|
295
|
+
}
|
|
296
|
+
let why = "";
|
|
297
|
+
const answer = await waitFor("quiet", `the earlier release task ${record.task} to stop`, async () => {
|
|
298
|
+
const step = await plane.supersede({ taskId: record.task, scopeDigest: record.scopeDigest, authority: record.authority, by: "toolroll release --new" });
|
|
299
|
+
if (step.state !== "refused" && step.steps.length > 0) {
|
|
300
|
+
record.steps = [...new Set([...record.steps, ...step.steps])];
|
|
301
|
+
keep();
|
|
302
|
+
}
|
|
303
|
+
if (step.state === "stopping") {
|
|
304
|
+
why = step.why;
|
|
305
|
+
return null;
|
|
306
|
+
}
|
|
307
|
+
return step;
|
|
308
|
+
}, () => new Stop("superseding", `The earlier release task ${record.task} hasn't stopped after ${limits.quiet} minutes (${why}). Nothing new was started.`));
|
|
309
|
+
if (answer.state === "refused") {
|
|
310
|
+
old.superseding = null;
|
|
311
|
+
keep();
|
|
312
|
+
const words = `The earlier release (task ${record.task}) can't be set aside: ${answer.why}. Nothing new was started; finish it with \`${resume}\`.`;
|
|
313
|
+
throw answer.merging ? new Stop("merging", words) : new Stop("release", words);
|
|
314
|
+
}
|
|
315
|
+
record.done = adapters.now().toISOString();
|
|
316
|
+
keep();
|
|
317
|
+
say(`Set aside the earlier release task ${record.task}${record.steps.length === 0 ? "" : ` (${record.steps.join(", ")})`}.`);
|
|
318
|
+
};
|
|
319
|
+
const writeUnknown = (what, error) => new Stop("write-unknown", `GitHub didn't answer ${what} (${networkWords(error)}), and GitHub's record doesn't show it happened. It wasn't asked again: check it on GitHub, then run \`${resume}\`.`);
|
|
242
320
|
try {
|
|
243
321
|
journal = readJournal(file);
|
|
244
|
-
if (journal !== null && options.fresh === true && journal.step !== "done") {
|
|
322
|
+
if (journal !== null && (options.fresh === true || journal.superseding != null) && journal.step !== "done") {
|
|
323
|
+
const theirs = journal;
|
|
324
|
+
const foreign = (stop) => { journal = null; return stop; };
|
|
325
|
+
if (theirs.checkout !== options.checkout)
|
|
326
|
+
throw foreign(new Stop("checkout", `This release runs in ${theirs.checkout}; nothing was set aside. Rerun with --repo ${theirs.checkout}.`));
|
|
327
|
+
if ((theirs.mode === "main") !== fromMain)
|
|
328
|
+
throw foreign(new Stop("usage", `This journal is ${theirs.mode === "main" ? `the release of ${theirs.packageVersion} from main` : "a branch release"}; nothing was set aside.`));
|
|
329
|
+
if (fromMain ? theirs.packageVersion !== options.version : theirs.branch !== options.branch)
|
|
330
|
+
throw foreign(new Stop("drift", `This journal is the release of ${fromMain ? theirs.packageVersion : theirs.branch}, not ${fromMain ? options.version : options.branch}; nothing was set aside.`));
|
|
331
|
+
if (await adapters.repo.github() !== theirs.github)
|
|
332
|
+
throw foreign(new Stop("drift", `This journal's release is in ${theirs.github}, not this checkout's repository; nothing was set aside.`));
|
|
245
333
|
if (journal.mode === "main" && (journal.intents.tag !== undefined || journal.tagged !== null))
|
|
246
334
|
throw new Stop("tagging", `The release of ${journal.candidate.sha.slice(0, 7)} already began tagging ${journal.tag}; finish it with \`${resume}\` instead of starting over.`);
|
|
247
335
|
if (journal.intents.merge !== undefined)
|
|
248
336
|
throw new Stop("merging", `The release of ${journal.candidate.sha.slice(0, 7)} already began merging; finish it with \`${resume}\` instead of starting over.`);
|
|
249
337
|
await recoverDeploy();
|
|
338
|
+
await supersede(journal);
|
|
250
339
|
const aside = file.replace(/\.json$/, `.superseded-${adapters.now().toISOString().replace(/[:.]/g, "-")}.json`);
|
|
251
340
|
renameSync(file, aside);
|
|
252
341
|
say(`Kept the earlier release journal at ${aside}.`);
|
|
253
342
|
freshApproval = journal.needsApproval === true;
|
|
254
343
|
supersededTask = journal.task.id;
|
|
255
|
-
if (journal.stopped?.reason === "check-failed")
|
|
344
|
+
if (journal.stopped?.reason === "check-failed" || journal.superseding?.apart === true)
|
|
256
345
|
stoppedCheck = journal.candidate.sha;
|
|
257
346
|
journal = null;
|
|
258
347
|
}
|
|
@@ -322,7 +411,17 @@ export async function runRelease(options, adapters) {
|
|
|
322
411
|
}
|
|
323
412
|
if (state.kind === "missing") {
|
|
324
413
|
intend("homebrew");
|
|
325
|
-
|
|
414
|
+
let proposed;
|
|
415
|
+
try {
|
|
416
|
+
proposed = await brew.propose(j.packageVersion);
|
|
417
|
+
}
|
|
418
|
+
catch (error) {
|
|
419
|
+
if (error instanceof NotYetPublished)
|
|
420
|
+
return { state: "pending", why: error.message };
|
|
421
|
+
if (transientNetworkError(error))
|
|
422
|
+
throw writeUnknown(`proposing ${brew.repo}'s change for ${j.packageVersion}`, error);
|
|
423
|
+
throw error;
|
|
424
|
+
}
|
|
326
425
|
state = { kind: "proposed", ...proposed };
|
|
327
426
|
}
|
|
328
427
|
const proposed = state;
|
|
@@ -369,7 +468,15 @@ export async function runRelease(options, adapters) {
|
|
|
369
468
|
const verified = await brew.verified(proposed.pr, proposed.head, j.packageVersion);
|
|
370
469
|
if (!verified.ok)
|
|
371
470
|
return { state: "failed", why: verified.why };
|
|
372
|
-
|
|
471
|
+
try {
|
|
472
|
+
await brew.merge(proposed.pr, proposed.head);
|
|
473
|
+
}
|
|
474
|
+
catch (error) {
|
|
475
|
+
if (!transientNetworkError(error))
|
|
476
|
+
throw error;
|
|
477
|
+
if (await writeTruth("the Homebrew merge", async () => (await brew.state(j.packageVersion)).kind === "current" ? true : null) === null)
|
|
478
|
+
throw writeUnknown(`merging ${brew.repo} #${proposed.pr}`, error);
|
|
479
|
+
}
|
|
373
480
|
return { state: "current", why: null };
|
|
374
481
|
};
|
|
375
482
|
const rel = adapters.release;
|
|
@@ -379,14 +486,52 @@ export async function runRelease(options, adapters) {
|
|
|
379
486
|
}
|
|
380
487
|
catch { } };
|
|
381
488
|
let lastCi = null;
|
|
489
|
+
let red = null;
|
|
382
490
|
const noteCi = async (runs, verdict) => {
|
|
491
|
+
if (verdict.state !== "failed")
|
|
492
|
+
red = null;
|
|
383
493
|
lastCi = { candidate: j.candidate.sha, state: verdict.state === "pending" ? "running" : verdict.state, failed: verdict.failed ?? [], runs: runs.filter(run => REQUIRED_PR_CHECKS.includes(run.name)) };
|
|
384
494
|
const seen = lastCi;
|
|
385
495
|
await tell(ready => ready.ci({ taskId: j.task.id, ...seen }));
|
|
386
496
|
};
|
|
387
497
|
const currentCi = () => lastCi;
|
|
498
|
+
const ciRed = async (runs, verdict) => {
|
|
499
|
+
const short = j.candidate.sha.slice(0, 7), words = verdict.failed.join(", ");
|
|
500
|
+
const attempts = verdict.attempts ?? [];
|
|
501
|
+
const runner = attempts.length > 0 && attempts.every(one => one.beforeTests === true && one.app === "github-actions" && typeof one.workflowRun === "number" && Number.isSafeInteger(one.workflowRun) && one.workflowRun > 0);
|
|
502
|
+
const suites = new Set(attempts.map(one => one.suite));
|
|
503
|
+
const inRerun = runs.filter(one => suites.has(one.suite));
|
|
504
|
+
const finished = runner && inRerun.length > 0 && inRerun.every(one => one.status === "completed");
|
|
505
|
+
const onlyRunner = finished && inRerun.every(one => one.conclusion === "success" || one.conclusion === "skipped" || one.conclusion === "neutral"
|
|
506
|
+
|| (one.beforeTests === true && one.app === "github-actions" && one.workflowRun === attempts.find(a => a.suite === one.suite).workflowRun));
|
|
507
|
+
const whole = onlyRunner && adapters.github.complete !== undefined && await adapters.github.complete(j.github, j.candidate.sha);
|
|
508
|
+
const already = j.ciRerun?.sha === j.candidate.sha;
|
|
509
|
+
if (runner && whole && !already && adapters.github.rerun !== undefined) {
|
|
510
|
+
const ids = [...new Set(attempts.map(one => one.workflowRun))];
|
|
511
|
+
j.ciRerun = { sha: j.candidate.sha, runs: ids, at: adapters.now().toISOString() };
|
|
512
|
+
save();
|
|
513
|
+
for (const id of ids) {
|
|
514
|
+
let asked;
|
|
515
|
+
try {
|
|
516
|
+
asked = await adapters.github.rerun(j.github, id);
|
|
517
|
+
}
|
|
518
|
+
catch (error) {
|
|
519
|
+
asked = { ok: false, why: String(error?.message ?? error).slice(0, 200) };
|
|
520
|
+
}
|
|
521
|
+
say(asked.ok ? ` GitHub's runner failed before the tests ran (${words}): Toolroll ran workflow run ${id} again, once, on ${short}`
|
|
522
|
+
: ` GitHub didn't run workflow run ${id} again (${asked.why}). Rerun the failed job on GitHub or push a fix; Toolroll waits for it.`);
|
|
523
|
+
}
|
|
524
|
+
red = `GitHub's checks failed on ${short}: ${words}.`;
|
|
525
|
+
return;
|
|
526
|
+
}
|
|
527
|
+
const now = `GitHub's checks failed on ${short}: ${words}.`;
|
|
528
|
+
if (red !== now)
|
|
529
|
+
say(` ${now} ${runner && already ? "Toolroll already ran it again once. " : ""}Rerun the failed job on GitHub or push a fix; Toolroll waits for it.`);
|
|
530
|
+
red = now;
|
|
531
|
+
};
|
|
532
|
+
const redAtLimit = (nothing) => () => red === null ? null : new Stop("ci-failed", `${red} ${nothing}. ${j.approval === null ? "" : `The approval covers ${j.candidate.sha.slice(0, 7)} only. `}Rerun the failed job on GitHub or push a fix, then run \`${resume}\`.`);
|
|
388
533
|
let epoch = null;
|
|
389
|
-
const owner = `${j.id}:${randomUUID()}`;
|
|
534
|
+
const owner = `${j.id}:${options.leaseOwner ?? randomUUID()}`;
|
|
390
535
|
const hold = async () => {
|
|
391
536
|
if (rel === undefined || !j.authority)
|
|
392
537
|
return;
|
|
@@ -399,8 +544,26 @@ export async function runRelease(options, adapters) {
|
|
|
399
544
|
const reconcile = async () => {
|
|
400
545
|
if (rel === undefined || !j.authority)
|
|
401
546
|
return;
|
|
402
|
-
for (
|
|
403
|
-
const inFlight = () => new Stop("operation-in-flight", `An earlier ${op.kind} (operation ${op.id})
|
|
547
|
+
for (let op of (await rel.operations(j.authority.id)).filter(one => one.state === "reserved" || one.state === "running" || one.state === "unknown")) {
|
|
548
|
+
const inFlight = (why = "was started by a process that may still be running") => new Stop("operation-in-flight", `An earlier ${op.kind} (operation ${op.id}) ${why}. Nothing was settled.`);
|
|
549
|
+
if (op.state !== "reserved" && !op.issuerGone && op.issuedHere !== true && !(op.kind === "deploy" && await served(adapters, builtHead()) !== null)) {
|
|
550
|
+
const authority = j.authority.id;
|
|
551
|
+
const waited = await waitFor("quiet", `the process that started the earlier ${op.kind} (operation ${op.id}) to end`, async () => {
|
|
552
|
+
if (epoch !== null && !await rel.renew(authority, owner, epoch))
|
|
553
|
+
throw new Stop("lease", "Another release coordinator took over this release.");
|
|
554
|
+
const now = (await rel.operations(authority)).find(one => one.id === op.id);
|
|
555
|
+
if (now === undefined || now.state === "succeeded" || now.state === "failed")
|
|
556
|
+
return { settled: true };
|
|
557
|
+
if (now.issuerGone)
|
|
558
|
+
return { settled: false, op: now };
|
|
559
|
+
if (now.issuedHere === true)
|
|
560
|
+
throw inFlight("was started by this process, and its answer was lost");
|
|
561
|
+
return null;
|
|
562
|
+
}, () => inFlight(`was started by a process still running after ${limits.quiet} minutes`));
|
|
563
|
+
if (waited.settled)
|
|
564
|
+
continue;
|
|
565
|
+
op = waited.op;
|
|
566
|
+
}
|
|
404
567
|
if (op.kind === "deploy") {
|
|
405
568
|
if (op.state === "reserved") {
|
|
406
569
|
await rel.finish(op.id, "failed", { detail: "the call never started" }, epoch);
|
|
@@ -411,7 +574,7 @@ export async function runRelease(options, adapters) {
|
|
|
411
574
|
continue;
|
|
412
575
|
}
|
|
413
576
|
if (!op.issuerGone)
|
|
414
|
-
throw inFlight();
|
|
577
|
+
throw inFlight(op.issuedHere === true ? "was started by this process, and its answer was lost" : undefined);
|
|
415
578
|
if (op.direct) {
|
|
416
579
|
if (!await adapters.toolroll.deploymentIdle(op.stage))
|
|
417
580
|
throw new Stop("deploy-recovery", `A person's deploy of this release (operation ${op.id}) ended without finishing${op.stage === null ? "" : `; its journal is in ${op.stage}`}. Recover it, then rerun.`);
|
|
@@ -428,7 +591,7 @@ export async function runRelease(options, adapters) {
|
|
|
428
591
|
else if (op.state === "reserved")
|
|
429
592
|
await rel.finish(op.id, "failed", { detail: "reconciled: the merge never started" }, epoch);
|
|
430
593
|
else if (!op.issuerGone)
|
|
431
|
-
throw inFlight();
|
|
594
|
+
throw inFlight(op.issuedHere === true ? "was started by this process, and its answer was lost" : undefined);
|
|
432
595
|
else if (pr?.state === "open" && pr.number === j.pr && pr.head === op.candidate)
|
|
433
596
|
await rel.finish(op.id, "failed", { detail: "reconciled: the merge's process ended and the pull request is still open at the gated head" }, epoch);
|
|
434
597
|
else
|
|
@@ -635,8 +798,10 @@ export async function runRelease(options, adapters) {
|
|
|
635
798
|
const verdict = prChecksVerdict(runs, j.candidate.sha, REQUIRED_PR_CHECKS, { workflow: REQUIRED_PR_CHECKS_WORKFLOW });
|
|
636
799
|
await noteCi(runs, verdict);
|
|
637
800
|
if (verdict.state === "failed") {
|
|
638
|
-
|
|
801
|
+
await ciRed(runs, verdict);
|
|
802
|
+
return false;
|
|
639
803
|
}
|
|
804
|
+
red = null;
|
|
640
805
|
if (verdict.state !== "passed")
|
|
641
806
|
return false;
|
|
642
807
|
await liftCiHold(ask, nothing);
|
|
@@ -654,12 +819,12 @@ export async function runRelease(options, adapters) {
|
|
|
654
819
|
await watch("deploy");
|
|
655
820
|
if (await ciWhileRunning("Nothing was deployed, merged, tagged or published", false))
|
|
656
821
|
return true;
|
|
657
|
-
if (!said) {
|
|
822
|
+
if (!said && red === null) {
|
|
658
823
|
say(` ${CI_RUNNING_WORDS}`);
|
|
659
824
|
said = true;
|
|
660
825
|
}
|
|
661
826
|
return null;
|
|
662
|
-
});
|
|
827
|
+
}, redAtLimit("Nothing was deployed, merged, tagged or published"));
|
|
663
828
|
};
|
|
664
829
|
const approved = async (gate, action = "dispatch") => {
|
|
665
830
|
if (gate.candidate !== j.candidate.sha || gate.scopeDigest !== j.task.scopeDigest)
|
|
@@ -758,7 +923,7 @@ export async function runRelease(options, adapters) {
|
|
|
758
923
|
j.task.scopeDigest = existing.scopeDigest;
|
|
759
924
|
}
|
|
760
925
|
else {
|
|
761
|
-
const settled = isMain ? true : await earlyChecks(adapters, j, (what, probe) => waitFor("gate", what, probe), { pendingIsEnough: true, seen: (runs, verdict) => noteCi(runs, verdict) });
|
|
926
|
+
const settled = isMain ? true : await earlyChecks(adapters, j, (what, probe) => waitFor("gate", what, probe), { pendingIsEnough: true, seen: (runs, verdict) => noteCi(runs, verdict), red: ciRed });
|
|
762
927
|
if (!settled)
|
|
763
928
|
await rel?.auto?.ciRunning?.(j.task.id, j.candidate.sha);
|
|
764
929
|
j.ciAhead = !settled;
|
|
@@ -813,8 +978,13 @@ export async function runRelease(options, adapters) {
|
|
|
813
978
|
say(` Not approved automatically: ${authorized.why}. A person approves it.`);
|
|
814
979
|
}
|
|
815
980
|
}
|
|
816
|
-
if (j.ciAhead === true)
|
|
817
|
-
await
|
|
981
|
+
if (j.ciAhead === true && !await ciWhileRunning("Nothing was deployed or merged", true) && red !== null) {
|
|
982
|
+
await waitFor("approval", `a rerun or a fix of the failed checks on ${j.candidate.sha.slice(0, 7)}`, async () => {
|
|
983
|
+
await watch("dispatch");
|
|
984
|
+
await ciWhileRunning("Nothing was deployed or merged", true);
|
|
985
|
+
return red === null ? true : null;
|
|
986
|
+
}, redAtLimit("Nothing was deployed or merged"));
|
|
987
|
+
}
|
|
818
988
|
await tell(ready => ready.asked(j.task.id));
|
|
819
989
|
say(` The release scope needs your approval: \`toolroll task approve ${j.task.id} --digest ${j.task.scopeDigest}\`, or open the task in the console.`);
|
|
820
990
|
say(` Or approve it from here: \`toolroll release approve ${isMain ? j.packageVersion : releaseBranchArg(j.branch)}\`.`);
|
|
@@ -831,7 +1001,7 @@ export async function runRelease(options, adapters) {
|
|
|
831
1001
|
if (!owner.ok && gate.approval !== null && owner.why !== "the approval is for different scope text")
|
|
832
1002
|
throw new Stop("approval", `Task ${j.task.id} was ${owner.why}; the release needs a person to approve it.`);
|
|
833
1003
|
return owner.ok ? owner : null;
|
|
834
|
-
});
|
|
1004
|
+
}, redAtLimit("Nothing was deployed or merged"));
|
|
835
1005
|
j.approval = { by: approved.by, at: approved.at };
|
|
836
1006
|
say(` approved by ${approved.by}`);
|
|
837
1007
|
if (rel !== undefined) {
|
|
@@ -910,7 +1080,7 @@ export async function runRelease(options, adapters) {
|
|
|
910
1080
|
if (j.auto?.state === "checking" && !j.authority) {
|
|
911
1081
|
if (j.ciAhead === true) {
|
|
912
1082
|
try {
|
|
913
|
-
await earlyChecks(adapters, j, (what, probe) => waitFor("gate", what, probe), { nothing: "Nothing was approved" });
|
|
1083
|
+
await earlyChecks(adapters, j, (what, probe) => waitFor("gate", what, probe), { nothing: "Nothing was approved", red: ciRed });
|
|
914
1084
|
await liftCiHold(false, "Nothing was approved");
|
|
915
1085
|
}
|
|
916
1086
|
catch (error) {
|
|
@@ -1024,6 +1194,9 @@ export async function runRelease(options, adapters) {
|
|
|
1024
1194
|
const result = await adapters.toolroll.deploy({ run: check.run, worktree: check.worktree, stage: j.deployAttempt.stage, ...(operation === undefined ? {} : { operation: { id: operation, secret } }) });
|
|
1025
1195
|
if (operation !== undefined)
|
|
1026
1196
|
await rel.finish(operation, result.ok ? "succeeded" : "failed", { detail: result.ok ? result.runtime : result.message.slice(0, 500) }, epoch);
|
|
1197
|
+
if (!result.ok && result.gate === undefined && result.message.includes("Current work must finish first") && await adapters.toolroll.deploymentIdle(j.deployAttempt.stage)) {
|
|
1198
|
+
throw new Stop("deploy-busy", `The deployment of run ${check.run} waited: ${result.message.replace(/\s*The deployment checks once[\s\S]*$/, "")} Nothing was changed.`);
|
|
1199
|
+
}
|
|
1027
1200
|
if (!result.ok)
|
|
1028
1201
|
throw deployStop("deploy", `The deployment of run ${check.run} stopped: ${result.message}`, result);
|
|
1029
1202
|
if (!/[\\/]dist$/.test(result.runtime))
|
|
@@ -1050,11 +1223,19 @@ export async function runRelease(options, adapters) {
|
|
|
1050
1223
|
j.links = await adapters.toolroll.cliLinks();
|
|
1051
1224
|
intend("link");
|
|
1052
1225
|
}
|
|
1053
|
-
|
|
1054
|
-
|
|
1055
|
-
|
|
1056
|
-
|
|
1057
|
-
|
|
1226
|
+
for (let attempt = 1;; attempt++) {
|
|
1227
|
+
try {
|
|
1228
|
+
await adapters.toolroll.switchLinks(j.links, join(runtime, "bin.js"), j.packageVersion);
|
|
1229
|
+
break;
|
|
1230
|
+
}
|
|
1231
|
+
catch (error) {
|
|
1232
|
+
if (attempt >= RELINK_TRIES)
|
|
1233
|
+
throw new Stop("link", `The CLI names were not moved to ${runtime} after ${RELINK_TRIES} tries (they point where they did): ${error.message}. The service already runs the new build; nothing else changed.`);
|
|
1234
|
+
say(` the CLI names didn't move to ${runtime} (${error.message}); they point where they did, and Toolroll tries again`);
|
|
1235
|
+
await adapters.sleep(RELINK_PAUSE_MS * attempt);
|
|
1236
|
+
if (await served(adapters, builtHead()) !== runtime)
|
|
1237
|
+
throw new Stop("drift", `The console and worker no longer run ${runtime}; the CLI names were not moved.`);
|
|
1238
|
+
}
|
|
1058
1239
|
}
|
|
1059
1240
|
const everywhere = await deployed(adapters, builtHead());
|
|
1060
1241
|
if (everywhere !== runtime)
|
|
@@ -1135,7 +1316,17 @@ export async function runRelease(options, adapters) {
|
|
|
1135
1316
|
catch (error) {
|
|
1136
1317
|
if (operation !== undefined)
|
|
1137
1318
|
await rel.finish(operation, "unknown", { detail: String(error?.message ?? error).slice(0, 500) }, epoch);
|
|
1138
|
-
|
|
1319
|
+
if (!transientNetworkError(error))
|
|
1320
|
+
throw error;
|
|
1321
|
+
const truth = await writeTruth("the merge", async () => {
|
|
1322
|
+
const pr = await adapters.github.pullRequest(j.github, j.branch);
|
|
1323
|
+
return pr?.state === "merged" && pr.number === j.pr && pr.head === j.candidate.sha && pr.base === "main" && pr.mergeCommit !== null ? pr.mergeCommit : null;
|
|
1324
|
+
});
|
|
1325
|
+
if (truth === null)
|
|
1326
|
+
throw writeUnknown(`merging pull request #${j.pr}`, error);
|
|
1327
|
+
if (operation !== undefined)
|
|
1328
|
+
await rel.finish(operation, "succeeded", { externalRef: truth, detail: "reconciled: GitHub shows it merged from the gated head" }, epoch);
|
|
1329
|
+
merged = truth;
|
|
1139
1330
|
}
|
|
1140
1331
|
if (operation !== undefined)
|
|
1141
1332
|
await rel.finish(operation, "succeeded", { externalRef: merged }, epoch);
|
|
@@ -1170,7 +1361,15 @@ export async function runRelease(options, adapters) {
|
|
|
1170
1361
|
await autoCiHolds("the tag");
|
|
1171
1362
|
await nightlyHolds("tag");
|
|
1172
1363
|
intend("tag");
|
|
1173
|
-
|
|
1364
|
+
try {
|
|
1365
|
+
await adapters.github.createTag(j.github, j.tag, merge.sha);
|
|
1366
|
+
}
|
|
1367
|
+
catch (error) {
|
|
1368
|
+
if (!transientNetworkError(error))
|
|
1369
|
+
throw error;
|
|
1370
|
+
if (await writeTruth("the tag", async () => (await adapters.github.tag(j.github, j.tag)) === merge.sha ? true : null) === null)
|
|
1371
|
+
throw writeUnknown(`creating ${j.tag}`, error);
|
|
1372
|
+
}
|
|
1174
1373
|
}
|
|
1175
1374
|
j.tagged = { sha: merge.sha };
|
|
1176
1375
|
advance("publish");
|
|
@@ -1233,9 +1432,12 @@ export async function runRelease(options, adapters) {
|
|
|
1233
1432
|
return { ok: true, journal: j, file };
|
|
1234
1433
|
}
|
|
1235
1434
|
catch (error) {
|
|
1236
|
-
const stop = error instanceof Stop ? error
|
|
1435
|
+
const stop = error instanceof Stop ? error
|
|
1436
|
+
: error instanceof CheckoutBusy ? new Stop("checkout-busy", `Toolroll's own git on ${options.checkout} was still busy (another of its git commands is still running). Nothing was changed.`)
|
|
1437
|
+
: transientNetworkError(error) ? new Stop("network", `GitHub didn't answer a read (${networkWords(error)}).`)
|
|
1438
|
+
: new Stop("error", String(error?.message ?? error));
|
|
1237
1439
|
if (journal !== null) {
|
|
1238
|
-
journal.stopped = { step: journal.step, reason: stop.reason, message: stop.message, at: adapters.now().toISOString() };
|
|
1440
|
+
journal.stopped = { step: journal.step, reason: stop.reason, message: stop.message, at: adapters.now().toISOString(), ...(stop.waited === null ? {} : { waited: stop.waited }) };
|
|
1239
1441
|
try {
|
|
1240
1442
|
save();
|
|
1241
1443
|
}
|
|
@@ -1249,7 +1451,7 @@ export async function runRelease(options, adapters) {
|
|
|
1249
1451
|
catch { }
|
|
1250
1452
|
}
|
|
1251
1453
|
}
|
|
1252
|
-
return { ok: false, reason: stop.reason, message: stop.message, step: journal?.step ?? step, journal, file, resume };
|
|
1454
|
+
return { ok: false, reason: stop.reason, message: stop.message, step: journal?.step ?? step, journal, file, resume, ...(stop.waited === null ? {} : { waited: stop.waited }) };
|
|
1253
1455
|
}
|
|
1254
1456
|
}
|
|
1255
1457
|
async function begin(options, adapters, now) {
|
|
@@ -1433,7 +1635,7 @@ async function earlyChecks(adapters, j, wait, options = {}) {
|
|
|
1433
1635
|
const nothing = options.nothing ?? "Nothing was filed or sent for approval";
|
|
1434
1636
|
const sha = j.candidate.sha.slice(0, 7);
|
|
1435
1637
|
const required = REQUIRED_PR_CHECKS;
|
|
1436
|
-
let named = "", unread = false;
|
|
1638
|
+
let named = "", unread = false, failing = null;
|
|
1437
1639
|
try {
|
|
1438
1640
|
return await wait(`the pull request checks on ${sha}`, async () => {
|
|
1439
1641
|
let runs;
|
|
@@ -1448,6 +1650,11 @@ async function earlyChecks(adapters, j, wait, options = {}) {
|
|
|
1448
1650
|
}
|
|
1449
1651
|
const verdict = prChecksVerdict(runs.filter(run => required.includes(run.name)), j.candidate.sha, required, { workflow: REQUIRED_PR_CHECKS_WORKFLOW });
|
|
1450
1652
|
await options.seen?.(runs, verdict);
|
|
1653
|
+
failing = verdict.state === "failed" ? verdict.failed : null;
|
|
1654
|
+
if (verdict.state === "failed" && options.red !== undefined) {
|
|
1655
|
+
await options.red(runs, verdict);
|
|
1656
|
+
return null;
|
|
1657
|
+
}
|
|
1451
1658
|
if (verdict.state === "failed") {
|
|
1452
1659
|
throw new Stop("ci-failed", `Pull request checks already failed on ${sha}: ${verdict.failed.join(", ")}. ${nothing}. Fix the branch, then release the new commit with \`toolroll release ${j.branch} --repo ${j.checkout} --new\` (or rerun the failed job on GitHub and run this command again).`);
|
|
1453
1660
|
}
|
|
@@ -1466,6 +1673,9 @@ async function earlyChecks(adapters, j, wait, options = {}) {
|
|
|
1466
1673
|
catch (error) {
|
|
1467
1674
|
if (!(error instanceof Stop) || error.reason !== "timeout")
|
|
1468
1675
|
throw error;
|
|
1676
|
+
const stillRed = failing;
|
|
1677
|
+
if (stillRed !== null)
|
|
1678
|
+
throw new Stop("ci-failed", `Pull request checks failed on ${sha}: ${stillRed.join(", ")}. ${nothing}. Rerun the failed job on GitHub or push a fix, then run this command again.`);
|
|
1469
1679
|
throw new Stop("ci-missing", `Pull request checks on ${sha} didn't all finish in time${named === "" ? (unread ? " (GitHub didn't answer)" : "") : `: ${named}`}. ${nothing}. Start or rerun them on GitHub, then run this command again.`);
|
|
1470
1680
|
}
|
|
1471
1681
|
}
|
|
@@ -1479,6 +1689,7 @@ function networkWords(error) {
|
|
|
1479
1689
|
}
|
|
1480
1690
|
export function prChecksVerdict(runs, head, required, options = {}) {
|
|
1481
1691
|
const failed = [], waiting = [], failures = [];
|
|
1692
|
+
const failedAttempts = [];
|
|
1482
1693
|
const valid = [];
|
|
1483
1694
|
for (const run of runs) {
|
|
1484
1695
|
const advisory = Object.hasOwn(ADVISORY_PR_CHECKS, run.name) ? ADVISORY_PR_CHECKS[run.name] : undefined;
|
|
@@ -1543,6 +1754,7 @@ export function prChecksVerdict(runs, head, required, options = {}) {
|
|
|
1543
1754
|
}
|
|
1544
1755
|
if (latest.conclusion !== "success") {
|
|
1545
1756
|
failed.push(`${name} (${latest.conclusion ?? "no conclusion"})`);
|
|
1757
|
+
failedAttempts.push(latest);
|
|
1546
1758
|
continue;
|
|
1547
1759
|
}
|
|
1548
1760
|
}
|
|
@@ -1569,7 +1781,7 @@ export function prChecksVerdict(runs, head, required, options = {}) {
|
|
|
1569
1781
|
if (!judged.has(name))
|
|
1570
1782
|
waiting.push(`${name} (not started)`);
|
|
1571
1783
|
if (failed.length > 0)
|
|
1572
|
-
return { state: "failed", failed };
|
|
1784
|
+
return failedAttempts.length === failed.length ? { state: "failed", failed, attempts: failedAttempts } : { state: "failed", failed };
|
|
1573
1785
|
return waiting.length > 0 ? { state: "pending", waiting } : { state: "passed", failures };
|
|
1574
1786
|
}
|
|
1575
1787
|
export function checkFailedWords(input) {
|
package/dist/runner.js
CHANGED
|
@@ -5,13 +5,14 @@ import { inspectAcpAgent, inspectionWords } from "./acp-inspect.js";
|
|
|
5
5
|
import { createHash, randomBytes, timingSafeEqual } from "node:crypto";
|
|
6
6
|
import { resolve } from "node:path";
|
|
7
7
|
import { canonicalProject } from "./project.js";
|
|
8
|
-
import { lifecycleOf, reportLifecycle } from "./store.js";
|
|
8
|
+
import { lifecycleOf, reportLifecycle, reviveWatchLease, watchLeaseRow } from "./store.js";
|
|
9
9
|
import { ALL_CREDENTIAL_ENV, PROVIDER_IDS, inspectionOf } from "./provider.js";
|
|
10
10
|
import { attestationOf, versionInRange } from "./attest.js";
|
|
11
11
|
import { IDENTITY_FAILED_PROBE, LOGIN_PROBE, PATH_PROBE } from "./phase-routing.js";
|
|
12
12
|
import { homedir } from "node:os";
|
|
13
13
|
import { readAuthMode } from "./keys.js";
|
|
14
14
|
import { signInFacts } from "./provider-connection.js";
|
|
15
|
+
import { updateAdmissionPaused } from "./desktop-update-gate.js";
|
|
15
16
|
export function canonicalRepos(repos) {
|
|
16
17
|
return repos.map(repo => canonicalProject(repo) ?? resolve(repo));
|
|
17
18
|
}
|
|
@@ -327,3 +328,37 @@ export function drainOf(store, runner, now) {
|
|
|
327
328
|
return null;
|
|
328
329
|
return { until: row.drainUntil, ended: Date.parse(row.drainUntil) <= now.getTime() };
|
|
329
330
|
}
|
|
331
|
+
export function renewWatchLeaseAuthed(store, args, now) {
|
|
332
|
+
return store.transact(() => {
|
|
333
|
+
const auth = authenticate(store, args.runner, args.token);
|
|
334
|
+
if (!auth.ok)
|
|
335
|
+
return { ok: false, reason: auth.reason };
|
|
336
|
+
if (store.heartbeatWatchLease(args.runner, args.repo, args.owner, args.ttlMs, now)) {
|
|
337
|
+
store.touchRunner(args.runner, now);
|
|
338
|
+
return { ok: true, lateMs: 0 };
|
|
339
|
+
}
|
|
340
|
+
const row = watchLeaseRow(store, args.runner, args.repo);
|
|
341
|
+
if (row === null)
|
|
342
|
+
return { ok: false, reason: "missing" };
|
|
343
|
+
if (row.owner !== args.owner)
|
|
344
|
+
return { ok: false, reason: "taken" };
|
|
345
|
+
if (!boundTo(auth.runner, args.repo))
|
|
346
|
+
return { ok: false, reason: "unbound" };
|
|
347
|
+
if (updateAdmissionPaused(store.raw()) || drainOf(store, auth.runner, now) !== null)
|
|
348
|
+
return { ok: false, reason: "paused" };
|
|
349
|
+
if (!reviveWatchLease(store, args.runner, args.repo, args.owner, row.generation, args.ttlMs, now))
|
|
350
|
+
return { ok: false, reason: "taken" };
|
|
351
|
+
store.touchRunner(args.runner, now);
|
|
352
|
+
return { ok: true, lateMs: Math.max(0, now.getTime() - Date.parse(row.expiresAt)) };
|
|
353
|
+
});
|
|
354
|
+
}
|
|
355
|
+
function boundTo(runner, repo) {
|
|
356
|
+
if (runner.repos.includes(repo))
|
|
357
|
+
return true;
|
|
358
|
+
try {
|
|
359
|
+
return runner.repos.includes(canonicalProject(repo) ?? resolve(repo));
|
|
360
|
+
}
|
|
361
|
+
catch {
|
|
362
|
+
return false;
|
|
363
|
+
}
|
|
364
|
+
}
|
package/dist/scout.js
CHANGED
|
@@ -9,6 +9,7 @@ import { dirname, join, relative, isAbsolute } from "node:path";
|
|
|
9
9
|
import { run } from "./exec.js";
|
|
10
10
|
import { checkoutGit } from "./teardown-git.js";
|
|
11
11
|
import { auditOf } from "./provider.js";
|
|
12
|
+
import { isDatabaseBusy } from "./store.js";
|
|
12
13
|
import { currentClaim, heartbeat } from "./claim.js";
|
|
13
14
|
import { heartbeat as runnerHeartbeat, RUNNER_HEARTBEAT_MS } from "./runner.js";
|
|
14
15
|
import { parseDecision } from "./decision.js";
|
|
@@ -249,7 +250,9 @@ async function scoutWith(store, request, outputDir) {
|
|
|
249
250
|
if (!answer.ok)
|
|
250
251
|
fencedMidScout = true;
|
|
251
252
|
}
|
|
252
|
-
catch {
|
|
253
|
+
catch (error) {
|
|
254
|
+
if (isDatabaseBusy(error))
|
|
255
|
+
return;
|
|
253
256
|
fencedMidScout = true;
|
|
254
257
|
}
|
|
255
258
|
if (fencedMidScout && pulseTimer !== undefined)
|