@melite/estate-queue 0.0.0-stage → 0.1.5-pre-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.
Files changed (131) hide show
  1. package/LICENSE +557 -0
  2. package/README.md +54 -2
  3. package/lib/bakeParams.d.ts +17 -0
  4. package/lib/bakeParams.js +182 -0
  5. package/lib/bench.d.ts +32 -0
  6. package/lib/bench.js +111 -0
  7. package/lib/cardsArmError.d.ts +61 -0
  8. package/lib/cardsArmError.js +57 -0
  9. package/lib/cardsCompose.d.ts +53 -0
  10. package/lib/cardsCompose.js +295 -0
  11. package/lib/cardsDangling.d.ts +16 -0
  12. package/lib/cardsDangling.js +213 -0
  13. package/lib/cardsFacts.d.ts +87 -0
  14. package/lib/cardsFacts.js +78 -0
  15. package/lib/cardsLanes.d.ts +43 -0
  16. package/lib/cardsLanes.js +178 -0
  17. package/lib/cardsRegistry.d.ts +404 -0
  18. package/lib/cardsRegistry.js +1543 -0
  19. package/lib/cardsVariant.d.ts +37 -0
  20. package/lib/cardsVariant.js +243 -0
  21. package/lib/discloseRegistry.d.ts +95 -0
  22. package/lib/discloseRegistry.js +156 -0
  23. package/lib/filmLead.d.ts +4 -0
  24. package/lib/filmLead.js +17 -0
  25. package/lib/filmMemoryWarn.d.ts +27 -0
  26. package/lib/filmMemoryWarn.js +99 -0
  27. package/lib/flowsData.d.ts +234 -0
  28. package/lib/flowsData.js +673 -0
  29. package/lib/flowsFamilyCompose.d.ts +45 -0
  30. package/lib/flowsFamilyCompose.js +191 -0
  31. package/lib/flowsParamsOverlay.d.ts +55 -0
  32. package/lib/flowsParamsOverlay.js +197 -0
  33. package/lib/flowsRegistryRows.d.ts +12 -0
  34. package/lib/flowsRegistryRows.js +520 -0
  35. package/lib/index.d.ts +47 -0
  36. package/lib/index.js +75 -0
  37. package/lib/ledgerTail.d.ts +20 -0
  38. package/lib/ledgerTail.js +123 -0
  39. package/lib/lifecycleLatch.d.ts +16 -0
  40. package/lib/lifecycleLatch.js +42 -0
  41. package/lib/loadPlane.d.ts +94 -0
  42. package/lib/loadPlane.js +570 -0
  43. package/lib/loadRegistry.d.ts +22 -0
  44. package/lib/loadRegistry.js +55 -0
  45. package/lib/manageOps.d.ts +27 -0
  46. package/lib/manageOps.js +162 -0
  47. package/lib/managePlane.d.ts +151 -0
  48. package/lib/managePlane.js +1790 -0
  49. package/lib/manageProbe.d.ts +48 -0
  50. package/lib/manageProbe.js +165 -0
  51. package/lib/manageRegistry.d.ts +66 -0
  52. package/lib/manageRegistry.js +113 -0
  53. package/lib/managerRail.d.ts +33 -0
  54. package/lib/managerRail.js +91 -0
  55. package/lib/mediaKinds.d.ts +3 -0
  56. package/lib/mediaKinds.js +2 -0
  57. package/lib/queue.d.ts +9 -0
  58. package/lib/queue.js +80 -0
  59. package/lib/queueCore.d.ts +72 -0
  60. package/lib/queueCore.js +128 -0
  61. package/lib/queueLifecycle.d.ts +2 -0
  62. package/lib/queueLifecycle.js +11 -0
  63. package/lib/queueLock.d.ts +60 -0
  64. package/lib/queueLock.js +198 -0
  65. package/lib/queueResurrect.d.ts +59 -0
  66. package/lib/queueResurrect.js +249 -0
  67. package/lib/queueRetry.d.ts +36 -0
  68. package/lib/queueRetry.js +24 -0
  69. package/lib/queueSidecar.d.ts +149 -0
  70. package/lib/queueSidecar.js +183 -0
  71. package/lib/queueSubmit.d.ts +82 -0
  72. package/lib/queueSubmit.js +191 -0
  73. package/lib/queueSweep.d.ts +30 -0
  74. package/lib/queueSweep.js +132 -0
  75. package/lib/resurrect.d.ts +6 -0
  76. package/lib/resurrect.js +18 -0
  77. package/lib/rootsManifest.d.ts +11 -0
  78. package/lib/rootsManifest.js +11 -0
  79. package/lib/runsChange.d.ts +61 -0
  80. package/lib/runsChange.js +79 -0
  81. package/lib/runsErrorCodes.d.ts +2 -0
  82. package/lib/runsErrorCodes.js +48 -0
  83. package/lib/runsExecute.d.ts +52 -0
  84. package/lib/runsExecute.js +494 -0
  85. package/lib/runsGates.d.ts +161 -0
  86. package/lib/runsGates.js +307 -0
  87. package/lib/runsList.d.ts +78 -0
  88. package/lib/runsList.js +574 -0
  89. package/lib/runsRefusalVoices.d.ts +9 -0
  90. package/lib/runsRefusalVoices.js +96 -0
  91. package/lib/runsRegistry.d.ts +351 -0
  92. package/lib/runsRegistry.js +2394 -0
  93. package/lib/runsSourceEcho.d.ts +81 -0
  94. package/lib/runsSourceEcho.js +341 -0
  95. package/lib/runsStart.d.ts +163 -0
  96. package/lib/runsStart.js +667 -0
  97. package/lib/runsTypes.d.ts +218 -0
  98. package/lib/runsTypes.js +289 -0
  99. package/lib/runsValidate.d.ts +5 -0
  100. package/lib/runsValidate.js +31 -0
  101. package/lib/runsValidateArms.d.ts +7 -0
  102. package/lib/runsValidateArms.js +339 -0
  103. package/lib/runsValidateInline.d.ts +6 -0
  104. package/lib/runsValidateInline.js +82 -0
  105. package/lib/runsValidateRefusals.d.ts +7 -0
  106. package/lib/runsValidateRefusals.js +18 -0
  107. package/lib/runsValidateServe.d.ts +15 -0
  108. package/lib/runsValidateServe.js +276 -0
  109. package/lib/runsValidateShared.d.ts +84 -0
  110. package/lib/runsValidateShared.js +88 -0
  111. package/lib/runsValidateStages.d.ts +32 -0
  112. package/lib/runsValidateStages.js +511 -0
  113. package/lib/runsValidateSweeps.d.ts +6 -0
  114. package/lib/runsValidateSweeps.js +143 -0
  115. package/lib/service.d.ts +63 -0
  116. package/lib/service.js +89 -0
  117. package/lib/skillFrontmatter.d.ts +11 -0
  118. package/lib/skillFrontmatter.js +46 -0
  119. package/lib/skillFs.d.ts +24 -0
  120. package/lib/skillFs.js +78 -0
  121. package/lib/skillPlane.d.ts +99 -0
  122. package/lib/skillPlane.js +269 -0
  123. package/lib/skillRegistry.d.ts +23 -0
  124. package/lib/skillRegistry.js +55 -0
  125. package/lib/skillRows.d.ts +127 -0
  126. package/lib/skillRows.js +468 -0
  127. package/lib/toolProjection.d.ts +30 -0
  128. package/lib/toolProjection.js +142 -0
  129. package/lib/vocab.d.ts +6 -0
  130. package/lib/vocab.js +18 -0
  131. package/package.json +48 -4
@@ -0,0 +1,48 @@
1
+ // runsErrorCodes.ts — the refusal-code -> HTTP answer-code table
2
+ // (the one mapping; an unnamed code is a LOUD bug, never generic).
3
+ //
4
+
5
+ // NEW envelope code must touch every seat below in the same change,
6
+ // or it compiles and then bites later —
7
+ // 1. a row HERE (the envelope spelling -> the runs/* wire value);
8
+ // 2. a `RemoteErrorDetailsMap` merge entry in runsRegistry.ts
9
+ // (the compiler enforces table <-> details sync at
10
+ // toRemoteError — details must satisfy the map's row);
11
+ // 3. the CLIENT's refusedCode discrimination (melite-card-view:
12
+ // cards-tab-body's heal-vs-carry split reads the wire value;
13
+ // an untabled class silently takes the default fail-carry —
14
+ // the replay-poison shape this table exists to prevent);
15
+ // 4. the validate-arm guards in runsValidateArms.ts (the two LOUD
16
+ // throw sites that refuse untabled codes at the door);
17
+ // 5. phaseRefusalCode (cardsArmError.ts) — its param is narrowed
18
+ // to this table's keys, so a new throw-site code fails
19
+ // TYPECHECK here first, never at the client.
20
+ // The two spellings are law: the ENVELOPE key (card_compose) rides
21
+ // the throw; the WIRE value (runs/card-compose) is what the client
22
+ // compares. Both live in this table's one row.
23
+ //
24
+
25
+ // wire codes never ride the envelope and are NOT tabled here, by
26
+ // design — `runs/unknown-run` and `runs/run-unknown` are thrown
27
+ // direct with the wire spelling at their own sites (status/stop
28
+ // misses; their details rows live in the RemoteErrorDetailsMap at
29
+ // runsRegistry.ts, not in this envelope table), and `bad_json` is
30
+ // the strict-wire gate's 400 payload (runsGates.ts; its door path
31
+ // has zero production consumers — its deletion call sits with the
32
+ // dead-exports census row, not here). A new code must still take
33
+ // the five seats above; the exemption is closed.
34
+ export const RUNS_ERROR_CODES = {
35
+ bad_envelope: "runs/bad-envelope",
36
+ draft_required: "runs/draft-required",
37
+ draft_malformed: "runs/draft-malformed",
38
+ draft_unknown: "runs/draft-unknown",
39
+ invalid_request: "runs/invalid-request",
40
+ preview_scope: "runs/preview-scope",
41
+ flow_compile: "runs/flow-compile",
42
+ workflow_pin: "runs/workflow-pin",
43
+ card_compose: "runs/card-compose",
44
+ card_compose_incomplete: "runs/card-compose-incomplete",
45
+ lane_input_missing: "runs/lane-input-missing",
46
+ lifecycle_inflight: "runs/lifecycle-inflight",
47
+ };
48
+ //# sourceMappingURL=runsErrorCodes.js.map
@@ -0,0 +1,52 @@
1
+ import type { Context } from "@deepseek-ai/cordis";
2
+ import { type RunRecord } from "./runsTypes.js";
3
+
4
+
5
+
6
+
7
+
8
+
9
+
10
+
11
+
12
+
13
+
14
+
15
+
16
+
17
+
18
+
19
+
20
+ export declare const LIVENESS_NOTIFY_MS = 300;
21
+ export declare const LIVENESS_WATCHDOG_MS = 5000;
22
+ export interface RunLiveness {
23
+ /** The report fold's tail: silence resets + a throttled notify. */
24
+ report(): void;
25
+ /** Clears the watchdog tick — the finally of every execute path. */
26
+ stop(): void;
27
+ }
28
+ export declare function startRunLiveness(run: RunRecord): RunLiveness;
29
+
30
+
31
+
32
+
33
+
34
+
35
+
36
+
37
+
38
+
39
+
40
+
41
+
42
+
43
+
44
+ export declare function declaredPrimaryFirst(names: string[], stem: string | undefined): string[];
45
+ export type SettleFn = (run: RunRecord) => void | Promise<void>;
46
+ /** One run through the merged path (door-verbatim: stages ->
47
+ * running + merged:true, splice rows, ONE executeFlow submit,
48
+ * per-stage harvest + result_outputs, the stop-gated terminal
49
+ * mapping, the settle persist). */
50
+ export declare function runOne(run: RunRecord, ctx: Context, settle: SettleFn): Promise<void>;
51
+ export declare function runEngine(run: RunRecord): string;
52
+ //# sourceMappingURL=runsExecute.d.ts.map
@@ -0,0 +1,494 @@
1
+ import { CARD_PLANE_ENGINE } from "@melite/contracts/benchStage";
2
+ import { loadCardDefs, needComfyUI, spliceWorkflow } from "@melite/comfyui-cordis";
3
+ import { deadline } from "@deepseek-ai/dsh-timeout";
4
+ import { errText, runRel } from "./runsTypes.js";
5
+ import { notifyRunChanged } from "./runsChange.js";
6
+ import { engineFilmName } from "./filmLead.js";
7
+
8
+
9
+
10
+
11
+
12
+
13
+
14
+
15
+
16
+
17
+
18
+ async function raceExecuteFuse(p, ceilMs, what) {
19
+ const ceil = ceilMs ?? 0; // undefined (a minimal fake seat) = disabled, like <= 0
20
+ const dl = deadline(undefined, ceil, "RUN_EXECUTE_HUNG");
21
+ try {
22
+ return await Promise.race([
23
+ p,
24
+ new Promise((_, reject) => {
25
+ dl.signal.addEventListener("abort", () => {
26
+ const shown = ceil < 60_000
27
+ ? Math.round(ceil) + "ms"
28
+ : Math.round(ceil / 60_000) + " min";
29
+ reject(new Error("runs/execute-hung: " + what + " exceeded the execute ceiling (" +
30
+ shown +
31
+ ") — a hung engine call must never strand the serial queue; raise the queue config's executeCeilMs or set it <= 0 to disable"));
32
+ }, { once: true });
33
+ }),
34
+ ]);
35
+ }
36
+ finally {
37
+ dl[Symbol.dispose]();
38
+ void p.catch(() => { }); // the losing promise's rejection is already handled
39
+ }
40
+ }
41
+
42
+
43
+
44
+
45
+
46
+
47
+
48
+
49
+
50
+
51
+
52
+
53
+
54
+
55
+
56
+
57
+
58
+ export const LIVENESS_NOTIFY_MS = 300;
59
+ export const LIVENESS_WATCHDOG_MS = 5_000;
60
+ export function startRunLiveness(run) {
61
+ let lastNotify = 0;
62
+ let lastReportAt = Date.now();
63
+ const stampWaiting = () => {
64
+ const waitedS = Math.round((Date.now() - lastReportAt) / 1000);
65
+ for (const stage of run.stages) {
66
+ if (stage["status"] === "running") {
67
+ stage["activity"] =
68
+ "waiting on engine (" + waitedS + "s — no engine events)";
69
+ }
70
+ }
71
+ };
72
+ const tick = () => {
73
+ // settled runs own no stamp (the terminal writer deleted the
74
+ // activity lines); only a still-running row may move.
75
+ if (run.status !== "running")
76
+ return;
77
+ if (Date.now() - lastReportAt < LIVENESS_WATCHDOG_MS)
78
+ return;
79
+ stampWaiting();
80
+ lastNotify = Date.now();
81
+ notifyRunChanged(run.runId);
82
+ };
83
+ const handle = setInterval(tick, LIVENESS_WATCHDOG_MS);
84
+ handle.unref?.();
85
+ return {
86
+ report() {
87
+ lastReportAt = Date.now();
88
+ const now = Date.now();
89
+ if (now - lastNotify < LIVENESS_NOTIFY_MS)
90
+ return;
91
+ lastNotify = now;
92
+ notifyRunChanged(run.runId);
93
+ },
94
+ stop() {
95
+ clearInterval(handle);
96
+ },
97
+ };
98
+ }
99
+
100
+
101
+
102
+
103
+
104
+
105
+
106
+
107
+
108
+
109
+
110
+
111
+
112
+
113
+
114
+ export function declaredPrimaryFirst(names, stem) {
115
+ if (stem === undefined || stem === "")
116
+ return names;
117
+ const token = new RegExp("(^|_)" + stem.replace(/[.*+?^${}()|[\]\\]/g, "\\$&") + "(_[0-9]|\\.|$)");
118
+ const hero = names.find((n) => {
119
+ const base = n.slice(n.lastIndexOf("/") + 1);
120
+ return token.test(base);
121
+ });
122
+ if (hero === undefined)
123
+ return names;
124
+ return [hero, ...names.filter((n) => n !== hero)];
125
+ }
126
+ /** One run through the merged path (door-verbatim: stages ->
127
+ * running + merged:true, splice rows, ONE executeFlow submit,
128
+ * per-stage harvest + result_outputs, the stop-gated terminal
129
+ * mapping, the settle persist). */
130
+ export async function runOne(run, ctx, settle) {
131
+ run.status = "running";
132
+ for (const stage of run.stages) {
133
+ stage["status"] = "running";
134
+ stage["merged"] = true;
135
+ }
136
+ const inputNames = run.inputNames ?? {};
137
+ // THE ENGINE-GENERICS DISPATCH (stroke 53): the 'engines' seat
138
+ // governs when mounted — the executor owns graph surgery
139
+ // (splice inside the adapter), the tap, and the merged submit.
140
+ // Seat-less boots (fixtures, walls) keep the pre-seam direct
141
+ // path byte-for-byte. Runs stay single-engine today: the
142
+ // single-stage gateway constraint means one run names one
143
+ // engine; mixed-engine grouping arrives with the MCP executor.
144
+ const enginesSeat = ctx.get("engines");
145
+ let seatExecutor = null;
146
+ if (enginesSeat !== undefined &&
147
+ typeof enginesSeat.resolve === "function") {
148
+ // resolve() throws LOUD on an unknown id (the contract's
149
+ // miswire voice) — INSIDE the splice-catch scope so the run
150
+ // settles failed and the pump SURVIVES: outside it, the throw
151
+ // escaped runOne with activeId still held, and every future
152
+ // tryDequeue returned null — all inference bricked until
153
+ // restart (audit R1, stroke 82).
154
+ try {
155
+
156
+ // EVERY stage row to the ONE executor resolved from the first
157
+ // stage's engine (runEngine's rule below) — a flow whose
158
+ // stages name two engines would mis-submit rows to the wrong
159
+ // engine. Refuse loud at claim, inside this same settle-failed
160
+ // scope, never mid-flight.
161
+ const seen = [];
162
+ for (const stage of run.stages) {
163
+ const e = stage["engine"];
164
+ const name = typeof e === "string" && e !== "" ? e : CARD_PLANE_ENGINE;
165
+ if (!seen.includes(name))
166
+ seen.push(name);
167
+ }
168
+ if (seen.length > 1) {
169
+ throw new Error("runs/mixed-engines: the flow's stages name " +
170
+ seen.join(" + ") +
171
+ " — the seat submits every row to one executor (the first stage's engine); a mixed-engine flow is refused, never mis-dispatched");
172
+ }
173
+ seatExecutor = enginesSeat.resolve(runEngine(run)).executor;
174
+ }
175
+ catch (exc) {
176
+ const text = errText(exc);
177
+ for (const stage of run.stages) {
178
+ // (every stage reads running — runOne stamps them before
179
+ // the engine call, so this fence never filters.)
180
+ /* v8 ignore next */
181
+ if (stage["status"] === "running") {
182
+ stage["status"] = "failed";
183
+ stage["error"] = text;
184
+ }
185
+ }
186
+ run.status = "failed";
187
+ run.error = text;
188
+ await settle(run);
189
+ return;
190
+ }
191
+ }
192
+ let rows;
193
+ try {
194
+ rows = seatExecutor !== null ? [] : run.stages.map((stage, i) => ({
195
+ stageId: stage.id,
196
+ card: typeof stage["card"] === "string" && stage["card"] !== ""
197
+ ? stage["card"]
198
+ : typeof run.cardId === "string" && run.cardId !== ""
199
+ ? run.cardId
200
+ : undefined,
201
+ workflow: spliceWorkflow(run.params[i]),
202
+ outputs: { ...stage.outputs },
203
+ outputNodes: { ...run.outputNodes[i] },
204
+ params: { ...run.params[i] },
205
+ }));
206
+ }
207
+ catch (exc) {
208
+ // splice refusal pre-submit: the run fails with the
209
+ // planner's text (the per-stage fallback loop is later
210
+ // scope).
211
+ const text = errText(exc);
212
+ for (const stage of run.stages) {
213
+ // (every stage reads running — runOne stamps them just
214
+ // above, so the fence never filters.)
215
+ /* v8 ignore next */
216
+ if (stage["status"] === "running") {
217
+ stage["status"] = "failed";
218
+ stage["error"] = text;
219
+ }
220
+ }
221
+ run.status = "failed";
222
+ run.error = text;
223
+ await settle(run);
224
+ return;
225
+ }
226
+
227
+
228
+ // call is a wall someone remembered to build, not the schema
229
+ // system). The rows are BUILT here, in the run seat, before any
230
+ // engine action — so the doc-walk judges HERE, in the same
231
+ // fence as the splice refusal above: every stage's graph names
232
+ // only class_types and inputs the engine's own /object_info
233
+ // declares, in the run's voice, before the first wire moves.
234
+ // (The merge that follows namespaces ids and resolves $spells
235
+ // into link VALUES — it adds no names, so the rows' name
236
+ // surface is the engine's.) The judge is the wiring service's
237
+ // own wall — ONE owner (wiringWall.ts), the same walk the
238
+ // card-compose seat has always had, now at the seat every path
239
+ // (start, restore, queue replay) already walks. NO SEAT-BRANCH
240
+ // GATE (the audit's finding: the first cut walked only when
241
+ // seatExecutor was null, and production ALWAYS takes the seat
242
+ // path — the wall was dead on the lane).
243
+ //
244
+ // AND THE CLAIM WAS FALSE UNTIL NOW (the coverage audit's HIGH
245
+ // finding, proven live by two independent probes: seat-mounted +
246
+ // armed doc + a graph naming an undeclared class_type → the run
247
+ // COMPLETED and the engine was submitted). `rows` is `[]` on the
248
+ // seat path, so this loop iterated ZERO times in production while
249
+ // the comment above claimed "the rows walk on BOTH paths here".
250
+ // The adapter's post-splice walk caught the poison anyway, which
251
+ // is why nobody saw it — but the run seat's own voice (naming the
252
+ // STAGE, before the engine is ever touched) never fired on the
253
+ // lane, and a composition without the adapter would submit poison
254
+ // with the suite green.
255
+ //
256
+ // The fence therefore judges ONE GRAPH per stage on BOTH paths:
257
+ // the spliced rows where the seat path already built them, and
258
+ // the SEAT path's own splice of the stage params HERE — because
259
+ // the compiled params are the ENVELOPE {workflow, output_nodes},
260
+ // not the graph. The first cut walked the envelope raw and every
261
+ // object-valued param became a PHANTOM NODE: an armed doc
262
+ // refused every seat-path run as "card 'flow' built node
263
+ // 'workflow' with no class_type — the graph is not addressable"
264
+
265
+ // refused by a wall judging its own envelope). The same cut
266
+ // named the card from a stage row that carries none, falling
267
+ // back to the invented 'flow'. The walk now names the REAL
268
+ // card: the stage's own card when stamped, the record's cardId
269
+ // (registration's own law: stamped for card runs, absent for
270
+ // inline — never a guess), the stage id last.
271
+ // Unarmed (no wiring service in the composition): the wall
272
+ // stands down — the standing law.
273
+ const wiring = ctx.get("comfyuiWiring");
274
+ // UNARMED, THE WHOLE FENCE STANDS DOWN — splice included (the
275
+
276
+ // wall's own stand-down, so a lane whose /object_info fetch
277
+ // failed — wall disarmed, judgment forbidden — still refused
278
+ // runs with the SPLICE's compose voice. A/B: an unarmed
279
+ // mcp:blender run completed before the cut and failed after,
280
+ // the executor never called. armed() mirrors the wall's own
281
+ // doc-null stand-down; assert() re-checks it inside.)
282
+ if (wiring !== undefined && wiring.armed()) {
283
+ for (let i = 0; i < run.stages.length; i++) {
284
+ const stage = run.stages[i];
285
+ // THE WALK IS A COMFY-GRAPH LAW: the stage's OWN engine token
286
+ // is the discriminator (runEngine's rule, per stage). Absent
287
+ // or card-plane → the compiled params are the comfy envelope;
288
+ // anything else is a foreign lane (mcp/craft/agent) whose tool
289
+ // params are NOT a graph — its seats own its voices, and this
290
+ // wall never judges it, armed or not.
291
+ const eng = stage["engine"];
292
+ if (rows.length === 0 &&
293
+ typeof eng === "string" &&
294
+ eng !== "" &&
295
+ eng !== CARD_PLANE_ENGINE) {
296
+ continue;
297
+ }
298
+ try {
299
+ const graph = rows.length > 0
300
+ ? rows[i].workflow
301
+ : spliceWorkflow((run.params[i] ?? {}));
302
+ wiring.assert(String(stage["card"] ?? run.cardId ?? stage.id), graph);
303
+ }
304
+ catch (exc) {
305
+ const text = errText(exc);
306
+ for (const st of run.stages) {
307
+ // (same fence as the splice-catch above — every stage is
308
+ // still running when this splice reports.)
309
+ /* v8 ignore next */
310
+ if (st["status"] === "running") {
311
+ st["status"] = "failed";
312
+ st["error"] = text;
313
+ }
314
+ }
315
+ run.status = "failed";
316
+ run.error = text;
317
+ await settle(run);
318
+ return;
319
+ }
320
+ }
321
+ }
322
+ // THE LIVE ROW's owner: created before the submit path, stopped
323
+ // in the finally — every execute path (success, throw, fuse)
324
+ // retires the watchdog exactly once.
325
+ const live = startRunLiveness(run);
326
+ try {
327
+
328
+ // the comfyui progress webhooks like before"): the engine
329
+ // drains its tap into this callback; the merged submit mints
330
+ // ONE prompt, so every stage row shares the same live fold
331
+ // (status serves stages VERBATIM — the poll rides the
332
+ // existing door, no new wire verb). Hoisted for both paths.
333
+ const report = (updates) => {
334
+ const act = updates["activity"];
335
+ const prog = updates["progress"];
336
+ const pRec = typeof prog === "object" && prog !== null && !Array.isArray(prog)
337
+ ? prog
338
+ : null;
339
+ for (const stage of run.stages) {
340
+ if (typeof act === "string" && act !== "")
341
+ stage["activity"] = act;
342
+ if (pRec !== null &&
343
+ typeof pRec["value"] === "number" &&
344
+ typeof pRec["max"] === "number") {
345
+ stage["progress"] = { value: pRec["value"], max: pRec["max"] };
346
+ }
347
+ }
348
+ // THE LIVE ROW (the module law above): the stamps are memory
349
+ // until this notify — the push-only tail never re-reads.
350
+ live.report();
351
+ };
352
+ const shouldStop = () => run.stopFlag;
353
+ let result;
354
+ if (seatExecutor !== null) {
355
+ // The seat path: engine-agnostic rows — the adapter splices
356
+ // (its splice refusal lands in this same catch: the run
357
+ // fails with the planner's text, stages failed, settled).
358
+ const genericRows = run.stages.map((stage, i) => ({
359
+ stageId: stage.id,
360
+ // the card label for the adapter's walk voice — the
361
+ // SAME preference chain the estate fence above uses
362
+ // (stage's own card, then the run's, then the stage id
363
+ // for flow stages that never had one)
364
+ card: typeof stage["card"] === "string" && stage["card"] !== ""
365
+ ? stage["card"]
366
+ : typeof run.cardId === "string" && run.cardId !== ""
367
+ ? run.cardId
368
+ : undefined,
369
+ outputs: { ...stage.outputs },
370
+ params: { ...run.params[i] },
371
+ }));
372
+ const outcome = await raceExecuteFuse(seatExecutor.executeStages(genericRows, run.dir, inputNames, { shouldStop, report, stateRoots: ctx.queue.stateRoots },
373
+ // The run's request initials ride every engine submit: the
374
+ // gate-blessed values the start door extracted for this
375
+ // flow's declared initials, so `$spell` params resolve at
376
+ // the engine's merge. Engines whose param dialect has no
377
+ // `$spells` ignore the record.
378
+ run.initials), ctx.queue.executeCeilMs, "the seat executor");
379
+ result = {
380
+ stages: Object.fromEntries(outcome.stages.map((s) => [
381
+ s.stageId,
382
+ { outputs: s.outputs, artifacts: [...s.artifacts] },
383
+ ])),
384
+ // THE REPLAY VERDICT (D11): forwarded, never re-derived —
385
+ // the executor's seated tap is the only witness.
386
+ replaySuspect: outcome.replaySuspect,
387
+ };
388
+ }
389
+ else {
390
+ const engine = needComfyUI(ctx, "runsRemote worker");
391
+ const nodeCount = rows.reduce((n, r) => n + Object.keys(r.workflow).length, 0);
392
+ for (const stage of run.stages) {
393
+ stage["activity"] =
394
+ "merged submit (" + rows.length + " stages, " + nodeCount + " nodes)";
395
+ }
396
+ // Same law as the seat path above: the run's request initials
397
+ // resolve the `$spells` at this merge. The hung-run fuse wraps
398
+ // BOTH executors (one law, no escape hatch).
399
+ result = await raceExecuteFuse(engine.executeFlow(rows, run.dir, inputNames, run.initials, {
400
+ shouldStop,
401
+ report,
402
+ stateRoots: ctx.queue.stateRoots,
403
+ }), ctx.queue.executeCeilMs, "the engine submit");
404
+ }
405
+ for (const stage of run.stages) {
406
+ const row = result.stages[stage.id] ?? { outputs: {}, artifacts: [] };
407
+ const arts = row.artifacts.filter((a) => a !== "");
408
+ run.artifacts.push(...arts);
409
+ notifyRunChanged(run.runId);
410
+ if (arts.length > 0) {
411
+ // DIVERGENCE-BY-ORDER: run-relative names, no /v1 prefix
412
+ // (the asset HTTP face died with the app).
413
+ let names = arts.map((a) => runRel(run, a));
414
+
415
+ // when the disk-stitch valve died): when the engine
416
+ // composed the film (h3_t4_film), presentation order is the
417
+ // harness's only job — film first, windows after. No mux,
418
+ // no mix, never a shell ffmpeg: composition belongs to the
419
+ // engine (the film-assemble stage's model-free workflow).
420
+ const semanticNames = new Set(Object.values(row.outputs)
421
+ .filter((value) => typeof value === 'string' && value !== '')
422
+ .map((value) => runRel(run, value)));
423
+ const semantic = names.find((name) => semanticNames.has(name));
424
+ if (semantic !== undefined) {
425
+ names = [semantic, ...names.filter((name) => name !== semantic)];
426
+ }
427
+ const engineFilm = engineFilmName(names);
428
+ if (engineFilm !== null && names[0] !== engineFilm) {
429
+ names = [engineFilm, ...names.filter((name) => name !== engineFilm)];
430
+ }
431
+ const stem = run.cardId !== undefined
432
+ ? (await loadCardDefs()).get(run.cardId)?.primaryFile
433
+ : undefined;
434
+ names = declaredPrimaryFirst(names, stem);
435
+
436
+ // provenance law: every artifact traces to a composition
437
+ // of cards — no harness ffmpeg ever owned the film. The
438
+ // film is assembled IN-GRAPH (the film-assemble stage's
439
+ // model-free workflow: MeliteLoadVideo + the Melite audio
440
+ // chain + CreateVideo/SaveVideo h3_t4_film); the harness's
441
+ // only job here is presentation order.)
442
+ stage["url"] = names[0];
443
+ stage["gallery"] = names.map((n) => ({ name: n }));
444
+ }
445
+ stage["result_outputs"] = { ...row.outputs };
446
+ stage["status"] = "completed";
447
+ delete stage["progress"];
448
+ delete stage["activity"];
449
+ }
450
+ run.status = run.stopFlag ? "stopped" : "completed";
451
+
452
+ // folded zero engine events before settlement — the engine
453
+ // served memo'd outputs without executing (byte-identical
454
+ // graphs replay the previous film in ~0.01s, no ws events, the
455
+ // tile frozen at "merged submit"). The run still completes —
456
+ // the harvest is what the engine said — but the row tells the
457
+ // truth: this film may predate the request. A dead tap
458
+ // withholds the verdict (its own warn, never a replay claim).
459
+ if (result.replaySuspect === true) {
460
+ run.replaySuspect = true;
461
+ console.warn(`[runs] ${run.runId} completed with no engine progress events — the film may be a replay of an earlier identical submit (the request's inputs never executed)`);
462
+ }
463
+ await settle(run);
464
+ }
465
+ catch (exc) {
466
+ const text = errText(exc);
467
+ const stopped = run.stopFlag && text.toLowerCase().includes("stop");
468
+ for (const stage of run.stages) {
469
+ // (same fence as the splice-catch above — every stage is
470
+ // still running here.)
471
+ /* v8 ignore next */
472
+ if (stage["status"] === "running") {
473
+ stage["status"] = stopped ? "stopped" : "failed";
474
+ stage["error"] = text;
475
+ }
476
+ delete stage["progress"];
477
+ delete stage["activity"];
478
+ }
479
+ run.status = stopped ? "stopped" : "failed";
480
+ if (!stopped)
481
+ run.error = text;
482
+ await settle(run);
483
+ }
484
+ finally {
485
+ live.stop();
486
+ }
487
+ }
488
+ export function runEngine(run) {
489
+ const first = run.stages[0];
490
+ const engine = first?.["engine"];
491
+ // the card plane engine is the contract value (one owner per token)
492
+ return typeof engine === "string" && engine !== "" ? engine : CARD_PLANE_ENGINE;
493
+ }
494
+ //# sourceMappingURL=runsExecute.js.map