@melite/estate-queue 0.2.0-alpha → 0.2.3-rc.4

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 (87) hide show
  1. package/README.md +0 -5
  2. package/lib/bench.js +30 -3
  3. package/lib/cardsCompose.d.ts +31 -0
  4. package/lib/cardsCompose.js +65 -1
  5. package/lib/cardsDangling.js +17 -7
  6. package/lib/cardsDroppable.d.ts +11 -0
  7. package/lib/cardsDroppable.js +50 -0
  8. package/lib/cardsFacts.d.ts +37 -0
  9. package/lib/cardsFacts.js +47 -1
  10. package/lib/cardsLanes.d.ts +18 -0
  11. package/lib/cardsLanes.js +2 -1
  12. package/lib/cardsRegistry.d.ts +12 -20
  13. package/lib/cardsRegistry.js +288 -96
  14. package/lib/discloseRegistry.d.ts +5 -0
  15. package/lib/discloseRegistry.js +3 -3
  16. package/lib/filmLead.js +9 -1
  17. package/lib/filmMemoryWarn.js +1 -0
  18. package/lib/flowsData.d.ts +110 -21
  19. package/lib/flowsData.js +201 -23
  20. package/lib/flowsFamilyCompose.js +1 -0
  21. package/lib/flowsParamsOverlay.d.ts +8 -1
  22. package/lib/flowsParamsOverlay.js +47 -2
  23. package/lib/flowsRegistryRows.d.ts +0 -4
  24. package/lib/flowsRegistryRows.js +177 -371
  25. package/lib/index.d.ts +0 -1
  26. package/lib/index.js +0 -4
  27. package/lib/ledgerTail.js +1 -0
  28. package/lib/loadPlane.d.ts +46 -4
  29. package/lib/loadPlane.js +109 -7
  30. package/lib/loadRegistry.js +9 -2
  31. package/lib/managePlane.d.ts +5 -0
  32. package/lib/managePlane.js +412 -51
  33. package/lib/managePreflight.js +38 -6
  34. package/lib/manageProbe.d.ts +35 -0
  35. package/lib/manageProbe.js +141 -2
  36. package/lib/manageRegistry.d.ts +10 -0
  37. package/lib/manageRegistry.js +7 -1
  38. package/lib/managerRail.js +1 -0
  39. package/lib/queueCore.js +3 -1
  40. package/lib/queueLock.js +22 -10
  41. package/lib/queueResurrect.d.ts +0 -3
  42. package/lib/queueResurrect.js +5 -3
  43. package/lib/queueRetry.d.ts +12 -10
  44. package/lib/queueRetry.js +2 -4
  45. package/lib/queueSidecar.d.ts +36 -1
  46. package/lib/queueSidecar.js +30 -2
  47. package/lib/queueSubmit.d.ts +4 -1
  48. package/lib/queueSubmit.js +28 -5
  49. package/lib/queueSweep.d.ts +38 -11
  50. package/lib/queueSweep.js +73 -16
  51. package/lib/runsChange.d.ts +5 -4
  52. package/lib/runsExecute.d.ts +16 -1
  53. package/lib/runsExecute.js +102 -50
  54. package/lib/runsGates.d.ts +11 -3
  55. package/lib/runsGates.js +12 -3
  56. package/lib/runsList.d.ts +59 -3
  57. package/lib/runsList.js +228 -36
  58. package/lib/runsRegistry.d.ts +87 -6
  59. package/lib/runsRegistry.js +664 -98
  60. package/lib/runsSourceEcho.js +9 -3
  61. package/lib/runsStart.d.ts +6 -4
  62. package/lib/runsStart.js +32 -25
  63. package/lib/runsTypes.d.ts +54 -1
  64. package/lib/runsTypes.js +82 -3
  65. package/lib/runsValidate.d.ts +1 -0
  66. package/lib/runsValidate.js +5 -0
  67. package/lib/runsValidateArms.js +48 -2
  68. package/lib/runsValidateServe.js +15 -12
  69. package/lib/runsValidateShared.d.ts +8 -10
  70. package/lib/runsValidateShared.js +41 -15
  71. package/lib/runsValidateStages.d.ts +1 -1
  72. package/lib/runsValidateStages.js +90 -50
  73. package/lib/runtimeProvision.js +10 -2
  74. package/lib/skillAuthored.d.ts +50 -0
  75. package/lib/skillAuthored.js +178 -0
  76. package/lib/skillFs.js +3 -0
  77. package/lib/skillPlane.d.ts +40 -2
  78. package/lib/skillPlane.js +63 -13
  79. package/lib/skillRegistry.d.ts +24 -1
  80. package/lib/skillRegistry.js +69 -5
  81. package/lib/skillRows.d.ts +13 -3
  82. package/lib/skillRows.js +52 -9
  83. package/lib/vocab.d.ts +29 -0
  84. package/lib/vocab.js +78 -0
  85. package/package.json +24 -14
  86. package/lib/resurrect.d.ts +0 -6
  87. package/lib/resurrect.js +0 -18
@@ -1,3 +1,4 @@
1
+ import { CARD_ENVELOPE_KEYS } from "./vocab.js";
1
2
  export function sidecarStageOf(stage) {
2
3
  const out = {
3
4
  id: stage.id,
@@ -14,6 +15,10 @@ export function sidecarStageOf(stage) {
14
15
  if (typeof stage.url === 'string')
15
16
  out.url = stage.url;
16
17
  if (Array.isArray(stage.gallery)) {
18
+ // THE LABEL CARRY (queue 12): a gallery row may carry a display
19
+ // `label` (the output_name mint at settle) beside its file `name`
20
+ // — the name is the media-route key, the label is what faces
21
+ // read. Both ride the sidecar so a restored row renders labeled.
17
22
  const gallery = stage.gallery.filter((entry) => typeof entry === 'object' && entry !== null && !Array.isArray(entry)
18
23
  && typeof entry.name === 'string'
19
24
  && entry.name !== '');
@@ -23,6 +28,11 @@ export function sidecarStageOf(stage) {
23
28
  if (typeof stage.result_outputs === 'object' && stage.result_outputs !== null && !Array.isArray(stage.result_outputs)) {
24
29
  out.result_outputs = stage.result_outputs;
25
30
  }
31
+ if (typeof stage.metadata === 'object' && stage.metadata !== null && !Array.isArray(stage.metadata)) {
32
+ const meta = stage.metadata;
33
+ if (Object.keys(meta).length > 0)
34
+ out.result_metadata = meta;
35
+ }
26
36
  if (typeof stage.error === 'string')
27
37
  out.error = stage.error;
28
38
  if (stage.merged === true)
@@ -117,6 +127,8 @@ export function graphReceiptOf(params, composed) {
117
127
  const found = [];
118
128
  const missed = [];
119
129
  for (const [key, value] of Object.entries(params)) {
130
+ if (CARD_ENVELOPE_KEYS.includes(key))
131
+ continue;
120
132
  const scalar = receiptScalarOf(value);
121
133
  if (scalar === undefined)
122
134
  continue;
@@ -131,7 +143,9 @@ export function graphReceiptOf(params, composed) {
131
143
  populated,
132
144
  carried: found,
133
145
  dropped: missed,
134
- verdict: missed.length === 0 ? "complete" : "partial",
146
+ // the verdict names its plane (D-11): not integration
147
+ // vocabulary — populated params whose literal never rode
148
+ verdict: missed.length === 0 ? "complete" : "params_unbound",
135
149
  ...(bake !== undefined ? { bake } : {}),
136
150
  };
137
151
  }
@@ -171,7 +185,7 @@ export function graphReceiptFoldOf(rows, promptId) {
171
185
  populated: union((r) => r.populated),
172
186
  carried: union((r) => r.carried),
173
187
  dropped: union((r) => r.dropped),
174
- verdict: complete ? "complete" : "partial",
188
+ verdict: complete ? "complete" : "params_unbound",
175
189
  stages: rows.map((r) => graphReceiptStageOf(r.stage, r)),
176
190
  // THE BAKE rides the fold: the first stage that carries one
177
191
  // (the card run's single stage; a multi-stage flow receipts the
@@ -244,12 +258,26 @@ export function sidecarDoc(args) {
244
258
  .map((s) => (s.bench_stage_id !== undefined && s.bench_stage_id !== "" ? s.bench_stage_id : s.id))
245
259
  .filter((id) => id !== "")
246
260
  .join(","),
261
+
262
+ // doc's `epoch` at press (drafts clearBench is its only writer),
263
+ // stamped into the identity prefix so the list row carries it
264
+ // and melite-construct's withLastRun can require equality
265
+ // alongside draft_id — a post-clear read binds only post-clear
266
+ // runs. Absent on pre-cure runs (the optional-key law: never
267
+ // guessed); runsList projects it verbatim beside the digest.
268
+ ...(args.benchEpoch !== undefined && args.benchEpoch !== ""
269
+ ? { bench_epoch: args.benchEpoch }
270
+ : {}),
247
271
  ...(args.exportName !== undefined && args.exportName !== "" ? { export_name: args.exportName } : {}),
248
272
  ...(args.exportPath !== undefined && args.exportPath !== "" ? { export_path: args.exportPath } : {}),
249
273
  ...(args.variant !== undefined && args.variant !== "" ? { variant: args.variant } : {}),
250
274
  ...(args.loudness !== undefined ? { loudness: args.loudness } : {}),
251
275
  ...(args.voiceFreshness !== undefined ? { voice_freshness: args.voiceFreshness } : {}),
252
276
  ...(args.replaySuspect === true ? { replay_suspect: true } : {}),
277
+ // THE ATTRIBUTION MARKER (D3-07): rides the identity prefix —
278
+ // the list row's 8191-byte window must reach it so a missed
279
+ // stamp is visible even when the payload before it is bulky.
280
+ ...(args.attribution !== undefined && args.attribution !== "" ? { attribution: args.attribution } : {}),
253
281
  error: args.error !== "" ? JSON.stringify(args.error).slice(0, 20000) : "",
254
282
  stages: args.stages,
255
283
  skipped_stages: [...args.skippedStages],
@@ -134,7 +134,10 @@ export declare function walkSubmitEnvelope(doc: unknown, draftExists: (draftId:
134
134
  kind: "ok";
135
135
  body: Record<string, unknown>;
136
136
  testFlag: boolean;
137
- draftId: DraftId;
137
+ /** Undefined on the FLOW-DOC EXEMPTION (a {flow}/{flow_inline}
138
+ * body with no draft_id — the flow's own doc is the birth
139
+ * doc). Every other shape carries one (the CARD BIRTH LAW). */
140
+ draftId: DraftId | undefined;
138
141
  /** The start body's own execute ceiling (absent = the queue
139
142
  * config decides; <= 0 disables the fuse). */
140
143
  ceilMs: number | undefined;
@@ -132,10 +132,28 @@ export function submitEnvelopeStructuralRefusal(doc) {
132
132
  return envelopeRefusal("bad-test", doc, { testFlag });
133
133
  }
134
134
  const draftId = body["draft_id"];
135
+ // THE FLOW-DOC EXEMPTION (flows-are-compositions slice C,
136
+
137
+ // carries its OWN doc — the registry row / the inline stages — so
138
+ // the CARD BIRTH LAW's draft_id requirement does not bind it (the
139
+ // Slice-A {flow} press minted a bench draft purely to satisfy this
140
+ // gate; the marker row died, and with it the press's only draft
141
+ // source — every run-door {flow} press refused draft_required
142
+ // while the fake-estate walls certified the call shape, the exact
143
+ // anti-ghost seam). The EXEMPTION IS REQUIREDNESS ONLY: a draft_id
144
+ // that IS present still walks the whole shape law below (empty,
145
+ // non-string, malformed all refuse) — a flow press naming a draft
146
+ // gets it probed and snapshot like any other.
147
+ const namesFlowDoc = "flow" in body || "flow_inline" in body;
135
148
  if (typeof draftId !== "string" || draftId === "") {
136
- return envelopeRefusal("missing-draft", doc);
149
+ if (draftId === undefined && namesFlowDoc) {
150
+ // absent + a flow door key: the flow's own doc is the birth doc
151
+ }
152
+ else {
153
+ return envelopeRefusal("missing-draft", doc);
154
+ }
137
155
  }
138
- if (!draftIdOk(draftId)) {
156
+ if (draftId !== undefined && typeof draftId === "string" && draftId !== "" && !draftIdOk(draftId)) {
139
157
  return envelopeRefusal("malformed-draft", doc, { draftId });
140
158
  }
141
159
  // THE PRESS KEY (audit N-E1): an OPTIONAL client-minted id naming
@@ -290,9 +308,14 @@ export async function walkSubmitEnvelope(doc, draftExists) {
290
308
  const body = doc;
291
309
  // THE PARSE EDGE: the draft_id arrived on the wire and passed the
292
310
  // structural walk above (present, non-empty, draftIdOk) — branded
293
- // here (the DraftId seating; the brand is compile-time-only).
294
- const draftId = draftIdOf(body["draft_id"]);
295
- if (!(await draftExists(draftId))) {
311
+ // here (the DraftId seating; the brand is compile-time-only). The
312
+ // FLOW-DOC EXEMPTION admits its absence: a {flow}/{flow_inline}
313
+ // body runs doc-less (the flow's own declaration is the doc —
314
+ // nothing to probe, nothing to snapshot; the run row is the
315
+ // record).
316
+ const rawDraftId = body["draft_id"];
317
+ const draftId = rawDraftId === undefined ? undefined : draftIdOf(rawDraftId);
318
+ if (draftId !== undefined && !(await draftExists(draftId))) {
296
319
  return { kind: "refusal", refusal: unknownDraftRefusal(draftId) };
297
320
  }
298
321
  // THE PER-RUN CEILING REFUSAL (the F8 burn): the shape is judged at
@@ -1,18 +1,41 @@
1
+ import type { RunId } from "./queueCore.js";
1
2
  export interface SweepResult {
2
3
  readonly touched: boolean;
3
4
  readonly wasQueued: boolean;
5
+ /** The D-8 hold: the queued face was NOT resettled — the row
6
+ * stays queued for the next boot's replay (only a caller that
7
+ * passes maxHolds > 0 can hold; the default resettles). */
8
+ readonly held: boolean;
4
9
  readonly doc: Record<string, unknown>;
5
10
  }
6
- /** Patch a stale sidecar (pure half of sweep_sidecar): every
7
- * running/queued status — top-level AND per-stage (any depth) —
8
- * becomes failed. Idempotent (an already-swept file has no active
9
- * statuses left → touched false, no write). A run still QUEUED
10
- * never executed: its sweep note + error say so (queuedWhy)
11
- * instead of implying a crash mid-run. */
12
- export declare function sweepSidecar(doc: Record<string, unknown>, why: string, queuedWhy?: string): SweepResult;
11
+
12
+
13
+
14
+
15
+
16
+
17
+
18
+
19
+
20
+
21
+
22
+
23
+
24
+
25
+
26
+ export declare function sweepSidecar(doc: Record<string, unknown>, why: string, queuedWhy?: string, maxHolds?: number): SweepResult;
13
27
  /** Boot-sweep notes (boot_sweep 2402-2409). */
14
28
  export declare const BOOT_SWEEP_WHY: string;
15
29
  export declare const BOOT_SWEEP_QUEUED_WHY: string;
30
+
31
+
32
+
33
+
34
+
35
+
36
+
37
+
38
+ export declare const BOOT_SWEEP_MAX_HOLDS: number;
16
39
  /** Read-time sweep notes + response errors (sidecar_status
17
40
  * 2428-2451): the ledger state is ALWAYS "failed" (even for a
18
41
  * queued zombie — the error TEXT carries the never-executed
@@ -23,8 +46,12 @@ export declare const READ_SWEEP_RUNNING_ERROR: string;
23
46
  /** Boot-time zombie sweep (boot_sweep 2378-2410, fs half): every
24
47
  * sidecar still claiming running/queued belongs to a DEAD process
25
48
  * — EXCEPT liveRunIds (boot_resurrect just re-queued those; their
26
- * queued sidecar is resurrected work, not a zombie). Swept BEFORE
27
- * traffic, so the ledger never shows phantom actives. Returns the
28
- * swept run ids in sorted order. */
29
- export declare function bootSweep(stateRoot: string, liveRunIds?: readonly string[], nowS?: number): Promise<string[]>;
49
+ * queued sidecar is resurrected work, not a zombie). A RUNNING
50
+ * claim retires failed; a still-QUEUED claim NEVER executed, so it
51
+ * HOLDS as queued for the next boot's replay (D-8, bounded by
52
+ * BOOT_SWEEP_MAX_HOLDS — past the bound it settles failed loud).
53
+ * Swept BEFORE traffic, so the ledger never shows phantom actives.
54
+ * Returns the RETIRED run ids in sorted order (held rows are not
55
+ * retired and never ride it). */
56
+ export declare function bootSweep(stateRoot: string, liveRunIds?: readonly RunId[], nowS?: number): Promise<string[]>;
30
57
  //# sourceMappingURL=queueSweep.d.ts.map
package/lib/queueSweep.js CHANGED
@@ -7,14 +7,36 @@
7
7
  import { readdirSync, readFileSync, rmSync } from "node:fs";
8
8
  import { join } from "node:path";
9
9
  import { appendLedger, writeJsonAtomic } from "./queueLock.js";
10
- /** Patch a stale sidecar (pure half of sweep_sidecar): every
11
- * running/queued status — top-level AND per-stage (any depth) —
12
- * becomes failed. Idempotent (an already-swept file has no active
13
- * statuses left → touched false, no write). A run still QUEUED
14
- * never executed: its sweep note + error say so (queuedWhy)
15
- * instead of implying a crash mid-run. */
16
- export function sweepSidecar(doc, why, queuedWhy = "") {
10
+
11
+
12
+
13
+
14
+
15
+
16
+
17
+
18
+
19
+
20
+
21
+
22
+
23
+
24
+
25
+ export function sweepSidecar(doc, why, queuedWhy = "", maxHolds = 0) {
17
26
  const wasQueued = doc["status"] === "queued";
27
+ if (wasQueued && maxHolds > 0) {
28
+ const held = (typeof doc["sweep_holds"] === "number" ? doc["sweep_holds"] : 0) + 1;
29
+ doc["sweep_holds"] = held;
30
+ if (held <= maxHolds) {
31
+ const note = queuedWhy !== "" ? queuedWhy : why;
32
+ doc["sweep"] =
33
+ `${note} — held as queued for the next boot's replay ` +
34
+ `(hold ${held}/${maxHolds}, defect board D-8)`;
35
+ return { touched: true, wasQueued, held: true, doc };
36
+ }
37
+ // past the bound: fall through to the terminal resettle — the
38
+ // note below names the exhausted holds (the haunt law)
39
+ }
18
40
  let touched = false;
19
41
  const patch = (o) => {
20
42
  if (Array.isArray(o)) {
@@ -42,16 +64,30 @@ export function sweepSidecar(doc, why, queuedWhy = "") {
42
64
  };
43
65
  patch(doc);
44
66
  if (!touched)
45
- return { touched: false, wasQueued, doc };
46
- const note = wasQueued && queuedWhy !== "" ? queuedWhy : why;
67
+ return { touched: false, wasQueued, held: false, doc };
68
+ const exhausted = wasQueued && maxHolds > 0;
69
+ const note = exhausted
70
+ ? `${queuedWhy !== "" ? queuedWhy : why} — held ${String(doc["sweep_holds"])} boots without a replay; settling failed (resubmit)`
71
+ : wasQueued && queuedWhy !== ""
72
+ ? queuedWhy
73
+ : why;
47
74
  doc["sweep"] = note;
48
75
  if (wasQueued && queuedWhy !== "")
49
- doc["error"] = queuedWhy;
50
- return { touched: true, wasQueued, doc };
76
+ doc["error"] = note;
77
+ return { touched: true, wasQueued, held: false, doc };
51
78
  }
52
79
  /** Boot-sweep notes (boot_sweep 2402-2409). */
53
80
  export const BOOT_SWEEP_WHY = "host restarted (boot sweep): stale active sidecar from a dead process";
54
- export const BOOT_SWEEP_QUEUED_WHY = "host restarted before the run started (never executed) — resubmit";
81
+ export const BOOT_SWEEP_QUEUED_WHY = "host restarted before the run started (never executed)";
82
+
83
+
84
+
85
+
86
+
87
+
88
+
89
+
90
+ export const BOOT_SWEEP_MAX_HOLDS = 3;
55
91
  /** Read-time sweep notes + response errors (sidecar_status
56
92
  * 2428-2451): the ledger state is ALWAYS "failed" (even for a
57
93
  * queued zombie — the error TEXT carries the never-executed
@@ -62,16 +98,24 @@ export const READ_SWEEP_RUNNING_ERROR = "zombie swept at read time";
62
98
  /** Boot-time zombie sweep (boot_sweep 2378-2410, fs half): every
63
99
  * sidecar still claiming running/queued belongs to a DEAD process
64
100
  * — EXCEPT liveRunIds (boot_resurrect just re-queued those; their
65
- * queued sidecar is resurrected work, not a zombie). Swept BEFORE
66
- * traffic, so the ledger never shows phantom actives. Returns the
67
- * swept run ids in sorted order. */
101
+ * queued sidecar is resurrected work, not a zombie). A RUNNING
102
+ * claim retires failed; a still-QUEUED claim NEVER executed, so it
103
+ * HOLDS as queued for the next boot's replay (D-8, bounded by
104
+ * BOOT_SWEEP_MAX_HOLDS — past the bound it settles failed loud).
105
+ * Swept BEFORE traffic, so the ledger never shows phantom actives.
106
+ * Returns the RETIRED run ids in sorted order (held rows are not
107
+ * retired and never ride it). */
68
108
  export async function bootSweep(stateRoot, liveRunIds = [], nowS = Math.floor(Date.now() / 1000)) {
69
109
  const swept = [];
110
+ // THE ONE UNBRAND, at the durable edge (the brand rides the bus
111
+ // and the registry rows; the sweep compares against directory
112
+ // names, which the fs hands back as bare strings).
70
113
  const live = new Set(liveRunIds);
71
114
  const outRoot = join(stateRoot, "output");
72
115
  let names;
73
116
  try {
74
117
  names = readdirSync(outRoot);
118
+ // an absent or unreadable output root holds no runs to sweep — the empty swept set is the answer
75
119
  }
76
120
  catch {
77
121
  return swept;
@@ -87,6 +131,7 @@ export async function bootSweep(stateRoot, liveRunIds = [], nowS = Math.floor(Da
87
131
  if (typeof pre !== "object" || pre === null || Array.isArray(pre)) {
88
132
  pre = {};
89
133
  }
134
+ // a pre-read that cannot read or parse the sidecar cannot prove the queued hold — the row falls to the retire path, and the authoritative read below still ledgers it
90
135
  }
91
136
  catch {
92
137
  pre = {};
@@ -120,10 +165,22 @@ export async function bootSweep(stateRoot, liveRunIds = [], nowS = Math.floor(Da
120
165
  appendLedger(stateRoot, "run.swept", { run_id: name, state: "unreadable", error: "boot sweep: _flow.json is not an object" }, nowS);
121
166
  continue;
122
167
  }
123
- const res = sweepSidecar(current, BOOT_SWEEP_WHY, wasQueued ? BOOT_SWEEP_QUEUED_WHY : "");
168
+ const res = sweepSidecar(current, BOOT_SWEEP_WHY, wasQueued ? BOOT_SWEEP_QUEUED_WHY : "", BOOT_SWEEP_MAX_HOLDS);
124
169
  if (!res.touched)
125
170
  continue;
126
171
  await writeJsonAtomic(path, res.doc);
172
+ if (res.held) {
173
+ // D-8: the press never executed — the row stays queued for the
174
+ // next boot's replay, ledgered queued_held (never failed). It
175
+ // is NOT in the swept return: the sweep retired nothing.
176
+ appendLedger(stateRoot, "run.swept", {
177
+ run_id: name,
178
+ state: "queued_held",
179
+ error: `boot sweep: held as queued for the next boot's replay ` +
180
+ `(hold ${String(res.doc["sweep_holds"])}/${BOOT_SWEEP_MAX_HOLDS}) — the press never executed`,
181
+ }, nowS);
182
+ continue;
183
+ }
127
184
  appendLedger(stateRoot, "run.swept", { run_id: name, state: wasQueued ? "queued_lost" : "failed", error: "boot sweep" }, nowS);
128
185
  swept.push(name);
129
186
  }
@@ -1,10 +1,11 @@
1
1
  import type { Context } from "@deepseek-ai/cordis";
2
- type RunChangeListener = (runId: string) => void;
2
+ import type { RunId } from "./queueCore.js";
3
+ type RunChangeListener = (runId: RunId) => void;
3
4
  /** The event seam this pure-domain spine reaches the bus through
4
5
  * (the bench seam's law, verbatim: the writers own no Context, the
5
6
  * owning service installs the pair once). */
6
7
  export interface RunsChangeSeam {
7
- emit: (runId: string) => void;
8
+ emit: (runId: RunId) => void;
8
9
  on: (fn: RunChangeListener) => () => void;
9
10
  }
10
11
  declare module "@deepseek-ai/cordis" {
@@ -16,7 +17,7 @@ declare module "@deepseek-ai/cordis" {
16
17
  * @mode emit
17
18
  * @param runId - the run whose row moved.
18
19
  */
19
- "runs.changed": (runId: string) => void;
20
+ "runs.changed": (runId: RunId) => void;
20
21
  }
21
22
  }
22
23
  /** Install the seam (the registry service does this with its
@@ -48,7 +49,7 @@ export declare function onRunChange(fn: RunChangeListener): () => void;
48
49
  * subscriber's park in a microtask, by which time the writer's
49
50
  * synchronous mutation has landed — the re-read serves the moved
50
51
  * row, never the pre-write one. */
51
- export declare function notifyRunChanged(runId: string): void;
52
+ export declare function notifyRunChanged(runId: RunId): void;
52
53
  /** Install the typed runs event seam on a Context (the registry
53
54
  * service's constructor — the bench installer's law, drafts
54
55
  * remote.ts installBenchChangeSeam): fiber-scoped through
@@ -1,5 +1,5 @@
1
1
  import type { Context } from "@deepseek-ai/cordis";
2
- import { type RunRecord } from "./runsTypes.js";
2
+ import { type RunRecord, type RunStageRow } from "./runsTypes.js";
3
3
 
4
4
 
5
5
 
@@ -43,6 +43,21 @@ export declare function startRunLiveness(run: RunRecord): RunLiveness;
43
43
 
44
44
  export declare function declaredPrimaryFirst(names: string[], stem: string | undefined): string[];
45
45
  export type SettleFn = (run: RunRecord) => void | Promise<void>;
46
+ /** THE PER-ROW TRUTH STAMP (qa8 F2/F43, the per-row status law): a
47
+ * pass-level death settles every UNANSWERED stage row by ownership —
48
+ * a stage's outcome marks only its own row. A row that already
49
+ * answered (completed/failed/stopped) stands untouched. A named
50
+ * owner — the fence refusal's own stage, the missing-harvest rows
51
+ * the verdict condemns — reads failed with the cause. Ownerless, a
52
+ * SOLE-stage run's row still reads the run's word with the cause:
53
+ * one stage and the run are the same pass, so the receipt is its
54
+ * own. Every other unanswered row reads stopped and carries NO
55
+ * error text — "failed" would claim an outcome it never produced,
56
+ * and the text would name another stage's cause. The pass-level
57
+ * word itself rides the run doc (run.status + run.error), never the
58
+ * rows. Pure over the run record; every runOne catch and the pump's
59
+ * claim refusals share it. */
60
+ export declare function stampUnansweredRows(run: RunRecord, text: string, stopped: boolean, owners?: ReadonlySet<RunStageRow>): void;
46
61
  /** One run through the merged path (door-verbatim: stages ->
47
62
  * running + merged:true, splice rows, ONE executeFlow submit,
48
63
  * per-stage harvest + result_outputs, the stop-gated terminal
@@ -1,5 +1,5 @@
1
1
  import { CARD_PLANE_ENGINE } from "@melite/contracts/benchStage";
2
- import { loadCardDefs, needComfyUI, spliceWorkflow } from "@melite/comfyui-cordis";
2
+ import { loadCardDefs, needComfyUI, spliceWorkflow, warnWiringAbsent } from "@melite/comfyui-cordis";
3
3
  import { deadline } from "@deepseek-ai/dsh-timeout";
4
4
  import { errText, runRel } from "./runsTypes.js";
5
5
  import { notifyRunChanged } from "./runsChange.js";
@@ -27,7 +27,11 @@ async function raceExecuteFuse(p, ceilMs, what) {
27
27
  dl.signal.addEventListener("abort", () => {
28
28
  const shown = ceil < 60_000
29
29
  ? Math.round(ceil) + "ms"
30
- : Math.round(ceil / 60_000) + " min";
30
+ : /* v8 ignore next -- the min face needs a ceiling ≥ 60 s AND a
31
+ * call that outlives it: an honest arm is a minute-long
32
+ * timed test, a flake factory by construction. The ms face
33
+ * (every real ceiling) is the walled spelling. */
34
+ Math.round(ceil / 60_000) + " min";
31
35
  reject(new Error("runs/execute-hung: " + what + " exceeded the execute ceiling (" +
32
36
  shown +
33
37
  ") — a hung engine call must never strand the serial queue; raise the queue config's executeCeilMs, set it <= 0 to disable, or state the run's own execute_ceil_ms"));
@@ -73,7 +77,13 @@ export function startRunLiveness(run) {
73
77
  };
74
78
  const tick = () => {
75
79
  // settled runs own no stamp (the terminal writer deleted the
76
- // activity lines); only a still-running row may move.
80
+ // activity lines); only a still-running row may move. The two
81
+ // guard tails below are timer-edge classes: a tick landing after
82
+ // settle (clearInterval racing the interval's in-flight fire) and
83
+ // a stamp fired inside the watchdog window — both benign by
84
+ // design, honest arms would be wall-clock flakes.
85
+ /* v8 ignore next 2 -- timer-edge tails: the guard exists for the
86
+ * clear-race, not a state any arm can hold. */
77
87
  if (run.status !== "running")
78
88
  return;
79
89
  if (Date.now() - lastReportAt < LIVENESS_WATCHDOG_MS)
@@ -125,6 +135,35 @@ export function declaredPrimaryFirst(names, stem) {
125
135
  return names;
126
136
  return [hero, ...names.filter((n) => n !== hero)];
127
137
  }
138
+ /** THE PER-ROW TRUTH STAMP (qa8 F2/F43, the per-row status law): a
139
+ * pass-level death settles every UNANSWERED stage row by ownership —
140
+ * a stage's outcome marks only its own row. A row that already
141
+ * answered (completed/failed/stopped) stands untouched. A named
142
+ * owner — the fence refusal's own stage, the missing-harvest rows
143
+ * the verdict condemns — reads failed with the cause. Ownerless, a
144
+ * SOLE-stage run's row still reads the run's word with the cause:
145
+ * one stage and the run are the same pass, so the receipt is its
146
+ * own. Every other unanswered row reads stopped and carries NO
147
+ * error text — "failed" would claim an outcome it never produced,
148
+ * and the text would name another stage's cause. The pass-level
149
+ * word itself rides the run doc (run.status + run.error), never the
150
+ * rows. Pure over the run record; every runOne catch and the pump's
151
+ * claim refusals share it. */
152
+ export function stampUnansweredRows(run, text, stopped, owners) {
153
+ const sole = run.stages.length === 1 ? run.stages[0] : undefined;
154
+ for (const stage of run.stages) {
155
+ const word = stage["status"];
156
+ if (word === "completed" || word === "failed" || word === "stopped")
157
+ continue;
158
+ if (owners?.has(stage) === true || (owners === undefined && stage === sole)) {
159
+ stage["status"] = stopped ? "stopped" : "failed";
160
+ stage["error"] = text;
161
+ }
162
+ else {
163
+ stage["status"] = "stopped";
164
+ }
165
+ }
166
+ }
128
167
  /** One run through the merged path (door-verbatim: stages ->
129
168
  * running + merged:true, splice rows, ONE executeFlow submit,
130
169
  * per-stage harvest + result_outputs, the stop-gated terminal
@@ -176,15 +215,11 @@ export async function runOne(run, ctx, settle) {
176
215
  }
177
216
  catch (exc) {
178
217
  const text = errText(exc);
179
- for (const stage of run.stages) {
180
- // (every stage reads running — runOne stamps them before
181
- // the engine call, so this fence never filters.)
182
- /* v8 ignore next */
183
- if (stage["status"] === "running") {
184
- stage["status"] = "failed";
185
- stage["error"] = text;
186
- }
187
- }
218
+ // THE PER-ROW TRUTH STAMP (F2): a pass-level refusal (mixed
219
+ // engines, an unknown engine) names no single stage — the
220
+ // unanswered rows read stopped, the sole stage owns the
221
+ // cause, and the run doc carries the word.
222
+ stampUnansweredRows(run, text, false);
188
223
  run.status = "failed";
189
224
  run.error = text;
190
225
  await settle(run);
@@ -209,17 +244,11 @@ export async function runOne(run, ctx, settle) {
209
244
  catch (exc) {
210
245
  // splice refusal pre-submit: the run fails with the
211
246
  // planner's text (the per-stage fallback loop is later
212
- // scope).
247
+ // scope). THE PER-ROW TRUTH STAMP (F2): the splice cannot
248
+ // name the offending stage — the rows read stopped, the sole
249
+ // stage owns the cause, the run doc carries the word.
213
250
  const text = errText(exc);
214
- for (const stage of run.stages) {
215
- // (every stage reads running — runOne stamps them just
216
- // above, so the fence never filters.)
217
- /* v8 ignore next */
218
- if (stage["status"] === "running") {
219
- stage["status"] = "failed";
220
- stage["error"] = text;
221
- }
222
- }
251
+ stampUnansweredRows(run, text, false);
223
252
  run.status = "failed";
224
253
  run.error = text;
225
254
  await settle(run);
@@ -273,6 +302,12 @@ export async function runOne(run, ctx, settle) {
273
302
  // Unarmed (no wiring service in the composition): the wall
274
303
  // stands down — the standing law.
275
304
  const wiring = ctx.get("comfyuiWiring");
305
+ // Absent PROVIDER (never an unarmed doc): the composition
306
+ // mounted no wiring row at all — the whole fence stands down,
307
+ // LOUD once per process (warnWiringAbsent). An armed-but-empty
308
+ // doc keeps its silent stand-down (the doc-null law below).
309
+ if (wiring === undefined)
310
+ warnWiringAbsent(ctx, "run seat fence");
276
311
  // UNARMED, THE WHOLE FENCE STANDS DOWN — splice included (the
277
312
 
278
313
  // wall's own stand-down, so a lane whose /object_info fetch
@@ -305,15 +340,12 @@ export async function runOne(run, ctx, settle) {
305
340
  }
306
341
  catch (exc) {
307
342
  const text = errText(exc);
308
- for (const st of run.stages) {
309
- // (same fence as the splice-catch above — every stage is
310
- // still running when this splice reports.)
311
- /* v8 ignore next */
312
- if (st["status"] === "running") {
313
- st["status"] = "failed";
314
- st["error"] = text;
315
- }
316
- }
343
+ // THE PER-ROW TRUTH STAMP (F43): the fence's refusal is the
344
+ // offending stage's OWN verdict — the assert names its card
345
+ // and its graph — so that row alone reads failed with the
346
+ // cause; its peers never pressed and carry no borrowed
347
+ // text (the run doc carries the word for the pass).
348
+ stampUnansweredRows(run, text, false, new Set([stage]));
317
349
  run.status = "failed";
318
350
  run.error = text;
319
351
  await settle(run);
@@ -414,18 +446,21 @@ export async function runOne(run, ctx, settle) {
414
446
  stampReceiptPromptId(run, result.promptId);
415
447
  // THE MISSING-STAGE REFUSAL (P7 B1): the engine answered for a
416
448
  // submitted stage id or it did not — there is no empty success.
417
- // Judge the whole harvest BEFORE touching a stage row, so one
418
- // missing id fails every running stage instead of leaving the
419
- // answered stages completed beside it.
420
- const missingStageIds = run.stages
421
- .map((stage) => stage.id)
422
- .filter((id) => result.stages[id] === undefined);
423
- if (missingStageIds.length > 0) {
424
- throw new Error("runs/missing-stage-result: the engine result has no row for " +
425
- missingStageIds.map((id) => `stage "${id}"`).join(", ") +
426
- " — a submitted stage with no result fails, never settles completed/empty");
449
+ // The harvest is refused whole (no completed row beside an
450
+ // unanswered one), and the rows the verdict condemns stamp
451
+ // FIRST (the per-row truth stamp, F43): the missing ids are
452
+ // the refusal's own subjects — they read failed with it —
453
+ // while the rows the engine did answer settle through the
454
+ // catch below as stopped, never carrying a borrowed verdict.
455
+ const missingRows = new Set(run.stages.filter((stage) => result.stages[stage.id] === undefined));
456
+ if (missingRows.size > 0) {
457
+ const refusal = "runs/missing-stage-result: the engine result has no row for " +
458
+ [...missingRows].map((s) => `stage "${s.id}"`).join(", ") +
459
+ " — a submitted stage with no result fails, never settles completed/empty";
460
+ stampUnansweredRows(run, refusal, false, missingRows);
461
+ throw new Error(refusal);
427
462
  }
428
- for (const stage of run.stages) {
463
+ for (const [stageIdx, stage] of run.stages.entries()) {
429
464
  const row = result.stages[stage.id];
430
465
  const arts = row.artifacts.filter((a) => a !== "");
431
466
  run.artifacts.push(...arts);
@@ -463,7 +498,25 @@ export async function runOne(run, ctx, settle) {
463
498
  // chain + CreateVideo/SaveVideo h3_t4_film); the harness's
464
499
  // only job here is presentation order.)
465
500
  stage["url"] = names[0];
466
- stage["gallery"] = names.map((n) => ({ name: n }));
501
+
502
+ // "there is no place for the ai agent or the user through
503
+ // the card UI to label output names"): the stage's reserved
504
+ // `output_name` param (spelled by the agent's patch or the
505
+ // user's field — STAGE_RESERVED_PARAMS carries it onto the
506
+ // composed row) labels the gallery rows on the DISPLAY
507
+ // plane. The `name` stays the machine file key (the media
508
+ // route and every dedup law ride it); the `label` is what
509
+ // faces read. One artifact wears the stem alone; several
510
+ // wear the stem on the hero and `stem · 2…n` after (the
511
+ // hero-led gallery order above decides which is which).
512
+ const stageParams = run.params[stageIdx];
513
+ const labelStem = typeof stageParams?.["output_name"] === "string"
514
+ && stageParams["output_name"].trim() !== ""
515
+ ? stageParams["output_name"].trim()
516
+ : null;
517
+ stage["gallery"] = names.map((n, i) => (labelStem === null
518
+ ? { name: n }
519
+ : { name: n, label: i === 0 ? labelStem : `${labelStem} · ${i + 1}` }));
467
520
  }
468
521
  stage["result_outputs"] = { ...row.outputs };
469
522
  stage["status"] = "completed";
@@ -488,14 +541,13 @@ export async function runOne(run, ctx, settle) {
488
541
  catch (exc) {
489
542
  const text = errText(exc);
490
543
  const stopped = run.stopFlag && text.toLowerCase().includes("stop");
544
+ // THE PER-ROW TRUTH STAMP (F2): the merged submit's death is
545
+ // the RUN's receipt, not each row's — answered rows stand, the
546
+ // sole stage carries the cause, and every unanswered peer reads
547
+ // stopped with no borrowed text. The pass-level word rides the
548
+ // run doc below.
549
+ stampUnansweredRows(run, text, stopped);
491
550
  for (const stage of run.stages) {
492
- // (same fence as the splice-catch above — every stage is
493
- // still running here.)
494
- /* v8 ignore next */
495
- if (stage["status"] === "running") {
496
- stage["status"] = stopped ? "stopped" : "failed";
497
- stage["error"] = text;
498
- }
499
551
  delete stage["progress"];
500
552
  delete stage["activity"];
501
553
  }