From 7952026a5d0a54ae79a060440595da85973be746 Mon Sep 17 00:00:00 2001 From: Shay Date: Mon, 13 Jul 2026 22:05:26 -0700 Subject: [PATCH] =?UTF-8?q?feat(adr-0241):=20GREEN=20holographic=20vault?= =?UTF-8?q?=20=E2=80=94=20VaultStore-backed=20standing-wave=20spectrum?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Implement HolographicVaultStore seal/load/resonant_recall on VaultStore.store (INV-21 allowlist). SPECULATIVE default; COHERENT only via authorized review seal. Restart reconstruction-over-storage; empty spectrum refuses confabulation; closure/drift gate on seal. WaveManifold energy for lock-in. Ledger W5 green. --- core/physics/__init__.py | 6 + core/physics/holographic_vault.py | 154 +++++++++++++++--- .../research/third-door-blueprint-fidelity.md | 6 +- tests/test_architectural_invariants.py | 4 + 4 files changed, 141 insertions(+), 29 deletions(-) diff --git a/core/physics/__init__.py b/core/physics/__init__.py index cad95bc6..ae2d6c75 100644 --- a/core/physics/__init__.py +++ b/core/physics/__init__.py @@ -77,6 +77,11 @@ from core.physics.trajectory_invariants import ( relative_holonomy, trajectory_divergence, ) +from core.physics.holographic_vault import ( + HolographicVaultError, + HolographicVaultStore, + SealedMode, +) __all__ = [ "SalienceOperator", "SalienceMap", "FieldRegion", @@ -110,4 +115,5 @@ __all__ = [ "TrajectoryAssessment", "TrajectoryInvariantError", "assess_trajectory", "energy_boundary_ok", "relative_holonomy", "trajectory_divergence", + "HolographicVaultError", "HolographicVaultStore", "SealedMode", ] diff --git a/core/physics/holographic_vault.py b/core/physics/holographic_vault.py index 92764ed4..e6bcc3f1 100644 --- a/core/physics/holographic_vault.py +++ b/core/physics/holographic_vault.py @@ -1,32 +1,34 @@ """ core/physics/holographic_vault.py -ADR-0241 durable holographic standing-wave spectrum (issue D / vault store). +ADR-0241 durable holographic standing-wave spectrum (vault-backed). Session-local WaveManifold modes are not enough for restart lock-in. This module is the **durable** standing-wave path: * Writes go through ``VaultStore.store`` only (INV-21 one-mutation-path; - this module must be allowlisted when GREEN). + this module is on ALLOWED_VAULT_WRITERS). * Default epistemic status is SPECULATIVE (INV-22/23); COHERENT only via - explicit authorized seal (INV-29 transitions stay in vault/store.py). + explicit authorized seal (status stamped at store time — INV-29 remains + owned by vault/store.py transitions). * Recall is resonant lock-in over stored modes (reconstruction-over-storage), using algebraic reverse-product energy only (no approximate neighbor search). * Empty spectrum / cold start refuses confabulated recall. - -Status: RED stubs (#21-adjacent productization). GREEN implements seal/load/recall. """ from __future__ import annotations +import hashlib from dataclasses import dataclass -from typing import Any, Optional, Sequence +from typing import Any, Optional import numpy as np from algebra.cl41 import N_COMPONENTS +from algebra.versor import versor_condition +from core.physics.wave_manifold import WaveManifold from teaching.epistemic import EpistemicStatus -from vault.store import VaultStore +from vault.store import VaultStore, _parse_entry_status, _status_admits _SCHEMA = "holographic_mode_v1" _KIND = "standing_wave_mode" @@ -53,6 +55,20 @@ class SealedMode: metadata: dict[str, Any] +def _as_mv(psi: np.ndarray, name: str = "ψ") -> np.ndarray: + arr = np.asarray(psi, dtype=np.float64) + if arr.shape != (N_COMPONENTS,): + raise HolographicVaultError( + "bad_shape", name=name, shape=tuple(arr.shape) + ) + return arr + + +def _default_mode_id(psi: np.ndarray) -> str: + digest = hashlib.sha256(np.asarray(psi, dtype=np.float64).tobytes()).hexdigest() + return f"mode-{digest[:16]}" + + class HolographicVaultStore: """Durable standing-wave spectrum backed by VaultStore + WaveManifold recall. @@ -68,13 +84,59 @@ class HolographicVaultStore: ) -> None: self._vault = vault if vault is not None else VaultStore() self.epsilon_drift = float(epsilon_drift) - # Session reconstruction cache — never the sole source of truth. - self._mode_ids: list[str] = [] + self._manifold = WaveManifold(epsilon_drift=self.epsilon_drift) + # Reconstruction cache (never sole source of truth). + self._sealed: list[SealedMode] = [] @property def vault(self) -> VaultStore: return self._vault + def _admit(self, psi: np.ndarray) -> np.ndarray: + """Refuse non-closed or high-drift states (dual-checked unitary residual).""" + arr = _as_mv(psi) + cond = float(versor_condition(arr)) + drift = float(self._manifold.measure_unitary_residual(arr)) + if cond >= _CLOSURE_TOL or drift > self.epsilon_drift: + raise HolographicVaultError( + "not_closed_or_high_drift", + versor_condition=cond, + residual=drift, + epsilon_drift=self.epsilon_drift, + ) + return arr + + def _seal( + self, + psi: np.ndarray, + *, + status: EpistemicStatus, + mode_id: str | None, + metadata: dict[str, Any] | None, + ) -> SealedMode: + arr = self._admit(psi) + mid = mode_id if mode_id is not None else _default_mode_id(arr) + meta: dict[str, Any] = dict(metadata) if metadata else {} + meta.update( + { + "kind": _KIND, + "schema_version": _SCHEMA, + "mode_id": mid, + } + ) + idx = self._vault.store(arr, meta, epistemic_status=status) + sealed = SealedMode( + mode=arr.copy(), + vault_index=int(idx), + epistemic_status=status, + mode_id=mid, + metadata=dict(meta), + ) + # Warm reconstruction cache so same-instance recall works after seal. + self._manifold.register_resonant_mode(arr) + self._sealed.append(sealed) + return sealed + def seal_mode( self, psi: np.ndarray, @@ -86,8 +148,11 @@ class HolographicVaultStore: Refuses non-closed / high-drift states. Never writes COHERENT. """ - raise NotImplementedError( - "HolographicVaultStore.seal_mode: ADR-0241 holographic vault GREEN pending" + return self._seal( + psi, + status=EpistemicStatus.SPECULATIVE, + mode_id=mode_id, + metadata=metadata, ) def seal_mode_reviewed( @@ -100,11 +165,18 @@ class HolographicVaultStore: ) -> SealedMode: """Persist a mode as COHERENT — only with explicit authorization. - Unauthorized calls refuse (proposal-only; same discipline as GoldTether - promote). Does not self-authorize. + Unauthorized calls refuse (proposal-only). Does not self-authorize. """ - raise NotImplementedError( - "HolographicVaultStore.seal_mode_reviewed: ADR-0241 GREEN pending" + if not authorized: + raise HolographicVaultError( + "authorization_required", + detail="seal_mode_reviewed requires authorized=True (review gate)", + ) + return self._seal( + psi, + status=EpistemicStatus.COHERENT, + mode_id=mode_id, + metadata=metadata, ) def load_spectrum( @@ -117,9 +189,27 @@ class HolographicVaultStore: Reconstruction-over-storage: manifold cache is cleared and refilled from vault entries tagged as standing-wave modes. """ - raise NotImplementedError( - "HolographicVaultStore.load_spectrum: ADR-0241 GREEN pending" - ) + self._manifold.clear_resonant_modes() + self._sealed.clear() + for i, meta in self._vault.iter_metadata(): + if meta.get("kind") != _KIND: + continue + status = _parse_entry_status(meta.get("epistemic_status", "speculative")) + if min_status is not None and not _status_admits(status, min_status): + continue + # Read durable versor at live deque index (same as recall/index ABI). + mode = np.asarray(self._vault._versors[i], dtype=np.float64).copy() + mid = str(meta.get("mode_id") or f"idx-{i}") + sealed = SealedMode( + mode=mode, + vault_index=int(i), + epistemic_status=status, + mode_id=mid, + metadata=dict(meta), + ) + self._manifold.register_resonant_mode(mode) + self._sealed.append(sealed) + return tuple(self._sealed) def resonant_recall( self, @@ -129,18 +219,30 @@ class HolographicVaultStore: ) -> tuple[np.ndarray, float, int, SealedMode]: """Resonant lock-in over the durable spectrum. - Empty spectrum / cold start without load → refuse (no confabulation). - Uses algebraic reverse-product energy, never cosine/ANN. + Empty spectrum / cold start without modes → refuse (no confabulation). + Uses algebraic reverse-product energy via WaveManifold. """ - raise NotImplementedError( - "HolographicVaultStore.resonant_recall: ADR-0241 GREEN pending" - ) + if min_status is not None: + # Rebuild filtered view so COHERENT-tier evidence excludes SPECULATIVE. + spectrum = list(self.load_spectrum(min_status=min_status)) + else: + spectrum = list(self._sealed) + if not spectrum: + # Cold start: attempt unfiltered load once. + spectrum = list(self.load_spectrum()) + if not spectrum: + raise HolographicVaultError( + "empty_spectrum", + detail="no standing-wave modes for resonant recall (no confabulation)", + ) + query = _as_mv(psi_query, "ψ_query") + modes = [s.mode for s in spectrum] + mode, energy, idx = self._manifold.resonant_recall(query, modes=modes) + return mode, float(energy), int(idx), spectrum[int(idx)] def spectrum_size(self) -> int: """Number of standing-wave modes currently in the reconstruction cache.""" - raise NotImplementedError( - "HolographicVaultStore.spectrum_size: ADR-0241 GREEN pending" - ) + return len(self._sealed) __all__ = [ diff --git a/docs/research/third-door-blueprint-fidelity.md b/docs/research/third-door-blueprint-fidelity.md index 85583069..84c05c03 100644 --- a/docs/research/third-door-blueprint-fidelity.md +++ b/docs/research/third-door-blueprint-fidelity.md @@ -41,7 +41,7 @@ | W2 | Spectral leakage surprise | ADR-0241 §2.4B | 🟢 subsumed into `surprise_residual` | ADR-0241 | | W3 | Wave polar + multi-pair conjugacy | ADR-0241 §2.4A | 🟢 single polar + multi-pair thin wrap | ADR-0241 | | W4 | Unitary residual + chiral charge readout | ADR-0241 §2.4C–D | 🟢 (Q structural 0 in real Cl(4,1); see §12) | ADR-0241 / #18 | -| W5 | Biography resonant lock-in | ADR-0241 + ADR-0240 | 🟢 unitary lock-in + mode registry / resonant_recall; durable holographic vault store deferred | ADR-0241 | +| W5 | Biography resonant lock-in + durable holographic vault | ADR-0241 + ADR-0240 | 🟢 session registry + `HolographicVaultStore` (VaultStore-backed) | ADR-0241 | | W6 | `core_ha` deprecation / absorption | deprecation plan | 🟢 no live tree + hygiene pin | ADR-0241 | | — | Biography holonomy | (ADR-0240; not in blueprints) | 🟢 sound (pointwise) | — | | — | Temporal admissibility gate | (ADR-0240; not in blueprints) | 🟢 sound | — | @@ -307,7 +307,7 @@ PY | `integrate_biography` | unitary lock-in + mode register + resonant_recall; encode `holonomy_encode` | ### Deferred (explicit, not namesake green) -- Durable holographic memory **vault store** (CRDT-backed standing-wave spectrum) — session registry only today. +- Durable holographic memory **vault store** — 🟢 `core/physics/holographic_vault.py` (VaultStore-backed SPECULATIVE spectrum; restart lock-in). - Rust/MLX acceleration of exp-map / cross-spectral (ADR-0235 later). - Full ADR-0092 reviewer-service integration (promote remains caller-gated). - Optional Rust Ring-1 port of trajectory invariants (Python is authority today). @@ -326,6 +326,6 @@ PY | Trajectory invariants + ADR-DAG embedding — 🟢 Python surfaces | #21 | | Wave-field substrate + operator subsumption (W1–W6) — 🟢 on branch | ADR-0241 | | `core_ha` deprecation — 🟢 no live tree + hygiene pin | ADR-0241 / deprecation plan | -| Durable holographic vault spectrum — deferred | ADR-0241 follow-on | +| Durable holographic vault spectrum — 🟢 HolographicVaultStore | ADR-0241 | Closing a gap = flip its `xfail` in `tests/test_third_door_blueprint_fidelity.py` (or the ADR-0241 suite) to a passing behavioral test and delete the matching characterization lock. That is the definition of "done right" here. diff --git a/tests/test_architectural_invariants.py b/tests/test_architectural_invariants.py index 008e9148..24516142 100644 --- a/tests/test_architectural_invariants.py +++ b/tests/test_architectural_invariants.py @@ -648,6 +648,10 @@ ALLOWED_VAULT_WRITERS: frozenset[str] = frozenset({ # it stores via the same VaultStore.store path (no parallel memory), defaults to # SPECULATIVE (never COHERENT), and writes nothing on a Refusal (wrong=0). "generate/realize/realize.py", + # ADR-0241 durable standing-wave spectrum: holographic modes sealed via the + # same VaultStore.store path (no parallel memory). Defaults SPECULATIVE; + # COHERENT only through explicit authorized seal_mode_reviewed. + "core/physics/holographic_vault.py", }) PROJECT_ROOT_FOR_INV21 = Path(__file__).resolve().parent.parent