Skip to content

feat!: strengthen level-one normalization and move fullmap to schema v6 - #172

Merged
SkyeAv merged 2 commits into
stronger-l1/rust-corefrom
stronger-l1/python-level-one
Sep 15, 2026
Merged

SkyeAv merged 2 commits into
stronger-l1/rust-corefrom
stronger-l1/python-level-one

Conversation

@SkyeAv

@SkyeAv SkyeAv commented Sep 15, 2026

Copy link
Copy Markdown
Owner

BREAKING: strengthens level-one normalization on both sides of the fullmap contract at once — the Python query side routes through the shared Rust normalizer, and fullmap builds derive their keys from the same implementation, moving databases to schema tablassert.fullmap.v6.

Why one PR

  • Two-sided exact-match contract: fullmap lookups are exact string matches between Python query keys and Rust-emitted DB keys. Strengthening one side alone leaves the other's keys unreachable (empirically: the intermediate state failed the agent/e2e suites in CI), so query side and build side land as one atomic layer.

Python query side (src/tablassert/nlp.py)

  • level_one(lf, col): signature and in-place semantics unchanged; the column is cast to string and mapped through rs.normalize_terms via a null-safe map_batches (map_elements stays forbidden per repo convention). Nulls never reach the pyo3 surface; "" stays "".
  • 7 new tests (tests/test_nlp.py) with WHY docstrings: token-order insensitivity, stemming fold, dedupe + whitespace collapse, null/empty preservation, digit/punctuation pass-through, Unicode lowercase, other columns untouched. All 8 pre-existing tests pass unmodified.
  • Hand-keyed fake-fullmap fixtures re-keyed (tests/test_lib.py) to normalized forms, each mapping verified against the real normalizer — expectation-preserving, no weakened assertions.

Rust build side (rust/src/fullmap.rs)

  • emit_term: level-one keys now derive via nlp::normalize_l1, byte-for-byte matching the query side.
  • Quality gates stay pre-stemming: token_qc's banned-token check compares literal spellings (hypothetical, uncharacterized) that Porter2 would mutate (hypotheticalhypothet); a second post-normalization is_dead_term guard blocks terms that normalize onto query-side sentinels. Level-two derivation composes after level one unchanged.

Schema migration

  • SCHEMA_VERSION v5 → v6: the key SPACE changed, so old databases can never be hit by normalized queries; validate_schema rejects v1–v5 loudly with the existing rebuild instruction, covered by v4/v5 rejection tests.
  • Golden pins regenerated deliberately (rust/tests/build_golden.rs, rust/tests/common/mod.rs, rust/tests/extract_prebuilt.rs) with the documented regeneration command; Python real-DB expectations re-keyed; schema strings updated in docs/fullmap.md and docs/cli.md.

Testing

  • cargo test --manifest-path rust/Cargo.toml--lib 126 passed, fullmap 57 passed, --test build_golden 11 passed, 1 ignored (the documented regeneration helper)
  • Targeted Python (test_fullmap, test_cover_fullmap, test_docs_source_of_truth, test_nlp, test_lib) → 471 passed
  • Independent verifier exercise: real-DB lock-step probe over 1,232,064 terms → HITS=1,221,965 EXPECTED_DROPS=10,099 UNEXPECTED_MISSES=0; forged v5-tagged DB rejected loudly through both direct lookup and the production resolve_many path
  • Throughput: golden build ~0.99×; repeated 2M-row builds ≤1.25× of the pre-change baseline
  • CI: python-lint, python-test, python-type, rust all pass on this head

Caveats

  • Existing fullmap databases must be rebuilt (tablassert build-fullmap); prebuilt archives need a re-release.

- nlp.level_one keeps its (lf, col) -> lf signature and in-place semantics but now
  routes the column through rs.normalize_terms via a null-safe map_batches
  (whole-column precedent from coerce.py; map_elements forbidden)
- _normalize_terms_series: cast -> arg_true index mask -> one Rust batch call ->
  scatter back, so nulls never reach the pyo3 Vec<String> surface
- 7 new tests: token-order insensitivity, stemming fold, dedupe + whitespace
  collapse, null/empty/whitespace-only preservation, digit/punctuation
  pass-through, unicode lowercase, other columns untouched
- tests/test_lib.py fake-fullmap fixtures re-keyed to the new normalized forms
  (expectation-preserving: same logical assertions, keys verified against the
  real normalizer) so every commit leaves the suite green

Verified: pytest tests/test_nlp.py tests/test_lib.py -n 0 -> 271 passed, 1 failed
(pre-existing QcRuntimeMissingError: env lacks the [qc] extra, fails at HEAD too);
pyright src/tablassert/nlp.py -> 0 errors; ruff check/format clean.
- route emit_term level-one keys through the shared Rust normalize_l1
  implementation while retaining pre-normalization token/dead-term quality
  gates and post-normalization sentinel protection
- bump the on-disk fullmap schema from v5 to v6 and reject v1-v5 with the
  existing rebuild instruction
- regenerate and document golden pins; update normalized real-DB expectations
  and schema references in docs

Verified: cargo fmt clean; clippy -D warnings clean; Rust lib 126 passed,
fullmap 57 passed, build_golden 11 passed/1 ignored, extract_prebuilt 17
passed; targeted Python 471 passed with only the pre-existing QC-extra failure;
golden and 2M-row builds within 1.25x; independent lock-step probe 1,232,064
terms with 0 unexpected misses; forged v5 lookup rejected loudly.
@coderabbitai

coderabbitai Bot commented Sep 15, 2026

Copy link
Copy Markdown

Important

  • 🔍 Trigger review

This repository does not receive automatic reviews because it has fewer than 10 stars.

⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Advanced

Run ID: 61e0df30-1120-42c2-8720-7df5968b93b2


Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@SkyeAv
SkyeAv added this pull request to stack #177 September 15, 2026 17:41
@SkyeAv SkyeAv changed the title feat: [US-002] strengthen Python level_one via the Rust batch normalizer feat: route Python level_one through the Rust normalizer Sep 15, 2026
@SkyeAv
SkyeAv marked this pull request as ready for review September 15, 2026 17:42
@SkyeAv
SkyeAv removed this pull request from stack #177 September 15, 2026 17:50
@SkyeAv
SkyeAv added this pull request to stack #179 September 15, 2026 17:51
@SkyeAv SkyeAv changed the title feat: route Python level_one through the Rust normalizer feat!: strengthen level-one normalization and move fullmap to schema v6 Sep 15, 2026
@SkyeAv
SkyeAv merged commit 77378c6 into main Sep 15, 2026
9 checks passed
SkyeAv added a commit that referenced this pull request Sep 15, 2026
Cut 19.0.0 and bump the package version in pyproject.toml, CITATION.cff,
and uv.lock.

Major: five breaking changes ship. The `tablassert` console command now
requires the optional `[cli]` extra, since `cyclopts` and `rich` left the
base install (#187). Level-one normalization redefines fullmap keys as
cleaned Unicode-lowercase, Porter2-normalized, byte-ordered token sets and
moves the database to schema v6, so every schema-v5 fullmap is rejected and
must be rebuilt (#171, #172, #174, #175, #176). `build-fullmap --aria2c`
is gone -- aria2c is used automatically whenever the `[aria2]` extra is
installed (#178) -- and `--taxon-allowlist` is gone because the built-in
top-100 experimental-taxon allowlist now applies to every build, guarding
both reuse paths by `META.taxon_allowlist` identity (#153). Logging now
requires the `[log]` extra and is fully disabled without it (#152).

Features: `tablassert.net` is a new stdlib-only transient/permanent
classification and retry seam shared by the agent and the BABEL downloader
(#163, #164), with one bounded jittered retry layer across the inner agent,
reflexion, and judge (#167) and machine-readable `error_code` values on
skipped checkpoint records (#166). `build-kg` gained an automatic ephemeral
shared-prefix TCode cache keyed by content-addressed XXH64 op digests
(#155-#159, #161). The `--distill` corpus became schema-uniform v2 with a
sibling `outcomes.ndjson`, a deterministic `RewardConfig`-tunable reward,
and the new zero-dependency `tablassert distill-weigh` command (#180-#183).
`CLASS_FIELD_OVERRIDES` grants the DAKP sparse qualifier stack on the pinned
association classes (#188).

Fixes: `distill-export` partitions its corpus by content and unions the
schema across record files, so a mixed v1/v2 directory no longer CastErrors
or silently stringifies a column (#184); BABEL retry warnings survive the
loguru sink; PMC downloads are idempotent, atomic, and bounded-parallel
(#165); reflexion and judge prompts are hard-bounded (#168).

Changelog:
- versioned the Unreleased section as 19.0.0 - 2026-09-15
- merged three duplicate `### Added` blocks into one
- moved the two `BREAKING:` entries from `### Changed` into
  `### Breaking Changes` and added a `**Migration:**` note to all five
- added PR links to all 17 entries, which carried none
- added the missing entries: the distill v2 corpus/reward/distill-weigh
  stack (#180-#183), the distill-export schema-drift fix (#184), the
  TCode run-cache detail (#155-#161), and the README badge removal (#154)

Docs: none needed here. Every shipped doc change landed with its own PR,
and the docs source-of-truth gate passes against the bumped tree.

Testing:
- make check -> exit 0
- uv run ruff check . -> All checks passed!
- uv run pyright -> 0 errors, 0 warnings, 0 informations
- uv run pytest -> 1622 passed, 52 skipped
- cargo test --manifest-path rust/Cargo.toml -> 156 passed, 0 failed
- cargo clippy --all-targets -- -D warnings -> clean
- uv lock --check -> resolved 169 packages, lock current
- uv run mkdocs build --strict -> exit 0
- docs SSOT + CLI coverage after the changelog edit -> 204 passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant