@melite/estate-queue 0.3.0-rc.1 → 0.3.0-rc.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -12,11 +12,22 @@ runs-registry row mounts after queue, drafts, and card registry.
12
12
 
13
13
  - Seats mounted: `ctx.queue` (QueueService — lock, ledger, sidecars,
14
14
  bootSweep), `ctx.runs` (RunsRuntimeService — start/status/stop/list/
15
- validate, onRunChange), `ctx.manage` (ManageGatewayService), and
16
- `ctx.meliteFlows` (the flows seat, mounted first in the row).
17
- - Config: `{ repoRoot? }` for the default `data/runs` state root;
18
- `MELITE_STATE_ROOT` overrides it, and `MELITE_STATE_ROOTS`
19
- (colon-separated) declares the cross-roots manifest, own root first.
15
+ validate/renameOutput, onRunChange), `ctx.manage`
16
+ (ManageGatewayService), `ctx.meliteFlows` (the flows seat, mounted
17
+ first in the row), `ctx.cardRegistry` (cards/lanes), `ctx.disclose`
18
+ (disclosure), `ctx.load` (bundle serving), and `ctx.meliteSkills`
19
+ (the skill plane).
20
+ - Config (declared schema, validated before apply — the 2026-11-20
21
+ config-law cure): `{ repoRoot? }` for the default `data/runs`
22
+ state root; `stateRoot?` (absolute) overrides it and wins over
23
+ repoRoot; `stateRoots?` declares the cross-roots manifest extras,
24
+ own root first (the retired `MELITE_STATE_ROOT`/`MELITE_STATE_ROOTS`
25
+ env seams' config twins); `executeCeilMs?` is the one-run engine
26
+ execution ceiling (`<= 0` disables — the hung-run fuse).
27
+ - The lifecycle latch (MP-R1) is instance state on the queue seat:
28
+ the manage doors hold `ctx.queue.lifecycleLatch` across destructive
29
+ vendor calls; the run press reads it and refuses with
30
+ `runs/lifecycle-inflight` while a teardown is in flight.
20
31
  - The submit vocabulary lives here: draft-id law (re-exported from
21
32
  estate-drafts), run gates, refusals, validation, ledger tail. The skill
22
33
  plane serves skills over the same storage melite_load reads.
@@ -46,5 +57,5 @@ Independent — no conversation state.
46
57
 
47
58
  - **One serial queue per fiber** — the lock is the fiber's; two fibers mean
48
59
  two queues with no cross-fiber ordering promise.
49
- - **MELITE_STATE_ROOTS is colon-separated** — a root path containing a
50
- colon cannot be declared; relocate such a root instead.
60
+ - **Cross-roots are a config array** — `stateRoots` takes each root
61
+ verbatim, so a colon-bearing path declares fine.
@@ -36,6 +36,14 @@ export interface ComposeSeat {
36
36
  * siblings merge over it. Exported so the phase-1 admission seat
37
37
  * gates the LIFTED body, never the raw stanza shell. */
38
38
  export declare function liftStanza(params: Record<string, unknown>): Record<string, unknown>;
39
+ /** The stage-policy words for one reserved key — its own sentence when
40
+ * the table has the key, the generic sentence otherwise. Every SEAM
41
+ * key of STAGE_RESERVED_PARAMS carries its own words (the admission
42
+ * matrix judges that: a new seam key without its sentence reds
43
+ * there), so the generic sentence is reached by no key the merge
44
+ * declares; the run-policy keys (RUN_POLICY_KEYS) never reach this
45
+ * table — no door refuses them. */
46
+ export declare function stagePolicyWords(key: string): string;
39
47
  export declare function composeOnce(deps: ComposeSeat, card: string, fam: string, params: Record<string, unknown>, runId: string, phase: string): Promise<Record<string, unknown>>;
40
48
 
41
49
 
@@ -3,7 +3,7 @@
3
3
  // 2-6) and the in-process compose (steps 7-9). Explicit seat
4
4
  // deps; no Service state beyond the accessors the seat passes.
5
5
  import { ComfyUIService, resolveEngineBaseUrl, composeCards, ComposeRefusal, checkModelPresent, owningAtom } from "@melite/comfyui-cordis";
6
- import { cardAdmits, familyLanesOf } from "./cardsFacts.js";
6
+ import { cardAdmits, familyLanesOf, liftRunPolicyForCompose, runPolicyKeyLifts, stageReservedKeyLifts } from "./cardsFacts.js";
7
7
  import { ESTATE_NAMING_ROW } from "@melite/contracts/formSpec";
8
8
  export { cardAdmits };
9
9
  import { EngineContext, composeModPlane, loadFacts, theService } from "@melite/comfyui-cordis";
@@ -34,6 +34,27 @@ export function liftStanza(params) {
34
34
  }
35
35
  return params;
36
36
  }
37
+ /** THE STAGE-POLICY WORDS (B5): what each SEAM reserved key arms and
38
+ * why a lone card compose refuses it — keyed by the reserved key,
39
+ * with one sentence (`default`) for a key this table has not met.
40
+ * A RUN-POLICY key (RUN_POLICY_KEYS — the ceiling) has no row: its
41
+ * reader is the start door on every press, so no door refuses it
42
+ * (the B6 cure; the admission matrix judges the roster split). */
43
+ const STAGE_POLICY_WORDS = {
44
+ boundary_unload_models: () => "STAGE POLICY — it arms the unload boundary at the seam between two WIRED stages of a merged run, and this press composes one card alone: there is no seam to arm. State it on the downstream stage of a two-stage bench, or drop it",
45
+ vram_budget_mb: () => "STAGE POLICY — the merged run's VRAM headroom budget, read at the merge, and this press composes one card alone and never merges. State it on a bench stage, or drop it",
46
+ default: () => "STAGE POLICY (STAGE_RESERVED_PARAMS) — read by the merge plane between stages, and this press composes one card alone. State it on a bench stage, or drop it",
47
+ };
48
+ /** The stage-policy words for one reserved key — its own sentence when
49
+ * the table has the key, the generic sentence otherwise. Every SEAM
50
+ * key of STAGE_RESERVED_PARAMS carries its own words (the admission
51
+ * matrix judges that: a new seam key without its sentence reds
52
+ * there), so the generic sentence is reached by no key the merge
53
+ * declares; the run-policy keys (RUN_POLICY_KEYS) never reach this
54
+ * table — no door refuses them. */
55
+ export function stagePolicyWords(key) {
56
+ return (STAGE_POLICY_WORDS[key] ?? STAGE_POLICY_WORDS["default"])();
57
+ }
37
58
  export async function composeOnce(deps, card, fam, params, runId, phase) {
38
59
  // R3 (live): the engine's own node set arms the gate — an
39
60
  // unreachable engine refuses CLOSED, never composes blind.
@@ -75,7 +96,11 @@ export async function composeOnce(deps, card, fam, params, runId, phase) {
75
96
  ctx.comfyui.setWeightPresent((relativePath, name) => checkModelPresent(relativePath, name) !== null);
76
97
  // THE NESTED STANZA UNWRAP (cli.ts:82-91): a `params` dict key in
77
98
  // the incoming params IS the stanza; siblings merge over it.
78
- const lifted = liftStanza(params);
99
+
100
+ // the start body for the queue's own reader and never the card
101
+ // surface — the engine composes the copy without it, whatever
102
+ // door the press came through.
103
+ const lifted = liftRunPolicyForCompose(deps.cardDecls()[card], liftStanza(params));
79
104
  // THE ADMISSION CONTRACT GATE (cli.ts admission verbatim voice):
80
105
  // every param key must be a declared knob or ride the admits row.
81
106
 
@@ -209,7 +234,11 @@ export function admissionRefusal(deps, card, fam, lifted, phase, facts) {
209
234
  // refuses is the no-cheat lie; the declared row (h3's slug) already
210
235
  // admits through schemaNames — this arm serves every OTHER card.
211
236
  const admitted = (key) => key === ESTATE_NAMING_ROW.name || cardAdmits(decl, modNames, key);
212
- const unknown = Object.keys(lifted).filter((k) => !admitted(k)).sort();
237
+ // A RUN-POLICY KEY IS NOT UNKNOWN (B6): the start door reads it
238
+ // off the body for the whole run; the compose walk lifts it on
239
+ // every door (liftRunPolicyForCompose hands the engine a copy
240
+ // without it). A seam knob keeps the no-seam refusal below.
241
+ const unknown = Object.keys(lifted).filter((k) => !admitted(k) && !runPolicyKeyLifts(decl, k)).sort();
213
242
  if (unknown.length > 0) {
214
243
  const hints = unknown
215
244
  .filter((k) => packFields.has(k))
@@ -225,10 +254,21 @@ export function admissionRefusal(deps, card, fam, lifted, phase, facts) {
225
254
  o.families.map((f) => "family '" + f + "'").join(" / ") +
226
255
  " — state params.model on that family's lane to ride it";
227
256
  });
257
+
258
+ // reached THIS door composed alone — the run and bench doors
259
+ // lift STAGE_RESERVED_PARAMS out of the card walk before the
260
+ // merge reads them; here one card composes with no seam and no
261
+ // merge, so the knob has nothing to arm. The old refusal called
262
+ // it unknown — the operator's word for a missing feature — over a
263
+ // key the merge plane declares.
264
+ const policyHints = unknown
265
+ .filter((k) => stageReservedKeyLifts(decl, k))
266
+ .map((k) => " '" + k + "' is " + stagePolicyWords(k));
228
267
  throw phaseRefusal(phase, "compose-door: unknown param(s) on the " + card + " card: " + unknown.join(", ") +
229
268
  " (admission is the declared surface — knobs + contract admits; see the card's TS definition)" +
230
269
  (hints.length > 0 ? " Mod-pack keys:" + hints.join(";") : "") +
231
- (fieldHints.length > 0 ? " Mod-field families:" + fieldHints.join(";") : ""));
270
+ (fieldHints.length > 0 ? " Mod-field families:" + fieldHints.join(";") : "") +
271
+ (policyHints.length > 0 ? " Stage-policy keys:" + policyHints.join(";") : ""));
232
272
  }
233
273
  }
234
274
 
@@ -1,5 +1,5 @@
1
1
  import type { CardDefinition } from "@melite/comfyui-card-kit/card-definition";
2
- import type { LaneRelations, SamplerEnvelope } from "@melite/contracts/laneRelations";
2
+ import type { LaneRelations, LaneSizeLaw, SamplerEnvelope } from "@melite/contracts/laneRelations";
3
3
  export interface VariantCellRow {
4
4
  readonly quant: string;
5
5
  readonly route: string;
@@ -64,6 +64,11 @@ export interface ModelFactsRow {
64
64
 
65
65
 
66
66
 
67
+
68
+ readonly size?: LaneSizeLaw;
69
+
70
+
71
+
67
72
  readonly required_defaults?: readonly {
68
73
  readonly name: string;
69
74
  readonly class: "user" | "variant" | "mod";
@@ -137,4 +142,38 @@ export declare function stageReservedKeyLifts(decl: CardDeclRow | undefined, key
137
142
  * @param params the row's params bag.
138
143
  * @returns the judged copy (never the caller's record). */
139
144
  export declare function liftStageReservedForAdmission(decl: CardDeclRow | undefined, params: Record<string, unknown>): Record<string, unknown>;
145
+
146
+
147
+
148
+
149
+
150
+
151
+
152
+
153
+
154
+
155
+
156
+
157
+
158
+
159
+ export declare const RUN_POLICY_KEYS: readonly string[];
160
+ /** THE RUN-POLICY LIFT PREDICATE: a run-policy key the card's own
161
+ * DECLARATION does not admit is run policy, not a card param — the
162
+ * compose walk lifts it (stageReservedKeyLifts's declared-key
163
+ * sparing applies verbatim: a card that declares the key owns it,
164
+ * and it walks).
165
+ * @param decl the card's DECL projection (undefined lifts — no card
166
+ * admits a policy key by default).
167
+ * @param key the params key being judged.
168
+ * @returns true when the key is run policy the compose walk lifts. */
169
+ export declare function runPolicyKeyLifts(decl: CardDeclRow | undefined, key: string): boolean;
170
+ /** THE COMPOSE COPY a compose seat hands its card walk and the
171
+ * engine when the bag carries run-policy keys (runPolicyKeyLifts
172
+ * above): the run-policy set lifts OUT, everything else rides
173
+ * verbatim. The start body is NEVER this copy's business — the
174
+ * caller's body keeps the key for the start door's reader.
175
+ * @param decl the card's DECL projection.
176
+ * @param params the compose bag.
177
+ * @returns the compose copy (never the caller's record). */
178
+ export declare function liftRunPolicyForCompose(decl: CardDeclRow | undefined, params: Record<string, unknown>): Record<string, unknown>;
140
179
  //# sourceMappingURL=cardsFacts.d.ts.map
package/lib/cardsFacts.js CHANGED
@@ -145,4 +145,47 @@ export function liftStageReservedForAdmission(decl, params) {
145
145
  }
146
146
  return judged;
147
147
  }
148
+
149
+
150
+
151
+
152
+
153
+
154
+
155
+
156
+
157
+
158
+
159
+
160
+
161
+
162
+ export const RUN_POLICY_KEYS = ["execute_ceil_ms"];
163
+ /** THE RUN-POLICY LIFT PREDICATE: a run-policy key the card's own
164
+ * DECLARATION does not admit is run policy, not a card param — the
165
+ * compose walk lifts it (stageReservedKeyLifts's declared-key
166
+ * sparing applies verbatim: a card that declares the key owns it,
167
+ * and it walks).
168
+ * @param decl the card's DECL projection (undefined lifts — no card
169
+ * admits a policy key by default).
170
+ * @param key the params key being judged.
171
+ * @returns true when the key is run policy the compose walk lifts. */
172
+ export function runPolicyKeyLifts(decl, key) {
173
+ return RUN_POLICY_KEYS.includes(key) && !cardAdmits(decl, new Set(), key);
174
+ }
175
+ /** THE COMPOSE COPY a compose seat hands its card walk and the
176
+ * engine when the bag carries run-policy keys (runPolicyKeyLifts
177
+ * above): the run-policy set lifts OUT, everything else rides
178
+ * verbatim. The start body is NEVER this copy's business — the
179
+ * caller's body keeps the key for the start door's reader.
180
+ * @param decl the card's DECL projection.
181
+ * @param params the compose bag.
182
+ * @returns the compose copy (never the caller's record). */
183
+ export function liftRunPolicyForCompose(decl, params) {
184
+ const composed = { ...params };
185
+ for (const k of Object.keys(composed)) {
186
+ if (runPolicyKeyLifts(decl, k))
187
+ delete composed[k];
188
+ }
189
+ return composed;
190
+ }
148
191
  //# sourceMappingURL=cardsFacts.js.map
@@ -66,6 +66,17 @@ export declare const FAMILY_RESEAT_CARVE: readonly string[];
66
66
 
67
67
 
68
68
 
69
+ export declare const CARD_REGISTRY_PRIME_BOUND_MS = 60000;
70
+
71
+
72
+
73
+
74
+
75
+
76
+
77
+
78
+
79
+
69
80
 
70
81
 
71
82
 
@@ -85,9 +85,9 @@ import { probeMedia } from '@melite/contracts/media-probe';
85
85
  import { resolveSourceRefs } from "./runsSourceEcho.js";
86
86
  import { CardArmError, EnvelopeRefusal, phaseRefusalCode } from "./cardsArmError.js";
87
87
  export { CardArmError } from "./cardsArmError.js";
88
- import { cardAdmits, factsPath, deriveDecls, familyLanesOf, liftStageReservedForAdmission } from "./cardsFacts.js";
88
+ import { cardAdmits, factsPath, deriveDecls, familyLanesOf, liftRunPolicyForCompose, liftStageReservedForAdmission } from "./cardsFacts.js";
89
89
  import { reseatDeadKeys } from "@melite/contracts/familyLane";
90
- import { dropAuthoringIncomplete, isUnstatedRequiredVoice, judgeDeliverableSize, judgeLaneBounds, judgeLaneRelations, judgeLaneSurface, laneBoundsOf, laneStaleCarry, laneSurfaceOf, laneTogetherClosure, RELATION_WORDS } from "@melite/contracts/laneRelations";
90
+ import { dropAuthoringIncomplete, isUnstatedRequiredVoice, judgeDeliverableSize, judgeLaneBounds, judgeLaneCanvas, judgeLaneRelations, judgeLaneSurface, laneBoundsOf, laneStaleCarry, laneSurfaceOf, laneTogetherClosure, RELATION_WORDS } from "@melite/contracts/laneRelations";
91
91
  import { lanePresenceRefusal } from "./cardsLanes.js";
92
92
  import { selectCardVariant, liftCardParams } from "./cardsVariant.js";
93
93
  // the extracted planes re-export through the registry's public
@@ -614,6 +614,17 @@ export const FAMILY_RESEAT_CARVE = [];
614
614
 
615
615
 
616
616
 
617
+ export const CARD_REGISTRY_PRIME_BOUND_MS = 60_000;
618
+
619
+
620
+
621
+
622
+
623
+
624
+
625
+
626
+
627
+
617
628
  function familyLawOfCard(def) {
618
629
  for (const family of def.boarded) {
619
630
  const law = getModel(family).familyLaw;
@@ -918,7 +929,7 @@ export class CardRegistryService extends Service {
918
929
 
919
930
 
920
931
 
921
- async primeObjectInfo(boundMs = 60_000) {
932
+ async primeObjectInfo(boundMs = CARD_REGISTRY_PRIME_BOUND_MS) {
922
933
  try {
923
934
  this.oi = await liveObjectInfo(resolveEngineBaseUrl(), undefined, boundMs);
924
935
  this.armWiringFromDoc(this.oi);
@@ -1877,7 +1888,11 @@ export class CardRegistryService extends Service {
1877
1888
  ...judgeLaneSurface(surface, knobFields, prep.params),
1878
1889
  ...(servesDeliverableSwitch ? judgeDeliverableSize(prep.params) : []),
1879
1890
  ...judgeLaneRelations(relations, prep.params),
1880
- ...judgeLaneBounds(bounds, prep.params),
1891
+ // THE CANVAS PAIR LAW rides the bounds' seat (the h3-image
1892
+
1893
+ // area/aspect/step grain, one door — a per-side row that
1894
+ // already voices the crime keeps the pair silent (one row).
1895
+ ...judgeLaneCanvas(bounds, famRow.size ?? null, prep.params),
1881
1896
  ];
1882
1897
  const violations = admitIncomplete
1883
1898
  ? incompleteDraftViolations(judgedFam)
@@ -2198,7 +2213,18 @@ export class CardRegistryService extends Service {
2198
2213
  // size knobs gets no stamped keys — the stamp may not invent
2199
2214
  // params admission will refuse.
2200
2215
  stampClipGeometry(body, clipGeometryAdmits(this, mid));
2201
- const prep = prepareCardParams(this, body, mid, "1");
2216
+ const prepared = prepareCardParams(this, body, mid, "1");
2217
+ // THE RUN-POLICY LIFT AT THE RUN SEAT (benchgen's defect sheet B6,
2218
+
2219
+ // {stage} press, every row of a bench pass, every press-time
2220
+ // params override — composed the RAW body and refused the run's
2221
+ // own execute_ceil_ms as an unknown card param, in words naming
2222
+ // the bench-stage seat the refusal blocked. A run-policy key is
2223
+ // the start door's (queueSubmit reads it off the BODY, which
2224
+ // stays untouched here); the compose walk and the engine get the
2225
+ // copy without it. A card that DECLARES the key keeps it
2226
+ // (runPolicyKeyLifts's declared-key sparing).
2227
+ const prep = { ...prepared, params: liftRunPolicyForCompose(prepared.decl, prepared.params) };
2202
2228
  // THE SILENT-SOURCE REFUSAL (F26): an armed sound-carrying bag's
2203
2229
  // source must carry audio — refused here, zero GPU, with the lane
2204
2230
  // and the file named (the run door's own envelope walk, so the
@@ -0,0 +1,37 @@
1
+ import type { ManageCtx } from "./managePlane.js";
2
+ /** The poll cadence under the quiet window — short enough that a
3
+ * press landing between two readings is caught inside the window. */
4
+ export declare const QUIET_POLL_MS = 1000;
5
+ export interface QuietVerdict {
6
+ /** True only when the queue read empty and STAYED empty for the
7
+ * whole quiet window inside the budget. */
8
+ readonly quiet: boolean;
9
+ /** The last answerable reading's running rows. */
10
+ readonly running: number;
11
+ /** The last answerable reading's pending rows. */
12
+ readonly pending: number;
13
+ /** Readings that saw a busy queue (zero when the first reading
14
+ * was already empty). */
15
+ readonly busyReads: number;
16
+ }
17
+ /** The caller's abort reason — an Error rides as itself. */
18
+ export declare function abortReason(signal: AbortSignal): unknown;
19
+ /** Sleep on the seat's timer (the no-bare-setTimeout law: the
20
+ * ManageCtx.timeout seat IS the timer), racing the caller's abort.
21
+ * The abort listener is registered before the timer starts and is
22
+ * removed on either settle; the post-registration re-check closes
23
+ * the race between the aborted check and the listener landing.
24
+ * @param ctx - the manage context (timer seat + signal).
25
+ * @param ms - the delay in milliseconds.
26
+ * @returns a promise settling when the timer fires; rejects with
27
+ * the abort reason when the caller aborts first. */
28
+ export declare function seatSleep(ctx: ManageCtx, ms: number): Promise<void>;
29
+ /** Wait for a QUIET engine queue inside the caller's budget.
30
+ * @param ctx - the manage context (endpoint + timer seat + signal).
31
+ * @param budgetMs - the teardown door's rail budget in milliseconds.
32
+ * @param quiesceMs - the quiet window in milliseconds; 0 tears on
33
+ * the first empty reading.
34
+ * @returns the verdict: quiet, or the last reading that never
35
+ * went quiet inside the budget. */
36
+ export declare function awaitEngineQuiet(ctx: ManageCtx, budgetMs: number, quiesceMs: number): Promise<QuietVerdict>;
37
+ //# sourceMappingURL=engineQuiet.d.ts.map
@@ -0,0 +1,107 @@
1
+ // engineQuiet.ts — THE QUIET LAW every teardown door rides (B4,
2
+
3
+ //
4
+ // THE BURN: the lifecycle guard read ONE lane's run sidecars — its
5
+ // own state roots — and never the engine's own queue. A film
6
+ // pressing from another lane was invisible to `comfy_manage
7
+ // restart`, and the reboot landed under its live windows: the next
8
+ // press died on a connection refusal and the film with it. The
9
+ // engine's queue is the machine-wide truth (every lane's press is a
10
+ // row in it); the gap between two windows of one film is seconds.
11
+ // So the law is QUIESCENCE, never one empty reading: a teardown
12
+ // waits for a queue that is empty AND stays empty for the ctx's
13
+ // quiet window before it tears; a prompt landing inside the window
14
+ // re-arms the clock. Unlocked by design — the wait holds no latch,
15
+ // so a same-lane press during the wait lands (and is itself the busy
16
+ // signal); the caller takes the lifecycle latch only after the
17
+ // verdict, across the vendor call.
18
+ //
19
+ // AN UNANSWERABLE QUEUE IS NOT A BUSY SIGNAL: engineQueueView
20
+ // answers null for a dead engine and for a malformed body alike.
21
+ // The vendor call that follows the verdict is the truth-teller for
22
+ // a dead engine (it fails loud); a "busy" refusal against a dead
23
+ // engine would be the lying-cure class. An unquiet verdict reports
24
+ // the last answerable reading.
25
+ import { engineQueueView } from "./manageProbe.js";
26
+ /** The poll cadence under the quiet window — short enough that a
27
+ * press landing between two readings is caught inside the window. */
28
+ export const QUIET_POLL_MS = 1000;
29
+ /** The caller's abort reason — an Error rides as itself. */
30
+ export function abortReason(signal) {
31
+ return signal.reason instanceof Error ? signal.reason : new DOMException("The operation was aborted", "AbortError");
32
+ }
33
+ /** Sleep on the seat's timer (the no-bare-setTimeout law: the
34
+ * ManageCtx.timeout seat IS the timer), racing the caller's abort.
35
+ * The abort listener is registered before the timer starts and is
36
+ * removed on either settle; the post-registration re-check closes
37
+ * the race between the aborted check and the listener landing.
38
+ * @param ctx - the manage context (timer seat + signal).
39
+ * @param ms - the delay in milliseconds.
40
+ * @returns a promise settling when the timer fires; rejects with
41
+ * the abort reason when the caller aborts first. */
42
+ export function seatSleep(ctx, ms) {
43
+ const signal = ctx.signal;
44
+ if (signal?.aborted === true)
45
+ return Promise.reject(abortReason(signal));
46
+ return new Promise((resolvePromise, rejectPromise) => {
47
+ let cancel = () => { };
48
+ const onAbort = () => {
49
+ signal?.removeEventListener("abort", onAbort);
50
+ cancel();
51
+ rejectPromise(abortReason(signal));
52
+ };
53
+ signal?.addEventListener("abort", onAbort, { once: true });
54
+ cancel = ctx.timeout(() => {
55
+ signal?.removeEventListener("abort", onAbort);
56
+ resolvePromise();
57
+ }, ms);
58
+ if (signal?.aborted === true)
59
+ onAbort();
60
+ });
61
+ }
62
+ /** Wait for a QUIET engine queue inside the caller's budget.
63
+ * @param ctx - the manage context (endpoint + timer seat + signal).
64
+ * @param budgetMs - the teardown door's rail budget in milliseconds.
65
+ * @param quiesceMs - the quiet window in milliseconds; 0 tears on
66
+ * the first empty reading.
67
+ * @returns the verdict: quiet, or the last reading that never
68
+ * went quiet inside the budget. */
69
+ export async function awaitEngineQuiet(ctx, budgetMs, quiesceMs) {
70
+ // misconfiguration fails loud at the earliest resolvable point: an
71
+ // unpinned window would compare false forever and the door would
72
+ // stall the whole rail — a named refusal instead of a silent wait
73
+ if (!Number.isFinite(quiesceMs) || quiesceMs < 0) {
74
+ throw new Error("[manage] the teardown door's quiet window is unpinned on the manage context (engineQuiesceMs=" +
75
+ String(quiesceMs) + ") — the manage provider resolves it from its config; the door refuses to guess");
76
+ }
77
+ const deadline = Date.now() + Math.max(0, budgetMs);
78
+ let emptySince = null;
79
+ let last = { running: 0, pending: 0 };
80
+ let busyReads = 0;
81
+ for (;;) {
82
+ if (ctx.signal?.aborted === true)
83
+ throw abortReason(ctx.signal);
84
+ const reading = await engineQueueView(ctx);
85
+ if (reading !== null)
86
+ last = reading;
87
+ const busy = reading !== null && (reading.running > 0 || reading.pending > 0);
88
+ const now = Date.now();
89
+ if (busy) {
90
+ emptySince = null;
91
+ busyReads += 1;
92
+ }
93
+ else {
94
+ // the window starts at the FIRST empty reading and is held
95
+ // across every later one; a zero window tears on that first read
96
+ emptySince ??= now;
97
+ if (now - emptySince >= quiesceMs) {
98
+ return { quiet: true, running: last.running, pending: last.pending, busyReads };
99
+ }
100
+ }
101
+ if (now >= deadline) {
102
+ return { quiet: false, running: last.running, pending: last.pending, busyReads };
103
+ }
104
+ await seatSleep(ctx, Math.min(QUIET_POLL_MS, Math.max(1, deadline - now)));
105
+ }
106
+ }
107
+ //# sourceMappingURL=engineQuiet.js.map
package/lib/index.d.ts CHANGED
@@ -1,4 +1,5 @@
1
1
  import type { Context, Plugin } from "@deepseek-ai/cordis";
2
+ import Schema from "@deepseek-ai/schemastery";
2
3
  import type { QueueConfig } from "./service.js";
3
4
  export { QueueService } from "./service.js";
4
5
  export { RunsRuntimeService } from "./runsRegistry.js";
@@ -8,6 +9,15 @@ export * from "./vocab.js";
8
9
  export * from "./queue.js";
9
10
  export declare const name = "estate-queue";
10
11
  export declare const inject: string[];
12
+
13
+
14
+
15
+
16
+
17
+
18
+
19
+
20
+ export declare const Config: Schema<QueueConfig>;
11
21
  export declare function apply(ctx: Context, config?: QueueConfig): void;
12
22
  declare const plugin: Plugin;
13
23
  export default plugin;
package/lib/index.js CHANGED
@@ -1,3 +1,4 @@
1
+ import Schema from "@deepseek-ai/schemastery";
1
2
  import { QueueService } from "./service.js";
2
3
  import { RunsRuntimeService } from "./runsRegistry.js";
3
4
  export { QueueService } from "./service.js";
@@ -14,6 +15,20 @@ export * from "./queue.js";
14
15
  import { FlowsSeatService } from "./flowsData.js";
15
16
  export const name = "estate-queue";
16
17
  export const inject = ["timer"];
18
+
19
+
20
+
21
+
22
+
23
+
24
+
25
+
26
+ export const Config = Schema.object({
27
+ repoRoot: Schema.string(),
28
+ stateRoot: Schema.string(),
29
+ stateRoots: Schema.array(Schema.string()),
30
+ executeCeilMs: Schema.number(),
31
+ });
17
32
  export function apply(ctx, config = {}) {
18
33
 
19
34
  // registry's live table is service instance state, its seed rows
@@ -1,16 +1,22 @@
1
- /**
2
- * Hold the latch for one door; the door releases it in its own finally.
3
- * Holds nest under the same action name and across names; a release
4
- * only retires its own hold.
5
- * @param action the destructive action in flight (the door's own name)
6
- * @returns the door's release closure, idempotent for its own hold
7
- */
8
- export declare function holdLifecycle(action: string): () => void;
9
- /**
10
- * The earliest action whose teardown is in flight, or null — read by
11
- * the run press before its press reserve and record mint, and re-read
12
- * by the press after its last await (runsStart's enqueue gate).
13
- * @returns the held action name, or null when no teardown is in flight
14
- */
15
- export declare function lifecycleInFlight(): string | null;
1
+ /** The reservation half of the lifecycle guard. One instance per
2
+ * queue seat; the manage doors hold, the run press reads. */
3
+ export declare class LifecycleLatch {
4
+ #private;
5
+ /**
6
+ * Hold the latch for one door; the door releases it in its own
7
+ * finally. Holds nest under the same action name and across
8
+ * names; a release only retires its own hold.
9
+ * @param action the destructive action in flight (the door's own name)
10
+ * @returns the door's release closure, idempotent for its own hold
11
+ */
12
+ hold(action: string): () => void;
13
+ /**
14
+ * The earliest action whose teardown is in flight, or null — read
15
+ * by the run press before its press reserve and record mint, and
16
+ * re-read by the press after its last await (runsStart's enqueue
17
+ * gate).
18
+ * @returns the held action name, or null when no teardown is in flight
19
+ */
20
+ inFlight(): string | null;
21
+ }
16
22
  //# sourceMappingURL=lifecycleLatch.d.ts.map
@@ -7,36 +7,53 @@
7
7
  // while its engine reboots). The latch is the reservation half: a
8
8
  // guarded door holds it across its destructive section and the run
9
9
  // press (RunsRegistry.start) refuses while it names an action.
10
+ //
10
11
  // Doors overlap (the manage dispatch is unserialized): one slot would
11
12
  // let the first finisher's release clear the other's live hold. Each
12
13
  // holder counts under its own action name; the read names the earliest
13
14
  // holder (Map insertion order).
14
- const holders = new Map();
15
- /**
16
- * Hold the latch for one door; the door releases it in its own finally.
17
- * Holds nest under the same action name and across names; a release
18
- * only retires its own hold.
19
- * @param action the destructive action in flight (the door's own name)
20
- * @returns the door's release closure, idempotent for its own hold
21
- */
22
- export function holdLifecycle(action) {
23
- holders.set(action, (holders.get(action) ?? 0) + 1);
24
- return () => {
25
- const left = (holders.get(action) ?? 1) - 1;
26
- if (left <= 0)
27
- holders.delete(action);
28
- else
29
- holders.set(action, left);
30
- };
31
- }
32
- /**
33
- * The earliest action whose teardown is in flight, or null — read by
34
- * the run press before its press reserve and record mint, and re-read
35
- * by the press after its last await (runsStart's enqueue gate).
36
- * @returns the held action name, or null when no teardown is in flight
37
- */
38
- export function lifecycleInFlight() {
39
- const first = holders.keys().next();
40
- return first.done ? null : first.value;
15
+ //
16
+
17
+ // is INSTANCE state on the latch the queue seat owns
18
+ // (QueueService.lifecycleLatch), never a module global — the exact
19
+ // hazard melite-tools retired in its own V4 cure. Two hosts, two
20
+ // tests, two anything each get their own latch; nothing outside the
21
+ // holder Map's owner can reach it.
22
+ /** The reservation half of the lifecycle guard. One instance per
23
+ * queue seat; the manage doors hold, the run press reads. */
24
+ export class LifecycleLatch {
25
+ #holders = new Map();
26
+ /**
27
+ * Hold the latch for one door; the door releases it in its own
28
+ * finally. Holds nest under the same action name and across
29
+ * names; a release only retires its own hold.
30
+ * @param action the destructive action in flight (the door's own name)
31
+ * @returns the door's release closure, idempotent for its own hold
32
+ */
33
+ hold(action) {
34
+ this.#holders.set(action, (this.#holders.get(action) ?? 0) + 1);
35
+ let released = false;
36
+ return () => {
37
+ if (released)
38
+ return;
39
+ released = true;
40
+ const left = (this.#holders.get(action) ?? 1) - 1;
41
+ if (left <= 0)
42
+ this.#holders.delete(action);
43
+ else
44
+ this.#holders.set(action, left);
45
+ };
46
+ }
47
+ /**
48
+ * The earliest action whose teardown is in flight, or null — read
49
+ * by the run press before its press reserve and record mint, and
50
+ * re-read by the press after its last await (runsStart's enqueue
51
+ * gate).
52
+ * @returns the held action name, or null when no teardown is in flight
53
+ */
54
+ inFlight() {
55
+ const first = this.#holders.keys().next();
56
+ return first.done ? null : first.value;
57
+ }
41
58
  }
42
59
  //# sourceMappingURL=lifecycleLatch.js.map