@melite/estate-queue 0.1.4-alpha → 0.2.0-alpha
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/LICENSE +561 -457
- package/README.md +55 -0
- package/lib/bench.d.ts +19 -11
- package/lib/bench.js +47 -57
- package/lib/cardsArmError.d.ts +94 -2
- package/lib/cardsArmError.js +34 -4
- package/lib/cardsCompose.d.ts +13 -1
- package/lib/cardsCompose.js +151 -67
- package/lib/cardsDangling.d.ts +2 -2
- package/lib/cardsDangling.js +82 -37
- package/lib/cardsFacts.d.ts +32 -3
- package/lib/cardsFacts.js +39 -1
- package/lib/cardsLanes.d.ts +62 -4
- package/lib/cardsLanes.js +407 -20
- package/lib/cardsLanesCopy.d.ts +21 -0
- package/lib/cardsLanesCopy.js +22 -0
- package/lib/cardsRegistry.d.ts +195 -10
- package/lib/cardsRegistry.js +959 -67
- package/lib/cardsVariant.d.ts +22 -8
- package/lib/cardsVariant.js +243 -52
- package/lib/discloseRegistry.d.ts +42 -11
- package/lib/discloseRegistry.js +163 -23
- package/lib/filmLead.js +5 -3
- package/lib/flowsData.d.ts +68 -13
- package/lib/flowsData.js +236 -107
- package/lib/flowsFamilyCompose.d.ts +5 -8
- package/lib/flowsFamilyCompose.js +25 -14
- package/lib/flowsParamsOverlay.d.ts +55 -0
- package/lib/flowsParamsOverlay.js +197 -0
- package/lib/flowsRegistryRows.d.ts +4 -1
- package/lib/flowsRegistryRows.js +325 -25
- package/lib/index.d.ts +1 -3
- package/lib/index.js +20 -5
- package/lib/lifecycleLatch.d.ts +16 -0
- package/lib/lifecycleLatch.js +42 -0
- package/lib/loadPlane.d.ts +3 -2
- package/lib/loadPlane.js +34 -8
- package/lib/loadRegistry.js +1 -1
- package/lib/manageOps.d.ts +8 -2
- package/lib/manageOps.js +28 -7
- package/lib/managePlane.d.ts +42 -1
- package/lib/managePlane.js +911 -101
- package/lib/managePreflight.d.ts +26 -0
- package/lib/managePreflight.js +179 -0
- package/lib/manageProbe.d.ts +15 -7
- package/lib/manageProbe.js +79 -8
- package/lib/manageRegistry.d.ts +42 -4
- package/lib/manageRegistry.js +45 -7
- package/lib/mediaKinds.d.ts +1 -1
- package/lib/mediaKinds.js +1 -1
- package/lib/queue.js +14 -10
- package/lib/queueCore.d.ts +21 -5
- package/lib/queueCore.js +22 -5
- package/lib/queueLifecycle.d.ts +0 -24
- package/lib/queueLifecycle.js +9 -63
- package/lib/queueLock.d.ts +8 -2
- package/lib/queueLock.js +9 -6
- package/lib/queueResurrect.d.ts +7 -2
- package/lib/queueResurrect.js +25 -6
- package/lib/queueSidecar.d.ts +114 -1
- package/lib/queueSidecar.js +178 -7
- package/lib/queueSubmit.d.ts +124 -10
- package/lib/queueSubmit.js +251 -48
- package/lib/queueSweep.js +13 -2
- package/lib/runsChange.d.ts +8 -0
- package/lib/runsChange.js +21 -5
- package/lib/runsErrorCodes.d.ts +1 -1
- package/lib/runsErrorCodes.js +35 -0
- package/lib/runsExecute.d.ts +26 -0
- package/lib/runsExecute.js +184 -6
- package/lib/runsGates.d.ts +5 -1
- package/lib/runsGates.js +10 -5
- package/lib/runsList.d.ts +43 -3
- package/lib/runsList.js +172 -58
- package/lib/runsRefusalVoices.js +101 -0
- package/lib/runsRegistry.d.ts +188 -12
- package/lib/runsRegistry.js +1233 -179
- package/lib/runsSourceEcho.d.ts +27 -0
- package/lib/runsSourceEcho.js +84 -18
- package/lib/runsStart.d.ts +80 -17
- package/lib/runsStart.js +303 -49
- package/lib/runsTypes.d.ts +62 -2
- package/lib/runsTypes.js +30 -6
- package/lib/runsValidateArms.js +61 -7
- package/lib/runsValidateServe.d.ts +2 -2
- package/lib/runsValidateServe.js +46 -14
- package/lib/runsValidateShared.d.ts +10 -1
- package/lib/runsValidateShared.js +14 -0
- package/lib/runsValidateStages.d.ts +10 -3
- package/lib/runsValidateStages.js +44 -12
- package/lib/runtimeProvision.d.ts +119 -0
- package/lib/runtimeProvision.js +243 -0
- package/lib/service.d.ts +24 -6
- package/lib/service.js +19 -11
- package/lib/skillFs.d.ts +9 -4
- package/lib/skillFs.js +12 -14
- package/lib/skillPlane.d.ts +3 -2
- package/lib/skillPlane.js +12 -6
- package/lib/skillRegistry.js +1 -1
- package/lib/skillRows.d.ts +4 -3
- package/lib/skillRows.js +21 -14
- package/lib/toolProjection.d.ts +1 -1
- package/lib/toolProjection.js +1 -1
- package/package.json +18 -17
- package/lib/runStatus.d.ts +0 -7
- package/lib/runStatus.js +0 -21
package/lib/managePlane.js
CHANGED
|
@@ -12,14 +12,22 @@
|
|
|
12
12
|
// Erasable-syntax TS only (node --experimental-strip-types).
|
|
13
13
|
import { execFile } from "node:child_process";
|
|
14
14
|
import { promisify } from "node:util";
|
|
15
|
-
import {
|
|
16
|
-
import { join } from "node:path";
|
|
17
|
-
import {
|
|
18
|
-
import {
|
|
15
|
+
import { readFileSync } from "node:fs";
|
|
16
|
+
import { dirname, join } from "node:path";
|
|
17
|
+
import { resolveRuntimeProvision, nodeRuntimeFs, runtimeEnvView, engineOutputDir, engineRootOf, sentinelHit } from "./runtimeProvision.js";
|
|
18
|
+
import { ComfyError, endpointConfigPath, invalidateObjectInfo, liveObjectInfo, loadEndpointConfig, resolveEngineBaseUrl, } from "@melite/comfyui-cordis";
|
|
19
|
+
import { writeJsonAtomic } from "./queueLock.js";
|
|
20
|
+
import { installUserLora, installUserLoraBytes, loraNamesFromObjectInfo, readUserLoraRows, refmodNamesFromObjectInfo, resolveEngineLorasDir, unboardedRows, userLorasPath, validateUserLoraRow, } from "@melite/comfyui-cordis/user-loras";
|
|
21
|
+
import { AcquireBusyError, LIVE_ACQUIRE_STATES } from "@melite/estate-provisioning";
|
|
19
22
|
import { ManagerApiError, managerGet, managerPost, planeUnavailable } from "./managerRail.js";
|
|
20
|
-
import { probeEndpoint, activeRuns, managerSecurity, engineQueueView } from "./manageProbe.js";
|
|
21
|
-
import {
|
|
23
|
+
import { probeEndpoint, activeRuns, managerSecurity, engineQueueView, settleStaleClaims } from "./manageProbe.js";
|
|
24
|
+
import { runPreflight, preflightLine } from "./managePreflight.js";
|
|
25
|
+
import { base, mapManagerRefused, mapRail, railMs, estateOnly, awaitQueueDrained, systemctl, guardLifecycle } from "./manageOps.js";
|
|
26
|
+
import { holdLifecycle } from "./lifecycleLatch.js";
|
|
22
27
|
import { deadline as deadlineOf, timeoutOf } from "@deepseek-ai/dsh-timeout";
|
|
28
|
+
import { segmentConfined } from "@melite/contracts/mediaKinds";
|
|
29
|
+
import { artifactFileName } from "@melite/contracts/benchResult";
|
|
30
|
+
import { cellArtifactCoordinates } from "@melite/contracts/laneRelations";
|
|
23
31
|
const execFileAsync = promisify(execFile);
|
|
24
32
|
// ── SSOT vocabulary ─────────────────────────────────────────────────
|
|
25
33
|
// Closed vocabulary — a typo is a 422, not a silent miss.
|
|
@@ -35,16 +43,65 @@ export const ACTIONS = [
|
|
|
35
43
|
"download_model",
|
|
36
44
|
"provision_model",
|
|
37
45
|
"acquire_weight",
|
|
46
|
+
|
|
47
|
+
// the run-rescue runtime banner fires — links the engine tree's
|
|
48
|
+
// data/runtime/<name> to the repo's healthy seed (SYMLINK, never a
|
|
49
|
+
// copy). Decided by the same core the press-time gate reads
|
|
50
|
+
// (runtimeProvision.ts): gate and verb can never disagree.
|
|
51
|
+
"provision_runtime",
|
|
52
|
+
// THE RESCUE VERBS (ERRORS.md k2 + the purge plan's P5 rescue
|
|
53
|
+
// honesty): a settled-failed acquire is retryable — a fresh fetch
|
|
54
|
+
// on the dead row's ref, the dead row's truth kept — and the dead
|
|
55
|
+
// row is discardable — evicted, so a later poll 404s. The k2 burn's
|
|
56
|
+
// own words, "no retry, no delete, just stuck", die here.
|
|
57
|
+
"acquire_retry",
|
|
58
|
+
"acquire_discard",
|
|
38
59
|
"restart",
|
|
39
60
|
"stop",
|
|
40
61
|
"launch",
|
|
41
62
|
"update",
|
|
42
63
|
"switch_version",
|
|
43
64
|
"free",
|
|
65
|
+
|
|
66
|
+
// sidecars from before a rebuild. The lifecycle guard is sync and
|
|
67
|
+
// fail-closed — it cannot consult the engine — so the historical
|
|
68
|
+
// claims it refuses on are retired by explicit operator gesture,
|
|
69
|
+
// never by the guard looking away.
|
|
70
|
+
"settle_stale",
|
|
44
71
|
"snapshot_save",
|
|
45
72
|
"snapshot_restore",
|
|
46
73
|
"lora_list",
|
|
47
74
|
"lora_install",
|
|
75
|
+
|
|
76
|
+
// LORA-FROM-URL burn, ROADMAP line 7892: "Can you add this lora
|
|
77
|
+
// to krea 2" + a HuggingFace URL is the ONE download an operator
|
|
78
|
+
// actually does, and nothing served it — the session fell to raw
|
|
79
|
+
// bash archaeology against the no-loras-remote rule). THE
|
|
80
|
+
// AMENDED LAW, voiced here where the verb lives: the rule is
|
|
81
|
+
// amended, NOT deleted — no SILENT remote fetch; a stated URL
|
|
82
|
+
// rides the provisioning service (download_model's own stack:
|
|
83
|
+
// range resume, kept parts, live ledger, honest voices) behind
|
|
84
|
+
// the human's operator_confirmed gate, lands under the FAMILY
|
|
85
|
+
// subfolder the engine already serves (loras/<family>/<file> —
|
|
86
|
+
// the combo lists '<family>/<file>'), and the landing drops the
|
|
87
|
+
// estate's cached /object_info doc so the next lora_list re-asks.
|
|
88
|
+
// download_model's own loras refusal STAYS (its comment names
|
|
89
|
+
// this verb as the supersession). Recipe: add a lora to <family>:
|
|
90
|
+
// lora_fetch url → auto restart → the mod appears in the family's
|
|
91
|
+
// mods.
|
|
92
|
+
"lora_fetch",
|
|
93
|
+
|
|
94
|
+
// square): the H3 refmods loader's own mod_N combo, read off the
|
|
95
|
+
// same cached /object_info doc lora_list rides — the stems, sorted.
|
|
96
|
+
"refmods_list",
|
|
97
|
+
|
|
98
|
+
// every setup miss (engine reachable? Manager present? required
|
|
99
|
+
// declared packs landed? store root on disk? wiring visible?) —
|
|
100
|
+
// each miss names its door, instead of null presence + mid-run
|
|
101
|
+
// burns. A READ on any posture (BYO is its primary audience — no
|
|
102
|
+
// estateOnly); a probe that throws is a named miss, so the answer
|
|
103
|
+
// can never degrade to all-green over an unchecked axis.
|
|
104
|
+
"preflight",
|
|
48
105
|
];
|
|
49
106
|
/** The status reconcile bound (the wall law — see hStatus): status
|
|
50
107
|
* answers inside the plane's 5s wall; the digest-verifying
|
|
@@ -174,18 +231,21 @@ export function parseReq(doc) {
|
|
|
174
231
|
action: action,
|
|
175
232
|
nodes: Array.isArray(d["nodes"]) ? d["nodes"].map(String).filter((s) => s !== "") : [],
|
|
176
233
|
url: str("url"),
|
|
234
|
+
ref: str("ref"),
|
|
177
235
|
relative_path: str("relative_path"),
|
|
178
236
|
wait: typeof d["wait"] === "boolean" ? d["wait"] : null,
|
|
179
237
|
timeout_seconds: num("timeout_seconds", 300),
|
|
180
238
|
model: str("model"),
|
|
181
239
|
variant: str("variant"),
|
|
182
240
|
quant: str("quant"),
|
|
241
|
+
runtime: str("runtime"),
|
|
183
242
|
tail: num("tail", 200),
|
|
184
243
|
query: str("query"),
|
|
185
244
|
version: str("version"),
|
|
186
245
|
target: str("target") || "comfy",
|
|
187
246
|
extra_args: Array.isArray(d["extra_args"]) ? d["extra_args"].map(String) : [],
|
|
188
247
|
force: d["force"] === true,
|
|
248
|
+
operator_confirmed: d["operator_confirmed"] === true,
|
|
189
249
|
snapshot: str("snapshot"),
|
|
190
250
|
|
|
191
251
|
// ENGINE will accept (its own combo) plus the user's own rows;
|
|
@@ -200,6 +260,8 @@ export function parseReq(doc) {
|
|
|
200
260
|
filename: str("filename") || str("file"),
|
|
201
261
|
families: Array.isArray(d["families"]) ? d["families"].map(String).filter((s) => s !== "") : [],
|
|
202
262
|
operation_id: str("operation_id"),
|
|
263
|
+
// THE LORA-FETCH VERIFY (see Req.sha256)
|
|
264
|
+
sha256: str("sha256"),
|
|
203
265
|
};
|
|
204
266
|
}
|
|
205
267
|
function need(req, ...fields) {
|
|
@@ -240,11 +302,22 @@ function withNextAction(response, nextAction) {
|
|
|
240
302
|
function engineBootReceiptPath(ctx) {
|
|
241
303
|
return join(ctx.repoRoot, "data", "runtime", "comfyui", ".estate-engine-boot.json");
|
|
242
304
|
}
|
|
243
|
-
function recordEngineBoot(ctx, source) {
|
|
305
|
+
async function recordEngineBoot(ctx, source) {
|
|
244
306
|
try {
|
|
245
|
-
|
|
307
|
+
// J6: the receipt rides the package's atomic writer — a bare
|
|
308
|
+
// writeFileSync could tear the file across a crash, and a torn
|
|
309
|
+
// receipt is a FALSE blindness signal for the status reader.
|
|
310
|
+
await writeJsonAtomic(engineBootReceiptPath(ctx), { boot_at: Date.now(), source });
|
|
246
311
|
}
|
|
247
312
|
catch {
|
|
313
|
+
// Swallowed with reason: the engine IS rebooting regardless; a
|
|
314
|
+
// failed receipt write must never fail the restart answer — with
|
|
315
|
+
// ONE exception (MP-R2, round 19): the caller's own abort. An
|
|
316
|
+
// abort surfacing inside this write must propagate (the hRestart
|
|
317
|
+
// finally still drops the cache for the issued reboot) instead of
|
|
318
|
+
// being laundered into a success the caller cancelled.
|
|
319
|
+
if (signalIsAborted(ctx.signal))
|
|
320
|
+
throw abortReason(ctx.signal);
|
|
248
321
|
return;
|
|
249
322
|
}
|
|
250
323
|
}
|
|
@@ -280,51 +353,55 @@ function safeStatusItems(items) {
|
|
|
280
353
|
...(item.detail === undefined ? {} : { detail: item.detail }),
|
|
281
354
|
}));
|
|
282
355
|
}
|
|
283
|
-
function normalizedResources(resources, provisioning) {
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
356
|
+
async function normalizedResources(resources, provisioning) {
|
|
357
|
+
const rows = [];
|
|
358
|
+
for (const resource of resources) {
|
|
359
|
+
rows.push(await normalizeResource(resource, provisioning));
|
|
360
|
+
}
|
|
361
|
+
return rows;
|
|
362
|
+
}
|
|
363
|
+
|
|
364
|
+
|
|
365
|
+
|
|
366
|
+
|
|
367
|
+
|
|
368
|
+
|
|
369
|
+
|
|
370
|
+
|
|
371
|
+
|
|
372
|
+
async function normalizeResource(resource, provisioning) {
|
|
373
|
+
const row = (operationId, state, items, detail) => ({
|
|
374
|
+
...resource,
|
|
375
|
+
state,
|
|
376
|
+
items,
|
|
377
|
+
...(operationId === undefined ? {} : { operationId }),
|
|
378
|
+
...(detail === undefined ? {} : { detail }),
|
|
379
|
+
});
|
|
380
|
+
if (provisioning === undefined) {
|
|
291
381
|
|
|
292
382
|
|
|
293
383
|
|
|
294
384
|
|
|
295
385
|
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
};
|
|
304
|
-
}
|
|
305
|
-
try {
|
|
306
|
-
const operation = provisioning.operationOf(resource.ref);
|
|
307
|
-
if (operation !== undefined) {
|
|
308
|
-
operationId = operation.operationId;
|
|
309
|
-
state = operation.state;
|
|
310
|
-
items = operation.items;
|
|
311
|
-
detail = detail ?? operation.detail;
|
|
312
|
-
}
|
|
386
|
+
|
|
387
|
+
return row(resource.operationId, resource.state, resource.items, resource.detail);
|
|
388
|
+
}
|
|
389
|
+
try {
|
|
390
|
+
const operation = provisioning.operationOf(resource.ref);
|
|
391
|
+
if (operation === undefined) {
|
|
392
|
+
return row(resource.operationId, resource.state, resource.items, resource.detail);
|
|
313
393
|
}
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
detail
|
|
394
|
+
const verified = provisioning.verifyOperation === undefined
|
|
395
|
+
? operation
|
|
396
|
+
: await provisioning.verifyOperation(operation);
|
|
397
|
+
if (verified.state !== operation.state) {
|
|
398
|
+
return row(verified.operationId, verified.state, verified.items, verified.items[0]?.detail ?? resource.detail);
|
|
319
399
|
}
|
|
320
|
-
return
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
...(detail === undefined ? {} : { detail }),
|
|
326
|
-
};
|
|
327
|
-
});
|
|
400
|
+
return row(operation.operationId, operation.state, operation.items, resource.detail ?? operation.detail);
|
|
401
|
+
}
|
|
402
|
+
catch {
|
|
403
|
+
return row(resource.operationId, resource.state, resource.items, resource.detail);
|
|
404
|
+
}
|
|
328
405
|
}
|
|
329
406
|
function operationRows(resources) {
|
|
330
407
|
return resources.flatMap((resource) => {
|
|
@@ -425,7 +502,7 @@ function versionOptions(doc) {
|
|
|
425
502
|
async function hStatus(req, ctx) {
|
|
426
503
|
const cfg = ctx.endpoint();
|
|
427
504
|
const endpoint = await probeEndpoint(ctx);
|
|
428
|
-
const active = activeRuns();
|
|
505
|
+
const active = activeRuns(ctx.stateRoots);
|
|
429
506
|
|
|
430
507
|
// law (unreadable ⇒ active — guardLifecycle refuses restarts on
|
|
431
508
|
// it), but the STATUS view was asserting every unsettled sidecar
|
|
@@ -439,7 +516,7 @@ async function hStatus(req, ctx) {
|
|
|
439
516
|
const engineIdle = engineQueue !== null && engineQueue.running === 0 && engineQueue.pending === 0;
|
|
440
517
|
const activeView = engineIdle ? [] : active;
|
|
441
518
|
const staleClaims = engineIdle
|
|
442
|
-
? active.map((name) => name + " (claimed live; engine queue empty — historical: the sidecar never settled;
|
|
519
|
+
? active.map((name) => name + " (claimed live; engine queue empty — historical: the sidecar never settled; retire it with the settle_stale action)")
|
|
443
520
|
: [];
|
|
444
521
|
const routing = { mode: cfg["provision"] === "managed" ? "managed" : "byo" };
|
|
445
522
|
let manager = {};
|
|
@@ -495,12 +572,24 @@ async function hStatus(req, ctx) {
|
|
|
495
572
|
resourcesDetail = error instanceof Error ? error.message : String(error);
|
|
496
573
|
}
|
|
497
574
|
}
|
|
498
|
-
const normalized = normalizedResources(resources, provisionSeat);
|
|
575
|
+
const normalized = await normalizedResources(resources, provisionSeat);
|
|
499
576
|
const operations = operationRows(normalized);
|
|
500
577
|
const resourceRows = normalized.map((resource) => ({
|
|
501
578
|
...resource,
|
|
502
579
|
...(resource.operationId === undefined ? {} : { operation_id: resource.operationId }),
|
|
503
580
|
}));
|
|
581
|
+
|
|
582
|
+
// status budget cannot sha256-census a healthy estate, and the
|
|
583
|
+
// truncated list served as the whole "Declared resources" truth —
|
|
584
|
+
// "1/1 failed" over files that sat byte-exact on disk). Any
|
|
585
|
+
// 'unknown' ROW is the scan's own artifact — and so is any
|
|
586
|
+
// 'unknown' ITEM (audit F1: a failed item over unchecked siblings
|
|
587
|
+
// aggregates the row to 'failed', a real verdict that must stand,
|
|
588
|
+
// but the partial mark must still fire or the sidebar titles a
|
|
589
|
+
// partial scan as the whole truth). The mark derives from both
|
|
590
|
+
// levels: row OR item unknown.
|
|
591
|
+
const censusPartial = resourceRows.some((row) => row.state === "unknown")
|
|
592
|
+
|| resourceRows.some((row) => (row.items ?? []).some((item) => item.state === "unknown"));
|
|
504
593
|
const state = endpoint.reachable ? "up" : "down";
|
|
505
594
|
const nextAction = nextActionFor(endpoint.reachable, normalized, routing.mode === "managed");
|
|
506
595
|
const catalog = modelOptions(ctx.models);
|
|
@@ -511,7 +600,7 @@ async function hStatus(req, ctx) {
|
|
|
511
600
|
manager: {
|
|
512
601
|
...manager,
|
|
513
602
|
security: managerSecurity(ctx.repoRoot),
|
|
514
|
-
unit:
|
|
603
|
+
unit: ctx.comfyUnit,
|
|
515
604
|
operations,
|
|
516
605
|
},
|
|
517
606
|
comfyui_versions: comfyuiVersions,
|
|
@@ -526,7 +615,9 @@ async function hStatus(req, ctx) {
|
|
|
526
615
|
: {}),
|
|
527
616
|
engine_boot: engineBootRow(ctx),
|
|
528
617
|
routing,
|
|
618
|
+
auto_provision: ctx.autoProvision,
|
|
529
619
|
resources: resourceRows,
|
|
620
|
+
...(censusPartial ? { census_partial: true } : {}),
|
|
530
621
|
operations,
|
|
531
622
|
...(resourcesDetail === undefined ? {} : { resources_detail: resourcesDetail }),
|
|
532
623
|
};
|
|
@@ -537,7 +628,7 @@ async function hLogs(req, ctx) {
|
|
|
537
628
|
const tail = Math.max(1, Math.min(Math.trunc(req.tail), 2000));
|
|
538
629
|
let stdout;
|
|
539
630
|
try {
|
|
540
|
-
const out = await execFileAsync("journalctl", ["--user", "-u",
|
|
631
|
+
const out = await execFileAsync("journalctl", ["--user", "-u", ctx.comfyUnit, "-n", String(tail), "--no-pager", "-o", "cat"], {
|
|
541
632
|
timeout: 15 * 1000,
|
|
542
633
|
encoding: "utf8",
|
|
543
634
|
signal: ctx.signal,
|
|
@@ -547,15 +638,20 @@ async function hLogs(req, ctx) {
|
|
|
547
638
|
catch (error) {
|
|
548
639
|
if (signalIsAborted(ctx.signal))
|
|
549
640
|
throw abortReason(ctx.signal);
|
|
550
|
-
throw unavailable("logs need the estate deployment's journal (unit " +
|
|
641
|
+
throw unavailable("logs need the estate deployment's journal (unit " + ctx.comfyUnit + "): " +
|
|
551
642
|
error.message.slice(0, 120));
|
|
552
643
|
}
|
|
553
644
|
throwIfAborted(ctx.signal);
|
|
554
645
|
const lines = stdout.split("\n").filter((ln) => ln !== "");
|
|
555
|
-
return ok(req.action, lines.length + " log line(s) from " +
|
|
646
|
+
return ok(req.action, lines.length + " log line(s) from " + ctx.comfyUnit, lines);
|
|
556
647
|
}
|
|
557
648
|
async function hSearch(req, ctx) {
|
|
558
|
-
|
|
649
|
+
|
|
650
|
+
|
|
651
|
+
// exploring the catalog hit a refusal instead of the roster. An
|
|
652
|
+
// omitted or empty query lists the whole cache (capped); a carried
|
|
653
|
+
// query filters it. The filter syntax rides the unfiltered detail
|
|
654
|
+
// so the agent learns it from the answer itself.
|
|
559
655
|
const cfg = ctx.endpoint();
|
|
560
656
|
estateOnly(req, cfg);
|
|
561
657
|
let doc;
|
|
@@ -566,12 +662,18 @@ async function hSearch(req, ctx) {
|
|
|
566
662
|
throw mapRail(e, req.action);
|
|
567
663
|
}
|
|
568
664
|
const models = doc["models"] ?? [];
|
|
569
|
-
const
|
|
665
|
+
const raw = typeof req.query === "string" ? req.query : "";
|
|
666
|
+
const q = raw.toLowerCase();
|
|
570
667
|
const hits = models.filter((m) => {
|
|
668
|
+
if (q === "")
|
|
669
|
+
return true;
|
|
571
670
|
const hay = [m["name"], m["type"], m["base"], m["filename"]].map((v) => String(v ?? "").toLowerCase()).join(" ");
|
|
572
671
|
return hay.includes(q);
|
|
573
672
|
}).slice(0, 50);
|
|
574
|
-
|
|
673
|
+
const detail = q === ""
|
|
674
|
+
? hits.length + " model(s) in the Manager external catalog (no filter — pass query to narrow: it case-folds over name/type/base/filename)"
|
|
675
|
+
: hits.length + " hit(s) from Manager external catalog for '" + req.query + "'";
|
|
676
|
+
return ok(req.action, detail, hits);
|
|
575
677
|
}
|
|
576
678
|
async function withManageTimeout(req, ctx, work, boundMs = railMs(req)) {
|
|
577
679
|
throwIfAborted(ctx.signal);
|
|
@@ -583,14 +685,13 @@ async function withManageTimeout(req, ctx, work, boundMs = railMs(req)) {
|
|
|
583
685
|
const timedOut = () => timeoutOf(dl.signal, "MANAGE_OP") !== undefined;
|
|
584
686
|
try {
|
|
585
687
|
const value = await work(dl.signal);
|
|
688
|
+
|
|
689
|
+
// RESOLVED, its value is real — reporting 504 for a result the
|
|
690
|
+
// caller could have used (the old Date.now arm fired on work that
|
|
691
|
+
// landed one tick past boundAt) serves nobody. An unresolved work
|
|
692
|
+
// still dies at the deadline below (the abort arm).
|
|
586
693
|
if (signalIsAborted(ctx.signal))
|
|
587
694
|
throw abortReason(ctx.signal);
|
|
588
|
-
if (timedOut() || Date.now() >= boundAt) {
|
|
589
|
-
throw new Refused(504, "manage operation timed out", {
|
|
590
|
-
state: "timeout",
|
|
591
|
-
next_action: "status",
|
|
592
|
-
});
|
|
593
|
-
}
|
|
594
695
|
return value;
|
|
595
696
|
}
|
|
596
697
|
catch (error) {
|
|
@@ -616,16 +717,32 @@ function externalModelPath(req) {
|
|
|
616
717
|
if (folder.includes("..") || folder.startsWith("/")) {
|
|
617
718
|
throw badRequest("relative_path must stay under the models root: " + req.relative_path);
|
|
618
719
|
}
|
|
619
|
-
|
|
620
|
-
//
|
|
621
|
-
//
|
|
622
|
-
//
|
|
623
|
-
//
|
|
720
|
+
|
|
721
|
+
// ROADMAP line 7892): the rule is amended, not deleted — no
|
|
722
|
+
// SILENT remote fetch; a stated URL now rides its OWN verb,
|
|
723
|
+
// lora_fetch (the provisioning service's full progress face,
|
|
724
|
+
// family subfolder, operator_confirmed gate). THIS door keeps
|
|
725
|
+
// its refusal: the generic model fetch never writes the loras
|
|
726
|
+
// dir — that is the lora verb's ground, and a checkpoint URL
|
|
727
|
+
// has no business masquerading as a LoRA.
|
|
624
728
|
if (folder === "loras" || folder.startsWith("loras/")) {
|
|
625
|
-
throw badRequest("download_model refuses the loras dir —
|
|
729
|
+
throw badRequest("download_model refuses the loras dir — a LoRA URL rides the lora_fetch verb (operator order 2026-11-09: the provisioning service lands it under the family's loras subfolder); this generic model door never writes loras");
|
|
626
730
|
}
|
|
627
|
-
|
|
628
|
-
|
|
731
|
+
|
|
732
|
+
// rides the SSOT the cell artifacts ride — a URL's query and
|
|
733
|
+
// fragment are never the file's name ("...safetensors?download=1"
|
|
734
|
+
// landed bytes under a name the engine never listed), a trailing
|
|
735
|
+
// slash names a directory (the empty name refuses by the bare-name
|
|
736
|
+
// fence below), and %XX escapes decode to the true name.
|
|
737
|
+
const filename = req.filename !== "" ? req.filename : artifactFileName(req.url);
|
|
738
|
+
// The bare-name fence rides the SSOT (the dry-sweep's N5):
|
|
739
|
+
// segmentConfined owns the bytes of a legal segment — inner dots
|
|
740
|
+
// are legal ("model..ckpt" stays under the root; the traversal
|
|
741
|
+
// fence is the slash arm, since the SSOT judges one segment) and
|
|
742
|
+
// the NUL arm is its behavioral wall. The old hand-roll refused
|
|
743
|
+
// every inner ".." and had drifted from the grammar every other
|
|
744
|
+
// door rides.
|
|
745
|
+
if (filename.includes("/") || !segmentConfined(filename)) {
|
|
629
746
|
throw badRequest("filename must be a bare name under the models root");
|
|
630
747
|
}
|
|
631
748
|
return { relativePath: folder, filename };
|
|
@@ -847,24 +964,202 @@ async function hInstallExtension(req, ctx) {
|
|
|
847
964
|
}, operations);
|
|
848
965
|
});
|
|
849
966
|
}
|
|
967
|
+
|
|
968
|
+
|
|
969
|
+
|
|
970
|
+
|
|
971
|
+
|
|
972
|
+
|
|
973
|
+
|
|
974
|
+
function operatorConfirmGate(req, door) {
|
|
975
|
+
if (req.operator_confirmed === true)
|
|
976
|
+
return null;
|
|
977
|
+
return [
|
|
978
|
+
409,
|
|
979
|
+
{
|
|
980
|
+
action: door,
|
|
981
|
+
ok: false,
|
|
982
|
+
state: "conflict",
|
|
983
|
+
detail: door + ": external acquisitions land bytes from a caller-named URL — pass operator_confirmed=true " +
|
|
984
|
+
"(the human's approval) to proceed. The flag is recorded with the operation.",
|
|
985
|
+
next_action: "operator_confirmed",
|
|
986
|
+
},
|
|
987
|
+
];
|
|
988
|
+
}
|
|
850
989
|
async function hInstallExtensionUrl(req, ctx) {
|
|
851
990
|
need(req, "url");
|
|
852
991
|
estateOnly(req, ctx.endpoint());
|
|
853
|
-
|
|
992
|
+
// THE SEAT ASKS FIRST (the hProvisionModel order law): a seatless
|
|
993
|
+
// lane names its own 503 before any human flag is demanded
|
|
994
|
+
const provisioner = provisioningOf(ctx);
|
|
995
|
+
const confirmed = operatorConfirmGate(req, "install_extension_url");
|
|
996
|
+
if (confirmed !== null)
|
|
997
|
+
return confirmed;
|
|
998
|
+
const result = await withManageTimeout(req, ctx, (signal) => provisioner.acquireExternal({ kind: "extension", url: req.url, ...(req.ref === "" ? {} : { ref: req.ref }) }, { operatorConfirmed: req.operator_confirmed }, signal));
|
|
854
999
|
return provisionEnvelope(req.action, result);
|
|
855
1000
|
}
|
|
856
1001
|
async function hDownloadModel(req, ctx) {
|
|
857
1002
|
need(req, "url");
|
|
858
1003
|
estateOnly(req, ctx.endpoint());
|
|
859
1004
|
const path = externalModelPath(req);
|
|
860
|
-
|
|
1005
|
+
// THE SEAT ASKS FIRST (the hProvisionModel order law), then the
|
|
1006
|
+
// gate below the shape guards: a request refused on its own merits
|
|
1007
|
+
// never needs the human's flag
|
|
1008
|
+
const provisioner = provisioningOf(ctx);
|
|
1009
|
+
const confirmed = operatorConfirmGate(req, "download_model");
|
|
1010
|
+
if (confirmed !== null)
|
|
1011
|
+
return confirmed;
|
|
1012
|
+
const result = await withManageTimeout(req, ctx, (signal) => provisioner.acquireExternal({
|
|
861
1013
|
kind: "model",
|
|
862
1014
|
url: req.url,
|
|
863
1015
|
relativePath: path.relativePath,
|
|
864
1016
|
filename: path.filename,
|
|
865
|
-
}, { operatorConfirmed:
|
|
1017
|
+
}, { operatorConfirmed: req.operator_confirmed }, signal));
|
|
1018
|
+
|
|
1019
|
+
// living process must not leave the boot-time /object_info doc
|
|
1020
|
+
// serving. The old restartRequired guard was dead — the service
|
|
1021
|
+
// answers models "active" on every path (only extension installs
|
|
1022
|
+
// arm restart_required), so model landings never dropped and the
|
|
1023
|
+
// census stayed boot-stale until a reboot.
|
|
1024
|
+
invalidateLiveObjectInfo(ctx);
|
|
1025
|
+
ctx.rearmWeights?.();
|
|
866
1026
|
return provisionEnvelope(req.action, result);
|
|
867
1027
|
}
|
|
1028
|
+
|
|
1029
|
+
|
|
1030
|
+
|
|
1031
|
+
|
|
1032
|
+
|
|
1033
|
+
|
|
1034
|
+
|
|
1035
|
+
|
|
1036
|
+
|
|
1037
|
+
|
|
1038
|
+
|
|
1039
|
+
|
|
1040
|
+
|
|
1041
|
+
|
|
1042
|
+
async function hLoraFetch(req, ctx) {
|
|
1043
|
+
need(req, "url");
|
|
1044
|
+
estateOnly(req, ctx.endpoint());
|
|
1045
|
+
// ONE family — the subfolder the file lands under; the combo
|
|
1046
|
+
// name is '<family>/<filename>' and the mods plane scopes the
|
|
1047
|
+
// offer by it
|
|
1048
|
+
if (req.families.length !== 1) {
|
|
1049
|
+
throw badRequest("lora_fetch requires exactly one family (the loras subfolder the engine serves the file under) — families: [\"<family-id>\"]");
|
|
1050
|
+
}
|
|
1051
|
+
const family = req.families[0];
|
|
1052
|
+
if (family.includes("/") || !segmentConfined(family)) {
|
|
1053
|
+
throw badRequest("family must be one safe path segment under the loras root: " + family);
|
|
1054
|
+
}
|
|
1055
|
+
// THE C5 FILENAME LAW (the download_model door's own SSOT): the
|
|
1056
|
+
// URL's query/fragment never names the file
|
|
1057
|
+
const filename = req.filename !== "" ? req.filename : artifactFileName(req.url);
|
|
1058
|
+
if (filename.includes("/") || !segmentConfined(filename)) {
|
|
1059
|
+
throw badRequest("filename must be a bare name under the loras root");
|
|
1060
|
+
}
|
|
1061
|
+
// THE ROW GRAMMAR OWNS WHAT A LORA FILE IS (one spelling with
|
|
1062
|
+
// the user rows: the same extension judge the picker's rows
|
|
1063
|
+
// serve — probe rides validateUserLoraRow and reads only its
|
|
1064
|
+
// problem)
|
|
1065
|
+
const probe = validateUserLoraRow({ id: "probe", filename: family + "/" + filename, families: [family] }, 0);
|
|
1066
|
+
if (probe.problem !== undefined)
|
|
1067
|
+
throw badRequest("lora_fetch: " + probe.problem);
|
|
1068
|
+
// THE SEAT ASKS FIRST (the hProvisionModel order law), then the
|
|
1069
|
+
// gate below the shape guards: a request refused on its own
|
|
1070
|
+
// merits never needs the human's flag
|
|
1071
|
+
const provisioner = provisioningOf(ctx);
|
|
1072
|
+
const confirmed = operatorConfirmGate(req, "lora_fetch");
|
|
1073
|
+
if (confirmed !== null)
|
|
1074
|
+
return confirmed;
|
|
1075
|
+
const result = await withManageTimeout(req, ctx, (signal) => provisioner.acquireExternal({
|
|
1076
|
+
kind: "model",
|
|
1077
|
+
url: req.url,
|
|
1078
|
+
relativePath: "loras/" + family,
|
|
1079
|
+
filename,
|
|
1080
|
+
...(req.sha256 === "" ? {} : { sha256: req.sha256 }),
|
|
1081
|
+
}, { operatorConfirmed: req.operator_confirmed }, signal));
|
|
1082
|
+
// THE UNCONDITIONAL DROP (the download_model law this verb
|
|
1083
|
+
// rides): the boot-time /object_info memo must not outlive a
|
|
1084
|
+
// landed file — the next lora_list (and the next form-spec
|
|
1085
|
+
// serve) re-asks, and the engine's mtime-based folder scan
|
|
1086
|
+
// serves the new name. ZERO restarts estate-side; the engine
|
|
1087
|
+
// reboot below is a separate, voiced concern.
|
|
1088
|
+
invalidateLiveObjectInfo(ctx);
|
|
1089
|
+
ctx.rearmWeights?.();
|
|
1090
|
+
const comboName = family + "/" + filename;
|
|
1091
|
+
// THE COMBO ASK, PRE-RESTART: a modern core re-scans the loras
|
|
1092
|
+
// folder per read, so the name may already serve; an unreachable
|
|
1093
|
+
// engine proves nothing (the null-doc contract) and refuses
|
|
1094
|
+
// nothing — the deadline refusal is folded by the same honesty.
|
|
1095
|
+
let inComboNow = false;
|
|
1096
|
+
try {
|
|
1097
|
+
inComboNow = loraNamesFromObjectInfo(await objectInfoDoc(ctx, railMs(req))).includes(comboName);
|
|
1098
|
+
}
|
|
1099
|
+
catch {
|
|
1100
|
+
inComboNow = false;
|
|
1101
|
+
}
|
|
1102
|
+
// THE RESTART CHAIN (the operator's design: the Manager reloads
|
|
1103
|
+
// ComfyUI). The chain rides the guarded restart door; ANY fold —
|
|
1104
|
+
// the guard's 409 (runs live), a rail error, a dead engine —
|
|
1105
|
+
// leaves the fetch ok and voices the owed restart.
|
|
1106
|
+
let restartVoice;
|
|
1107
|
+
try {
|
|
1108
|
+
await hRestart({ ...req, action: "restart" }, ctx);
|
|
1109
|
+
restartVoice = {
|
|
1110
|
+
restart_required: false,
|
|
1111
|
+
next_action: "status",
|
|
1112
|
+
note: "engine restart issued (the Manager reloads ComfyUI)",
|
|
1113
|
+
};
|
|
1114
|
+
}
|
|
1115
|
+
catch (e) {
|
|
1116
|
+
const why = e instanceof Refused ? e.message : e instanceof Error ? e.message : String(e);
|
|
1117
|
+
restartVoice = {
|
|
1118
|
+
restart_required: true,
|
|
1119
|
+
next_action: "restart",
|
|
1120
|
+
note: "the lora LANDED; the engine restart is owed and did not fire: " + why,
|
|
1121
|
+
};
|
|
1122
|
+
}
|
|
1123
|
+
const detail = comboName + " landed for " + family + " — " + restartVoice.note +
|
|
1124
|
+
(inComboNow ? " (already in the engine's combo)" : " (not yet in the engine's combo read)");
|
|
1125
|
+
const first = result.items[0];
|
|
1126
|
+
const data = {
|
|
1127
|
+
family,
|
|
1128
|
+
filename: comboName,
|
|
1129
|
+
url: req.url,
|
|
1130
|
+
operation_id: result.operationId,
|
|
1131
|
+
state: result.state,
|
|
1132
|
+
...(first?.path !== undefined ? { path: first.path } : {}),
|
|
1133
|
+
in_combo_now: inComboNow,
|
|
1134
|
+
restart_required: restartVoice.restart_required,
|
|
1135
|
+
next_action: restartVoice.next_action,
|
|
1136
|
+
// THE ROW SUGGESTION (the lora_install door's pattern): paste
|
|
1137
|
+
// this into the family's user rows (or the DECL) and the
|
|
1138
|
+
// picker's id-pick composes; the engine name serves as the
|
|
1139
|
+
// candidate either way (the mods union)
|
|
1140
|
+
row_suggestion: {
|
|
1141
|
+
id: comboName,
|
|
1142
|
+
filename: comboName,
|
|
1143
|
+
families: [family],
|
|
1144
|
+
source_url: req.url,
|
|
1145
|
+
label: filename.replace(/\.[^.]+$/, ""),
|
|
1146
|
+
},
|
|
1147
|
+
};
|
|
1148
|
+
return [
|
|
1149
|
+
200,
|
|
1150
|
+
{
|
|
1151
|
+
action: req.action,
|
|
1152
|
+
ok: true,
|
|
1153
|
+
detail,
|
|
1154
|
+
status: 200,
|
|
1155
|
+
state: result.state,
|
|
1156
|
+
next_action: restartVoice.next_action,
|
|
1157
|
+
operation_id: result.operationId,
|
|
1158
|
+
restart_required: restartVoice.restart_required,
|
|
1159
|
+
data,
|
|
1160
|
+
},
|
|
1161
|
+
];
|
|
1162
|
+
}
|
|
868
1163
|
function familyModelDeclared(ctx, id) {
|
|
869
1164
|
return ctx.models.allDecls().some((decl) => decl.id === id || decl.variants.some((variant) => variant.route === id || variant.cells.some((cell) => cell.route === id)));
|
|
870
1165
|
}
|
|
@@ -919,6 +1214,19 @@ async function hProvisionModel(req, ctx) {
|
|
|
919
1214
|
}
|
|
920
1215
|
throwIfAborted(signal);
|
|
921
1216
|
const result = await provisioner.ensure(ref, undefined, signal);
|
|
1217
|
+
// THE WEIGHTS LANDED UNDER A LIVING PROCESS (cold-drive run 6,
|
|
1218
|
+
|
|
1219
|
+
|
|
1220
|
+
// boot-time /object_info doc — the next compose read an empty combo
|
|
1221
|
+
// ("unet_name allows 0 values"). The engine's own folder scan is
|
|
1222
|
+
// mtime-live, so dropping the cached doc makes the landing visible
|
|
1223
|
+
// without a reboot (same door law as loraInstalled below).
|
|
1224
|
+
|
|
1225
|
+
// dead guard — model items never arm it (service answers "active";
|
|
1226
|
+
// only extensions yield restart_required), so the drop must not
|
|
1227
|
+
// wait on a flag that never fires.
|
|
1228
|
+
invalidateLiveObjectInfo(ctx);
|
|
1229
|
+
ctx.rearmWeights?.();
|
|
922
1230
|
return provisionEnvelope(req.action, result, {
|
|
923
1231
|
model: req.model,
|
|
924
1232
|
files: result.items.filter((item) => item.state === "active").map((item) => item.key),
|
|
@@ -926,6 +1234,83 @@ async function hProvisionModel(req, ctx) {
|
|
|
926
1234
|
}, [operationRow(req.model, result, ref, plan)]);
|
|
927
1235
|
});
|
|
928
1236
|
}
|
|
1237
|
+
|
|
1238
|
+
|
|
1239
|
+
|
|
1240
|
+
|
|
1241
|
+
|
|
1242
|
+
|
|
1243
|
+
|
|
1244
|
+
|
|
1245
|
+
|
|
1246
|
+
|
|
1247
|
+
|
|
1248
|
+
|
|
1249
|
+
async function hProvisionRuntime(req, ctx) {
|
|
1250
|
+
need(req, "runtime");
|
|
1251
|
+
estateOnly(req, ctx.endpoint());
|
|
1252
|
+
const decls = ctx.models.allDecls();
|
|
1253
|
+
const rt = decls.map((d) => d.runtime).find((r) => r !== undefined && r.name === req.runtime);
|
|
1254
|
+
if (rt === undefined) {
|
|
1255
|
+
const declared = [...new Set(decls.map((d) => d.runtime?.name).filter((n) => n !== undefined))];
|
|
1256
|
+
throw badRequest("unknown runtime '" + req.runtime + "' — no family DECL declares a runtime by this name (declared runtimes: " +
|
|
1257
|
+
(declared.length === 0 ? "none" : declared.join(", ")) + ")");
|
|
1258
|
+
}
|
|
1259
|
+
const root = engineRootOf();
|
|
1260
|
+
const decision = resolveRuntimeProvision(rt, {
|
|
1261
|
+
engineRoot: root,
|
|
1262
|
+
walkStart: root === null ? "" : engineOutputDir(root),
|
|
1263
|
+
env: runtimeEnvView(rt.env),
|
|
1264
|
+
repoSeedHome: join(ctx.repoRoot, "data", "runtime", rt.name),
|
|
1265
|
+
fs: nodeRuntimeFs,
|
|
1266
|
+
});
|
|
1267
|
+
if (decision.kind === "refused") {
|
|
1268
|
+
throw new Refused(decision.reason === "no-engine-root" || decision.reason === "env-invalid" ? 422 : 409, decision.detail, { kind: decision.reason, runtime: rt.name });
|
|
1269
|
+
}
|
|
1270
|
+
if (decision.kind === "linkable") {
|
|
1271
|
+
nodeRuntimeFs.mkdir(dirname(decision.target));
|
|
1272
|
+
nodeRuntimeFs.symlink(decision.seed, decision.target);
|
|
1273
|
+
// THE THROUGH-THE-LINK VERIFY (the operator's own gate): the
|
|
1274
|
+
// sentinels are re-read THROUGH the new link — a link that does
|
|
1275
|
+
// not resolve is a loud refusal, never a success envelope.
|
|
1276
|
+
const verified = rt.sentinel.filter((s) => sentinelHit(decision.target, s));
|
|
1277
|
+
if (verified.length !== rt.sentinel.length) {
|
|
1278
|
+
throw new Refused(500, "provision_runtime: the link " + decision.target + " → " + decision.seed +
|
|
1279
|
+
" landed but does not resolve every sentinel (" + rt.sentinel.join(", ") +
|
|
1280
|
+
") — remove the link by hand and press again", { kind: "broken-seed", runtime: rt.name });
|
|
1281
|
+
}
|
|
1282
|
+
return ok(req.action, "provision_runtime " + rt.name + ": linked " + decision.target + " → " + decision.seed +
|
|
1283
|
+
" (symlink — the engine tree holds a link, the repo seed stays the source of truth); sentinels verified through the link: " +
|
|
1284
|
+
verified.join(", "), {
|
|
1285
|
+
runtime: rt.name,
|
|
1286
|
+
state: "active",
|
|
1287
|
+
provisioned: true,
|
|
1288
|
+
strategy: "symlink",
|
|
1289
|
+
link: { seed: decision.seed, target: decision.target },
|
|
1290
|
+
sentinels_verified: [...verified],
|
|
1291
|
+
restart_required: false,
|
|
1292
|
+
next_action: "status",
|
|
1293
|
+
});
|
|
1294
|
+
}
|
|
1295
|
+
// THE ALREADY-PRESENT RECEIPT names where the runtime stood, and —
|
|
1296
|
+
// for a lanes.env-sourced value — states the engine-visibility
|
|
1297
|
+
|
|
1298
|
+
// file: the lane process may predate the edit; a restart arms it).
|
|
1299
|
+
const presentClause = decision.source === "lanes.env"
|
|
1300
|
+
? " — value read from the endpoint's lanes_env_file; this assumes the engine's lane reads the same file (EnvironmentFile), so restart the lane to arm a fresh edit"
|
|
1301
|
+
: decision.source === "walk-up"
|
|
1302
|
+
? " (walk-up from the engine's own output)"
|
|
1303
|
+
: "";
|
|
1304
|
+
return ok(req.action, "provision_runtime " + rt.name + ": already present at " + decision.home + " (" + decision.source + ")" + presentClause, {
|
|
1305
|
+
runtime: rt.name,
|
|
1306
|
+
state: "active",
|
|
1307
|
+
provisioned: false,
|
|
1308
|
+
home: decision.home,
|
|
1309
|
+
source: decision.source,
|
|
1310
|
+
restart_required: false,
|
|
1311
|
+
next_action: "status",
|
|
1312
|
+
});
|
|
1313
|
+
}
|
|
929
1314
|
/** THE F9 ACQUISITION DOOR (run-press acquisition — ONE door, TWO
|
|
930
1315
|
* callers): the bench popup's Download button and the agent's
|
|
931
1316
|
* comfy_manage acquire_weight seat both land here. It starts the
|
|
@@ -938,23 +1323,45 @@ async function hAcquireWeight(req, ctx) {
|
|
|
938
1323
|
const provisioner = provisioningOf(ctx);
|
|
939
1324
|
// THE POLL (the tracker's read): same action, operation id only —
|
|
940
1325
|
// no model, no fetch, no wait. Unknown ids 404 (never a fake
|
|
941
|
-
// zero — the tracker must render the truth).
|
|
1326
|
+
// zero — the tracker must render the truth). The cross-process
|
|
1327
|
+
|
|
1328
|
+
// the SHARED STORE — the transient seat's poll sees the durable
|
|
1329
|
+
// seat's states without sharing its memory.
|
|
942
1330
|
if (req.operation_id !== "") {
|
|
943
1331
|
if (typeof provisioner.progressOf !== "function") {
|
|
944
1332
|
throw unavailable("acquire_weight progress is not configured on this lane");
|
|
945
1333
|
}
|
|
946
|
-
const progress = provisioner.
|
|
1334
|
+
const progress = typeof provisioner.readProgress === "function"
|
|
1335
|
+
? await provisioner.readProgress(req.operation_id)
|
|
1336
|
+
: provisioner.progressOf(req.operation_id);
|
|
947
1337
|
if (progress === null || progress === undefined) {
|
|
948
1338
|
throw notFound("unknown acquire_weight operation: " + req.operation_id);
|
|
949
1339
|
}
|
|
1340
|
+
|
|
1341
|
+
// the files (same door law as hProvisionModel); the next read
|
|
1342
|
+
// re-fetches once and sees the landed weights
|
|
1343
|
+
if (progress.state === "installed" ||
|
|
1344
|
+
progress.state === "restart_required" ||
|
|
1345
|
+
progress.state === "active") {
|
|
1346
|
+
invalidateLiveObjectInfo(ctx);
|
|
1347
|
+
// the presence face re-arms with the doc: the files the engine
|
|
1348
|
+
// will serve are the files the board's present flags claim
|
|
1349
|
+
ctx.rearmWeights?.();
|
|
1350
|
+
}
|
|
950
1351
|
return ok(req.action, "acquire_weight " + progress.operationId + ": " + String(progress.bytes) + "/" + String(progress.total)
|
|
951
|
-
+ " bytes (" + progress.state
|
|
1352
|
+
+ " bytes (" + progress.state
|
|
1353
|
+
// THE LIVE-PHASE VOICE (audit F2): a frozen byte count with a
|
|
1354
|
+
// live phase names it (verifying:verify) — the popup's only
|
|
1355
|
+
// liveness window rides this text. Phaseless rows keep the
|
|
1356
|
+
// old shape.
|
|
1357
|
+
+ (progress.phase === undefined ? "" : ":" + progress.phase) + ")", {
|
|
952
1358
|
operation_id: progress.operationId,
|
|
953
1359
|
state: progress.state,
|
|
954
1360
|
bytes: progress.bytes,
|
|
955
1361
|
total: progress.total,
|
|
956
1362
|
next_action: "acquire_weight",
|
|
957
1363
|
...(progress.detail === undefined ? {} : { detail: progress.detail }),
|
|
1364
|
+
...(progress.phase === undefined ? {} : { phase: progress.phase }),
|
|
958
1365
|
});
|
|
959
1366
|
}
|
|
960
1367
|
// THE START (the Download press): model required, the missing file
|
|
@@ -966,6 +1373,7 @@ async function hAcquireWeight(req, ctx) {
|
|
|
966
1373
|
if (typeof provisioner.startWeightAcquire !== "function" || typeof provisioner.progressOf !== "function") {
|
|
967
1374
|
throw unavailable("acquire_weight is not configured on this lane");
|
|
968
1375
|
}
|
|
1376
|
+
const startAcquire = provisioner.startWeightAcquire;
|
|
969
1377
|
const family = {
|
|
970
1378
|
kind: "model",
|
|
971
1379
|
owner: "family",
|
|
@@ -973,11 +1381,19 @@ async function hAcquireWeight(req, ctx) {
|
|
|
973
1381
|
...(req.variant === "" ? {} : { variant: req.variant }),
|
|
974
1382
|
...(req.quant === "" ? {} : { quant: req.quant }),
|
|
975
1383
|
};
|
|
1384
|
+
// The provisioner hops ride the same deadline fuse as every
|
|
1385
|
+
// sibling arm (audit N-E2): a stalled provisioner answers 504
|
|
1386
|
+
// inside the request's own railMs, never hangs the door.
|
|
976
1387
|
let ref = family;
|
|
1388
|
+
let plan = null;
|
|
977
1389
|
try {
|
|
978
|
-
await provisioner.plan(family);
|
|
1390
|
+
plan = await withManageTimeout(req, ctx, async () => await provisioner.plan(family));
|
|
979
1391
|
}
|
|
980
1392
|
catch (error) {
|
|
1393
|
+
// the fuse's own refusal keeps its voice (audit F1): a deadline
|
|
1394
|
+
// maps to 504 here, never into the unknown-model 404 below
|
|
1395
|
+
if (error instanceof Refused)
|
|
1396
|
+
throw error;
|
|
981
1397
|
if (familyModelDeclared(ctx, req.model)) {
|
|
982
1398
|
throw notFound(error instanceof Error ? error.message : String(error));
|
|
983
1399
|
}
|
|
@@ -989,18 +1405,111 @@ async function hAcquireWeight(req, ctx) {
|
|
|
989
1405
|
...(req.quant === "" ? {} : { quant: req.quant }),
|
|
990
1406
|
};
|
|
991
1407
|
try {
|
|
992
|
-
await provisioner.plan(ref);
|
|
1408
|
+
plan = await withManageTimeout(req, ctx, async () => await provisioner.plan(ref));
|
|
993
1409
|
}
|
|
994
1410
|
catch (nested) {
|
|
1411
|
+
if (nested instanceof Refused)
|
|
1412
|
+
throw nested;
|
|
995
1413
|
throw notFound(nested instanceof Error ? nested.message : String(nested));
|
|
996
1414
|
}
|
|
997
1415
|
}
|
|
998
|
-
|
|
1416
|
+
|
|
1417
|
+
|
|
1418
|
+
// downloads every row of a multi-GB family. The name maps to plan
|
|
1419
|
+
// item keys exactly as the provisioner's own options.items filter
|
|
1420
|
+
// keys them (extension → id, else name — the snapshot channel
|
|
1421
|
+
// keys its trees by name, the row the missing-file refusal
|
|
1422
|
+
// voices); an unknown filename is the item-not-found refusal,
|
|
1423
|
+
// never a whole-family fetch.
|
|
1424
|
+
let acquireOptions;
|
|
1425
|
+
if (req.filename !== "" && plan !== null) {
|
|
1426
|
+
const itemsNamed = (p) => p.items
|
|
1427
|
+
.filter((item) => (item.kind === "extension" ? item.id : item.name) === req.filename)
|
|
1428
|
+
.map((item) => (item.kind === "extension" ? item.id : item.name));
|
|
1429
|
+
let wanted = itemsNamed(plan);
|
|
1430
|
+
|
|
1431
|
+
// a filename of a NON-default lane's cell artifact matched no item —
|
|
1432
|
+
// the family plan resolves ONE coordinate (the stated one, else the
|
|
1433
|
+
// family default), so every kroma weight refused item-not-found at
|
|
1434
|
+
// the ONE download door while the refusal's own anchor spoke the
|
|
1435
|
+
// URL ("they didn't get the URLs"). Derive the file's own
|
|
1436
|
+
// (variant, quant) from the DECL's cell artifacts and re-plan at
|
|
1437
|
+
// that coordinate — the DECL owns the fetch source (the names-only
|
|
1438
|
+
// law), the re-plan carries exactly the named row, and the
|
|
1439
|
+
// coordinate-scoped key (T-S4) keeps the dedupe honest.
|
|
1440
|
+
if (wanted.length === 0 && ref.kind === "model" && ref.owner === "family") {
|
|
1441
|
+
const decl = ctx.models.allDecls().find((d) => d.id === ref.id);
|
|
1442
|
+
const coords = decl === undefined
|
|
1443
|
+
? null
|
|
1444
|
+
: cellArtifactCoordinates(decl.variants ?? [], req.filename);
|
|
1445
|
+
if (coords !== null && coords.variant !== "") {
|
|
1446
|
+
ref = {
|
|
1447
|
+
...ref,
|
|
1448
|
+
variant: coords.variant,
|
|
1449
|
+
...(coords.quant !== "" ? { quant: coords.quant } : {}),
|
|
1450
|
+
};
|
|
1451
|
+
plan = await withManageTimeout(req, ctx, async () => await provisioner.plan(ref));
|
|
1452
|
+
wanted = itemsNamed(plan);
|
|
1453
|
+
}
|
|
1454
|
+
}
|
|
1455
|
+
if (wanted.length === 0) {
|
|
1456
|
+
throw badRequest(`acquire_weight file '${req.filename}' matches no provision row of '${req.model}' (item-not-found) — refusing to fetch the whole family for a one-file miss`);
|
|
1457
|
+
}
|
|
1458
|
+
acquireOptions = { items: wanted };
|
|
1459
|
+
}
|
|
1460
|
+
// THE BUSY MAP (audit I-S4): a plane at its concurrency cap is a
|
|
1461
|
+
// wait, not a failure — the 429 carries retry_after_ms and points
|
|
1462
|
+
// the caller back at the poll arm.
|
|
1463
|
+
|
|
1464
|
+
// starts the fetch HERE (the GUI press, the lane's own lifetime);
|
|
1465
|
+
// a transient seat (an agent session) QUEUES — but ONLY while a
|
|
1466
|
+
// FRESH claimer heartbeat from another seat answers on the shared
|
|
1467
|
+
// store (the dead-queue impossibility: no live claimer, no queue —
|
|
1468
|
+
// the press takes the wire itself). The queue arm never takes a
|
|
1469
|
+
// concurrency slot and never throws busy.
|
|
1470
|
+
const queueReady = provisioner.durableDownloads?.() !== true
|
|
1471
|
+
&& provisioner.requestWeightAcquire !== undefined
|
|
1472
|
+
&& (await provisioner.durableClaimerLive?.()) === true;
|
|
1473
|
+
const requestAcquire = queueReady ? provisioner.requestWeightAcquire : undefined;
|
|
1474
|
+
let operationId;
|
|
1475
|
+
try {
|
|
1476
|
+
operationId = await withManageTimeout(req, ctx, async () => requestAcquire !== undefined
|
|
1477
|
+
? await requestAcquire.call(provisioner, ref)
|
|
1478
|
+
: await startAcquire.call(provisioner, ref, acquireOptions));
|
|
1479
|
+
}
|
|
1480
|
+
catch (error) {
|
|
1481
|
+
if (error instanceof AcquireBusyError) {
|
|
1482
|
+
return [429, {
|
|
1483
|
+
action: req.action,
|
|
1484
|
+
ok: false,
|
|
1485
|
+
state: "busy",
|
|
1486
|
+
status: 429,
|
|
1487
|
+
detail: error.message,
|
|
1488
|
+
next_action: "acquire_weight",
|
|
1489
|
+
retry_after_ms: error.retryAfterMs,
|
|
1490
|
+
}];
|
|
1491
|
+
}
|
|
1492
|
+
throw error;
|
|
1493
|
+
}
|
|
999
1494
|
const progress = provisioner.progressOf(operationId);
|
|
1000
1495
|
const bytes = progress?.bytes ?? 0;
|
|
1001
1496
|
const total = progress?.total ?? 0;
|
|
1002
1497
|
const state = progress?.state ?? "acquiring";
|
|
1003
1498
|
const file = req.filename !== "" ? " (" + req.filename + ")" : "";
|
|
1499
|
+
|
|
1500
|
+
// acquiring text — the operator/agent reads WHERE the fetch runs
|
|
1501
|
+
// (the durable lane seat), never a started-here lie.
|
|
1502
|
+
if (state === "requested") {
|
|
1503
|
+
return ok(req.action, "queued " + req.model + file + " for the durable lane seat — the fetch starts there, never in this session (poll acquire_weight operation_id=" + operationId + ")", {
|
|
1504
|
+
operation_id: operationId,
|
|
1505
|
+
operationId,
|
|
1506
|
+
state,
|
|
1507
|
+
bytes,
|
|
1508
|
+
total,
|
|
1509
|
+
model: req.model,
|
|
1510
|
+
next_action: "acquire_weight",
|
|
1511
|
+
});
|
|
1512
|
+
}
|
|
1004
1513
|
return ok(req.action, "acquiring " + req.model + file + " — " + String(bytes) + "/" + String(total)
|
|
1005
1514
|
+ " bytes (poll acquire_weight operation_id=" + operationId + ")", {
|
|
1006
1515
|
operation_id: operationId,
|
|
@@ -1013,19 +1522,129 @@ async function hAcquireWeight(req, ctx) {
|
|
|
1013
1522
|
...(req.variant === "" ? {} : { variant: req.variant }),
|
|
1014
1523
|
...(req.quant === "" ? {} : { quant: req.quant }),
|
|
1015
1524
|
next_action: "acquire_weight",
|
|
1525
|
+
// the start answers the opening phase with the row (the face's
|
|
1526
|
+
// first paint already names the re-check, never a phaseless 0)
|
|
1527
|
+
...(progress?.phase === undefined ? {} : { phase: progress.phase }),
|
|
1528
|
+
});
|
|
1529
|
+
}
|
|
1530
|
+
// ── THE RESCUE VERBS (k2: "no retry, no delete, just stuck") ────────
|
|
1531
|
+
// The acquire door's own ledger judges both: a row whose fetch
|
|
1532
|
+
// stopped progressing (the service's stall budget settles it FAILED)
|
|
1533
|
+
// must leave the operator one press to re-fetch and one press to
|
|
1534
|
+
// clear the wedge.
|
|
1535
|
+
/** The shared live-refusal for both rescue verbs: a settled operation
|
|
1536
|
+
* passes; a live one (the provisioning contract's LIVE_ACQUIRE_STATES
|
|
1537
|
+
* — one spelling with the run gate's in-flight voice) answers 409
|
|
1538
|
+
* pointing back at the poll.
|
|
1539
|
+
* @param req the verb's request (names the verb in the voice).
|
|
1540
|
+
* @param progress the polled ledger row.
|
|
1541
|
+
* @returns void.
|
|
1542
|
+
* @throws Refused 409 when the row is still in flight. */
|
|
1543
|
+
function settledAcquireOrRefuse(req, progress) {
|
|
1544
|
+
if (LIVE_ACQUIRE_STATES.has(progress.state)) {
|
|
1545
|
+
throw new Refused(409, "acquire_weight " + progress.operationId + " is still in flight (" + progress.state + ", "
|
|
1546
|
+
+ String(progress.bytes) + "/" + String(progress.total) + " bytes) — poll acquire_weight operation_id="
|
|
1547
|
+
+ progress.operationId + "; " + req.action + " is for a settled operation");
|
|
1548
|
+
}
|
|
1549
|
+
}
|
|
1550
|
+
/** acquire_retry — a fresh fetch on a settled-failed row's ref. The
|
|
1551
|
+
* dead row's truth stays (the face keeps its why); the answer's
|
|
1552
|
+
* operation_id is the FRESH fetch (never a resurrect of the dead
|
|
1553
|
+
* row). A live row refuses 409; a landed row refuses 409 (the
|
|
1554
|
+
* weights are on the store — nothing to retry); an unknown id 404s. */
|
|
1555
|
+
async function hAcquireRetry(req, ctx) {
|
|
1556
|
+
need(req, "operation_id");
|
|
1557
|
+
estateOnly(req, ctx.endpoint());
|
|
1558
|
+
const provisioner = provisioningOf(ctx);
|
|
1559
|
+
if (typeof provisioner.progressOf !== "function" || typeof provisioner.startWeightAcquire !== "function") {
|
|
1560
|
+
throw unavailable("acquire_retry is not configured on this lane");
|
|
1561
|
+
}
|
|
1562
|
+
const progress = provisioner.progressOf(req.operation_id);
|
|
1563
|
+
if (progress === null || progress === undefined) {
|
|
1564
|
+
throw notFound("unknown acquire_weight operation: " + req.operation_id);
|
|
1565
|
+
}
|
|
1566
|
+
settledAcquireOrRefuse(req, progress);
|
|
1567
|
+
if (progress.state === "installed" || progress.state === "restart_required" || progress.state === "active") {
|
|
1568
|
+
throw new Refused(409, "acquire_weight " + progress.operationId + " already landed (" + progress.state
|
|
1569
|
+
+ ") — the weights are on the store, nothing to retry");
|
|
1570
|
+
}
|
|
1571
|
+
const startAcquire = provisioner.startWeightAcquire;
|
|
1572
|
+
let operationId;
|
|
1573
|
+
try {
|
|
1574
|
+
operationId = await withManageTimeout(req, ctx, async () => await startAcquire.call(provisioner, progress.ref));
|
|
1575
|
+
}
|
|
1576
|
+
catch (error) {
|
|
1577
|
+
// THE BUSY MAP (audit I-S4): the same wait-not-failure face the
|
|
1578
|
+
// start arm answers — a plane at its cap is a retry_after, and
|
|
1579
|
+
// the dead row stays exactly as it was
|
|
1580
|
+
if (error instanceof AcquireBusyError) {
|
|
1581
|
+
return [429, {
|
|
1582
|
+
action: req.action,
|
|
1583
|
+
ok: false,
|
|
1584
|
+
state: "busy",
|
|
1585
|
+
status: 429,
|
|
1586
|
+
detail: error.message,
|
|
1587
|
+
next_action: "acquire_weight",
|
|
1588
|
+
retry_after_ms: error.retryAfterMs,
|
|
1589
|
+
}];
|
|
1590
|
+
}
|
|
1591
|
+
throw error;
|
|
1592
|
+
}
|
|
1593
|
+
return ok(req.action, "retrying " + progress.operationId + " (" + progress.state + ") as a fresh fetch — poll acquire_weight operation_id="
|
|
1594
|
+
+ operationId + " (the dead row's truth is kept)", {
|
|
1595
|
+
operation_id: operationId,
|
|
1596
|
+
operationId,
|
|
1597
|
+
state: "acquiring",
|
|
1598
|
+
retried_operation_id: progress.operationId,
|
|
1599
|
+
next_action: "acquire_weight",
|
|
1600
|
+
});
|
|
1601
|
+
}
|
|
1602
|
+
/** acquire_discard — a settled acquire row is evicted (ledger entry,
|
|
1603
|
+
* by-ref pointer, stored row) so the wedge is clearable and a later
|
|
1604
|
+
* acquire_weight poll answers 404. A live row refuses 409; an
|
|
1605
|
+
* unknown id 404s. */
|
|
1606
|
+
async function hAcquireDiscard(req, ctx) {
|
|
1607
|
+
need(req, "operation_id");
|
|
1608
|
+
estateOnly(req, ctx.endpoint());
|
|
1609
|
+
const provisioner = provisioningOf(ctx);
|
|
1610
|
+
if (typeof provisioner.progressOf !== "function" || typeof provisioner.discardAcquire !== "function") {
|
|
1611
|
+
throw unavailable("acquire_discard is not configured on this lane");
|
|
1612
|
+
}
|
|
1613
|
+
const progress = provisioner.progressOf(req.operation_id);
|
|
1614
|
+
if (progress === null || progress === undefined) {
|
|
1615
|
+
throw notFound("unknown acquire_weight operation: " + req.operation_id);
|
|
1616
|
+
}
|
|
1617
|
+
settledAcquireOrRefuse(req, progress);
|
|
1618
|
+
provisioner.discardAcquire(req.operation_id);
|
|
1619
|
+
ctx.rearmWeights?.();
|
|
1620
|
+
return ok(req.action, "discarded acquire_weight " + progress.operationId + " (" + progress.state + ") — a later poll answers 404", {
|
|
1621
|
+
operation_id: progress.operationId,
|
|
1622
|
+
state: progress.state,
|
|
1623
|
+
next_action: "status",
|
|
1016
1624
|
});
|
|
1017
1625
|
}
|
|
1018
1626
|
async function hRestart(req, ctx) {
|
|
1019
1627
|
guardLifecycle(req, ctx);
|
|
1020
1628
|
const cfg = ctx.endpoint();
|
|
1021
1629
|
estateOnly(req, cfg);
|
|
1630
|
+
|
|
1631
|
+
// call so a run pressed mid-reboot refuses instead of tearing.
|
|
1632
|
+
const releaseLifecycle = holdLifecycle(req.action);
|
|
1022
1633
|
try {
|
|
1023
1634
|
await managerPost(base(ctx), "/manager/reboot", {}, { ctx, timeoutMs: 10_000 });
|
|
1024
|
-
recordEngineBoot(ctx, "estate restart");
|
|
1025
|
-
|
|
1026
|
-
// the cached /object_info doc must not outlive it (the refresh
|
|
1027
1635
|
|
|
1028
|
-
|
|
1636
|
+
// await — the cached /object_info doc must not outlive it. The
|
|
1637
|
+
// drop rides a finally so an abort inside the receipt write
|
|
1638
|
+
// cannot skip it (the abort still propagates after the drop).
|
|
1639
|
+
try {
|
|
1640
|
+
await recordEngineBoot(ctx, "estate restart");
|
|
1641
|
+
}
|
|
1642
|
+
finally {
|
|
1643
|
+
|
|
1644
|
+
// the cached /object_info doc must not outlive it (the refresh
|
|
1645
|
+
|
|
1646
|
+
invalidateLiveObjectInfo(ctx);
|
|
1647
|
+
}
|
|
1029
1648
|
return ok(req.action, "reboot issued (systemd re-spawns the engine)", { next_action: "status" });
|
|
1030
1649
|
}
|
|
1031
1650
|
catch (e) {
|
|
@@ -1033,23 +1652,38 @@ async function hRestart(req, ctx) {
|
|
|
1033
1652
|
// The vendor reboots by exiting: the connection can drop after
|
|
1034
1653
|
// the 200 is sent — same honest answer.
|
|
1035
1654
|
if (/fetch failed|ECONNRESET|socket/i.test(e.text)) {
|
|
1036
|
-
|
|
1037
|
-
|
|
1655
|
+
try {
|
|
1656
|
+
await recordEngineBoot(ctx, "estate restart (connection dropped mid-answer)");
|
|
1657
|
+
}
|
|
1658
|
+
finally {
|
|
1659
|
+
invalidateLiveObjectInfo(ctx);
|
|
1660
|
+
}
|
|
1038
1661
|
return ok(req.action, "reboot issued (connection closed by restart)", { next_action: "status" });
|
|
1039
1662
|
}
|
|
1040
1663
|
throw mapManagerRefused(e, req.action);
|
|
1041
1664
|
}
|
|
1042
1665
|
throw mapRail(e, req.action);
|
|
1043
1666
|
}
|
|
1667
|
+
finally {
|
|
1668
|
+
releaseLifecycle();
|
|
1669
|
+
}
|
|
1044
1670
|
}
|
|
1045
1671
|
async function hStop(req, ctx) {
|
|
1046
1672
|
guardLifecycle(req, ctx);
|
|
1047
1673
|
estateOnly(req, ctx.endpoint());
|
|
1048
|
-
|
|
1674
|
+
|
|
1675
|
+
// systemctl call so a run pressed mid-stop refuses.
|
|
1676
|
+
const releaseLifecycle = holdLifecycle(req.action);
|
|
1677
|
+
try {
|
|
1678
|
+
return await systemctl(req, "stop", ctx.comfyUnit, ctx.signal);
|
|
1679
|
+
}
|
|
1680
|
+
finally {
|
|
1681
|
+
releaseLifecycle();
|
|
1682
|
+
}
|
|
1049
1683
|
}
|
|
1050
1684
|
async function hLaunch(req, ctx) {
|
|
1051
1685
|
estateOnly(req, ctx.endpoint());
|
|
1052
|
-
return await systemctl(req, "start", ctx.signal);
|
|
1686
|
+
return await systemctl(req, "start", ctx.comfyUnit, ctx.signal);
|
|
1053
1687
|
}
|
|
1054
1688
|
async function hUpdate(req, ctx) {
|
|
1055
1689
|
if (req.target !== "comfy") {
|
|
@@ -1058,6 +1692,9 @@ async function hUpdate(req, ctx) {
|
|
|
1058
1692
|
guardLifecycle(req, ctx);
|
|
1059
1693
|
const cfg = ctx.endpoint();
|
|
1060
1694
|
estateOnly(req, cfg);
|
|
1695
|
+
|
|
1696
|
+
// calls so a run pressed mid-update refuses instead of tearing.
|
|
1697
|
+
const releaseLifecycle = holdLifecycle(req.action);
|
|
1061
1698
|
try {
|
|
1062
1699
|
await managerPost(base(ctx), "/manager/queue/update_comfyui", {}, { ctx, timeoutMs: 10_000 });
|
|
1063
1700
|
await managerPost(base(ctx), "/manager/queue/start", {}, { ctx, timeoutMs: 10_000 });
|
|
@@ -1082,12 +1719,18 @@ async function hUpdate(req, ctx) {
|
|
|
1082
1719
|
throw e;
|
|
1083
1720
|
throw mapRail(e, req.action);
|
|
1084
1721
|
}
|
|
1722
|
+
finally {
|
|
1723
|
+
releaseLifecycle();
|
|
1724
|
+
}
|
|
1085
1725
|
}
|
|
1086
1726
|
async function hSwitchVersion(req, ctx) {
|
|
1087
1727
|
need(req, "version");
|
|
1088
1728
|
guardLifecycle(req, ctx);
|
|
1089
1729
|
const cfg = ctx.endpoint();
|
|
1090
1730
|
estateOnly(req, cfg);
|
|
1731
|
+
|
|
1732
|
+
// switch so a run pressed mid-switch refuses instead of tearing.
|
|
1733
|
+
const releaseLifecycle = holdLifecycle(req.action);
|
|
1091
1734
|
try {
|
|
1092
1735
|
const doc = await managerGet(base(ctx), "/comfyui_manager/comfyui_versions", {
|
|
1093
1736
|
ctx, timeoutMs: 30_000,
|
|
@@ -1103,6 +1746,9 @@ async function hSwitchVersion(req, ctx) {
|
|
|
1103
1746
|
catch (e) {
|
|
1104
1747
|
throw mapRail(e, req.action);
|
|
1105
1748
|
}
|
|
1749
|
+
finally {
|
|
1750
|
+
releaseLifecycle();
|
|
1751
|
+
}
|
|
1106
1752
|
return ok(req.action, "switch to " + req.version + " issued (restart required)", {
|
|
1107
1753
|
state: "restart_required",
|
|
1108
1754
|
restart_required: true,
|
|
@@ -1114,14 +1760,51 @@ async function hFree(req, ctx) {
|
|
|
1114
1760
|
const b = base(ctx);
|
|
1115
1761
|
if (b === "")
|
|
1116
1762
|
throw planeUnavailable(b, "no endpoint url");
|
|
1763
|
+
|
|
1764
|
+
// call so a run pressed mid-free refuses instead of tearing.
|
|
1765
|
+
const releaseLifecycle = holdLifecycle(req.action);
|
|
1117
1766
|
try {
|
|
1118
1767
|
await managerPost(b, "/free", { unload_models: true, free_memory: true }, { ctx, timeoutMs: 30_000 });
|
|
1119
1768
|
}
|
|
1120
1769
|
catch (e) {
|
|
1121
1770
|
throw mapRail(e, req.action);
|
|
1122
1771
|
}
|
|
1772
|
+
finally {
|
|
1773
|
+
releaseLifecycle();
|
|
1774
|
+
}
|
|
1123
1775
|
return ok(req.action, "free issued (next worker iteration)", { next_action: "status" });
|
|
1124
1776
|
}
|
|
1777
|
+
|
|
1778
|
+
|
|
1779
|
+
|
|
1780
|
+
|
|
1781
|
+
|
|
1782
|
+
|
|
1783
|
+
|
|
1784
|
+
|
|
1785
|
+
|
|
1786
|
+
|
|
1787
|
+
|
|
1788
|
+
const SETTLE_GRACE_MS = 120_000;
|
|
1789
|
+
async function hSettleStale(req, ctx) {
|
|
1790
|
+
const queue = await engineQueueView(ctx);
|
|
1791
|
+
if (queue === null) {
|
|
1792
|
+
throw new Refused(409, "settle_stale refused: the engine queue is unreachable — no corroboration, nothing settles (fail-closed)");
|
|
1793
|
+
}
|
|
1794
|
+
if (queue.running > 0 || queue.pending > 0) {
|
|
1795
|
+
throw new Refused(409, "settle_stale refused: the engine is working (running " + queue.running + " · pending " + queue.pending +
|
|
1796
|
+
") — every live-worded sidecar may be live; settle only against an idle engine");
|
|
1797
|
+
}
|
|
1798
|
+
const boot = engineBootRow(ctx);
|
|
1799
|
+
const bootAt = boot["known"] === true ? Date.parse(String(boot["boot_at"])) : NaN;
|
|
1800
|
+
const now = Date.now();
|
|
1801
|
+
const outcome = settleStaleClaims(ctx.stateRoots, (_name, mtimeMs) => {
|
|
1802
|
+
if (Number.isFinite(bootAt) && mtimeMs < bootAt)
|
|
1803
|
+
return true;
|
|
1804
|
+
return mtimeMs < now - SETTLE_GRACE_MS;
|
|
1805
|
+
});
|
|
1806
|
+
return ok(req.action, "settled " + outcome.settled.length + " stale claim(s), skipped " + outcome.skipped.length, { next_action: "status", settled: outcome.settled, skipped: outcome.skipped });
|
|
1807
|
+
}
|
|
1125
1808
|
// ── endpoint_set: the operator's server URL change ────────────────
|
|
1126
1809
|
// Validates FIRST (a live /system_stats probe — an unreachable URL
|
|
1127
1810
|
// is refused, never written), then rewrites ONLY `url` in the
|
|
@@ -1135,6 +1818,19 @@ async function hEndpointSet(req, ctx) {
|
|
|
1135
1818
|
}
|
|
1136
1819
|
// Probe the candidate BEFORE writing (no unreachable URL ever
|
|
1137
1820
|
// lands in the config; the old URL keeps serving on refusal).
|
|
1821
|
+
// THE ENV FENCE (audit I-S2, the KEY LAW divergence enforced):
|
|
1822
|
+
// resolveEngineBaseUrl reads COMFYUI_URL FIRST, so with the env
|
|
1823
|
+
// set, this file write lands on a plane no reader keys off —
|
|
1824
|
+
// the census, lora doors, and live docs keep answering the env
|
|
1825
|
+
// server while the UI reports the file's. Refuse instead of
|
|
1826
|
+
// warning: the operator unsets COMFYUI_URL (or points it at the
|
|
1827
|
+
// same server) and the write becomes real.
|
|
1828
|
+
const envUrl = (process.env["COMFYUI_URL"] ?? "").trim().replace(/\/+$/, "");
|
|
1829
|
+
if (envUrl !== "" && envUrl !== url) {
|
|
1830
|
+
throw new Refused(409, "endpoint_set: COMFYUI_URL='" + envUrl + "' overrides the config file — " +
|
|
1831
|
+
"every reader keys off the env while this write lands on the file, " +
|
|
1832
|
+
"so the door would silently change nothing. Unset COMFYUI_URL or point it at '" + url + "' first.", { state: "conflict", next_action: "endpoint_set" });
|
|
1833
|
+
}
|
|
1138
1834
|
const dl = deadlineOf(ctx.signal, 5000, "ENDPOINT_SET_PROBE");
|
|
1139
1835
|
let stats;
|
|
1140
1836
|
try {
|
|
@@ -1161,14 +1857,48 @@ async function hEndpointSet(req, ctx) {
|
|
|
1161
1857
|
throwIfAborted(ctx.signal);
|
|
1162
1858
|
const cfgPath = endpointConfigPath();
|
|
1163
1859
|
const cfg = { ...loadEndpointConfig() };
|
|
1860
|
+
// Captured BEFORE the mutation below: priorUrl must read the
|
|
1861
|
+
// PRE-write config url. Reading cfg["url"] after `cfg["url"] = url`
|
|
1862
|
+
// returns the new url twice and the old server's doc never drops
|
|
1863
|
+
// (found by the MP-R2 wall — the drop loop read [url, url]).
|
|
1864
|
+
const priorUrl = (() => {
|
|
1865
|
+
const raw = cfg["url"];
|
|
1866
|
+
return typeof raw === "string" && raw.trim() !== "" ? raw.trim().replace(/\/+$/, "") : url;
|
|
1867
|
+
})();
|
|
1164
1868
|
cfg["url"] = url;
|
|
1165
1869
|
try {
|
|
1166
|
-
|
|
1870
|
+
// J6: the endpoint config rides the atomic writer — a torn
|
|
1871
|
+
// comfyui_endpoint.json would brick every later config read on
|
|
1872
|
+
// this estate. The writer rejects with Error only (fs/promises),
|
|
1873
|
+
// so the Refused narrow still holds.
|
|
1874
|
+
await writeJsonAtomic(cfgPath, cfg);
|
|
1167
1875
|
}
|
|
1168
1876
|
catch (e) {
|
|
1169
|
-
// writeFileSync throws SystemError (an Error) only — the narrow is the law.
|
|
1170
1877
|
throw new Refused(500, "endpoint_set: config write failed (" + e.message + ") — the endpoint is unchanged");
|
|
1171
1878
|
}
|
|
1879
|
+
|
|
1880
|
+
// server's ~3.5MB census doc forever (oiCache is unbounded) — drop
|
|
1881
|
+
// the pre-write config url AND the new one, so neither seat serves
|
|
1882
|
+
|
|
1883
|
+
|
|
1884
|
+
// abort check — the write above already landed, so an abort
|
|
1885
|
+
// delivered between the write and the drop still drops (the old
|
|
1886
|
+
// server's doc must not be served indefinitely). A write that did
|
|
1887
|
+
// NOT land throws above and never reaches this drop.
|
|
1888
|
+
for (const stale of [priorUrl, url]) {
|
|
1889
|
+
try {
|
|
1890
|
+
invalidateObjectInfo(stale);
|
|
1891
|
+
}
|
|
1892
|
+
catch (e) {
|
|
1893
|
+
// no endpoint configured under this spelling — no key was
|
|
1894
|
+
// cached under it. The LIVE key failing is different (audit
|
|
1895
|
+
// N-S6): the stale doc survives and the next census serves the
|
|
1896
|
+
// old server's node set — that failure is voiced, not folded.
|
|
1897
|
+
if (stale === url) {
|
|
1898
|
+
console.log("[estate-queue] endpoint_set: the oiCache drop failed on the LIVE key — the next census may serve the previous server's node set:", e instanceof Error ? e.message : String(e));
|
|
1899
|
+
}
|
|
1900
|
+
}
|
|
1901
|
+
}
|
|
1172
1902
|
throwIfAborted(ctx.signal);
|
|
1173
1903
|
const sys = (stats["system"] ?? {});
|
|
1174
1904
|
return ok(req.action, "endpoint set to " + url + " (ComfyUI " + String(sys["comfyui_version"] ?? "?") + " answered)", { url, comfyui_version: sys["comfyui_version"] ?? null });
|
|
@@ -1244,6 +1974,28 @@ async function hSnapshotList(req, ctx) {
|
|
|
1244
1974
|
const items = snapshotItems(doc);
|
|
1245
1975
|
return withNextAction(ok(req.action, items.length + " snapshot(s)", items), "snapshot_save");
|
|
1246
1976
|
}
|
|
1977
|
+
// THE PREFLIGHT HANDLER (audit 019 C3): the five-axis read — one
|
|
1978
|
+
// row per axis, misses named with their doors, never a degraded
|
|
1979
|
+
// green (a probe throw IS a miss — see managePreflight.ts). ok
|
|
1980
|
+
// stays true: the read succeeded; the misses are the read's
|
|
1981
|
+
// payload, voiced by the render and the estate's boot note.
|
|
1982
|
+
async function hPreflight(req, ctx) {
|
|
1983
|
+
const rows = await runPreflight(ctx);
|
|
1984
|
+
const misses = rows.filter((r) => r.state === "miss");
|
|
1985
|
+
const lines = rows.map(preflightLine);
|
|
1986
|
+
return [
|
|
1987
|
+
200,
|
|
1988
|
+
{
|
|
1989
|
+
action: req.action,
|
|
1990
|
+
ok: true,
|
|
1991
|
+
detail: rows.length + " axis(es) checked, " +
|
|
1992
|
+
(misses.length === 0 ? "all green" : misses.length + " miss(es): " + misses.map((m) => m.axis).join(", ")),
|
|
1993
|
+
rows: lines,
|
|
1994
|
+
misses: misses.map(preflightLine),
|
|
1995
|
+
data: { axes: rows },
|
|
1996
|
+
},
|
|
1997
|
+
];
|
|
1998
|
+
}
|
|
1247
1999
|
async function hSnapshotSave(req, ctx) {
|
|
1248
2000
|
const cfg = ctx.endpoint();
|
|
1249
2001
|
estateOnly(req, cfg);
|
|
@@ -1281,12 +2033,18 @@ async function hSnapshotRestore(req, ctx) {
|
|
|
1281
2033
|
guardLifecycle(req, ctx);
|
|
1282
2034
|
const cfg = ctx.endpoint();
|
|
1283
2035
|
estateOnly(req, cfg);
|
|
2036
|
+
|
|
2037
|
+
// call so a run pressed mid-restore refuses instead of tearing.
|
|
2038
|
+
const releaseLifecycle = holdLifecycle(req.action);
|
|
1284
2039
|
try {
|
|
1285
2040
|
await managerPost(base(ctx), "/snapshot/restore", { target: req.snapshot }, { ctx, timeoutMs: 30_000 });
|
|
1286
2041
|
}
|
|
1287
2042
|
catch (e) {
|
|
1288
2043
|
throw mapRail(e, req.action);
|
|
1289
2044
|
}
|
|
2045
|
+
finally {
|
|
2046
|
+
releaseLifecycle();
|
|
2047
|
+
}
|
|
1290
2048
|
return ok(req.action, "restore of " + req.snapshot + " scheduled (restart required)", {
|
|
1291
2049
|
state: "restart_required",
|
|
1292
2050
|
restart_required: true,
|
|
@@ -1311,7 +2069,7 @@ const LORAS_DIR_UNDECLARED = 'the loras install dir is undeclared — set MELITE
|
|
|
1311
2069
|
async function hLoraList(req, ctx) {
|
|
1312
2070
|
const cfg = ctx.endpoint();
|
|
1313
2071
|
estateOnly(req, cfg);
|
|
1314
|
-
const combo = loraNamesFromObjectInfo(await objectInfoDoc(ctx));
|
|
2072
|
+
const combo = loraNamesFromObjectInfo(await objectInfoDoc(ctx, railMs(req)));
|
|
1315
2073
|
const file = readUserLoraRows(userLorasPath());
|
|
1316
2074
|
const unboarded = unboardedRows(file.rows, combo);
|
|
1317
2075
|
return ok(req.action, combo.length + ' LoRA name(s) the engine accepts; ' + file.rows.length + ' user row(s) offered', {
|
|
@@ -1362,16 +2120,21 @@ async function hLoraInstall(req, ctx) {
|
|
|
1362
2120
|
return loraInstalled(req, ctx, dir, result, 'copied');
|
|
1363
2121
|
}
|
|
1364
2122
|
/** THE ANSWER both arms share: the name, the bytes, whether the
|
|
1365
|
-
* engine already lists it, and the restart it needs
|
|
1366
|
-
* folder
|
|
1367
|
-
*
|
|
1368
|
-
*
|
|
2123
|
+
* engine already lists it, and the restart it needs. The pinned
|
|
2124
|
+
* core's folder listing is mtime-live (cached_filename_list_
|
|
2125
|
+
* re-stats each folder per read — data/runtime/comfyui/
|
|
2126
|
+
* folder_paths.py:499), so a landed file shows in the next census
|
|
2127
|
+
* WITHOUT a reboot; the harness's own cached /object_info doc is
|
|
2128
|
+
* the stale layer, and the acquisition doors drop it (1a6f773c).
|
|
2129
|
+
* A restart stays required for custom_nodes (import-time), never
|
|
2130
|
+
* for a weight file. The row suggestion rides along so the
|
|
2131
|
+
* operator's next step is a paste, not a hunt. */
|
|
1369
2132
|
async function loraInstalled(req, ctx, dir, result, verb) {
|
|
1370
2133
|
// truth at answer time: the engine may have rebooted since the
|
|
1371
2134
|
// cache filled (an out-of-band restart), so the combo read below
|
|
1372
2135
|
// must not serve the pre-restart doc — one fresh fetch per install
|
|
1373
2136
|
invalidateLiveObjectInfo(ctx);
|
|
1374
|
-
const combo = loraNamesFromObjectInfo(await objectInfoDoc(ctx));
|
|
2137
|
+
const combo = loraNamesFromObjectInfo(await objectInfoDoc(ctx, railMs(req)));
|
|
1375
2138
|
const visible = combo.includes(result.filename);
|
|
1376
2139
|
return ok(req.action, verb + ' ' + result.filename + ' (' + result.bytes + ' bytes) into ' + dir
|
|
1377
2140
|
+ (visible ? ' — already in the engine\'s list' : ' — restart the engine to enter its list'), {
|
|
@@ -1390,6 +2153,22 @@ async function loraInstalled(req, ctx, dir, result, verb) {
|
|
|
1390
2153
|
},
|
|
1391
2154
|
});
|
|
1392
2155
|
}
|
|
2156
|
+
|
|
2157
|
+
|
|
2158
|
+
|
|
2159
|
+
|
|
2160
|
+
|
|
2161
|
+
|
|
2162
|
+
|
|
2163
|
+
|
|
2164
|
+
|
|
2165
|
+
|
|
2166
|
+
async function hRefmodsList(req, ctx) {
|
|
2167
|
+
const cfg = ctx.endpoint();
|
|
2168
|
+
estateOnly(req, cfg);
|
|
2169
|
+
const stems = refmodNamesFromObjectInfo(await objectInfoDoc(ctx, railMs(req)));
|
|
2170
|
+
return ok(req.action, stems.length + " refmods pack(s) the engine accepts", { stems });
|
|
2171
|
+
}
|
|
1393
2172
|
/** The engine's node declaration, or null when the engine is
|
|
1394
2173
|
* unreachable (the cross-check then proves nothing and refuses
|
|
1395
2174
|
* nothing — never a throw across the sidebar). ONE reader, the
|
|
@@ -1400,13 +2179,32 @@ async function loraInstalled(req, ctx, dir, result, verb) {
|
|
|
1400
2179
|
* is unreachable. It is the doc (not one node) because the reader
|
|
1401
2180
|
* that turns it into the LoRA list is the reader's own job, and a
|
|
1402
2181
|
* per-node hop here would make the two spellings drift. */
|
|
1403
|
-
async function objectInfoDoc(ctx) {
|
|
2182
|
+
async function objectInfoDoc(ctx, boundMs) {
|
|
2183
|
+
|
|
2184
|
+
|
|
2185
|
+
// same railMs bound every other manage hop rides. The deadline
|
|
2186
|
+
// refusal is LOUD — a hung engine refuses the door (504), it
|
|
2187
|
+
// never reads as an empty lora combo; only an engine that cannot
|
|
2188
|
+
// be reached at all folds to the null-doc contract.
|
|
2189
|
+
throwIfAborted(ctx.signal);
|
|
2190
|
+
if (ctx.objectInfo !== undefined) {
|
|
2191
|
+
try {
|
|
2192
|
+
return await ctx.objectInfo();
|
|
2193
|
+
}
|
|
2194
|
+
catch {
|
|
2195
|
+
return null;
|
|
2196
|
+
}
|
|
2197
|
+
}
|
|
1404
2198
|
try {
|
|
1405
|
-
return ctx.
|
|
1406
|
-
? await ctx.objectInfo()
|
|
1407
|
-
: await liveObjectInfo(resolveEngineBaseUrl());
|
|
2199
|
+
return await liveObjectInfo(resolveEngineBaseUrl(), ctx.signal, boundMs);
|
|
1408
2200
|
}
|
|
1409
|
-
catch {
|
|
2201
|
+
catch (error) {
|
|
2202
|
+
// only the deadline goes loud; an unreachable or endpoint-less
|
|
2203
|
+
// engine keeps the settled null-doc contract (not-visible), and
|
|
2204
|
+
// an aborted door needs no refusal past its own teardown
|
|
2205
|
+
if (error instanceof ComfyError && error.code === 'deadline') {
|
|
2206
|
+
throw new Refused(504, error.message);
|
|
2207
|
+
}
|
|
1410
2208
|
return null;
|
|
1411
2209
|
}
|
|
1412
2210
|
}
|
|
@@ -1414,7 +2212,12 @@ async function objectInfoDoc(ctx) {
|
|
|
1414
2212
|
* process serves — the same key objectInfoDoc's live arm reads.
|
|
1415
2213
|
* A ctx carrying its own objectInfo seam never touches the global
|
|
1416
2214
|
* cache, so there is nothing to drop; and an endpoint-less
|
|
1417
|
-
* resolveEngineBaseUrl refusal means no key was ever cached.
|
|
2215
|
+
* resolveEngineBaseUrl refusal means no key was ever cached.
|
|
2216
|
+
* KEY LAW: the drop keys off resolveEngineBaseUrl() (env/config),
|
|
2217
|
+
* never ctx.endpoint() — matching the reader. A lane seating a
|
|
2218
|
+
* ctx.endpoint() that differs from the resolved base must point
|
|
2219
|
+
* COMFYUI_URL at the same server, or the drop lands on a key no
|
|
2220
|
+
* census reads and the stale doc survives. */
|
|
1418
2221
|
function invalidateLiveObjectInfo(ctx) {
|
|
1419
2222
|
if (ctx.objectInfo !== undefined)
|
|
1420
2223
|
return;
|
|
@@ -1438,17 +2241,24 @@ const HANDLERS = {
|
|
|
1438
2241
|
install_extension_url: hInstallExtensionUrl,
|
|
1439
2242
|
download_model: hDownloadModel,
|
|
1440
2243
|
provision_model: hProvisionModel,
|
|
2244
|
+
provision_runtime: hProvisionRuntime,
|
|
1441
2245
|
acquire_weight: hAcquireWeight,
|
|
2246
|
+
acquire_retry: hAcquireRetry,
|
|
2247
|
+
acquire_discard: hAcquireDiscard,
|
|
1442
2248
|
restart: hRestart,
|
|
1443
2249
|
stop: hStop,
|
|
1444
2250
|
launch: hLaunch,
|
|
1445
2251
|
update: hUpdate,
|
|
1446
2252
|
switch_version: hSwitchVersion,
|
|
1447
2253
|
free: hFree,
|
|
2254
|
+
settle_stale: hSettleStale,
|
|
1448
2255
|
snapshot_save: hSnapshotSave,
|
|
1449
2256
|
snapshot_restore: hSnapshotRestore,
|
|
1450
2257
|
lora_list: hLoraList,
|
|
1451
2258
|
lora_install: hLoraInstall,
|
|
2259
|
+
lora_fetch: hLoraFetch,
|
|
2260
|
+
refmods_list: hRefmodsList,
|
|
2261
|
+
preflight: hPreflight,
|
|
1452
2262
|
};
|
|
1453
2263
|
function refusalDataFields(data) {
|
|
1454
2264
|
if (typeof data !== "object" || data === null)
|