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/operate.js
CHANGED
|
@@ -110,7 +110,7 @@ import { basename, dirname, isAbsolute, join, resolve } from "node:path";
|
|
|
110
110
|
import { CHECK_RECOVERY_HELD, readCheckRecoveryHoldsForTaskRef } from "./check-recovery-hold.js";
|
|
111
111
|
import { currentRuntime, driftWords, releaseStalledUpdate, serviceDriftHere, waitingUpdate } from "./toolroll-update.js";
|
|
112
112
|
import { dur } from "./design/kit.js";
|
|
113
|
-
import { requeueEligibility, checkoutIdle, setCheckoutIdle, leadQuickAnswersOn, setLeadQuickAnswers, openStore, openStoreNoMigrate, initLocalMode, localModeCandidate, consoleServingNow, consoleComponent, consoleRowForPort, openConsoleRows, enrollOwnerPassword, installationCreatedBy, laptopPortOf, recordLaptopPort, localModeOf, localOwnerBinding, archiveTaskFamily, restoreTaskFamily, shipChecksForTask, elapsedSeconds, CONCURRENT_WRITER_WAIT_MS, isDatabaseBusy, databasePath, BUILT_IN, parseCapabilityKey, verifiedAuthor, isDigestTime, predecessorWatches, RESULT_SCREENSHOTS, lifecycleOf, reportLifecycle, beatLifecycle, } from "./store.js";
|
|
113
|
+
import { requeueEligibility, checkoutIdle, setCheckoutIdle, leadQuickAnswersOn, setLeadQuickAnswers, openStore, openStoreNoMigrate, initLocalMode, localModeCandidate, consoleServingNow, consoleComponent, consoleRowForPort, openConsoleRows, enrollOwnerPassword, installationCreatedBy, laptopPortOf, recordLaptopPort, localModeOf, localOwnerBinding, archiveTaskFamily, restoreTaskFamily, shipChecksForTask, elapsedSeconds, CONCURRENT_WRITER_WAIT_MS, isDatabaseBusy, briefly, databasePath, BUILT_IN, parseCapabilityKey, verifiedAuthor, isDigestTime, predecessorWatches, RESULT_SCREENSHOTS, lifecycleOf, reportLifecycle, beatLifecycle, } from "./store.js";
|
|
114
114
|
import { createHash, randomBytes, randomInt, randomUUID } from "node:crypto";
|
|
115
115
|
import { claimInstance, clearInstance, instanceRunDir, openInstanceSocket, prepareRunDir, proveLiveConsole } from "./console-instance.js";
|
|
116
116
|
import { backgroundOff, backgroundOn, backgroundShow, laptopStatus, laptopStop, restartOwnBuilder } from "./laptop-background.js";
|
|
@@ -205,7 +205,7 @@ import { moveTask } from "./task-moves.js";
|
|
|
205
205
|
import { disposeBuildOutcome, holdStaleApproval, regateTask } from "./dispose.js";
|
|
206
206
|
import { proposeGrant, describeGrant, describeWithheld, permits, MUTATION_CLASSES, DEFAULT_MUTATIONS, } from "./grant.js";
|
|
207
207
|
import { builtIn, guarded } from "./backend.js";
|
|
208
|
-
import { register, authenticate, heartbeat as heartbeatRunner, isAlive, recoverDead, recoveredAnything, acquireWatchLeaseAuthed,
|
|
208
|
+
import { register, authenticate, heartbeat as heartbeatRunner, isAlive, recoverDead, recoveredAnything, acquireWatchLeaseAuthed, renewWatchLeaseAuthed, addRunnerReposAuthed, removeRunnerRepoAuthed, registerRunnerIfIdle, retireRunnerIfCurrent, drainRunnerIfCurrent, drainOf, RUNNER_HEARTBEAT_MS, MAX_WATCH_LEASE_MS, normalizeRunnerName, validRunnerName, canonicalRepos, RUNNER_NAME_MAX, RUNNER_CAPACITY_MAX, parseRunnerCapacity, hashToken as hashRunnerToken, } from "./runner.js";
|
|
209
209
|
import { processIdentityProblem } from "./process-identity.js";
|
|
210
210
|
import { openAddress } from "./browser-open.js";
|
|
211
211
|
import { credentialDigest, recordedHolderProvedGone, processGone, processStart, readRunnerProcessRecord, runnerProcessFile, sealRunnerProcessRecord, writeRunnerProcessRecord } from "./runner-process.js";
|
|
@@ -260,18 +260,21 @@ import { attachTmux, elapsedWords, openInTmux, PEEK_TAIL_LINES, runPeek, snapsho
|
|
|
260
260
|
import { scout as scoutTask } from "./scout.js";
|
|
261
261
|
import { profileDigestOf } from "./scope.js";
|
|
262
262
|
import { PROVIDER_KEY_ENV, clearProviderKey, keyStatus, readAuthMode, readAuthModeStrict, readProviderKey, saveProviderKey, setAuthMode, verifyProviderKey, verdictWords } from "./keys.js";
|
|
263
|
-
import { run, terminateLiveProviders, run as execRun } from "./exec.js";
|
|
263
|
+
import { run, terminateLiveProviders, liveProviderCount, run as execRun } from "./exec.js";
|
|
264
264
|
import { hardenedGit, lazyFetchSafeGit, noLazyFetch, PARTIAL_CLONE_REFUSAL } from "./teardown-git.js";
|
|
265
265
|
import { installedGitFloorProblem } from "./git-floor.js";
|
|
266
266
|
import { noticeGitIncidents } from "./git-incident.js";
|
|
267
267
|
import { containmentNotice, containmentStatus, currentContainment, describeContainment, resolveContainment } from "./containment.js";
|
|
268
268
|
import { readPulls } from "./pulls.js";
|
|
269
|
-
import { startMaintenance } from "./maintenance.js";
|
|
269
|
+
import { startMaintenance, busyRetryAfter } from "./maintenance.js";
|
|
270
270
|
import { WakePoker, wakeHubFor } from "./wake-hub.js";
|
|
271
271
|
import { livePin, modelWatchPass } from "./model-catalog.js";
|
|
272
272
|
import { runModelsCommand } from "./models-cli.js";
|
|
273
273
|
import { ALL_PROJECTS, chatApprovalSettings, chatApprovalWords, setChatApproval } from "./chat-approval.js";
|
|
274
274
|
import { updateAdmissionPaused, UPDATE_PAUSED } from "./desktop-update-gate.js";
|
|
275
|
+
import { abortablePause } from "./chat-follow.js";
|
|
276
|
+
import { endAfterExitProof, watchdogVerdict } from "./shutdown-proof.js";
|
|
277
|
+
import { loopEndRecovery, relaunchAdmission, relaunchDelayMs, LOOP_STABLE_MS, RELAUNCH_WAIT_WORDS } from "./loop-recovery.js";
|
|
275
278
|
import { beads } from "./beads.js";
|
|
276
279
|
import { githubIssues } from "./issues.js";
|
|
277
280
|
import { installationStatus, renderInstallationStatus, renderTaskWait, repairStaleStatuses, taskWaitSnapshot } from "./lead-status.js";
|
|
@@ -988,6 +991,8 @@ async function dispatchOn(command, positional, flags, repoList, base, options, e
|
|
|
988
991
|
...(options.flowTriggerIo === undefined ? {} : { flowTriggerIo: options.flowTriggerIo }),
|
|
989
992
|
...(options.flowStepIo === undefined ? {} : { flowStepIo: options.flowStepIo }),
|
|
990
993
|
...(options.flowEveryMs === undefined ? {} : { flowEveryMs: options.flowEveryMs }),
|
|
994
|
+
...(options.watchHeartbeatMs === undefined ? {} : { watchHeartbeatMs: options.watchHeartbeatMs }),
|
|
995
|
+
...(options.loopRelaunchMs === undefined ? {} : { loopRelaunchMs: options.loopRelaunchMs }),
|
|
991
996
|
...(options.platform === undefined ? {} : { platform: options.platform }),
|
|
992
997
|
...(options.fenceAvailable === undefined ? {} : { fenceAvailable: options.fenceAvailable }),
|
|
993
998
|
...(options.flowFetch === undefined ? {} : { flowFetch: options.flowFetch }),
|
|
@@ -5488,6 +5493,10 @@ function startTelegramFollower(args) {
|
|
|
5488
5493
|
});
|
|
5489
5494
|
}
|
|
5490
5495
|
const TELEGRAM_STOP_WAIT_MS = 5_000;
|
|
5496
|
+
const CLEANUP_SLOW_MS = 30_000;
|
|
5497
|
+
const SHUTDOWN_DEADLINE_MS = 60_000;
|
|
5498
|
+
const WORKER_ALIVE_EVERY_MS = 5_000;
|
|
5499
|
+
const WORKER_SILENCE_MS = 60_000;
|
|
5491
5500
|
let staleStatusesRepaired = false;
|
|
5492
5501
|
async function runWatchLoop(args) {
|
|
5493
5502
|
const { context, flags, runner, token, repo, progress } = args;
|
|
@@ -5543,8 +5552,10 @@ async function runWatchLoop(args) {
|
|
|
5543
5552
|
progress(`watch: recorded ${repaired.exitsRecorded} finished process exit(s) left open by an earlier version`);
|
|
5544
5553
|
}
|
|
5545
5554
|
let leaseLost = false;
|
|
5555
|
+
let leaseLostReason = null;
|
|
5556
|
+
let custodyUnknown = false;
|
|
5546
5557
|
const followController = new AbortController();
|
|
5547
|
-
const hub = wakeHubFor(store);
|
|
5558
|
+
const hub = wakeHubFor(store, read => briefly(store, read));
|
|
5548
5559
|
const wakes = new WakePoker();
|
|
5549
5560
|
args.onFollowController?.(followController);
|
|
5550
5561
|
let failed = false;
|
|
@@ -5556,45 +5567,86 @@ async function runWatchLoop(args) {
|
|
|
5556
5567
|
wakes.poke();
|
|
5557
5568
|
};
|
|
5558
5569
|
const stopping = () => args.isStopping() || leaseLost || failed;
|
|
5559
|
-
const
|
|
5560
|
-
|
|
5561
|
-
|
|
5570
|
+
const heartbeatEveryMs = context.watchHeartbeatMs ?? WATCH_HEARTBEAT_MS;
|
|
5571
|
+
let heartbeatTimer = null;
|
|
5572
|
+
let heartbeatStopped = false;
|
|
5573
|
+
let busyBeats = 0;
|
|
5574
|
+
const scheduleBeat = (ms) => {
|
|
5575
|
+
if (heartbeatStopped)
|
|
5576
|
+
return;
|
|
5577
|
+
heartbeatTimer = setTimeout(beat, ms);
|
|
5578
|
+
heartbeatTimer.unref?.();
|
|
5579
|
+
};
|
|
5580
|
+
function beat() {
|
|
5581
|
+
heartbeatTimer = null;
|
|
5582
|
+
if (heartbeatStopped || leaseLost)
|
|
5583
|
+
return;
|
|
5584
|
+
let answer = null;
|
|
5585
|
+
let problem = null;
|
|
5562
5586
|
try {
|
|
5563
|
-
|
|
5587
|
+
answer = briefly(store, () => renewWatchLeaseAuthed(store, { runner, token, repo, owner: incarnation, ttlMs: WATCH_LEASE_MS }, new Date()));
|
|
5564
5588
|
}
|
|
5565
5589
|
catch (error) {
|
|
5590
|
+
if (isDatabaseBusy(error)) {
|
|
5591
|
+
busyBeats++;
|
|
5592
|
+
if (!custodyUnknown)
|
|
5593
|
+
progress(`watch: ${runner} on ${repo}: the database is busy, so this worker can't prove it still holds the project yet — no new work starts until it can`);
|
|
5594
|
+
custodyUnknown = true;
|
|
5595
|
+
scheduleBeat(Math.min(heartbeatEveryMs, 1_000 * 2 ** Math.min(busyBeats - 1, 4)));
|
|
5596
|
+
return;
|
|
5597
|
+
}
|
|
5566
5598
|
problem = `renewal could not be proved: ${describe(error)}`;
|
|
5567
5599
|
}
|
|
5568
|
-
if (
|
|
5569
|
-
|
|
5570
|
-
|
|
5571
|
-
|
|
5572
|
-
|
|
5600
|
+
if (answer !== null && answer.ok) {
|
|
5601
|
+
busyBeats = 0;
|
|
5602
|
+
if (answer.lateMs > 0)
|
|
5603
|
+
progress(`watch: renewal late by ${Math.max(1, Math.round(answer.lateMs / 1000))}s — this worker still holds ${repo}; carrying on`);
|
|
5604
|
+
if (custodyUnknown) {
|
|
5605
|
+
custodyUnknown = false;
|
|
5606
|
+
progress(`watch: ${runner} on ${repo}: proved it still holds the project — new work may start again`);
|
|
5607
|
+
wakes.poke();
|
|
5608
|
+
}
|
|
5609
|
+
scheduleBeat(heartbeatEveryMs);
|
|
5610
|
+
return;
|
|
5573
5611
|
}
|
|
5574
|
-
|
|
5575
|
-
|
|
5612
|
+
leaseLostReason = answer === null ? "error" : answer.reason;
|
|
5613
|
+
leaseLost = true;
|
|
5614
|
+
followController.abort();
|
|
5615
|
+
wakes.poke();
|
|
5616
|
+
progress(`watch: ${runner} on ${repo}: ${problem ?? renewalRefusedWords(answer.reason)} — stopping without admitting more work`);
|
|
5617
|
+
}
|
|
5618
|
+
scheduleBeat(heartbeatEveryMs);
|
|
5619
|
+
const stopHeartbeat = () => {
|
|
5620
|
+
heartbeatStopped = true;
|
|
5621
|
+
if (heartbeatTimer !== null)
|
|
5622
|
+
clearTimeout(heartbeatTimer);
|
|
5623
|
+
heartbeatTimer = null;
|
|
5624
|
+
};
|
|
5625
|
+
let cleanupStage = null;
|
|
5626
|
+
let lastPassAt = null;
|
|
5627
|
+
args.health?.(() => ({ repo, leaseLive: !leaseLost && !custodyUnknown && cleanupStage === null, lastPassAt, stopping: stopping(), cleanup: cleanupStage }));
|
|
5576
5628
|
const serviceBridge = args.serviceBridge === true;
|
|
5577
5629
|
const follower = serviceBridge
|
|
5578
5630
|
? null
|
|
5579
5631
|
: startTelegramFollower({ context, publicUrl: text(flags, "public-url"), signal: followController.signal, progress, label: "watch: bridge", died: { prefix: "watch: ", then: "taps wait for the next watch" } });
|
|
5580
|
-
const slackFollower = followSlack({ store, dir: dirname(context.databaseFile), signal: followController.signal,
|
|
5632
|
+
const slackFollower = superviseChatFollower("Slack", followController.signal, progress, () => followSlack({ store, dir: dirname(context.databaseFile), signal: followController.signal,
|
|
5581
5633
|
readProjects: telegramReadProjects(context), evidenceRoot: context.evidenceRoot,
|
|
5582
5634
|
...(context.leadSeams?.subscriptionRunner ? { subscriptionRunner: context.leadSeams.subscriptionRunner } : {}),
|
|
5583
5635
|
origin: () => phoneOrigin(process.env, dirname(context.databaseFile), { serverOrigin: text(flags, "public-url") ?? null }),
|
|
5584
5636
|
notifications: () => effectivePrimary(process.env, dirname(context.databaseFile), loadBotToken(process.env, context.telegramTokenFile) !== null).channel === "slack",
|
|
5585
|
-
})
|
|
5586
|
-
const teamsFollower = followTeams({ store, dir: dirname(context.databaseFile), signal: followController.signal,
|
|
5637
|
+
}));
|
|
5638
|
+
const teamsFollower = superviseChatFollower("Teams", followController.signal, progress, () => followTeams({ store, dir: dirname(context.databaseFile), signal: followController.signal,
|
|
5587
5639
|
readProjects: telegramReadProjects(context), evidenceRoot: context.evidenceRoot,
|
|
5588
5640
|
...(context.leadSeams?.subscriptionRunner ? { subscriptionRunner: context.leadSeams.subscriptionRunner } : {}),
|
|
5589
5641
|
origin: () => phoneOrigin(process.env, dirname(context.databaseFile), { serverOrigin: text(flags, "public-url") ?? null }),
|
|
5590
5642
|
notifications: () => effectivePrimary(process.env, dirname(context.databaseFile), loadBotToken(process.env, context.telegramTokenFile) !== null).channel === "teams",
|
|
5591
|
-
})
|
|
5592
|
-
const discordFollower = followDiscord({ store, dir: dirname(context.databaseFile), signal: followController.signal,
|
|
5643
|
+
}));
|
|
5644
|
+
const discordFollower = superviseChatFollower("Discord", followController.signal, progress, () => followDiscord({ store, dir: dirname(context.databaseFile), signal: followController.signal,
|
|
5593
5645
|
readProjects: telegramReadProjects(context), evidenceRoot: context.evidenceRoot,
|
|
5594
5646
|
...(context.leadSeams?.subscriptionRunner ? { subscriptionRunner: context.leadSeams.subscriptionRunner } : {}),
|
|
5595
5647
|
origin: () => phoneOrigin(process.env, dirname(context.databaseFile), { serverOrigin: text(flags, "public-url") ?? null }),
|
|
5596
5648
|
notifications: () => effectivePrimary(process.env, dirname(context.databaseFile), loadBotToken(process.env, context.telegramTokenFile) !== null).channel === "discord",
|
|
5597
|
-
})
|
|
5649
|
+
}));
|
|
5598
5650
|
const quiet = [];
|
|
5599
5651
|
const sink = line => quiet.push(line);
|
|
5600
5652
|
const passFlags = (extra = {}) => {
|
|
@@ -5607,7 +5659,8 @@ async function runWatchLoop(args) {
|
|
|
5607
5659
|
};
|
|
5608
5660
|
let reconciliationReady = false;
|
|
5609
5661
|
let reconciliationFailure = null;
|
|
5610
|
-
|
|
5662
|
+
let reconciliationBusy = false;
|
|
5663
|
+
const paused = () => custodyUnknown || !reconciliationReady || updateAdmissionPaused(store.raw()) || context.shouldPauseAdmission?.() === true;
|
|
5611
5664
|
const admissionStopped = () => stopping() || paused();
|
|
5612
5665
|
const quietContext = { ...context, write: sink, json: true, shouldStop: stopping, shouldPauseAdmission: paused };
|
|
5613
5666
|
const startedAt = Date.now();
|
|
@@ -5628,7 +5681,9 @@ async function runWatchLoop(args) {
|
|
|
5628
5681
|
if (detail !== reconciliationFailure)
|
|
5629
5682
|
progress(`watch: reconciliation failed — ${detail}; new work is paused until a recovery pass succeeds`);
|
|
5630
5683
|
reconciliationFailure = detail;
|
|
5684
|
+
reconciliationBusy = busyFailure(error);
|
|
5631
5685
|
},
|
|
5686
|
+
retryAfter: (error, failuresInARow) => busyRetryAfter(busyFailure(error), failuresInARow),
|
|
5632
5687
|
run: async () => {
|
|
5633
5688
|
const maintenanceLines = [];
|
|
5634
5689
|
const maintenanceContext = { ...quietContext, ...(runFor === null ? { sweepOwner } : {}), write: line => maintenanceLines.push(line) };
|
|
@@ -5773,7 +5828,7 @@ async function runWatchLoop(args) {
|
|
|
5773
5828
|
run: async () => { if (await modelWatchPass(store, context.clock()))
|
|
5774
5829
|
progress("watch: checked models and CLI versions"); },
|
|
5775
5830
|
});
|
|
5776
|
-
const leaveServiceBeats = joinServiceBeats({ context, progress, ciReady: () => !admissionStopped() });
|
|
5831
|
+
const leaveServiceBeats = joinServiceBeats({ context, progress, ciReady: () => !admissionStopped(), stopping });
|
|
5777
5832
|
const passes = args.passes ?? new ProjectPasses();
|
|
5778
5833
|
const slotFacts = (yieldingSince) => {
|
|
5779
5834
|
const now = new Date();
|
|
@@ -5885,6 +5940,7 @@ async function runWatchLoop(args) {
|
|
|
5885
5940
|
const code = await tickCommand(passFlags(yieldBuilds ? { "yield-builds": "1" } : {}), quietContext);
|
|
5886
5941
|
passes.passed(repo);
|
|
5887
5942
|
ticks++;
|
|
5943
|
+
lastPassAt = new Date().toISOString();
|
|
5888
5944
|
if (code === EXIT.ok) {
|
|
5889
5945
|
tickDidWork = true;
|
|
5890
5946
|
built++;
|
|
@@ -5936,31 +5992,44 @@ async function runWatchLoop(args) {
|
|
|
5936
5992
|
fail(error);
|
|
5937
5993
|
}
|
|
5938
5994
|
finally {
|
|
5939
|
-
|
|
5940
|
-
|
|
5941
|
-
|
|
5942
|
-
|
|
5943
|
-
|
|
5944
|
-
|
|
5945
|
-
|
|
5946
|
-
|
|
5947
|
-
|
|
5995
|
+
const step = async (name, work) => {
|
|
5996
|
+
cleanupStage = name;
|
|
5997
|
+
const slow = setTimeout(() => progress(`watch: stopping is still waiting on ${name}`), CLEANUP_SLOW_MS);
|
|
5998
|
+
slow.unref?.();
|
|
5999
|
+
try {
|
|
6000
|
+
await work();
|
|
6001
|
+
}
|
|
6002
|
+
finally {
|
|
6003
|
+
clearTimeout(slow);
|
|
6004
|
+
}
|
|
6005
|
+
};
|
|
6006
|
+
await step("its builds", () => Promise.all(lanes));
|
|
6007
|
+
await step("reconciliation", () => maintenance.stop());
|
|
6008
|
+
await step("follow-up checks", () => followUpChecks.stop());
|
|
6009
|
+
await step("the code map check", () => codeMapChecks.stop());
|
|
6010
|
+
await step("flow moves", () => flowMoves.stop());
|
|
6011
|
+
await step("flow steps", () => flowSteps.stop());
|
|
6012
|
+
await step("the model check", () => modelWatch.stop());
|
|
6013
|
+
await step("deliveries and fast CI", () => leaveServiceBeats());
|
|
6014
|
+
stopHeartbeat();
|
|
5948
6015
|
followController.abort();
|
|
5949
6016
|
if (follower !== null)
|
|
5950
|
-
await follower;
|
|
5951
|
-
await slackFollower;
|
|
5952
|
-
await teamsFollower;
|
|
5953
|
-
await discordFollower;
|
|
6017
|
+
await step("the Telegram follower", () => follower);
|
|
6018
|
+
await step("the Slack follower", () => slackFollower);
|
|
6019
|
+
await step("the Teams follower", () => teamsFollower);
|
|
6020
|
+
await step("the Discord follower", () => discordFollower);
|
|
6021
|
+
cleanupStage = "releasing the project";
|
|
5954
6022
|
store.endWatchEpisode(incarnation, { ticks, built, broke: brokeCount }, new Date());
|
|
5955
6023
|
store.releaseWatchLease(runner, repo, incarnation, new Date());
|
|
6024
|
+
cleanupStage = null;
|
|
5956
6025
|
}
|
|
5957
6026
|
if (failed)
|
|
5958
6027
|
throw failure;
|
|
5959
6028
|
if (leaseLost) {
|
|
5960
|
-
return { ok: false, reason: "lease-lost", detail: `the watch lease for ${runner} on ${repo} stopped renewing —
|
|
6029
|
+
return { ok: false, reason: "lease-lost", lost: leaseLostReason ?? "error", detail: `the watch lease for ${runner} on ${repo} stopped renewing — ${renewalRefusedWords(leaseLostReason ?? "error")}`, ticks, built, broke: brokeCount };
|
|
5961
6030
|
}
|
|
5962
6031
|
if (reconciliationFailure !== null) {
|
|
5963
|
-
return { ok: false, reason: "reconciliation-failed", detail: reconciliationFailure, ticks, built, broke: brokeCount };
|
|
6032
|
+
return { ok: false, reason: "reconciliation-failed", detail: reconciliationFailure, ticks, built, broke: brokeCount, busy: reconciliationBusy };
|
|
5964
6033
|
}
|
|
5965
6034
|
return { ok: true, ticks, built, broke: brokeCount, incarnation };
|
|
5966
6035
|
}
|
|
@@ -6016,7 +6085,7 @@ async function watchCommand(flags, context) {
|
|
|
6016
6085
|
}
|
|
6017
6086
|
stopping = true;
|
|
6018
6087
|
followAbort?.abort();
|
|
6019
|
-
wakeHubFor(context.store).poke();
|
|
6088
|
+
wakeHubFor(context.store, read => briefly(context.store, read)).poke();
|
|
6020
6089
|
graceTimer = setTimeout(hardStop, stopGraceMs);
|
|
6021
6090
|
};
|
|
6022
6091
|
process.on("SIGINT", stop);
|
|
@@ -6662,6 +6731,16 @@ async function upCommand(flags, context) {
|
|
|
6662
6731
|
workerRole = startUpRole({
|
|
6663
6732
|
role: "worker", split, context, build, onSpawned: pid => roleSpawned("worker", pid),
|
|
6664
6733
|
shutdownMs: Math.max(1, stopGraceMs) + 15_000,
|
|
6734
|
+
watchdog: {
|
|
6735
|
+
graceMs: stopGraceMs, say: line => roleLine("worker")(line),
|
|
6736
|
+
...(context.upSeams?.watchdogSilenceMs === undefined ? {} : { silenceMs: context.upSeams.watchdogSilenceMs }),
|
|
6737
|
+
paused: () => briefly(store, () => {
|
|
6738
|
+
if (updateAdmissionPaused(store.raw()))
|
|
6739
|
+
return true;
|
|
6740
|
+
const own = store.getRunner(runnerName)?.runner;
|
|
6741
|
+
return own !== undefined && drainOf(store, own, clock()) !== null;
|
|
6742
|
+
}),
|
|
6743
|
+
},
|
|
6665
6744
|
start: generation => ({
|
|
6666
6745
|
type: "start", role: "worker", databaseFile: context.databaseFile, containment: containmentFlag, build,
|
|
6667
6746
|
config: {
|
|
@@ -6706,7 +6785,17 @@ async function upCommand(flags, context) {
|
|
|
6706
6785
|
}
|
|
6707
6786
|
}
|
|
6708
6787
|
const runnerHeartbeat = setInterval(() => {
|
|
6709
|
-
|
|
6788
|
+
let beat;
|
|
6789
|
+
try {
|
|
6790
|
+
beat = briefly(store, () => heartbeatRunner(store, runnerName, runnerToken, clock()));
|
|
6791
|
+
}
|
|
6792
|
+
catch (error) {
|
|
6793
|
+
if (isDatabaseBusy(error) || stopping)
|
|
6794
|
+
return;
|
|
6795
|
+
fatal = `the builder's heartbeat could not be recorded (${describe(error)})`;
|
|
6796
|
+
stop();
|
|
6797
|
+
return;
|
|
6798
|
+
}
|
|
6710
6799
|
if (!beat.ok && !stopping) {
|
|
6711
6800
|
fatal = `the builder identity changed (${beat.reason})`;
|
|
6712
6801
|
stop();
|
|
@@ -7549,7 +7638,7 @@ async function statusCommand(positional, flags, context) {
|
|
|
7549
7638
|
const runtimeDrift = drift === null ? {} : { runtimeDrift: { service: drift.service.version, serviceRuntime: drift.service.dist, cli: current, words: driftLine, fix: "toolroll update --yes" } };
|
|
7550
7639
|
const projects = projectBuildsStatus(context);
|
|
7551
7640
|
const projectsLine = projects.length === 0 ? null
|
|
7552
|
-
: `Builds by project: ${projects.slice(0, 8).map(one => `${one.name} ${one.running} of ${one.limit}`).join(", ")}${projects.length > 8 ? ", …" : ""}`;
|
|
7641
|
+
: `Builds by project: ${projects.slice(0, 8).map(one => `${one.name} ${one.running} of ${one.limit}${one.builder === "restarting" ? " (builder restarting)" : ""}`).join(", ")}${projects.length > 8 ? ", …" : ""}`;
|
|
7553
7642
|
const unsent = context.store.unsentTelegramReplies(null, null, new Date(context.clock().getTime() - UNSENT_REPLY_MS));
|
|
7554
7643
|
const unsentLine = unsentRepliesLine(unsent);
|
|
7555
7644
|
const unsentReplies = unsent.length === 0 ? {} : { unsentReplies: unsent.map(one => ({ ...one, retry: "toolroll bridge telegram retry" })) };
|
|
@@ -7574,7 +7663,9 @@ function projectBuildsStatus(context) {
|
|
|
7574
7663
|
return repos.map(repo => {
|
|
7575
7664
|
const capacities = workers.filter(one => one.repos.includes(repo)).map(one => one.capacity);
|
|
7576
7665
|
const setting = saved.get(repo) ?? PROJECT_CONCURRENCY_DEFAULT;
|
|
7577
|
-
|
|
7666
|
+
const builders = buildersFor(context.store, repo, now);
|
|
7667
|
+
const restarting = builders.alive.length > 0 && builders.watching.length === 0;
|
|
7668
|
+
return { repo, name: projectName(repo), running: running.get(repo) ?? 0, limit: capacities.length === 0 ? setting : effectiveConcurrency(setting, Math.max(...capacities)), ...(restarting ? { builder: "restarting" } : {}) };
|
|
7578
7669
|
});
|
|
7579
7670
|
}
|
|
7580
7671
|
async function integrationIoFor(context) {
|
|
@@ -10726,7 +10817,7 @@ function upNeedsOneProcess(options) {
|
|
|
10726
10817
|
return options.openDatabase !== undefined || options.desktopIdentity !== undefined || options.additionalProjectRepos !== undefined ||
|
|
10727
10818
|
options.agentRunner !== undefined || options.gitRunner !== undefined || options.telegramTransport !== undefined || options.telegramEnv !== undefined ||
|
|
10728
10819
|
options.publishExec !== undefined || options.dispatchAdapter !== undefined || options.flowTriggerIo !== undefined || options.flowStepIo !== undefined ||
|
|
10729
|
-
options.flowEveryMs !== undefined || options.platform !== undefined || options.fenceAvailable !== undefined || options.flowFetch !== undefined ||
|
|
10820
|
+
options.flowEveryMs !== undefined || options.watchHeartbeatMs !== undefined || options.loopRelaunchMs !== undefined || options.platform !== undefined || options.fenceAvailable !== undefined || options.flowFetch !== undefined ||
|
|
10730
10821
|
options.integrationIo !== undefined || options.shouldStop !== undefined || options.leadSeams !== undefined || options.waitSleep !== undefined ||
|
|
10731
10822
|
options.releaseIo !== undefined || options.installBin !== undefined || options.tempRoots !== undefined || options.filingSizer !== undefined ||
|
|
10732
10823
|
options.now !== undefined || options.folderLook !== undefined;
|
|
@@ -10808,6 +10899,8 @@ function startUpRole(args) {
|
|
|
10808
10899
|
closedProblem = message.problem;
|
|
10809
10900
|
return;
|
|
10810
10901
|
}
|
|
10902
|
+
if (message.type === "alive")
|
|
10903
|
+
return;
|
|
10811
10904
|
args.onMessage(message);
|
|
10812
10905
|
};
|
|
10813
10906
|
if (!args.split) {
|
|
@@ -10837,6 +10930,53 @@ function startUpRole(args) {
|
|
|
10837
10930
|
const controller = new AbortController();
|
|
10838
10931
|
let child = null;
|
|
10839
10932
|
const command = upRoleChildCommand(role);
|
|
10933
|
+
let heardAt = Date.now();
|
|
10934
|
+
let stoppingSince = null;
|
|
10935
|
+
let liveBuilds = 0;
|
|
10936
|
+
let saidPaused = false;
|
|
10937
|
+
let saidWaiting = false;
|
|
10938
|
+
const watchdog = args.watchdog === undefined ? null : setInterval(() => {
|
|
10939
|
+
const owned = child;
|
|
10940
|
+
if (stopping || controller.signal.aborted || owned === null || owned.exitCode !== null || owned.signalCode !== null || !generations.current())
|
|
10941
|
+
return;
|
|
10942
|
+
const now = Date.now();
|
|
10943
|
+
const silentMs = now - heardAt;
|
|
10944
|
+
const silenceMs = args.watchdog.silenceMs ?? WORKER_SILENCE_MS;
|
|
10945
|
+
const facts = { silentMs, silenceMs, stoppingForMs: stoppingSince === null ? null : now - stoppingSince, graceMs: args.watchdog.graceMs, deadlineMs: SHUTDOWN_DEADLINE_MS, liveBuilds, paused: false };
|
|
10946
|
+
if (watchdogVerdict(facts) === "fine") {
|
|
10947
|
+
saidPaused = false;
|
|
10948
|
+
saidWaiting = false;
|
|
10949
|
+
return;
|
|
10950
|
+
}
|
|
10951
|
+
try {
|
|
10952
|
+
facts.paused = args.watchdog.paused();
|
|
10953
|
+
}
|
|
10954
|
+
catch {
|
|
10955
|
+
facts.paused = true;
|
|
10956
|
+
}
|
|
10957
|
+
const verdict = watchdogVerdict(facts);
|
|
10958
|
+
if (verdict === "leave") {
|
|
10959
|
+
if (!saidPaused)
|
|
10960
|
+
args.watchdog.say(`the ${role} isn't answering, but an update or restart is under way; leaving it to that`);
|
|
10961
|
+
saidPaused = true;
|
|
10962
|
+
return;
|
|
10963
|
+
}
|
|
10964
|
+
if (verdict === "wait") {
|
|
10965
|
+
if (!saidWaiting)
|
|
10966
|
+
args.watchdog.say(`the ${role} is still stopping: ${liveBuilds === 1 ? "a build hasn't" : `${liveBuilds} builds haven't`} confirmed ${liveBuilds === 1 ? "it" : "they"} stopped; leaving it to finish`);
|
|
10967
|
+
saidWaiting = true;
|
|
10968
|
+
return;
|
|
10969
|
+
}
|
|
10970
|
+
if (verdict !== "restart")
|
|
10971
|
+
return;
|
|
10972
|
+
args.watchdog.say(silentMs < silenceMs
|
|
10973
|
+
? `the ${role}'s stop overran its deadline; stopping it and starting it again`
|
|
10974
|
+
: `the ${role} hasn't answered for ${Math.round(silentMs / 1000)}s; stopping it and starting it again`);
|
|
10975
|
+
if (!stopProcessTree(owned))
|
|
10976
|
+
owned.kill("SIGKILL");
|
|
10977
|
+
heardAt = now;
|
|
10978
|
+
}, WORKER_ALIVE_EVERY_MS);
|
|
10979
|
+
watchdog?.unref?.();
|
|
10840
10980
|
const supervised = superviseController({
|
|
10841
10981
|
file: command.file, argv: command.argv, signal: controller.signal, ipc: true, shutdownMs: args.shutdownMs,
|
|
10842
10982
|
label: envValue(process.env, "LOG_FORMAT") === "json" ? "" : `[${role}]`,
|
|
@@ -10845,7 +10985,17 @@ function startUpRole(args) {
|
|
|
10845
10985
|
fatal = null;
|
|
10846
10986
|
failed = null;
|
|
10847
10987
|
generations.spawned();
|
|
10848
|
-
|
|
10988
|
+
heardAt = Date.now();
|
|
10989
|
+
stoppingSince = null;
|
|
10990
|
+
owned.on("message", raw => {
|
|
10991
|
+
heardAt = Date.now();
|
|
10992
|
+
const alive = roleMessage(raw, role);
|
|
10993
|
+
if (alive?.type === "alive") {
|
|
10994
|
+
stoppingSince = alive.stopping ? stoppingSince ?? heardAt : null;
|
|
10995
|
+
liveBuilds = alive.liveBuilds;
|
|
10996
|
+
}
|
|
10997
|
+
receive(raw, () => controller.abort());
|
|
10998
|
+
});
|
|
10849
10999
|
owned.on("error", () => { });
|
|
10850
11000
|
let recorded = false;
|
|
10851
11001
|
try {
|
|
@@ -10887,11 +11037,16 @@ function startUpRole(args) {
|
|
|
10887
11037
|
endForGood(fatal ?? `the ${role} stopped (exit ${exit})`);
|
|
10888
11038
|
return;
|
|
10889
11039
|
}
|
|
11040
|
+
if (generations.struggling()) {
|
|
11041
|
+
args.onEnded(`${fatal === null ? "" : `${fatal} — `}the ${role} is still restarting (${generations.notReady()} tries so far, exit ${exit})`, true);
|
|
11042
|
+
return;
|
|
11043
|
+
}
|
|
10890
11044
|
args.onEnded(`${fatal === null ? "" : `${fatal} — `}the ${role} stopped unexpectedly (exit ${exit})`, true);
|
|
10891
11045
|
},
|
|
10892
11046
|
}).catch(error => { if (!generations.wasReady())
|
|
10893
11047
|
resolveReady({ ok: false, reason: "start", detail: describe(error) }); });
|
|
10894
|
-
const done = supervised.
|
|
11048
|
+
const done = supervised.finally(() => { if (watchdog !== null)
|
|
11049
|
+
clearInterval(watchdog); }).then(() => {
|
|
10895
11050
|
if (!generations.wasReady())
|
|
10896
11051
|
resolveReady({ ok: false, ...(failed ?? { reason: "start", detail: fatal ?? `the ${role} did not start` }) });
|
|
10897
11052
|
else
|
|
@@ -11076,16 +11231,35 @@ async function runUpWorkerRole(context, config, port, build) {
|
|
|
11076
11231
|
if (terminated > 0)
|
|
11077
11232
|
progress(`Stopped ${terminated} running build(s). Their work is saved, and each resumes when the builder starts again.`);
|
|
11078
11233
|
};
|
|
11234
|
+
const loopHealth = new Map();
|
|
11235
|
+
let deadlineTimer;
|
|
11236
|
+
const stillWaitingOn = () => {
|
|
11237
|
+
const named = [...loopHealth.values()].map(read => read()).filter(one => one.cleanup !== null).map(one => `${projectName(one.repo)}: ${one.cleanup}`);
|
|
11238
|
+
return named.length === 0 ? "the worker's own shutdown" : named.join(", ");
|
|
11239
|
+
};
|
|
11240
|
+
const forceEnd = async () => {
|
|
11241
|
+
const waiting = stillWaitingOn();
|
|
11242
|
+
progress(`Stopping is taking too long (still waiting on ${waiting}); stopping this worker's builds now`);
|
|
11243
|
+
await endAfterExitProof({ hardStop, liveBuilds: liveProviderCount, say: progress, exit: port.exit, code: EXIT.failed,
|
|
11244
|
+
before: () => port.send({ type: "fatal", detail: `the worker's stop didn't finish (still waiting on ${waiting}); Toolroll is restarting it` }) });
|
|
11245
|
+
};
|
|
11246
|
+
const armDeadline = () => {
|
|
11247
|
+
if (deadlineTimer !== undefined)
|
|
11248
|
+
return;
|
|
11249
|
+
deadlineTimer = setTimeout(() => { void forceEnd(); }, config.stopGraceMs + SHUTDOWN_DEADLINE_MS);
|
|
11250
|
+
deadlineTimer.unref?.();
|
|
11251
|
+
};
|
|
11079
11252
|
const stop = () => {
|
|
11080
11253
|
if (stopping) {
|
|
11081
11254
|
hardStop();
|
|
11082
11255
|
return;
|
|
11083
11256
|
}
|
|
11084
11257
|
stopping = true;
|
|
11258
|
+
armDeadline();
|
|
11085
11259
|
resolveStopped();
|
|
11086
11260
|
for (const controller of followControllers)
|
|
11087
11261
|
controller.abort();
|
|
11088
|
-
wakeHubFor(store).poke();
|
|
11262
|
+
wakeHubFor(store, read => briefly(store, read)).poke();
|
|
11089
11263
|
const building = store.liveClaimCount(runnerName, clock());
|
|
11090
11264
|
if (building > 0) {
|
|
11091
11265
|
progress(`Stopping: ${building} build(s) running. Waiting up to ${Math.round(config.stopGraceMs / 1000)}s for them to finish; any still running then is saved and resumes when the builder starts again.`);
|
|
@@ -11130,9 +11304,82 @@ async function runUpWorkerRole(context, config, port, build) {
|
|
|
11130
11304
|
const loopResults = new Map();
|
|
11131
11305
|
const projectPasses = new ProjectPasses();
|
|
11132
11306
|
const releasedRepos = new Set();
|
|
11133
|
-
const
|
|
11307
|
+
const relaunches = new Map();
|
|
11308
|
+
const relaunchAttempts = new Map();
|
|
11309
|
+
const relaunchAbort = new AbortController();
|
|
11310
|
+
followControllers.push(relaunchAbort);
|
|
11311
|
+
const relaunchPause = (ms) => new Promise(resolvePause => {
|
|
11312
|
+
const timer = setTimeout(done, ms);
|
|
11313
|
+
function done() { clearTimeout(timer); relaunchAbort.signal.removeEventListener("abort", done); resolvePause(); }
|
|
11314
|
+
if (relaunchAbort.signal.aborted)
|
|
11315
|
+
done();
|
|
11316
|
+
else
|
|
11317
|
+
relaunchAbort.signal.addEventListener("abort", done, { once: true });
|
|
11318
|
+
});
|
|
11319
|
+
const scheduleRelaunch = (repo, detail) => {
|
|
11320
|
+
if (relaunches.has(repo) || stopping)
|
|
11321
|
+
return;
|
|
11322
|
+
const attempt = relaunchAttempts.get(repo) ?? 0;
|
|
11323
|
+
relaunchAttempts.set(repo, attempt + 1);
|
|
11324
|
+
const delay = relaunchDelayMs(attempt, context.loopRelaunchMs);
|
|
11325
|
+
progress(`${prefix(repo)}this project's builder stopped (${detail}); Toolroll is restarting it in ${Math.max(1, Math.round(delay / 1000))}s`);
|
|
11326
|
+
const pending = (async () => {
|
|
11327
|
+
await relaunchPause(delay);
|
|
11328
|
+
let waited = 0;
|
|
11329
|
+
let saidWaiting = false;
|
|
11330
|
+
for (;;) {
|
|
11331
|
+
if (stopping)
|
|
11332
|
+
return;
|
|
11333
|
+
if (releasedRepos.has(repo)) {
|
|
11334
|
+
fatal = `${prefix(repo)}${detail}`;
|
|
11335
|
+
stop();
|
|
11336
|
+
return;
|
|
11337
|
+
}
|
|
11338
|
+
if (!activeRepos.has(repo))
|
|
11339
|
+
return;
|
|
11340
|
+
let admission;
|
|
11341
|
+
try {
|
|
11342
|
+
admission = briefly(store, () => relaunchAdmission(store, runnerName, repo, clock()));
|
|
11343
|
+
}
|
|
11344
|
+
catch (error) {
|
|
11345
|
+
if (!isDatabaseBusy(error))
|
|
11346
|
+
throw error;
|
|
11347
|
+
await relaunchPause(relaunchDelayMs(waited++, context.loopRelaunchMs));
|
|
11348
|
+
continue;
|
|
11349
|
+
}
|
|
11350
|
+
if (admission === "identity") {
|
|
11351
|
+
fatal = `the builder identity changed while restarting ${projectName(repo)}`;
|
|
11352
|
+
stop();
|
|
11353
|
+
return;
|
|
11354
|
+
}
|
|
11355
|
+
if (admission === "gone") {
|
|
11356
|
+
loopResults.delete(repo);
|
|
11357
|
+
activeRepos.delete(repo);
|
|
11358
|
+
reportRepos();
|
|
11359
|
+
progress(`project removed — ${projectName(repo)} is no longer built here`);
|
|
11360
|
+
return;
|
|
11361
|
+
}
|
|
11362
|
+
if (admission === "go")
|
|
11363
|
+
break;
|
|
11364
|
+
if (!saidWaiting)
|
|
11365
|
+
progress(`${prefix(repo)}still restarting: waiting for ${RELAUNCH_WAIT_WORDS[admission]}`);
|
|
11366
|
+
saidWaiting = true;
|
|
11367
|
+
await relaunchPause(relaunchDelayMs(waited++, context.loopRelaunchMs));
|
|
11368
|
+
}
|
|
11369
|
+
loopResults.delete(repo);
|
|
11370
|
+
relaunches.delete(repo);
|
|
11371
|
+
await launchRepo(repo, false, false, true);
|
|
11372
|
+
})().catch(error => {
|
|
11373
|
+
fatal = `${prefix(repo)}the builder couldn't be restarted (${describe(error)})`;
|
|
11374
|
+
stop();
|
|
11375
|
+
}).finally(() => { if (relaunches.get(repo) === pending)
|
|
11376
|
+
relaunches.delete(repo); });
|
|
11377
|
+
relaunches.set(repo, pending);
|
|
11378
|
+
};
|
|
11379
|
+
const launchRepo = async (repo, bind, drain = false, relaunching = false) => {
|
|
11134
11380
|
if (loopResults.has(repo) || stopping)
|
|
11135
11381
|
return;
|
|
11382
|
+
let readyAt = null;
|
|
11136
11383
|
if (drain)
|
|
11137
11384
|
releasedRepos.add(repo);
|
|
11138
11385
|
if (bind) {
|
|
@@ -11162,14 +11409,18 @@ async function runUpWorkerRole(context, config, port, build) {
|
|
|
11162
11409
|
containmentLines,
|
|
11163
11410
|
passes: projectPasses,
|
|
11164
11411
|
serviceBridge: true,
|
|
11412
|
+
health: read => loopHealth.set(repo, read),
|
|
11165
11413
|
leaseWaitMs: config.leaseWaitMs,
|
|
11166
11414
|
...(drain ? { leaseWaitStopping: () => stopping } : {}),
|
|
11167
11415
|
onReady: () => {
|
|
11416
|
+
readyAt = Date.now();
|
|
11168
11417
|
markReady();
|
|
11169
11418
|
if (bind)
|
|
11170
11419
|
progress(`${prefix(repo)}builder connected — queued work can start`);
|
|
11420
|
+
if (relaunching)
|
|
11421
|
+
progress(`${prefix(repo)}builder restarted automatically — queued work can start`);
|
|
11171
11422
|
},
|
|
11172
|
-
}).then(result => ({ repo, result }), error => ({ repo, result: { ok: false, reason: "loop-failed", detail: describe(error), ticks: 0, built: 0, broke: 0 } }));
|
|
11423
|
+
}).then(result => ({ repo, result }), error => ({ repo, result: { ok: false, reason: "loop-failed", detail: describe(error), ticks: 0, built: 0, broke: 0, busy: isDatabaseBusy(error) } }));
|
|
11173
11424
|
loopResults.set(repo, loop);
|
|
11174
11425
|
void loop.then(({ repo: endedRepo, result }) => {
|
|
11175
11426
|
if (releasedRepos.has(endedRepo) && !stopping && !result.ok) {
|
|
@@ -11191,6 +11442,13 @@ async function runUpWorkerRole(context, config, port, build) {
|
|
|
11191
11442
|
return;
|
|
11192
11443
|
}
|
|
11193
11444
|
if (!result.ok && !stopping) {
|
|
11445
|
+
if (readyAt !== null && Date.now() - readyAt >= LOOP_STABLE_MS)
|
|
11446
|
+
relaunchAttempts.delete(endedRepo);
|
|
11447
|
+
if (loopEndRecovery(result, relaunching) === "relaunch" && activeRepos.has(endedRepo)) {
|
|
11448
|
+
scheduleRelaunch(endedRepo, result.detail);
|
|
11449
|
+
markReady();
|
|
11450
|
+
return;
|
|
11451
|
+
}
|
|
11194
11452
|
fatal = `${prefix(endedRepo)}${result.detail}`;
|
|
11195
11453
|
stop();
|
|
11196
11454
|
}
|
|
@@ -11376,10 +11634,35 @@ async function runUpWorkerRole(context, config, port, build) {
|
|
|
11376
11634
|
: null;
|
|
11377
11635
|
if (fatal === null && !stopping)
|
|
11378
11636
|
port.send({ type: "ready", role: "worker", build, pid: process.pid, url: null, port: null });
|
|
11637
|
+
const cleanupSince = new Map();
|
|
11638
|
+
const aliveTimer = setInterval(() => {
|
|
11639
|
+
const repos = [...loopHealth.entries()].filter(([repo]) => loopResults.has(repo)).map(([, read]) => read());
|
|
11640
|
+
port.send({ type: "alive", stopping, repos, liveBuilds: liveProviderCount() });
|
|
11641
|
+
if (stopping)
|
|
11642
|
+
return;
|
|
11643
|
+
for (const one of repos) {
|
|
11644
|
+
if (one.cleanup === null || one.cleanup === "its builds") {
|
|
11645
|
+
cleanupSince.delete(one.repo);
|
|
11646
|
+
continue;
|
|
11647
|
+
}
|
|
11648
|
+
const since = cleanupSince.get(one.repo);
|
|
11649
|
+
if (since === undefined || since.stage !== one.cleanup) {
|
|
11650
|
+
cleanupSince.set(one.repo, { stage: one.cleanup, at: Date.now() });
|
|
11651
|
+
continue;
|
|
11652
|
+
}
|
|
11653
|
+
if (Date.now() - since.at < config.stopGraceMs + SHUTDOWN_DEADLINE_MS)
|
|
11654
|
+
continue;
|
|
11655
|
+
fatal = `${prefix(one.repo)}its loop stopped but never finished stopping (still waiting on ${one.cleanup})`;
|
|
11656
|
+
stop();
|
|
11657
|
+
return;
|
|
11658
|
+
}
|
|
11659
|
+
}, WORKER_ALIVE_EVERY_MS);
|
|
11660
|
+
aliveTimer.unref?.();
|
|
11379
11661
|
await stopped;
|
|
11380
11662
|
if (readinessTimer !== undefined)
|
|
11381
11663
|
clearInterval(readinessTimer);
|
|
11382
11664
|
await registrySupervisor;
|
|
11665
|
+
await Promise.all([...relaunches.values()]);
|
|
11383
11666
|
await Promise.all([...loopResults.values()]);
|
|
11384
11667
|
await stopLiveBackups?.();
|
|
11385
11668
|
await new Promise(done => {
|
|
@@ -11389,6 +11672,9 @@ async function runUpWorkerRole(context, config, port, build) {
|
|
|
11389
11672
|
});
|
|
11390
11673
|
if (graceTimer !== undefined)
|
|
11391
11674
|
clearTimeout(graceTimer);
|
|
11675
|
+
if (deadlineTimer !== undefined)
|
|
11676
|
+
clearTimeout(deadlineTimer);
|
|
11677
|
+
clearInterval(aliveTimer);
|
|
11392
11678
|
if (fatal !== null) {
|
|
11393
11679
|
port.send({ type: "fatal", detail: fatal });
|
|
11394
11680
|
return EXIT.failed;
|
|
@@ -12486,10 +12772,11 @@ function startServiceBeats(store) {
|
|
|
12486
12772
|
shouldStop: () => beats.stopped,
|
|
12487
12773
|
onError: () => { },
|
|
12488
12774
|
run: async () => {
|
|
12489
|
-
const
|
|
12775
|
+
const standingMembers = () => [...beats.members].filter(one => one.stopping?.() !== true);
|
|
12776
|
+
const standing = () => { const members = standingMembers(); return !beats.stopped && members.length > 0 && members.every(one => one.ciReady()); };
|
|
12490
12777
|
if (!standing())
|
|
12491
12778
|
return;
|
|
12492
|
-
const { context, progress } =
|
|
12779
|
+
const { context, progress } = standingMembers()[0];
|
|
12493
12780
|
const now = context.clock();
|
|
12494
12781
|
const waiting = fastCiWaiting(store, now, FAST_CI_LIMIT, attempted);
|
|
12495
12782
|
if (waiting.length === 0)
|
|
@@ -12512,7 +12799,7 @@ function startServiceBeats(store) {
|
|
|
12512
12799
|
},
|
|
12513
12800
|
});
|
|
12514
12801
|
const poker = new WakePoker();
|
|
12515
|
-
const hub = wakeHubFor(store);
|
|
12802
|
+
const hub = wakeHubFor(store, read => briefly(store, read));
|
|
12516
12803
|
const beats = { members: new Set(), stopped: false, delivery, fastCi, poker, wakeLoop: Promise.resolve() };
|
|
12517
12804
|
beats.wakeLoop = (async () => {
|
|
12518
12805
|
while (!beats.stopped) {
|
|
@@ -13593,3 +13880,40 @@ function acceptedWords(completion) {
|
|
|
13593
13880
|
const by = completedByOf(completion);
|
|
13594
13881
|
return by === null ? "accepted" : `accepted by ${by}`;
|
|
13595
13882
|
}
|
|
13883
|
+
function renewalRefusedWords(reason) {
|
|
13884
|
+
switch (reason) {
|
|
13885
|
+
case "taken": return "another watch took this project over";
|
|
13886
|
+
case "missing": return "the project's lease record is gone (the project was removed)";
|
|
13887
|
+
case "unbound": return "the project is no longer connected to this builder";
|
|
13888
|
+
case "paused": return "the lease lapsed while an update or restart was under way";
|
|
13889
|
+
case "error": return "the renewal failed";
|
|
13890
|
+
default: return `the builder's credential no longer holds (${reason})`;
|
|
13891
|
+
}
|
|
13892
|
+
}
|
|
13893
|
+
const CHAT_CONFIG_FAILURE = /\b(invalid_auth|not_authed|account_inactive|token_revoked|unauthori[sz]ed|forbidden|401|403|missing_scope|invalid token|bad token)\b/i;
|
|
13894
|
+
async function superviseChatFollower(name, signal, progress, start) {
|
|
13895
|
+
const pause = abortablePause(signal);
|
|
13896
|
+
let attempt = 0;
|
|
13897
|
+
while (!signal.aborted) {
|
|
13898
|
+
const began = Date.now();
|
|
13899
|
+
try {
|
|
13900
|
+
await start();
|
|
13901
|
+
return;
|
|
13902
|
+
}
|
|
13903
|
+
catch (error) {
|
|
13904
|
+
if (signal.aborted)
|
|
13905
|
+
return;
|
|
13906
|
+
if (Date.now() - began >= 60_000)
|
|
13907
|
+
attempt = 0;
|
|
13908
|
+
const delay = Math.min(30_000, 1_000 * 2 ** Math.min(attempt++, 5));
|
|
13909
|
+
const detail = describe(error);
|
|
13910
|
+
progress(CHAT_CONFIG_FAILURE.test(detail)
|
|
13911
|
+
? `watch: ${name} stopped (${detail.slice(0, 160)}). Check ${name} settings; Toolroll tries again in ${Math.round(delay / 1000)}s.`
|
|
13912
|
+
: `watch: ${name} stopped for a moment (${isDatabaseBusy(error) ? "the database was busy" : detail.slice(0, 160)}); reconnecting in ${Math.round(delay / 1000)}s.`);
|
|
13913
|
+
await pause(delay);
|
|
13914
|
+
}
|
|
13915
|
+
}
|
|
13916
|
+
}
|
|
13917
|
+
function busyFailure(error) {
|
|
13918
|
+
return isDatabaseBusy(error) || /\b(database[- ](is )?(locked|busy)|SQLITE_BUSY)\b/i.test(describe(error));
|
|
13919
|
+
}
|