Commit graph

30 commits

Author SHA1 Message Date
Shay
70e58ce446 feat(adr-0020): parity gates for cga_inner, geometric_product, versor_condition, versor_apply
ADR-0020 next-level: close the parity-gate hole on the four remaining
ungated Rust surfaces.

Gates landed (subprocess-based, raw f32/f64 byte equality):
  cga_inner         — 14/14 bit-identical (random + basis blades + self-norm)
  geometric_product — 15/15 bit-identical (random + basis blades + scalar identity)
  versor_condition  —  9/9  bit-identical AFTER kernel fix
  versor_apply      —  8/8  intentionally skipped (see below)

Kernel fix: versor_condition_raw

  The Python source-of-truth (algebra.versor.versor_unit_residual) folds
  the geometric product + identity subtraction + Frobenius norm in f64.
  The Rust kernel was folding in f32, drifting by 1 ULP on out-of-shell
  inputs. Rewrote versor_condition_raw to promote inputs to f64, use the
  existing geometric_product_f64/reverse_f64 building blocks, and cast
  only the final scalar back to f32. Python is canonical per CLAUDE.md
  sequencing rule 5.

Honest disable: versor_apply

  The Rust versor_apply_closed diverges structurally:
    (1) precision    — f32 sandwich vs Python's f64 throughout
    (2) closure form — Rust has a null-vector early branch + no
                       post-unitize condition recheck; Python is the
                       inverse (no null branch; recheck + seed-rotor
                       fallback)
  Per ADR-0020 "default-off until parity passes", the Rust dispatch for
  versor_apply is disabled in algebra/backend.py with a pointer to the
  gate. The parity tests are skipped with explicit reason. The follow-up
  f64 port is documented in the ADR's new Parity status table.

Lane registration: all four parity files added to --suite algebra.
After: algebra 124 passed, 8 skipped (was 86). All other lanes green:
smoke 54, runtime 19, cognition 57, teaching 17, packs 6. Cognition
eval 100%.
2026-05-16 20:37:58 -07:00
Shay
e36998d25d perf(rust): zero-copy vault_recall — Rust beats Python at scale
ADR-0020 follow-on (task #35). Two-pronged fix:

1. Kernel: ported ADR-0019 Stage 1 diagonal-metric kernel to
   core-rs/src/vault.rs. Per-versor scoring is now 32 multiplies
   + 32 adds via the precomputed Cl(4,1) metric, not the
   1024-op full geometric_product the prior path computed.
   Bit-identity preserved by serial fold order matching Python.

2. Zero-copy marshalling: replaced Vec<&PyAny> + extract-per-
   versor with PyReadonlyArray2<f32> via the numpy Rust crate.
   The Rust binding now reads a slice view directly into the
   numpy buffer — no Python→Rust copy, no Vec<[f32;32]>
   re-chunk. Python caller passes the (N, 32) ndarray as-is
   (ascontiguousarray ensures C-contiguous f32).

Result:
  N      python   rust    speedup
  1k     0.20ms   0.26ms  0.77x  (Python wins on fixed overhead)
  10k    1.62ms   1.45ms  1.12x
  100k   19.22ms  12.93ms 1.49x
  1M     251.50ms 131.36ms 1.91x

Parity bit-identical (raw f32 bytes) at every scale across the
parameterised test in tests/test_vault_recall_rust_parity.py.

Both ADR-0020 first-surface gates now pass: parity AND
performance at the scales where Rust is meant to win. Python
remains the default per CLAUDE.md sequencing rule 5;
CORE_BACKEND=rust is now a legitimate opt-in acceleration.

Smoke 27/27, algebra 70/70, runtime 19/19 all green.
2026-05-16 17:25:41 -07:00
Shay
9e1add43a1 feat(phase4): long-context-cost lane + ADR-0019 Stage 1 vault recall vectorisation
Phase 4 lane #2 (long_context_cost) measured vault.recall latency
as a function of vault size N. The pre-vectorisation curve was
median 875 ms at N=1k, ~9 s at N=10k — unfit for runtime use.

ADR-0019 Stage 1 replaces the per-element Python dispatch loop in
algebra/backend.py::vault_recall with a vectorised exact scan over
the diagonal Cl(4,1) CGA inner-product metric. Per-versor serial
component reduction order is preserved, so scores are bit-identical
to the scalar cga_inner path. CLAUDE.md exactness is preserved; no
approximate recall is introduced.

Post-vectorisation: 0.217 ms at N=1k, 20.795 ms at N=100k. Slope
0.99 (linear). ~4,000-5,000x speedup at every probed N. Smoke,
algebra, and runtime suites all green.

Stages 2 (norm-bucketed exact pre-filter) and 3 (layered store
with deterministic promotion) are documented in ADR-0019 but
deferred — Stage 1 has dissolved the bottleneck at the scales
relevant to current curriculum work.
2026-05-16 16:39:30 -07:00
Shay
07f49eb215 fix(drift): proper rotor-manifold scaling; restore respond contract
Three issues in the drift-fix landing (922bddc) addressed:

1. algebra/rotor.py: add rotor_power(R, alpha) — slerp on the rotor manifold
   via the rotor's exp/log decomposition. Handles both rotation planes
   (cos/sin) and boost planes (cosh/sinh); falls back to identity for
   non-simple bivectors or null cases.

2. generate/stream.py: the score-weighted vault recall previously did
   `weight*V + (1-weight)*np.eye(V.shape[0])`. Two bugs:
   - np.eye produced a 32x32 matrix for a 1D multivector, crashing
     versor_apply with a broadcasting error (2 cognition tests failing
     on main).
   - The linear blend produced multivectors with versor_condition up to
     2.2e-2, violating the non-negotiable 1e-6 invariant declared in
     CLAUDE.md. Now uses rotor_power(V, weight) which stays on the
     manifold by construction (versor_condition <= 1.1e-16).

3. session/context.py: respond() now re-binds result.final_state to
   self.state after finalize_turn's anchor pull, restoring the
   "respond returns the same object that was vaulted" contract
   (test_engine_loop_proof regression).

Verification:
- 41 new tests in tests/test_rotor_power.py covering closure preservation,
  alpha=0/1 boundaries, half-angle composition, and word-transition rotors.
- Empirical multi-turn versor_condition stays at machine epsilon with
  anchor pull, max 9.4e-7 without (under threshold either way after fix).
- Full suite: 609 passed, 4 skipped, 0 failed.
2026-05-16 11:44:45 -07:00
Shay
8c539df3fa fix(algebra): enforce strict runtime closure after unitize 2026-05-15 23:23:11 -07:00
Shay
5af7a4d750 fix(algebra): require explicit rust backend opt-in 2026-05-15 23:19:23 -07:00
Shay
d09b1c8ad0 fix(algebra): close runtime versor applications in float64 2026-05-15 23:18:07 -07:00
Shay
7aa8626ec4
fix(algebra): make versor_apply close runtime field results
Remove the implicit null-vector bypass from the runtime-facing versor_apply closure boundary.

FieldState.F is treated throughout the runtime and cognitive pipeline as a unit versor field. Returning null-like raw sandwich results from versor_apply created a contract mismatch and allowed multi-turn closure drift to escape into session state.

- make _close_applied_versor always close runtime field results
- keep unitize-first semantics and construction-seed fallback
- add regression proving null-like sandwich output is closed for the runtime contract

Null-vector preservation should return later behind an explicit geometry API, not the generic runtime field propagation path.

No GitHub CI/status checks were exposed for this PR.
2026-05-15 23:12:26 -07:00
Shay
be6b278dc4
fix(algebra): enforce transition rotor invariants
Replace synthetic word-transition rotor construction with the closed product B * reverse(A).

- preserve make_rotor_from_angle compatibility
- fail closed on non-closed transition candidates instead of using construction fallback behavior
- validate transition operator condition
- add targeted transition rotor regression tests

No GitHub CI/status checks were exposed for this PR.
2026-05-15 21:13:14 -07:00
Shay
eb30c75810 feat: Full Proof — surface realizer join, Rust diffusion parity, benchmark harness
Surface realizer join: pulse output_versor → vault recall → ground_graph fills
<pending> obj slots with recalled words → realize_semantic produces deterministic
sentences. PulseResult replaces bare word list. Every intent type surfaces.

Rust backend parity: unitize_f32 (exponential-map with boost/rotation blade
distinction) and graph_diffusion_step now in core-rs. Python dispatches through
algebra.backend, falls back transparently. 37x speedup on 200-step diffusion.

Benchmark harness (core bench): determinism (100% trace stability), latency
(~150ms median), backend speedup, versor closure audit (0 violations across all
intermediate states), convergence proof (41/45 exact, 4 bounded oscillation),
realizer coverage (8/8 intent types).

Proof property tests (31 tests): Rust/Python parity, pulse determinism across
prompts, V3 convergence for 10+ topologies, coupled V4 output validity, realizer
coverage per intent, versor closure at every intermediate step.

CLI: core pulse, core bench, core test --suite pulse, core test --suite proof.
Fix test_correction_pulls_toward_target (diffuse first, then correct).
2026-05-15 17:39:14 -07:00
Shay
523c072818 feat: vault recall index, Rust versor parity, cognitive pack expansion
Phase 3 — vault exact recall index:
- Replace O(N) np.array_equal scan with hash-based exact-match index
- Add optional max_entries with deterministic FIFO eviction
- Index rebuilds on reproject for consistency

Phase 4 — Rust versor_apply parity:
- Fix CGA metric signature (+,+,+,+,-) and blade ordering to match Python
- Implement versor_apply_closed with null-vector preservation, f64 unitize,
  and construction seed fallback matching Python closure semantics
- Gate Rust dispatch behind CORE_BACKEND=rust; Python remains default
- Add f64 geometric product for closure-path precision

Phase 5 — cognitive quality pack expansion:
- Expand lexicon from 55 to 70 entries (evidence, inference, procedure,
  verification, distinction, relation, thought, understanding, judgment,
  principle, order, connectives)
- Improve semantic templates for cause, procedure, comparison, recall,
  verification intents
- Expand eval cases from 20 to 45 across all categories

Validation: 491 tests pass, 45 eval cases at 100% all metrics.
2026-05-15 15:34:39 -07:00
Shay
249592c37e
Fix final runtime suite regressions
- preserve null vectors through versor_apply
- keep algebra closure for non-null sandwich outputs
- downgrade declarative refute telemetry to elaborate
- make minimal English question surfaces prompt-sensitive
2026-05-14 19:16:57 -07:00
Shay
2bd70d0a9d
Fix remaining runtime regressions after contract cleanup
- close versor_apply outputs at algebra boundary
- route backend versor_apply through canonical closure semantics
- keep selected ChatResponse surface equal to ArticulationPlan surface
- derive proposition relation from selected slots
- rank proposition slots with pure CGA metric
2026-05-14 19:05:36 -07:00
Shay
c46eae8fc8
Fix main chat test regressions
- make async chat reuse initialized synchronous chat lifecycle
- restore make_rotor_from_angle compatibility helper
- restore identity ValueAxis export and legacy IdentityCheck call style
- preserve legacy reasoning trajectory fixtures for existing tests
2026-05-14 15:48:45 -07:00
Shay
541b1646b2 Fix test suite errors across core physics and generation
Key issues fixed:
- `CORE_BACKEND=numpy` was ignored, so tests mixed Python CGA embedding with Rust metric behavior.
- Dense construction seeds were being rejected by strict `unitize_versor()`, while sparse dirty inputs still needed to fail closed.
- Holonomy needed a construction-boundary path for raw/dense vocab fixtures and rare null final accumulators.
- Proposition storage polluted vault recall by storing the live field instead of the proposition’s subject versor.
- Dialogue qualitative frames rendered the same surface as assertive copular frames.
- Repeated session prompts could collapse into the same deterministic response path.
- Two proof fixtures were stale: one hand-built a non-null “null” vector, and one alignment proof omitted the English “with” anchor used by the resonance proof.

Verification:
`CORE_BACKEND=numpy CORE_STRICT_MLX_ON_APPLE=0 uv run core test -- -q`
Result: `277 passed in 59.52s`
2026-05-14 13:02:32 -07:00
Shay
fbbd7c52e3 Fix fail-closed versor construction 2026-05-14 12:13:04 -07:00
Shay
2e8169bbb0 Allow float32 residue roundoff in versor construction 2026-05-14 12:13:04 -07:00
Shay
79e28c5835 Fail closed on invalid versor construction 2026-05-14 12:12:43 -07:00
Shay
9723941a38
Fail closed on invalid versor construction
Make versor construction fail closed instead of synthesizing hash-derived fallback rotors.

- remove pseudo-random construction fallback from unitize_versor
- add signed residual helper for +1 field states vs ±1 manifold entries
- validate vocab manifold entries with full residuals
- document antipodal transition rotor failure contract
- add focused invariant tests for versor closure and manifold validation
2026-05-14 10:55:11 -07:00
Shay
df9ced7104
Activate and verify Rust backend
Add Rust backend CLI controls, fix core-rs build/test configuration, align Rust Cl(4,1)/CGA conventions with Python, and validate core_rs activation.
2026-05-13 22:23:48 -07:00
Shay
a87c7a9c6f Fix full test suite after cognitive runtime 2026-05-13 13:52:11 -07:00
Shay
99c0e31bbe fix(INV-02): replace normalize_to_versor with unitize_versor at construction sites
algebra/rotor.py and persona/motor.py were calling normalize_to_versor()
which is the gate-only injection primitive. Both are construction-time
sites (building rotors and motors from raw arrays), so the correct call
is unitize_versor().

Also tightens TestINV02 to scan for normalize_to_versor violations only —
unitize_versor has its own legitimate call sites and is not under the
same single-site restriction. Adds a new TestINV02b that verifies
unitize_versor is NOT called inside propagation, generation, or vault
recall paths.

Fixes: INV-02 architectural invariant test failure.
2026-05-13 13:14:59 -07:00
Shay
fca6216e3f Stabilize holonomy accumulation 2026-05-13 12:54:53 -07:00
Shay
ba45158f8e Fix CGA null embedding convention 2026-05-13 12:51:49 -07:00
Shay
4fe19c08ba Fix Python Cl41 blade product table 2026-05-13 12:51:26 -07:00
Shay
5b34b72158 Fix versor condition residual 2026-05-13 12:49:53 -07:00
Shay
3746f06898 fix: cohesive seam pass — frozen FieldState, GenerationResult, generation/vocab/algebra separation, normalization doctrine
- field/state.py: FieldState is now frozen+slotted; constructor copies and
  enforces float32 shape (32,); advance() updated to pass raw arrays.
  np.ndarray inside frozen dataclass is ref-frozen — copy() at construction
  is the explicit contract boundary.

- generate/result.py: NEW — GenerationResult frozen dataclass carrying
  tokens + final_state. Async variant yields tokens and exposes final_state
  on completion.

- generate/stream.py: generate() now returns GenerationResult, not list[str].
  vocab.edge_rotor() call replaced with:
    A = vocab.get_versor_at(current.node)
    B = vocab.get_versor_at(word_idx)
    V = word_transition_rotor(A, B)
  agenerate() updated to yield tokens and surface final_state.

- vocab/manifold.py: added get_versor_at(idx) and get_word_at(idx) indexed
  accessors. VocabManifold stores points; algebra constructs operators.
  normalize_to_versor() call-site in docstring clarified: callers must call
  unitize_versor() (algebra construction primitive) before add(), not
  normalize_to_versor() directly.

- algebra/versor.py: unitize_versor() added as the explicit construction-time
  primitive. normalize_to_versor() kept but marked internal/gate-only.
  Distinction encoded in docstrings and __all__.

- persona/motor.py + ingest/gate.py: SessionContext.respond() is not yet in
  the repo as a separate file; gate.py docstring updated to reflect the
  three-tier normalization doctrine:
    unitize_versor()    — algebra construction only
    inject()            — gate, once per raw input
    normalization       — forbidden in propagate/generate/vault recall
2026-05-13 12:32:36 -07:00
Shay
bd423e489c arch: close coordinate back-door in vocab layer
- Add algebra/rotor.py: word_transition_rotor() as a free operator function
- Update algebra/__init__.py: export word_transition_rotor
- Refactor vocab/manifold.py: remove edge_rotor(), add versor grade-norm
  invariant check in add() to reject raw coordinate vectors at insertion time

VocabManifold now stores only algebraically valid Cl(4,1) versors and
exposes only relational lookup (CGA inner product). Rotor construction
is a contextual algebra-layer concern, not a vocabulary property.
2026-05-12 20:52:14 -07:00
Shay
f882408e62 init: Rust build config, Python dispatch layer, Rust tests 2026-05-12 19:20:42 -07:00
Shay
b80dd57a9b init: algebra layer — cl41, versor, cga, holonomy 2026-05-12 19:12:48 -07:00