pi-mega-compact 0.20.14 → 0.20.16
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.js +20 -0
- package/dist/config.js +1 -1
- package/dist/extensions/dashboard-server/api-contracts/vector-cortex-diagnostics.js +35 -0
- package/dist/extensions/dashboard-server/route-dispatch.js +6 -0
- package/dist/extensions/dashboard-server/routes-rag-settings-vector-cortex.js +1 -0
- package/dist/extensions/dashboard-server/routes-vector-cortex-diagnostics.js +68 -0
- package/dist/src/config/vector-cortex.js +20 -0
- package/dist/src/config.js +1 -1
- package/dist/src/vector-cortex/cache/_diagnostics-fixture.js +31 -0
- package/dist/src/vector-cortex/cache/breaker.js +110 -0
- package/dist/src/vector-cortex/cache/diagnostics-emit.js +64 -0
- package/dist/src/vector-cortex/cache/diagnostics-types.js +15 -0
- package/dist/src/vector-cortex/cache/diagnostics.js +97 -0
- package/dist/src/vector-cortex/migrations/request-hash-v2-ops.js +154 -0
- package/dist/src/vector-cortex/migrations/request-hash-v2-types.js +30 -0
- package/dist/src/vector-cortex/migrations/request-hash-v2.js +42 -147
- package/dist/vector-cortex/cache/_diagnostics-fixture.js +31 -0
- package/dist/vector-cortex/cache/breaker.js +110 -0
- package/dist/vector-cortex/cache/diagnostics-emit.js +64 -0
- package/dist/vector-cortex/cache/diagnostics-types.js +15 -0
- package/dist/vector-cortex/cache/diagnostics.js +97 -0
- package/dist/vector-cortex/migrations/request-hash-v2-ops.js +154 -0
- package/dist/vector-cortex/migrations/request-hash-v2-types.js +30 -0
- package/dist/vector-cortex/migrations/request-hash-v2.js +42 -147
- package/extensions/dashboard-client/dist/assets/{AreaChart-VUd_iOtO.js → AreaChart-B_FKg8xJ.js} +2 -2
- package/extensions/dashboard-client/dist/assets/{AreaChart-VUd_iOtO.js.map → AreaChart-B_FKg8xJ.js.map} +1 -1
- package/extensions/dashboard-client/dist/assets/{BarChart-BoqeJ5mM.js → BarChart-BU5RJ0In.js} +2 -2
- package/extensions/dashboard-client/dist/assets/{BarChart-BoqeJ5mM.js.map → BarChart-BU5RJ0In.js.map} +1 -1
- package/extensions/dashboard-client/dist/assets/{CacheTab-1ON7meDK.js → CacheTab-CbX033mt.js} +2 -2
- package/extensions/dashboard-client/dist/assets/{CacheTab-1ON7meDK.js.map → CacheTab-CbX033mt.js.map} +1 -1
- package/extensions/dashboard-client/dist/assets/{EventsTab-Dr9eqt1k.js → EventsTab-D8Z_4gSB.js} +2 -2
- package/extensions/dashboard-client/dist/assets/{EventsTab-Dr9eqt1k.js.map → EventsTab-D8Z_4gSB.js.map} +1 -1
- package/extensions/dashboard-client/dist/assets/{HealthTab-Ciaigd4i.js → HealthTab-BUUkoQXo.js} +2 -2
- package/extensions/dashboard-client/dist/assets/{HealthTab-Ciaigd4i.js.map → HealthTab-BUUkoQXo.js.map} +1 -1
- package/extensions/dashboard-client/dist/assets/{MaintenanceTab-DjZRr3Lf.js → MaintenanceTab-DKZQmY1T.js} +2 -2
- package/extensions/dashboard-client/dist/assets/{MaintenanceTab-DjZRr3Lf.js.map → MaintenanceTab-DKZQmY1T.js.map} +1 -1
- package/extensions/dashboard-client/dist/assets/{MemoryMapTab-BpZXHA7j.js → MemoryMapTab-DwMGbe3h.js} +2 -2
- package/extensions/dashboard-client/dist/assets/{MemoryMapTab-BpZXHA7j.js.map → MemoryMapTab-DwMGbe3h.js.map} +1 -1
- package/extensions/dashboard-client/dist/assets/{MetricsTab-QemocY5k.js → MetricsTab-C85lieXW.js} +2 -2
- package/extensions/dashboard-client/dist/assets/{MetricsTab-QemocY5k.js.map → MetricsTab-C85lieXW.js.map} +1 -1
- package/extensions/dashboard-client/dist/assets/{OverviewTab-VtC1F-mO.js → OverviewTab-D7VPibBT.js} +2 -2
- package/extensions/dashboard-client/dist/assets/{OverviewTab-VtC1F-mO.js.map → OverviewTab-D7VPibBT.js.map} +1 -1
- package/extensions/dashboard-client/dist/assets/{ReposTab-CJD1cBxp.js → ReposTab-eIHk_mDG.js} +2 -2
- package/extensions/dashboard-client/dist/assets/{ReposTab-CJD1cBxp.js.map → ReposTab-eIHk_mDG.js.map} +1 -1
- package/extensions/dashboard-client/dist/assets/{SessionsTab-Cj0erPR4.js → SessionsTab-EYOHEzc3.js} +2 -2
- package/extensions/dashboard-client/dist/assets/{SessionsTab-Cj0erPR4.js.map → SessionsTab-EYOHEzc3.js.map} +1 -1
- package/extensions/dashboard-client/dist/assets/{SetupTab-AOVROZ4G.js → SetupTab-DXpiXu4i.js} +2 -2
- package/extensions/dashboard-client/dist/assets/{SetupTab-AOVROZ4G.js.map → SetupTab-DXpiXu4i.js.map} +1 -1
- package/extensions/dashboard-client/dist/assets/{TimeSavedCard-ZliVn8DH.js → TimeSavedCard-DUsUC_sm.js} +2 -2
- package/extensions/dashboard-client/dist/assets/{TimeSavedCard-ZliVn8DH.js.map → TimeSavedCard-DUsUC_sm.js.map} +1 -1
- package/extensions/dashboard-client/dist/assets/{TurnsTab-DsoTWeIh.js → TurnsTab-w7qdB0px.js} +2 -2
- package/extensions/dashboard-client/dist/assets/{TurnsTab-DsoTWeIh.js.map → TurnsTab-w7qdB0px.js.map} +1 -1
- package/extensions/dashboard-client/dist/assets/VectorCortexTab-BmgdxV5K.js +2 -0
- package/extensions/dashboard-client/dist/assets/VectorCortexTab-BmgdxV5K.js.map +1 -0
- package/extensions/dashboard-client/dist/assets/{WikiTab-CK8fcW1l.js → WikiTab-B4hwpXpw.js} +2 -2
- package/extensions/dashboard-client/dist/assets/{WikiTab-CK8fcW1l.js.map → WikiTab-B4hwpXpw.js.map} +1 -1
- package/extensions/dashboard-client/dist/assets/{button-DdPcvex1.js → button-BnbvfQjm.js} +2 -2
- package/extensions/dashboard-client/dist/assets/{button-DdPcvex1.js.map → button-BnbvfQjm.js.map} +1 -1
- package/extensions/dashboard-client/dist/assets/{card-DXFuZph_.js → card-DCyvWfpF.js} +2 -2
- package/extensions/dashboard-client/dist/assets/{card-DXFuZph_.js.map → card-DCyvWfpF.js.map} +1 -1
- package/extensions/dashboard-client/dist/assets/{generateCategoricalChart-BagDVGWn.js → generateCategoricalChart-b3HeKJLU.js} +2 -2
- package/extensions/dashboard-client/dist/assets/{generateCategoricalChart-BagDVGWn.js.map → generateCategoricalChart-b3HeKJLU.js.map} +1 -1
- package/extensions/dashboard-client/dist/assets/{index-DVdDtRY4.js → index-DhlcXMlE.js} +3 -3
- package/extensions/dashboard-client/dist/assets/{index-DVdDtRY4.js.map → index-DhlcXMlE.js.map} +1 -1
- package/extensions/dashboard-client/dist/assets/{switch-CtdtGyUR.js → switch-B74pQOFy.js} +2 -2
- package/extensions/dashboard-client/dist/assets/{switch-CtdtGyUR.js.map → switch-B74pQOFy.js.map} +1 -1
- package/extensions/dashboard-client/dist/assets/{toggle-Cvvwlbye.js → toggle-bXDrMX-A.js} +2 -2
- package/extensions/dashboard-client/dist/assets/{toggle-Cvvwlbye.js.map → toggle-bXDrMX-A.js.map} +1 -1
- package/extensions/dashboard-client/dist/assets/{useSSE-DvlceHjV.js → useSSE-Yq86SUA0.js} +2 -2
- package/extensions/dashboard-client/dist/assets/{useSSE-DvlceHjV.js.map → useSSE-Yq86SUA0.js.map} +1 -1
- package/extensions/dashboard-client/dist/index.html +1 -1
- package/extensions/dashboard-client/src/api/vector-cortex.ts +9 -0
- package/extensions/dashboard-client/src/tabs/VectorCortexDiagnosticsCard.tsx +46 -0
- package/extensions/dashboard-client/src/tabs/VectorCortexTab.tsx +25 -121
- package/extensions/dashboard-client/src/tabs/useVectorCortexPoll.ts +123 -0
- package/extensions/dashboard-client/src/types/vector-cortex-vc7.ts +63 -0
- package/extensions/dashboard-client/src/types/vector-cortex.ts +5 -33
- package/extensions/dashboard-server/api-contracts/vector-cortex-diagnostics.ts +76 -0
- package/extensions/dashboard-server/route-dispatch.ts +5 -0
- package/extensions/dashboard-server/routes-rag-settings-vector-cortex.ts +6 -0
- package/extensions/dashboard-server/routes-vector-cortex-diagnostics.ts +77 -0
- package/package.json +1 -1
- package/src/config/vector-cortex.ts +21 -0
- package/src/config.ts +1 -0
- package/src/vector-cortex/cache/_diagnostics-fixture.ts +32 -0
- package/src/vector-cortex/cache/breaker.ts +124 -0
- package/src/vector-cortex/cache/diagnostics-emit.ts +90 -0
- package/src/vector-cortex/cache/diagnostics-types.ts +87 -0
- package/src/vector-cortex/cache/diagnostics.ts +119 -0
- package/src/vector-cortex/migrations/request-hash-v2-ops.ts +201 -0
- package/src/vector-cortex/migrations/request-hash-v2-types.ts +87 -0
- package/src/vector-cortex/migrations/request-hash-v2.ts +65 -213
- package/extensions/dashboard-client/dist/assets/VectorCortexTab-BBa7rp6C.js +0 -2
- package/extensions/dashboard-client/dist/assets/VectorCortexTab-BBa7rp6C.js.map +0 -1
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* cache/_diagnostics-fixture.ts — VC7C acceptance-test fixture helpers.
|
|
3
|
+
*
|
|
4
|
+
* Reads conformance fixtures from the v2 `cache-diagnostics/` domain and provides
|
|
5
|
+
* a flag-toggling wrapper for VC7C parity tests. Mirrors `_economics-fixture.ts`.
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
import { readFileSync } from "node:fs";
|
|
9
|
+
import { join, dirname } from "node:path";
|
|
10
|
+
import { fileURLToPath } from "node:url";
|
|
11
|
+
|
|
12
|
+
const here = dirname(fileURLToPath(import.meta.url));
|
|
13
|
+
const V2 = join(here, "..", "..", "..", "conformance", "vector-cortex", "v2");
|
|
14
|
+
const DIR = join(V2, "cache-diagnostics");
|
|
15
|
+
|
|
16
|
+
/** Read + parse one conformance fixture by ID. */
|
|
17
|
+
export function diagnosticsFixture(id: string): Record<string, unknown> {
|
|
18
|
+
const raw = readFileSync(join(DIR, `${id}.json`), "utf8");
|
|
19
|
+
return JSON.parse(raw);
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
/** Run `fn` with MEGACOMPACT_VC7C set to `value`, restoring the prior value after. */
|
|
23
|
+
export function withVc7cFlag<T>(value: string, fn: () => T): T {
|
|
24
|
+
const prior = process.env.MEGACOMPACT_VC7C;
|
|
25
|
+
process.env.MEGACOMPACT_VC7C = value;
|
|
26
|
+
try {
|
|
27
|
+
return fn();
|
|
28
|
+
} finally {
|
|
29
|
+
if (prior === undefined) delete process.env.MEGACOMPACT_VC7C;
|
|
30
|
+
else process.env.MEGACOMPACT_VC7C = prior;
|
|
31
|
+
}
|
|
32
|
+
}
|
|
@@ -0,0 +1,124 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* cache/breaker.ts — VC7C cache-serve breaker (composes VC0C's createBreaker).
|
|
3
|
+
*
|
|
4
|
+
* This file does NOT reinvent a state machine. It wraps the TRIAD breaker from
|
|
5
|
+
* `../resilience/breaker-core.js` (VC0C) — the same CLOSED_A / OPEN_B / OPEN_C /
|
|
6
|
+
* PROBE_* / MANUAL_HALT states that protect every other subsystem — and adds the
|
|
7
|
+
* ONE cache-specific decision: whether a classified miss should block a cache
|
|
8
|
+
* SERVE before it can answer from a stale or invalid identity.
|
|
9
|
+
*
|
|
10
|
+
* TRIP KIND CLASSIFICATION (per team-lead correction + TRIAD_RESILIENCE §breaker):
|
|
11
|
+
* The four cache demotion conditions map onto `BreakerTripKind` as follows:
|
|
12
|
+
*
|
|
13
|
+
* CORRECTNESS trips (trip on the FIRST failure, no rolling window):
|
|
14
|
+
* - profile mismatch — the crystal was minted under a different provider
|
|
15
|
+
* profile; serving it would return bytes for the wrong
|
|
16
|
+
* model tier. This is never "recovered from" by waiting.
|
|
17
|
+
* - range mismatch — the crystal's covered digest differs from the
|
|
18
|
+
* request's; the crystal covers different spans and
|
|
19
|
+
* serving it would return another conversation's frozen
|
|
20
|
+
* bytes. (Includes digest failure / collision.)
|
|
21
|
+
* - request mismatch — the request digest differs; the crystal was built
|
|
22
|
+
* for a different request entirely.
|
|
23
|
+
*
|
|
24
|
+
* PERFORMANCE trips (accumulated over a rolling window before opening):
|
|
25
|
+
* - dependency advanced — the dependency high-water moved past the crystal's
|
|
26
|
+
* cached position. The crystal is stale but not WRONG;
|
|
27
|
+
* a single advance is normal churn. Repeated advances
|
|
28
|
+
* across a window indicate the cache is systematically
|
|
29
|
+
* behind the frontier — that is a performance signal.
|
|
30
|
+
* - generation invalidated — the M6 router generation was invalidated. A single
|
|
31
|
+
* invalidation is expected during a router cut; repeated
|
|
32
|
+
* invalidations indicate a systematic generation
|
|
33
|
+
* instability.
|
|
34
|
+
*
|
|
35
|
+
* The distinction matters because a CORRECTNESS trip opens the breaker IMMEDIATELY
|
|
36
|
+
* (first failure), while a PERFORMANCE trip requires BREAKER_PERF_FAILURES within
|
|
37
|
+
* BREAKER_WINDOW_MS. The VC0C breaker-core already implements this via
|
|
38
|
+
* `BreakerTripKind`; we map each miss class to its trip kind and let breaker-core
|
|
39
|
+
* handle the window/threshold logic.
|
|
40
|
+
*
|
|
41
|
+
* "PROBE OUTPUT IS NEVER SERVED" (TRIAD_RESILIENCE line 13): when the breaker is in
|
|
42
|
+
* PROBE_A or PROBE_B, the probe is a TEST serve — its output must not be returned
|
|
43
|
+
* to the caller. `decideCacheServe` enforces this: PROBE_* states always return
|
|
44
|
+
* `block: true` and the fallback mode, never serving from cache.
|
|
45
|
+
*
|
|
46
|
+
* The decision is a CORRECTNESS behavior and is NEVER flag-gated (unlike the
|
|
47
|
+
* reporter seam in `./diagnostics-emit.ts`): flag-off must be byte-identical to
|
|
48
|
+
* the predecessor. `breakerRetryDelay()` from VC0C already implements the
|
|
49
|
+
* deterministic +-10% jitter from the subsystem digest — we use it, don't re-derive.
|
|
50
|
+
*
|
|
51
|
+
* PREVENT-002/011/PI-004 honored.
|
|
52
|
+
*/
|
|
53
|
+
|
|
54
|
+
import { createBreaker, type ConcreteBreaker } from "../resilience/breaker-core.js";
|
|
55
|
+
import type { BreakerRecord, BreakerTripKind, Mode } from "../resilience/types.js";
|
|
56
|
+
import type { MissClass } from "./diagnostics-types.js";
|
|
57
|
+
|
|
58
|
+
/** The cache subsystem the breaker tracks (one triad state machine). */
|
|
59
|
+
export const CACHE_SUBSYSTEM = "vector-cortex-cache-serve";
|
|
60
|
+
|
|
61
|
+
/** Build the cache breaker. Composes VC0C — no parallel state machine here. */
|
|
62
|
+
export function createCacheBreaker(opts?: {
|
|
63
|
+
now?: () => number;
|
|
64
|
+
onEvent?: (event: Record<string, unknown>) => void;
|
|
65
|
+
}): ConcreteBreaker {
|
|
66
|
+
return createBreaker({ now: opts?.now, onEvent: opts?.onEvent });
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
/**
|
|
70
|
+
* Map a miss class to its breaker trip kind. Profile, range (digest/collision),
|
|
71
|
+
* and request mismatches are CORRECTNESS trips — they trip on the FIRST failure
|
|
72
|
+
* because serving a crystal with the wrong identity is never safe, no matter how
|
|
73
|
+
* rarely it happens. Dependency advance and generation invalidation are
|
|
74
|
+
* PERFORMANCE trips — a single occurrence is normal churn; only repeated
|
|
75
|
+
* failures within a window indicate a systematic problem.
|
|
76
|
+
*/
|
|
77
|
+
export function tripKindForMiss(missClass: MissClass): BreakerTripKind {
|
|
78
|
+
switch (missClass) {
|
|
79
|
+
case "profile":
|
|
80
|
+
case "range":
|
|
81
|
+
case "request":
|
|
82
|
+
return "correctness";
|
|
83
|
+
case "dependency":
|
|
84
|
+
case "generation":
|
|
85
|
+
return "performance";
|
|
86
|
+
case "unknown":
|
|
87
|
+
return "performance";
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
/**
|
|
92
|
+
* Whether a classified miss must block the cache serve. Pure over the class; the
|
|
93
|
+
* ONLY thing that is allowed to demote an otherwise-healthy cache is a real
|
|
94
|
+
* disagreement between what was cached and what the request now requires.
|
|
95
|
+
* `unknown` is not auto-blocked — the triad's own performance window handles it.
|
|
96
|
+
*/
|
|
97
|
+
export function shouldBlockServe(missClass: MissClass): boolean {
|
|
98
|
+
return missClass !== "unknown";
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
/**
|
|
102
|
+
* Decide the triad mode to render under, given a classified miss and the live
|
|
103
|
+
* breaker. A blockable miss forces mode B (fresh render) unless the breaker is
|
|
104
|
+
* already in a deeper open state (C = all-cache bypass) — never contradicting the
|
|
105
|
+
* triad's own resilience verdict. PROBE_* states are NEVER served from cache
|
|
106
|
+
* (TRIAD_RESILIENCE line 13: "probe output is never served").
|
|
107
|
+
*/
|
|
108
|
+
export function decideCacheServe(
|
|
109
|
+
missClass: MissClass,
|
|
110
|
+
breaker: ConcreteBreaker,
|
|
111
|
+
): { block: boolean; fallbackMode: Mode; tripKind: BreakerTripKind } {
|
|
112
|
+
const tripKind = tripKindForMiss(missClass);
|
|
113
|
+
if (!shouldBlockServe(missClass)) {
|
|
114
|
+
return { block: false, fallbackMode: breaker.modeFor(CACHE_SUBSYSTEM), tripKind };
|
|
115
|
+
}
|
|
116
|
+
const record: BreakerRecord = breaker.snapshot(CACHE_SUBSYSTEM);
|
|
117
|
+
if (record.state === "OPEN_C" || record.state === "MANUAL_HALT") {
|
|
118
|
+
return { block: true, fallbackMode: "C", tripKind };
|
|
119
|
+
}
|
|
120
|
+
if (record.state === "PROBE_A" || record.state === "PROBE_B") {
|
|
121
|
+
return { block: true, fallbackMode: record.state === "PROBE_A" ? "C" : "B", tripKind };
|
|
122
|
+
}
|
|
123
|
+
return { block: true, fallbackMode: "B", tripKind };
|
|
124
|
+
}
|
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* cache/diagnostics-emit.ts — VC7C reporter seam (FLAG-GATED).
|
|
3
|
+
*
|
|
4
|
+
* Mirrors `./economics-emit.ts`: a thin `safe()` wrapper around an optional
|
|
5
|
+
* injected `emit`, and the two event names the sprint spec requires verbatim:
|
|
6
|
+
* - `vector_cortex_cache_miss_classified` — a miss was classified.
|
|
7
|
+
* - `vector_cortex_cache_serve_blocked` — a cache serve was blocked by a
|
|
8
|
+
* breaker condition before it could answer from a stale/invalid identity.
|
|
9
|
+
*
|
|
10
|
+
* FLAG SEMANTICS. `classifyMiss` (`./diagnostics.ts`) is PURE and runs REGARDLESS
|
|
11
|
+
* of `MEGACOMPACT_VC7C`. The flag gates ONLY this reporting + dashboard seam:
|
|
12
|
+
* with the flag off the classifier still returns the SAME class, the breaker
|
|
13
|
+
* still blocks the SAME serve — we just do not announce them under the VC7C
|
|
14
|
+
* event namespace, and the dashboard reports `enabled:false` + mode C. That is
|
|
15
|
+
* what makes flag-off byte-identical to the predecessor (VC7B): the arithmetic
|
|
16
|
+
* and the correctness decision are never skipped, only the emission. (NOTE the
|
|
17
|
+
* asymmetry vs VC7B: VC7B gated pure telemetry; here the blocked-serve DECISION
|
|
18
|
+
* is a correctness behavior and is never flag-gated — only its announcement is.)
|
|
19
|
+
*
|
|
20
|
+
* PAYLOAD DISCIPLINE. These events carry the `missClass` and the payload-free
|
|
21
|
+
* `evidence` booleans/counts (see `./diagnostics-types.ts`) — never a session
|
|
22
|
+
* id, never a covered range, never a request or covered digest. The classifier
|
|
23
|
+
* is payload-free by construction, so there is no slot to leak into
|
|
24
|
+
* (SECURITY_PRIVACY — the exact ledger is not diagnostic data).
|
|
25
|
+
*
|
|
26
|
+
* No console, no storage, no network (PREVENT-PI-004 / PREVENT-011). Every line
|
|
27
|
+
* is a structured JSON event with `ts` + `event`.
|
|
28
|
+
*/
|
|
29
|
+
|
|
30
|
+
import { VC7C_ENABLED } from "../../config/vector-cortex.js";
|
|
31
|
+
import type { CacheDiagnosticV1, MissClass } from "./diagnostics-types.js";
|
|
32
|
+
|
|
33
|
+
/** The two structured events the VC7C reporter emits. */
|
|
34
|
+
export type CacheDiagnosticEventName =
|
|
35
|
+
| "vector_cortex_cache_miss_classified"
|
|
36
|
+
| "vector_cortex_cache_serve_blocked";
|
|
37
|
+
|
|
38
|
+
/** Optional emit fn injected by the runtime; tests pass `undefined`. */
|
|
39
|
+
export type CacheDiagnosticEmit = (name: string, payload: unknown) => void;
|
|
40
|
+
|
|
41
|
+
/** Run `fn` only when an emit exists; a reporting failure is never fatal. */
|
|
42
|
+
function safe(
|
|
43
|
+
emit: CacheDiagnosticEmit | undefined,
|
|
44
|
+
fn: (emit: CacheDiagnosticEmit) => void,
|
|
45
|
+
): void {
|
|
46
|
+
if (emit === undefined) return;
|
|
47
|
+
try {
|
|
48
|
+
fn(emit);
|
|
49
|
+
} catch {
|
|
50
|
+
// Non-fatal: a reporting failure must never break the agent loop.
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
/** Report a classified miss. Gated only by the reporter/dashboard flag. */
|
|
55
|
+
export function reportCacheMissClassified(
|
|
56
|
+
emit: CacheDiagnosticEmit | undefined,
|
|
57
|
+
diagnostic: CacheDiagnosticV1,
|
|
58
|
+
): void {
|
|
59
|
+
if (!VC7C_ENABLED()) return;
|
|
60
|
+
safe(emit, (e) =>
|
|
61
|
+
e("vector_cortex_cache_miss_classified", {
|
|
62
|
+
ts: undefined,
|
|
63
|
+
event: "vector_cortex_cache_miss_classified",
|
|
64
|
+
schema: diagnostic.schema,
|
|
65
|
+
missClass: diagnostic.missClass,
|
|
66
|
+
evidence: diagnostic.evidence,
|
|
67
|
+
}),
|
|
68
|
+
);
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
/** Report a cache serve that was blocked before answering. Gated by the flag. */
|
|
72
|
+
export function reportCacheServeBlocked(
|
|
73
|
+
emit: CacheDiagnosticEmit | undefined,
|
|
74
|
+
blocked: {
|
|
75
|
+
readonly missClass: MissClass;
|
|
76
|
+
readonly triadState: string;
|
|
77
|
+
readonly reason: string;
|
|
78
|
+
},
|
|
79
|
+
): void {
|
|
80
|
+
if (!VC7C_ENABLED()) return;
|
|
81
|
+
safe(emit, (e) =>
|
|
82
|
+
e("vector_cortex_cache_serve_blocked", {
|
|
83
|
+
ts: undefined,
|
|
84
|
+
event: "vector_cortex_cache_serve_blocked",
|
|
85
|
+
missClass: blocked.missClass,
|
|
86
|
+
triadState: blocked.triadState,
|
|
87
|
+
reason: blocked.reason,
|
|
88
|
+
}),
|
|
89
|
+
);
|
|
90
|
+
}
|
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* cache/diagnostics-types.ts — VC7C cache miss-diagnostic contract types.
|
|
3
|
+
*
|
|
4
|
+
* Single source of truth for the miss-classification vocabulary. Kept separate
|
|
5
|
+
* from the arithmetic (`diagnostics.ts`) so the dashboard client, the emit layer
|
|
6
|
+
* and the acceptance test all import ONE definition. No logic here; pure types
|
|
7
|
+
* + the registered ID lists. PREVENT-011 honored (no `any`).
|
|
8
|
+
*/
|
|
9
|
+
|
|
10
|
+
/** The exclusive miss classes, in the order the classifier ranks them. */
|
|
11
|
+
export type MissClass =
|
|
12
|
+
| "profile"
|
|
13
|
+
| "range"
|
|
14
|
+
| "dependency"
|
|
15
|
+
| "request"
|
|
16
|
+
| "generation"
|
|
17
|
+
| "unknown";
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* Payload-free by construction. Every field is a boolean or a bounded,
|
|
21
|
+
* non-negative count — there is no string slot into which a request body, a
|
|
22
|
+
* session id, or a covered range of user content could be placed. See
|
|
23
|
+
* SECURITY_PRIVACY: a diagnostic that carried the offending payload would leak
|
|
24
|
+
* it to the dashboard.
|
|
25
|
+
*/
|
|
26
|
+
export interface MissEvidence {
|
|
27
|
+
readonly profileMismatch: boolean;
|
|
28
|
+
readonly rangeMismatch: boolean;
|
|
29
|
+
readonly dependencyAdvanced: boolean;
|
|
30
|
+
readonly requestMismatch: boolean;
|
|
31
|
+
readonly generationInvalidated: boolean;
|
|
32
|
+
/** Ranges the caller asked for (always observable, even on a cold key). */
|
|
33
|
+
readonly requestedRangeCount: number;
|
|
34
|
+
/** Ranges the cache could serve; 0 on a cold key (no crystal). */
|
|
35
|
+
readonly cachedRangeCount: number;
|
|
36
|
+
/** max(0, requestHighWater - cachedHighWater), saturated at MAX_SAFE_INTEGER. */
|
|
37
|
+
readonly dependencyDelta: number;
|
|
38
|
+
/** True when nothing was cached for this key (null cached fields). */
|
|
39
|
+
readonly absent: boolean;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
/**
|
|
43
|
+
* A single observation fed to the classifier. A `null` cached field means that
|
|
44
|
+
* piece of state was never persisted — "absence is not a mismatch". Digests
|
|
45
|
+
* follow convention: `coveredDigest` is `sha256:<hex>` (WITH prefix);
|
|
46
|
+
* `requestDigest` is BARE lowercase hex (NO prefix).
|
|
47
|
+
*/
|
|
48
|
+
export interface MissObservation {
|
|
49
|
+
readonly requestProfileId: string;
|
|
50
|
+
readonly requestProfileVersion: string;
|
|
51
|
+
readonly cachedProfileId: string | null;
|
|
52
|
+
readonly cachedProfileVersion: string | null;
|
|
53
|
+
readonly requestCoveredDigest: string;
|
|
54
|
+
readonly cachedCoveredDigest: string | null;
|
|
55
|
+
readonly requestedRangeCount: number;
|
|
56
|
+
readonly cachedRangeCount: number | null;
|
|
57
|
+
readonly requestDigest: string;
|
|
58
|
+
readonly cachedRequestDigest: string | null;
|
|
59
|
+
/** Dependency validation high-water (monotonic frontier), as a bigint. */
|
|
60
|
+
readonly requestDependencyHighWater: bigint;
|
|
61
|
+
readonly cachedDependencyHighWater: bigint | null;
|
|
62
|
+
readonly generationInvalidated: boolean;
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
/** The versioned diagnostic record emitted for every classified miss. */
|
|
66
|
+
export interface CacheDiagnosticV1 {
|
|
67
|
+
readonly schema: "cache-diagnostic-v1";
|
|
68
|
+
readonly missClass: MissClass;
|
|
69
|
+
readonly evidence: MissEvidence;
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
/** Registered conformance IDs (CACHE-016..030). */
|
|
73
|
+
export const CACHE_DIAGNOSTIC_IDS: readonly string[] = Array.from(
|
|
74
|
+
{ length: 15 },
|
|
75
|
+
(_v, i) => `CACHE-${String(i + 16).padStart(3, "0")}`,
|
|
76
|
+
);
|
|
77
|
+
|
|
78
|
+
/** Named headlines surfaced by the conformance corpus. */
|
|
79
|
+
export const CACHE_DIAGNOSTIC_NAMED_IDS = [
|
|
80
|
+
"CACHE-MISS-001",
|
|
81
|
+
"CACHE-STALE-003",
|
|
82
|
+
] as const;
|
|
83
|
+
|
|
84
|
+
/** Event names this subsystem emits (gated by MEGACOMPACT_VC7C). */
|
|
85
|
+
export type CacheDiagnosticEventName =
|
|
86
|
+
| "vector_cortex_cache_miss_classified"
|
|
87
|
+
| "vector_cortex_cache_serve_blocked";
|
|
@@ -0,0 +1,119 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* cache/diagnostics.ts — VC7C pure miss classification (flag-independent).
|
|
3
|
+
*
|
|
4
|
+
* The classifier is PURE arithmetic: given a `MissObservation` it returns
|
|
5
|
+
* exactly ONE `MissClass` and the payload-free `MissEvidence`. It is NOT gated by
|
|
6
|
+
* MEGACOMPACT_VC7C — flag-off must be byte-identical to the predecessor, so the
|
|
7
|
+
* SAME class a user sees today, they see tomorrow. The flag gates only the
|
|
8
|
+
* reporter/dashboard seam (see `diagnostics-emit.ts`).
|
|
9
|
+
*
|
|
10
|
+
* Exclusive ranking: profile -> range -> dependency -> request -> generation ->
|
|
11
|
+
* unknown. First match wins; the ranking itself is the contract and is pinned by
|
|
12
|
+
* CACHE-016..030. "Absence is not a mismatch": a cold key (null cached fields)
|
|
13
|
+
* classifies `unknown`, never `profile`. PREVENT-002/011/PI-004 honored.
|
|
14
|
+
*/
|
|
15
|
+
|
|
16
|
+
import type {
|
|
17
|
+
CacheDiagnosticV1,
|
|
18
|
+
MissClass,
|
|
19
|
+
MissEvidence,
|
|
20
|
+
MissObservation,
|
|
21
|
+
} from "./diagnostics-types.js";
|
|
22
|
+
|
|
23
|
+
/** A cached field is present iff it is non-null. */
|
|
24
|
+
function isPresent(value: string | number | bigint | null): boolean {
|
|
25
|
+
return value !== null;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
/**
|
|
29
|
+
* Clamp the dependency delta to a non-negative, safe-integer count. A request
|
|
30
|
+
* BEHIND the cached frontier is not an advance (delta 0); a huge advance
|
|
31
|
+
* saturates rather than losing precision.
|
|
32
|
+
*/
|
|
33
|
+
function advanceDelta(
|
|
34
|
+
request: bigint,
|
|
35
|
+
cached: bigint | null,
|
|
36
|
+
): { advanced: boolean; delta: number } {
|
|
37
|
+
if (cached === null) return { advanced: false, delta: 0 };
|
|
38
|
+
if (request <= cached) return { advanced: false, delta: 0 };
|
|
39
|
+
const diff = request - cached;
|
|
40
|
+
if (diff > BigInt(Number.MAX_SAFE_INTEGER)) {
|
|
41
|
+
return { advanced: true, delta: Number.MAX_SAFE_INTEGER };
|
|
42
|
+
}
|
|
43
|
+
return { advanced: true, delta: Number(diff) };
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
/** Collect the payload-free evidence from one observation. */
|
|
47
|
+
export function collectEvidence(o: MissObservation): MissEvidence {
|
|
48
|
+
const profileMismatch =
|
|
49
|
+
isPresent(o.cachedProfileId) &&
|
|
50
|
+
isPresent(o.cachedProfileVersion) &&
|
|
51
|
+
(o.cachedProfileId !== o.requestProfileId ||
|
|
52
|
+
o.cachedProfileVersion !== o.requestProfileVersion);
|
|
53
|
+
|
|
54
|
+
const rangeMismatch =
|
|
55
|
+
(isPresent(o.cachedCoveredDigest) &&
|
|
56
|
+
o.cachedCoveredDigest !== o.requestCoveredDigest) ||
|
|
57
|
+
(isPresent(o.cachedRangeCount) &&
|
|
58
|
+
o.cachedRangeCount !== o.requestedRangeCount);
|
|
59
|
+
|
|
60
|
+
const dep = advanceDelta(
|
|
61
|
+
o.requestDependencyHighWater,
|
|
62
|
+
o.cachedDependencyHighWater,
|
|
63
|
+
);
|
|
64
|
+
|
|
65
|
+
const requestMismatch =
|
|
66
|
+
isPresent(o.cachedRequestDigest) &&
|
|
67
|
+
o.cachedRequestDigest !== o.requestDigest;
|
|
68
|
+
|
|
69
|
+
const absent =
|
|
70
|
+
!isPresent(o.cachedProfileId) &&
|
|
71
|
+
!isPresent(o.cachedCoveredDigest) &&
|
|
72
|
+
!isPresent(o.cachedRequestDigest) &&
|
|
73
|
+
!isPresent(o.cachedDependencyHighWater);
|
|
74
|
+
|
|
75
|
+
return {
|
|
76
|
+
profileMismatch,
|
|
77
|
+
rangeMismatch,
|
|
78
|
+
dependencyAdvanced: dep.advanced,
|
|
79
|
+
requestMismatch,
|
|
80
|
+
generationInvalidated: o.generationInvalidated,
|
|
81
|
+
requestedRangeCount: o.requestedRangeCount,
|
|
82
|
+
// Nothing was cached when the observation is absent, so a stale
|
|
83
|
+
// cachedRangeCount on the observation is not real — report 0.
|
|
84
|
+
cachedRangeCount:
|
|
85
|
+
o.cachedRangeCount === null || absent ? 0 : o.cachedRangeCount,
|
|
86
|
+
dependencyDelta: dep.delta,
|
|
87
|
+
absent,
|
|
88
|
+
};
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
/** The exclusive ranking: first true cause wins. */
|
|
92
|
+
export function classFor(e: MissEvidence): MissClass {
|
|
93
|
+
if (e.profileMismatch) return "profile";
|
|
94
|
+
if (e.rangeMismatch) return "range";
|
|
95
|
+
if (e.dependencyAdvanced) return "dependency";
|
|
96
|
+
if (e.requestMismatch) return "request";
|
|
97
|
+
if (e.generationInvalidated) return "generation";
|
|
98
|
+
return "unknown";
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
/** Classify one observation: exactly one deterministic class. */
|
|
102
|
+
export function classifyMiss(o: MissObservation): CacheDiagnosticV1 {
|
|
103
|
+
const evidence = collectEvidence(o);
|
|
104
|
+
return {
|
|
105
|
+
schema: "cache-diagnostic-v1",
|
|
106
|
+
missClass: classFor(evidence),
|
|
107
|
+
evidence,
|
|
108
|
+
};
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
/**
|
|
112
|
+
* A miss a caller can self-heal on the next turn (re-fetch under a fresh
|
|
113
|
+
* profile / a new generation), so a triad recovery path may treat it as
|
|
114
|
+
* transient. Only profile + generation qualify; the rest are hard mismatches.
|
|
115
|
+
* An `unknown` miss is NEVER transient.
|
|
116
|
+
*/
|
|
117
|
+
export function isTransientMiss(d: CacheDiagnosticV1): boolean {
|
|
118
|
+
return d.missClass === "profile" || d.missClass === "generation";
|
|
119
|
+
}
|
|
@@ -0,0 +1,201 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* request-hash-v2-ops.ts — M5 migration operational logic (copy/verify/switch).
|
|
3
|
+
*
|
|
4
|
+
* Extracted from request-hash-v2.ts to keep the parent file under the 300-line
|
|
5
|
+
* soft limit (soft-as-hard gate). Pure logic over an injected M5Host;
|
|
6
|
+
* deterministic + testable; no console. PREVENT-002/011/PI-004 honored.
|
|
7
|
+
*/
|
|
8
|
+
import { createHash } from "node:crypto";
|
|
9
|
+
import { invalidationKey } from "../topology/query.js";
|
|
10
|
+
import type {
|
|
11
|
+
M5Host,
|
|
12
|
+
M5MigrationCode,
|
|
13
|
+
M5ValidateResult,
|
|
14
|
+
RequestHashV1Row,
|
|
15
|
+
RequestHashV2Row,
|
|
16
|
+
} from "./request-hash-v2-types.js";
|
|
17
|
+
import {
|
|
18
|
+
M5_FAIL,
|
|
19
|
+
REQUEST_HASH_LEGACY_VERSION,
|
|
20
|
+
} from "./request-hash-v2-types.js";
|
|
21
|
+
|
|
22
|
+
/** Length-prefixed framing so the folded fields cannot alias. */
|
|
23
|
+
function field(value: string): string {
|
|
24
|
+
return `${Buffer.byteLength(value, "utf8")}:${value}`;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
const identity = (profileId: string, requestDigest: string): string =>
|
|
28
|
+
`${profileId}::${requestDigest}`;
|
|
29
|
+
|
|
30
|
+
/**
|
|
31
|
+
* The authoritative v2 hash: SHA-256 over the version tag, profile, request
|
|
32
|
+
* digest, and economics version. Length-prefixed for injectivity, exactly as the
|
|
33
|
+
* crystal key encoder frames its fields.
|
|
34
|
+
*/
|
|
35
|
+
export function deriveRequestHashV2(
|
|
36
|
+
profileId: string,
|
|
37
|
+
requestDigest: string,
|
|
38
|
+
economicsVersion: string,
|
|
39
|
+
): string {
|
|
40
|
+
return createHash("sha256")
|
|
41
|
+
.update(
|
|
42
|
+
field("request-hash-v2") +
|
|
43
|
+
field(profileId) +
|
|
44
|
+
field(requestDigest) +
|
|
45
|
+
field(economicsVersion),
|
|
46
|
+
"utf8",
|
|
47
|
+
)
|
|
48
|
+
.digest("hex");
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
/** Derive the v2 row for one v1 row. */
|
|
52
|
+
export function deriveRequestHashRow(
|
|
53
|
+
host: M5Host,
|
|
54
|
+
v1: RequestHashV1Row,
|
|
55
|
+
): RequestHashV2Row {
|
|
56
|
+
const economicsVersion = host.economicsVersionOf(v1.profileId);
|
|
57
|
+
return {
|
|
58
|
+
profileId: v1.profileId,
|
|
59
|
+
// IDENTITY-PRESERVING: carried through verbatim, never re-derived.
|
|
60
|
+
requestDigest: v1.requestDigest,
|
|
61
|
+
economicsVersion,
|
|
62
|
+
hash: deriveRequestHashV2(v1.profileId, v1.requestDigest, economicsVersion),
|
|
63
|
+
};
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
/**
|
|
67
|
+
* Economics versions encode the generation they were minted under. We treat the
|
|
68
|
+
* trailing numeric segment as the generation; if it is not numeric the row is
|
|
69
|
+
* considered tied to generation 0 (always live unless explicitly invalidated).
|
|
70
|
+
*/
|
|
71
|
+
function generationFromEconomics(economicsVersion: string): bigint {
|
|
72
|
+
const match = /(\d+)$/.exec(economicsVersion);
|
|
73
|
+
return match ? BigInt(match[1]) : 0n;
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
export function detectCollision(host: M5Host): boolean {
|
|
77
|
+
const byHash = new Map<string, string>();
|
|
78
|
+
const seenIdentities = new Set<string>();
|
|
79
|
+
for (const v1 of host.v1Rows()) {
|
|
80
|
+
const row = deriveRequestHashRow(host, v1);
|
|
81
|
+
const id = identity(v1.profileId, v1.requestDigest);
|
|
82
|
+
// Two distinct v1 rows (different v1 hash) with the same v2 hash collide,
|
|
83
|
+
// even if they share an identity — the v2 table cannot distinguish them.
|
|
84
|
+
if (seenIdentities.has(id)) return true;
|
|
85
|
+
seenIdentities.add(id);
|
|
86
|
+
const prior = byHash.get(row.hash);
|
|
87
|
+
if (prior !== undefined && prior !== id) return true;
|
|
88
|
+
byHash.set(row.hash, id);
|
|
89
|
+
}
|
|
90
|
+
return false;
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
export function isGenerationInvalidated(
|
|
94
|
+
host: M5Host,
|
|
95
|
+
row: RequestHashV2Row,
|
|
96
|
+
): boolean {
|
|
97
|
+
const session = host.sessionOf(row.profileId);
|
|
98
|
+
const live = host.liveGenerationOf(session);
|
|
99
|
+
const keyForLive = invalidationKey(session, live);
|
|
100
|
+
const keyForRow = invalidationKey(
|
|
101
|
+
session,
|
|
102
|
+
generationFromEconomics(row.economicsVersion),
|
|
103
|
+
);
|
|
104
|
+
return keyForLive !== keyForRow;
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
export function m5Copy(host: M5Host): {
|
|
108
|
+
readonly written: readonly RequestHashV2Row[];
|
|
109
|
+
readonly all: readonly RequestHashV2Row[];
|
|
110
|
+
} {
|
|
111
|
+
const existing = new Map(
|
|
112
|
+
host.existingV2().map((r) => [identity(r.profileId, r.requestDigest), r]),
|
|
113
|
+
);
|
|
114
|
+
const wanted: RequestHashV2Row[] = [];
|
|
115
|
+
for (const v1 of host.v1Rows()) {
|
|
116
|
+
const fresh = deriveRequestHashRow(host, v1);
|
|
117
|
+
if (isGenerationInvalidated(host, fresh)) continue;
|
|
118
|
+
const stored = existing.get(identity(v1.profileId, v1.requestDigest));
|
|
119
|
+
if (
|
|
120
|
+
stored !== undefined &&
|
|
121
|
+
stored.hash === fresh.hash &&
|
|
122
|
+
stored.economicsVersion === fresh.economicsVersion
|
|
123
|
+
) {
|
|
124
|
+
continue;
|
|
125
|
+
}
|
|
126
|
+
wanted.push(fresh);
|
|
127
|
+
}
|
|
128
|
+
if (wanted.length > 0) host.putV2(wanted);
|
|
129
|
+
return { written: wanted, all: [...host.existingV2()] };
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
function dedupe(codes: readonly M5MigrationCode[]): M5MigrationCode[] {
|
|
133
|
+
const out: M5MigrationCode[] = [];
|
|
134
|
+
for (const c of codes) if (!out.includes(c)) out.push(c);
|
|
135
|
+
return out;
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
export function m5Verify(host: M5Host): M5ValidateResult {
|
|
139
|
+
const codes: M5MigrationCode[] = [];
|
|
140
|
+
const stored = host.existingV2();
|
|
141
|
+
const v1Rows = host.v1Rows();
|
|
142
|
+
|
|
143
|
+
const counts = new Map<string, number>();
|
|
144
|
+
for (const r of stored) {
|
|
145
|
+
const id = identity(r.profileId, r.requestDigest);
|
|
146
|
+
counts.set(id, (counts.get(id) ?? 0) + 1);
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
const expected = new Set<string>();
|
|
150
|
+
for (const v1 of v1Rows) {
|
|
151
|
+
const id = identity(v1.profileId, v1.requestDigest);
|
|
152
|
+
// Dead-generation rows are intentionally skipped by copy; do not flag.
|
|
153
|
+
const fresh = deriveRequestHashRow(host, v1);
|
|
154
|
+
if (isGenerationInvalidated(host, fresh)) continue;
|
|
155
|
+
expected.add(id);
|
|
156
|
+
const n = counts.get(id) ?? 0;
|
|
157
|
+
if (n === 0) codes.push(M5_FAIL.COPY_PARTIAL);
|
|
158
|
+
if (n > 1) codes.push(M5_FAIL.COUNT_MISMATCH);
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
const v1Digests = new Set(
|
|
162
|
+
v1Rows.map((r) => identity(r.profileId, r.requestDigest)),
|
|
163
|
+
);
|
|
164
|
+
for (const r of stored) {
|
|
165
|
+
const fresh = deriveRequestHashV2(
|
|
166
|
+
r.profileId,
|
|
167
|
+
r.requestDigest,
|
|
168
|
+
r.economicsVersion,
|
|
169
|
+
);
|
|
170
|
+
if (r.hash !== fresh) codes.push(M5_FAIL.DIGEST_MISMATCH);
|
|
171
|
+
const id = identity(r.profileId, r.requestDigest);
|
|
172
|
+
if (!v1Digests.has(id)) {
|
|
173
|
+
codes.push(
|
|
174
|
+
expected.size > 0 ? M5_FAIL.IDENTITY_DRIFT : M5_FAIL.COUNT_MISMATCH,
|
|
175
|
+
);
|
|
176
|
+
}
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
if (detectCollision(host)) codes.push(M5_FAIL.REQUEST_HASH_COLLISION);
|
|
180
|
+
|
|
181
|
+
return { ok: codes.length === 0, codes: dedupe(codes) };
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
export function m5Switch(host: M5Host): M5ValidateResult {
|
|
185
|
+
if (host.activeVersion() !== REQUEST_HASH_LEGACY_VERSION) {
|
|
186
|
+
return { ok: false, codes: [M5_FAIL.NOT_ON_LEGACY] };
|
|
187
|
+
}
|
|
188
|
+
// Collision check runs before copy-completeness verify: a structural
|
|
189
|
+
// collision is a switch-blocker regardless of copy state.
|
|
190
|
+
if (detectCollision(host))
|
|
191
|
+
return { ok: false, codes: [M5_FAIL.REQUEST_HASH_COLLISION] };
|
|
192
|
+
const verify = m5Verify(host);
|
|
193
|
+
if (!verify.ok) return verify;
|
|
194
|
+
host.switchToV2();
|
|
195
|
+
return { ok: true, codes: [] };
|
|
196
|
+
}
|
|
197
|
+
|
|
198
|
+
export function migrateRequestHashV2(host: M5Host): M5ValidateResult {
|
|
199
|
+
m5Copy(host);
|
|
200
|
+
return m5Switch(host);
|
|
201
|
+
}
|