pi-mega-compact 0.20.70 → 0.20.72
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/dist/extensions/dashboard-server/routes-setup-cortex.js +7 -1
- package/dist/extensions/dashboard-server/routes-vector-cortex-crystals.js +45 -30
- package/dist/extensions/dashboard-server/routes-vector-cortex-diagnostics.js +50 -29
- package/dist/extensions/dashboard-server/routes-vector-cortex-economics.js +33 -20
- package/dist/extensions/dashboard-server/routes-vector-cortex-helpers.js +54 -0
- package/dist/extensions/dashboard-server/routes-vector-cortex-policy.js +33 -16
- package/dist/src/vector-cortex/cache/store.js +25 -2
- package/dist/src/vector-cortex/encoder/asset.js +34 -2
- package/dist/src/vector-cortex/encoder/router.js +31 -3
- package/dist/src/vector-cortex/livewire/livewire-live.js +163 -0
- package/dist/src/vector-cortex/livewire/livewire-registry.js +73 -0
- package/dist/src/vector-cortex/livewire/livewire-runtime.js +107 -0
- package/dist/src/vector-cortex/livewire/livewire-snapshot.js +101 -0
- package/dist/src/vector-cortex/livewire/livewire-types.js +19 -0
- package/dist/src/vector-cortex/provider/registry.js +44 -12
- package/dist/src/vector-cortex/setup-cortex-blockers-compute.js +43 -7
- package/dist/vector-cortex/cache/store.js +25 -2
- package/dist/vector-cortex/encoder/asset.js +34 -2
- package/dist/vector-cortex/encoder/router.js +31 -3
- package/dist/vector-cortex/provider/registry.js +44 -12
- package/dist/vector-cortex/setup-cortex-blockers-compute.js +43 -7
- package/extensions/dashboard-server/routes-setup-cortex.ts +8 -1
- package/extensions/dashboard-server/routes-vector-cortex-crystals.ts +46 -30
- package/extensions/dashboard-server/routes-vector-cortex-diagnostics.ts +52 -29
- package/extensions/dashboard-server/routes-vector-cortex-economics.ts +35 -20
- package/extensions/dashboard-server/routes-vector-cortex-helpers.ts +84 -0
- package/extensions/dashboard-server/routes-vector-cortex-policy.ts +35 -16
- package/package.json +1 -1
- package/src/vector-cortex/cache/store.ts +26 -2
- package/src/vector-cortex/encoder/asset.ts +46 -3
- package/src/vector-cortex/encoder/router.ts +56 -2
- package/src/vector-cortex/encoder/types.ts +3 -0
- package/src/vector-cortex/livewire/livewire-live.ts +223 -0
- package/src/vector-cortex/livewire/livewire-registry.ts +91 -0
- package/src/vector-cortex/livewire/livewire-runtime.ts +117 -0
- package/src/vector-cortex/livewire/livewire-snapshot.ts +108 -0
- package/src/vector-cortex/livewire/livewire-types.ts +84 -0
- package/src/vector-cortex/provider/economics.ts +9 -31
- package/src/vector-cortex/provider/registry.ts +82 -11
- package/src/vector-cortex/provider/types.ts +37 -0
- package/src/vector-cortex/setup-cortex-blockers-compute.ts +48 -7
|
@@ -70,6 +70,11 @@ export class CrystalStore {
|
|
|
70
70
|
writes = 0;
|
|
71
71
|
duplicateWrites = 0;
|
|
72
72
|
collisions = 0;
|
|
73
|
+
/** Restart-survival crystal count/bytes (LIVEWIRE rehydrate). The `committed`
|
|
74
|
+
* map is empty in a fresh process; these offsets carry the persisted totals
|
|
75
|
+
* so the dashboard does not reset to zero on restart. */
|
|
76
|
+
rehydratedCrystalCount = 0;
|
|
77
|
+
rehydratedTotalBytes = 0;
|
|
73
78
|
/** Freeze a crystal object for a key/bytes pair (digest computed here). */
|
|
74
79
|
static freeze(keyDigest, bytes, key) {
|
|
75
80
|
const copy = new Uint8Array(bytes);
|
|
@@ -178,12 +183,12 @@ export class CrystalStore {
|
|
|
178
183
|
}
|
|
179
184
|
/** Reader-only aggregate for the dashboard seam — counts and bytes only. */
|
|
180
185
|
stats() {
|
|
181
|
-
let totalBytes =
|
|
186
|
+
let totalBytes = this.rehydratedTotalBytes;
|
|
182
187
|
for (const c of this.committed.values())
|
|
183
188
|
totalBytes += c.byteCount;
|
|
184
189
|
return {
|
|
185
190
|
mode: this.mode(),
|
|
186
|
-
crystalCount: this.committed.size,
|
|
191
|
+
crystalCount: this.rehydratedCrystalCount + this.committed.size,
|
|
187
192
|
totalBytes,
|
|
188
193
|
hits: this.hits,
|
|
189
194
|
misses: this.misses,
|
|
@@ -193,4 +198,22 @@ export class CrystalStore {
|
|
|
193
198
|
collisions: this.collisions,
|
|
194
199
|
};
|
|
195
200
|
}
|
|
201
|
+
/**
|
|
202
|
+
* Restart survival: seed the CUMULATIVE counters from a previously-persisted
|
|
203
|
+
* aggregate (LIVEWIRE). The in-memory `committed` map is naturally empty in a
|
|
204
|
+
* fresh process — this only restores the running totals the dashboard reports,
|
|
205
|
+
* so a process restart does not reset the dashboard to zero. It deliberately
|
|
206
|
+
* does NOT reconstruct crystals: frozen bytes are never persisted to the
|
|
207
|
+
* reader aggregate, only the counts.
|
|
208
|
+
*/
|
|
209
|
+
rehydrate(stats) {
|
|
210
|
+
this.rehydratedCrystalCount = stats.crystalCount;
|
|
211
|
+
this.rehydratedTotalBytes = stats.totalBytes;
|
|
212
|
+
this.hits = stats.hits;
|
|
213
|
+
this.misses = stats.misses;
|
|
214
|
+
this.hitBytes = stats.hitBytes;
|
|
215
|
+
this.writes = stats.writes;
|
|
216
|
+
this.duplicateWrites = stats.duplicateWrites;
|
|
217
|
+
this.collisions = stats.collisions;
|
|
218
|
+
}
|
|
196
219
|
}
|
|
@@ -67,7 +67,14 @@ function isManifest(m) {
|
|
|
67
67
|
typeof o.onnx.path === "string" &&
|
|
68
68
|
typeof o.onnx.sha256 === "string" &&
|
|
69
69
|
typeof o.tokenizer.path === "string" &&
|
|
70
|
-
typeof o.tokenizer.sha256 === "string"
|
|
70
|
+
typeof o.tokenizer.sha256 === "string" &&
|
|
71
|
+
// ML5-A (VC2B-2): optional headWeights must, when present, be a valid
|
|
72
|
+
// ManifestAssetFile (path basename + sha256 + bytes).
|
|
73
|
+
(o.headWeights === undefined ||
|
|
74
|
+
(!!o.headWeights &&
|
|
75
|
+
typeof o.headWeights.path === "string" &&
|
|
76
|
+
typeof o.headWeights.sha256 === "string" &&
|
|
77
|
+
typeof o.headWeights.bytes === "number")));
|
|
71
78
|
}
|
|
72
79
|
/**
|
|
73
80
|
* Verify the asset manifest + digest + constraints BEFORE allocation.
|
|
@@ -107,6 +114,11 @@ export function verifyEncoderAsset(assetDir, manifest, platform = detectPlatform
|
|
|
107
114
|
if (!isBasename(manifest.onnx.path) || !isBasename(manifest.tokenizer.path)) {
|
|
108
115
|
return { ok: false, code: ENC_FAIL.MANIFEST_INVALID };
|
|
109
116
|
}
|
|
117
|
+
// ML5-A (VC2B-2): a manifest-declared headWeights path must also be a bare
|
|
118
|
+
// basename (no traversal into arbitrary paths off the asset dir).
|
|
119
|
+
if (manifest.headWeights !== undefined && !isBasename(manifest.headWeights.path)) {
|
|
120
|
+
return { ok: false, code: ENC_FAIL.MANIFEST_INVALID };
|
|
121
|
+
}
|
|
110
122
|
const onnxPath = join(assetDir, manifest.onnx.path);
|
|
111
123
|
const onnxDigest = digestFile(onnxPath);
|
|
112
124
|
if (onnxDigest === null)
|
|
@@ -119,6 +131,19 @@ export function verifyEncoderAsset(assetDir, manifest, platform = detectPlatform
|
|
|
119
131
|
return { ok: false, code: ENC_FAIL.ASSET_UNREADABLE };
|
|
120
132
|
if (tokDigest !== manifest.tokenizer.sha256)
|
|
121
133
|
return { ok: false, code: ENC_FAIL.DIGEST_MISMATCH };
|
|
134
|
+
// ML5-A (VC2B-2): verify the manifest-pinned trained-heads sibling when the
|
|
135
|
+
// manifest declares it. Absent declaration -> headWeightsDigest: null and no
|
|
136
|
+
// failure (committed placeholder bundle ships no trained weights).
|
|
137
|
+
let headWeightsDigest = null;
|
|
138
|
+
if (manifest.headWeights !== undefined) {
|
|
139
|
+
const hwPath = join(assetDir, manifest.headWeights.path);
|
|
140
|
+
const hwDigest = digestFile(hwPath);
|
|
141
|
+
if (hwDigest === null)
|
|
142
|
+
return { ok: false, code: ENC_FAIL.ASSET_UNREADABLE };
|
|
143
|
+
if (hwDigest !== manifest.headWeights.sha256)
|
|
144
|
+
return { ok: false, code: ENC_FAIL.DIGEST_MISMATCH };
|
|
145
|
+
headWeightsDigest = hwDigest;
|
|
146
|
+
}
|
|
122
147
|
let embeddedBytes = 0;
|
|
123
148
|
try {
|
|
124
149
|
embeddedBytes = statSync(onnxPath).size + statSync(tokPath).size;
|
|
@@ -126,7 +151,14 @@ export function verifyEncoderAsset(assetDir, manifest, platform = detectPlatform
|
|
|
126
151
|
catch {
|
|
127
152
|
return { ok: false, code: ENC_FAIL.ASSET_UNREADABLE };
|
|
128
153
|
}
|
|
129
|
-
return {
|
|
154
|
+
return {
|
|
155
|
+
ok: true,
|
|
156
|
+
embeddedBytes,
|
|
157
|
+
maxTokens: manifest.maxTokens,
|
|
158
|
+
onnxDigest,
|
|
159
|
+
tokenizerDigest: tokDigest,
|
|
160
|
+
headWeightsDigest,
|
|
161
|
+
};
|
|
130
162
|
}
|
|
131
163
|
/**
|
|
132
164
|
* Read + shape-check a committed ModelManifestV1 from an asset directory.
|
|
@@ -25,11 +25,12 @@
|
|
|
25
25
|
* Pi-agnostic, zero network (PREVENT-PI-004), no `any` (PREVENT-011).
|
|
26
26
|
*/
|
|
27
27
|
import { createEncoderRuntime } from "./runtime.js";
|
|
28
|
-
import { encodeVectorSet } from "./heads.js";
|
|
28
|
+
import { encodeVectorSet, loadHeadProjections, projectHeadFromTrunk, } from "./heads.js";
|
|
29
29
|
import { embedTrigram512, selectTrigramBFallback } from "./trigram.js";
|
|
30
30
|
import { embedLexical, selectLexicalC } from "./lexical.js";
|
|
31
31
|
import { createEncoderHeadsReporter } from "./emit-vc2b.js";
|
|
32
|
-
import {
|
|
32
|
+
import { ML5A_ENABLED } from "../../config/vector-cortex.js";
|
|
33
|
+
import { ENC_FAIL, ENCODER_HEAD_ORDER, } from "./types.js";
|
|
33
34
|
/** Deterministic text derived from an int token sequence so the asset-free
|
|
34
35
|
* fallback producers operate on the same authority the learned path encoded. */
|
|
35
36
|
function textFromTokens(tokens) {
|
|
@@ -92,9 +93,36 @@ export function encodeOrFallback(input, assetDir, options = {}) {
|
|
|
92
93
|
if (!inferred.ok) {
|
|
93
94
|
return fallbackFromLoad({ ok: false, mode: "B", code: inferred.code }, reporter, tokens);
|
|
94
95
|
}
|
|
95
|
-
const vectorSet =
|
|
96
|
+
const vectorSet = produceVectorSet(inferred.semantic, tokens, options, reporter);
|
|
96
97
|
return { ok: true, mode: "A", vectorSet, code: null };
|
|
97
98
|
}
|
|
99
|
+
/**
|
|
100
|
+
* Produce a mode-A `VectorSetV1` from the [1,384] trunk embedding (the
|
|
101
|
+
* `runtime.infer` result). VC2B-2 ML5-A: when real trained heads are loaded
|
|
102
|
+
* (`MEGACOMPACT_ML5_A` on + a `trainedHeadsPath` that loads), the multi-head
|
|
103
|
+
* output is projected through the real trained projection matrices via
|
|
104
|
+
* `projectHeadFromTrunk`. Otherwise (flag-off / absent / unloadable artifact)
|
|
105
|
+
* the deterministic LCG placeholder `encodeVectorSet` serves mode A —
|
|
106
|
+
* byte-identical to the VC2B predecessor. Non-fatal: an unloadable artifact
|
|
107
|
+
* degrades to the placeholder, never a throw.
|
|
108
|
+
*/
|
|
109
|
+
function produceVectorSet(trunkEmbedding, tokens, options, reporter) {
|
|
110
|
+
const table = ML5A_ENABLED() && options.trainedHeadsPath !== undefined
|
|
111
|
+
? loadHeadProjections(options.trainedHeadsPath)
|
|
112
|
+
: null;
|
|
113
|
+
if (table !== null) {
|
|
114
|
+
const heads = ENCODER_HEAD_ORDER.map((h) => projectHeadFromTrunk(h, trunkEmbedding, table));
|
|
115
|
+
reporter.headsEmitted({
|
|
116
|
+
heads: heads.length,
|
|
117
|
+
dims: heads.map((h) => h.dim).join("/"),
|
|
118
|
+
normalized: true,
|
|
119
|
+
tokens: tokens.length,
|
|
120
|
+
});
|
|
121
|
+
return { schema: "vector-set-v1", inputTokens: [...tokens], heads, normalized: true };
|
|
122
|
+
}
|
|
123
|
+
// ML5-A placeholder fallback (byte-identical predecessor).
|
|
124
|
+
return encodeVectorSet(tokens, { reporter, seed: options.seed });
|
|
125
|
+
}
|
|
98
126
|
/**
|
|
99
127
|
* Catch a (real or forced) A load failure (ok === false only) and select the
|
|
100
128
|
* B/C fallback that emits `vector_cortex_encoder_fallback_selected` from the
|
|
@@ -45,48 +45,80 @@ function baseCache(stableFields) {
|
|
|
45
45
|
};
|
|
46
46
|
}
|
|
47
47
|
/** Build a contract-profile shape pinned as a conformance fixture too. */
|
|
48
|
-
function profile(id, version, excludedJsonPointers) {
|
|
48
|
+
function profile(id, version, excludedJsonPointers, economics) {
|
|
49
49
|
return {
|
|
50
50
|
schema: "provider-profile-v1",
|
|
51
51
|
id,
|
|
52
52
|
version,
|
|
53
53
|
hashMode: "entire-canonical-request",
|
|
54
54
|
excludedJsonPointers,
|
|
55
|
+
economics,
|
|
55
56
|
};
|
|
56
57
|
}
|
|
58
|
+
/**
|
|
59
|
+
* Build integer micro-unit economics for a base profile (VC7B). A cache WRITE
|
|
60
|
+
* costs more than an uncached token, a cache READ costs less — the standard
|
|
61
|
+
* provider-prompt-cache shape. `exclusionFixtureId` mirrors the profile's own
|
|
62
|
+
* exclusion fixture (or null when the profile has none to prove).
|
|
63
|
+
*/
|
|
64
|
+
function econ(id, version, exclusionFixtureId, values) {
|
|
65
|
+
return {
|
|
66
|
+
schema: "provider-economics-v1",
|
|
67
|
+
profileId: id,
|
|
68
|
+
profileVersion: version,
|
|
69
|
+
basePrice: values.basePrice,
|
|
70
|
+
readPrice: values.readPrice,
|
|
71
|
+
writePrice: values.writePrice,
|
|
72
|
+
ttlMs: values.ttlMs,
|
|
73
|
+
minPrefix: values.minPrefix,
|
|
74
|
+
exclusionFixtureId,
|
|
75
|
+
};
|
|
76
|
+
}
|
|
77
|
+
/** Representative integer micro-unit economics for the Anthropic opus base tier. */
|
|
78
|
+
const OPUS_ECON = econ("anthropic-claude-opus", "v1", null, { basePrice: 15, readPrice: 2, writePrice: 19, ttlMs: 300_000, minPrefix: 1024 });
|
|
79
|
+
/** Representative integer micro-unit economics for the Anthropic sonnet base tier. */
|
|
80
|
+
const SONNET_ECON = econ("anthropic-claude-sonnet", "v1", null, { basePrice: 3, readPrice: 0, writePrice: 4, ttlMs: 300_000, minPrefix: 1024 });
|
|
81
|
+
/** Representative integer micro-unit economics for the OpenAI gpt base tier. */
|
|
82
|
+
const GPT_ECON = econ("openai-gpt", "v1", null, { basePrice: 5, readPrice: 1, writePrice: 6, ttlMs: 300_000, minPrefix: 1024 });
|
|
83
|
+
/** The gemini profile's versioned, fixture-proven exclusion. */
|
|
84
|
+
const GEMINI_EXCLUSIONS = [
|
|
85
|
+
{
|
|
86
|
+
pointer: "/requestId",
|
|
87
|
+
fixtureId: "PRO-EXCLUDE-010",
|
|
88
|
+
proofDigest: "sha256:excluded-request-id-proof",
|
|
89
|
+
},
|
|
90
|
+
];
|
|
91
|
+
/** Representative integer micro-unit economics for the gemini base tier. */
|
|
92
|
+
const GEMINI_ECON = econ("google-gemini", "v1", "PRO-EXCLUDE-010", { basePrice: 3, readPrice: 1, writePrice: 4, ttlMs: 300_000, minPrefix: 1024 });
|
|
57
93
|
/**
|
|
58
94
|
* The fixture-backed base profiles. Each entry is the REAL bundle the renderer
|
|
59
95
|
* resolves; the parallel conformance fixtures prove the cache-identity behavior.
|
|
60
96
|
*/
|
|
61
97
|
const BASE_PROFILES = [
|
|
62
98
|
{
|
|
63
|
-
profile: profile("anthropic-claude-opus", "v1", []),
|
|
99
|
+
profile: profile("anthropic-claude-opus", "v1", [], OPUS_ECON),
|
|
64
100
|
role: BASE_ROLE,
|
|
65
101
|
tool: BASE_TOOL,
|
|
66
102
|
cache: baseCache(["systemPromptPrepend", "tools", "nodes"]),
|
|
67
103
|
},
|
|
68
104
|
{
|
|
69
|
-
profile: profile("anthropic-claude-sonnet", "v1", []),
|
|
105
|
+
profile: profile("anthropic-claude-sonnet", "v1", [], SONNET_ECON),
|
|
70
106
|
role: BASE_ROLE,
|
|
71
107
|
tool: BASE_TOOL,
|
|
72
108
|
cache: baseCache(["systemPromptPrepend", "tools", "nodes"]),
|
|
73
109
|
},
|
|
74
110
|
{
|
|
75
|
-
profile: profile("openai-gpt", "v1", []),
|
|
111
|
+
profile: profile("openai-gpt", "v1", [], GPT_ECON),
|
|
76
112
|
role: BASE_ROLE,
|
|
77
113
|
tool: BASE_TOOL,
|
|
78
114
|
cache: baseCache(["systemPromptPrepend", "tools", "nodes"]),
|
|
79
115
|
},
|
|
80
116
|
{
|
|
81
117
|
// A profile that proves a fixture-excluded pointer: a provider whose
|
|
82
|
-
// request-id header cannot affect cache identity. Excluded + versioned
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
fixtureId: "PRO-EXCLUDE-010",
|
|
87
|
-
proofDigest: "sha256:excluded-request-id-proof",
|
|
88
|
-
},
|
|
89
|
-
]),
|
|
118
|
+
// request-id header cannot affect cache identity. Excluded + versioned, and
|
|
119
|
+
// the exclusion fixture id is carried into economics so the proof is
|
|
120
|
+
// honored (an unproven exclusion would fail economics validation).
|
|
121
|
+
profile: profile("google-gemini", "v1", GEMINI_EXCLUSIONS, GEMINI_ECON),
|
|
90
122
|
role: BASE_ROLE,
|
|
91
123
|
tool: BASE_TOOL,
|
|
92
124
|
cache: baseCache(["systemPromptPrepend", "tools", "nodes"]),
|
|
@@ -14,9 +14,12 @@
|
|
|
14
14
|
* all-open, byte-identical to ENC-0f-era for flag-off). `computeSetupCortexBlockers`
|
|
15
15
|
* is a PURE function over (platform, ENC-0f QualificationV1 record, asset-manifest
|
|
16
16
|
* head-count) that returns the live blocker list: HG-1 closes on a five-head
|
|
17
|
-
* manifest (ENC-0c), HG-5 reflects the measured qualification verdict, HG-4
|
|
18
|
-
*
|
|
19
|
-
*
|
|
17
|
+
* manifest (ENC-0c), HG-5 reflects the measured qualification verdict, HG-4 is
|
|
18
|
+
* superseded (upstream arm64-only darwin binary gap, ENC-0e demotion surface),
|
|
19
|
+
* HG-6 is superseded (4-thread mandate = runtime p95 gate), HG-7 closes (frozen
|
|
20
|
+
* model card / dataset manifest / calibration), HG-3 closes when native
|
|
21
|
+
* onnxruntime-node is installed (ENC-2a/2b). `setupCortexActionBlockers`
|
|
22
|
+
* re-derives VC9B
|
|
20
23
|
* action gating from the live computed blockers (intersects each action's
|
|
21
24
|
* static candidate gate ids with the currently-open blocker ids).
|
|
22
25
|
*
|
|
@@ -26,6 +29,7 @@
|
|
|
26
29
|
* never magic numbers in the computed path.
|
|
27
30
|
*/
|
|
28
31
|
import { ENCODER_HEAD_ORDER, ENCODER_LATENCY_P95_MS, ENCODER_RSS_BUDGET_BYTES, } from "./encoder/types.js";
|
|
32
|
+
import { INSTALL_BUDGET_DEFAULT_MIB } from "./encoder/decision.js";
|
|
29
33
|
const MIB = 1024 * 1024;
|
|
30
34
|
/**
|
|
31
35
|
* Marker threshold-failure emitted by the status route when NO QualificationV1
|
|
@@ -100,14 +104,20 @@ export function setupCortexBlocker(id) {
|
|
|
100
104
|
* - HG-1 → `"closed"` when the asset manifest declares all five projection
|
|
101
105
|
* heads (`headCount === ENCODER_HEAD_ORDER.length`); otherwise stays open.
|
|
102
106
|
* - HG-3 → unchanged (genuinely open — onnxruntime-node budget unresolved).
|
|
103
|
-
* - HG-4 →
|
|
104
|
-
*
|
|
107
|
+
* - HG-4 → `"superseded"` (documented upstream platform gap — onnxruntime-node
|
|
108
|
+
* is arm64-only for darwin; ENC-0e ships the demotion surface, no code fix
|
|
109
|
+
* is possible).
|
|
105
110
|
* - HG-5 → derived from the qualification record: an empty record is
|
|
106
111
|
* `"superseded"` (no measurement on this device); a `failed` verdict closes
|
|
107
112
|
* it with the measured p95/RSS wording; a `qualified` verdict closes it with
|
|
108
113
|
* "measured" wording. Severity stays `"medium"` from the base row.
|
|
114
|
+
* - HG-6 → `"superseded"` (the 4-thread mandate is a runtime p95 gate enforced
|
|
115
|
+
* by the ENC-0f qualification bench — a platform failing the p95 threshold
|
|
116
|
+
* auto-demotes to mode B; no separate code surface needed).
|
|
117
|
+
* - HG-7 → `"closed"` (model card, dataset manifest, and VC2C calibration
|
|
118
|
+
* thresholds are all committed and frozen).
|
|
109
119
|
* `platform` is carried for contract symmetry with Worker B's route input; the
|
|
110
|
-
* HG rules here do not branch on it (
|
|
120
|
+
* HG rules here do not branch on it (the closures are unconditional).
|
|
111
121
|
*/
|
|
112
122
|
export function computeSetupCortexBlockers(input) {
|
|
113
123
|
const { qualification, headCount } = input;
|
|
@@ -117,10 +127,36 @@ export function computeSetupCortexBlockers(input) {
|
|
|
117
127
|
return headCount === ENCODER_HEAD_ORDER.length
|
|
118
128
|
? { ...base, status: "closed" }
|
|
119
129
|
: base;
|
|
130
|
+
case "HG-3":
|
|
131
|
+
// HG-3 is the install-budget gate: closes when native onnxruntime-node is
|
|
132
|
+
// installed (the ~101 MiB tarball fits within the 300 MiB default budget).
|
|
133
|
+
// The runtime p95/RSS qualification is HG-5's domain — this gate only asks
|
|
134
|
+
// "is the binding installed and within budget?".
|
|
135
|
+
if (input.nativeOrtInstalledVersion != null) {
|
|
136
|
+
return {
|
|
137
|
+
...base,
|
|
138
|
+
status: "closed",
|
|
139
|
+
resolution: `Native onnxruntime-node ${input.nativeOrtInstalledVersion} installed (~101 MiB, within the ${INSTALL_BUDGET_DEFAULT_MIB} MiB budget). Runtime qualification is HG-5.`,
|
|
140
|
+
};
|
|
141
|
+
}
|
|
142
|
+
return base;
|
|
120
143
|
case "HG-4":
|
|
121
144
|
return {
|
|
122
145
|
...base,
|
|
123
|
-
|
|
146
|
+
status: "superseded",
|
|
147
|
+
resolution: "Upstream onnxruntime-node ships arm64-only for darwin. ENC-0e ships the demotion surface: darwin-x64 users use the WASM path (mode B) or lexical fallback (mode C). No code fix is possible — the binary does not exist upstream.",
|
|
148
|
+
};
|
|
149
|
+
case "HG-6":
|
|
150
|
+
return {
|
|
151
|
+
...base,
|
|
152
|
+
status: "superseded",
|
|
153
|
+
resolution: "The 4-thread mandate is a runtime p95 gate enforced by the qualification bench (ENC-0f gate-qualify.mjs). A platform that fails the p95 latency threshold (40ms) is automatically demoted to mode B — no separate code surface needed. Low-core platforms are handled by the same qualification gate.",
|
|
154
|
+
};
|
|
155
|
+
case "HG-7":
|
|
156
|
+
return {
|
|
157
|
+
...base,
|
|
158
|
+
status: "closed",
|
|
159
|
+
resolution: "Model card (training/vector-cortex/model-card.json), dataset manifest (training/vector-cortex/dataset-manifest.json), and VC2C calibration thresholds (EVALUATION_THRESHOLDS in types-vc2c.ts) are all committed and frozen.",
|
|
124
160
|
};
|
|
125
161
|
case "HG-5":
|
|
126
162
|
if (qualification === null) {
|
|
@@ -25,7 +25,7 @@ import { readFileSync, statSync } from "node:fs";
|
|
|
25
25
|
import { join, dirname } from "node:path";
|
|
26
26
|
import { fileURLToPath } from "node:url";
|
|
27
27
|
import type { RouteContext } from "./routes-core.js";
|
|
28
|
-
import { VC9A_ENABLED, ENC_0E_ENABLED, ENC_0F_ENABLED, ENC_0G_ENABLED } from "../../src/config.js";
|
|
28
|
+
import { VC9A_ENABLED, ENC_0E_ENABLED, ENC_0F_ENABLED, ENC_0G_ENABLED, ENC_2A_ENABLED } from "../../src/config.js";
|
|
29
29
|
import { readEncoderManifest, verifyEncoderAsset, detectPlatform } from "../../src/vector-cortex/encoder/asset.js";
|
|
30
30
|
import type { QualificationV1 } from "../../src/vector-cortex/encoder/qualify.js";
|
|
31
31
|
import { selectRuntimeBackend } from "../../src/vector-cortex/encoder/runtime-select.js";
|
|
@@ -37,6 +37,7 @@ import {
|
|
|
37
37
|
encoderStateDir,
|
|
38
38
|
QUALIFICATION_RECORD_UNAVAILABLE,
|
|
39
39
|
} from "./qualification-record.js";
|
|
40
|
+
import { readEnc2aGuide } from "./routes-setup-enc2a.js";
|
|
40
41
|
import type {
|
|
41
42
|
SetupCortexStatusResponse,
|
|
42
43
|
BlockerV1,
|
|
@@ -214,12 +215,18 @@ export function handleSetupCortexStatus(
|
|
|
214
215
|
|
|
215
216
|
const facts = enabled ? setupCortexFacts(record, recordGate) : null;
|
|
216
217
|
|
|
218
|
+
// ENC-2a native ORT detection: pass the installed version + retest verdict to
|
|
219
|
+
// the blockers compute so HG-3 can close when native is installed + qualified.
|
|
220
|
+
const enc2a = enabled && ENC_2A_ENABLED() ? readEnc2aGuide(encoderStateDir()) : null;
|
|
221
|
+
const nativeOrtInstalledVersion = enc2a?.installedVersion ?? null;
|
|
222
|
+
|
|
217
223
|
const blocks: BlockerV1[] = enabled
|
|
218
224
|
? enc0g
|
|
219
225
|
? [...computeSetupCortexBlockers({
|
|
220
226
|
platform: detectPlatform(),
|
|
221
227
|
qualification: record,
|
|
222
228
|
headCount: facts ? facts.headCount : null,
|
|
229
|
+
nativeOrtInstalledVersion,
|
|
223
230
|
})]
|
|
224
231
|
: [...SETUP_CORTEX_BLOCKERS]
|
|
225
232
|
: [];
|
|
@@ -28,21 +28,21 @@ import type { IncomingMessage, ServerResponse } from "node:http";
|
|
|
28
28
|
import type { RouteContext } from "./routes-core.js";
|
|
29
29
|
import { VC7A_ENABLED } from "../../src/config.js";
|
|
30
30
|
import { sendJson } from "./routes-vector-cortex-shared.js";
|
|
31
|
-
import { countVcEvents, vcCount } from "./vc-event-counts.js";
|
|
32
31
|
import { deriveVcStatus } from "./vc-status.js";
|
|
32
|
+
import { readLivewireSnapshot } from "../../src/vector-cortex/livewire/livewire-registry.js";
|
|
33
33
|
import type { VectorCortexCrystalsView } from "./api-contracts/vector-cortex-cache.js";
|
|
34
34
|
|
|
35
|
-
//
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
"vector_cortex_crystal_collision",
|
|
39
|
-
] as const;
|
|
35
|
+
// The flag-off deferred reason, kept byte-identical to the pre-LIVEWIRE
|
|
36
|
+
// predecessor (VC7A: `crystal_store_not_instantiated_v0_20_23`).
|
|
37
|
+
const DEFERRED_REASON = "crystal_store_not_instantiated_v0_20_23";
|
|
40
38
|
|
|
41
39
|
/**
|
|
42
40
|
* Reader-only GET /api/vector-cortex/cache-crystals (VC7A).
|
|
43
41
|
*
|
|
44
|
-
* Counts, byte volumes, and CRY_* codes only
|
|
45
|
-
*
|
|
42
|
+
* Counts, byte volumes, and CRY_* codes only. With the flag ON it surfaces the
|
|
43
|
+
* LIVEWIRE `CrystalStore` aggregate (live reads/writes/collisions accumulated at
|
|
44
|
+
* runtime); with the flag OFF it returns the byte-identical legacy deferred view
|
|
45
|
+
* (mode C, deferredReason present) so flag-off parity holds.
|
|
46
46
|
*/
|
|
47
47
|
export function handleVectorCortexCrystals(
|
|
48
48
|
req: IncomingMessage,
|
|
@@ -58,31 +58,47 @@ export function handleVectorCortexCrystals(
|
|
|
58
58
|
}
|
|
59
59
|
|
|
60
60
|
const enabled = VC7A_ENABLED();
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
61
|
+
if (!enabled) {
|
|
62
|
+
// Flag-off parity: byte-identical to the predecessor (mode C + deferred).
|
|
63
|
+
const body: VectorCortexCrystalsView = {
|
|
64
|
+
enabled: false,
|
|
65
|
+
mode: "C",
|
|
66
|
+
crystalCount: 0,
|
|
67
|
+
totalBytes: 0,
|
|
68
|
+
hits: 0,
|
|
69
|
+
misses: 0,
|
|
70
|
+
hitBytes: 0,
|
|
71
|
+
writes: 0,
|
|
72
|
+
duplicateWrites: 0,
|
|
73
|
+
collisions: 0,
|
|
74
|
+
lastFailure: null,
|
|
75
|
+
updatedAt: new Date().toISOString(),
|
|
76
|
+
deferredReason: DEFERRED_REASON,
|
|
77
|
+
status: deriveVcStatus({ enabled: false, hasData: false }),
|
|
78
|
+
};
|
|
79
|
+
sendJson(res, 200, body);
|
|
80
|
+
return true;
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
const snap = readLivewireSnapshot(ctx.stateDir);
|
|
84
|
+
const crystal = snap.crystals;
|
|
85
|
+
const hasData = crystal.crystalCount > 0;
|
|
67
86
|
const body: VectorCortexCrystalsView = {
|
|
68
|
-
enabled,
|
|
69
|
-
mode,
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
87
|
+
enabled: true,
|
|
88
|
+
// Surface the store's honest triad mode (B until a hit, A after, C when the
|
|
89
|
+
// store was set unavailable) rather than a hardcoded A.
|
|
90
|
+
mode: crystal.mode,
|
|
91
|
+
crystalCount: crystal.crystalCount,
|
|
92
|
+
totalBytes: crystal.totalBytes,
|
|
93
|
+
hits: crystal.hits,
|
|
94
|
+
misses: crystal.misses,
|
|
95
|
+
hitBytes: crystal.hitBytes,
|
|
96
|
+
writes: crystal.writes,
|
|
97
|
+
duplicateWrites: crystal.duplicateWrites,
|
|
98
|
+
collisions: crystal.collisions,
|
|
78
99
|
lastFailure: null,
|
|
79
100
|
updatedAt: new Date().toISOString(),
|
|
80
|
-
|
|
81
|
-
status: deriveVcStatus({
|
|
82
|
-
enabled,
|
|
83
|
-
deferredReason: "crystal_store_not_instantiated_v0_20_23",
|
|
84
|
-
hasData: vcCount(counts, "vector_cortex_crystal_written") > 0,
|
|
85
|
-
}),
|
|
101
|
+
status: deriveVcStatus({ enabled: true, hasData }),
|
|
86
102
|
};
|
|
87
103
|
sendJson(res, 200, body);
|
|
88
104
|
return true;
|
|
@@ -30,18 +30,21 @@ import type { IncomingMessage, ServerResponse } from "node:http";
|
|
|
30
30
|
import type { RouteContext } from "./routes-core.js";
|
|
31
31
|
import { VC7C_ENABLED } from "../../src/config.js";
|
|
32
32
|
import { sendJson } from "./routes-vector-cortex-shared.js";
|
|
33
|
-
import { countVcEvents, vcCount } from "./vc-event-counts.js";
|
|
34
33
|
import { deriveVcStatus } from "./vc-status.js";
|
|
34
|
+
import { readLivewireSnapshot } from "../../src/vector-cortex/livewire/livewire-registry.js";
|
|
35
35
|
import type { VectorCortexDiagnosticsView } from "./api-contracts/vector-cortex-diagnostics.js";
|
|
36
36
|
|
|
37
|
-
//
|
|
38
|
-
|
|
37
|
+
// The flag-off deferred reason, kept byte-identical to the pre-LIVEWIRE
|
|
38
|
+
// predecessor (VC7C: `cache_classifier_not_wired_v0_20_23`).
|
|
39
|
+
const DEFERRED_REASON = "cache_classifier_not_wired_v0_20_23";
|
|
39
40
|
|
|
40
41
|
/**
|
|
41
42
|
* Reader-only GET /api/vector-cortex/cache-diagnostics (VC7C).
|
|
42
43
|
*
|
|
43
|
-
* Per-miss-class counts, breaker state, and CACHE
|
|
44
|
-
*
|
|
44
|
+
* Per-miss-class counts, serveBlocked, breaker state, and CACHE/M5 codes only.
|
|
45
|
+
* With the flag ON it surfaces the LIVEWIRE classifier/breaker tallies
|
|
46
|
+
* accumulated at runtime; with the flag OFF it returns the byte-identical legacy
|
|
47
|
+
* deferred view (mode C, deferredReason present).
|
|
45
48
|
*/
|
|
46
49
|
export function handleVectorCortexDiagnostics(
|
|
47
50
|
req: IncomingMessage,
|
|
@@ -57,32 +60,52 @@ export function handleVectorCortexDiagnostics(
|
|
|
57
60
|
}
|
|
58
61
|
|
|
59
62
|
const enabled = VC7C_ENABLED();
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
63
|
+
if (!enabled) {
|
|
64
|
+
// Flag-off parity: byte-identical to the predecessor (mode C + deferred).
|
|
65
|
+
const body: VectorCortexDiagnosticsView = {
|
|
66
|
+
enabled: false,
|
|
67
|
+
mode: "C",
|
|
68
|
+
profileMisses: 0,
|
|
69
|
+
rangeMisses: 0,
|
|
70
|
+
dependencyMisses: 0,
|
|
71
|
+
requestMisses: 0,
|
|
72
|
+
generationMisses: 0,
|
|
73
|
+
unknownMisses: 0,
|
|
74
|
+
serveBlocked: 0,
|
|
75
|
+
breakerState: "closed",
|
|
76
|
+
lastFailure: null,
|
|
77
|
+
updatedAt: new Date().toISOString(),
|
|
78
|
+
deferredReason: DEFERRED_REASON,
|
|
79
|
+
status: deriveVcStatus({ enabled: false, hasData: false }),
|
|
80
|
+
};
|
|
81
|
+
sendJson(res, 200, body);
|
|
82
|
+
return true;
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
const diag = readLivewireSnapshot(ctx.stateDir).diagnostics;
|
|
86
|
+
const hasData =
|
|
87
|
+
diag.profileMisses +
|
|
88
|
+
diag.rangeMisses +
|
|
89
|
+
diag.dependencyMisses +
|
|
90
|
+
diag.requestMisses +
|
|
91
|
+
diag.generationMisses +
|
|
92
|
+
diag.unknownMisses +
|
|
93
|
+
diag.serveBlocked >
|
|
94
|
+
0;
|
|
67
95
|
const body: VectorCortexDiagnosticsView = {
|
|
68
|
-
enabled,
|
|
69
|
-
mode,
|
|
70
|
-
profileMisses:
|
|
71
|
-
rangeMisses:
|
|
72
|
-
dependencyMisses:
|
|
73
|
-
requestMisses:
|
|
74
|
-
generationMisses:
|
|
75
|
-
unknownMisses:
|
|
76
|
-
serveBlocked:
|
|
77
|
-
breakerState:
|
|
78
|
-
lastFailure:
|
|
96
|
+
enabled: true,
|
|
97
|
+
mode: "A",
|
|
98
|
+
profileMisses: diag.profileMisses,
|
|
99
|
+
rangeMisses: diag.rangeMisses,
|
|
100
|
+
dependencyMisses: diag.dependencyMisses,
|
|
101
|
+
requestMisses: diag.requestMisses,
|
|
102
|
+
generationMisses: diag.generationMisses,
|
|
103
|
+
unknownMisses: diag.unknownMisses,
|
|
104
|
+
serveBlocked: diag.serveBlocked,
|
|
105
|
+
breakerState: diag.breakerState,
|
|
106
|
+
lastFailure: diag.lastFailure,
|
|
79
107
|
updatedAt: new Date().toISOString(),
|
|
80
|
-
|
|
81
|
-
status: deriveVcStatus({
|
|
82
|
-
enabled,
|
|
83
|
-
deferredReason: "cache_classifier_not_wired_v0_20_23",
|
|
84
|
-
hasData: vcCount(counts, "vector_cortex_cache_serve_blocked") > 0,
|
|
85
|
-
}),
|
|
108
|
+
status: deriveVcStatus({ enabled: true, hasData }),
|
|
86
109
|
};
|
|
87
110
|
sendJson(res, 200, body);
|
|
88
111
|
return true;
|