pi-mega-compact 0.20.47 → 0.20.49

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (32) hide show
  1. package/dist/config/vector-cortex-enc0f.js +36 -0
  2. package/dist/config/vector-cortex-enc0g.js +37 -0
  3. package/dist/config/vector-cortex.js +2 -0
  4. package/dist/config.js +1 -1
  5. package/dist/extensions/dashboard-server/qualification-record.js +71 -0
  6. package/dist/extensions/dashboard-server/routes-rag-settings-vector-cortex.js +2 -0
  7. package/dist/extensions/dashboard-server/routes-setup-cortex-actions.js +49 -3
  8. package/dist/extensions/dashboard-server/routes-setup-cortex.js +65 -16
  9. package/dist/extensions/dashboard-server/setup-cortex-actions.js +21 -4
  10. package/dist/extensions/dashboard-server/setup-cortex-blockers.js +3 -69
  11. package/dist/src/config/vector-cortex-enc0f.js +36 -0
  12. package/dist/src/config/vector-cortex-enc0g.js +37 -0
  13. package/dist/src/config/vector-cortex.js +2 -0
  14. package/dist/src/config.js +1 -1
  15. package/dist/src/vector-cortex/encoder/qualify.js +50 -0
  16. package/dist/src/vector-cortex/setup-cortex-blockers-compute.js +160 -0
  17. package/dist/vector-cortex/encoder/qualify.js +50 -0
  18. package/dist/vector-cortex/setup-cortex-blockers-compute.js +160 -0
  19. package/extensions/dashboard-server/api-contracts/setup-cortex.ts +6 -2
  20. package/extensions/dashboard-server/qualification-record.ts +70 -0
  21. package/extensions/dashboard-server/routes-rag-settings-vector-cortex.ts +12 -0
  22. package/extensions/dashboard-server/routes-setup-cortex-actions.ts +50 -3
  23. package/extensions/dashboard-server/routes-setup-cortex.ts +92 -16
  24. package/extensions/dashboard-server/setup-cortex-actions.ts +23 -4
  25. package/extensions/dashboard-server/setup-cortex-blockers.ts +3 -97
  26. package/package.json +1 -1
  27. package/src/config/vector-cortex-enc0f.ts +38 -0
  28. package/src/config/vector-cortex-enc0g.ts +39 -0
  29. package/src/config/vector-cortex.ts +2 -0
  30. package/src/config.ts +2 -0
  31. package/src/vector-cortex/encoder/qualify.ts +83 -0
  32. package/src/vector-cortex/setup-cortex-blockers-compute.ts +216 -0
@@ -25,12 +25,18 @@ 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 } from "../../src/config.js";
28
+ import { VC9A_ENABLED, ENC_0E_ENABLED, ENC_0F_ENABLED, ENC_0G_ENABLED } from "../../src/config.js";
29
29
  import { readEncoderManifest, verifyEncoderAsset, detectPlatform } from "../../src/vector-cortex/encoder/asset.js";
30
+ import type { QualificationV1 } from "../../src/vector-cortex/encoder/qualify.js";
30
31
  import { selectRuntimeBackend } from "../../src/vector-cortex/encoder/runtime-select.js";
31
32
  import { sendJson } from "./routes-vector-cortex-shared.js";
32
33
  import { deriveVcStatus } from "./vc-status.js";
33
- import { SETUP_CORTEX_BLOCKERS } from "./setup-cortex-blockers.js";
34
+ import { SETUP_CORTEX_BLOCKERS, computeSetupCortexBlockers } from "./setup-cortex-blockers.js";
35
+ import {
36
+ readQualificationRecord,
37
+ encoderStateDir,
38
+ QUALIFICATION_RECORD_UNAVAILABLE,
39
+ } from "./qualification-record.js";
34
40
  import type {
35
41
  SetupCortexStatusResponse,
36
42
  BlockerV1,
@@ -62,6 +68,8 @@ interface SetupCortexFacts {
62
68
  assetDigestPrefix: string | null;
63
69
  verdict: "qualified" | "demoted" | "unavailable";
64
70
  thresholdFailures: string[];
71
+ /** Number of projection heads the verified manifest declares, or null. */
72
+ headCount: number | null;
65
73
  }
66
74
 
67
75
  interface SetupCortexFactCache {
@@ -72,7 +80,13 @@ interface SetupCortexFactCache {
72
80
  let factCache: SetupCortexFactCache | null = null;
73
81
 
74
82
  /** Stable cache key: manifest bytes + (size,mtime) of the asset files + platform. */
75
- function factCacheKey(dir: string, manifestPath: string): string | null {
83
+ function factCacheKey(
84
+ dir: string,
85
+ manifestPath: string,
86
+ stateDir: string,
87
+ record: QualificationV1 | null,
88
+ recordGate: boolean,
89
+ ): string | null {
76
90
  const platform = detectPlatform();
77
91
  if (!platform) return null;
78
92
  const parts: string[] = [platform];
@@ -86,16 +100,56 @@ function factCacheKey(dir: string, manifestPath: string): string | null {
86
100
  } catch {
87
101
  return null;
88
102
  }
103
+ // ENC-0g: fold the qualification-record gate + (mtime, content sha) into the
104
+ // key so a re-run gate invalidates memoized facts (no stale verdict served).
105
+ try {
106
+ const s = statSync(join(stateDir, "encoder-qualification.json"));
107
+ parts.push(`g:${recordGate ? "on" : "off"}`, `q:${s.size}:${s.mtimeMs}`);
108
+ parts.push(createHash("sha256").update(JSON.stringify(record)).digest("hex"));
109
+ } catch {
110
+ parts.push(`g:${recordGate ? "on" : "off"}`, "q:absent");
111
+ }
89
112
  return parts.join("|");
90
113
  }
91
114
 
92
- function computeSetupCortexFacts(dir: string): SetupCortexFacts | null {
115
+ function applyQualificationOverride(
116
+ base: SetupCortexFacts,
117
+ record: QualificationV1 | null,
118
+ recordGate: boolean,
119
+ ): SetupCortexFacts {
120
+ // Flag-off (recordGate false): byte-identical verify-derived facts.
121
+ if (!recordGate) return base;
122
+ if (record !== null) {
123
+ // The ENC-0f QualificationV1 failure maps onto the contract "demoted": a
124
+ // structurally-valid asset whose real-asset gate measured failure is honest
125
+ // as demoted, NOT qualified. mode stays verify-derived (A).
126
+ return {
127
+ ...base,
128
+ verdict: record.verdict === "qualified" ? "qualified" : "demoted",
129
+ thresholdFailures: [...record.reasons],
130
+ };
131
+ }
132
+ // No record + gate on: keep the verify verdict but surface the missing-record
133
+ // sentinel (never a fabricated pass, never a bare silent fallback).
134
+ return {
135
+ ...base,
136
+ thresholdFailures: [...base.thresholdFailures, QUALIFICATION_RECORD_UNAVAILABLE],
137
+ };
138
+ }
139
+
140
+ function computeSetupCortexFacts(
141
+ dir: string,
142
+ stateDir: string,
143
+ record: QualificationV1 | null,
144
+ recordGate: boolean,
145
+ ): SetupCortexFacts | null {
93
146
  const manifest = readEncoderManifest(dir);
94
147
  if (manifest === null) {
95
- return { mode: "C", assetDigestPrefix: null, verdict: "unavailable", thresholdFailures: [] };
148
+ return { mode: "C", assetDigestPrefix: null, verdict: "unavailable", thresholdFailures: [], headCount: null };
96
149
  }
150
+ const headCount = Object.keys(manifest.heads).length;
97
151
  const manifestPath = join(dir, "manifest.json");
98
- const key = factCacheKey(dir, manifestPath);
152
+ const key = factCacheKey(dir, manifestPath, stateDir, record, recordGate);
99
153
  if (key === null) return null;
100
154
  if (factCache !== null && factCache.key === key) return factCache.facts;
101
155
  let digest: string;
@@ -103,26 +157,31 @@ function computeSetupCortexFacts(dir: string): SetupCortexFacts | null {
103
157
  // guardrails-allow PREVENT-PI-004: local manifest filesystem read (loopback)
104
158
  digest = createHash("sha256").update(readFileSync(manifestPath)).digest("hex");
105
159
  } catch {
106
- const facts: SetupCortexFacts = { mode: "B", assetDigestPrefix: null, verdict: "demoted", thresholdFailures: ["ENC_ASSET_UNREADABLE"] };
160
+ const base: SetupCortexFacts = { mode: "B", assetDigestPrefix: null, verdict: "demoted", thresholdFailures: ["ENC_ASSET_UNREADABLE"], headCount };
161
+ const facts = applyQualificationOverride(base, record, recordGate);
107
162
  factCache = { key, facts };
108
163
  return facts;
109
164
  }
110
165
  const verify = verifyEncoderAsset(dir, manifest, detectPlatform());
111
166
  const prefix = digest.slice(0, 12);
112
- const facts: SetupCortexFacts = verify.ok
113
- ? { mode: "A", assetDigestPrefix: prefix, verdict: "qualified", thresholdFailures: [] }
114
- : { mode: "B", assetDigestPrefix: prefix, verdict: "demoted", thresholdFailures: [verify.code] };
167
+ const base: SetupCortexFacts = verify.ok
168
+ ? { mode: "A", assetDigestPrefix: prefix, verdict: "qualified", thresholdFailures: [], headCount }
169
+ : { mode: "B", assetDigestPrefix: prefix, verdict: "demoted", thresholdFailures: [verify.code], headCount };
170
+ const facts = applyQualificationOverride(base, record, recordGate);
115
171
  factCache = { key, facts };
116
172
  return facts;
117
173
  }
118
174
 
119
- function setupCortexFacts(): SetupCortexFacts {
175
+ function setupCortexFacts(
176
+ record: QualificationV1 | null,
177
+ recordGate: boolean,
178
+ ): SetupCortexFacts {
120
179
  const dir = encoderAssetDir();
121
180
  if (dir === null) {
122
- return { mode: "C", assetDigestPrefix: null, verdict: "unavailable", thresholdFailures: [] };
181
+ return { mode: "C", assetDigestPrefix: null, verdict: "unavailable", thresholdFailures: [], headCount: null };
123
182
  }
124
- const facts = computeSetupCortexFacts(dir);
125
- return facts ?? { mode: "C", assetDigestPrefix: null, verdict: "unavailable", thresholdFailures: [] };
183
+ const facts = computeSetupCortexFacts(dir, encoderStateDir(), record, recordGate);
184
+ return facts ?? { mode: "C", assetDigestPrefix: null, verdict: "unavailable", thresholdFailures: [], headCount: null };
126
185
  }
127
186
 
128
187
  /**
@@ -145,8 +204,25 @@ export function handleSetupCortexStatus(
145
204
  }
146
205
 
147
206
  const enabled = VC9A_ENABLED();
148
- const facts = enabled ? setupCortexFacts() : null;
149
- const blocks: BlockerV1[] = enabled ? [...SETUP_CORTEX_BLOCKERS] : [];
207
+
208
+ // ENC-0g: when both gates are ON, read the QualificationV1 record and let its
209
+ // verdict override the structural verify for the `qualification` field. When
210
+ // ENC_0G is OFF, nothing below reads the record (byte-identical to ENC-0f-era).
211
+ const enc0g = enabled && ENC_0G_ENABLED();
212
+ const recordGate = enc0g && ENC_0F_ENABLED();
213
+ const record = recordGate ? readQualificationRecord(encoderStateDir()) : null;
214
+
215
+ const facts = enabled ? setupCortexFacts(record, recordGate) : null;
216
+
217
+ const blocks: BlockerV1[] = enabled
218
+ ? enc0g
219
+ ? [...computeSetupCortexBlockers({
220
+ platform: detectPlatform(),
221
+ qualification: record,
222
+ headCount: facts ? facts.headCount : null,
223
+ })]
224
+ : [...SETUP_CORTEX_BLOCKERS]
225
+ : [];
150
226
 
151
227
  // ENC-0e: surface the darwin-x64 demotion reason additively (reader-only GET,
152
228
  // no new route). The platform is read locally; the selection is pure. On a
@@ -36,6 +36,11 @@ import {
36
36
  verifyEncoderAsset,
37
37
  detectPlatform,
38
38
  } from "../../src/vector-cortex/encoder/asset.js";
39
+ import { ENC_0G_ENABLED, ENC_0F_ENABLED } from "../../src/config.js";
40
+ import {
41
+ readQualificationRecord,
42
+ encoderStateDir,
43
+ } from "./qualification-record.js";
39
44
 
40
45
  /** Cap applied to every log tail served by the action-log route. */
41
46
  export const ACTION_LOG_TAIL_BYTES = 8192;
@@ -174,23 +179,37 @@ function runVerifyAsset(stateDir: string): SetupCortexActionResult {
174
179
  };
175
180
  }
176
181
 
182
+ /**
183
+ * The ENC-0g honesty suffix for the verify-asset summary line: when both gates
184
+ * are ON, surface the QualificationV1 record verdict so the action log is honest
185
+ * alongside the (possibly demoted) status card. Returns "" byte-identical when
186
+ * ENC_0G is off. Bounded + redacted (verdict + reasons only).
187
+ */
188
+ function qualificationRecordSuffix(): string {
189
+ if (!ENC_0G_ENABLED() || !ENC_0F_ENABLED()) return "";
190
+ const record = readQualificationRecord(encoderStateDir());
191
+ if (record === null) return " record_verdict=unavailable";
192
+ return ` record_verdict=${record.verdict} record_reasons=${record.reasons.join(",")}`;
193
+ }
194
+
177
195
  /** Compute the redacted verify-asset summary lines (digests + codes only). */
178
196
  function buildVerifySummary(): string {
197
+ const suffix = qualificationRecordSuffix();
179
198
  const dir = encoderAssetDir();
180
199
  if (dir === null) {
181
- return "mode=C verdict=unavailable reason=asset_missing\n";
200
+ return `mode=C verdict=unavailable reason=asset_missing${suffix}\n`;
182
201
  }
183
202
  const manifest = readEncoderManifest(dir);
184
203
  if (manifest === null) {
185
- return "mode=B verdict=demoted reason=ENC_MANIFEST_INVALID\n";
204
+ return `mode=B verdict=demoted reason=ENC_MANIFEST_INVALID${suffix}\n`;
186
205
  }
187
206
  const platform = detectPlatform();
188
207
  const verify = verifyEncoderAsset(dir, manifest, platform);
189
208
  if (verify.ok) {
190
209
  const prefix = verify.onnxDigest.slice(0, 12);
191
- return `mode=A verdict=qualified onnx_digest_prefix=${prefix} embedded_bytes=${verify.embeddedBytes}\n`;
210
+ return `mode=A verdict=qualified onnx_digest_prefix=${prefix} embedded_bytes=${verify.embeddedBytes}${suffix}\n`;
192
211
  }
193
- return `mode=B verdict=demoted reason=${verify.code}\n`;
212
+ return `mode=B verdict=demoted reason=${verify.code}${suffix}\n`;
194
213
  }
195
214
 
196
215
  /** Walk up to the committed encoder-v1 asset dir (mirrors routes-setup-cortex.ts). */
@@ -1,99 +1,5 @@
1
1
  /**
2
- * dashboard-server/setup-cortex-blockers.ts — canonical blocker manifest for the
3
- * dashboard Setup Cortex status read path (VC9A).
4
- *
5
- * The hard-gate items enumerated in docs/vector-cortex/vc2-model-prep.md §6
6
- * (per the 2026-08-05 research update: the opset-14→17 re-export blocker is
7
- * REMOVED because onnx-community exports are now opset 21). This module is the
8
- * SINGLE canonical source of those blockers — the route file
9
- * (routes-setup-cortex.ts) carries NO string literals for them; it reads this
10
- * static manifest so the UI rows and the spec stay in one place.
11
- *
12
- * Reader-only, static: zero network, no writes (PREVENT-PI-004), no `any`
13
- * (PREVENT-011).
2
+ * dashboard-server/setup-cortex-blockers.ts — thin shell re-exporting the
3
+ * canonical Setup Cortex blocker compute from src (single source of truth).
14
4
  */
15
-
16
- /** The open hard-gate items VC9A surfaces (nothing is closed in-workstream). */
17
- export interface SetupCortexBlockerV1 {
18
- /** Stable machine id (e.g. HG-1) the client can key rows on. */
19
- readonly id: string;
20
- /** Human title shown on the blockers card. */
21
- readonly title: string;
22
- /** Severity: blocker | high | medium. */
23
- readonly severity: "blocker" | "high" | "medium";
24
- /** Lifecycle state — all OPEN (hard gates are never silently closed). */
25
- readonly status: "open";
26
- /** Optional candidate resolution surfaced for the controller / user. */
27
- readonly resolution?: string;
28
- }
29
-
30
- /**
31
- * The four blockers VC9A reports. Enumerates the vc2-model-prep §6 items that
32
- * remain per the 2026-08-05 research. The opset re-export blocker (formerly
33
- * §6 #2) is NOT listed: onnx-community exports are opset 21, so it is removed.
34
- */
35
- export const SETUP_CORTEX_BLOCKERS: readonly SetupCortexBlockerV1[] = [
36
- {
37
- id: "HG-1",
38
- title: "Five projection heads do not exist",
39
- severity: "blocker",
40
- status: "open",
41
- resolution:
42
- "Supervision transfer onto a frozen bge-small-en-v1.5 trunk (contradiction distilled from cross-encoder/nli-deberta-v3-small; dependency NLI-assisted; cache-stability deterministic; payload-routing small MLP) — VC2B training + export.",
43
- },
44
- {
45
- id: "HG-3",
46
- title: "onnxruntime-node install exceeds the 80 MiB asset budget",
47
- severity: "blocker",
48
- status: "open",
49
- resolution:
50
- "onnxruntime-node bundles ~258 MiB across all platforms. Candidate: transformers.js v4.2.0 (9.5 MiB shell, pure-Node via onnxruntime-web WASM) measured against budget + p95 gate before committing.",
51
- },
52
- {
53
- id: "HG-4",
54
- title: "No darwin-x64 binary in onnxruntime-node",
55
- severity: "high",
56
- status: "open",
57
- resolution:
58
- "Intel-Mac mode-A users demote to the WASM path (if HG-3 resolves that way) or mode B. " +
59
- "darwin-x64: no native binary upstream (arm64-only); mode-B WASM per HG-4.",
60
- },
61
- {
62
- id: "HG-5",
63
- title: "RSS margin at 512 tokens is ~0.5%",
64
- severity: "medium",
65
- status: "open",
66
- resolution:
67
- "149.2 MiB vs 150 MiB cap with run-to-run variance 119-149 MiB; considers capping mode A at 384 tokens or using the marginal-footprint accounting runtime.ts already implements.",
68
- },
69
- ];
70
-
71
- /** Look up one blocker by id; undefined when unknown (defensive). */
72
- export function setupCortexBlocker(id: string): SetupCortexBlockerV1 | undefined {
73
- return SETUP_CORTEX_BLOCKERS.find((b) => b.id === id);
74
- }
75
-
76
- // ─── VC9B action gating ─────────────────────────────────────────────────────
77
-
78
- /** The VC9B action kinds the drivers know how to run. */
79
- export type SetupCortexActionKind = "fetch-model" | "bench" | "verify-asset";
80
-
81
- /**
82
- * The open hard-gate ids that BLOCK a given action. fetch-model and bench are
83
- * gated by HG-1 (five-head training open) and HG-3 (install budget open) per the
84
- * VC9 workstream plan; verify-asset is a pure re-read of committed assets and is
85
- * NOT gated. When a gated action is requested, the route returns
86
- * action_blocked_by_open_item with these ids and does NOT spawn. The ids are
87
- * always drawn from SETUP_CORTEX_BLOCKERS (each exists — verified by test).
88
- */
89
- export function setupCortexActionBlockers(
90
- action: SetupCortexActionKind,
91
- ): readonly string[] {
92
- switch (action) {
93
- case "fetch-model":
94
- case "bench":
95
- return ["HG-1", "HG-3"];
96
- case "verify-asset":
97
- return [];
98
- }
99
- }
5
+ export * from "../../src/vector-cortex/setup-cortex-blockers-compute.js";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "pi-mega-compact",
3
- "version": "0.20.47",
3
+ "version": "0.20.49",
4
4
  "description": "Layered, local, vector-backed context compressor for pi — supersede/collapse/cluster compaction with deduped inline recall.",
5
5
  "type": "module",
6
6
  "license": "BSD-3-Clause",
@@ -0,0 +1,38 @@
1
+ /**
2
+ * config/vector-cortex-enc0f.ts — ENC-0f p95 + marginal-RSS qualification gate.
3
+ *
4
+ * Extracted from vector-cortex.ts so that file stays under the 300-line soft
5
+ * limit (soft-as-hard gate), exactly as vector-cortex-enc0a.ts / enc0b.ts /
6
+ * enc0c.ts / enc0d.ts / enc0e.ts and the VC8C/VC9A-D/ML5A-E/DEDUP_ATTR
7
+ * siblings were. vector-cortex.ts re-exports the flag below and root
8
+ * src/config.ts re-exports it, so no consumer import path changes.
9
+ *
10
+ * ENC-0f closes HG-5 (RSS margin) with a real asset: the qualification gate
11
+ * that admits the ENC-0d-promoted trained asset to mode A. The gate runs the
12
+ * ML5-B bench under --expose-gc and asserts p95 ≤ ENCODER_LATENCY_P95_MS
13
+ * (40 ms @ 512 tokens / 4 threads), marginal RSS ≤ ENCODER_RSS_BUDGET_BYTES
14
+ * (150 MiB, baseline-subtracted), determinism (distinct digests == 1), and
15
+ * the opset-21 handshake. On pass it emits a QualificationV1 record that flips
16
+ * the runtime to qualified mode A; on any failure the asset stays demoted.
17
+ *
18
+ * `MEGACOMPACT_ENC_0F=0` disables the gate entirely: no qualification gate
19
+ * runs, no QualificationV1 record is written for the real trained asset, and
20
+ * the runtime keeps serving the ENC-0d survivor. Flag-off is byte-identical to
21
+ * the predecessor. The flag MUST also be a dashboard SETTINGS toggle (visible
22
+ * in config UI, never in EXCLUDED_SETTINGS).
23
+ *
24
+ * Pi-agnostic, dependency-free (PREVENT-PI-004 / PREVENT-011).
25
+ */
26
+
27
+ import { sprintFlag } from "./vector-cortex-flag.js";
28
+
29
+ /**
30
+ * ENC-0f — p95 + marginal-RSS qualification gate for the real trained asset.
31
+ * Default ON. `MEGACOMPACT_ENC_0F=0` disables and is byte-identical to the
32
+ * predecessor (ENC-0e): no qualification gate runs, no QualificationV1 record
33
+ * is written for the real trained asset, and the runtime keeps serving the
34
+ * ENC-0d survivor. This flag MUST also be a dashboard SETTINGS toggle (visible
35
+ * in config UI, never in EXCLUDED_SETTINGS), mirroring
36
+ * ENC_0A/ENC_0B/ENC_0C/ENC_0D/ENC_0E.
37
+ */
38
+ export const ENC_0F_ENABLED = (): boolean => sprintFlag("MEGACOMPACT_ENC_0F");
@@ -0,0 +1,39 @@
1
+ /**
2
+ * config/vector-cortex-enc0g.ts — ENC-0g Setup Cortex status route honest state.
3
+ *
4
+ * Extracted from vector-cortex.ts so that file stays under the 300-line soft
5
+ * limit (soft-as-hard gate), exactly as vector-cortex-enc0a.ts .. enc0f.ts and
6
+ * the VC8C/VC9A-D/ML5A-E/DEDUP_ATTR siblings were. vector-cortex.ts re-exports
7
+ * the flag below and root src/config.ts re-exports it, so no consumer import
8
+ * path changes.
9
+ *
10
+ * ENC-0g makes the Setup Cortex status route honest: the status route reads the
11
+ * latest ENC-0f `QualificationV1` record (when ENC_0F is ON and a record
12
+ * exists) and lets its verdict override the structural verifyEncoderAsset
13
+ * result for the `qualification` field; the blocker list becomes a pure
14
+ * computed function over (platform, qualification record, manifest head-count)
15
+ * with corrected HG statuses/wording; and VC9B action gating is re-derived from
16
+ * the live computed blockers instead of the stale static manifest.
17
+ *
18
+ * `MEGACOMPACT_ENC_0G=0` disables: the status route derives its `qualification`
19
+ * verdict from `verifyEncoderAsset(...).ok` alone, the blocker list is the
20
+ * static `SETUP_CORTEX_BLOCKERS` array exactly as ENC-0f-era, and action gating
21
+ * reads the static table as today — byte-identical to the predecessor. The flag
22
+ * MUST also be a dashboard SETTINGS toggle (visible in config UI, never in
23
+ * EXCLUDED_SETTINGS).
24
+ *
25
+ * Pi-agnostic, dependency-free (PREVENT-PI-004 / PREVENT-011).
26
+ */
27
+
28
+ import { sprintFlag } from "./vector-cortex-flag.js";
29
+
30
+ /**
31
+ * ENC-0g — Setup Cortex status route honest state (verdict override + live
32
+ * blockers + re-derived gating). Default ON. `MEGACOMPACT_ENC_0G=0` disables
33
+ * and is byte-identical to the predecessor (ENC-0f): verdict from
34
+ * `verifyEncoderAsset` alone, static `SETUP_CORTEX_BLOCKERS`, static
35
+ * `setupCortexActionBlockers`. This flag MUST also be a dashboard SETTINGS
36
+ * toggle (visible in config UI, never in EXCLUDED_SETTINGS), mirroring
37
+ * ENC_0A/ENC_0B/ENC_0C/ENC_0D/ENC_0E/ENC_0F.
38
+ */
39
+ export const ENC_0G_ENABLED = (): boolean => sprintFlag("MEGACOMPACT_ENC_0G");
@@ -60,6 +60,8 @@ export { ENC_0B_ENABLED } from "./vector-cortex-enc0b.js";
60
60
  export { ENC_0C_ENABLED } from "./vector-cortex-enc0c.js";
61
61
  export { ENC_0D_ENABLED } from "./vector-cortex-enc0d.js";
62
62
  export { ENC_0E_ENABLED } from "./vector-cortex-enc0e.js";
63
+ export { ENC_0F_ENABLED } from "./vector-cortex-enc0f.js";
64
+ export { ENC_0G_ENABLED } from "./vector-cortex-enc0g.js";
63
65
  // Breaker constants (TRIAD_RESILIENCE.md §breaker) extracted to vector-cortex-breakers.ts.
64
66
  export {
65
67
  BREAKER_WINDOW_MS,
package/src/config.ts CHANGED
@@ -194,6 +194,8 @@ export {
194
194
  ENC_0C_ENABLED,
195
195
  ENC_0D_ENABLED,
196
196
  ENC_0E_ENABLED,
197
+ ENC_0F_ENABLED,
198
+ ENC_0G_ENABLED,
197
199
  BREAKER_WINDOW_MS,
198
200
  BREAKER_MIN_ATTEMPTS,
199
201
  BREAKER_PERF_FAILURES,
@@ -0,0 +1,83 @@
1
+ /**
2
+ * vector-cortex/encoder/qualify.ts — ENC-0f pure qualification function.
3
+ *
4
+ * Constructs a {@link QualificationV1} record from a {@link BenchResultV1} by
5
+ * asserting four independent gates (latency, marginal-RSS, determinism, opset)
6
+ * plus the bench's own conjunctive `gates.all`. A gated-off bench can NEVER be
7
+ * swept into mode A by a sub-threshold p95 alone — `bench_gates_not_green`
8
+ * forces `"failed"` regardless of the sub-threshold values.
9
+ *
10
+ * Pure (TRIAD_RESILIENCE §pure): no `any` (PREVENT-011), no casts, no clock, no
11
+ * storage, no network (PREVENT-PI-004). Thresholds are sourced from
12
+ * {@link ENCODER_LATENCY_P95_MS} / {@link ENCODER_RSS_BUDGET_BYTES} /
13
+ * {@link ENCODER_OPSET} — never magic numbers.
14
+ */
15
+
16
+ import type { BenchResultV1 } from "./bench-export.js";
17
+ import {
18
+ ENCODER_LATENCY_P95_MS,
19
+ ENCODER_RSS_BUDGET_BYTES,
20
+ ENCODER_OPSET,
21
+ } from "./types.js";
22
+
23
+ /** The qualification verdict for a real trained encoder asset. */
24
+ export interface QualificationV1 {
25
+ readonly schema: "qualification-v1";
26
+ readonly verdict: "qualified" | "failed";
27
+ readonly reasons: string[];
28
+ readonly platform: string;
29
+ readonly p95Ms: number;
30
+ readonly rssMib: number;
31
+ readonly opset: number;
32
+ /** SHA-256 hex of the bench run's embedding output (never payload content). */
33
+ readonly digest: string;
34
+ }
35
+
36
+ /**
37
+ * Qualify a bench result against the four independent gates + the bench's own
38
+ * conjunctive gate. Returns a QualificationV1 with `verdict:"qualified"` only
39
+ * when ALL gates pass and `bench.gates.all` is true.
40
+ */
41
+ export function qualifyEncodedAsset(
42
+ bench: BenchResultV1,
43
+ platform: string,
44
+ ): QualificationV1 {
45
+ const reasons: string[] = [];
46
+
47
+ if (bench.p95Ms !== null && bench.p95Ms > ENCODER_LATENCY_P95_MS) {
48
+ reasons.push("latency");
49
+ }
50
+
51
+ if (
52
+ bench.rssMarginalMib !== null &&
53
+ bench.rssMarginalMib * 1024 * 1024 > ENCODER_RSS_BUDGET_BYTES
54
+ ) {
55
+ reasons.push("rss");
56
+ }
57
+
58
+ if (!bench.deterministic) {
59
+ reasons.push("determinism");
60
+ }
61
+
62
+ if (bench.opset !== null && bench.opset !== ENCODER_OPSET) {
63
+ reasons.push("opset");
64
+ }
65
+
66
+ if (!bench.gates.all && !reasons.includes("bench_gates_not_green")) {
67
+ reasons.push("bench_gates_not_green");
68
+ }
69
+
70
+ const verdict: "qualified" | "failed" =
71
+ reasons.length === 0 && bench.gates.all ? "qualified" : "failed";
72
+
73
+ return {
74
+ schema: "qualification-v1",
75
+ verdict,
76
+ reasons,
77
+ platform,
78
+ p95Ms: bench.p95Ms ?? 0,
79
+ rssMib: bench.rssMarginalMib ?? 0,
80
+ opset: bench.opset ?? 0,
81
+ digest: bench.digest ?? "",
82
+ };
83
+ }