pi-mega-compact 0.20.52 → 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/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/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/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-Dika24if.js → AreaChart-COjQ_jJm.js} +2 -2
- package/extensions/dashboard-client/dist/assets/{AreaChart-Dika24if.js.map → AreaChart-COjQ_jJm.js.map} +1 -1
- package/extensions/dashboard-client/dist/assets/{BarChart-MxPpphaX.js → BarChart-eAIpwb8c.js} +2 -2
- package/extensions/dashboard-client/dist/assets/{BarChart-MxPpphaX.js.map → BarChart-eAIpwb8c.js.map} +1 -1
- package/extensions/dashboard-client/dist/assets/{CacheTab-e90mt1aw.js → CacheTab-BS_G9_YV.js} +2 -2
- package/extensions/dashboard-client/dist/assets/{CacheTab-e90mt1aw.js.map → CacheTab-BS_G9_YV.js.map} +1 -1
- package/extensions/dashboard-client/dist/assets/{EventsTab-CSl9CNXa.js → EventsTab-CDFk5d3P.js} +2 -2
- package/extensions/dashboard-client/dist/assets/{EventsTab-CSl9CNXa.js.map → EventsTab-CDFk5d3P.js.map} +1 -1
- package/extensions/dashboard-client/dist/assets/{HealthTab-CgUm8sp5.js → HealthTab-zFyPJb5b.js} +2 -2
- package/extensions/dashboard-client/dist/assets/{HealthTab-CgUm8sp5.js.map → HealthTab-zFyPJb5b.js.map} +1 -1
- package/extensions/dashboard-client/dist/assets/{MaintenanceTab-Dyhjzk6G.js → MaintenanceTab-DxJX4lXh.js} +2 -2
- package/extensions/dashboard-client/dist/assets/{MaintenanceTab-Dyhjzk6G.js.map → MaintenanceTab-DxJX4lXh.js.map} +1 -1
- package/extensions/dashboard-client/dist/assets/{MemoryMapTab-C1YR7CoA.js → MemoryMapTab-CRy5I6mg.js} +2 -2
- package/extensions/dashboard-client/dist/assets/{MemoryMapTab-C1YR7CoA.js.map → MemoryMapTab-CRy5I6mg.js.map} +1 -1
- package/extensions/dashboard-client/dist/assets/{MetricsTab-Bktg-486.js → MetricsTab-K4kPea0Q.js} +2 -2
- package/extensions/dashboard-client/dist/assets/{MetricsTab-Bktg-486.js.map → MetricsTab-K4kPea0Q.js.map} +1 -1
- package/extensions/dashboard-client/dist/assets/{OverviewTab-B7qTLQc2.js → OverviewTab-BZoJ1oOv.js} +2 -2
- package/extensions/dashboard-client/dist/assets/{OverviewTab-B7qTLQc2.js.map → OverviewTab-BZoJ1oOv.js.map} +1 -1
- package/extensions/dashboard-client/dist/assets/{ReposTab-Cr9W3KFw.js → ReposTab-uMFKxT0a.js} +2 -2
- package/extensions/dashboard-client/dist/assets/{ReposTab-Cr9W3KFw.js.map → ReposTab-uMFKxT0a.js.map} +1 -1
- package/extensions/dashboard-client/dist/assets/{SessionsTab-5x_LL9D8.js → SessionsTab-DDzmcCuH.js} +2 -2
- package/extensions/dashboard-client/dist/assets/{SessionsTab-5x_LL9D8.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-vB72Y7pk.js.map → SetupTab-KLTE-VKV.js.map} +1 -1
- package/extensions/dashboard-client/dist/assets/{TimeSavedCard-hsMc2BFT.js → TimeSavedCard-D_mBYAzE.js} +2 -2
- package/extensions/dashboard-client/dist/assets/{TimeSavedCard-hsMc2BFT.js.map → TimeSavedCard-D_mBYAzE.js.map} +1 -1
- package/extensions/dashboard-client/dist/assets/{TurnsTab-CjUIvDlj.js → TurnsTab-C6xr2lsO.js} +2 -2
- package/extensions/dashboard-client/dist/assets/{TurnsTab-CjUIvDlj.js.map → TurnsTab-C6xr2lsO.js.map} +1 -1
- package/extensions/dashboard-client/dist/assets/{VcStatusBadge-yDtZGtnm.js → VcStatusBadge-J0DVlxH0.js} +2 -2
- package/extensions/dashboard-client/dist/assets/{VcStatusBadge-yDtZGtnm.js.map → VcStatusBadge-J0DVlxH0.js.map} +1 -1
- package/extensions/dashboard-client/dist/assets/{VectorCortexTab-CvbaaeXD.js → VectorCortexTab-AvL73DpJ.js} +2 -2
- package/extensions/dashboard-client/dist/assets/{VectorCortexTab-CvbaaeXD.js.map → VectorCortexTab-AvL73DpJ.js.map} +1 -1
- package/extensions/dashboard-client/dist/assets/{WikiTab-c7K7kspY.js → WikiTab-DVcIWjLT.js} +2 -2
- package/extensions/dashboard-client/dist/assets/{WikiTab-c7K7kspY.js.map → WikiTab-DVcIWjLT.js.map} +1 -1
- package/extensions/dashboard-client/dist/assets/{button-vdqzHHyW.js → button-Cl_gFaIf.js} +2 -2
- package/extensions/dashboard-client/dist/assets/{button-vdqzHHyW.js.map → button-Cl_gFaIf.js.map} +1 -1
- package/extensions/dashboard-client/dist/assets/{card-DEzbxZLz.js → card-DMzHffVs.js} +2 -2
- package/extensions/dashboard-client/dist/assets/{card-DEzbxZLz.js.map → card-DMzHffVs.js.map} +1 -1
- package/extensions/dashboard-client/dist/assets/{client-extra-CJe2UKEK.js → client-extra-Dkkppa5C.js} +2 -2
- package/extensions/dashboard-client/dist/assets/{client-extra-CJe2UKEK.js.map → client-extra-Dkkppa5C.js.map} +1 -1
- package/extensions/dashboard-client/dist/assets/{generateCategoricalChart-Br3cS-GZ.js → generateCategoricalChart-Bi8zQmZN.js} +2 -2
- package/extensions/dashboard-client/dist/assets/{generateCategoricalChart-Br3cS-GZ.js.map → generateCategoricalChart-Bi8zQmZN.js.map} +1 -1
- package/extensions/dashboard-client/dist/assets/{index-CBMWirAB.js → index-mZRDesSq.js} +3 -3
- package/extensions/dashboard-client/dist/assets/{index-CBMWirAB.js.map → index-mZRDesSq.js.map} +1 -1
- package/extensions/dashboard-client/dist/assets/{switch-D_uPnF8u.js → switch-K_lsOl6x.js} +2 -2
- package/extensions/dashboard-client/dist/assets/{switch-D_uPnF8u.js.map → switch-K_lsOl6x.js.map} +1 -1
- package/extensions/dashboard-client/dist/assets/{toggle-DIaGjpNm.js → toggle-67IU2JLn.js} +2 -2
- package/extensions/dashboard-client/dist/assets/{toggle-DIaGjpNm.js.map → toggle-67IU2JLn.js.map} +1 -1
- package/extensions/dashboard-client/dist/assets/{useSSE-CJOcvXIe.js → useSSE-DiLgyP7C.js} +2 -2
- package/extensions/dashboard-client/dist/assets/{useSSE-CJOcvXIe.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-server/api-contracts/setup.ts +13 -0
- 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/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-vB72Y7pk.js +0 -3
|
@@ -0,0 +1,46 @@
|
|
|
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
|
+
import { sprintFlag } from "./vector-cortex-flag.js";
|
|
33
|
+
/** ENC-2a knob: persisted env name, read by `installBudgetMib()` at runtime. */
|
|
34
|
+
export const ENC_2BUDGET_NATIVE_ORT_BUDGET_ENV = "MEGACOMPACT_NATIVE_ORT_BUDGET_MIB";
|
|
35
|
+
/** Upper bound on the budget (MiB). Mirrors decision.ts's clamp. */
|
|
36
|
+
export const ENC_2BUDGET_MAX_MIB = 8192;
|
|
37
|
+
/** Default budget (MiB) when the env var is unset or invalid. */
|
|
38
|
+
export const ENC_2BUDGET_DEFAULT_MIB = 300;
|
|
39
|
+
/**
|
|
40
|
+
* ENC-2a — operator-configurable native install budget Settings surface.
|
|
41
|
+
* Default ON. `MEGACOMPACT_ENC_2BUDGET=0` disables and is byte-identical to the
|
|
42
|
+
* ENC-1b predecessor: no new GET fields, no writer branch, no new Settings rows.
|
|
43
|
+
* This flag MUST also be a dashboard SETTINGS toggle (visible in config UI,
|
|
44
|
+
* never in EXCLUDED_SETTINGS).
|
|
45
|
+
*/
|
|
46
|
+
export const ENC_2BUDGET_ENABLED = () => sprintFlag("MEGACOMPACT_ENC_2BUDGET");
|
|
@@ -34,5 +34,6 @@ export { ENC_0F_ENABLED } from "./vector-cortex-enc0f.js";
|
|
|
34
34
|
export { ENC_0G_ENABLED } from "./vector-cortex-enc0g.js";
|
|
35
35
|
export { ENC_1A_ENABLED } from "./vector-cortex-enc1a.js";
|
|
36
36
|
export { ENC_1B_ENABLED, ENC_1B_MAX_EMBEDDING_DIM, ENC_1B_EMBEDDING_DIM_ENV, ENC_1B_EMBEDDING_HEADERS_ENV, ENC_1B_ALLOW_REMOTE_EMBEDDER_ENV, ENC_1B_ENCODER_NATIVE_ENV, } from "./vector-cortex-enc1b.js";
|
|
37
|
+
export { ENC_2BUDGET_ENABLED, ENC_2BUDGET_NATIVE_ORT_BUDGET_ENV, ENC_2BUDGET_MAX_MIB, ENC_2BUDGET_DEFAULT_MIB, } from "./vector-cortex-enc2budget.js";
|
|
37
38
|
// Breaker constants (TRIAD_RESILIENCE.md §breaker) extracted to vector-cortex-breakers.ts.
|
|
38
39
|
export { BREAKER_WINDOW_MS, BREAKER_MIN_ATTEMPTS, BREAKER_PERF_FAILURES, BREAKER_PERF_FAILURE_RATE, BREAKER_CORRECTNESS_FAILURES, BREAKER_COOLDOWN_MS, BREAKER_PROBE_COUNT, BREAKER_RETRY_BASE_MS, BREAKER_RETRY_CAP_MS, BREAKER_RETRY_JITTER, BREAKER_HYSTERESIS_FAILURE_RATE, BREAKER_HYSTERESIS_BUDGET_P95_MS, BREAKER_MIN_HEALTHY_RESIDENCE_MS, } from "./vector-cortex-breakers.js";
|
package/dist/config.js
CHANGED
|
@@ -114,4 +114,4 @@ export const NEW_UI = () => ragEnabled("MEGACOMPACT_NEW_UI");
|
|
|
114
114
|
// default ON, `=0`/`_DISABLED` off. Re-exported from src/config/vector-cortex.ts
|
|
115
115
|
// so root consumers share one source of truth.
|
|
116
116
|
// ---------------------------------------------------------------------------
|
|
117
|
-
export { VC0A_ENABLED, VC0B_ENABLED, VC1A_ENABLED, VC0C_ENABLED, VC1B_ENABLED, VC1C_ENABLED, VC2A_ENABLED, VC2B_ENABLED, VC2C_ENABLED, VC3A_ENABLED, VC3B_ENABLED, VC3C_ENABLED, VC4A_ENABLED, VC4B_ENABLED, VC4C_ENABLED, VC5A_ENABLED, VC5B_ENABLED, VC5C_ENABLED, VC6A_ENABLED, VC6B_ENABLED, VC6C_ENABLED, VC7A_ENABLED, VC7B_ENABLED, VC7C_ENABLED, VC8A_ENABLED, VC8B_ENABLED, VC8C_ENABLED, VC9A_ENABLED, VC9B_ENABLED, VC9C_ENABLED, VC9D_ENABLED, PCC_ENABLED, ML5A_ENABLED, ML5B_ENABLED, ML5C_ENABLED, ML5D_ENABLED, ML5E_ENABLED, DEDUP_ATTR_ENABLED, ENC_0A_ENABLED, ENC_0B_ENABLED, ENC_0C_ENABLED, ENC_0D_ENABLED, ENC_0E_ENABLED, ENC_0F_ENABLED, ENC_0G_ENABLED, ENC_1A_ENABLED, ENC_1B_ENABLED, BREAKER_WINDOW_MS, BREAKER_MIN_ATTEMPTS, BREAKER_PERF_FAILURES, BREAKER_PERF_FAILURE_RATE, BREAKER_CORRECTNESS_FAILURES, BREAKER_COOLDOWN_MS, BREAKER_PROBE_COUNT, BREAKER_RETRY_BASE_MS, BREAKER_RETRY_CAP_MS, BREAKER_RETRY_JITTER, BREAKER_HYSTERESIS_FAILURE_RATE, BREAKER_HYSTERESIS_BUDGET_P95_MS, BREAKER_MIN_HEALTHY_RESIDENCE_MS, } from "./config/vector-cortex.js";
|
|
117
|
+
export { VC0A_ENABLED, VC0B_ENABLED, VC1A_ENABLED, VC0C_ENABLED, VC1B_ENABLED, VC1C_ENABLED, VC2A_ENABLED, VC2B_ENABLED, VC2C_ENABLED, VC3A_ENABLED, VC3B_ENABLED, VC3C_ENABLED, VC4A_ENABLED, VC4B_ENABLED, VC4C_ENABLED, VC5A_ENABLED, VC5B_ENABLED, VC5C_ENABLED, VC6A_ENABLED, VC6B_ENABLED, VC6C_ENABLED, VC7A_ENABLED, VC7B_ENABLED, VC7C_ENABLED, VC8A_ENABLED, VC8B_ENABLED, VC8C_ENABLED, VC9A_ENABLED, VC9B_ENABLED, VC9C_ENABLED, VC9D_ENABLED, PCC_ENABLED, ML5A_ENABLED, ML5B_ENABLED, ML5C_ENABLED, ML5D_ENABLED, ML5E_ENABLED, DEDUP_ATTR_ENABLED, ENC_0A_ENABLED, ENC_0B_ENABLED, ENC_0C_ENABLED, ENC_0D_ENABLED, ENC_0E_ENABLED, ENC_0F_ENABLED, ENC_0G_ENABLED, ENC_1A_ENABLED, ENC_1B_ENABLED, ENC_2BUDGET_ENABLED, ENC_2BUDGET_NATIVE_ORT_BUDGET_ENV, ENC_2BUDGET_MAX_MIB, ENC_2BUDGET_DEFAULT_MIB, BREAKER_WINDOW_MS, BREAKER_MIN_ATTEMPTS, BREAKER_PERF_FAILURES, BREAKER_PERF_FAILURE_RATE, BREAKER_CORRECTNESS_FAILURES, BREAKER_COOLDOWN_MS, BREAKER_PROBE_COUNT, BREAKER_RETRY_BASE_MS, BREAKER_RETRY_CAP_MS, BREAKER_RETRY_JITTER, BREAKER_HYSTERESIS_FAILURE_RATE, BREAKER_HYSTERESIS_BUDGET_P95_MS, BREAKER_MIN_HEALTHY_RESIDENCE_MS, } from "./config/vector-cortex.js";
|
|
@@ -67,5 +67,6 @@ export const VECTOR_CORTEX_SETTINGS = {
|
|
|
67
67
|
boolDirect("MEGACOMPACT_ENC_0G", "ENC-0g Setup Cortex honest state (verdict override + live blockers)", "ENC-0g makes the Setup Cortex status route honest: reads the ENC-0f QualificationV1 record (when ENC_0F is ON and a record exists) and lets its verdict override the structural verify for the qualification field; computes the blocker list from (platform, record, manifest head-count) with corrected HG statuses/wording; re-derives VC9B action gating from live blockers. OFF = verdict from verifyEncoderAsset alone, static SETUP_CORTEX_BLOCKERS, static action gating (byte-identical ENC-0f predecessor).", true),
|
|
68
68
|
boolDirect("MEGACOMPACT_ENC_1A", "ENC-1a external embedder API key + endpoint Settings fields", "ENC-1a adds a Settings-visible field pair for the external embedder endpoint URL + optional Bearer API key, persisted by the setup-configure writer branch to the per-repo .mega-compact.env (MEGACOMPACT_EMBEDDING_URL / MEGACOMPACT_EMBEDDING_KEY). The GET status route echoes the endpoint URL and reports embeddingApiKeySet as a boolean ONLY — the raw key is never returned. OFF = no new GET fields, no writer branch, no new Settings text rows (byte-identical ENC-0g predecessor).", true),
|
|
69
69
|
boolDirect("MEGACOMPACT_ENC_1B", "ENC-1b ONNX runtime backend + embedder API settings", "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).", true),
|
|
70
|
+
boolDirect("MEGACOMPACT_ENC_2BUDGET", "ENC-2a operator-configurable native install-budget knob", "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).", true),
|
|
70
71
|
],
|
|
71
72
|
};
|
|
@@ -0,0 +1,155 @@
|
|
|
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
|
+
import { writeFileSync, mkdirSync, readFileSync, existsSync } from "node:fs";
|
|
25
|
+
import { join } from "node:path";
|
|
26
|
+
import { ENC_2BUDGET_ENABLED, ENC_2BUDGET_MAX_MIB, ENC_2BUDGET_NATIVE_ORT_BUDGET_ENV, } from "../../src/config/vector-cortex.js";
|
|
27
|
+
import { installBudgetMib, resolveInstallBudgetMib, } from "../../src/vector-cortex/encoder/decision.js";
|
|
28
|
+
function envPath(stateDir) {
|
|
29
|
+
return join(stateDir, ".mega-compact.env");
|
|
30
|
+
}
|
|
31
|
+
/** Extract the value of `export MEGACOMPACT_X="..."` (or unquoted) from a line. */
|
|
32
|
+
function lineValue(line, key) {
|
|
33
|
+
const m = line.match(new RegExp(`^export\\s+${key}=(.*)$`));
|
|
34
|
+
if (!m)
|
|
35
|
+
return null;
|
|
36
|
+
const rest = m[1].trim();
|
|
37
|
+
if (rest.length === 0)
|
|
38
|
+
return null;
|
|
39
|
+
const q = rest.match(/^"([^"]*)"$/);
|
|
40
|
+
return q ? q[1] : rest;
|
|
41
|
+
}
|
|
42
|
+
/** True when the payload carries the ENC-2a key (flag-gated). */
|
|
43
|
+
export function wantsEnc2Budget(body) {
|
|
44
|
+
return ENC_2BUDGET_ENABLED() && typeof body.nativeOrtBudgetMib === "string";
|
|
45
|
+
}
|
|
46
|
+
/** Read the ENC-2a knob from the per-repo `.mega-compact.env`. Returns the raw
|
|
47
|
+
* persisted string when present, or null when absent. */
|
|
48
|
+
export function readEnc2BudgetEnv(stateDir) {
|
|
49
|
+
try {
|
|
50
|
+
const p = envPath(stateDir);
|
|
51
|
+
if (!existsSync(p))
|
|
52
|
+
return { raw: null };
|
|
53
|
+
const lines = readFileSync(p, "utf8").split(/\r?\n/);
|
|
54
|
+
for (const line of lines) {
|
|
55
|
+
const v = lineValue(line, ENC_2BUDGET_NATIVE_ORT_BUDGET_ENV);
|
|
56
|
+
if (v !== null && v.length > 0)
|
|
57
|
+
return { raw: v };
|
|
58
|
+
}
|
|
59
|
+
return { raw: null };
|
|
60
|
+
}
|
|
61
|
+
catch {
|
|
62
|
+
return { raw: null };
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
/**
|
|
66
|
+
* ENC-2a additive GET status fields. Omitted when flag-off. Surfaces the raw
|
|
67
|
+
* persisted value (when set) AND the effective runtime operand — the integer
|
|
68
|
+
* MiB `installBudgetMib()` actually resolves to. Reading `installBudgetMib()`
|
|
69
|
+
* here (instead of reimplementing the clamp) keeps the dashboard honest when
|
|
70
|
+
* the env var is unset or out-of-range.
|
|
71
|
+
*/
|
|
72
|
+
export function enc2BudgetStatusFields(stateDir) {
|
|
73
|
+
if (!ENC_2BUDGET_ENABLED())
|
|
74
|
+
return {};
|
|
75
|
+
const { raw } = readEnc2BudgetEnv(stateDir);
|
|
76
|
+
// The EFFECTIVE operand is what the runtime WILL use: if a value has been
|
|
77
|
+
// persisted to the disk file, resolve THAT through the clamp (the operator
|
|
78
|
+
// just POSTed it; the running process has not re-sourced `.mega-compact.env`
|
|
79
|
+
// yet so `installBudgetMib()` reads the stale env). On restart the saved
|
|
80
|
+
// value is what the runtime loads. When nothing is persisted, fall back to
|
|
81
|
+
// the live env var / process.env (= `installBudgetMib()`).
|
|
82
|
+
const effective = raw !== null ? resolveInstallBudgetMib(raw) : installBudgetMib();
|
|
83
|
+
return {
|
|
84
|
+
...(raw !== null ? { nativeOrtBudgetMib: raw } : {}),
|
|
85
|
+
nativeOrtBudgetEffectiveMib: String(effective),
|
|
86
|
+
};
|
|
87
|
+
}
|
|
88
|
+
/** Upsert the ENC-2a knob into the per-repo `.mega-compact.env`. Creates the
|
|
89
|
+
* file if absent; preserves every unrelated line; never deletes other keys.
|
|
90
|
+
* `entries.raw === null` leaves the key's line untouched. */
|
|
91
|
+
export function writeEnc2BudgetEnv(stateDir, entries) {
|
|
92
|
+
const p = envPath(stateDir);
|
|
93
|
+
const existingLines = existsSync(p) ? readFileSync(p, "utf8").split(/\r?\n/) : [];
|
|
94
|
+
const out = [];
|
|
95
|
+
let written = false;
|
|
96
|
+
for (const line of existingLines) {
|
|
97
|
+
if (entries.raw !== null &&
|
|
98
|
+
entries.raw !== undefined &&
|
|
99
|
+
lineValue(line, ENC_2BUDGET_NATIVE_ORT_BUDGET_ENV) !== null) {
|
|
100
|
+
out.push(`export ${ENC_2BUDGET_NATIVE_ORT_BUDGET_ENV}="${entries.raw}"`);
|
|
101
|
+
written = true;
|
|
102
|
+
continue;
|
|
103
|
+
}
|
|
104
|
+
out.push(line);
|
|
105
|
+
}
|
|
106
|
+
if (entries.raw !== null && entries.raw !== undefined && !written) {
|
|
107
|
+
out.push(`export ${ENC_2BUDGET_NATIVE_ORT_BUDGET_ENV}="${entries.raw}"`);
|
|
108
|
+
}
|
|
109
|
+
mkdirSync(stateDir, { recursive: true });
|
|
110
|
+
writeFileSync(p, out.join("\n"), "utf-8");
|
|
111
|
+
return p;
|
|
112
|
+
}
|
|
113
|
+
/** Validate `nativeOrtBudgetMib` as a positive integer string within
|
|
114
|
+
* `ENC_2BUDGET_MAX_MIB`. Returns `null` when valid, else the error code.
|
|
115
|
+
* Exported so the routes host (combined-payload path) and the aggregator share
|
|
116
|
+
* the same rule. */
|
|
117
|
+
export function validateNativeOrtBudgetMib(value) {
|
|
118
|
+
if (typeof value !== "string" || value.trim().length === 0)
|
|
119
|
+
return "invalid_native_ort_budget_mib";
|
|
120
|
+
if (!/^\d+$/.test(value))
|
|
121
|
+
return "invalid_native_ort_budget_mib";
|
|
122
|
+
const n = Number(value);
|
|
123
|
+
if (!Number.isSafeInteger(n) || n < 1 || n > ENC_2BUDGET_MAX_MIB) {
|
|
124
|
+
return "invalid_native_ort_budget_mib";
|
|
125
|
+
}
|
|
126
|
+
return null;
|
|
127
|
+
}
|
|
128
|
+
/**
|
|
129
|
+
* Combined-payload upsert: after the main embedder write has freshly written
|
|
130
|
+
* the per-repo env, append the ENC-2a key when carried alongside a valid
|
|
131
|
+
* embedder selection (flag-gated, additive). No-op when flag-off or no ENC-2a
|
|
132
|
+
* key present.
|
|
133
|
+
*/
|
|
134
|
+
export function tryEnc2BudgetInto(stateDir, body) {
|
|
135
|
+
if (!wantsEnc2Budget(body))
|
|
136
|
+
return;
|
|
137
|
+
writeEnc2BudgetEnv(stateDir, {
|
|
138
|
+
raw: typeof body.nativeOrtBudgetMib === "string" ? body.nativeOrtBudgetMib : null,
|
|
139
|
+
});
|
|
140
|
+
}
|
|
141
|
+
/**
|
|
142
|
+
* Combined-path validation: the routes host runs this before the combined
|
|
143
|
+
* upsert when a payload ALSO carries a valid embedder — returned as the error
|
|
144
|
+
* code string, or `null` if validation passes (or the flag is off).
|
|
145
|
+
*/
|
|
146
|
+
export function enc2BudgetValidateCombined(body) {
|
|
147
|
+
if (!ENC_2BUDGET_ENABLED())
|
|
148
|
+
return null;
|
|
149
|
+
if (body.nativeOrtBudgetMib !== undefined) {
|
|
150
|
+
const e = validateNativeOrtBudgetMib(body.nativeOrtBudgetMib);
|
|
151
|
+
if (e !== null)
|
|
152
|
+
return e;
|
|
153
|
+
}
|
|
154
|
+
return null;
|
|
155
|
+
}
|
|
@@ -13,6 +13,7 @@ import { join } from "node:path";
|
|
|
13
13
|
import { VC9D_ENABLED } from "../../src/config.js";
|
|
14
14
|
import { enc1aStatusFields, writeEnc1aEnv, tryEnc1aConfigure, wantsEnc1a } from "./routes-setup-enc1a.js";
|
|
15
15
|
import { enc1bStatusFields, tryEnc1bConfigure, tryEnc1bInto, enc1bValidateCombined } from "./routes-setup-enc1b.js";
|
|
16
|
+
import { enc2BudgetStatusFields, tryEnc2BudgetInto, enc2BudgetValidateCombined, } from "./routes-setup-enc2budget.js";
|
|
16
17
|
import { writeEmbedderEnv } from "./routes-setup-env-upsert.js";
|
|
17
18
|
import { detectOllama, detectLlamaCpp, detectOnnx, memoizedDetectOllama, memoizedDetectLlamaCpp, memoizedDetectOnnx, } from "./routes-setup-detect-cache.js";
|
|
18
19
|
// ---------------------------------------------------------------------------
|
|
@@ -71,6 +72,7 @@ export function handleSetupStatus(req, res, ctx) {
|
|
|
71
72
|
embedCache: process.env["MEGACOMPACT_EMBED_CACHE"] ?? null,
|
|
72
73
|
minilm: ["1", "true", "yes"].includes((process.env["MEGACOMPACT_MINILM"] ?? "").trim().toLowerCase()),
|
|
73
74
|
...enc1aStatusFields(ctx.stateDir), ...enc1bStatusFields(ctx.stateDir),
|
|
75
|
+
...enc2BudgetStatusFields(ctx.stateDir),
|
|
74
76
|
};
|
|
75
77
|
// guardrails-allow PREVENT-PI-004: loopback dashboard response (local)
|
|
76
78
|
res.writeHead(200, { "Content-Type": "application/json" });
|
|
@@ -194,6 +196,18 @@ export function handleSetupConfigure(req, res, ctx) {
|
|
|
194
196
|
res.end(JSON.stringify({ error: combinedError }));
|
|
195
197
|
return;
|
|
196
198
|
}
|
|
199
|
+
// ENC-2a combined-payload validation: when a payload carries a valid
|
|
200
|
+
// embedder PLUS the budget key, validate the budget BEFORE the upsert so
|
|
201
|
+
// the combined path is rejected with the same 400 code. Flag-off:
|
|
202
|
+
// enc2BudgetValidateCombined returns null (byte-identical predecessor —
|
|
203
|
+
// the unknown key falls through untouched).
|
|
204
|
+
const budgetCombinedError = enc2BudgetValidateCombined(body);
|
|
205
|
+
if (budgetCombinedError !== null) {
|
|
206
|
+
// guardrails-allow PREVENT-PI-004: loopback dashboard response (local)
|
|
207
|
+
res.writeHead(400, { "Content-Type": "application/json" });
|
|
208
|
+
res.end(JSON.stringify({ error: budgetCombinedError }));
|
|
209
|
+
return;
|
|
210
|
+
}
|
|
197
211
|
const embedder = body.embedder;
|
|
198
212
|
if (embedder !== "ollama" && embedder !== "llama" && embedder !== "trigram" && embedder !== "custom" && embedder !== "onnx") {
|
|
199
213
|
res.writeHead(400, { "Content-Type": "application/json" });
|
|
@@ -247,6 +261,7 @@ export function handleSetupConfigure(req, res, ctx) {
|
|
|
247
261
|
});
|
|
248
262
|
}
|
|
249
263
|
tryEnc1bInto(stateDir, body); // ENC-1b combined upsert (dim/headers/allow-remote/native)
|
|
264
|
+
tryEnc2BudgetInto(stateDir, body); // ENC-2a combined upsert (native budget MiB)
|
|
250
265
|
// Detect if the new config matches what's already active (no restart needed).
|
|
251
266
|
const currentUrl = process.env["MEGACOMPACT_EMBEDDING_URL"];
|
|
252
267
|
const alreadyActive = (resolvedUrl === null && !currentUrl) || (resolvedUrl !== null && currentUrl === resolvedUrl);
|
|
@@ -0,0 +1,46 @@
|
|
|
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
|
+
import { sprintFlag } from "./vector-cortex-flag.js";
|
|
33
|
+
/** ENC-2a knob: persisted env name, read by `installBudgetMib()` at runtime. */
|
|
34
|
+
export const ENC_2BUDGET_NATIVE_ORT_BUDGET_ENV = "MEGACOMPACT_NATIVE_ORT_BUDGET_MIB";
|
|
35
|
+
/** Upper bound on the budget (MiB). Mirrors decision.ts's clamp. */
|
|
36
|
+
export const ENC_2BUDGET_MAX_MIB = 8192;
|
|
37
|
+
/** Default budget (MiB) when the env var is unset or invalid. */
|
|
38
|
+
export const ENC_2BUDGET_DEFAULT_MIB = 300;
|
|
39
|
+
/**
|
|
40
|
+
* ENC-2a — operator-configurable native install budget Settings surface.
|
|
41
|
+
* Default ON. `MEGACOMPACT_ENC_2BUDGET=0` disables and is byte-identical to the
|
|
42
|
+
* ENC-1b predecessor: no new GET fields, no writer branch, no new Settings rows.
|
|
43
|
+
* This flag MUST also be a dashboard SETTINGS toggle (visible in config UI,
|
|
44
|
+
* never in EXCLUDED_SETTINGS).
|
|
45
|
+
*/
|
|
46
|
+
export const ENC_2BUDGET_ENABLED = () => sprintFlag("MEGACOMPACT_ENC_2BUDGET");
|
|
@@ -34,5 +34,6 @@ export { ENC_0F_ENABLED } from "./vector-cortex-enc0f.js";
|
|
|
34
34
|
export { ENC_0G_ENABLED } from "./vector-cortex-enc0g.js";
|
|
35
35
|
export { ENC_1A_ENABLED } from "./vector-cortex-enc1a.js";
|
|
36
36
|
export { ENC_1B_ENABLED, ENC_1B_MAX_EMBEDDING_DIM, ENC_1B_EMBEDDING_DIM_ENV, ENC_1B_EMBEDDING_HEADERS_ENV, ENC_1B_ALLOW_REMOTE_EMBEDDER_ENV, ENC_1B_ENCODER_NATIVE_ENV, } from "./vector-cortex-enc1b.js";
|
|
37
|
+
export { ENC_2BUDGET_ENABLED, ENC_2BUDGET_NATIVE_ORT_BUDGET_ENV, ENC_2BUDGET_MAX_MIB, ENC_2BUDGET_DEFAULT_MIB, } from "./vector-cortex-enc2budget.js";
|
|
37
38
|
// Breaker constants (TRIAD_RESILIENCE.md §breaker) extracted to vector-cortex-breakers.ts.
|
|
38
39
|
export { BREAKER_WINDOW_MS, BREAKER_MIN_ATTEMPTS, BREAKER_PERF_FAILURES, BREAKER_PERF_FAILURE_RATE, BREAKER_CORRECTNESS_FAILURES, BREAKER_COOLDOWN_MS, BREAKER_PROBE_COUNT, BREAKER_RETRY_BASE_MS, BREAKER_RETRY_CAP_MS, BREAKER_RETRY_JITTER, BREAKER_HYSTERESIS_FAILURE_RATE, BREAKER_HYSTERESIS_BUDGET_P95_MS, BREAKER_MIN_HEALTHY_RESIDENCE_MS, } from "./vector-cortex-breakers.js";
|
package/dist/src/config.js
CHANGED
|
@@ -114,4 +114,4 @@ export const NEW_UI = () => ragEnabled("MEGACOMPACT_NEW_UI");
|
|
|
114
114
|
// default ON, `=0`/`_DISABLED` off. Re-exported from src/config/vector-cortex.ts
|
|
115
115
|
// so root consumers share one source of truth.
|
|
116
116
|
// ---------------------------------------------------------------------------
|
|
117
|
-
export { VC0A_ENABLED, VC0B_ENABLED, VC1A_ENABLED, VC0C_ENABLED, VC1B_ENABLED, VC1C_ENABLED, VC2A_ENABLED, VC2B_ENABLED, VC2C_ENABLED, VC3A_ENABLED, VC3B_ENABLED, VC3C_ENABLED, VC4A_ENABLED, VC4B_ENABLED, VC4C_ENABLED, VC5A_ENABLED, VC5B_ENABLED, VC5C_ENABLED, VC6A_ENABLED, VC6B_ENABLED, VC6C_ENABLED, VC7A_ENABLED, VC7B_ENABLED, VC7C_ENABLED, VC8A_ENABLED, VC8B_ENABLED, VC8C_ENABLED, VC9A_ENABLED, VC9B_ENABLED, VC9C_ENABLED, VC9D_ENABLED, PCC_ENABLED, ML5A_ENABLED, ML5B_ENABLED, ML5C_ENABLED, ML5D_ENABLED, ML5E_ENABLED, DEDUP_ATTR_ENABLED, ENC_0A_ENABLED, ENC_0B_ENABLED, ENC_0C_ENABLED, ENC_0D_ENABLED, ENC_0E_ENABLED, ENC_0F_ENABLED, ENC_0G_ENABLED, ENC_1A_ENABLED, ENC_1B_ENABLED, BREAKER_WINDOW_MS, BREAKER_MIN_ATTEMPTS, BREAKER_PERF_FAILURES, BREAKER_PERF_FAILURE_RATE, BREAKER_CORRECTNESS_FAILURES, BREAKER_COOLDOWN_MS, BREAKER_PROBE_COUNT, BREAKER_RETRY_BASE_MS, BREAKER_RETRY_CAP_MS, BREAKER_RETRY_JITTER, BREAKER_HYSTERESIS_FAILURE_RATE, BREAKER_HYSTERESIS_BUDGET_P95_MS, BREAKER_MIN_HEALTHY_RESIDENCE_MS, } from "./config/vector-cortex.js";
|
|
117
|
+
export { VC0A_ENABLED, VC0B_ENABLED, VC1A_ENABLED, VC0C_ENABLED, VC1B_ENABLED, VC1C_ENABLED, VC2A_ENABLED, VC2B_ENABLED, VC2C_ENABLED, VC3A_ENABLED, VC3B_ENABLED, VC3C_ENABLED, VC4A_ENABLED, VC4B_ENABLED, VC4C_ENABLED, VC5A_ENABLED, VC5B_ENABLED, VC5C_ENABLED, VC6A_ENABLED, VC6B_ENABLED, VC6C_ENABLED, VC7A_ENABLED, VC7B_ENABLED, VC7C_ENABLED, VC8A_ENABLED, VC8B_ENABLED, VC8C_ENABLED, VC9A_ENABLED, VC9B_ENABLED, VC9C_ENABLED, VC9D_ENABLED, PCC_ENABLED, ML5A_ENABLED, ML5B_ENABLED, ML5C_ENABLED, ML5D_ENABLED, ML5E_ENABLED, DEDUP_ATTR_ENABLED, ENC_0A_ENABLED, ENC_0B_ENABLED, ENC_0C_ENABLED, ENC_0D_ENABLED, ENC_0E_ENABLED, ENC_0F_ENABLED, ENC_0G_ENABLED, ENC_1A_ENABLED, ENC_1B_ENABLED, ENC_2BUDGET_ENABLED, ENC_2BUDGET_NATIVE_ORT_BUDGET_ENV, ENC_2BUDGET_MAX_MIB, ENC_2BUDGET_DEFAULT_MIB, BREAKER_WINDOW_MS, BREAKER_MIN_ATTEMPTS, BREAKER_PERF_FAILURES, BREAKER_PERF_FAILURE_RATE, BREAKER_CORRECTNESS_FAILURES, BREAKER_COOLDOWN_MS, BREAKER_PROBE_COUNT, BREAKER_RETRY_BASE_MS, BREAKER_RETRY_CAP_MS, BREAKER_RETRY_JITTER, BREAKER_HYSTERESIS_FAILURE_RATE, BREAKER_HYSTERESIS_BUDGET_P95_MS, BREAKER_MIN_HEALTHY_RESIDENCE_MS, } from "./config/vector-cortex.js";
|
|
@@ -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
|
|
@@ -37,10 +38,37 @@ export const DARWIN_X64_DEMOTION_REASON = "darwin-x64: no native binary upstream
|
|
|
37
38
|
*/
|
|
38
39
|
export const DARWIN_X64_DEMOTION_REASON_SENTINEL = "darwin-x64: demoted to WASM (reason unavailable in platform matrix)";
|
|
39
40
|
/**
|
|
40
|
-
* The
|
|
41
|
-
*
|
|
41
|
+
* The operator-configurable native-ort install byte-budget (MiB). Default 300
|
|
42
|
+
* (shipped 5-platform ~160 MiB comfortably fits); override via
|
|
43
|
+
* `MEGACOMPACT_NATIVE_ORT_BUDGET_MIB`. Safe upper clamp `INSTALL_BUDGET_CLAMP_MIB`
|
|
44
|
+
* rejects absurd values. Backend qualifies (`budgetOk`) iff the shipped
|
|
45
|
+
* byte-count fits the configured budget.
|
|
42
46
|
*/
|
|
43
|
-
export const
|
|
47
|
+
export const INSTALL_BUDGET_CLAMP_MIB = 8192;
|
|
48
|
+
export const INSTALL_BUDGET_DEFAULT_MIB = 300;
|
|
49
|
+
/**
|
|
50
|
+
* Pure resolver: given a raw string (or null/undefined when the env var is
|
|
51
|
+
* unset), return the integer budget the runtime will use. Out-of-range /
|
|
52
|
+
* non-integer / empty input falls back to the default. Exported so the
|
|
53
|
+
* dashboard Settings surface can compute the EFFECTIVE operand from a
|
|
54
|
+
* persisted-but-not-yet-env-loaded value (the operator just POSTed a new
|
|
55
|
+
* budget to disk; the running process has not sourced `.mega-compact.env`,
|
|
56
|
+
* so `installBudgetMib()` reads the stale env, but the dashboard should show
|
|
57
|
+
* what the runtime WILL use after the restart the dashboard itself tells the
|
|
58
|
+
* operator is required).
|
|
59
|
+
*/
|
|
60
|
+
export function resolveInstallBudgetMib(raw) {
|
|
61
|
+
if (raw === undefined || raw === null || raw === "")
|
|
62
|
+
return INSTALL_BUDGET_DEFAULT_MIB;
|
|
63
|
+
const n = Number(raw);
|
|
64
|
+
if (!Number.isInteger(n) || n <= 0 || n > INSTALL_BUDGET_CLAMP_MIB) {
|
|
65
|
+
return INSTALL_BUDGET_DEFAULT_MIB;
|
|
66
|
+
}
|
|
67
|
+
return n;
|
|
68
|
+
}
|
|
69
|
+
export function installBudgetMib() {
|
|
70
|
+
return resolveInstallBudgetMib(process.env.MEGACOMPACT_NATIVE_ORT_BUDGET_MIB);
|
|
71
|
+
}
|
|
44
72
|
/** The p95 latency gate at 512 tokens / 4 threads on linux-x64 (ms). */
|
|
45
73
|
export const ENCODER_DECISION_P95_MS = 40;
|
|
46
74
|
/**
|
|
@@ -20,17 +20,16 @@
|
|
|
20
20
|
*/
|
|
21
21
|
import { ENCODER_LATENCY_P95_MS, } from "./types.js";
|
|
22
22
|
import { ML5C_ENABLED, ENC_0E_ENABLED } from "../../config/vector-cortex.js";
|
|
23
|
+
import { installBudgetMib } from "./decision.js";
|
|
23
24
|
import { DARWIN_X64_DEMOTION_REASON, DARWIN_X64_DEMOTION_REASON_SENTINEL, } from "./decision.js";
|
|
24
|
-
/** The 80 MiB install budget in bytes (the HG-3 ceiling, unamended). */
|
|
25
|
-
export const RUNTIME_NATIVE_INSTALL_BUDGET_MIB = 80;
|
|
26
25
|
/**
|
|
27
26
|
* Per-platform optionalDependency footprint of onnxruntime-node (MiB, approx).
|
|
28
27
|
* These sum to ~160 MiB SHIPPED in the npm package (every target platform is
|
|
29
|
-
* included so the resolver lands on a concrete row at install time)
|
|
30
|
-
*
|
|
31
|
-
*
|
|
32
|
-
*
|
|
33
|
-
*
|
|
28
|
+
* included so the resolver lands on a concrete row at install time). Compared
|
|
29
|
+
* against the configurable install budget (`installBudgetMib()`, default 300
|
|
30
|
+
* MiB) to set `budgetOk` — the per-host INSTALLED footprint (one row only,
|
|
31
|
+
* 28–35 MiB) is irrelevant to this ceiling; the budget covers the shipped
|
|
32
|
+
* tarball, not the single-platform install.
|
|
34
33
|
*/
|
|
35
34
|
export const NATIVE_FOOTPRINT_MIB = {
|
|
36
35
|
"linux-x64": 33,
|
|
@@ -80,39 +79,41 @@ export function selectRuntimeBackend(input) {
|
|
|
80
79
|
};
|
|
81
80
|
}
|
|
82
81
|
// Native opt-in short-circuits: operator explicitly wants the native path.
|
|
83
|
-
// The
|
|
84
|
-
//
|
|
85
|
-
//
|
|
86
|
-
//
|
|
87
|
-
//
|
|
82
|
+
// The budget compares the SHIPPED byte-count (sum across every platform row
|
|
83
|
+
// in the package's optionalDependencies map) against the configurable
|
|
84
|
+
// `installBudgetMib()` ceiling (default 300 MiB; operator-overridable). At
|
|
85
|
+
// the default, shipped ~160 MiB fits — budgetOk:true. The operator may lower
|
|
86
|
+
// it (e.g. 100) to surface a budget breach in `budgetOk:false` and the
|
|
87
|
+
// rationale string; the decision rule does not gate on it.
|
|
88
88
|
if (input.nativeOptIn) {
|
|
89
89
|
const shippedMib = Object.values(NATIVE_FOOTPRINT_MIB).reduce((a, b) => a + b, 0);
|
|
90
|
+
const budgetMib = installBudgetMib();
|
|
90
91
|
return {
|
|
91
92
|
backend: "native",
|
|
92
|
-
budgetOk: shippedMib <=
|
|
93
|
+
budgetOk: shippedMib <= budgetMib,
|
|
93
94
|
p95Ms: input.benchRecord?.p95Ms ?? null,
|
|
94
95
|
platform: input.platform,
|
|
95
|
-
rationale: `native opt-in (MEGACOMPACT_ENCODER_NATIVE=1); shipped ${shippedMib} MiB across 5 platforms
|
|
96
|
+
rationale: `native opt-in (MEGACOMPACT_ENCODER_NATIVE=1); shipped ${shippedMib} MiB across 5 platforms vs ${budgetMib} MiB budget`,
|
|
96
97
|
demotionReason: null,
|
|
97
98
|
};
|
|
98
99
|
}
|
|
99
100
|
// No bench record or degraded (gates.all:false) → WASM cannot qualify (the
|
|
100
101
|
// placeholder 42-byte asset has no measured real p95), so native is selected
|
|
101
|
-
// with the SAME
|
|
102
|
-
// evidence records the closed HG-3 amendment.
|
|
102
|
+
// with the SAME budget comparison as the opt-in path above (configurable).
|
|
103
103
|
if (!input.benchRecord || !input.benchRecord.gates.all || input.benchRecord.p95Ms === null) {
|
|
104
104
|
const shippedMib = Object.values(NATIVE_FOOTPRINT_MIB).reduce((a, b) => a + b, 0);
|
|
105
|
+
const budgetMib = installBudgetMib();
|
|
105
106
|
return {
|
|
106
107
|
backend: "native",
|
|
107
|
-
budgetOk:
|
|
108
|
+
budgetOk: shippedMib <= budgetMib,
|
|
108
109
|
p95Ms: input.benchRecord?.p95Ms ?? null,
|
|
109
110
|
platform: input.platform,
|
|
110
|
-
rationale: `no qualifying bench record — native fallback
|
|
111
|
+
rationale: `no qualifying bench record — native fallback (shipped ${shippedMib} MiB vs ${budgetMib} MiB budget)`,
|
|
111
112
|
demotionReason: null,
|
|
112
113
|
};
|
|
113
114
|
}
|
|
114
115
|
// The decision rule: WASM iff p95 <= 40 ms (linux-x64, 512 tokens, 4 threads) —
|
|
115
|
-
// native required otherwise, with the same budget
|
|
116
|
+
// native required otherwise, with the same configurable budget comparison.
|
|
116
117
|
if (input.benchRecord.p95Ms <= ENCODER_LATENCY_P95_MS) {
|
|
117
118
|
return {
|
|
118
119
|
backend: "wasm",
|
|
@@ -123,12 +124,14 @@ export function selectRuntimeBackend(input) {
|
|
|
123
124
|
demotionReason: null,
|
|
124
125
|
};
|
|
125
126
|
}
|
|
127
|
+
const shippedMib = Object.values(NATIVE_FOOTPRINT_MIB).reduce((a, b) => a + b, 0);
|
|
128
|
+
const budgetMib = installBudgetMib();
|
|
126
129
|
return {
|
|
127
130
|
backend: "native",
|
|
128
|
-
budgetOk:
|
|
131
|
+
budgetOk: shippedMib <= budgetMib,
|
|
129
132
|
p95Ms: input.benchRecord.p95Ms,
|
|
130
133
|
platform: input.platform,
|
|
131
|
-
rationale: `native required: p95 ${input.benchRecord.p95Ms}ms > ${ENCODER_LATENCY_P95_MS}ms on WASM`,
|
|
134
|
+
rationale: `native required: p95 ${input.benchRecord.p95Ms}ms > ${ENCODER_LATENCY_P95_MS}ms on WASM (shipped ${shippedMib} MiB vs ${budgetMib} MiB budget)`,
|
|
132
135
|
demotionReason: null,
|
|
133
136
|
};
|
|
134
137
|
}
|
|
@@ -52,10 +52,10 @@ export const SETUP_CORTEX_BLOCKERS = [
|
|
|
52
52
|
},
|
|
53
53
|
{
|
|
54
54
|
id: "HG-3",
|
|
55
|
-
title: "onnxruntime-node install
|
|
55
|
+
title: "native onnxruntime-node install path unresolved (needs operator install + probe), currently demoted to WASM",
|
|
56
56
|
severity: "blocker",
|
|
57
57
|
status: "open",
|
|
58
|
-
resolution: "onnxruntime-node
|
|
58
|
+
resolution: "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).",
|
|
59
59
|
},
|
|
60
60
|
{
|
|
61
61
|
id: "HG-4",
|
|
@@ -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
|
|
@@ -37,10 +38,37 @@ export const DARWIN_X64_DEMOTION_REASON = "darwin-x64: no native binary upstream
|
|
|
37
38
|
*/
|
|
38
39
|
export const DARWIN_X64_DEMOTION_REASON_SENTINEL = "darwin-x64: demoted to WASM (reason unavailable in platform matrix)";
|
|
39
40
|
/**
|
|
40
|
-
* The
|
|
41
|
-
*
|
|
41
|
+
* The operator-configurable native-ort install byte-budget (MiB). Default 300
|
|
42
|
+
* (shipped 5-platform ~160 MiB comfortably fits); override via
|
|
43
|
+
* `MEGACOMPACT_NATIVE_ORT_BUDGET_MIB`. Safe upper clamp `INSTALL_BUDGET_CLAMP_MIB`
|
|
44
|
+
* rejects absurd values. Backend qualifies (`budgetOk`) iff the shipped
|
|
45
|
+
* byte-count fits the configured budget.
|
|
42
46
|
*/
|
|
43
|
-
export const
|
|
47
|
+
export const INSTALL_BUDGET_CLAMP_MIB = 8192;
|
|
48
|
+
export const INSTALL_BUDGET_DEFAULT_MIB = 300;
|
|
49
|
+
/**
|
|
50
|
+
* Pure resolver: given a raw string (or null/undefined when the env var is
|
|
51
|
+
* unset), return the integer budget the runtime will use. Out-of-range /
|
|
52
|
+
* non-integer / empty input falls back to the default. Exported so the
|
|
53
|
+
* dashboard Settings surface can compute the EFFECTIVE operand from a
|
|
54
|
+
* persisted-but-not-yet-env-loaded value (the operator just POSTed a new
|
|
55
|
+
* budget to disk; the running process has not sourced `.mega-compact.env`,
|
|
56
|
+
* so `installBudgetMib()` reads the stale env, but the dashboard should show
|
|
57
|
+
* what the runtime WILL use after the restart the dashboard itself tells the
|
|
58
|
+
* operator is required).
|
|
59
|
+
*/
|
|
60
|
+
export function resolveInstallBudgetMib(raw) {
|
|
61
|
+
if (raw === undefined || raw === null || raw === "")
|
|
62
|
+
return INSTALL_BUDGET_DEFAULT_MIB;
|
|
63
|
+
const n = Number(raw);
|
|
64
|
+
if (!Number.isInteger(n) || n <= 0 || n > INSTALL_BUDGET_CLAMP_MIB) {
|
|
65
|
+
return INSTALL_BUDGET_DEFAULT_MIB;
|
|
66
|
+
}
|
|
67
|
+
return n;
|
|
68
|
+
}
|
|
69
|
+
export function installBudgetMib() {
|
|
70
|
+
return resolveInstallBudgetMib(process.env.MEGACOMPACT_NATIVE_ORT_BUDGET_MIB);
|
|
71
|
+
}
|
|
44
72
|
/** The p95 latency gate at 512 tokens / 4 threads on linux-x64 (ms). */
|
|
45
73
|
export const ENCODER_DECISION_P95_MS = 40;
|
|
46
74
|
/**
|