@melite/estate-queue 0.2.0-alpha → 0.2.2-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 (61) hide show
  1. package/README.md +0 -5
  2. package/lib/cardsCompose.d.ts +31 -0
  3. package/lib/cardsCompose.js +55 -0
  4. package/lib/cardsRegistry.d.ts +5 -2
  5. package/lib/cardsRegistry.js +160 -3
  6. package/lib/discloseRegistry.d.ts +5 -0
  7. package/lib/discloseRegistry.js +3 -3
  8. package/lib/flowsData.d.ts +77 -21
  9. package/lib/flowsData.js +156 -21
  10. package/lib/flowsRegistryRows.d.ts +0 -4
  11. package/lib/flowsRegistryRows.js +137 -351
  12. package/lib/index.d.ts +0 -1
  13. package/lib/index.js +0 -4
  14. package/lib/loadPlane.d.ts +46 -4
  15. package/lib/loadPlane.js +107 -7
  16. package/lib/loadRegistry.js +9 -2
  17. package/lib/managePlane.d.ts +5 -0
  18. package/lib/managePlane.js +404 -49
  19. package/lib/managePreflight.js +38 -6
  20. package/lib/manageProbe.d.ts +35 -0
  21. package/lib/manageProbe.js +110 -0
  22. package/lib/queueLock.js +19 -10
  23. package/lib/queueResurrect.d.ts +0 -3
  24. package/lib/queueResurrect.js +0 -3
  25. package/lib/queueRetry.d.ts +12 -10
  26. package/lib/queueRetry.js +2 -4
  27. package/lib/queueSidecar.d.ts +12 -0
  28. package/lib/queueSidecar.js +15 -0
  29. package/lib/queueSubmit.d.ts +4 -1
  30. package/lib/queueSubmit.js +28 -5
  31. package/lib/runsExecute.d.ts +16 -1
  32. package/lib/runsExecute.js +63 -45
  33. package/lib/runsGates.d.ts +11 -3
  34. package/lib/runsGates.js +11 -3
  35. package/lib/runsList.d.ts +59 -3
  36. package/lib/runsList.js +217 -36
  37. package/lib/runsRegistry.d.ts +58 -3
  38. package/lib/runsRegistry.js +479 -92
  39. package/lib/runsStart.d.ts +6 -4
  40. package/lib/runsStart.js +32 -25
  41. package/lib/runsTypes.d.ts +19 -1
  42. package/lib/runsTypes.js +40 -3
  43. package/lib/runsValidate.d.ts +1 -0
  44. package/lib/runsValidate.js +5 -0
  45. package/lib/runsValidateArms.js +25 -0
  46. package/lib/runsValidateServe.js +15 -12
  47. package/lib/runsValidateShared.d.ts +8 -10
  48. package/lib/runsValidateShared.js +41 -15
  49. package/lib/runsValidateStages.d.ts +1 -1
  50. package/lib/runsValidateStages.js +90 -50
  51. package/lib/skillAuthored.d.ts +50 -0
  52. package/lib/skillAuthored.js +178 -0
  53. package/lib/skillPlane.d.ts +40 -2
  54. package/lib/skillPlane.js +63 -13
  55. package/lib/skillRegistry.d.ts +24 -1
  56. package/lib/skillRegistry.js +69 -5
  57. package/lib/skillRows.d.ts +13 -3
  58. package/lib/skillRows.js +42 -3
  59. package/package.json +24 -14
  60. package/lib/resurrect.d.ts +0 -6
  61. package/lib/resurrect.js +0 -18
@@ -13,6 +13,7 @@ import { isAbsolute, resolve } from "node:path";
13
13
  import { probeEndpoint } from "./manageProbe.js";
14
14
  import { managerGet } from "./managerRail.js";
15
15
  import { loadShippedExtensionManifest } from "@melite/comfyui-cordis/provisioning-manifest";
16
+ import { errText } from "./runsTypes.js";
16
17
  /** The wiring probe's per-folder dial (LAN engines answer in ms;
17
18
  * the bound only bites the absent — the INSPECT_DIAL precedent). */
18
19
  const FOLDER_DIAL_MS = 2_000;
@@ -23,8 +24,27 @@ const WIRING_BUDGET_MS = 10_000;
23
24
  function row(axis, state, detail, door) {
24
25
  return state === "miss" ? { axis, state, detail, door } : { axis, state, detail };
25
26
  }
26
- function errText(e) {
27
- return (e instanceof Error ? e.message : String(e)).slice(0, 200);
27
+
28
+
29
+
30
+
31
+
32
+
33
+
34
+
35
+
36
+
37
+
38
+
39
+ function censusKey(id) {
40
+ const fold = id.trim().toLowerCase();
41
+ const channel = fold.indexOf("@");
42
+ return channel === -1 ? fold : fold.slice(0, channel);
43
+ }
44
+ /** The preflight's detail budget (a whole-axis miss row stays one
45
+ * row); the message half rides the shared thrown-value fold (F38). */
46
+ function errDetail(e) {
47
+ return errText(e).slice(0, 200);
28
48
  }
29
49
  /** `GET <url>/models/<folder>` — registration-only (the preflight's
30
50
  * question is "does the engine see the wiring at all"). The deep
@@ -81,7 +101,7 @@ export async function runPreflight(mctx) {
81
101
  rows.push(row("manager", "green", "ComfyUI-Manager answered /customnode/installed (" + Object.keys(installed).length + " pack(s) listed)"));
82
102
  }
83
103
  catch (e) {
84
- rows.push(row("manager", "miss", "the manager rail refused: " + errText(e) +
104
+ rows.push(row("manager", "miss", "the manager rail refused: " + errDetail(e) +
85
105
  " — the engine is up but ComfyUI-Manager is absent or refusing (BYO engines must carry it; every pack door rides it)", "install_extension_url (after the engine carries ComfyUI-Manager — https://github.com/Comfy-Org/ComfyUI-Manager)"));
86
106
  }
87
107
  }
@@ -93,21 +113,33 @@ export async function runPreflight(mctx) {
93
113
  try {
94
114
  const declared = loadShippedExtensionManifest();
95
115
  const required = declared.filter((d) => d.required);
96
- const missing = required.filter((d) => !Object.prototype.hasOwnProperty.call(installed, d.name));
116
+ const listed = new Set(Object.keys(installed).map(censusKey));
117
+ const missing = required.filter((d) => !listed.has(censusKey(d.name)));
97
118
  const optional = declared.length - required.length;
98
119
  if (missing.length === 0) {
99
120
  rows.push(row("packs", "green", "every required declared pack landed (" + required.length + " of " + declared.length +
100
121
  " rows required" + (optional > 0 ? "; " + optional + " optional" : "") + ")"));
101
122
  }
102
123
  else {
103
- rows.push(row("packs", "miss", missing.length + " required pack(s) not landed: " + missing.map((d) => d.name).join(", "), "install_extension"));
124
+
125
+ // install_extension on the Impact ids is a DEAD door — Manager
126
+ // HTTP 400 on the git_url rail for both ids — so the cure rides
127
+ // install_extension_url with the real repos, never the id door.
128
+
129
+ // manifest's declared rows — the URL door byte-matches the pin
130
+ // and provisions with NO operator gesture; operator_confirmed
131
+ // is only for URLs the manifest does not declare. The detail
132
+ // carries each missing pack's declared repo.
133
+ rows.push(row("packs", "miss", missing.length + " required pack(s) not landed: " + missing.map((d) => d.name).join(", ") +
134
+ " — install each from its declared repo with install_extension_url (the declared URL auto-provisions — no operator_confirmed needed for a manifest pin): " +
135
+ missing.map((d) => d.name + " <" + d.url + ">").join(", "), "install_extension_url"));
104
136
  }
105
137
  }
106
138
  catch (e) {
107
139
  // The shipped manifest's own loud refusal (missing/malformed
108
140
  // data file) is a packs miss naming the regenerate door —
109
141
  // never a silent zero-row census (the 019 F1 burn's shape).
110
- rows.push(row("packs", "miss", errText(e), "regenerate: pnpm --filter @melite/comfyui-cordis run regen:extension-manifest"));
142
+ rows.push(row("packs", "miss", errDetail(e), "regenerate: pnpm --filter @melite/comfyui-cordis run regen:extension-manifest"));
111
143
  }
112
144
  }
113
145
  // ── store: the estate's weights root on disk ──────────────────
@@ -61,5 +61,40 @@ interface EndpointView {
61
61
 
62
62
 
63
63
  export declare function probeEndpoint(mctx: ManageCtx): Promise<EndpointView>;
64
+ /** @param lines - journal output lines (already split, non-empty).
65
+ * @returns how many lines carry an oom-kill marker. */
66
+ export declare function countOomLines(lines: readonly string[]): number;
67
+ /** The systemd census of the estate's engine unit (the probe seat
68
+ * beside probeEndpoint — the reachability probe knows the HTTP door,
69
+ * this knows the unit the engine dies inside). */
70
+ export interface EngineUnitCensus {
71
+
72
+
73
+
74
+ known: boolean;
75
+ unit: string;
76
+ /** systemctl show NRestarts — the restart counter the burn watched
77
+ * climb 1→3→270. */
78
+ restarts?: number;
79
+ /** systemctl show ExecMainStatus — the raw exit status (9 for the
80
+ * burn's `status=9/KILL`). */
81
+ last_exit_status?: number;
82
+ /** systemctl show ExecMainCode — "killed" | "exited" | ... verbatim. */
83
+ last_exit_code?: string;
84
+ /** systemctl show ExecMainExitTimestamp, verbatim (systemd's own
85
+ * spelling — never reformatted into a claim). */
86
+ last_exit_at?: string;
87
+ /** oom-kill lines in the recent journal tail (countOomLines). */
88
+ oom_kills?: number;
89
+ /** "degraded" (restart loop / signal death / oom evidence),
90
+ * "settled" (answered, no anomaly), "unknown" (could not answer). */
91
+ verdict: "degraded" | "settled" | "unknown";
92
+ note?: string;
93
+ }
94
+ /** @param mctx - the manage context (unit + signal).
95
+ * @returns the unit census; `known:false` + note when systemd or the
96
+ * journal cannot answer (BYO lane, bus-less box) — never invented
97
+ * zeros dressed as data. @throws the caller's own abort (N-S2). */
98
+ export declare function engineUnitCensus(mctx: ManageCtx): Promise<EngineUnitCensus>;
64
99
  export {};
65
100
  //# sourceMappingURL=manageProbe.d.ts.map
@@ -1,10 +1,13 @@
1
1
  // manageProbe.ts — the manage plane's estate probes (extracted
2
2
  // from managePlane.ts, the god-file cut): the TS-native status
3
3
  // walk, the active-runs census, and the manager security probe.
4
+ import { execFile } from "node:child_process";
5
+ import { promisify } from "node:util";
4
6
  import { readFileSync, readdirSync, statSync, writeFileSync } from "node:fs";
5
7
  import { join } from "node:path";
6
8
  import { sweepOutputRoots } from "./cardsDangling.js";
7
9
  import { deadline } from "@deepseek-ai/dsh-timeout";
10
+ const execFileAsync = promisify(execFile);
8
11
  // ── runs / security / probe (TS-native) ────────────────────────────
9
12
  const STATUS_RE = /"status"\s*:\s*"([a-z]+)"/;
10
13
 
@@ -222,4 +225,111 @@ export async function probeEndpoint(mctx) {
222
225
  dl[Symbol.dispose]();
223
226
  }
224
227
  }
228
+
229
+ // THE BURN (FRICTION_3 W-P2-3a / F3-09): the audio pack's env assert
230
+ // self-killed the engine at boot in a systemd restart loop (restart
231
+ // counter 270) while `comfy_manage status` read `state: up / endpoint:
232
+ // reachable` — reachability is the WHOLE truth the status stamp knew,
233
+ // and a monotonic self-kill loop answers it green. The census reads
234
+ // the truth the deployment already keeps: `systemctl --user show`
235
+ // (restart count, last exit code) plus the same journal the logs door
236
+ // reads (oom-kill lines). Keyless execs, the manageOps class.
237
+ /** One line of journal output counted as an oom kill. systemd's own
238
+ * result word (`oom-kill`), the cgroup event (`oom_kill`), and the
239
+ * kernel's killer line (`Out of memory:`) — the burn's evidence all
240
+ * reached the tool face through this exact read, uninterpreted. */
241
+ const OOM_LINE_RE = /oom-kill|oom_kill|Out of memory:/i;
242
+ /** @param lines - journal output lines (already split, non-empty).
243
+ * @returns how many lines carry an oom-kill marker. */
244
+ export function countOomLines(lines) {
245
+ return lines.filter((ln) => OOM_LINE_RE.test(ln)).length;
246
+ }
247
+ /** The census bound: the status face answers inside the plane's 5s
248
+ * wall (STATUS_RECONCILE_MS's own comment) — both execs ride 1.5s
249
+ * fuses so a hung bus can never eat the status answer; a census that
250
+ * cannot answer in time is an honest `unknown`, never a lie. */
251
+ const CENSUS_EXEC_MS = 1_500;
252
+ /** THE DEGRADED LAW: two unplanned restarts, a SIGKILL last exit (the
253
+ * burn's `status=9/KILL` — signal 9 never arrives from a clean
254
+ * stop), or oom evidence in the recent journal. One of these alone
255
+ * degrades; a reachable /system_stats cannot clear them. */
256
+ const DEGRADE_RESTART_FLOOR = 2;
257
+ const KILL_SIGNAL = 9;
258
+ /** @param mctx - the manage context (unit + signal).
259
+ * @returns the unit census; `known:false` + note when systemd or the
260
+ * journal cannot answer (BYO lane, bus-less box) — never invented
261
+ * zeros dressed as data. @throws the caller's own abort (N-S2). */
262
+ export async function engineUnitCensus(mctx) {
263
+ const unit = mctx.comfyUnit;
264
+ const execOpts = { timeout: CENSUS_EXEC_MS, encoding: "utf8", signal: mctx.signal };
265
+ const [propsResult, journalResult] = await Promise.allSettled([
266
+ execFileAsync("systemctl", [
267
+ "--user", "show", unit,
268
+ "--property=NRestarts",
269
+ "--property=ExecMainStatus",
270
+ "--property=ExecMainCode",
271
+ "--property=ExecMainExitTimestamp",
272
+ ], execOpts),
273
+ execFileAsync("journalctl", ["--user", "-u", unit, "-n", "200", "--no-pager", "-o", "cat"], execOpts),
274
+ ]);
275
+ rethrowIfCallerAborted(mctx.signal);
276
+ const props = {};
277
+ if (propsResult.status === "fulfilled") {
278
+ for (const line of propsResult.value.stdout.split("\n")) {
279
+ const m = /^([A-Za-z]+)=(.*)$/.exec(line);
280
+ if (m)
281
+ props[m[1]] = m[2];
282
+ }
283
+ }
284
+ if (props["NRestarts"] === undefined && props["ExecMainCode"] === undefined) {
285
+ const why = propsResult.status === "rejected"
286
+ ? String(propsResult.reason.stderr ?? propsResult.reason.message).trim().slice(0, 120)
287
+ : "systemd answered nothing parseable";
288
+ return { known: false, unit, verdict: "unknown", note: "the unit census cannot answer on this lane: " + why };
289
+ }
290
+ let oomKills;
291
+ let journalNote;
292
+ if (journalResult.status === "fulfilled") {
293
+ const lines = journalResult.value.stdout.split("\n").filter((ln) => ln !== "");
294
+ oomKills = countOomLines(lines);
295
+ }
296
+ else {
297
+ journalNote = "the journal tail could not be read for oom lines (" +
298
+ String(journalResult.reason.message).trim().slice(0, 80) + ")";
299
+ }
300
+ const restarts = Number.parseInt(props["NRestarts"] ?? "", 10);
301
+ // THE UNSET-ENUM LAW: systemd prints an unset enum as its numeric
302
+ // encoding (`ExecMainCode=0`, `ExecMainStatus=0` — the live-box
303
+ // census answered exactly that, restarts 3 + oom kills on the
304
+ // journal). A bare number is "nothing recorded", not an exit code —
305
+ // carrying `last exit 0/0` would be noise dressed as data. Only a
306
+ // word-form code (killed / exited) carries its status with it.
307
+ const codeWord = props["ExecMainCode"] ?? "";
308
+ const exitCode = /^[A-Za-z]+$/.test(codeWord) ? codeWord : undefined;
309
+ const exitStatus = exitCode === undefined ? Number.NaN : Number.parseInt(props["ExecMainStatus"] ?? "", 10);
310
+ const row = {
311
+ known: true,
312
+ unit,
313
+ verdict: "settled",
314
+ };
315
+ if (Number.isFinite(restarts))
316
+ row.restarts = restarts;
317
+ if (exitCode !== undefined)
318
+ row.last_exit_code = exitCode;
319
+ if (Number.isFinite(exitStatus))
320
+ row.last_exit_status = exitStatus;
321
+ const exitAt = props["ExecMainExitTimestamp"];
322
+ if (exitAt !== undefined && exitAt !== "" && exitAt !== "n/a")
323
+ row.last_exit_at = exitAt;
324
+ if (oomKills !== undefined)
325
+ row.oom_kills = oomKills;
326
+ const degraded = (Number.isFinite(restarts) && restarts >= DEGRADE_RESTART_FLOOR)
327
+ || (Number.isFinite(exitStatus) && exitStatus === KILL_SIGNAL)
328
+ || (oomKills !== undefined && oomKills > 0);
329
+ if (degraded)
330
+ row.verdict = "degraded";
331
+ if (journalNote !== undefined)
332
+ row.note = journalNote;
333
+ return row;
334
+ }
225
335
  //# sourceMappingURL=manageProbe.js.map
package/lib/queueLock.js CHANGED
@@ -62,36 +62,43 @@ export function isPidAlive(pid) {
62
62
  return false;
63
63
  }
64
64
  }
65
+ /** Write the holder pid O_EXCL. Returns "" on success, else the
66
+ * failing open/write errno code (EACCES: the runs root is not
67
+ * writable by this user — the 0500 class; EEXIST/EISDIR: a holder
68
+ * shape already sits at the path) so the refusal names its reason
69
+ * (the cold-boot audit F5: a reason-blind "steal failed" sent the
70
+ * operator hunting a lock that was never the problem). */
65
71
  function writePidFile(lockPath, pid) {
66
72
  let fd = -1;
67
73
  try {
68
74
  fd = openSync(lockPath, "wx", 0o644);
69
75
  }
70
- catch {
71
- return false;
76
+ catch (exc) {
77
+ return String(exc.code ?? "UNKNOWN");
72
78
  }
73
79
  try {
74
80
  writeSync(fd, String(pid));
75
81
 
76
82
 
77
83
  }
78
- catch {
84
+ catch (exc) {
85
+ const why = String(exc.code ?? "UNKNOWN");
79
86
  try {
80
87
  closeSync(fd);
81
88
  }
82
89
  catch {
83
- /* gone */
90
+ /* fd already gone — nothing left to close */
84
91
  }
85
- return false;
92
+ return why;
86
93
  /* v8 ignore stop */
87
94
  }
88
95
  try {
89
96
  closeSync(fd);
90
97
  }
91
98
  catch {
92
- /* closed */
99
+ /* already closed — the pid bytes are on disk */
93
100
  }
94
- return true;
101
+ return "";
95
102
  }
96
103
  /** R2 single-writer: O_CREAT|O_EXCL acquire; on
97
104
  * collision the holder pid decides — alive refuses loud (the
@@ -100,7 +107,8 @@ function writePidFile(lockPath, pid) {
100
107
  export function acquireLock(stateRoot, pid = process.pid, nowS = Math.floor(Date.now() / 1000)) {
101
108
  const lockPath = lockPathFor(stateRoot);
102
109
  mkdirSync(stateRoot, { recursive: true });
103
- if (writePidFile(lockPath, pid))
110
+ const first = writePidFile(lockPath, pid);
111
+ if (first === "")
104
112
  return { ok: true, note: "acquired" };
105
113
  let holder = "";
106
114
  try {
@@ -123,10 +131,11 @@ export function acquireLock(stateRoot, pid = process.pid, nowS = Math.floor(Date
123
131
  /* already gone */
124
132
  }
125
133
  appendLedger(stateRoot, "server.lock_stolen", { stale_pid: hpid }, nowS);
126
- if (writePidFile(lockPath, pid)) {
134
+ const stole = writePidFile(lockPath, pid);
135
+ if (stole === "") {
127
136
  return { ok: true, note: "stolen from dead pid " + hpid };
128
137
  }
129
- return { ok: false, note: "lock steal failed: " + lockPath };
138
+ return { ok: false, note: "lock steal failed: " + lockPath + " (open " + stole + (stole === "EACCES" ? " — the runs root is not writable by this user)" : ")") };
130
139
  }
131
140
  /** PID-CHECKED release (release_lock 4450-4468): a boot that never
132
141
  * owned the lock frees only its OWN, never the live holder's (the
@@ -58,7 +58,4 @@ export interface QueueRoots {
58
58
  readonly runsRoot: string;
59
59
  readonly ledgerPath: string;
60
60
  }
61
- /** One rebuilt queued run — RETIRED (stroke 83): the hollow
62
- * requeue road is deleted; the service's bootReconcile REPLAYS _request.json
63
- * through the start door so revived rows carry REAL params. */
64
61
  //# sourceMappingURL=queueResurrect.d.ts.map
@@ -262,7 +262,4 @@ export function planResurrect(stateRoot, readSidecar = (runId) => {
262
262
  candidates.sort((a, b) => a.created - b.created);
263
263
  return { order: candidates.map((c) => c.runId), orphans };
264
264
  }
265
- /** One rebuilt queued run — RETIRED (stroke 83): the hollow
266
- * requeue road is deleted; the service's bootReconcile REPLAYS _request.json
267
- * through the start door so revived rows carry REAL params. */
268
265
  //# sourceMappingURL=queueResurrect.js.map
@@ -9,14 +9,16 @@ export interface RetryNote {
9
9
  retries_used: number;
10
10
  retry_last_error: string;
11
11
  };
12
- /** The durable row: ledger("run.stage_retry", ...). */
13
- readonly ledgerEvent: string;
14
- readonly ledgerData: {
15
- run_id: string;
16
- stage: string;
17
- attempt: number;
18
- error: string;
19
- };
12
+
13
+
14
+
15
+
16
+
17
+
18
+
19
+
20
+
21
+
20
22
  /** The live row: publish(run_id, stage/…/retry). Key order . */
21
23
  readonly busFrame: {
22
24
  type: string;
@@ -30,7 +32,7 @@ export interface RetryNote {
30
32
  * retries (both the exception arm 1754 and the error-dict arm
31
33
  * 1775-1778 gate on the stop flag). */
32
34
  export declare function shouldRetry(ask: RetryAsk): boolean;
33
- /** One documented retry: sidecar row + events bus +
34
- * ledger — never a silent re-run. */
35
+ /** One documented retry: sidecar row + events bus — never a
36
+ * silent re-run, never a journal row (see RetryNote). */
35
37
  export declare function noteStageRetry(runId: string, stageId: string, stageIndex: number, attempt: number, why: string): RetryNote;
36
38
  //# sourceMappingURL=queueRetry.d.ts.map
package/lib/queueRetry.js CHANGED
@@ -11,13 +11,11 @@
11
11
  export function shouldRetry(ask) {
12
12
  return ask.attempt < ask.maxExtra && !ask.stopSet;
13
13
  }
14
- /** One documented retry: sidecar row + events bus +
15
- * ledger — never a silent re-run. */
14
+ /** One documented retry: sidecar row + events bus — never a
15
+ * silent re-run, never a journal row (see RetryNote). */
16
16
  export function noteStageRetry(runId, stageId, stageIndex, attempt, why) {
17
17
  return {
18
18
  stagePatch: { retries_used: attempt, retry_last_error: why },
19
- ledgerEvent: "run.stage_retry",
20
- ledgerData: { run_id: runId, stage: stageId, attempt, error: why },
21
19
  busFrame: { type: "stage", stage: stageId, index: stageIndex, retry: attempt },
22
20
  };
23
21
  }
@@ -26,6 +26,13 @@ export interface SidecarStage {
26
26
  name: string;
27
27
  }>;
28
28
  readonly result_outputs?: Record<string, unknown>;
29
+
30
+
31
+
32
+
33
+
34
+
35
+ readonly result_metadata?: Record<string, unknown>;
29
36
  readonly error?: string;
30
37
  readonly merged?: boolean;
31
38
  readonly outputs: Record<string, unknown>;
@@ -161,6 +168,11 @@ export declare function sidecarDoc(args: {
161
168
  testFlag: boolean;
162
169
  draftId: DraftId;
163
170
  pipeline: string;
171
+ /** THE BENCH INCARNATION (W-3 / F3-11): the draft doc's `epoch`
172
+ * at press — the identity-prefix `bench_epoch` key, the join
173
+ * half of the stage-id-reuse cure. Optional: pre-cure runs and
174
+ * epoch-less benches stamp nothing (never guessed). */
175
+ benchEpoch?: string;
164
176
  graph: GraphRow[];
165
177
  /** THE SNAPSHOT KEYS (strokes 45/45d, carried stroke 48): the exact
166
178
  * card + bench that ran. Absent when unstamped (inline runs)
@@ -23,6 +23,11 @@ export function sidecarStageOf(stage) {
23
23
  if (typeof stage.result_outputs === 'object' && stage.result_outputs !== null && !Array.isArray(stage.result_outputs)) {
24
24
  out.result_outputs = stage.result_outputs;
25
25
  }
26
+ if (typeof stage.metadata === 'object' && stage.metadata !== null && !Array.isArray(stage.metadata)) {
27
+ const meta = stage.metadata;
28
+ if (Object.keys(meta).length > 0)
29
+ out.result_metadata = meta;
30
+ }
26
31
  if (typeof stage.error === 'string')
27
32
  out.error = stage.error;
28
33
  if (stage.merged === true)
@@ -244,6 +249,16 @@ export function sidecarDoc(args) {
244
249
  .map((s) => (s.bench_stage_id !== undefined && s.bench_stage_id !== "" ? s.bench_stage_id : s.id))
245
250
  .filter((id) => id !== "")
246
251
  .join(","),
252
+
253
+ // doc's `epoch` at press (drafts clearBench is its only writer),
254
+ // stamped into the identity prefix so the list row carries it
255
+ // and melite-construct's withLastRun can require equality
256
+ // alongside draft_id — a post-clear read binds only post-clear
257
+ // runs. Absent on pre-cure runs (the optional-key law: never
258
+ // guessed); runsList projects it verbatim beside the digest.
259
+ ...(args.benchEpoch !== undefined && args.benchEpoch !== ""
260
+ ? { bench_epoch: args.benchEpoch }
261
+ : {}),
247
262
  ...(args.exportName !== undefined && args.exportName !== "" ? { export_name: args.exportName } : {}),
248
263
  ...(args.exportPath !== undefined && args.exportPath !== "" ? { export_path: args.exportPath } : {}),
249
264
  ...(args.variant !== undefined && args.variant !== "" ? { variant: args.variant } : {}),
@@ -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,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