@melite/estate-queue 0.1.4-alpha → 0.2.0-alpha
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +561 -457
- package/README.md +55 -0
- package/lib/bench.d.ts +19 -11
- package/lib/bench.js +47 -57
- package/lib/cardsArmError.d.ts +94 -2
- package/lib/cardsArmError.js +34 -4
- package/lib/cardsCompose.d.ts +13 -1
- package/lib/cardsCompose.js +151 -67
- package/lib/cardsDangling.d.ts +2 -2
- package/lib/cardsDangling.js +82 -37
- package/lib/cardsFacts.d.ts +32 -3
- package/lib/cardsFacts.js +39 -1
- package/lib/cardsLanes.d.ts +62 -4
- package/lib/cardsLanes.js +407 -20
- package/lib/cardsLanesCopy.d.ts +21 -0
- package/lib/cardsLanesCopy.js +22 -0
- package/lib/cardsRegistry.d.ts +195 -10
- package/lib/cardsRegistry.js +959 -67
- package/lib/cardsVariant.d.ts +22 -8
- package/lib/cardsVariant.js +243 -52
- package/lib/discloseRegistry.d.ts +42 -11
- package/lib/discloseRegistry.js +163 -23
- package/lib/filmLead.js +5 -3
- package/lib/flowsData.d.ts +68 -13
- package/lib/flowsData.js +236 -107
- package/lib/flowsFamilyCompose.d.ts +5 -8
- package/lib/flowsFamilyCompose.js +25 -14
- package/lib/flowsParamsOverlay.d.ts +55 -0
- package/lib/flowsParamsOverlay.js +197 -0
- package/lib/flowsRegistryRows.d.ts +4 -1
- package/lib/flowsRegistryRows.js +325 -25
- package/lib/index.d.ts +1 -3
- package/lib/index.js +20 -5
- package/lib/lifecycleLatch.d.ts +16 -0
- package/lib/lifecycleLatch.js +42 -0
- package/lib/loadPlane.d.ts +3 -2
- package/lib/loadPlane.js +34 -8
- package/lib/loadRegistry.js +1 -1
- package/lib/manageOps.d.ts +8 -2
- package/lib/manageOps.js +28 -7
- package/lib/managePlane.d.ts +42 -1
- package/lib/managePlane.js +911 -101
- package/lib/managePreflight.d.ts +26 -0
- package/lib/managePreflight.js +179 -0
- package/lib/manageProbe.d.ts +15 -7
- package/lib/manageProbe.js +79 -8
- package/lib/manageRegistry.d.ts +42 -4
- package/lib/manageRegistry.js +45 -7
- package/lib/mediaKinds.d.ts +1 -1
- package/lib/mediaKinds.js +1 -1
- package/lib/queue.js +14 -10
- package/lib/queueCore.d.ts +21 -5
- package/lib/queueCore.js +22 -5
- package/lib/queueLifecycle.d.ts +0 -24
- package/lib/queueLifecycle.js +9 -63
- package/lib/queueLock.d.ts +8 -2
- package/lib/queueLock.js +9 -6
- package/lib/queueResurrect.d.ts +7 -2
- package/lib/queueResurrect.js +25 -6
- package/lib/queueSidecar.d.ts +114 -1
- package/lib/queueSidecar.js +178 -7
- package/lib/queueSubmit.d.ts +124 -10
- package/lib/queueSubmit.js +251 -48
- package/lib/queueSweep.js +13 -2
- package/lib/runsChange.d.ts +8 -0
- package/lib/runsChange.js +21 -5
- package/lib/runsErrorCodes.d.ts +1 -1
- package/lib/runsErrorCodes.js +35 -0
- package/lib/runsExecute.d.ts +26 -0
- package/lib/runsExecute.js +184 -6
- package/lib/runsGates.d.ts +5 -1
- package/lib/runsGates.js +10 -5
- package/lib/runsList.d.ts +43 -3
- package/lib/runsList.js +172 -58
- package/lib/runsRefusalVoices.js +101 -0
- package/lib/runsRegistry.d.ts +188 -12
- package/lib/runsRegistry.js +1233 -179
- package/lib/runsSourceEcho.d.ts +27 -0
- package/lib/runsSourceEcho.js +84 -18
- package/lib/runsStart.d.ts +80 -17
- package/lib/runsStart.js +303 -49
- package/lib/runsTypes.d.ts +62 -2
- package/lib/runsTypes.js +30 -6
- package/lib/runsValidateArms.js +61 -7
- package/lib/runsValidateServe.d.ts +2 -2
- package/lib/runsValidateServe.js +46 -14
- package/lib/runsValidateShared.d.ts +10 -1
- package/lib/runsValidateShared.js +14 -0
- package/lib/runsValidateStages.d.ts +10 -3
- package/lib/runsValidateStages.js +44 -12
- package/lib/runtimeProvision.d.ts +119 -0
- package/lib/runtimeProvision.js +243 -0
- package/lib/service.d.ts +24 -6
- package/lib/service.js +19 -11
- package/lib/skillFs.d.ts +9 -4
- package/lib/skillFs.js +12 -14
- package/lib/skillPlane.d.ts +3 -2
- package/lib/skillPlane.js +12 -6
- package/lib/skillRegistry.js +1 -1
- package/lib/skillRows.d.ts +4 -3
- package/lib/skillRows.js +21 -14
- package/lib/toolProjection.d.ts +1 -1
- package/lib/toolProjection.js +1 -1
- package/package.json +18 -17
- package/lib/runStatus.d.ts +0 -7
- package/lib/runStatus.js +0 -21
package/lib/queueSubmit.d.ts
CHANGED
|
@@ -1,11 +1,24 @@
|
|
|
1
|
+
import { type DraftId } from "@melite/contracts/benchStage";
|
|
1
2
|
export interface QueueRefusal {
|
|
2
3
|
readonly status: number;
|
|
3
4
|
readonly payload: Record<string, unknown>;
|
|
4
5
|
}
|
|
5
6
|
export declare function refusal(status: number, error: string, code: string, loc?: string, expected?: string, got?: string): QueueRefusal;
|
|
7
|
+
/** The envelope refusal texts (door-verbatim, the ONE voice — both
|
|
8
|
+
* the submit envelope validator below and the registry's envelope
|
|
9
|
+
* walk delegate here; one copy, no drift). Kept as a table — one
|
|
10
|
+
* voice each, like the admission gate's static tables. */
|
|
11
|
+
export declare function envelopeRefusal(kind: "not-object" | "bad-test" | "missing-draft" | "malformed-draft", doc: unknown, detail?: {
|
|
12
|
+
testFlag?: unknown;
|
|
13
|
+
draftId?: string;
|
|
14
|
+
}): QueueRefusal;
|
|
15
|
+
/** The unknown-draft refusal (door-verbatim; the probe rides the
|
|
16
|
+
* caller's drafts domain — the remote hops the ctx seat). Takes the
|
|
17
|
+
* branded id: the walker mints it off the validated wire body. */
|
|
18
|
+
export declare function unknownDraftRefusal(draftId: DraftId): QueueRefusal;
|
|
6
19
|
/** Draft id rule (draftIdOk in @melite/estate-drafts, re-exported below): <=96 chars of [A-Za-z0-9_-]. */
|
|
7
20
|
/** This core re-checks nothing: it BUILDS the refusal for a caller-computed verdict (the check is one regex, owned by the drafts package so envelope validation is whole). */
|
|
8
|
-
/** Callers pass the raw draft_id; the malformed/unknown split needs the existence probe too — see
|
|
21
|
+
/** Callers pass the raw draft_id; the malformed/unknown split needs the existence probe too — see walkSubmitEnvelope. */
|
|
9
22
|
|
|
10
23
|
|
|
11
24
|
|
|
@@ -16,16 +29,117 @@ export { draftIdOk } from "@melite/estate-drafts";
|
|
|
16
29
|
export { RETIRED_RUNNER_KNOBS, RETIRED_CARRY_KEYS, DOOR_KEYS, } from "./vocab.js";
|
|
17
30
|
/** The strict-body gate (_strict_body 248-276). */
|
|
18
31
|
export declare function strictBodyCheck(body: Record<string, unknown>): QueueRefusal | null;
|
|
32
|
+
|
|
33
|
+
|
|
34
|
+
|
|
35
|
+
|
|
36
|
+
|
|
37
|
+
|
|
38
|
+
|
|
39
|
+
|
|
40
|
+
|
|
41
|
+
export declare function resolveTestFlag(body: Record<string, unknown>): unknown;
|
|
42
|
+
|
|
43
|
+
|
|
44
|
+
|
|
45
|
+
|
|
46
|
+
|
|
47
|
+
|
|
48
|
+
|
|
49
|
+
|
|
50
|
+
|
|
51
|
+
|
|
52
|
+
|
|
53
|
+
|
|
54
|
+
|
|
55
|
+
export declare function submitEnvelopeStructuralRefusal(doc: unknown): QueueRefusal | null;
|
|
19
56
|
/** Door-selection order (resolve_request 302: flow/flow_inline/
|
|
20
57
|
* model fixed order — ambiguity lists in DOOR order, not sorted). */
|
|
21
58
|
export declare const SUBMIT_DOORS: readonly string[];
|
|
22
|
-
/**
|
|
23
|
-
*
|
|
24
|
-
*
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
*
|
|
28
|
-
*
|
|
29
|
-
*
|
|
30
|
-
|
|
59
|
+
/** THE SEED-SWEEP CAP (the GPU-spend law): one press fans out to at
|
|
60
|
+
* most this many runs — a runaway array mints that many runs, each
|
|
61
|
+
* a full render. Larger compares split across presses. */
|
|
62
|
+
export declare const SEED_SWEEP_MAX = 16;
|
|
63
|
+
/** The door's KNOB PRESENCE-PROBES (the envelope wall's counterpart
|
|
64
|
+
* list): card knob names the submit door reads the PRESENCE of to
|
|
65
|
+
* refuse an ambiguous press — never consumed, never lifted, and
|
|
66
|
+
* deliberately NEVER envelope-registered (a registered probe would
|
|
67
|
+
* stop being a knob and liftCardParams would drop it from the
|
|
68
|
+
* card's params). Today: `seed`, probed so a `seeds` sweep never
|
|
69
|
+
* silently overrides a stated single seed at either seat (the
|
|
70
|
+
* sibling top-level key or the params stanza — siblings win the
|
|
71
|
+
* lift, so the override would be silent). */
|
|
72
|
+
export declare const DOOR_KNOB_PROBES: readonly string[];
|
|
73
|
+
/** The seed-sweep expansion's verdict: no `seeds` key (the legacy
|
|
74
|
+
* single run), a judged sweep, or a loud refusal. */
|
|
75
|
+
export type SeedSweep = {
|
|
76
|
+
kind: "single";
|
|
77
|
+
} | {
|
|
78
|
+
kind: "sweep";
|
|
79
|
+
seeds: readonly number[];
|
|
80
|
+
} | {
|
|
81
|
+
kind: "refusal";
|
|
82
|
+
refusal: QueueRefusal;
|
|
83
|
+
};
|
|
84
|
+
|
|
85
|
+
|
|
86
|
+
|
|
87
|
+
|
|
88
|
+
|
|
89
|
+
|
|
90
|
+
|
|
91
|
+
|
|
92
|
+
|
|
93
|
+
|
|
94
|
+
export declare function expandSeedSweep(body: Record<string, unknown>): SeedSweep;
|
|
95
|
+
/** The walker's chain in order: non-object body (bad_envelope/body)
|
|
96
|
+
* -> non-bool test (bad_envelope/test) -> draft required
|
|
97
|
+
* (draft_required) -> malformed (draft_malformed) -> unknown doc
|
|
98
|
+
* (draft_unknown). The probe is the caller's seat (existence is
|
|
99
|
+
* I/O — the walker owns the TEXT, the seat owns the fs). Strict
|
|
100
|
+
* knobs and door selection judge past the walk, at startReserved. */
|
|
101
|
+
/** The door-selection helpers, ONE HOME (the envelope-twin cure's
|
|
102
|
+
* doors half): the shared door set and the runs seat's
|
|
103
|
+
* selectSubmitDoor derive the door set and both
|
|
104
|
+
* refusal texts from HERE — the wire contract cannot drift
|
|
105
|
+
* between the two seats. hasOwnProperty (never `in`): a door is a
|
|
106
|
+
* body-own key, not a prototype inheritance. */
|
|
107
|
+
export declare function submitDoorsOf(body: Record<string, unknown>): string[];
|
|
108
|
+
/** The too-many-doors refusal (text is the wire contract). */
|
|
109
|
+
export declare function ambiguousDoorsRefusal(doors: string[]): QueueRefusal;
|
|
110
|
+
/** The no-door refusal (text is the wire contract). */
|
|
111
|
+
export declare function noDoorRefusal(): QueueRefusal;
|
|
112
|
+
/** THE PER-RUN CEILING VERDICT (the F8 law): `execute_ceil_ms` is a
|
|
113
|
+
* finite number (<= 0 disables the fuse) or absent; any other shape
|
|
114
|
+
* refuses at the start door — a typo must never silently ride the
|
|
115
|
+
* config default past a 30-min kill. */
|
|
116
|
+
export type ExecuteCeilVerdict = {
|
|
117
|
+
kind: "ok";
|
|
118
|
+
ceilMs: number | undefined;
|
|
119
|
+
} | {
|
|
120
|
+
kind: "bad";
|
|
121
|
+
value: unknown;
|
|
122
|
+
};
|
|
123
|
+
export declare function executeCeilOf(doc: Record<string, unknown>): ExecuteCeilVerdict;
|
|
124
|
+
/** THE ONE ENVELOPE WALKER (the S3 twin cure): the structural
|
|
125
|
+
* faces, the draft probe ordering and the ok face live HERE and
|
|
126
|
+
* the runs registration delegates — there is no second sync face
|
|
127
|
+
* to drift against. draftExists is the caller's probe (the runs
|
|
128
|
+
* seat hops to the drafts service and awaits; a sync caller passes
|
|
129
|
+
* a sync probe — one signature carries both). Returns the ok face
|
|
130
|
+
* when the envelope may proceed to door selection, which the live
|
|
131
|
+
* face owns at startReserved (strict then doors, after the
|
|
132
|
+
* replay/reservation verdict). */
|
|
133
|
+
export declare function walkSubmitEnvelope(doc: unknown, draftExists: (draftId: DraftId) => boolean | Promise<boolean>): Promise<{
|
|
134
|
+
kind: "ok";
|
|
135
|
+
body: Record<string, unknown>;
|
|
136
|
+
testFlag: boolean;
|
|
137
|
+
draftId: DraftId;
|
|
138
|
+
/** The start body's own execute ceiling (absent = the queue
|
|
139
|
+
* config decides; <= 0 disables the fuse). */
|
|
140
|
+
ceilMs: number | undefined;
|
|
141
|
+
} | {
|
|
142
|
+
kind: "refusal";
|
|
143
|
+
refusal: QueueRefusal;
|
|
144
|
+
}>;
|
|
31
145
|
//# sourceMappingURL=queueSubmit.d.ts.map
|
package/lib/queueSubmit.js
CHANGED
|
@@ -4,6 +4,7 @@
|
|
|
4
4
|
//
|
|
5
5
|
// Erasable-syntax TS only (node --experimental-strip-types): no
|
|
6
6
|
// enums, import type for types, .ts specifiers for relative imports.
|
|
7
|
+
import { draftIdOf } from "@melite/contracts/benchStage";
|
|
7
8
|
export function refusal(status, error, code, loc, expected, got) {
|
|
8
9
|
const payload = { error, code };
|
|
9
10
|
if (loc !== undefined)
|
|
@@ -14,9 +15,47 @@ export function refusal(status, error, code, loc, expected, got) {
|
|
|
14
15
|
payload["got"] = got;
|
|
15
16
|
return { status, payload };
|
|
16
17
|
}
|
|
18
|
+
/** The envelope refusal texts (door-verbatim, the ONE voice — both
|
|
19
|
+
* the submit envelope validator below and the registry's envelope
|
|
20
|
+
* walk delegate here; one copy, no drift). Kept as a table — one
|
|
21
|
+
* voice each, like the admission gate's static tables. */
|
|
22
|
+
export function envelopeRefusal(kind, doc, detail) {
|
|
23
|
+
switch (kind) {
|
|
24
|
+
case "not-object":
|
|
25
|
+
return refusal(400, "request body must be a JSON object", "bad_envelope", "body", "object", Array.isArray(doc) ? "array" : typeof doc);
|
|
26
|
+
case "bad-test":
|
|
27
|
+
return refusal(400, "test flag must be a boolean (got " +
|
|
28
|
+
(typeof detail?.testFlag) +
|
|
29
|
+
" " +
|
|
30
|
+
JSON.stringify(detail?.testFlag) +
|
|
31
|
+
")", "bad_envelope", "test", "boolean", (typeof detail?.testFlag));
|
|
32
|
+
case "missing-draft":
|
|
33
|
+
return refusal(400, "draft_id is required — every run is born from an " +
|
|
34
|
+
"action card (CARD BIRTH LAW); compose the card first: " +
|
|
35
|
+
"POST /v1/flows/drafts, then start with its draft_id", "draft_required", "draft_id", "doc-backed draft id", "absent");
|
|
36
|
+
case "malformed-draft":
|
|
37
|
+
return refusal(400, "draft_id malformed (96 char cap, [A-Za-z0-9_-] only): " +
|
|
38
|
+
JSON.stringify(detail?.draftId ?? ""), "draft_malformed", "draft_id", "[A-Za-z0-9_-]{1,96}", (detail?.draftId ?? "").slice(0, 60));
|
|
39
|
+
default:
|
|
40
|
+
// Closed union: a new refusal kind fails loud at compile, not
|
|
41
|
+
// silently undefined at the door. assertNever from
|
|
42
|
+
// @deepseek-ai/dsh-util-values (maintained helper, not a handroll).
|
|
43
|
+
return assertNever(kind, "queueSubmit.envelopeRefusal");
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
/** The unknown-draft refusal (door-verbatim; the probe rides the
|
|
47
|
+
* caller's drafts domain — the remote hops the ctx seat). Takes the
|
|
48
|
+
* branded id: the walker mints it off the validated wire body. */
|
|
49
|
+
export function unknownDraftRefusal(draftId) {
|
|
50
|
+
return refusal(400, "unknown draft_id " +
|
|
51
|
+
JSON.stringify(draftId) +
|
|
52
|
+
" — no card doc at drafts/" +
|
|
53
|
+
draftId +
|
|
54
|
+
".json; compose the card first: POST /v1/flows/drafts", "draft_unknown", "draft_id", "existing card doc", draftId.slice(0, 60));
|
|
55
|
+
}
|
|
17
56
|
/** Draft id rule (draftIdOk in @melite/estate-drafts, re-exported below): <=96 chars of [A-Za-z0-9_-]. */
|
|
18
57
|
/** This core re-checks nothing: it BUILDS the refusal for a caller-computed verdict (the check is one regex, owned by the drafts package so envelope validation is whole). */
|
|
19
|
-
/** Callers pass the raw draft_id; the malformed/unknown split needs the existence probe too — see
|
|
58
|
+
/** Callers pass the raw draft_id; the malformed/unknown split needs the existence probe too — see walkSubmitEnvelope. */
|
|
20
59
|
|
|
21
60
|
|
|
22
61
|
|
|
@@ -30,6 +69,7 @@ export { draftIdOk } from "@melite/estate-drafts";
|
|
|
30
69
|
// these re-exports keep the @melite/gateway-queue barrel stable.
|
|
31
70
|
export { RETIRED_RUNNER_KNOBS, RETIRED_CARRY_KEYS, DOOR_KEYS, } from "./vocab.js";
|
|
32
71
|
import { RETIRED_RUNNER_KNOBS, RETIRED_CARRY_KEYS, DOOR_KEYS, } from "./vocab.js";
|
|
72
|
+
import { assertNever } from "@deepseek-ai/dsh-util-values";
|
|
33
73
|
import { draftIdOk } from "@melite/estate-drafts";
|
|
34
74
|
/** The strict-body gate (_strict_body 248-276). */
|
|
35
75
|
export function strictBodyCheck(body) {
|
|
@@ -55,63 +95,226 @@ export function strictBodyCheck(body) {
|
|
|
55
95
|
}
|
|
56
96
|
return null;
|
|
57
97
|
}
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
98
|
+
|
|
99
|
+
|
|
100
|
+
|
|
101
|
+
|
|
102
|
+
|
|
103
|
+
|
|
104
|
+
|
|
105
|
+
|
|
106
|
+
|
|
107
|
+
export function resolveTestFlag(body) {
|
|
108
|
+
if (!("test" in body) || body["test"] === null)
|
|
109
|
+
return false;
|
|
110
|
+
return body["test"];
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
|
|
114
|
+
|
|
115
|
+
|
|
116
|
+
|
|
117
|
+
|
|
118
|
+
|
|
119
|
+
|
|
120
|
+
|
|
121
|
+
|
|
122
|
+
|
|
123
|
+
|
|
124
|
+
|
|
125
|
+
export function submitEnvelopeStructuralRefusal(doc) {
|
|
74
126
|
if (typeof doc !== "object" || doc === null || Array.isArray(doc)) {
|
|
75
|
-
return
|
|
127
|
+
return envelopeRefusal("not-object", doc);
|
|
76
128
|
}
|
|
77
129
|
const body = doc;
|
|
78
|
-
const testFlag = body
|
|
130
|
+
const testFlag = resolveTestFlag(body);
|
|
79
131
|
if (typeof testFlag !== "boolean") {
|
|
80
|
-
return
|
|
81
|
-
(typeof testFlag) +
|
|
82
|
-
" " +
|
|
83
|
-
JSON.stringify(testFlag) +
|
|
84
|
-
")", "bad_envelope", "test", "boolean", (typeof testFlag));
|
|
132
|
+
return envelopeRefusal("bad-test", doc, { testFlag });
|
|
85
133
|
}
|
|
86
134
|
const draftId = body["draft_id"];
|
|
87
135
|
if (typeof draftId !== "string" || draftId === "") {
|
|
88
|
-
return
|
|
89
|
-
"action card (CARD BIRTH LAW); compose the card first: " +
|
|
90
|
-
"POST /v1/flows/drafts, then start with its draft_id", "draft_required", "draft_id", "doc-backed draft id", "absent");
|
|
136
|
+
return envelopeRefusal("missing-draft", doc);
|
|
91
137
|
}
|
|
92
138
|
if (!draftIdOk(draftId)) {
|
|
93
|
-
return
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
const doors = SUBMIT_DOORS.filter((k) => Object.prototype.hasOwnProperty.call(body, k));
|
|
107
|
-
if (doors.length > 1) {
|
|
108
|
-
return refusal(400, "ambiguous request: names " +
|
|
109
|
-
JSON.stringify(doors) +
|
|
110
|
-
" — provide exactly one of flow, flow_inline, model", "invalid_request");
|
|
111
|
-
}
|
|
112
|
-
if (doors.length === 0) {
|
|
113
|
-
return refusal(400, "no flow selected: provide flow, flow_inline or model", "invalid_request");
|
|
139
|
+
return envelopeRefusal("malformed-draft", doc, { draftId });
|
|
140
|
+
}
|
|
141
|
+
// THE PRESS KEY (audit N-E1): an OPTIONAL client-minted id naming
|
|
142
|
+
// THE PRESS — a transport retry or a double-fire of one press
|
|
143
|
+
// replays the same key, and the registry answers the FIRST run
|
|
144
|
+
// instead of minting a second one. Absent = the legacy behavior
|
|
145
|
+
// (every call is a new press). Opaque: bounded length, safe
|
|
146
|
+
// charset, never interpreted.
|
|
147
|
+
const pressKey = body["press_key"];
|
|
148
|
+
if (pressKey !== undefined) {
|
|
149
|
+
if (typeof pressKey !== "string" || !/^[-A-Za-z0-9_.]{8,128}$/.test(pressKey)) {
|
|
150
|
+
return refusal(400, "press_key must be 8-128 chars of [-A-Za-z0-9_.] — it names ONE press across retries", "invalid_request", "press_key");
|
|
151
|
+
}
|
|
114
152
|
}
|
|
115
153
|
return null;
|
|
116
154
|
}
|
|
155
|
+
/** Door-selection order (resolve_request 302: flow/flow_inline/
|
|
156
|
+
* model fixed order — ambiguity lists in DOOR order, not sorted). */
|
|
157
|
+
export const SUBMIT_DOORS = [
|
|
158
|
+
"flow",
|
|
159
|
+
"flow_inline",
|
|
160
|
+
"model",
|
|
161
|
+
];
|
|
162
|
+
/** THE SEED-SWEEP CAP (the GPU-spend law): one press fans out to at
|
|
163
|
+
* most this many runs — a runaway array mints that many runs, each
|
|
164
|
+
* a full render. Larger compares split across presses. */
|
|
165
|
+
export const SEED_SWEEP_MAX = 16;
|
|
166
|
+
/** The door's KNOB PRESENCE-PROBES (the envelope wall's counterpart
|
|
167
|
+
* list): card knob names the submit door reads the PRESENCE of to
|
|
168
|
+
* refuse an ambiguous press — never consumed, never lifted, and
|
|
169
|
+
* deliberately NEVER envelope-registered (a registered probe would
|
|
170
|
+
* stop being a knob and liftCardParams would drop it from the
|
|
171
|
+
* card's params). Today: `seed`, probed so a `seeds` sweep never
|
|
172
|
+
* silently overrides a stated single seed at either seat (the
|
|
173
|
+
* sibling top-level key or the params stanza — siblings win the
|
|
174
|
+
* lift, so the override would be silent). */
|
|
175
|
+
export const DOOR_KNOB_PROBES = ["seed"];
|
|
176
|
+
/** One seat of a stated knob: the sibling key, or the params stanza
|
|
177
|
+
* member (liftCardParams treats both as the same knob — the probe
|
|
178
|
+
* must too, or the stanza seat dodges the refusal). */
|
|
179
|
+
const knobStated = (body, knob) => {
|
|
180
|
+
if (body[knob] !== undefined)
|
|
181
|
+
return true;
|
|
182
|
+
const stanza = body["params"];
|
|
183
|
+
if (typeof stanza === "object" && stanza !== null && !Array.isArray(stanza)) {
|
|
184
|
+
return stanza[knob] !== undefined;
|
|
185
|
+
}
|
|
186
|
+
return false;
|
|
187
|
+
};
|
|
188
|
+
|
|
189
|
+
|
|
190
|
+
|
|
191
|
+
|
|
192
|
+
|
|
193
|
+
|
|
194
|
+
|
|
195
|
+
|
|
196
|
+
|
|
197
|
+
|
|
198
|
+
export function expandSeedSweep(body) {
|
|
199
|
+
const raw = body["seeds"];
|
|
200
|
+
if (raw === undefined)
|
|
201
|
+
return { kind: "single" };
|
|
202
|
+
const doors = submitDoorsOf(body);
|
|
203
|
+
if (doors.length !== 1 || doors[0] !== "model") {
|
|
204
|
+
const named = doors.length === 0 ? "no door" : JSON.stringify(doors);
|
|
205
|
+
return {
|
|
206
|
+
kind: "refusal",
|
|
207
|
+
refusal: refusal(400, "`seeds` rides the model (card) door alone — this body names " +
|
|
208
|
+
named +
|
|
209
|
+
". Send seeds with a {model: …} card body: the sweep mints one run per seed", "invalid_request"),
|
|
210
|
+
};
|
|
211
|
+
}
|
|
212
|
+
if (knobStated(body, "seed")) {
|
|
213
|
+
return {
|
|
214
|
+
kind: "refusal",
|
|
215
|
+
refusal: refusal(400, 'both "seed" and "seeds" stated — the sweep sets seed per run; state exactly one (a single seed for one roll, seeds: [...] for the sweep)', "invalid_request"),
|
|
216
|
+
};
|
|
217
|
+
}
|
|
218
|
+
if (!Array.isArray(raw) || raw.length === 0) {
|
|
219
|
+
return {
|
|
220
|
+
kind: "refusal",
|
|
221
|
+
refusal: refusal(400, '"seeds" must be a non-empty array of integers — the sweep mints one run per seed', "invalid_request"),
|
|
222
|
+
};
|
|
223
|
+
}
|
|
224
|
+
const seeds = [];
|
|
225
|
+
for (const [i, v] of raw.entries()) {
|
|
226
|
+
if (typeof v !== "number" || !Number.isSafeInteger(v)) {
|
|
227
|
+
return {
|
|
228
|
+
kind: "refusal",
|
|
229
|
+
refusal: refusal(400, "seeds[" + i + "] is " + JSON.stringify(v) +
|
|
230
|
+
" — every sweep seat is a safe integer (the engine seed's own domain)", "invalid_request"),
|
|
231
|
+
};
|
|
232
|
+
}
|
|
233
|
+
seeds.push(v);
|
|
234
|
+
}
|
|
235
|
+
if (seeds.length > SEED_SWEEP_MAX) {
|
|
236
|
+
return {
|
|
237
|
+
kind: "refusal",
|
|
238
|
+
refusal: refusal(400, "seeds carries " + seeds.length + " entries — the sweep mints one run per seed and caps at " +
|
|
239
|
+
SEED_SWEEP_MAX + " (the GPU-spend law); split larger compares across presses", "invalid_request"),
|
|
240
|
+
};
|
|
241
|
+
}
|
|
242
|
+
return { kind: "sweep", seeds };
|
|
243
|
+
}
|
|
244
|
+
/** The walker's chain in order: non-object body (bad_envelope/body)
|
|
245
|
+
* -> non-bool test (bad_envelope/test) -> draft required
|
|
246
|
+
* (draft_required) -> malformed (draft_malformed) -> unknown doc
|
|
247
|
+
* (draft_unknown). The probe is the caller's seat (existence is
|
|
248
|
+
* I/O — the walker owns the TEXT, the seat owns the fs). Strict
|
|
249
|
+
* knobs and door selection judge past the walk, at startReserved. */
|
|
250
|
+
/** The door-selection helpers, ONE HOME (the envelope-twin cure's
|
|
251
|
+
* doors half): the shared door set and the runs seat's
|
|
252
|
+
* selectSubmitDoor derive the door set and both
|
|
253
|
+
* refusal texts from HERE — the wire contract cannot drift
|
|
254
|
+
* between the two seats. hasOwnProperty (never `in`): a door is a
|
|
255
|
+
* body-own key, not a prototype inheritance. */
|
|
256
|
+
export function submitDoorsOf(body) {
|
|
257
|
+
return SUBMIT_DOORS.filter((k) => Object.prototype.hasOwnProperty.call(body, k));
|
|
258
|
+
}
|
|
259
|
+
/** The too-many-doors refusal (text is the wire contract). */
|
|
260
|
+
export function ambiguousDoorsRefusal(doors) {
|
|
261
|
+
return refusal(400, "ambiguous request: names " +
|
|
262
|
+
JSON.stringify(doors) +
|
|
263
|
+
" — provide exactly one of flow, flow_inline, model", "invalid_request");
|
|
264
|
+
}
|
|
265
|
+
/** The no-door refusal (text is the wire contract). */
|
|
266
|
+
export function noDoorRefusal() {
|
|
267
|
+
return refusal(400, "no flow selected: provide flow, flow_inline or model", "invalid_request");
|
|
268
|
+
}
|
|
269
|
+
export function executeCeilOf(doc) {
|
|
270
|
+
const raw = doc["execute_ceil_ms"];
|
|
271
|
+
if (raw === undefined)
|
|
272
|
+
return { kind: "ok", ceilMs: undefined };
|
|
273
|
+
if (typeof raw !== "number" || !Number.isFinite(raw))
|
|
274
|
+
return { kind: "bad", value: raw };
|
|
275
|
+
return { kind: "ok", ceilMs: raw };
|
|
276
|
+
}
|
|
277
|
+
/** THE ONE ENVELOPE WALKER (the S3 twin cure): the structural
|
|
278
|
+
* faces, the draft probe ordering and the ok face live HERE and
|
|
279
|
+
* the runs registration delegates — there is no second sync face
|
|
280
|
+
* to drift against. draftExists is the caller's probe (the runs
|
|
281
|
+
* seat hops to the drafts service and awaits; a sync caller passes
|
|
282
|
+
* a sync probe — one signature carries both). Returns the ok face
|
|
283
|
+
* when the envelope may proceed to door selection, which the live
|
|
284
|
+
* face owns at startReserved (strict then doors, after the
|
|
285
|
+
* replay/reservation verdict). */
|
|
286
|
+
export async function walkSubmitEnvelope(doc, draftExists) {
|
|
287
|
+
const structural = submitEnvelopeStructuralRefusal(doc);
|
|
288
|
+
if (structural !== null)
|
|
289
|
+
return { kind: "refusal", refusal: structural };
|
|
290
|
+
const body = doc;
|
|
291
|
+
// THE PARSE EDGE: the draft_id arrived on the wire and passed the
|
|
292
|
+
// 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))) {
|
|
296
|
+
return { kind: "refusal", refusal: unknownDraftRefusal(draftId) };
|
|
297
|
+
}
|
|
298
|
+
// THE PER-RUN CEILING REFUSAL (the F8 burn): the shape is judged at
|
|
299
|
+
// THE ONE WALKER every start crosses — a malformed lever never
|
|
300
|
+
// rides the queue config default into a long run's kill.
|
|
301
|
+
const ceil = executeCeilOf(body);
|
|
302
|
+
if (ceil.kind === "bad") {
|
|
303
|
+
return {
|
|
304
|
+
kind: "refusal",
|
|
305
|
+
refusal: refusal(400, "execute_ceil_ms must be a finite number of milliseconds (<= 0 disables the hung-run fuse) — got " +
|
|
306
|
+
JSON.stringify(ceil.value), "bad", "execute_ceil_ms", "finite number | <= 0", typeof ceil.value),
|
|
307
|
+
};
|
|
308
|
+
}
|
|
309
|
+
// (one-seat law §7 P7 F-1: the flag resolves ONLY through the
|
|
310
|
+
// named seat — the structural face above already refused
|
|
311
|
+
// non-bool, so the seat's unknown is boolean on this domain.)
|
|
312
|
+
return {
|
|
313
|
+
kind: "ok",
|
|
314
|
+
body,
|
|
315
|
+
testFlag: resolveTestFlag(body),
|
|
316
|
+
draftId,
|
|
317
|
+
ceilMs: ceil.ceilMs,
|
|
318
|
+
};
|
|
319
|
+
}
|
|
117
320
|
//# sourceMappingURL=queueSubmit.js.map
|
package/lib/queueSweep.js
CHANGED
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
//
|
|
5
5
|
// Erasable-syntax TS only (node --experimental-strip-types): no
|
|
6
6
|
// enums, import type for types, .ts specifiers for relative imports.
|
|
7
|
-
import { readdirSync, readFileSync } from "node:fs";
|
|
7
|
+
import { readdirSync, readFileSync, rmSync } from "node:fs";
|
|
8
8
|
import { join } from "node:path";
|
|
9
9
|
import { appendLedger, writeJsonAtomic } from "./queueLock.js";
|
|
10
10
|
/** Patch a stale sidecar (pure half of sweep_sidecar): every
|
|
@@ -102,7 +102,18 @@ export async function bootSweep(stateRoot, liveRunIds = [], nowS = Math.floor(Da
|
|
|
102
102
|
// not vanish from the sweep silently — the QUEUE LANE LAW
|
|
103
103
|
// wants every boot disposition ledgered so the operator can
|
|
104
104
|
// reconcile (the old bare continue left an unaudited row).
|
|
105
|
-
|
|
105
|
+
// THE CRASH-ORPHAN (lifecycle audit Q5): an ABSENT sidecar is
|
|
106
|
+
// the press that died between its two writes — the run was
|
|
107
|
+
// never enqueued, so the id is observed once here and the dir
|
|
108
|
+
// is reclaimed instead of sitting as orphan bytes. A
|
|
109
|
+
// PRESENT-but-unparsable sidecar keeps the ledger-only
|
|
110
|
+
// disposition (operator reconcile owns the genuinely corrupt).
|
|
111
|
+
const orphaned = e instanceof Error && e.code === "ENOENT";
|
|
112
|
+
if (orphaned)
|
|
113
|
+
rmSync(join(outRoot, name), { recursive: true, force: true });
|
|
114
|
+
appendLedger(stateRoot, "run.swept", { run_id: name, state: "unreadable", error: orphaned
|
|
115
|
+
? "boot sweep: _flow.json absent — crash-orphaned dir dropped"
|
|
116
|
+
: `boot sweep: _flow.json parse failed: ${e instanceof Error ? e.message : String(e)}` }, nowS);
|
|
106
117
|
continue;
|
|
107
118
|
}
|
|
108
119
|
if (typeof current !== "object" || current === null || Array.isArray(current)) {
|
package/lib/runsChange.d.ts
CHANGED
|
@@ -13,6 +13,7 @@ declare module "@deepseek-ai/cordis" {
|
|
|
13
13
|
* A run row moved — a claim (queued→running), a settle
|
|
14
14
|
* (terminal), an artifacts harvest, or a stop press (→stopping).
|
|
15
15
|
* Emitted after the write landed.
|
|
16
|
+
* @mode emit
|
|
16
17
|
* @param runId - the run whose row moved.
|
|
17
18
|
*/
|
|
18
19
|
"runs.changed": (runId: string) => void;
|
|
@@ -25,6 +26,13 @@ declare module "@deepseek-ai/cordis" {
|
|
|
25
26
|
* is single-tenant here, and the failure mode is loud — onRunChange
|
|
26
27
|
* refuses rather than subscribing to nothing). */
|
|
27
28
|
export declare function setRunsChangeSeam(seam: RunsChangeSeam | null): void;
|
|
29
|
+
/** Detach the seam ONLY if `seam` is still the installed one — the
|
|
30
|
+
* ownership stamp that keeps dispose honest: a fiber that installed
|
|
31
|
+
* EARLIER (a newer install displaced it) detaches nothing, so the
|
|
32
|
+
* live seam survives the older fiber's unwind.
|
|
33
|
+
* @param seam - the seam instance the caller installed.
|
|
34
|
+
*/
|
|
35
|
+
export declare function clearRunsChangeSeam(seam: RunsChangeSeam): void;
|
|
28
36
|
|
|
29
37
|
|
|
30
38
|
|
package/lib/runsChange.js
CHANGED
|
@@ -8,6 +8,16 @@ let runsChangeSeam = null;
|
|
|
8
8
|
export function setRunsChangeSeam(seam) {
|
|
9
9
|
runsChangeSeam = seam;
|
|
10
10
|
}
|
|
11
|
+
/** Detach the seam ONLY if `seam` is still the installed one — the
|
|
12
|
+
* ownership stamp that keeps dispose honest: a fiber that installed
|
|
13
|
+
* EARLIER (a newer install displaced it) detaches nothing, so the
|
|
14
|
+
* live seam survives the older fiber's unwind.
|
|
15
|
+
* @param seam - the seam instance the caller installed.
|
|
16
|
+
*/
|
|
17
|
+
export function clearRunsChangeSeam(seam) {
|
|
18
|
+
if (runsChangeSeam === seam)
|
|
19
|
+
runsChangeSeam = null;
|
|
20
|
+
}
|
|
11
21
|
|
|
12
22
|
|
|
13
23
|
|
|
@@ -24,8 +34,11 @@ export function onRunChange(fn) {
|
|
|
24
34
|
try {
|
|
25
35
|
fn(runId);
|
|
26
36
|
}
|
|
27
|
-
catch {
|
|
28
|
-
|
|
37
|
+
catch (fault) {
|
|
38
|
+
|
|
39
|
+
|
|
40
|
+
|
|
41
|
+
console.error("runs.changed listener fault:", fault);
|
|
29
42
|
}
|
|
30
43
|
});
|
|
31
44
|
}
|
|
@@ -48,14 +61,17 @@ export function notifyRunChanged(runId) {
|
|
|
48
61
|
export function installRunsChangeSeam(ctx) {
|
|
49
62
|
let detach = null;
|
|
50
63
|
ctx.effect(() => {
|
|
51
|
-
|
|
64
|
+
const mine = {
|
|
52
65
|
emit: (runId) => { ctx.emit("runs.changed", runId); },
|
|
53
66
|
on: (fn) => {
|
|
54
67
|
const stop = ctx.on("runs.changed", fn);
|
|
55
68
|
return () => { stop(); };
|
|
56
69
|
},
|
|
57
|
-
}
|
|
58
|
-
|
|
70
|
+
};
|
|
71
|
+
setRunsChangeSeam(mine);
|
|
72
|
+
// the ownership stamp: an older fiber's unwind clears only its own
|
|
73
|
+
// install — a displaced seam detaches nothing (clearRunsChangeSeam)
|
|
74
|
+
detach = () => { clearRunsChangeSeam(mine); };
|
|
59
75
|
return detach;
|
|
60
76
|
});
|
|
61
77
|
return () => { detach?.(); };
|
package/lib/runsErrorCodes.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export declare const RUNS_ERROR_CODES: Readonly<Record<string, "runs/bad-envelope" | "runs/draft-required" | "runs/draft-malformed" | "runs/draft-unknown" | "runs/invalid-request" | "runs/preview-scope" | "runs/flow-compile" | "runs/workflow-pin" | "runs/card-compose" | "runs/lane-input-missing">>;
|
|
1
|
+
export declare const RUNS_ERROR_CODES: Readonly<Record<string, "runs/bad-envelope" | "runs/draft-required" | "runs/draft-malformed" | "runs/draft-unknown" | "runs/invalid-request" | "runs/preview-scope" | "runs/flow-compile" | "runs/workflow-pin" | "runs/card-compose" | "runs/card-compose-incomplete" | "runs/lane-input-missing" | "runs/lifecycle-inflight">>;
|
|
2
2
|
//# sourceMappingURL=runsErrorCodes.d.ts.map
|
package/lib/runsErrorCodes.js
CHANGED
|
@@ -1,5 +1,38 @@
|
|
|
1
1
|
// runsErrorCodes.ts — the refusal-code -> HTTP answer-code table
|
|
2
2
|
// (the one mapping; an unnamed code is a LOUD bug, never generic).
|
|
3
|
+
//
|
|
4
|
+
|
|
5
|
+
// NEW envelope code must touch every seat below in the same change,
|
|
6
|
+
// or it compiles and then bites later —
|
|
7
|
+
// 1. a row HERE (the envelope spelling -> the runs/* wire value);
|
|
8
|
+
// 2. a `RemoteErrorDetailsMap` merge entry in runsRegistry.ts
|
|
9
|
+
// (the compiler enforces table <-> details sync at
|
|
10
|
+
// toRemoteError — details must satisfy the map's row);
|
|
11
|
+
// 3. the CLIENT's refusedCode discrimination (melite-card-view:
|
|
12
|
+
// cards-tab-body's heal-vs-carry split reads the wire value;
|
|
13
|
+
// an untabled class silently takes the default fail-carry —
|
|
14
|
+
// the replay-poison shape this table exists to prevent);
|
|
15
|
+
// 4. the validate-arm guards in runsValidateArms.ts (the two LOUD
|
|
16
|
+
// throw sites that refuse untabled codes at the door);
|
|
17
|
+
// 5. phaseRefusalCode (cardsArmError.ts) — its param is narrowed
|
|
18
|
+
// to this table's keys, so a new throw-site code fails
|
|
19
|
+
// TYPECHECK here first, never at the client.
|
|
20
|
+
// The two spellings are law: the ENVELOPE key (card_compose) rides
|
|
21
|
+
// the throw; the WIRE value (runs/card-compose) is what the client
|
|
22
|
+
// compares. Both live in this table's one row.
|
|
23
|
+
//
|
|
24
|
+
|
|
25
|
+
// wire codes that never ride the envelope and are NOT tabled here,
|
|
26
|
+
// by design — `runs/unknown-run` and `runs/run-unknown` are thrown
|
|
27
|
+
// direct with the wire spelling at their own sites (status/stop
|
|
28
|
+
// misses; their details rows live in the RemoteErrorDetailsMap at
|
|
29
|
+
// runsRegistry.ts, not in this envelope table), `runs/already-settled`
|
|
30
|
+
|
|
31
|
+
// door's loud refusal on a plainly settled row), and `bad_json` is
|
|
32
|
+
// the strict-wire gate's 400 payload (runsGates.ts; its door path
|
|
33
|
+
// has zero production consumers — its deletion call sits with the
|
|
34
|
+
// dead-exports census row, not here). A new code must still take
|
|
35
|
+
// the five seats above; the exemption is closed.
|
|
3
36
|
export const RUNS_ERROR_CODES = {
|
|
4
37
|
bad_envelope: "runs/bad-envelope",
|
|
5
38
|
draft_required: "runs/draft-required",
|
|
@@ -10,6 +43,8 @@ export const RUNS_ERROR_CODES = {
|
|
|
10
43
|
flow_compile: "runs/flow-compile",
|
|
11
44
|
workflow_pin: "runs/workflow-pin",
|
|
12
45
|
card_compose: "runs/card-compose",
|
|
46
|
+
card_compose_incomplete: "runs/card-compose-incomplete",
|
|
13
47
|
lane_input_missing: "runs/lane-input-missing",
|
|
48
|
+
lifecycle_inflight: "runs/lifecycle-inflight",
|
|
14
49
|
};
|
|
15
50
|
//# sourceMappingURL=runsErrorCodes.js.map
|