Commit graph

16 commits

Author SHA1 Message Date
Shay
3e2710faee
fix(ingest): close issue #300 — normalize_to_versor margin at the gate (#312)
The bug: ingest.gate.inject raised RuntimeError("Injection produced
non-versor field") on a class of ordinary English token combinations
(declarative-with-quantity + transfer phrase + "How many" question).
Both observed condition values (1.02e-06, 2.12e-06) cleared
unitize_versor's `bad_residue` heuristic but landed just above the
gate's 1e-6 downstream check, crashing the engine on textbook word
problems like:

  "Tom has 5 apples. He gives 2 to Sarah. How many does Tom have?"

Root cause: normalize_to_versor accepted the unitized candidate
without checking that it strictly satisfied the gate's
versor_condition < _RUNTIME_CLOSURE_TOLERANCE (1e-6) contract.
unitize_versor's internal tolerance is permissive for construction-
time inputs; the gate's downstream tolerance is stricter.  When the
two diverged on certain token mixes, the candidate slipped through
and the gate's assert fired.

Fix: mirror the strict-closure pattern from _runtime_closed /
_close_applied_versor.  If unitize_versor succeeds but the result
still fails the public versor_condition < _RUNTIME_CLOSURE_TOLERANCE
contract, project through the deterministic construction map
(_seed_to_rotor) instead of returning the drifted candidate.

Per CLAUDE.md: threshold stays at 1e-6 (Non-Negotiable Field
Invariant).  Construction boundary is where drift is repaired.
The fix lives at the SINGLE allowed normalization site
(ingest/gate.py's only entry point into the algebra) without
loosening any invariant.

Tests added (11):
- versor_condition strictly satisfied on a range of seeded random
  inputs (property test)
- 20-iteration synthetic-marginal probe exercises the construction-
  fallback path
- The three issue-#300 bisected crash repros run end-to-end through
  `core chat` and complete without raising the RuntimeError
- Threshold constant pinned (failing the test if anyone lowers
  _RUNTIME_CLOSURE_TOLERANCE)

Validation:
- All 11 new tests pass
- 37 existing versor / ingest tests pass (test_versor_closure +
  test_versor_*_rust_parity + test_core_ingest + test_unknown_token_ingest)
- Three pre-existing main failures (architectural_invariants
  INV02 / INV21 / INV24) are unchanged by this PR — verified by
  running them against origin/main directly before and after the
  fix
- The three crashing prompts now produce clean grounded surfaces
  through `core chat`

Closes issue #300.
2026-05-26 16:39:49 -07:00
Shay
694754ab46 feat(algebra): null-preserving versor_apply path + un-skip 2 invariant tests
Closes the two skipped null-preservation tests and the architectural
gap behind them.  In CGA, null vectors represent Euclidean points;
under a conformal transformation a point must map to a point —
applying a versor sandwich to a null vector must preserve null
property.  The previous implementation forced everything onto the
unit-versor shell, which is correct for field-state propagation but
wrong for geometric point input.

Implementation
- algebra/versor.py: new `_input_is_null(F)` checks `cga_inner(F,F) ≈ 0`;
  `versor_apply` routes null inputs around `_close_applied_versor`
  and returns the raw sandwich V·F·rev(V), which algebraically
  preserves null property.  Non-null inputs unchanged.
- core-rs/src/versor.rs: `versor_apply_closed_f64` gains the same
  null-check branch via `input_is_null_f64`.  ADR-0020 parity
  preserved (8/8 versor_apply bit-identity tests still pass).

Test changes
- tests/test_architectural_invariants.py::TestINV06NullConePreservation::
  test_versor_apply_preserves_null_property — un-skipped, passes.
- tests/test_rust_backend.py::test_rust_versor_apply_preserves_null_vectors
  — un-skipped, passes.
- tests/test_versor_closure.py::test_versor_apply_closes_null_like_field_
  results_for_runtime_contract — renamed to
  test_versor_apply_preserves_null_property_for_null_inputs and
  rewritten to assert the now-correct semantics (null in → null out).
  The old contract over-specified closure for null inputs and
  contradicted the architectural invariant; that's what kept the
  invariant test skipped.

Stale gap docs updated
- inference_closure / cross_domain_transfer / multi_step_reasoning
  gaps.md now lead with a resolution block: lanes pass at 100% on
  both splits after the typed operators (transitive_walk,
  multi_relation_walk, path_recall in generate/operators.py) +
  pipeline wiring (_maybe_transitive_walk + _fold_walk_into_surface)
  landed.  The historic findings are preserved below for traceability.
- compositionality gaps.md: partial resolution — recall up from
  6.25% to 68.75%; overall_pass True; residual ~30% miss requires
  a relation-aware `compose_relations` operator (v2 follow-on).

Lane health unchanged: algebra 132, smoke 55, runtime 19, teaching 17,
packs 6, cognition 103.  Cognition eval 100%.  Four formerly-"blocked"
reasoning lanes confirmed 100% / overall_pass=True end-to-end.
2026-05-16 21:40:37 -07:00
Shay
8c539df3fa fix(algebra): enforce strict runtime closure after unitize 2026-05-15 23:23:11 -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
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
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
a87c7a9c6f Fix full test suite after cognitive runtime 2026-05-13 13:52:11 -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
b80dd57a9b init: algebra layer — cl41, versor, cga, holonomy 2026-05-12 19:12:48 -07:00