pi-mega-compact 0.20.34 → 0.20.36
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-ml5a.js +28 -0
- package/dist/config/vector-cortex.js +4 -5
- package/dist/config.js +1 -1
- package/dist/extensions/dashboard-server/routes-rag-settings-vector-cortex.js +1 -0
- package/dist/extensions/mega-events/context-handler/afterCompact.js +33 -4
- package/dist/extensions/mega-events/context-handler/controller.js +161 -0
- package/dist/src/config/vector-cortex-ml5a.js +28 -0
- package/dist/src/config/vector-cortex.js +4 -5
- package/dist/src/config.js +1 -1
- package/dist/src/vector-cortex/encoder/calibrate.js +55 -0
- package/dist/src/vector-cortex/encoder/heads.js +87 -0
- package/dist/src/vector-cortex/encoder/select.js +10 -0
- package/dist/src/vector-cortex/heal/_vc6c-impl-fixture.js +29 -0
- package/dist/src/vector-cortex/reconstruct/rebuild.js +43 -0
- package/dist/src/vector-cortex/reconstruct/repair-plan.js +57 -0
- package/dist/vector-cortex/encoder/calibrate.js +55 -0
- package/dist/vector-cortex/encoder/heads.js +87 -0
- package/dist/vector-cortex/encoder/select.js +10 -0
- package/dist/vector-cortex/heal/_vc6c-impl-fixture.js +29 -0
- package/dist/vector-cortex/reconstruct/rebuild.js +43 -0
- package/dist/vector-cortex/reconstruct/repair-plan.js +57 -0
- package/extensions/dashboard-server/routes-rag-settings-vector-cortex.ts +6 -0
- package/extensions/mega-events/context-handler/afterCompact.ts +40 -4
- package/extensions/mega-events/context-handler/controller.ts +230 -0
- package/package.json +1 -1
- package/src/config/vector-cortex-ml5a.ts +30 -0
- package/src/config/vector-cortex.ts +4 -5
- package/src/config.ts +1 -0
- package/src/vector-cortex/encoder/calibrate.ts +49 -0
- package/src/vector-cortex/encoder/heads.ts +106 -0
- package/src/vector-cortex/encoder/select.ts +17 -0
- package/src/vector-cortex/heal/_vc6c-impl-fixture.ts +43 -0
- package/src/vector-cortex/reconstruct/rebuild.ts +75 -0
- package/src/vector-cortex/reconstruct/repair-plan.ts +112 -0
|
@@ -0,0 +1,112 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* vector-cortex/reconstruct/repair-plan.ts — VC6C-IMPL production repair plan seam.
|
|
3
|
+
*
|
|
4
|
+
* Maps a compact result into the production-facing plan the handler emits. The
|
|
5
|
+
* pure `heal/repair-types.ts` contract stays the canonical design carrier; this
|
|
6
|
+
* file owns the PRODUCTION shape (`RepairPlanV1` / `RepairEventV1`) that the
|
|
7
|
+
* post-compact controller drives, plus the builder that turns a per-subsystem
|
|
8
|
+
* gap into a plan.
|
|
9
|
+
*
|
|
10
|
+
* RELATIONSHIP TO heal/. The `heal/` modules (VC6C) already ship the pure
|
|
11
|
+
* gap-detection / backoff / rebuild / switch primitives and 74 passing tests.
|
|
12
|
+
* This sprint wires them into the production compact path; it does NOT fork
|
|
13
|
+
* them. `buildRepairPlan` reuses `computeBackoff` for the deterministic
|
|
14
|
+
* exponential delay (30s * 2^attempt, 15 min cap, ±10% SHA-256-derived jitter,
|
|
15
|
+
* never `Math.random`) so a plan's `backoffMs` is byte-reproducible in a
|
|
16
|
+
* fixture. Gap arithmetic mirrors `heal/controller.ts#gapRange`: the plan's seq
|
|
17
|
+
* window is `derived post-count + 1 .. durable authority high-water`, inclusive,
|
|
18
|
+
* exactly the unbuilt range.
|
|
19
|
+
*
|
|
20
|
+
* THE AUTHORITY IS NEVER WRITTEN. A plan carries `authorityHighWater` for
|
|
21
|
+
* identity only; no code here (or anywhere in this sprint) mutates the durable
|
|
22
|
+
* authority. `generation` is the NEW derived generation the rebuild writes into
|
|
23
|
+
* (always `current + 1`), mirroring the heal copy-then-switch rule.
|
|
24
|
+
*
|
|
25
|
+
* PURE. `node:crypto` is used only transitively through `computeBackoff`; no
|
|
26
|
+
* storage, no console, no clock of its own (`nowMs` is injected), no network
|
|
27
|
+
* (PREVENT-PI-004 / PREVENT-011).
|
|
28
|
+
*/
|
|
29
|
+
|
|
30
|
+
import { computeBackoff } from "../heal/controller.js";
|
|
31
|
+
import type { Mode, RepairSubsystem } from "../heal/repair-types.js";
|
|
32
|
+
|
|
33
|
+
/**
|
|
34
|
+
* Production repair plan: the exact shape the handler emits and the acceptance
|
|
35
|
+
* fixture VC6C-IMPL-004 pins.
|
|
36
|
+
*
|
|
37
|
+
* `range` is a plain `[seqStart, seqEnd]` tuple (inclusive) — the production
|
|
38
|
+
* handler deals in seq space, not byte shards, so the plan stays the cheap
|
|
39
|
+
* operator-facing shape while `heal/repair-types.ts#RepairPlanV1.range` remains
|
|
40
|
+
* the full `ShardRange` carrier for the pure controller.
|
|
41
|
+
*/
|
|
42
|
+
export interface RepairPlanV1 {
|
|
43
|
+
readonly schema: "repair-plan-v1";
|
|
44
|
+
/** The derived subsystem being repaired (e.g. "topology"). */
|
|
45
|
+
readonly subsystem: RepairSubsystem;
|
|
46
|
+
/** Inclusive seq window to rebuild: derived post-count + 1 .. authority. */
|
|
47
|
+
readonly range: readonly [number, number];
|
|
48
|
+
/** The NEW derived generation the rebuild materializes into. */
|
|
49
|
+
readonly generation: number;
|
|
50
|
+
/** Deterministic delay (ms) before the plan may execute. */
|
|
51
|
+
readonly backoffMs: number;
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
/**
|
|
55
|
+
* A repair lifecycle record emitted by the handler. Identity and counters only —
|
|
56
|
+
* never a rebuilt byte, never a root digest of user content (SECURITY_PRIVACY).
|
|
57
|
+
*/
|
|
58
|
+
export interface RepairEventV1 {
|
|
59
|
+
readonly schema: "repair-event-v1";
|
|
60
|
+
readonly subsystem: RepairSubsystem;
|
|
61
|
+
readonly kind: "planned" | "pointer-switched" | "backoff";
|
|
62
|
+
readonly generation: number;
|
|
63
|
+
readonly backoffMs: number;
|
|
64
|
+
readonly code?: string;
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
/**
|
|
68
|
+
* One subsystem's post-compact view used to build a plan. `postCount` is the
|
|
69
|
+
* derived high-water (inclusive) AFTER compaction; `authorityHighWater` is the
|
|
70
|
+
* durable contiguous authority frontier (inclusive), read-only.
|
|
71
|
+
*/
|
|
72
|
+
export interface PostCompactGap {
|
|
73
|
+
readonly subsystem: RepairSubsystem;
|
|
74
|
+
readonly postCount: number;
|
|
75
|
+
readonly authorityHighWater: number;
|
|
76
|
+
/** The CURRENT live generation; a plan targets `generation + 1`. */
|
|
77
|
+
readonly generation: number;
|
|
78
|
+
/** Consecutive failed attempts, the exponent in the exponential backoff. */
|
|
79
|
+
readonly failedAttempts?: number;
|
|
80
|
+
/** Which triad arm currently serves this subsystem. */
|
|
81
|
+
readonly mode: Mode;
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
/**
|
|
85
|
+
* The size of the gap (how many seq steps the derived tier fell behind the
|
|
86
|
+
* authority), used for the `gapSize` event payload — derived from the plan
|
|
87
|
+
* inputs, never a hardcoded literal.
|
|
88
|
+
*/
|
|
89
|
+
export function gapSizeOf(gap: PostCompactGap): number {
|
|
90
|
+
return Math.max(0, gap.authorityHighWater - gap.postCount);
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
/**
|
|
94
|
+
* Map one subsystem's post-compact gap into a production `RepairPlanV1`.
|
|
95
|
+
*
|
|
96
|
+
* Mirrors `heal/controller.ts#planRebuild`: the seq window is
|
|
97
|
+
* `[postCount + 1, authorityHighWater]`, the generation targets `current + 1`,
|
|
98
|
+
* and the backoff is the deterministic heal `computeBackoff`. No clock is read
|
|
99
|
+
* here — the production shape carries no `scheduledAt`; the `nowMs`-injected
|
|
100
|
+
* rate-limit/backoff decisions live in the heal controller (`detectGaps`), which
|
|
101
|
+
* the handler drives with its own injected clock for reproducible fixtures.
|
|
102
|
+
*/
|
|
103
|
+
export function buildRepairPlan(gap: PostCompactGap): RepairPlanV1 {
|
|
104
|
+
const backoffMs = computeBackoff(gap.subsystem, gap.failedAttempts ?? 0);
|
|
105
|
+
return {
|
|
106
|
+
schema: "repair-plan-v1",
|
|
107
|
+
subsystem: gap.subsystem,
|
|
108
|
+
range: [gap.postCount + 1, gap.authorityHighWater],
|
|
109
|
+
generation: gap.generation + 1,
|
|
110
|
+
backoffMs,
|
|
111
|
+
};
|
|
112
|
+
}
|