feat: ternary partition routing for LatticeIndex - #49
Merged
Conversation
…ementation plan Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
…c coverage - sorted(self._map, key=repr) so a bool wildcard (None) in served keys can't raise TypeError and mask the KeyError (breaks the KeyError->422 contract) - persistence round-trip tests for numeric + bool wildcard sentinels - document bool EXACT_KEY string-coalesce reliance
- _normalize_partition_key treats float NaN as missing (spec: null/NaN == absent) - apply_batch normalises key columns up front: absent columns filled, null/NaN coalesced to typed NOT_SET (bool keeps null); routing now mirrors single apply and no missing/NaN row is silently dropped - apply_auto uses validate=False so the witness matrix isn't rerun per call
Closes the final-review coverage gap on the provided-id branch (Codex-fix review). Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
|
❌ The last analysis has failed. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Generalises
LatticeIndexpartition routing from exact dict lookup to ternary + specificity semantics, so a lattice suite can declare wildcard/default partitions and route missing-field contexts correctly. Built on a newMatchStrategy.EXACT_KEYevaluated by an embeddedExpressionRulesEngineover a meta rules-table — routing now reuses the exact same ternary machinery as the constraint layer, so the two cannot drift.Spec:
docs/superpowers/specs/2026-07-19-ternary-partition-routing-design.md· Plan:docs/superpowers/plans/2026-07-19-ternary-partition-routing.mdWhat changed
MatchStrategy.EXACT_KEY(core/constants.py,core/compiler.py) — rule-side-wildcard-only exact match: rule UNKNOWN sentinel →0, rule == context →1, context-side sentinel/UNKNOWN/null vs a specific key →−1(the asymmetry vs stockEXACT, which scores0). Bool: rulenullis the wildcard.accumulator/engine.py) —_extract_partition_keyfills the typed NOT_SET sentinel (Nonefor bool) instead of raising;_normalize_partition_keytreatsNoneand float NaN as missing (spec §1: backend null/NaN ≡ absent).accumulator/lattice.py) — exact dict hit keeps the O(1) fast path; on a miss_routeruns the meta-engine (unique top-specificity winner; 0 survivors →KeyError "No lattice…"; tie →AmbiguousPartitionError, aKeyErrorsubclass so the service's partition-miss→422 handler is unchanged). Structural checks at construction: empty / duplicate / NOT_SET-bearing / keyless →ValueError.apply_batchnormalises key columns up front (absent columns filled; null/NaN coalesced to the typed sentinel; bool keeps null) so it routes identically to singleapply, with no row silently dropped or double-counted.index(lattices, validate=True, max_witnesses=1_000_000)runs an exhaustive witness-matrix check (equivalence classes = specific values + one OTHER per dim), chunked at 100k,ValueErroron cap overflow (no silent sampling).apply_autousesvalidate=Falseso the matrix isn't rerun per call.Lattice.save/load) and CLAUDE.md docs.Testing
804 passed, 36 skipped, 31 pre-registered xfailed · ruff clean · mypy unchanged (94, none new) · backend purity enforced (no new
# allow:tag — count stays at three).Review trail
Executed via subagent-driven development: per-task spec+quality review on every task, an Opus whole-branch review, and an independent Codex adversarial post-implementation review. Real defects found and fixed before this PR:
sorted(self._map)raisedTypeErroron a bool-keyed partition miss, masking theKeyErrorand breaking the KeyError→422 contract (→key=repr).apply_autoreran the full witness matrix every call; float NaN keys weren't normalised;apply_batcherrored on an absent key column where singleapplytolerates it. (A fourth finding — bool NOT_SET structural skip — was adjudicated as a non-issue: bool has no NOT_SET sentinel.)🤖 Generated with Claude Code