aglio-worker 0.115.7 → 0.115.8
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/agent.js +309 -61
- package/package.json +1 -1
package/agent.js
CHANGED
|
@@ -43273,11 +43273,11 @@ var require_codegen = __commonJS({
|
|
|
43273
43273
|
const rhs = this.rhs === void 0 ? "" : ` = ${this.rhs}`;
|
|
43274
43274
|
return `${varKind} ${this.name}${rhs};` + _n3;
|
|
43275
43275
|
}
|
|
43276
|
-
optimizeNames(names,
|
|
43276
|
+
optimizeNames(names, constants4) {
|
|
43277
43277
|
if (!names[this.name.str])
|
|
43278
43278
|
return;
|
|
43279
43279
|
if (this.rhs)
|
|
43280
|
-
this.rhs = optimizeExpr(this.rhs, names,
|
|
43280
|
+
this.rhs = optimizeExpr(this.rhs, names, constants4);
|
|
43281
43281
|
return this;
|
|
43282
43282
|
}
|
|
43283
43283
|
get names() {
|
|
@@ -43294,10 +43294,10 @@ var require_codegen = __commonJS({
|
|
|
43294
43294
|
render({ _n: _n3 }) {
|
|
43295
43295
|
return `${this.lhs} = ${this.rhs};` + _n3;
|
|
43296
43296
|
}
|
|
43297
|
-
optimizeNames(names,
|
|
43297
|
+
optimizeNames(names, constants4) {
|
|
43298
43298
|
if (this.lhs instanceof code_1.Name && !names[this.lhs.str] && !this.sideEffects)
|
|
43299
43299
|
return;
|
|
43300
|
-
this.rhs = optimizeExpr(this.rhs, names,
|
|
43300
|
+
this.rhs = optimizeExpr(this.rhs, names, constants4);
|
|
43301
43301
|
return this;
|
|
43302
43302
|
}
|
|
43303
43303
|
get names() {
|
|
@@ -43358,8 +43358,8 @@ var require_codegen = __commonJS({
|
|
|
43358
43358
|
optimizeNodes() {
|
|
43359
43359
|
return `${this.code}` ? this : void 0;
|
|
43360
43360
|
}
|
|
43361
|
-
optimizeNames(names,
|
|
43362
|
-
this.code = optimizeExpr(this.code, names,
|
|
43361
|
+
optimizeNames(names, constants4) {
|
|
43362
|
+
this.code = optimizeExpr(this.code, names, constants4);
|
|
43363
43363
|
return this;
|
|
43364
43364
|
}
|
|
43365
43365
|
get names() {
|
|
@@ -43388,12 +43388,12 @@ var require_codegen = __commonJS({
|
|
|
43388
43388
|
}
|
|
43389
43389
|
return nodes2.length > 0 ? this : void 0;
|
|
43390
43390
|
}
|
|
43391
|
-
optimizeNames(names,
|
|
43391
|
+
optimizeNames(names, constants4) {
|
|
43392
43392
|
const { nodes: nodes2 } = this;
|
|
43393
43393
|
let i = nodes2.length;
|
|
43394
43394
|
while (i--) {
|
|
43395
43395
|
const n = nodes2[i];
|
|
43396
|
-
if (n.optimizeNames(names,
|
|
43396
|
+
if (n.optimizeNames(names, constants4))
|
|
43397
43397
|
continue;
|
|
43398
43398
|
subtractNames(names, n.names);
|
|
43399
43399
|
nodes2.splice(i, 1);
|
|
@@ -43446,12 +43446,12 @@ var require_codegen = __commonJS({
|
|
|
43446
43446
|
return void 0;
|
|
43447
43447
|
return this;
|
|
43448
43448
|
}
|
|
43449
|
-
optimizeNames(names,
|
|
43449
|
+
optimizeNames(names, constants4) {
|
|
43450
43450
|
var _a6;
|
|
43451
|
-
this.else = (_a6 = this.else) === null || _a6 === void 0 ? void 0 : _a6.optimizeNames(names,
|
|
43452
|
-
if (!(super.optimizeNames(names,
|
|
43451
|
+
this.else = (_a6 = this.else) === null || _a6 === void 0 ? void 0 : _a6.optimizeNames(names, constants4);
|
|
43452
|
+
if (!(super.optimizeNames(names, constants4) || this.else))
|
|
43453
43453
|
return;
|
|
43454
|
-
this.condition = optimizeExpr(this.condition, names,
|
|
43454
|
+
this.condition = optimizeExpr(this.condition, names, constants4);
|
|
43455
43455
|
return this;
|
|
43456
43456
|
}
|
|
43457
43457
|
get names() {
|
|
@@ -43474,10 +43474,10 @@ var require_codegen = __commonJS({
|
|
|
43474
43474
|
render(opts) {
|
|
43475
43475
|
return `for(${this.iteration})` + super.render(opts);
|
|
43476
43476
|
}
|
|
43477
|
-
optimizeNames(names,
|
|
43478
|
-
if (!super.optimizeNames(names,
|
|
43477
|
+
optimizeNames(names, constants4) {
|
|
43478
|
+
if (!super.optimizeNames(names, constants4))
|
|
43479
43479
|
return;
|
|
43480
|
-
this.iteration = optimizeExpr(this.iteration, names,
|
|
43480
|
+
this.iteration = optimizeExpr(this.iteration, names, constants4);
|
|
43481
43481
|
return this;
|
|
43482
43482
|
}
|
|
43483
43483
|
get names() {
|
|
@@ -43513,10 +43513,10 @@ var require_codegen = __commonJS({
|
|
|
43513
43513
|
render(opts) {
|
|
43514
43514
|
return `for(${this.varKind} ${this.name} ${this.loop} ${this.iterable})` + super.render(opts);
|
|
43515
43515
|
}
|
|
43516
|
-
optimizeNames(names,
|
|
43517
|
-
if (!super.optimizeNames(names,
|
|
43516
|
+
optimizeNames(names, constants4) {
|
|
43517
|
+
if (!super.optimizeNames(names, constants4))
|
|
43518
43518
|
return;
|
|
43519
|
-
this.iterable = optimizeExpr(this.iterable, names,
|
|
43519
|
+
this.iterable = optimizeExpr(this.iterable, names, constants4);
|
|
43520
43520
|
return this;
|
|
43521
43521
|
}
|
|
43522
43522
|
get names() {
|
|
@@ -43558,11 +43558,11 @@ var require_codegen = __commonJS({
|
|
|
43558
43558
|
(_b = this.finally) === null || _b === void 0 ? void 0 : _b.optimizeNodes();
|
|
43559
43559
|
return this;
|
|
43560
43560
|
}
|
|
43561
|
-
optimizeNames(names,
|
|
43561
|
+
optimizeNames(names, constants4) {
|
|
43562
43562
|
var _a6, _b;
|
|
43563
|
-
super.optimizeNames(names,
|
|
43564
|
-
(_a6 = this.catch) === null || _a6 === void 0 ? void 0 : _a6.optimizeNames(names,
|
|
43565
|
-
(_b = this.finally) === null || _b === void 0 ? void 0 : _b.optimizeNames(names,
|
|
43563
|
+
super.optimizeNames(names, constants4);
|
|
43564
|
+
(_a6 = this.catch) === null || _a6 === void 0 ? void 0 : _a6.optimizeNames(names, constants4);
|
|
43565
|
+
(_b = this.finally) === null || _b === void 0 ? void 0 : _b.optimizeNames(names, constants4);
|
|
43566
43566
|
return this;
|
|
43567
43567
|
}
|
|
43568
43568
|
get names() {
|
|
@@ -43863,7 +43863,7 @@ var require_codegen = __commonJS({
|
|
|
43863
43863
|
function addExprNames(names, from) {
|
|
43864
43864
|
return from instanceof code_1._CodeOrName ? addNames(names, from.names) : names;
|
|
43865
43865
|
}
|
|
43866
|
-
function optimizeExpr(expr, names,
|
|
43866
|
+
function optimizeExpr(expr, names, constants4) {
|
|
43867
43867
|
if (expr instanceof code_1.Name)
|
|
43868
43868
|
return replaceName(expr);
|
|
43869
43869
|
if (!canOptimize(expr))
|
|
@@ -43878,14 +43878,14 @@ var require_codegen = __commonJS({
|
|
|
43878
43878
|
return items;
|
|
43879
43879
|
}, []));
|
|
43880
43880
|
function replaceName(n) {
|
|
43881
|
-
const c =
|
|
43881
|
+
const c = constants4[n.str];
|
|
43882
43882
|
if (c === void 0 || names[n.str] !== 1)
|
|
43883
43883
|
return n;
|
|
43884
43884
|
delete names[n.str];
|
|
43885
43885
|
return c;
|
|
43886
43886
|
}
|
|
43887
43887
|
function canOptimize(e) {
|
|
43888
|
-
return e instanceof code_1._Code && e._items.some((c) => c instanceof code_1.Name && names[c.str] === 1 &&
|
|
43888
|
+
return e instanceof code_1._Code && e._items.some((c) => c instanceof code_1.Name && names[c.str] === 1 && constants4[c.str] !== void 0);
|
|
43889
43889
|
}
|
|
43890
43890
|
}
|
|
43891
43891
|
function subtractNames(names, from) {
|
|
@@ -71473,6 +71473,24 @@ function parseWorkerLabels(input2) {
|
|
|
71473
71473
|
}
|
|
71474
71474
|
}
|
|
71475
71475
|
|
|
71476
|
+
// ../../packages/shared/src/worker-health.ts
|
|
71477
|
+
var WORKER_HEALTH_BLOCKING_CHECKS = [
|
|
71478
|
+
"docker-daemon",
|
|
71479
|
+
"workspace-write"
|
|
71480
|
+
];
|
|
71481
|
+
var STATUS_ORDER = { ok: 0, warn: 1, error: 2 };
|
|
71482
|
+
function workerHealthIssues(report) {
|
|
71483
|
+
return [...report?.checks ?? []].filter((check2) => check2.status !== "ok").sort((a, b3) => STATUS_ORDER[b3.status] - STATUS_ORDER[a.status]);
|
|
71484
|
+
}
|
|
71485
|
+
function workerHealthBlocksClaims(report) {
|
|
71486
|
+
const issues = workerHealthIssues(report);
|
|
71487
|
+
if (issues.length === 0) return false;
|
|
71488
|
+
if (report?.claimsBlocked) return true;
|
|
71489
|
+
return issues.some(
|
|
71490
|
+
(check2) => check2.status === "error" && WORKER_HEALTH_BLOCKING_CHECKS.includes(check2.id)
|
|
71491
|
+
);
|
|
71492
|
+
}
|
|
71493
|
+
|
|
71476
71494
|
// ../../packages/shared/src/events.ts
|
|
71477
71495
|
var appEventSchema = external_exports.object({
|
|
71478
71496
|
id: external_exports.number(),
|
|
@@ -72705,6 +72723,7 @@ async function waitForImagePulls() {
|
|
|
72705
72723
|
await Promise.allSettled([...inFlight.values()]);
|
|
72706
72724
|
}
|
|
72707
72725
|
var PLATFORM_MISMATCH = /no matching manifest|does not match the specified platform|no matching entries in manifest/i;
|
|
72726
|
+
var DOCKER_UNREACHABLE = /connect E[A-Z]+|\bE(?:ACCES|PERM|NOENT|ISDIR|CONNREFUSED|CONNRESET|TIMEDOUT)\b/;
|
|
72708
72727
|
function pullStreamError(line) {
|
|
72709
72728
|
try {
|
|
72710
72729
|
const parsed = JSON.parse(line);
|
|
@@ -72821,15 +72840,21 @@ async function ensureDockerImage(input2) {
|
|
|
72821
72840
|
} catch (error63) {
|
|
72822
72841
|
if (input2.signal?.aborted) throw error63;
|
|
72823
72842
|
const reason = error63 instanceof Error ? error63.message : String(error63);
|
|
72843
|
+
if (DOCKER_UNREACHABLE.test(reason)) {
|
|
72844
|
+
throw new Error(
|
|
72845
|
+
`Docker daemon unreachable while pulling ${input2.image}: ${reason}. Fix the socket mount or DOCKER_GID before changing the image or the registry login.`
|
|
72846
|
+
);
|
|
72847
|
+
}
|
|
72824
72848
|
throw new Error(
|
|
72825
72849
|
`Runner image ${input2.image} not found and could not be pulled: ${reason}. Check registry access or docker login, then retry: docker pull ${input2.image}`
|
|
72826
72850
|
);
|
|
72827
72851
|
}
|
|
72828
72852
|
try {
|
|
72829
72853
|
await input2.client.getImage(input2.image).inspect();
|
|
72830
|
-
} catch {
|
|
72854
|
+
} catch (error63) {
|
|
72855
|
+
const reason = error63 instanceof Error ? error63.message : String(error63);
|
|
72831
72856
|
throw new Error(
|
|
72832
|
-
`Runner image ${input2.image} pull finished but the image is still missing locally. Retry: docker pull ${input2.image}`
|
|
72857
|
+
`Runner image ${input2.image} pull finished but the image is still missing locally: ${reason}. Retry: docker pull ${input2.image}`
|
|
72833
72858
|
);
|
|
72834
72859
|
}
|
|
72835
72860
|
input2.log?.("runner image pulled", { image: input2.image });
|
|
@@ -72938,9 +72963,12 @@ function agentHostResources(resources) {
|
|
|
72938
72963
|
|
|
72939
72964
|
// src/runner-cache.ts
|
|
72940
72965
|
var RUNNER_CACHE_ENTRIES = [
|
|
72941
|
-
{ id: "npm", containerPath: "/root/.npm", description: "npm and
|
|
72966
|
+
{ id: "npm", containerPath: "/root/.npm", description: "npm metadata and tarballs" },
|
|
72942
72967
|
{ id: "pnpm", containerPath: "/root/.local/share/pnpm/store", description: "pnpm content-addressable store" },
|
|
72943
72968
|
{ id: "yarn", containerPath: "/root/.yarn/berry/cache", description: "Yarn Berry cache" },
|
|
72969
|
+
// Yarn classic writes elsewhere when it runs as root: it uses
|
|
72970
|
+
// /usr/local/share/.cache/yarn/v6 instead of ~/.cache/yarn.
|
|
72971
|
+
{ id: "yarn-classic", containerPath: "/usr/local/share/.cache/yarn", description: "Yarn classic cache" },
|
|
72944
72972
|
{ id: "bun", containerPath: "/root/.bun/install/cache", description: "Bun install cache" },
|
|
72945
72973
|
{ id: "pip", containerPath: "/root/.cache/pip", description: "pip wheel and HTTP cache" },
|
|
72946
72974
|
{ id: "uv", containerPath: "/root/.cache/uv", description: "uv cache" },
|
|
@@ -72951,6 +72979,9 @@ var RUNNER_CACHE_ENTRIES = [
|
|
|
72951
72979
|
{ id: "composer", containerPath: "/root/.cache/composer", description: "Composer package cache" },
|
|
72952
72980
|
{ id: "maven", containerPath: "/root/.m2/repository", description: "Maven local repository" },
|
|
72953
72981
|
{ id: "gradle", containerPath: "/root/.gradle/caches", description: "Gradle dependency cache" },
|
|
72982
|
+
// The wrapper downloads the Gradle distribution itself into a sibling
|
|
72983
|
+
// directory, which is the largest cold download of a Gradle job.
|
|
72984
|
+
{ id: "gradle-wrapper", containerPath: "/root/.gradle/wrapper", description: "Gradle wrapper distributions" },
|
|
72954
72985
|
// Browser builds are directory-per-revision, so two jobs running different
|
|
72955
72986
|
// Playwright versions on this host never write the same files.
|
|
72956
72987
|
{ id: "playwright", containerPath: "/root/.cache/ms-playwright", description: "Playwright browser builds" }
|
|
@@ -73061,14 +73092,29 @@ function remoteDockerClient(socketPath) {
|
|
|
73061
73092
|
defaultClients.set(socketPath, client);
|
|
73062
73093
|
return client;
|
|
73063
73094
|
}
|
|
73095
|
+
async function assertDockerDaemon(client, socketPath) {
|
|
73096
|
+
try {
|
|
73097
|
+
await client.info();
|
|
73098
|
+
} catch (error63) {
|
|
73099
|
+
const reason = error63 instanceof Error ? error63.message : String(error63);
|
|
73100
|
+
throw new Error(
|
|
73101
|
+
`Docker daemon at ${socketPath} is not reachable: ${reason}. Check the socket mount and DOCKER_GID; the worker stays offline until Docker answers.`
|
|
73102
|
+
);
|
|
73103
|
+
}
|
|
73104
|
+
}
|
|
73064
73105
|
async function createDockerJobExecutor(input2) {
|
|
73065
73106
|
const client = input2.client ?? remoteDockerClient(input2.socketPath ?? "/var/run/docker.sock");
|
|
73066
|
-
|
|
73067
|
-
|
|
73068
|
-
|
|
73069
|
-
|
|
73070
|
-
|
|
73071
|
-
|
|
73107
|
+
try {
|
|
73108
|
+
await ensureDockerImage({
|
|
73109
|
+
client,
|
|
73110
|
+
image: input2.image,
|
|
73111
|
+
signal: input2.signal,
|
|
73112
|
+
log: input2.log
|
|
73113
|
+
});
|
|
73114
|
+
} catch (error63) {
|
|
73115
|
+
input2.onImagePullError?.(error63 instanceof Error ? error63.message : String(error63));
|
|
73116
|
+
throw error63;
|
|
73117
|
+
}
|
|
73072
73118
|
if (input2.signal?.aborted) throw new Error("Job cancelled before the runner container started");
|
|
73073
73119
|
const { hostPath } = mapDockerWorkspace({
|
|
73074
73120
|
workspaceRoot: input2.workspaceRoot,
|
|
@@ -73201,9 +73247,11 @@ async function prefetchRunnerImage(input2) {
|
|
|
73201
73247
|
if (result === "present") input2.log?.("runner image ready", { image: input2.image });
|
|
73202
73248
|
return true;
|
|
73203
73249
|
} catch (error63) {
|
|
73250
|
+
const message = error63 instanceof Error ? error63.message : String(error63);
|
|
73251
|
+
input2.onError?.(message);
|
|
73204
73252
|
input2.log?.("runner image unavailable", {
|
|
73205
73253
|
image: input2.image,
|
|
73206
|
-
error:
|
|
73254
|
+
error: message
|
|
73207
73255
|
});
|
|
73208
73256
|
return false;
|
|
73209
73257
|
}
|
|
@@ -88224,7 +88272,11 @@ async function heartbeat(config2, token3, fetchImpl, signal) {
|
|
|
88224
88272
|
fetchImpl,
|
|
88225
88273
|
"/api/workers/heartbeat",
|
|
88226
88274
|
token3,
|
|
88227
|
-
{
|
|
88275
|
+
{
|
|
88276
|
+
version: config2.version,
|
|
88277
|
+
capacity: config2.capacity,
|
|
88278
|
+
...config2.health ? { health: config2.health.snapshot() } : {}
|
|
88279
|
+
},
|
|
88228
88280
|
signal
|
|
88229
88281
|
);
|
|
88230
88282
|
if (!response.ok) throw await errorFrom(response);
|
|
@@ -88647,6 +88699,7 @@ async function runRemoteWorker(config2, deps = {}) {
|
|
|
88647
88699
|
let capacityNoticeLogged = false;
|
|
88648
88700
|
const sendHeartbeat = async () => {
|
|
88649
88701
|
try {
|
|
88702
|
+
await config2.health?.refresh().catch(() => void 0);
|
|
88650
88703
|
const info = await heartbeat(config2, resolved.token, fetchImpl, controller.signal);
|
|
88651
88704
|
const desired = info.desiredCapacity;
|
|
88652
88705
|
if (!capacityNoticeLogged && typeof desired === "number" && desired !== workerCapacity(config2.capacity)) {
|
|
@@ -88715,6 +88768,16 @@ async function runRemoteWorker(config2, deps = {}) {
|
|
|
88715
88768
|
Math.min(workerCapacity(config2.capacity, resolved.capacity), workerCapacity(resolved.capacity))
|
|
88716
88769
|
);
|
|
88717
88770
|
let claimAttempt = 0;
|
|
88771
|
+
let blockedNotice = null;
|
|
88772
|
+
const reportBlockedWork = () => {
|
|
88773
|
+
const issues = workerHealthIssues(config2.health?.snapshot());
|
|
88774
|
+
const key = issues.map((issue2) => `${issue2.id}:${issue2.status}`).join(",");
|
|
88775
|
+
if (key === blockedNotice) return;
|
|
88776
|
+
blockedNotice = key;
|
|
88777
|
+
log("self-check blocking claims", {
|
|
88778
|
+
checks: issues.map((issue2) => ({ id: issue2.id, status: issue2.status, detail: issue2.detail }))
|
|
88779
|
+
});
|
|
88780
|
+
};
|
|
88718
88781
|
const backOffClaim = async (error63) => {
|
|
88719
88782
|
claimAttempt += 1;
|
|
88720
88783
|
const delay = claimBackoffMs(claimAttempt);
|
|
@@ -88730,6 +88793,15 @@ async function runRemoteWorker(config2, deps = {}) {
|
|
|
88730
88793
|
const runSlot = async () => {
|
|
88731
88794
|
while (!controller.signal.aborted) {
|
|
88732
88795
|
try {
|
|
88796
|
+
if (workerHealthBlocksClaims(config2.health?.snapshot())) {
|
|
88797
|
+
reportBlockedWork();
|
|
88798
|
+
await sleep2(5e3);
|
|
88799
|
+
continue;
|
|
88800
|
+
}
|
|
88801
|
+
if (blockedNotice !== null) {
|
|
88802
|
+
blockedNotice = null;
|
|
88803
|
+
log("self-check passed, claiming again");
|
|
88804
|
+
}
|
|
88733
88805
|
const result = await claim2(config2, resolved.token, fetchImpl, controller.signal);
|
|
88734
88806
|
if (claimAttempt > 0) {
|
|
88735
88807
|
log("claim recovered", { attempts: claimAttempt });
|
|
@@ -100652,7 +100724,8 @@ the configured image automatically; the default is
|
|
|
100652
100724
|
ghcr.io/h4kbas/aglio-runner:latest. A local build is pnpm runner:build. The
|
|
100653
100725
|
stock images do not include a browser; a browser-dependent job installs
|
|
100654
100726
|
Playwright and Chromium itself, for example with
|
|
100655
|
-
\`pnpm exec playwright install
|
|
100727
|
+
\`pnpm exec playwright install chromium\`. Chromium's system libraries are
|
|
100728
|
+
baked into the images, so \`--with-deps\` is unnecessary.
|
|
100656
100729
|
|
|
100657
100730
|
## Custom runner image
|
|
100658
100731
|
|
|
@@ -101871,6 +101944,145 @@ function createRemoteMcpHost(options) {
|
|
|
101871
101944
|
}
|
|
101872
101945
|
var REMOTE_MCP_TOOL_NAMES = [...REMOTE_RUN_TOOLS, ...PROJECT_AI_SETUP_TOOLS];
|
|
101873
101946
|
|
|
101947
|
+
// src/worker-health.ts
|
|
101948
|
+
import { access as access3, constants as constants3 } from "node:fs/promises";
|
|
101949
|
+
var REFRESH_INTERVAL_MS = 6e4;
|
|
101950
|
+
var PROBE_TIMEOUT_MS = 5e3;
|
|
101951
|
+
function withTimeout(work, ms2 = PROBE_TIMEOUT_MS) {
|
|
101952
|
+
return new Promise((resolvePromise, reject) => {
|
|
101953
|
+
const timer = setTimeout(() => reject(new Error(`check timed out after ${ms2} ms`)), ms2);
|
|
101954
|
+
timer.unref?.();
|
|
101955
|
+
work.then(
|
|
101956
|
+
(value) => {
|
|
101957
|
+
clearTimeout(timer);
|
|
101958
|
+
resolvePromise(value);
|
|
101959
|
+
},
|
|
101960
|
+
(error63) => {
|
|
101961
|
+
clearTimeout(timer);
|
|
101962
|
+
reject(error63);
|
|
101963
|
+
}
|
|
101964
|
+
);
|
|
101965
|
+
});
|
|
101966
|
+
}
|
|
101967
|
+
function errorText4(error63) {
|
|
101968
|
+
return error63 instanceof Error ? error63.message : String(error63);
|
|
101969
|
+
}
|
|
101970
|
+
function uniqueImages(images) {
|
|
101971
|
+
return [...new Set(images.map((image) => image.trim()).filter(Boolean))];
|
|
101972
|
+
}
|
|
101973
|
+
var WorkerHealthMonitor = class {
|
|
101974
|
+
constructor(input2) {
|
|
101975
|
+
this.input = input2;
|
|
101976
|
+
this.client = input2.mode === "docker" ? input2.client ?? remoteDockerClient(input2.socketPath) : null;
|
|
101977
|
+
this.images = uniqueImages(input2.runnerImages);
|
|
101978
|
+
}
|
|
101979
|
+
client;
|
|
101980
|
+
images;
|
|
101981
|
+
pullErrors = /* @__PURE__ */ new Map();
|
|
101982
|
+
lastRefreshedAt = 0;
|
|
101983
|
+
report = {
|
|
101984
|
+
checkedAt: (/* @__PURE__ */ new Date(0)).toISOString(),
|
|
101985
|
+
claimsBlocked: false,
|
|
101986
|
+
checks: []
|
|
101987
|
+
};
|
|
101988
|
+
/** Remember the last failed pull so the browser shows its reason, not just "missing". */
|
|
101989
|
+
recordPullFailure(image, message) {
|
|
101990
|
+
this.pullErrors.set(image, message);
|
|
101991
|
+
}
|
|
101992
|
+
/** Refresh at most once per interval unless `force` is set. */
|
|
101993
|
+
async refresh(force = false) {
|
|
101994
|
+
const now = Date.now();
|
|
101995
|
+
if (!force && now - this.lastRefreshedAt < REFRESH_INTERVAL_MS) return this.report;
|
|
101996
|
+
this.lastRefreshedAt = now;
|
|
101997
|
+
const checks = await Promise.all([
|
|
101998
|
+
this.dockerCheck(),
|
|
101999
|
+
this.runnerImageCheck(),
|
|
102000
|
+
this.workspaceCheck(),
|
|
102001
|
+
this.diskCheck()
|
|
102002
|
+
]);
|
|
102003
|
+
this.report = this.build(checks.filter((check2) => check2 !== null));
|
|
102004
|
+
return this.report;
|
|
102005
|
+
}
|
|
102006
|
+
snapshot() {
|
|
102007
|
+
return this.report;
|
|
102008
|
+
}
|
|
102009
|
+
build(checks) {
|
|
102010
|
+
return {
|
|
102011
|
+
checkedAt: (/* @__PURE__ */ new Date()).toISOString(),
|
|
102012
|
+
claimsBlocked: checks.some(
|
|
102013
|
+
(check2) => check2.status === "error" && WORKER_HEALTH_BLOCKING_CHECKS.includes(check2.id)
|
|
102014
|
+
),
|
|
102015
|
+
checks
|
|
102016
|
+
};
|
|
102017
|
+
}
|
|
102018
|
+
async dockerCheck() {
|
|
102019
|
+
if (!this.client) return null;
|
|
102020
|
+
try {
|
|
102021
|
+
const info = await withTimeout(this.client.info());
|
|
102022
|
+
return {
|
|
102023
|
+
id: "docker-daemon",
|
|
102024
|
+
status: "ok",
|
|
102025
|
+
detail: info?.ServerVersion ? `Docker ${info.ServerVersion}` : "Docker answered"
|
|
102026
|
+
};
|
|
102027
|
+
} catch (error63) {
|
|
102028
|
+
return { id: "docker-daemon", status: "error", detail: errorText4(error63) };
|
|
102029
|
+
}
|
|
102030
|
+
}
|
|
102031
|
+
async runnerImageCheck() {
|
|
102032
|
+
if (!this.client || this.images.length === 0) return null;
|
|
102033
|
+
const missing = [];
|
|
102034
|
+
for (const image of this.images) {
|
|
102035
|
+
try {
|
|
102036
|
+
await withTimeout(this.client.getImage(image).inspect());
|
|
102037
|
+
this.pullErrors.delete(image);
|
|
102038
|
+
} catch {
|
|
102039
|
+
missing.push(image);
|
|
102040
|
+
}
|
|
102041
|
+
}
|
|
102042
|
+
if (missing.length === 0) {
|
|
102043
|
+
return {
|
|
102044
|
+
id: "runner-image",
|
|
102045
|
+
status: "ok",
|
|
102046
|
+
detail: this.images.length === 1 ? this.images[0] : `${this.images.length} images ready`
|
|
102047
|
+
};
|
|
102048
|
+
}
|
|
102049
|
+
const failures = missing.map((image) => this.pullErrors.get(image)).filter((message) => Boolean(message));
|
|
102050
|
+
return {
|
|
102051
|
+
id: "runner-image",
|
|
102052
|
+
status: failures.length > 0 ? "error" : "warn",
|
|
102053
|
+
detail: failures.length > 0 ? `pull failed: ${failures[0]}` : `not pulled yet: ${missing.join(", ")}`
|
|
102054
|
+
};
|
|
102055
|
+
}
|
|
102056
|
+
async workspaceCheck() {
|
|
102057
|
+
const root = this.input.workspaceRoot?.trim();
|
|
102058
|
+
if (!root) return null;
|
|
102059
|
+
try {
|
|
102060
|
+
await access3(root, constants3.W_OK | constants3.X_OK);
|
|
102061
|
+
return { id: "workspace-write", status: "ok", detail: root };
|
|
102062
|
+
} catch (error63) {
|
|
102063
|
+
return { id: "workspace-write", status: "error", detail: `${root}: ${errorText4(error63)}` };
|
|
102064
|
+
}
|
|
102065
|
+
}
|
|
102066
|
+
async diskCheck() {
|
|
102067
|
+
const root = this.input.workspaceRoot?.trim();
|
|
102068
|
+
if (!root) return null;
|
|
102069
|
+
const space = await measureDiskSpace(root);
|
|
102070
|
+
const pressure = diskPressure(space, this.input.diskPolicy);
|
|
102071
|
+
if (!space) {
|
|
102072
|
+
return { id: "disk-space", status: "warn", detail: `could not measure ${root}` };
|
|
102073
|
+
}
|
|
102074
|
+
const freeGb = (space.freeBytes / GIB2).toFixed(1);
|
|
102075
|
+
const lowGb = (this.input.diskPolicy.minFreeBytes / GIB2).toFixed(1);
|
|
102076
|
+
if (pressure === "critical") {
|
|
102077
|
+
return { id: "disk-space", status: "error", detail: `${freeGb} GB free, below ${lowGb} GB` };
|
|
102078
|
+
}
|
|
102079
|
+
if (pressure === "low") {
|
|
102080
|
+
return { id: "disk-space", status: "warn", detail: `${freeGb} GB free, below ${lowGb} GB` };
|
|
102081
|
+
}
|
|
102082
|
+
return { id: "disk-space", status: "ok", detail: `${freeGb} GB free` };
|
|
102083
|
+
}
|
|
102084
|
+
};
|
|
102085
|
+
|
|
101874
102086
|
// src/remote-agent.ts
|
|
101875
102087
|
function required2(name2) {
|
|
101876
102088
|
const value = process.env[name2]?.trim();
|
|
@@ -101882,6 +102094,14 @@ function defaultOs() {
|
|
|
101882
102094
|
if (process.platform === "win32") return "windows";
|
|
101883
102095
|
return process.platform;
|
|
101884
102096
|
}
|
|
102097
|
+
async function dockerAgentResources(socketPath) {
|
|
102098
|
+
const client = remoteDockerClient(socketPath);
|
|
102099
|
+
await assertDockerDaemon(client, socketPath);
|
|
102100
|
+
return resolveRemoteAgentResources(
|
|
102101
|
+
client,
|
|
102102
|
+
(message, extra) => console.log(`[worker-agent] ${message}`, extra ?? "")
|
|
102103
|
+
);
|
|
102104
|
+
}
|
|
101885
102105
|
function agentVersion() {
|
|
101886
102106
|
const configured = process.env.AGLIO_WORKER_VERSION?.trim();
|
|
101887
102107
|
if (configured) return configured;
|
|
@@ -101952,6 +102172,18 @@ async function main() {
|
|
|
101952
102172
|
});
|
|
101953
102173
|
const runnerExtraHosts = sharesAgentNetwork(runnerNetwork) ? [] : process.platform === "linux" ? ["host.docker.internal:host-gateway"] : [];
|
|
101954
102174
|
const cacheBinds = mode === "docker" ? runnerCacheBinds() : [];
|
|
102175
|
+
const diskPolicy = resolveDiskGuardPolicy(process.env);
|
|
102176
|
+
const health = new WorkerHealthMonitor({
|
|
102177
|
+
mode,
|
|
102178
|
+
socketPath: dockerSocket,
|
|
102179
|
+
workspaceRoot,
|
|
102180
|
+
runnerImages: [
|
|
102181
|
+
...new Set([runnerImage, ...Object.values(runnerImages)].filter(
|
|
102182
|
+
(image) => Boolean(image)
|
|
102183
|
+
))
|
|
102184
|
+
],
|
|
102185
|
+
diskPolicy
|
|
102186
|
+
});
|
|
101955
102187
|
let mcpHost = null;
|
|
101956
102188
|
try {
|
|
101957
102189
|
mcpHost = createRemoteMcpHost({ port: mcpPort, baseUrl: containerMcpUrl });
|
|
@@ -101978,7 +102210,8 @@ async function main() {
|
|
|
101978
102210
|
runnerImages,
|
|
101979
102211
|
dockerSocket,
|
|
101980
102212
|
extraHosts: runnerExtraHosts,
|
|
101981
|
-
diskPolicy
|
|
102213
|
+
diskPolicy,
|
|
102214
|
+
health
|
|
101982
102215
|
};
|
|
101983
102216
|
const controller = new AbortController();
|
|
101984
102217
|
const stop = () => controller.abort();
|
|
@@ -101989,15 +102222,25 @@ async function main() {
|
|
|
101989
102222
|
);
|
|
101990
102223
|
const hostTools = await verifyHostRuntime({ mode, labels, platform: process.platform });
|
|
101991
102224
|
if (hostTools.length > 0) console.log(`[worker-agent] host tools ${hostTools.join(" | ")}`);
|
|
101992
|
-
|
|
101993
|
-
|
|
101994
|
-
|
|
101995
|
-
|
|
102225
|
+
let agentResources;
|
|
102226
|
+
if (mode === "docker") {
|
|
102227
|
+
try {
|
|
102228
|
+
agentResources = await dockerAgentResources(dockerSocket);
|
|
102229
|
+
} catch (error63) {
|
|
102230
|
+
console.error(
|
|
102231
|
+
`[worker-agent] ${error63 instanceof Error ? error63.message : String(error63)}`
|
|
102232
|
+
);
|
|
102233
|
+
}
|
|
102234
|
+
}
|
|
101996
102235
|
if (agentResources) {
|
|
101997
102236
|
console.log(
|
|
101998
102237
|
`[worker-agent] agent resources cpu=${agentResources.cpu} (${agentResources.cpuSource}) memoryBytes=${agentResources.memoryBytes} (${agentResources.memorySource})`
|
|
101999
102238
|
);
|
|
102000
102239
|
}
|
|
102240
|
+
const startupHealth = await health.refresh(true).catch(() => void 0);
|
|
102241
|
+
for (const issue2 of workerHealthIssues(startupHealth)) {
|
|
102242
|
+
console.error(`[worker-agent] self-check ${issue2.status} ${issue2.id}: ${issue2.detail}`);
|
|
102243
|
+
}
|
|
102001
102244
|
if (mode === "docker") {
|
|
102002
102245
|
const prefetchImages = poolBoot ? Object.values(runnerImages) : selectedVariants.map((variant) => runnerImages[variant] ?? runnerImage);
|
|
102003
102246
|
for (const image of new Set(
|
|
@@ -102007,7 +102250,8 @@ async function main() {
|
|
|
102007
102250
|
image,
|
|
102008
102251
|
refresh: !poolBoot,
|
|
102009
102252
|
socketPath: dockerSocket,
|
|
102010
|
-
log: (message, extra) => console.log(`[worker-agent] ${message}`, extra ?? "")
|
|
102253
|
+
log: (message, extra) => console.log(`[worker-agent] ${message}`, extra ?? ""),
|
|
102254
|
+
onError: (message) => health.recordPullFailure(image, message)
|
|
102011
102255
|
});
|
|
102012
102256
|
}
|
|
102013
102257
|
}
|
|
@@ -102016,26 +102260,30 @@ async function main() {
|
|
|
102016
102260
|
signal: controller.signal,
|
|
102017
102261
|
mcpHost: mcpHost ?? void 0,
|
|
102018
102262
|
runRoot: (workspace) => mode === "docker" ? "/workspace" : workspace,
|
|
102019
|
-
createExecutor: mode === "docker" ? ({ job, workspace, signal }) =>
|
|
102020
|
-
|
|
102021
|
-
workspace,
|
|
102022
|
-
workspaceRoot,
|
|
102023
|
-
hostWorkspaceRoot,
|
|
102024
|
-
signal,
|
|
102025
|
-
image: job.runnerImage ?? resolveRunnerImage({
|
|
102263
|
+
createExecutor: mode === "docker" ? ({ job, workspace, signal }) => {
|
|
102264
|
+
const image = job.runnerImage ?? resolveRunnerImage({
|
|
102026
102265
|
requiredLabels: job.requiredLabels,
|
|
102027
102266
|
images: runnerImages,
|
|
102028
102267
|
fallback: runnerImage
|
|
102029
|
-
})
|
|
102030
|
-
|
|
102031
|
-
|
|
102032
|
-
|
|
102033
|
-
|
|
102034
|
-
|
|
102035
|
-
|
|
102036
|
-
|
|
102037
|
-
|
|
102038
|
-
|
|
102268
|
+
});
|
|
102269
|
+
return createDockerJobExecutor({
|
|
102270
|
+
jobId: job.id,
|
|
102271
|
+
workspace,
|
|
102272
|
+
workspaceRoot,
|
|
102273
|
+
hostWorkspaceRoot,
|
|
102274
|
+
signal,
|
|
102275
|
+
image,
|
|
102276
|
+
socketPath: dockerSocket,
|
|
102277
|
+
networkMode: runnerNetwork,
|
|
102278
|
+
// Only the bridge fallback needs a host gateway. Docker Desktop
|
|
102279
|
+
// resolves host.docker.internal already; Linux needs the entry.
|
|
102280
|
+
extraHosts: runnerExtraHosts,
|
|
102281
|
+
resources: agentResources,
|
|
102282
|
+
cacheBinds,
|
|
102283
|
+
onImagePullError: (message) => health.recordPullFailure(image, message),
|
|
102284
|
+
log: (message, extra) => console.log(`[worker-agent] ${message}`, extra ?? "")
|
|
102285
|
+
});
|
|
102286
|
+
} : void 0
|
|
102039
102287
|
});
|
|
102040
102288
|
} finally {
|
|
102041
102289
|
await mcpHost?.close().catch(() => void 0);
|
|
@@ -102044,7 +102292,7 @@ async function main() {
|
|
|
102044
102292
|
}
|
|
102045
102293
|
main().catch((error63) => {
|
|
102046
102294
|
console.error(`[worker-agent] ${error63 instanceof Error ? error63.message : String(error63)}`);
|
|
102047
|
-
process.
|
|
102295
|
+
process.exit(2);
|
|
102048
102296
|
});
|
|
102049
102297
|
/*! Bundled license information:
|
|
102050
102298
|
|