@melite/estate-queue 0.3.0-rc.1 → 0.3.0-rc.2
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/README.md +18 -7
- package/lib/cardsCompose.d.ts +8 -0
- package/lib/cardsCompose.js +44 -4
- package/lib/cardsFacts.d.ts +40 -1
- package/lib/cardsFacts.js +43 -0
- package/lib/cardsRegistry.d.ts +11 -0
- package/lib/cardsRegistry.js +31 -5
- package/lib/engineQuiet.d.ts +37 -0
- package/lib/engineQuiet.js +107 -0
- package/lib/index.d.ts +10 -0
- package/lib/index.js +15 -0
- package/lib/lifecycleLatch.d.ts +21 -15
- package/lib/lifecycleLatch.js +44 -27
- package/lib/manageOps.d.ts +18 -0
- package/lib/manageOps.js +28 -29
- package/lib/managePlane.d.ts +13 -0
- package/lib/managePlane.js +146 -35
- package/lib/manageProbe.d.ts +22 -1
- package/lib/manageProbe.js +64 -7
- package/lib/manageRegistry.d.ts +14 -0
- package/lib/manageRegistry.js +6 -0
- package/lib/queueSidecar.d.ts +12 -2
- package/lib/queueSidecar.js +16 -3
- package/lib/runsExecute.d.ts +40 -0
- package/lib/runsExecute.js +93 -22
- package/lib/runsGates.js +1 -1
- package/lib/runsList.js +18 -1
- package/lib/runsRegistry.js +4 -3
- package/lib/runsStart.d.ts +5 -0
- package/lib/runsStart.js +3 -4
- package/lib/service.d.ts +8 -0
- package/lib/service.js +8 -0
- package/lib/vocab.d.ts +19 -0
- package/lib/vocab.js +19 -0
- package/package.json +8 -8
package/lib/manageOps.d.ts
CHANGED
|
@@ -11,6 +11,9 @@ export declare function mapManagerRefused(e: ManagerApiError, action: string): R
|
|
|
11
11
|
* so the fallthrough only guards the type, never a live error. */
|
|
12
12
|
export declare function mapRail(e: unknown, action: string): Refused;
|
|
13
13
|
export declare function railMs(req: Req): number;
|
|
14
|
+
/** Poll the vendor's task queue until drained (install arms: the
|
|
15
|
+
* vendor returns 202-semantics — queue accepted — and processes
|
|
16
|
+
* asynchronously; the poll bounds the AI door's wait). */
|
|
14
17
|
export declare function awaitQueueDrained(ctx: ManageCtx, req: Req): Promise<Record<string, unknown>>;
|
|
15
18
|
/** BYO guard: estate-orchestration legs (systemd, workspace reads)
|
|
16
19
|
* never touch a user-owned ComfyUI. */
|
|
@@ -24,4 +27,19 @@ export declare function estateOnly(req: Req, cfg: Record<string, unknown>): void
|
|
|
24
27
|
*/
|
|
25
28
|
export declare function systemctl(req: Req, verb: "start" | "stop", unit: string, signal?: AbortSignal): Promise<[number, ManageEnvelope]>;
|
|
26
29
|
export declare function guardLifecycle(req: Req, ctx: ManageCtx): void;
|
|
30
|
+
|
|
31
|
+
|
|
32
|
+
|
|
33
|
+
|
|
34
|
+
|
|
35
|
+
|
|
36
|
+
|
|
37
|
+
|
|
38
|
+
|
|
39
|
+
|
|
40
|
+
|
|
41
|
+
|
|
42
|
+
|
|
43
|
+
|
|
44
|
+
export declare function quietOrRefuse(req: Req, ctx: ManageCtx, action: "restart" | "stop"): Promise<void>;
|
|
27
45
|
//# sourceMappingURL=manageOps.d.ts.map
|
package/lib/manageOps.js
CHANGED
|
@@ -7,6 +7,7 @@ import { promisify } from "node:util";
|
|
|
7
7
|
import { activeRuns } from "./manageProbe.js";
|
|
8
8
|
import { ManagerApiError, managerBase, managerGet } from "./managerRail.js";
|
|
9
9
|
import { Refused } from "./managePlane.js";
|
|
10
|
+
import { abortReason, awaitEngineQuiet, seatSleep } from "./engineQuiet.js";
|
|
10
11
|
const execFileAsync = promisify(execFile);
|
|
11
12
|
// ── the manager rail (vendor HTTP — see manager-api.ts) ────────────
|
|
12
13
|
export function base(ctx) {
|
|
@@ -43,9 +44,6 @@ export function railMs(req) {
|
|
|
43
44
|
/** Poll the vendor's task queue until drained (install arms: the
|
|
44
45
|
* vendor returns 202-semantics — queue accepted — and processes
|
|
45
46
|
* asynchronously; the poll bounds the AI door's wait). */
|
|
46
|
-
function abortReason(signal) {
|
|
47
|
-
return signal.reason instanceof Error ? signal.reason : new DOMException("The operation was aborted", "AbortError");
|
|
48
|
-
}
|
|
49
47
|
export async function awaitQueueDrained(ctx, req) {
|
|
50
48
|
const deadline = Date.now() + railMs(req);
|
|
51
49
|
for (;;) {
|
|
@@ -70,34 +68,9 @@ export async function awaitQueueDrained(ctx, req) {
|
|
|
70
68
|
return st;
|
|
71
69
|
if (Date.now() >= deadline)
|
|
72
70
|
return { ...st, timed_out: true };
|
|
73
|
-
await
|
|
71
|
+
await seatSleep(ctx, 1000);
|
|
74
72
|
}
|
|
75
73
|
}
|
|
76
|
-
function waitForQueuePoll(ctx) {
|
|
77
|
-
const signal = ctx.signal;
|
|
78
|
-
if (signal?.aborted === true)
|
|
79
|
-
return Promise.reject(abortReason(signal));
|
|
80
|
-
return new Promise((resolvePromise, rejectPromise) => {
|
|
81
|
-
// The seat IS the timer (ManageCtx.timeout, the conformance
|
|
82
|
-
// stroke's no-bare-setTimeout guarantee): the poll waits on
|
|
83
|
-
// ctx.timeout and races the door's signal. No settled-flag dance
|
|
84
|
-
// -- a promise settles once, so the guard the wrapper carried
|
|
85
|
-
// was unreachable; the post-registration re-check closes the
|
|
86
|
-
// race where the signal aborts between the check above and the
|
|
87
|
-
// listener landing.
|
|
88
|
-
const dispose = ctx.timeout(() => {
|
|
89
|
-
signal?.removeEventListener('abort', onAbort);
|
|
90
|
-
resolvePromise();
|
|
91
|
-
}, 1000);
|
|
92
|
-
const onAbort = () => {
|
|
93
|
-
dispose();
|
|
94
|
-
rejectPromise(abortReason(signal));
|
|
95
|
-
};
|
|
96
|
-
signal?.addEventListener('abort', onAbort, { once: true });
|
|
97
|
-
if (signal?.aborted === true)
|
|
98
|
-
onAbort();
|
|
99
|
-
});
|
|
100
|
-
}
|
|
101
74
|
/** BYO guard: estate-orchestration legs (systemd, workspace reads)
|
|
102
75
|
* never touch a user-owned ComfyUI. */
|
|
103
76
|
export function estateOnly(req, cfg) {
|
|
@@ -160,4 +133,30 @@ export function guardLifecycle(req, ctx) {
|
|
|
160
133
|
") — wait for the fetch to land (poll acquire_weight) or pass force=true", { state: "conflict", next_action: "status" });
|
|
161
134
|
}
|
|
162
135
|
}
|
|
136
|
+
|
|
137
|
+
|
|
138
|
+
|
|
139
|
+
|
|
140
|
+
|
|
141
|
+
|
|
142
|
+
|
|
143
|
+
|
|
144
|
+
|
|
145
|
+
|
|
146
|
+
|
|
147
|
+
|
|
148
|
+
|
|
149
|
+
|
|
150
|
+
export async function quietOrRefuse(req, ctx, action) {
|
|
151
|
+
if (req.force)
|
|
152
|
+
return;
|
|
153
|
+
const budgetMs = railMs(req);
|
|
154
|
+
const verdict = await awaitEngineQuiet(ctx, budgetMs, ctx.engineQuiesceMs);
|
|
155
|
+
if (verdict.quiet)
|
|
156
|
+
return;
|
|
157
|
+
throw new Refused(409, "refused: the engine's queue is busy — " + verdict.running + " running, " + verdict.pending +
|
|
158
|
+
" pending (another lane's press, or a film between its windows) — not " +
|
|
159
|
+
(action === "restart" ? "restarted" : "stopped") + " after waiting " +
|
|
160
|
+
Math.round(budgetMs / 1000) + "s for a quiet queue; retry when it drains (comfy_manage status names the queue) or pass force=true", { state: "conflict", next_action: "status" });
|
|
161
|
+
}
|
|
163
162
|
//# sourceMappingURL=manageOps.js.map
|
package/lib/managePlane.d.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import type { ModelsService } from "@melite/comfyui-cordis";
|
|
2
2
|
import type { ProvisioningServiceDefinition } from "@melite/estate-provisioning";
|
|
3
|
+
import type { LifecycleLatch } from "./lifecycleLatch.js";
|
|
3
4
|
export declare const ACTIONS: readonly ["status", "endpoint_set", "logs", "search_models", "list_extensions", "snapshot_list", "install_extension", "install_extension_url", "download_model", "provision_model", "acquire_weight", "provision_runtime", "acquire_retry", "acquire_discard", "restart", "stop", "launch", "update", "switch_version", "free", "settle_stale", "snapshot_save", "snapshot_restore", "lora_list", "lora_install", "lora_fetch", "refmods_list", "preflight"];
|
|
4
5
|
export type ManageAction = (typeof ACTIONS)[number];
|
|
5
6
|
export declare const LIFECYCLE_GUARDED: ReadonlySet<ManageAction>;
|
|
@@ -25,6 +26,11 @@ export interface ManageEnvelope {
|
|
|
25
26
|
retry_after_ms?: number;
|
|
26
27
|
}
|
|
27
28
|
export interface ManageCtx {
|
|
29
|
+
|
|
30
|
+
|
|
31
|
+
|
|
32
|
+
|
|
33
|
+
latch: LifecycleLatch;
|
|
28
34
|
/** File-anchored repo root (routing, catalog, runs scan anchor). */
|
|
29
35
|
repoRoot: string;
|
|
30
36
|
/** The §23 cross-roots manifest (own state root first, then the
|
|
@@ -41,6 +47,13 @@ export interface ManageCtx {
|
|
|
41
47
|
* operator confirm — the raw-URL arms stay operator-gated in the
|
|
42
48
|
* deck's own gate regardless of this value. */
|
|
43
49
|
autoProvision: boolean;
|
|
50
|
+
|
|
51
|
+
|
|
52
|
+
|
|
53
|
+
|
|
54
|
+
|
|
55
|
+
|
|
56
|
+
engineQuiesceMs: number;
|
|
44
57
|
/** The endpoint config, re-read per call (fresh — never cached
|
|
45
58
|
* between calls): carries the engine url the manager rail rides.
|
|
46
59
|
* The bridges door passes loadEndpointConfig itself. */
|
package/lib/managePlane.js
CHANGED
|
@@ -22,10 +22,9 @@ import { installUserLora, installUserLoraBytes, loraNamesFromObjectInfo, readUse
|
|
|
22
22
|
import { rearmLoraFlavors } from "@melite/comfyui-cordis";
|
|
23
23
|
import { AcquireBusyError, LIVE_ACQUIRE_STATES } from "@melite/estate-provisioning";
|
|
24
24
|
import { ManagerApiError, managerGet, managerPost, planeUnavailable } from "./managerRail.js";
|
|
25
|
-
import { probeEndpoint, activeRuns, managerSecurity, engineQueueView, settleStaleClaims, engineUnitCensus, countOomLines } from "./manageProbe.js";
|
|
25
|
+
import { probeEndpoint, activeRuns, managerSecurity, engineQueueView, settleStaleClaims, engineUnitCensus, countOomLines, censusEnv } from "./manageProbe.js";
|
|
26
26
|
import { runPreflight, preflightLine } from "./managePreflight.js";
|
|
27
|
-
import { base, mapManagerRefused, mapRail, railMs, estateOnly, awaitQueueDrained, systemctl, guardLifecycle } from "./manageOps.js";
|
|
28
|
-
import { holdLifecycle } from "./lifecycleLatch.js";
|
|
27
|
+
import { base, mapManagerRefused, mapRail, railMs, estateOnly, awaitQueueDrained, systemctl, guardLifecycle, quietOrRefuse } from "./manageOps.js";
|
|
29
28
|
import { deadline as deadlineOf, timeoutOf } from "@deepseek-ai/dsh-timeout";
|
|
30
29
|
import { segmentConfined } from "@melite/contracts/mediaKinds";
|
|
31
30
|
import { artifactFileName } from "@melite/contracts/benchResult";
|
|
@@ -352,7 +351,27 @@ async function recordEngineBoot(ctx, source) {
|
|
|
352
351
|
return;
|
|
353
352
|
}
|
|
354
353
|
}
|
|
355
|
-
|
|
354
|
+
|
|
355
|
+
|
|
356
|
+
|
|
357
|
+
|
|
358
|
+
|
|
359
|
+
|
|
360
|
+
|
|
361
|
+
|
|
362
|
+
|
|
363
|
+
|
|
364
|
+
|
|
365
|
+
|
|
366
|
+
function engineBootRow(ctx, census) {
|
|
367
|
+
if (census?.started_at !== undefined) {
|
|
368
|
+
return {
|
|
369
|
+
known: true,
|
|
370
|
+
boot_at: census.started_at,
|
|
371
|
+
age_seconds: Math.max(0, Math.round((Date.now() - Date.parse(census.started_at)) / 1000)),
|
|
372
|
+
source: "systemd: " + census.unit + " ExecMainStartTimestamp",
|
|
373
|
+
};
|
|
374
|
+
}
|
|
356
375
|
try {
|
|
357
376
|
const raw = JSON.parse(readFileSync(engineBootReceiptPath(ctx), "utf8"));
|
|
358
377
|
const bootAt = typeof raw.boot_at === "number" ? raw.boot_at : NaN;
|
|
@@ -384,12 +403,18 @@ function safeStatusItems(items) {
|
|
|
384
403
|
...(item.detail === undefined ? {} : { detail: item.detail }),
|
|
385
404
|
}));
|
|
386
405
|
}
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
406
|
+
/** @param row - the status row.
|
|
407
|
+
* @param operation - the row's stored operation, when the seat has one.
|
|
408
|
+
* @returns the row with the operation's clock; an unstamped record
|
|
409
|
+
* (startedAt 0 — a seat that keeps no clock) adds nothing. */
|
|
410
|
+
function withOperationClock(row, operation) {
|
|
411
|
+
if (operation === undefined || typeof operation.startedAt !== "number" || operation.startedAt === 0)
|
|
412
|
+
return row;
|
|
413
|
+
return {
|
|
414
|
+
...row,
|
|
415
|
+
started_at: new Date(operation.startedAt).toISOString(),
|
|
416
|
+
...(typeof operation.finishedAt === "number" ? { finished_at: new Date(operation.finishedAt).toISOString() } : {}),
|
|
417
|
+
};
|
|
393
418
|
}
|
|
394
419
|
|
|
395
420
|
|
|
@@ -401,12 +426,11 @@ async function normalizedResources(resources, provisioning) {
|
|
|
401
426
|
|
|
402
427
|
|
|
403
428
|
async function normalizeResource(resource, provisioning) {
|
|
404
|
-
const row =
|
|
429
|
+
const row = withOperationClock;
|
|
430
|
+
const bare = () => ({
|
|
405
431
|
...resource,
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
...(operationId === undefined ? {} : { operationId }),
|
|
409
|
-
...(detail === undefined ? {} : { detail }),
|
|
432
|
+
...(resource.operationId === undefined ? {} : { operationId: resource.operationId }),
|
|
433
|
+
...(resource.detail === undefined ? {} : { detail: resource.detail }),
|
|
410
434
|
});
|
|
411
435
|
if (provisioning === undefined) {
|
|
412
436
|
|
|
@@ -415,29 +439,48 @@ async function normalizeResource(resource, provisioning) {
|
|
|
415
439
|
|
|
416
440
|
|
|
417
441
|
|
|
418
|
-
return
|
|
442
|
+
return bare();
|
|
419
443
|
}
|
|
420
444
|
try {
|
|
421
445
|
const operation = provisioning.operationOf(resource.ref);
|
|
422
|
-
if (operation === undefined)
|
|
423
|
-
return
|
|
424
|
-
}
|
|
446
|
+
if (operation === undefined)
|
|
447
|
+
return bare();
|
|
425
448
|
const verified = provisioning.verifyOperation === undefined
|
|
426
449
|
? operation
|
|
427
450
|
: await provisioning.verifyOperation(operation);
|
|
428
451
|
if (verified.state !== operation.state) {
|
|
429
|
-
return row(
|
|
452
|
+
return row({
|
|
453
|
+
...resource,
|
|
454
|
+
operationId: verified.operationId,
|
|
455
|
+
state: verified.state,
|
|
456
|
+
items: verified.items,
|
|
457
|
+
...(verified.items[0]?.detail === undefined && resource.detail === undefined ? {} : { detail: verified.items[0]?.detail ?? resource.detail }),
|
|
458
|
+
}, operation);
|
|
430
459
|
}
|
|
431
|
-
return row(
|
|
460
|
+
return row({
|
|
461
|
+
...resource,
|
|
462
|
+
operationId: operation.operationId,
|
|
463
|
+
state: operation.state,
|
|
464
|
+
items: operation.items,
|
|
465
|
+
...(resource.detail ?? operation.detail) === undefined ? {} : { detail: resource.detail ?? operation.detail },
|
|
466
|
+
}, operation);
|
|
432
467
|
}
|
|
433
468
|
catch {
|
|
434
|
-
return
|
|
469
|
+
return bare();
|
|
470
|
+
}
|
|
471
|
+
}
|
|
472
|
+
async function normalizedResources(resources, provisioning) {
|
|
473
|
+
const rows = [];
|
|
474
|
+
for (const resource of resources) {
|
|
475
|
+
rows.push(await normalizeResource(resource, provisioning));
|
|
435
476
|
}
|
|
477
|
+
return rows;
|
|
436
478
|
}
|
|
437
479
|
function operationRows(resources) {
|
|
438
480
|
return resources.flatMap((resource) => {
|
|
439
481
|
const operationId = resource.operationId;
|
|
440
482
|
const first = resource.items[0];
|
|
483
|
+
const timed = resource;
|
|
441
484
|
return operationId === undefined ? [] : [{
|
|
442
485
|
operation_id: operationId,
|
|
443
486
|
name: resource.ref.id,
|
|
@@ -445,6 +488,8 @@ function operationRows(resources) {
|
|
|
445
488
|
...(first?.path === undefined ? {} : { path: first.path }),
|
|
446
489
|
state: resource.state,
|
|
447
490
|
outcome: statusOutcome(resource.state),
|
|
491
|
+
...(timed.started_at === undefined ? {} : { started_at: timed.started_at }),
|
|
492
|
+
...(timed.finished_at === undefined ? {} : { finished_at: timed.finished_at }),
|
|
448
493
|
items: safeStatusItems(resource.items),
|
|
449
494
|
next_action: resource.state === "restart_required" || resource.state === "installed" ? "restart" : "status",
|
|
450
495
|
}];
|
|
@@ -668,7 +713,7 @@ async function hStatus(req, ctx) {
|
|
|
668
713
|
...(active.length > 1 && !engineIdle
|
|
669
714
|
? { active_runs_note: active.length + " claims; the one-run law bounds machine-wide actives at 1 — the surplus is unsettled sidecars (historical); the engine queue corroborates only when empty" }
|
|
670
715
|
: {}),
|
|
671
|
-
engine_boot: engineBootRow(ctx),
|
|
716
|
+
engine_boot: engineBootRow(ctx, census),
|
|
672
717
|
engine_unit: census,
|
|
673
718
|
routing,
|
|
674
719
|
auto_provision: ctx.autoProvision,
|
|
@@ -733,6 +778,7 @@ async function unitAppLogPath(ctx) {
|
|
|
733
778
|
const out = await execFileAsync("systemctl", ["--user", "cat", ctx.comfyUnit], {
|
|
734
779
|
timeout: 5 * 1000,
|
|
735
780
|
encoding: "utf8",
|
|
781
|
+
env: censusEnv(),
|
|
736
782
|
});
|
|
737
783
|
const m = /^StandardOutput=(?:append:|file:)(\S+)/m.exec(out.stdout);
|
|
738
784
|
return m === null ? null : m[1];
|
|
@@ -777,7 +823,7 @@ function tailLines(path, max) {
|
|
|
777
823
|
* @param path the RESOLVED application-log path (the unit's own
|
|
778
824
|
* StandardOutput directive first — the deployment's truth — then
|
|
779
825
|
* the canonical derivation; null when neither seat produced one). */
|
|
780
|
-
function appLogRow(ctx, path, tail) {
|
|
826
|
+
function appLogRow(ctx, path, tail, census) {
|
|
781
827
|
if (path === null) {
|
|
782
828
|
return {
|
|
783
829
|
known: false,
|
|
@@ -801,7 +847,7 @@ function appLogRow(ctx, path, tail) {
|
|
|
801
847
|
};
|
|
802
848
|
}
|
|
803
849
|
const ageSeconds = Math.max(0, Math.round((Date.now() - mtimeMs) / 1000));
|
|
804
|
-
const boot = engineBootRow(ctx);
|
|
850
|
+
const boot = engineBootRow(ctx, census);
|
|
805
851
|
const bootMs = boot.known === true && typeof boot.boot_at === "string" ? Date.parse(boot.boot_at) : NaN;
|
|
806
852
|
const fresh = ageSeconds * 1000 <= APP_LOG_FRESH_MS || (Number.isFinite(bootMs) && mtimeMs >= bootMs);
|
|
807
853
|
if (!fresh) {
|
|
@@ -848,10 +894,13 @@ async function hLogs(req, ctx) {
|
|
|
848
894
|
const tail = Math.max(1, Math.min(Math.trunc(req.tail), 2000));
|
|
849
895
|
let stdout;
|
|
850
896
|
try {
|
|
897
|
+
|
|
898
|
+
// same env the census does — a scrubbed lane found no user journal.
|
|
851
899
|
const out = await execFileAsync("journalctl", ["--user", "-u", ctx.comfyUnit, "-n", String(tail), "--no-pager", "-o", "cat"], {
|
|
852
900
|
timeout: 15 * 1000,
|
|
853
901
|
encoding: "utf8",
|
|
854
902
|
signal: ctx.signal,
|
|
903
|
+
env: censusEnv(),
|
|
855
904
|
});
|
|
856
905
|
stdout = out.stdout;
|
|
857
906
|
}
|
|
@@ -872,7 +921,11 @@ async function hLogs(req, ctx) {
|
|
|
872
921
|
// not own it (the logs-truth law, unchanged).
|
|
873
922
|
const port = appLogPort(ctx);
|
|
874
923
|
const unitPath = port !== null ? await unitAppLogPath(ctx) : null;
|
|
875
|
-
const
|
|
924
|
+
const appLogPathRow = unitPath ?? (port !== null ? appLogPath(ctx, port) : null);
|
|
925
|
+
// the fresh bound judges against the unit's own start when systemd
|
|
926
|
+
// answers (S1) — only a resolved path pays the census exec
|
|
927
|
+
const appLogCensus = appLogPathRow === null ? Promise.resolve(undefined) : engineUnitCensus(ctx);
|
|
928
|
+
const appLog = appLogRow(ctx, appLogPathRow, tail, await appLogCensus);
|
|
876
929
|
const data = {
|
|
877
930
|
source: {
|
|
878
931
|
kind: "journal",
|
|
@@ -1923,8 +1976,15 @@ async function hRestart(req, ctx) {
|
|
|
1923
1976
|
const cfg = ctx.endpoint();
|
|
1924
1977
|
estateOnly(req, cfg);
|
|
1925
1978
|
|
|
1979
|
+
// an engine queue that is empty and stays empty — a film pressing
|
|
1980
|
+
// from another lane is a row there, invisible to the lifecycle
|
|
1981
|
+
// guard's own-roots census. The latch is taken only after the
|
|
1982
|
+
// verdict, across the vendor call (a same-lane press during the
|
|
1983
|
+
// wait lands and is itself the busy signal).
|
|
1984
|
+
await quietOrRefuse(req, ctx, "restart");
|
|
1985
|
+
|
|
1926
1986
|
// call so a run pressed mid-reboot refuses instead of tearing.
|
|
1927
|
-
const releaseLifecycle =
|
|
1987
|
+
const releaseLifecycle = ctx.latch.hold(req.action);
|
|
1928
1988
|
try {
|
|
1929
1989
|
await managerPost(base(ctx), "/manager/reboot", {}, { ctx, timeoutMs: 10_000 });
|
|
1930
1990
|
|
|
@@ -1968,7 +2028,8 @@ async function hStop(req, ctx) {
|
|
|
1968
2028
|
estateOnly(req, ctx.endpoint());
|
|
1969
2029
|
|
|
1970
2030
|
// systemctl call so a run pressed mid-stop refuses.
|
|
1971
|
-
|
|
2031
|
+
await quietOrRefuse(req, ctx, "stop");
|
|
2032
|
+
const releaseLifecycle = ctx.latch.hold(req.action);
|
|
1972
2033
|
try {
|
|
1973
2034
|
return await systemctl(req, "stop", ctx.comfyUnit, ctx.signal);
|
|
1974
2035
|
}
|
|
@@ -1986,7 +2047,7 @@ async function hLaunch(req, ctx) {
|
|
|
1986
2047
|
// rides the lifecycle latch like every sibling teardown, so the
|
|
1987
2048
|
// re-arm actually re-arms: the seat re-binds to the launch action
|
|
1988
2049
|
// across the call and releases on settle.
|
|
1989
|
-
const releaseLifecycle =
|
|
2050
|
+
const releaseLifecycle = ctx.latch.hold(req.action);
|
|
1990
2051
|
try {
|
|
1991
2052
|
return await systemctl(req, "start", ctx.comfyUnit, ctx.signal);
|
|
1992
2053
|
}
|
|
@@ -2003,7 +2064,7 @@ async function hUpdate(req, ctx) {
|
|
|
2003
2064
|
estateOnly(req, cfg);
|
|
2004
2065
|
|
|
2005
2066
|
// calls so a run pressed mid-update refuses instead of tearing.
|
|
2006
|
-
const releaseLifecycle =
|
|
2067
|
+
const releaseLifecycle = ctx.latch.hold(req.action);
|
|
2007
2068
|
try {
|
|
2008
2069
|
await managerPost(base(ctx), "/manager/queue/update_comfyui", {}, { ctx, timeoutMs: 10_000 });
|
|
2009
2070
|
await managerPost(base(ctx), "/manager/queue/start", {}, { ctx, timeoutMs: 10_000 });
|
|
@@ -2039,7 +2100,7 @@ async function hSwitchVersion(req, ctx) {
|
|
|
2039
2100
|
estateOnly(req, cfg);
|
|
2040
2101
|
|
|
2041
2102
|
// switch so a run pressed mid-switch refuses instead of tearing.
|
|
2042
|
-
const releaseLifecycle =
|
|
2103
|
+
const releaseLifecycle = ctx.latch.hold(req.action);
|
|
2043
2104
|
try {
|
|
2044
2105
|
const doc = await managerGet(base(ctx), "/comfyui_manager/comfyui_versions", {
|
|
2045
2106
|
ctx, timeoutMs: 30_000,
|
|
@@ -2071,11 +2132,18 @@ async function hFree(req, ctx) {
|
|
|
2071
2132
|
throw planeUnavailable(b, "no endpoint url");
|
|
2072
2133
|
|
|
2073
2134
|
// call so a run pressed mid-free refuses instead of tearing.
|
|
2074
|
-
const releaseLifecycle =
|
|
2135
|
+
const releaseLifecycle = ctx.latch.hold(req.action);
|
|
2075
2136
|
// THE WARMED-SEAT COUNT, ANSWERED (qa8 F42): the envelope carries
|
|
2076
2137
|
// what the chain released — never the silent no-op face the burn
|
|
2077
2138
|
// served ("free issued" while 8.35 GB stayed resident).
|
|
2078
2139
|
let warmed;
|
|
2140
|
+
|
|
2141
|
+
// free answered "free issued" while the engine left — two presses
|
|
2142
|
+
// ~10s later died `fetch failed` + `comfyui is unreachable`. The
|
|
2143
|
+
// answer names which path the free took: the unit census before
|
|
2144
|
+
// and after (a moved boot is a restart under the free), plus the
|
|
2145
|
+
// post-free /system_stats read (reachable or still coming back).
|
|
2146
|
+
const censusBefore = await engineUnitCensus(ctx);
|
|
2079
2147
|
try {
|
|
2080
2148
|
await managerPost(b, "/free", { unload_models: true, free_memory: true }, { ctx, timeoutMs: 30_000 });
|
|
2081
2149
|
}
|
|
@@ -2107,7 +2175,48 @@ async function hFree(req, ctx) {
|
|
|
2107
2175
|
finally {
|
|
2108
2176
|
releaseLifecycle();
|
|
2109
2177
|
}
|
|
2110
|
-
|
|
2178
|
+
// THE FREE'S VERDICT (B12): restart-vs-unload, answered — never
|
|
2179
|
+
// the bare "free issued" the burn served while the engine left.
|
|
2180
|
+
const censusAfter = await engineUnitCensus(ctx);
|
|
2181
|
+
const probe = await probeEndpoint(ctx);
|
|
2182
|
+
return ok(req.action, freeVoice(censusBefore, censusAfter, probe.reachable, warmed), {
|
|
2183
|
+
next_action: "status",
|
|
2184
|
+
free_restarted: freeRestarted(censusBefore, censusAfter),
|
|
2185
|
+
engine_boot_before: engineBootRow(ctx, censusBefore),
|
|
2186
|
+
engine_boot_after: engineBootRow(ctx, censusAfter),
|
|
2187
|
+
post_free_reachable: probe.reachable,
|
|
2188
|
+
});
|
|
2189
|
+
}
|
|
2190
|
+
|
|
2191
|
+
|
|
2192
|
+
|
|
2193
|
+
|
|
2194
|
+
function freeRestarted(before, after) {
|
|
2195
|
+
if (before.started_at === undefined || after.started_at === undefined)
|
|
2196
|
+
return "unknown";
|
|
2197
|
+
return before.started_at !== after.started_at;
|
|
2198
|
+
}
|
|
2199
|
+
/** The free's own voice (B12): names the path the census judged —
|
|
2200
|
+
* restarted (with the boot move and the road back), stayed up (with
|
|
2201
|
+
* the steady boot), or census-unknown (with the probe's word) — so
|
|
2202
|
+
* the operator never presses blind into a booting engine again. */
|
|
2203
|
+
function freeVoice(before, after, reachable, warmed) {
|
|
2204
|
+
const path = freeRestarted(before, after);
|
|
2205
|
+
const road = reachable
|
|
2206
|
+
? "the engine answers — your next press queues normally (a still-settling unit is waited for at the press)"
|
|
2207
|
+
: "the engine is still coming back — give it a minute; the next press waits for the unit before failing";
|
|
2208
|
+
if (path === true) {
|
|
2209
|
+
return "free issued (next worker iteration); the engine RESTARTED under the free"
|
|
2210
|
+
+ " (unit boot moved " + String(before.started_at) + " → " + String(after.started_at) + "); "
|
|
2211
|
+
+ warmed + "; " + road;
|
|
2212
|
+
}
|
|
2213
|
+
if (path === false) {
|
|
2214
|
+
return "free issued (next worker iteration); the engine stayed up through the free"
|
|
2215
|
+
+ " (same boot " + String(after.started_at) + ", VRAM freed in place); "
|
|
2216
|
+
+ warmed + "; " + road;
|
|
2217
|
+
}
|
|
2218
|
+
return "free issued (next worker iteration); the unit census cannot answer on this lane"
|
|
2219
|
+
+ " (restart-vs-unload unknown); " + warmed + "; " + road;
|
|
2111
2220
|
}
|
|
2112
2221
|
|
|
2113
2222
|
|
|
@@ -2130,7 +2239,9 @@ async function hSettleStale(req, ctx) {
|
|
|
2130
2239
|
throw new Refused(409, "settle_stale refused: the engine is working (running " + queue.running + " · pending " + queue.pending +
|
|
2131
2240
|
") — every live-worded sidecar may be live; settle only against an idle engine");
|
|
2132
2241
|
}
|
|
2133
|
-
|
|
2242
|
+
// the unit's own start ranks over the receipt (S1): a sidecar that
|
|
2243
|
+
// predates the running engine process cannot be live
|
|
2244
|
+
const boot = engineBootRow(ctx, await engineUnitCensus(ctx));
|
|
2134
2245
|
const bootAt = boot["known"] === true ? Date.parse(String(boot["boot_at"])) : NaN;
|
|
2135
2246
|
const now = Date.now();
|
|
2136
2247
|
const outcome = settleStaleClaims(ctx.stateRoots, (_name, mtimeMs) => {
|
|
@@ -2374,7 +2485,7 @@ async function hSnapshotRestore(req, ctx) {
|
|
|
2374
2485
|
estateOnly(req, cfg);
|
|
2375
2486
|
|
|
2376
2487
|
// call so a run pressed mid-restore refuses instead of tearing.
|
|
2377
|
-
const releaseLifecycle =
|
|
2488
|
+
const releaseLifecycle = ctx.latch.hold(req.action);
|
|
2378
2489
|
try {
|
|
2379
2490
|
await managerPost(base(ctx), "/snapshot/restore", { target: req.snapshot }, { ctx, timeoutMs: 30_000 });
|
|
2380
2491
|
}
|
package/lib/manageProbe.d.ts
CHANGED
|
@@ -84,6 +84,12 @@ export interface EngineUnitCensus {
|
|
|
84
84
|
/** systemctl show ExecMainExitTimestamp, verbatim (systemd's own
|
|
85
85
|
* spelling — never reformatted into a claim). */
|
|
86
86
|
last_exit_at?: string;
|
|
87
|
+
|
|
88
|
+
|
|
89
|
+
|
|
90
|
+
|
|
91
|
+
|
|
92
|
+
started_at?: string;
|
|
87
93
|
/** oom-kill lines in the recent journal tail (countOomLines). */
|
|
88
94
|
oom_kills?: number;
|
|
89
95
|
/** "degraded" (restart loop / signal death / oom evidence),
|
|
@@ -91,10 +97,25 @@ export interface EngineUnitCensus {
|
|
|
91
97
|
verdict: "degraded" | "settled" | "unknown";
|
|
92
98
|
note?: string;
|
|
93
99
|
}
|
|
100
|
+
|
|
101
|
+
|
|
102
|
+
|
|
103
|
+
|
|
104
|
+
|
|
105
|
+
|
|
106
|
+
|
|
107
|
+
|
|
108
|
+
|
|
109
|
+
|
|
110
|
+
|
|
111
|
+
export declare function censusEnv(): NodeJS.ProcessEnv;
|
|
112
|
+
export declare function systemdStampIso(word: string | undefined): string | undefined;
|
|
94
113
|
/** @param mctx - the manage context (unit + signal).
|
|
95
114
|
* @returns the unit census; `known:false` + note when systemd or the
|
|
96
115
|
* journal cannot answer (BYO lane, bus-less box) — never invented
|
|
97
|
-
* zeros dressed as data
|
|
116
|
+
* zeros dressed as data; the note names which of the two happened
|
|
117
|
+
* and the runtime dir the execs rode. @throws the caller's own
|
|
118
|
+
* abort (N-S2). */
|
|
98
119
|
export declare function engineUnitCensus(mctx: ManageCtx): Promise<EngineUnitCensus>;
|
|
99
120
|
export {};
|
|
100
121
|
//# sourceMappingURL=manageProbe.d.ts.map
|
package/lib/manageProbe.js
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
// walk, the active-runs census, and the manager security probe.
|
|
4
4
|
import { execFile } from "node:child_process";
|
|
5
5
|
import { promisify } from "node:util";
|
|
6
|
-
import { readFileSync, readdirSync, statSync, writeFileSync } from "node:fs";
|
|
6
|
+
import { existsSync, readFileSync, readdirSync, statSync, writeFileSync } from "node:fs";
|
|
7
7
|
import { join } from "node:path";
|
|
8
8
|
import { sweepOutputRoots } from "./cardsDangling.js";
|
|
9
9
|
import { sdkClient } from "@melite/comfyui-cordis";
|
|
@@ -258,19 +258,74 @@ export function countOomLines(lines) {
|
|
|
258
258
|
* fuses so a hung bus can never eat the status answer; a census that
|
|
259
259
|
* cannot answer in time is an honest `unknown`, never a lie. */
|
|
260
260
|
const CENSUS_EXEC_MS = 1_500;
|
|
261
|
+
|
|
262
|
+
|
|
263
|
+
|
|
264
|
+
|
|
265
|
+
|
|
266
|
+
|
|
267
|
+
|
|
268
|
+
|
|
269
|
+
|
|
270
|
+
|
|
271
|
+
|
|
272
|
+
export function censusEnv() {
|
|
273
|
+
const env = { ...process.env, LC_ALL: "C", TZ: "UTC" };
|
|
274
|
+
if (env["XDG_RUNTIME_DIR"] === undefined || env["XDG_RUNTIME_DIR"] === "") {
|
|
275
|
+
const uid = process.getuid?.();
|
|
276
|
+
const dir = uid === undefined ? undefined : "/run/user/" + String(uid);
|
|
277
|
+
if (dir !== undefined && existsSync(dir)) {
|
|
278
|
+
env["XDG_RUNTIME_DIR"] = dir;
|
|
279
|
+
if (env["DBUS_SESSION_BUS_ADDRESS"] === undefined)
|
|
280
|
+
env["DBUS_SESSION_BUS_ADDRESS"] = "unix:path=" + dir + "/bus";
|
|
281
|
+
}
|
|
282
|
+
}
|
|
283
|
+
return env;
|
|
284
|
+
}
|
|
285
|
+
|
|
286
|
+
|
|
287
|
+
|
|
288
|
+
|
|
289
|
+
|
|
290
|
+
|
|
291
|
+
const SYSTEMD_STAMP_RE = /^([A-Z][a-z]{2}) (\d{4})-(\d{2})-(\d{2}) (\d{2}):(\d{2}):(\d{2}) UTC$/;
|
|
292
|
+
export function systemdStampIso(word) {
|
|
293
|
+
if (word === undefined)
|
|
294
|
+
return undefined;
|
|
295
|
+
const m = SYSTEMD_STAMP_RE.exec(word);
|
|
296
|
+
if (m === null)
|
|
297
|
+
return undefined;
|
|
298
|
+
return m[2] + "-" + m[3] + "-" + m[4] + "T" + m[5] + ":" + m[6] + ":" + m[7] + ".000Z";
|
|
299
|
+
}
|
|
261
300
|
/** THE DEGRADED LAW: two unplanned restarts, a SIGKILL last exit (the
|
|
262
301
|
* burn's `status=9/KILL` — signal 9 never arrives from a clean
|
|
263
302
|
* stop), or oom evidence in the recent journal. One of these alone
|
|
264
303
|
* degrades; a reachable /system_stats cannot clear them. */
|
|
265
304
|
const DEGRADE_RESTART_FLOOR = 2;
|
|
266
305
|
const KILL_SIGNAL = 9;
|
|
306
|
+
|
|
307
|
+
|
|
308
|
+
|
|
309
|
+
|
|
310
|
+
|
|
311
|
+
|
|
312
|
+
|
|
313
|
+
|
|
314
|
+
|
|
315
|
+
function execFailureText(reason) {
|
|
316
|
+
const err = reason;
|
|
317
|
+
return (err.stderr.trim() !== "" ? err.stderr : String(err.message)).trim().slice(0, 120);
|
|
318
|
+
}
|
|
267
319
|
/** @param mctx - the manage context (unit + signal).
|
|
268
320
|
* @returns the unit census; `known:false` + note when systemd or the
|
|
269
321
|
* journal cannot answer (BYO lane, bus-less box) — never invented
|
|
270
|
-
* zeros dressed as data
|
|
322
|
+
* zeros dressed as data; the note names which of the two happened
|
|
323
|
+
* and the runtime dir the execs rode. @throws the caller's own
|
|
324
|
+
* abort (N-S2). */
|
|
271
325
|
export async function engineUnitCensus(mctx) {
|
|
272
326
|
const unit = mctx.comfyUnit;
|
|
273
|
-
const
|
|
327
|
+
const env = censusEnv();
|
|
328
|
+
const execOpts = { timeout: CENSUS_EXEC_MS, encoding: "utf8", signal: mctx.signal, env };
|
|
274
329
|
const [propsResult, journalResult] = await Promise.allSettled([
|
|
275
330
|
execFileAsync("systemctl", [
|
|
276
331
|
"--user", "show", unit,
|
|
@@ -278,6 +333,7 @@ export async function engineUnitCensus(mctx) {
|
|
|
278
333
|
"--property=ExecMainStatus",
|
|
279
334
|
"--property=ExecMainCode",
|
|
280
335
|
"--property=ExecMainExitTimestamp",
|
|
336
|
+
"--property=ExecMainStartTimestamp",
|
|
281
337
|
], execOpts),
|
|
282
338
|
execFileAsync("journalctl", ["--user", "-u", unit, "-n", "200", "--no-pager", "-o", "cat"], execOpts),
|
|
283
339
|
]);
|
|
@@ -291,10 +347,8 @@ export async function engineUnitCensus(mctx) {
|
|
|
291
347
|
}
|
|
292
348
|
}
|
|
293
349
|
if (props["NRestarts"] === undefined && props["ExecMainCode"] === undefined) {
|
|
294
|
-
const why = propsResult.status === "rejected"
|
|
295
|
-
|
|
296
|
-
: "systemd answered nothing parseable";
|
|
297
|
-
return { known: false, unit, verdict: "unknown", note: "the unit census cannot answer on this lane: " + why };
|
|
350
|
+
const why = propsResult.status === "rejected" ? execFailureText(propsResult.reason) : "systemd answered nothing parseable";
|
|
351
|
+
return { known: false, unit, verdict: "unknown", note: "the unit census cannot answer on this lane: " + why + " (XDG_RUNTIME_DIR=" + String(env["XDG_RUNTIME_DIR"] ?? "unset") + ")" };
|
|
298
352
|
}
|
|
299
353
|
let oomKills;
|
|
300
354
|
let journalNote;
|
|
@@ -330,6 +384,9 @@ export async function engineUnitCensus(mctx) {
|
|
|
330
384
|
const exitAt = props["ExecMainExitTimestamp"];
|
|
331
385
|
if (exitAt !== undefined && exitAt !== "" && exitAt !== "n/a")
|
|
332
386
|
row.last_exit_at = exitAt;
|
|
387
|
+
const startedAt = systemdStampIso(props["ExecMainStartTimestamp"]);
|
|
388
|
+
if (startedAt !== undefined)
|
|
389
|
+
row.started_at = startedAt;
|
|
333
390
|
if (oomKills !== undefined)
|
|
334
391
|
row.oom_kills = oomKills;
|
|
335
392
|
const degraded = (Number.isFinite(restarts) && restarts >= DEGRADE_RESTART_FLOOR)
|