pi-mega-compact 0.20.51 → 0.20.53
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/assets/vector-cortex/encoder-v1/manifest.json +1 -1
- package/dist/config/vector-cortex-enc2budget.js +46 -0
- package/dist/config/vector-cortex.js +1 -0
- package/dist/config.js +1 -1
- package/dist/extensions/dashboard-server/api-contracts/vector-cortex-ledger.js +9 -0
- package/dist/extensions/dashboard-server/routes-rag-settings-vector-cortex.js +1 -0
- package/dist/extensions/dashboard-server/routes-setup-enc2budget.js +155 -0
- package/dist/extensions/dashboard-server/routes-setup.js +15 -0
- package/dist/extensions/dashboard-server/routes-vector-cortex-eval.js +4 -1
- package/dist/src/config/vector-cortex-enc2budget.js +46 -0
- package/dist/src/config/vector-cortex.js +1 -0
- package/dist/src/config.js +1 -1
- package/dist/src/vector-cortex/encoder/decision.js +34 -6
- package/dist/src/vector-cortex/encoder/runtime-select.js +24 -21
- package/dist/src/vector-cortex/setup-cortex-blockers-compute.js +2 -2
- package/dist/vector-cortex/encoder/decision.js +34 -6
- package/dist/vector-cortex/encoder/runtime-select.js +24 -21
- package/dist/vector-cortex/setup-cortex-blockers-compute.js +2 -2
- package/extensions/dashboard-client/dist/assets/{AreaChart-BFTUTmmW.js → AreaChart-COjQ_jJm.js} +2 -2
- package/extensions/dashboard-client/dist/assets/{AreaChart-BFTUTmmW.js.map → AreaChart-COjQ_jJm.js.map} +1 -1
- package/extensions/dashboard-client/dist/assets/{BarChart-DfFurESR.js → BarChart-eAIpwb8c.js} +2 -2
- package/extensions/dashboard-client/dist/assets/{BarChart-DfFurESR.js.map → BarChart-eAIpwb8c.js.map} +1 -1
- package/extensions/dashboard-client/dist/assets/{CacheTab-FpCJSmy8.js → CacheTab-BS_G9_YV.js} +2 -2
- package/extensions/dashboard-client/dist/assets/{CacheTab-FpCJSmy8.js.map → CacheTab-BS_G9_YV.js.map} +1 -1
- package/extensions/dashboard-client/dist/assets/{EventsTab--9lJFJtc.js → EventsTab-CDFk5d3P.js} +2 -2
- package/extensions/dashboard-client/dist/assets/{EventsTab--9lJFJtc.js.map → EventsTab-CDFk5d3P.js.map} +1 -1
- package/extensions/dashboard-client/dist/assets/{HealthTab-CkgtF1qa.js → HealthTab-zFyPJb5b.js} +2 -2
- package/extensions/dashboard-client/dist/assets/{HealthTab-CkgtF1qa.js.map → HealthTab-zFyPJb5b.js.map} +1 -1
- package/extensions/dashboard-client/dist/assets/{MaintenanceTab-ChXGq1or.js → MaintenanceTab-DxJX4lXh.js} +2 -2
- package/extensions/dashboard-client/dist/assets/{MaintenanceTab-ChXGq1or.js.map → MaintenanceTab-DxJX4lXh.js.map} +1 -1
- package/extensions/dashboard-client/dist/assets/{MemoryMapTab-CPpRR4MV.js → MemoryMapTab-CRy5I6mg.js} +2 -2
- package/extensions/dashboard-client/dist/assets/{MemoryMapTab-CPpRR4MV.js.map → MemoryMapTab-CRy5I6mg.js.map} +1 -1
- package/extensions/dashboard-client/dist/assets/{MetricsTab-Db1wkykf.js → MetricsTab-K4kPea0Q.js} +2 -2
- package/extensions/dashboard-client/dist/assets/{MetricsTab-Db1wkykf.js.map → MetricsTab-K4kPea0Q.js.map} +1 -1
- package/extensions/dashboard-client/dist/assets/{OverviewTab-LanDECrz.js → OverviewTab-BZoJ1oOv.js} +2 -2
- package/extensions/dashboard-client/dist/assets/{OverviewTab-LanDECrz.js.map → OverviewTab-BZoJ1oOv.js.map} +1 -1
- package/extensions/dashboard-client/dist/assets/{ReposTab-I2umKduk.js → ReposTab-uMFKxT0a.js} +2 -2
- package/extensions/dashboard-client/dist/assets/{ReposTab-I2umKduk.js.map → ReposTab-uMFKxT0a.js.map} +1 -1
- package/extensions/dashboard-client/dist/assets/{SessionsTab-D_IxuEt5.js → SessionsTab-DDzmcCuH.js} +2 -2
- package/extensions/dashboard-client/dist/assets/{SessionsTab-D_IxuEt5.js.map → SessionsTab-DDzmcCuH.js.map} +1 -1
- package/extensions/dashboard-client/dist/assets/SetupTab-KLTE-VKV.js +3 -0
- package/extensions/dashboard-client/dist/assets/{SetupTab-BZ7Jn5MR.js.map → SetupTab-KLTE-VKV.js.map} +1 -1
- package/extensions/dashboard-client/dist/assets/{TimeSavedCard-BTdcO1E2.js → TimeSavedCard-D_mBYAzE.js} +2 -2
- package/extensions/dashboard-client/dist/assets/{TimeSavedCard-BTdcO1E2.js.map → TimeSavedCard-D_mBYAzE.js.map} +1 -1
- package/extensions/dashboard-client/dist/assets/{TurnsTab-BXC8IL_B.js → TurnsTab-C6xr2lsO.js} +2 -2
- package/extensions/dashboard-client/dist/assets/{TurnsTab-BXC8IL_B.js.map → TurnsTab-C6xr2lsO.js.map} +1 -1
- package/extensions/dashboard-client/dist/assets/{VcStatusBadge-CNJnFtJo.js → VcStatusBadge-J0DVlxH0.js} +2 -2
- package/extensions/dashboard-client/dist/assets/{VcStatusBadge-CNJnFtJo.js.map → VcStatusBadge-J0DVlxH0.js.map} +1 -1
- package/extensions/dashboard-client/dist/assets/{VectorCortexTab-fsuWgA6e.js → VectorCortexTab-AvL73DpJ.js} +2 -2
- package/extensions/dashboard-client/dist/assets/{VectorCortexTab-fsuWgA6e.js.map → VectorCortexTab-AvL73DpJ.js.map} +1 -1
- package/extensions/dashboard-client/dist/assets/{WikiTab-Cn1BScDU.js → WikiTab-DVcIWjLT.js} +2 -2
- package/extensions/dashboard-client/dist/assets/{WikiTab-Cn1BScDU.js.map → WikiTab-DVcIWjLT.js.map} +1 -1
- package/extensions/dashboard-client/dist/assets/{button-B4_9rsul.js → button-Cl_gFaIf.js} +2 -2
- package/extensions/dashboard-client/dist/assets/{button-B4_9rsul.js.map → button-Cl_gFaIf.js.map} +1 -1
- package/extensions/dashboard-client/dist/assets/{card-DUvC_geI.js → card-DMzHffVs.js} +2 -2
- package/extensions/dashboard-client/dist/assets/{card-DUvC_geI.js.map → card-DMzHffVs.js.map} +1 -1
- package/extensions/dashboard-client/dist/assets/{client-extra-HaH97bzp.js → client-extra-Dkkppa5C.js} +2 -2
- package/extensions/dashboard-client/dist/assets/{client-extra-HaH97bzp.js.map → client-extra-Dkkppa5C.js.map} +1 -1
- package/extensions/dashboard-client/dist/assets/{generateCategoricalChart-BxFWU2Mt.js → generateCategoricalChart-Bi8zQmZN.js} +2 -2
- package/extensions/dashboard-client/dist/assets/{generateCategoricalChart-BxFWU2Mt.js.map → generateCategoricalChart-Bi8zQmZN.js.map} +1 -1
- package/extensions/dashboard-client/dist/assets/{index-xPdbZ73U.js → index-mZRDesSq.js} +3 -3
- package/extensions/dashboard-client/dist/assets/{index-xPdbZ73U.js.map → index-mZRDesSq.js.map} +1 -1
- package/extensions/dashboard-client/dist/assets/{switch-Bv3_1R_j.js → switch-K_lsOl6x.js} +2 -2
- package/extensions/dashboard-client/dist/assets/{switch-Bv3_1R_j.js.map → switch-K_lsOl6x.js.map} +1 -1
- package/extensions/dashboard-client/dist/assets/{toggle-DHXrB3Aw.js → toggle-67IU2JLn.js} +2 -2
- package/extensions/dashboard-client/dist/assets/{toggle-DHXrB3Aw.js.map → toggle-67IU2JLn.js.map} +1 -1
- package/extensions/dashboard-client/dist/assets/{useSSE-NigHeFyT.js → useSSE-DiLgyP7C.js} +2 -2
- package/extensions/dashboard-client/dist/assets/{useSSE-NigHeFyT.js.map → useSSE-DiLgyP7C.js.map} +1 -1
- package/extensions/dashboard-client/dist/index.html +1 -1
- package/extensions/dashboard-client/src/tabs/SetupTab/CortexRuntimeCard.tsx +98 -7
- package/extensions/dashboard-client/src/tabs/VectorCortexTab.tsx +7 -5
- package/extensions/dashboard-client/src/types/vector-cortex.ts +6 -0
- package/extensions/dashboard-server/api-contracts/setup.ts +13 -0
- package/extensions/dashboard-server/api-contracts/vector-cortex-ledger.ts +39 -0
- package/extensions/dashboard-server/api-contracts/vector-cortex.ts +10 -28
- package/extensions/dashboard-server/routes-rag-settings-vector-cortex.ts +6 -0
- package/extensions/dashboard-server/routes-setup-enc2budget.ts +171 -0
- package/extensions/dashboard-server/routes-setup.ts +19 -0
- package/extensions/dashboard-server/routes-vector-cortex-eval.ts +4 -1
- package/package.json +1 -1
- package/src/config/vector-cortex-enc2budget.ts +51 -0
- package/src/config/vector-cortex.ts +6 -0
- package/src/config.ts +4 -0
- package/src/vector-cortex/encoder/decision.ts +37 -6
- package/src/vector-cortex/encoder/runtime-select.ts +25 -23
- package/src/vector-cortex/setup-cortex-blockers-compute.ts +2 -2
- package/extensions/dashboard-client/dist/assets/SetupTab-BZ7Jn5MR.js +0 -3
|
@@ -55,6 +55,15 @@ export interface SetupStatusResponse {
|
|
|
55
55
|
* falls back (e.g. native selected but onnxruntime-node absent / darwin-x64
|
|
56
56
|
* demoted), surfaced verbatim; null when no demotion (additive, flag-gated). */
|
|
57
57
|
readonly encoderDemotionReason?: string | null;
|
|
58
|
+
/** ENC-2a: the persisted `MEGACOMPACT_NATIVE_ORT_BUDGET_MIB` value as its
|
|
59
|
+
* numeric string, when configured (additive, flag-gated). Absent when the
|
|
60
|
+
* operator has not set the knob. */
|
|
61
|
+
readonly nativeOrtBudgetMib?: string;
|
|
62
|
+
/** ENC-2a: the EFFECTIVE budget `installBudgetMib()` resolves to (integer
|
|
63
|
+
* MiB as a numeric string), so the dashboard can show the runtime's actual
|
|
64
|
+
* operand — persists even when `nativeOrtBudgetMib` is absent because the
|
|
65
|
+
* runtime applies the default when unset. Additive, flag-gated. */
|
|
66
|
+
readonly nativeOrtBudgetEffectiveMib?: string;
|
|
58
67
|
}
|
|
59
68
|
|
|
60
69
|
/**
|
|
@@ -119,6 +128,10 @@ export interface SetupConfigureRequest {
|
|
|
119
128
|
/** ENC-1b: opt in to `MEGACOMPACT_ENCODER_NATIVE` (onnxruntime-node native
|
|
120
129
|
* backend; additive, flag-gated). */
|
|
121
130
|
readonly encoderNativeOptIn?: boolean;
|
|
131
|
+
/** ENC-2a: persisted `MEGACOMPACT_NATIVE_ORT_BUDGET_MIB` install budget as a
|
|
132
|
+
* positive integer string within `ENC_2BUDGET_MAX_MIB` (validated; additive,
|
|
133
|
+
* flag-gated). */
|
|
134
|
+
readonly nativeOrtBudgetMib?: string;
|
|
122
135
|
}
|
|
123
136
|
|
|
124
137
|
/** Response for POST /api/setup-configure. */
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* api-contracts/vector-cortex-ledger.ts — VC1B occurrence-ledger surface.
|
|
3
|
+
*
|
|
4
|
+
* Extracted from `vector-cortex.ts` so the combined api-contracts module stays
|
|
5
|
+
* under the 400-line `extensions/` soft limit. Owns the reader-only ledger
|
|
6
|
+
* views (VC1B aggregate + identity rows). PREVENT-PI-004: type definitions
|
|
7
|
+
* only, no network code. PREVENT-011: no `any` type.
|
|
8
|
+
*/
|
|
9
|
+
|
|
10
|
+
/** Live-state derivation shared across the VC views (mirrors vector-cortex.ts). */
|
|
11
|
+
type VcStatus = "live" | "awaiting_data" | "deferred" | "structural" | "off";
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* Reader-only occurrence-ledger identity view for GET /api/vector-cortex/ledger (VC1B).
|
|
15
|
+
* Built on the LedgerReader capability surface. Exposes occurrence IDENTITY
|
|
16
|
+
* (seq/eventId/kind/digest/toolCallId) and the per-session high-water/count —
|
|
17
|
+
* NEVER sourceBytes or prompt text, honoring the reader-only no-ledger-text rule.
|
|
18
|
+
*/
|
|
19
|
+
export interface VectorCortexLedgerView {
|
|
20
|
+
/** Whether the VC1B occurrence ledger flag is enabled in this process. */
|
|
21
|
+
readonly enabled: boolean;
|
|
22
|
+
/** The ledger session whose occurrences are returned. */
|
|
23
|
+
readonly session: string;
|
|
24
|
+
/** Durable contiguous high-water (stringified bigint) for the session. */
|
|
25
|
+
readonly highWater: string;
|
|
26
|
+
/** Number of accepted occurrences for the session. */
|
|
27
|
+
readonly count: number;
|
|
28
|
+
/** Capped identity rows (ascending seq). No source bytes, never payload text. */
|
|
29
|
+
readonly occurrences: readonly {
|
|
30
|
+
readonly seq: string;
|
|
31
|
+
readonly eventId: string;
|
|
32
|
+
readonly kind: string;
|
|
33
|
+
readonly digest: string;
|
|
34
|
+
readonly toolCallId?: string;
|
|
35
|
+
}[];
|
|
36
|
+
/** ISO timestamp of the snapshot. */
|
|
37
|
+
readonly updatedAt: string;
|
|
38
|
+
readonly status?: VcStatus;
|
|
39
|
+
}
|
|
@@ -44,6 +44,13 @@ export interface VectorCortexEvaluationSummary {
|
|
|
44
44
|
};
|
|
45
45
|
/** Evaluator rejections (EVAL_*) observed in this window. */
|
|
46
46
|
readonly rejects: readonly string[];
|
|
47
|
+
/**
|
|
48
|
+
* ML5-D dashboard "Improve Cortex" flag state. Additive and omitted when
|
|
49
|
+
* MEGACOMPACT_ML5_D is off, so the client omits the ModelImprovementCard
|
|
50
|
+
* (byte-identical to the ML5-C-era tab). Present (true) only when the flag
|
|
51
|
+
* is enabled. Reader-only aggregate — never job verdicts or training bytes.
|
|
52
|
+
*/
|
|
53
|
+
readonly ml5dEnabled?: boolean;
|
|
47
54
|
/** ISO timestamp of the summary. */
|
|
48
55
|
readonly updatedAt: string;
|
|
49
56
|
readonly status?: VcStatus;
|
|
@@ -365,36 +372,11 @@ export interface VectorCortexRolloutView {
|
|
|
365
372
|
readonly status?: VcStatus;
|
|
366
373
|
}
|
|
367
374
|
|
|
368
|
-
/**
|
|
369
|
-
* Reader-only occurrence-ledger identity view for GET /api/vector-cortex/ledger (VC1B).
|
|
370
|
-
* Built on the LedgerReader capability surface. Exposes occurrence IDENTITY
|
|
371
|
-
* (seq/eventId/kind/digest/toolCallId) and the per-session high-water/count —
|
|
372
|
-
* NEVER sourceBytes or prompt text, honoring the reader-only no-ledger-text rule.
|
|
373
|
-
*/
|
|
374
|
-
export interface VectorCortexLedgerView {
|
|
375
|
-
/** Whether the VC1B occurrence ledger flag is enabled in this process. */
|
|
376
|
-
readonly enabled: boolean;
|
|
377
|
-
/** The ledger session whose occurrences are returned. */
|
|
378
|
-
readonly session: string;
|
|
379
|
-
/** Durable contiguous high-water (stringified bigint) for the session. */
|
|
380
|
-
readonly highWater: string;
|
|
381
|
-
/** Number of accepted occurrences for the session. */
|
|
382
|
-
readonly count: number;
|
|
383
|
-
/** Capped identity rows (ascending seq). No source bytes, never payload text. */
|
|
384
|
-
readonly occurrences: readonly {
|
|
385
|
-
readonly seq: string;
|
|
386
|
-
readonly eventId: string;
|
|
387
|
-
readonly kind: string;
|
|
388
|
-
readonly digest: string;
|
|
389
|
-
readonly toolCallId?: string;
|
|
390
|
-
}[];
|
|
391
|
-
/** ISO timestamp of the snapshot. */
|
|
392
|
-
readonly updatedAt: string;
|
|
393
|
-
readonly status?: VcStatus;
|
|
394
|
-
}
|
|
395
|
-
|
|
396
375
|
export type {
|
|
397
376
|
VectorCortexClosureProofView,
|
|
398
377
|
VectorCortexRestoreView,
|
|
399
378
|
VectorCortexRepairView,
|
|
400
379
|
} from "./vector-cortex-heal.js";
|
|
380
|
+
export type {
|
|
381
|
+
VectorCortexLedgerView,
|
|
382
|
+
} from "./vector-cortex-ledger.js";
|
|
@@ -306,5 +306,11 @@ export const VECTOR_CORTEX_SETTINGS: SettingGroup = {
|
|
|
306
306
|
"ENC-1b completes the embedder API Settings surface (dim / headers / allow-remote persisted to the per-repo .mega-compact.env) and surfaces the ONNX runtime selection knob (MEGACOMPACT_ENCODER_NATIVE) as a toggle plus the current effective backend + demotion reason. OFF = no new GET fields, no writer branch, no new Settings rows or toggle (byte-identical ENC-1a predecessor).",
|
|
307
307
|
true,
|
|
308
308
|
),
|
|
309
|
+
boolDirect(
|
|
310
|
+
"MEGACOMPACT_ENC_2BUDGET",
|
|
311
|
+
"ENC-2a operator-configurable native install-budget knob",
|
|
312
|
+
"ENC-2a exposes the runtime operator knob MEGACOMPACT_NATIVE_ORT_BUDGET_MIB (default 300 MiB, clamp 8192) as a dashboard Settings field. The knob gates budgetOk in the encoder runtime decision (decision.ts installBudgetMib + runtime-select.ts selectRuntimeBackend). Persisted to the per-repo .mega-compact.env via the setup-configure writer branch; the GET status route surfaces the persisted value AND the effective integer installBudgetMib() resolves to (so the dashboard shows the runtime's actual operand). OFF = no new GET fields, no writer branch, no new Settings rows (byte-identical ENC-1b predecessor).",
|
|
313
|
+
true,
|
|
314
|
+
),
|
|
309
315
|
],
|
|
310
316
|
};
|
|
@@ -0,0 +1,171 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* dashboard-server/routes-setup-enc2budget.ts — ENC-2a operator-configurable
|
|
3
|
+
* native onnxruntime install budget (MiB) Settings read/write + the additive
|
|
4
|
+
* writer branch.
|
|
5
|
+
*
|
|
6
|
+
* Extracted out of routes-setup.ts (which hovers at the 300-line source soft
|
|
7
|
+
* cap, mirroring the ENC-1a/ENC-1b sibling extracts) so the ENC-2a additive
|
|
8
|
+
* read/write of the per-repo `.mega-compact.env` key lives in a sibling impl
|
|
9
|
+
* file. One key is managed here: `MEGACOMPACT_NATIVE_ORT_BUDGET_MIB` — the exact
|
|
10
|
+
* name `installBudgetMib()` (`src/vector-cortex/encoder/decision.ts`) reads at
|
|
11
|
+
* runtime.
|
|
12
|
+
*
|
|
13
|
+
* The write is create-or-append: it upserts the key into the existing per-repo
|
|
14
|
+
* `.mega-compact.env`, preserving every unrelated line and never deleting
|
|
15
|
+
* another key. The read reports the persisted raw string AND the effective
|
|
16
|
+
* integer `installBudgetMib()` resolves to (so the dashboard shows what the
|
|
17
|
+
* runtime will actually use — including the 300 MiB default fallback when the
|
|
18
|
+
* knob is unset or invalid). Reader-only: setter/getter never reimplements
|
|
19
|
+
* `installBudgetMib()`'s clamp rule, it imports it.
|
|
20
|
+
*
|
|
21
|
+
* Guardrails: PREVENT-PI-004 (local filesystem reads/writes only — zero
|
|
22
|
+
* network), PREVENT-001 (null-safe), PREVENT-011 (no `any`).
|
|
23
|
+
*/
|
|
24
|
+
|
|
25
|
+
import { writeFileSync, mkdirSync, readFileSync, existsSync } from "node:fs";
|
|
26
|
+
import { join } from "node:path";
|
|
27
|
+
import {
|
|
28
|
+
ENC_2BUDGET_ENABLED,
|
|
29
|
+
ENC_2BUDGET_MAX_MIB,
|
|
30
|
+
ENC_2BUDGET_NATIVE_ORT_BUDGET_ENV,
|
|
31
|
+
} from "../../src/config/vector-cortex.js";
|
|
32
|
+
import {
|
|
33
|
+
installBudgetMib,
|
|
34
|
+
resolveInstallBudgetMib,
|
|
35
|
+
} from "../../src/vector-cortex/encoder/decision.js";
|
|
36
|
+
import type { SetupConfigureRequest } from "./api-contracts/setup.js";
|
|
37
|
+
|
|
38
|
+
function envPath(stateDir: string): string {
|
|
39
|
+
return join(stateDir, ".mega-compact.env");
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
/** Extract the value of `export MEGACOMPACT_X="..."` (or unquoted) from a line. */
|
|
43
|
+
function lineValue(line: string, key: string): string | null {
|
|
44
|
+
const m = line.match(new RegExp(`^export\\s+${key}=(.*)$`));
|
|
45
|
+
if (!m) return null;
|
|
46
|
+
const rest = m[1].trim();
|
|
47
|
+
if (rest.length === 0) return null;
|
|
48
|
+
const q = rest.match(/^"([^"]*)"$/);
|
|
49
|
+
return q ? q[1] : rest;
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
/** True when the payload carries the ENC-2a key (flag-gated). */
|
|
53
|
+
export function wantsEnc2Budget(body: SetupConfigureRequest): boolean {
|
|
54
|
+
return ENC_2BUDGET_ENABLED() && typeof body.nativeOrtBudgetMib === "string";
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
/** Read the ENC-2a knob from the per-repo `.mega-compact.env`. Returns the raw
|
|
58
|
+
* persisted string when present, or null when absent. */
|
|
59
|
+
export function readEnc2BudgetEnv(stateDir: string): { raw: string | null } {
|
|
60
|
+
try {
|
|
61
|
+
const p = envPath(stateDir);
|
|
62
|
+
if (!existsSync(p)) return { raw: null };
|
|
63
|
+
const lines = readFileSync(p, "utf8").split(/\r?\n/);
|
|
64
|
+
for (const line of lines) {
|
|
65
|
+
const v = lineValue(line, ENC_2BUDGET_NATIVE_ORT_BUDGET_ENV);
|
|
66
|
+
if (v !== null && v.length > 0) return { raw: v };
|
|
67
|
+
}
|
|
68
|
+
return { raw: null };
|
|
69
|
+
} catch {
|
|
70
|
+
return { raw: null };
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
/**
|
|
75
|
+
* ENC-2a additive GET status fields. Omitted when flag-off. Surfaces the raw
|
|
76
|
+
* persisted value (when set) AND the effective runtime operand — the integer
|
|
77
|
+
* MiB `installBudgetMib()` actually resolves to. Reading `installBudgetMib()`
|
|
78
|
+
* here (instead of reimplementing the clamp) keeps the dashboard honest when
|
|
79
|
+
* the env var is unset or out-of-range.
|
|
80
|
+
*/
|
|
81
|
+
export function enc2BudgetStatusFields(stateDir: string): {
|
|
82
|
+
nativeOrtBudgetMib?: string;
|
|
83
|
+
nativeOrtBudgetEffectiveMib?: string;
|
|
84
|
+
} {
|
|
85
|
+
if (!ENC_2BUDGET_ENABLED()) return {};
|
|
86
|
+
const { raw } = readEnc2BudgetEnv(stateDir);
|
|
87
|
+
// The EFFECTIVE operand is what the runtime WILL use: if a value has been
|
|
88
|
+
// persisted to the disk file, resolve THAT through the clamp (the operator
|
|
89
|
+
// just POSTed it; the running process has not re-sourced `.mega-compact.env`
|
|
90
|
+
// yet so `installBudgetMib()` reads the stale env). On restart the saved
|
|
91
|
+
// value is what the runtime loads. When nothing is persisted, fall back to
|
|
92
|
+
// the live env var / process.env (= `installBudgetMib()`).
|
|
93
|
+
const effective = raw !== null ? resolveInstallBudgetMib(raw) : installBudgetMib();
|
|
94
|
+
return {
|
|
95
|
+
...(raw !== null ? { nativeOrtBudgetMib: raw } : {}),
|
|
96
|
+
nativeOrtBudgetEffectiveMib: String(effective),
|
|
97
|
+
};
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
/** Upsert the ENC-2a knob into the per-repo `.mega-compact.env`. Creates the
|
|
101
|
+
* file if absent; preserves every unrelated line; never deletes other keys.
|
|
102
|
+
* `entries.raw === null` leaves the key's line untouched. */
|
|
103
|
+
export function writeEnc2BudgetEnv(
|
|
104
|
+
stateDir: string,
|
|
105
|
+
entries: { raw?: string | null },
|
|
106
|
+
): string {
|
|
107
|
+
const p = envPath(stateDir);
|
|
108
|
+
const existingLines: string[] = existsSync(p) ? readFileSync(p, "utf8").split(/\r?\n/) : [];
|
|
109
|
+
const out: string[] = [];
|
|
110
|
+
let written = false;
|
|
111
|
+
for (const line of existingLines) {
|
|
112
|
+
if (
|
|
113
|
+
entries.raw !== null &&
|
|
114
|
+
entries.raw !== undefined &&
|
|
115
|
+
lineValue(line, ENC_2BUDGET_NATIVE_ORT_BUDGET_ENV) !== null
|
|
116
|
+
) {
|
|
117
|
+
out.push(`export ${ENC_2BUDGET_NATIVE_ORT_BUDGET_ENV}="${entries.raw}"`);
|
|
118
|
+
written = true;
|
|
119
|
+
continue;
|
|
120
|
+
}
|
|
121
|
+
out.push(line);
|
|
122
|
+
}
|
|
123
|
+
if (entries.raw !== null && entries.raw !== undefined && !written) {
|
|
124
|
+
out.push(`export ${ENC_2BUDGET_NATIVE_ORT_BUDGET_ENV}="${entries.raw}"`);
|
|
125
|
+
}
|
|
126
|
+
mkdirSync(stateDir, { recursive: true });
|
|
127
|
+
writeFileSync(p, out.join("\n"), "utf-8");
|
|
128
|
+
return p;
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
/** Validate `nativeOrtBudgetMib` as a positive integer string within
|
|
132
|
+
* `ENC_2BUDGET_MAX_MIB`. Returns `null` when valid, else the error code.
|
|
133
|
+
* Exported so the routes host (combined-payload path) and the aggregator share
|
|
134
|
+
* the same rule. */
|
|
135
|
+
export function validateNativeOrtBudgetMib(value: unknown): string | null {
|
|
136
|
+
if (typeof value !== "string" || value.trim().length === 0) return "invalid_native_ort_budget_mib";
|
|
137
|
+
if (!/^\d+$/.test(value)) return "invalid_native_ort_budget_mib";
|
|
138
|
+
const n = Number(value);
|
|
139
|
+
if (!Number.isSafeInteger(n) || n < 1 || n > ENC_2BUDGET_MAX_MIB) {
|
|
140
|
+
return "invalid_native_ort_budget_mib";
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
return null;
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
/**
|
|
147
|
+
* Combined-payload upsert: after the main embedder write has freshly written
|
|
148
|
+
* the per-repo env, append the ENC-2a key when carried alongside a valid
|
|
149
|
+
* embedder selection (flag-gated, additive). No-op when flag-off or no ENC-2a
|
|
150
|
+
* key present.
|
|
151
|
+
*/
|
|
152
|
+
export function tryEnc2BudgetInto(stateDir: string, body: SetupConfigureRequest): void {
|
|
153
|
+
if (!wantsEnc2Budget(body)) return;
|
|
154
|
+
writeEnc2BudgetEnv(stateDir, {
|
|
155
|
+
raw: typeof body.nativeOrtBudgetMib === "string" ? body.nativeOrtBudgetMib : null,
|
|
156
|
+
});
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
/**
|
|
160
|
+
* Combined-path validation: the routes host runs this before the combined
|
|
161
|
+
* upsert when a payload ALSO carries a valid embedder — returned as the error
|
|
162
|
+
* code string, or `null` if validation passes (or the flag is off).
|
|
163
|
+
*/
|
|
164
|
+
export function enc2BudgetValidateCombined(body: SetupConfigureRequest): string | null {
|
|
165
|
+
if (!ENC_2BUDGET_ENABLED()) return null;
|
|
166
|
+
if (body.nativeOrtBudgetMib !== undefined) {
|
|
167
|
+
const e = validateNativeOrtBudgetMib(body.nativeOrtBudgetMib);
|
|
168
|
+
if (e !== null) return e;
|
|
169
|
+
}
|
|
170
|
+
return null;
|
|
171
|
+
}
|
|
@@ -16,6 +16,11 @@ import type { RouteContext } from "./routes-core.js";
|
|
|
16
16
|
import { VC9D_ENABLED } from "../../src/config.js";
|
|
17
17
|
import { enc1aStatusFields, writeEnc1aEnv, tryEnc1aConfigure, wantsEnc1a } from "./routes-setup-enc1a.js";
|
|
18
18
|
import { enc1bStatusFields, tryEnc1bConfigure, tryEnc1bInto, enc1bValidateCombined } from "./routes-setup-enc1b.js";
|
|
19
|
+
import {
|
|
20
|
+
enc2BudgetStatusFields,
|
|
21
|
+
tryEnc2BudgetInto,
|
|
22
|
+
enc2BudgetValidateCombined,
|
|
23
|
+
} from "./routes-setup-enc2budget.js";
|
|
19
24
|
import { writeEmbedderEnv } from "./routes-setup-env-upsert.js";
|
|
20
25
|
import {
|
|
21
26
|
detectOllama,
|
|
@@ -94,6 +99,7 @@ export function handleSetupStatus(
|
|
|
94
99
|
(process.env["MEGACOMPACT_MINILM"] ?? "").trim().toLowerCase(),
|
|
95
100
|
),
|
|
96
101
|
...enc1aStatusFields(ctx.stateDir), ...enc1bStatusFields(ctx.stateDir),
|
|
102
|
+
...enc2BudgetStatusFields(ctx.stateDir),
|
|
97
103
|
};
|
|
98
104
|
// guardrails-allow PREVENT-PI-004: loopback dashboard response (local)
|
|
99
105
|
res.writeHead(200, { "Content-Type": "application/json" });
|
|
@@ -232,6 +238,18 @@ export function handleSetupConfigure(
|
|
|
232
238
|
res.end(JSON.stringify({ error: combinedError }));
|
|
233
239
|
return;
|
|
234
240
|
}
|
|
241
|
+
// ENC-2a combined-payload validation: when a payload carries a valid
|
|
242
|
+
// embedder PLUS the budget key, validate the budget BEFORE the upsert so
|
|
243
|
+
// the combined path is rejected with the same 400 code. Flag-off:
|
|
244
|
+
// enc2BudgetValidateCombined returns null (byte-identical predecessor —
|
|
245
|
+
// the unknown key falls through untouched).
|
|
246
|
+
const budgetCombinedError = enc2BudgetValidateCombined(body);
|
|
247
|
+
if (budgetCombinedError !== null) {
|
|
248
|
+
// guardrails-allow PREVENT-PI-004: loopback dashboard response (local)
|
|
249
|
+
res.writeHead(400, { "Content-Type": "application/json" });
|
|
250
|
+
res.end(JSON.stringify({ error: budgetCombinedError }));
|
|
251
|
+
return;
|
|
252
|
+
}
|
|
235
253
|
const embedder = body.embedder;
|
|
236
254
|
if (embedder !== "ollama" && embedder !== "llama" && embedder !== "trigram" && embedder !== "custom" && embedder !== "onnx") {
|
|
237
255
|
res.writeHead(400, { "Content-Type": "application/json" });
|
|
@@ -281,6 +299,7 @@ export function handleSetupConfigure(
|
|
|
281
299
|
});
|
|
282
300
|
}
|
|
283
301
|
tryEnc1bInto(stateDir, body); // ENC-1b combined upsert (dim/headers/allow-remote/native)
|
|
302
|
+
tryEnc2BudgetInto(stateDir, body); // ENC-2a combined upsert (native budget MiB)
|
|
284
303
|
// Detect if the new config matches what's already active (no restart needed).
|
|
285
304
|
const currentUrl = process.env["MEGACOMPACT_EMBEDDING_URL"];
|
|
286
305
|
const alreadyActive = (resolvedUrl === null && !currentUrl) || (resolvedUrl !== null && currentUrl === resolvedUrl);
|
|
@@ -12,7 +12,7 @@
|
|
|
12
12
|
|
|
13
13
|
import type { IncomingMessage, ServerResponse } from "node:http";
|
|
14
14
|
import type { RouteContext } from "./routes-core.js";
|
|
15
|
-
import { VC0A_ENABLED } from "../../src/config.js";
|
|
15
|
+
import { VC0A_ENABLED, ML5D_ENABLED } from "../../src/config.js";
|
|
16
16
|
import { readEvalRows } from "../../src/vector-cortex/eval/persist.js";
|
|
17
17
|
import { summarizeEvalRows } from "../../src/vector-cortex/eval/reader.js";
|
|
18
18
|
import { sendJson } from "./routes-vector-cortex-shared.js";
|
|
@@ -53,6 +53,9 @@ export function handleVectorCortexEvaluation(
|
|
|
53
53
|
total: summary.histogram.total,
|
|
54
54
|
},
|
|
55
55
|
rejects: [], // VC0C wires live breaker/reject telemetry here
|
|
56
|
+
// ML5-D: additive, present only when the flag is enabled → the client can
|
|
57
|
+
// omit the ModelImprovementCard when off (byte-identical to ML5-C-era tab).
|
|
58
|
+
...(ML5D_ENABLED() ? { ml5dEnabled: true } : {}),
|
|
56
59
|
updatedAt: new Date().toISOString(),
|
|
57
60
|
status: deriveVcStatus({ enabled, hasData: summary.samples > 0 }),
|
|
58
61
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "pi-mega-compact",
|
|
3
|
-
"version": "0.20.
|
|
3
|
+
"version": "0.20.53",
|
|
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,51 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* config/vector-cortex-enc2budget.ts — ENC-2a operator-configurable native
|
|
3
|
+
* onnxruntime install-budget knob (dashboard Settings surface).
|
|
4
|
+
*
|
|
5
|
+
* Sibling of vector-cortex-enc1a.ts / vector-cortex-enc1b.ts so vector-cortex.ts
|
|
6
|
+
* stays under the 300-line soft limit (soft-as-hard gate). vector-cortex.ts
|
|
7
|
+
* re-exports the flag + constants below and root src/config.ts re-exports them,
|
|
8
|
+
* so no consumer import path changes.
|
|
9
|
+
*
|
|
10
|
+
* ENC-2a exposes the runtime's operator knob `MEGACOMPACT_NATIVE_ORT_BUDGET_MIB`
|
|
11
|
+
* as a dashboard Settings field. The knob itself is read at runtime by
|
|
12
|
+
* `installBudgetMib()` (`src/vector-cortex/encoder/decision.ts`) and gates the
|
|
13
|
+
* `budgetOk` decision in `src/vector-cortex/encoder/runtime-select.ts`. Setting
|
|
14
|
+
* it persists to the per-repo `.mega-compact.env` via the same upsert-writer
|
|
15
|
+
* path ENC-1a/ENC-1b use (never the global state dir — see the
|
|
16
|
+
* `statedir-per-repo-vs-global` memory).
|
|
17
|
+
*
|
|
18
|
+
* Bounds (mirror `decision.ts` clamp): positive integer, 1..8192 MiB. Out-of-
|
|
19
|
+
* range input is rejected by validation (400) and falls back to the default
|
|
20
|
+
* (300) in `installBudgetMib()` at runtime. Default 300 MiB was set on
|
|
21
|
+
* 2026-08-07 when the user lifted the prior 80 MiB restriction ("remove the
|
|
22
|
+
* 80mb limit that wasn't my design decision" → "set it to a number that is in
|
|
23
|
+
* the dashboard that defaults to lets say 300mb").
|
|
24
|
+
*
|
|
25
|
+
* `MEGACOMPACT_ENC_2BUDGET=0` disables: no new GET fields, no writer branch, no
|
|
26
|
+
* new Settings rows — byte-identical to the ENC-1b predecessor. The flag MUST
|
|
27
|
+
* also be a dashboard SETTINGS toggle (visible in config UI, never in
|
|
28
|
+
* EXCLUDED_SETTINGS — see `feedback_dashboard-flags-toggleable` memory).
|
|
29
|
+
*
|
|
30
|
+
* Pi-agnostic, dependency-free (PREVENT-PI-004 / PREVENT-011).
|
|
31
|
+
*/
|
|
32
|
+
|
|
33
|
+
import { sprintFlag } from "./vector-cortex-flag.js";
|
|
34
|
+
|
|
35
|
+
/** ENC-2a knob: persisted env name, read by `installBudgetMib()` at runtime. */
|
|
36
|
+
export const ENC_2BUDGET_NATIVE_ORT_BUDGET_ENV = "MEGACOMPACT_NATIVE_ORT_BUDGET_MIB";
|
|
37
|
+
|
|
38
|
+
/** Upper bound on the budget (MiB). Mirrors decision.ts's clamp. */
|
|
39
|
+
export const ENC_2BUDGET_MAX_MIB = 8192;
|
|
40
|
+
|
|
41
|
+
/** Default budget (MiB) when the env var is unset or invalid. */
|
|
42
|
+
export const ENC_2BUDGET_DEFAULT_MIB = 300;
|
|
43
|
+
|
|
44
|
+
/**
|
|
45
|
+
* ENC-2a — operator-configurable native install budget Settings surface.
|
|
46
|
+
* Default ON. `MEGACOMPACT_ENC_2BUDGET=0` disables and is byte-identical to the
|
|
47
|
+
* ENC-1b predecessor: no new GET fields, no writer branch, no new Settings rows.
|
|
48
|
+
* This flag MUST also be a dashboard SETTINGS toggle (visible in config UI,
|
|
49
|
+
* never in EXCLUDED_SETTINGS).
|
|
50
|
+
*/
|
|
51
|
+
export const ENC_2BUDGET_ENABLED = (): boolean => sprintFlag("MEGACOMPACT_ENC_2BUDGET");
|
|
@@ -71,6 +71,12 @@ export {
|
|
|
71
71
|
ENC_1B_ALLOW_REMOTE_EMBEDDER_ENV,
|
|
72
72
|
ENC_1B_ENCODER_NATIVE_ENV,
|
|
73
73
|
} from "./vector-cortex-enc1b.js";
|
|
74
|
+
export {
|
|
75
|
+
ENC_2BUDGET_ENABLED,
|
|
76
|
+
ENC_2BUDGET_NATIVE_ORT_BUDGET_ENV,
|
|
77
|
+
ENC_2BUDGET_MAX_MIB,
|
|
78
|
+
ENC_2BUDGET_DEFAULT_MIB,
|
|
79
|
+
} from "./vector-cortex-enc2budget.js";
|
|
74
80
|
// Breaker constants (TRIAD_RESILIENCE.md §breaker) extracted to vector-cortex-breakers.ts.
|
|
75
81
|
export {
|
|
76
82
|
BREAKER_WINDOW_MS,
|
package/src/config.ts
CHANGED
|
@@ -198,6 +198,10 @@ export {
|
|
|
198
198
|
ENC_0G_ENABLED,
|
|
199
199
|
ENC_1A_ENABLED,
|
|
200
200
|
ENC_1B_ENABLED,
|
|
201
|
+
ENC_2BUDGET_ENABLED,
|
|
202
|
+
ENC_2BUDGET_NATIVE_ORT_BUDGET_ENV,
|
|
203
|
+
ENC_2BUDGET_MAX_MIB,
|
|
204
|
+
ENC_2BUDGET_DEFAULT_MIB,
|
|
201
205
|
BREAKER_WINDOW_MS,
|
|
202
206
|
BREAKER_MIN_ATTEMPTS,
|
|
203
207
|
BREAKER_PERF_FAILURES,
|
|
@@ -3,9 +3,10 @@
|
|
|
3
3
|
*
|
|
4
4
|
* The durable EncoderBackendDecisionV1 record: which ONNX runtime backend the
|
|
5
5
|
* real learned encoder ships on (transformers.js/WASM vs onnxruntime-node
|
|
6
|
-
* native), whether the
|
|
7
|
-
*
|
|
8
|
-
* the
|
|
6
|
+
* native), whether the configurable install budget holds (default 300 MiB;
|
|
7
|
+
* operator-overridable via `MEGACOMPACT_NATIVE_ORT_BUDGET_MIB`), the per-platform
|
|
8
|
+
* install matrix, the opset baseline (locked 21 by ENC-0a), the license
|
|
9
|
+
* verdict, and the pinned model/tokenizer sha256 digests.
|
|
9
10
|
*
|
|
10
11
|
* ENC-0a is the DECISION + MEASUREMENT sprint: this contract is what the
|
|
11
12
|
* deterministic resolver (`scripts/encoder/resolve-backend-decision.mjs`) and
|
|
@@ -83,10 +84,40 @@ export interface EncoderBackendDecisionV1 {
|
|
|
83
84
|
}
|
|
84
85
|
|
|
85
86
|
/**
|
|
86
|
-
* The
|
|
87
|
-
*
|
|
87
|
+
* The operator-configurable native-ort install byte-budget (MiB). Default 300
|
|
88
|
+
* (shipped 5-platform ~160 MiB comfortably fits); override via
|
|
89
|
+
* `MEGACOMPACT_NATIVE_ORT_BUDGET_MIB`. Safe upper clamp `INSTALL_BUDGET_CLAMP_MIB`
|
|
90
|
+
* rejects absurd values. Backend qualifies (`budgetOk`) iff the shipped
|
|
91
|
+
* byte-count fits the configured budget.
|
|
88
92
|
*/
|
|
89
|
-
export const
|
|
93
|
+
export const INSTALL_BUDGET_CLAMP_MIB = 8192;
|
|
94
|
+
export const INSTALL_BUDGET_DEFAULT_MIB = 300;
|
|
95
|
+
|
|
96
|
+
/**
|
|
97
|
+
* Pure resolver: given a raw string (or null/undefined when the env var is
|
|
98
|
+
* unset), return the integer budget the runtime will use. Out-of-range /
|
|
99
|
+
* non-integer / empty input falls back to the default. Exported so the
|
|
100
|
+
* dashboard Settings surface can compute the EFFECTIVE operand from a
|
|
101
|
+
* persisted-but-not-yet-env-loaded value (the operator just POSTed a new
|
|
102
|
+
* budget to disk; the running process has not sourced `.mega-compact.env`,
|
|
103
|
+
* so `installBudgetMib()` reads the stale env, but the dashboard should show
|
|
104
|
+
* what the runtime WILL use after the restart the dashboard itself tells the
|
|
105
|
+
* operator is required).
|
|
106
|
+
*/
|
|
107
|
+
export function resolveInstallBudgetMib(
|
|
108
|
+
raw: string | null | undefined,
|
|
109
|
+
): number {
|
|
110
|
+
if (raw === undefined || raw === null || raw === "") return INSTALL_BUDGET_DEFAULT_MIB;
|
|
111
|
+
const n = Number(raw);
|
|
112
|
+
if (!Number.isInteger(n) || n <= 0 || n > INSTALL_BUDGET_CLAMP_MIB) {
|
|
113
|
+
return INSTALL_BUDGET_DEFAULT_MIB;
|
|
114
|
+
}
|
|
115
|
+
return n;
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
export function installBudgetMib(): number {
|
|
119
|
+
return resolveInstallBudgetMib(process.env.MEGACOMPACT_NATIVE_ORT_BUDGET_MIB);
|
|
120
|
+
}
|
|
90
121
|
|
|
91
122
|
/** The p95 latency gate at 512 tokens / 4 threads on linux-x64 (ms). */
|
|
92
123
|
export const ENCODER_DECISION_P95_MS = 40;
|
|
@@ -25,6 +25,7 @@ import {
|
|
|
25
25
|
} from "./types.js";
|
|
26
26
|
import type { BenchResultV1 } from "./bench-export.js";
|
|
27
27
|
import { ML5C_ENABLED, ENC_0E_ENABLED } from "../../config/vector-cortex.js";
|
|
28
|
+
import { installBudgetMib } from "./decision.js";
|
|
28
29
|
import type { EncoderPlatformRow } from "./decision.js";
|
|
29
30
|
import {
|
|
30
31
|
DARWIN_X64_DEMOTION_REASON,
|
|
@@ -53,7 +54,7 @@ export interface RuntimeSelectionInput {
|
|
|
53
54
|
export interface RuntimeSelectionResult {
|
|
54
55
|
/** The chosen backend. */
|
|
55
56
|
readonly backend: RuntimeBackendChoice;
|
|
56
|
-
/** HG-3 closure state: whether the
|
|
57
|
+
/** HG-3 closure state: whether the operator-configured install budget (`MEGACOMPACT_NATIVE_ORT_BUDGET_MIB`, default 300 MiB) is satisfied. */
|
|
57
58
|
readonly budgetOk: boolean;
|
|
58
59
|
/** The measured p95 (ms) that drove the decision, from BenchResultV1. */
|
|
59
60
|
readonly p95Ms: number | null;
|
|
@@ -69,17 +70,14 @@ export interface RuntimeSelectionResult {
|
|
|
69
70
|
readonly demotionReason: string | null;
|
|
70
71
|
}
|
|
71
72
|
|
|
72
|
-
/** The 80 MiB install budget in bytes (the HG-3 ceiling, unamended). */
|
|
73
|
-
export const RUNTIME_NATIVE_INSTALL_BUDGET_MIB = 80;
|
|
74
|
-
|
|
75
73
|
/**
|
|
76
74
|
* Per-platform optionalDependency footprint of onnxruntime-node (MiB, approx).
|
|
77
75
|
* These sum to ~160 MiB SHIPPED in the npm package (every target platform is
|
|
78
|
-
* included so the resolver lands on a concrete row at install time)
|
|
79
|
-
*
|
|
80
|
-
*
|
|
81
|
-
*
|
|
82
|
-
*
|
|
76
|
+
* included so the resolver lands on a concrete row at install time). Compared
|
|
77
|
+
* against the configurable install budget (`installBudgetMib()`, default 300
|
|
78
|
+
* MiB) to set `budgetOk` — the per-host INSTALLED footprint (one row only,
|
|
79
|
+
* 28–35 MiB) is irrelevant to this ceiling; the budget covers the shipped
|
|
80
|
+
* tarball, not the single-platform install.
|
|
83
81
|
*/
|
|
84
82
|
export const NATIVE_FOOTPRINT_MIB: Readonly<Record<EncoderPlatform, number>> = {
|
|
85
83
|
"linux-x64": 33,
|
|
@@ -132,41 +130,43 @@ export function selectRuntimeBackend(input: RuntimeSelectionInput): RuntimeSelec
|
|
|
132
130
|
}
|
|
133
131
|
|
|
134
132
|
// Native opt-in short-circuits: operator explicitly wants the native path.
|
|
135
|
-
// The
|
|
136
|
-
//
|
|
137
|
-
//
|
|
138
|
-
//
|
|
139
|
-
//
|
|
133
|
+
// The budget compares the SHIPPED byte-count (sum across every platform row
|
|
134
|
+
// in the package's optionalDependencies map) against the configurable
|
|
135
|
+
// `installBudgetMib()` ceiling (default 300 MiB; operator-overridable). At
|
|
136
|
+
// the default, shipped ~160 MiB fits — budgetOk:true. The operator may lower
|
|
137
|
+
// it (e.g. 100) to surface a budget breach in `budgetOk:false` and the
|
|
138
|
+
// rationale string; the decision rule does not gate on it.
|
|
140
139
|
if (input.nativeOptIn) {
|
|
141
140
|
const shippedMib = Object.values(NATIVE_FOOTPRINT_MIB).reduce((a, b) => a + b, 0);
|
|
141
|
+
const budgetMib = installBudgetMib();
|
|
142
142
|
return {
|
|
143
143
|
backend: "native",
|
|
144
|
-
budgetOk: shippedMib <=
|
|
144
|
+
budgetOk: shippedMib <= budgetMib,
|
|
145
145
|
p95Ms: input.benchRecord?.p95Ms ?? null,
|
|
146
146
|
platform: input.platform,
|
|
147
|
-
rationale: `native opt-in (MEGACOMPACT_ENCODER_NATIVE=1); shipped ${shippedMib} MiB across 5 platforms
|
|
147
|
+
rationale: `native opt-in (MEGACOMPACT_ENCODER_NATIVE=1); shipped ${shippedMib} MiB across 5 platforms vs ${budgetMib} MiB budget`,
|
|
148
148
|
demotionReason: null,
|
|
149
149
|
};
|
|
150
150
|
}
|
|
151
151
|
|
|
152
152
|
// No bench record or degraded (gates.all:false) → WASM cannot qualify (the
|
|
153
153
|
// placeholder 42-byte asset has no measured real p95), so native is selected
|
|
154
|
-
// with the SAME
|
|
155
|
-
// evidence records the closed HG-3 amendment.
|
|
154
|
+
// with the SAME budget comparison as the opt-in path above (configurable).
|
|
156
155
|
if (!input.benchRecord || !input.benchRecord.gates.all || input.benchRecord.p95Ms === null) {
|
|
157
156
|
const shippedMib = Object.values(NATIVE_FOOTPRINT_MIB).reduce((a, b) => a + b, 0);
|
|
157
|
+
const budgetMib = installBudgetMib();
|
|
158
158
|
return {
|
|
159
159
|
backend: "native",
|
|
160
|
-
budgetOk:
|
|
160
|
+
budgetOk: shippedMib <= budgetMib,
|
|
161
161
|
p95Ms: input.benchRecord?.p95Ms ?? null,
|
|
162
162
|
platform: input.platform,
|
|
163
|
-
rationale: `no qualifying bench record — native fallback
|
|
163
|
+
rationale: `no qualifying bench record — native fallback (shipped ${shippedMib} MiB vs ${budgetMib} MiB budget)`,
|
|
164
164
|
demotionReason: null,
|
|
165
165
|
};
|
|
166
166
|
}
|
|
167
167
|
|
|
168
168
|
// The decision rule: WASM iff p95 <= 40 ms (linux-x64, 512 tokens, 4 threads) —
|
|
169
|
-
// native required otherwise, with the same budget
|
|
169
|
+
// native required otherwise, with the same configurable budget comparison.
|
|
170
170
|
if (input.benchRecord.p95Ms <= ENCODER_LATENCY_P95_MS) {
|
|
171
171
|
return {
|
|
172
172
|
backend: "wasm",
|
|
@@ -178,12 +178,14 @@ export function selectRuntimeBackend(input: RuntimeSelectionInput): RuntimeSelec
|
|
|
178
178
|
};
|
|
179
179
|
}
|
|
180
180
|
|
|
181
|
+
const shippedMib = Object.values(NATIVE_FOOTPRINT_MIB).reduce((a, b) => a + b, 0);
|
|
182
|
+
const budgetMib = installBudgetMib();
|
|
181
183
|
return {
|
|
182
184
|
backend: "native",
|
|
183
|
-
budgetOk:
|
|
185
|
+
budgetOk: shippedMib <= budgetMib,
|
|
184
186
|
p95Ms: input.benchRecord.p95Ms,
|
|
185
187
|
platform: input.platform,
|
|
186
|
-
rationale: `native required: p95 ${input.benchRecord.p95Ms}ms > ${ENCODER_LATENCY_P95_MS}ms on WASM`,
|
|
188
|
+
rationale: `native required: p95 ${input.benchRecord.p95Ms}ms > ${ENCODER_LATENCY_P95_MS}ms on WASM (shipped ${shippedMib} MiB vs ${budgetMib} MiB budget)`,
|
|
187
189
|
demotionReason: null,
|
|
188
190
|
};
|
|
189
191
|
}
|
|
@@ -85,11 +85,11 @@ export const SETUP_CORTEX_BLOCKERS: readonly SetupCortexBlockerV1[] = [
|
|
|
85
85
|
},
|
|
86
86
|
{
|
|
87
87
|
id: "HG-3",
|
|
88
|
-
title: "onnxruntime-node install
|
|
88
|
+
title: "native onnxruntime-node install path unresolved (needs operator install + probe), currently demoted to WASM",
|
|
89
89
|
severity: "blocker",
|
|
90
90
|
status: "open",
|
|
91
91
|
resolution:
|
|
92
|
-
"onnxruntime-node
|
|
92
|
+
"operator-run install of the pinned onnxruntime-node version into ~/.pi/mega-compact/native-ort, then re-run the ENC-0f qualification gate. The install byte-budget is operator-configurable (MEGACOMPACT_NATIVE_ORT_BUDGET_MIB, default 300 MiB; shipped 5-platform ~160 MiB fits at the default).",
|
|
93
93
|
},
|
|
94
94
|
{
|
|
95
95
|
id: "HG-4",
|