feat(cache): native .ifclite writer at format v28 with cross-language conformance

Merged
NI
14d ago
+4258-1

Maintainer CI refresh (2026-11-17)

The previously approved Test run 43781076569 checked merge snapshot da773688fe60418df8c231677ba6ff50f38775c2 against old main 4b8a1e2473d4a8b6b11f42dcbe5c2e3dc9ab5cb6. Its semver lane correctly refused workspace 28.2.0 after crates.io advanced to 28.3.0. The current PR merge snapshot carries 28.3.0; this description edit requests a fresh current-base CI event. No crate version or acceptance rule is changed. The two older approval requests (Issue queue 43780555053 and Test 43780555058) are superseded by newer same-head runs and are not additional acceptance requirements. Conformance and full current-base acceptance remain pending.

Part of #9584 (slice 2 of 3: native library writer + cross-language conformance).

Built against the contract in #10349, packages/cache/SPEC.md §12 "Conformance for a second writer":

A second writer (e.g. a native Rust writer) conforms when all of the following hold. Counts alone are never sufficient: equal mesh, edge or row counts can hide wrong ids, coordinates, units, colours or relationships.

§12 itemCovered by
1. Self-reproducible across runs and thread countsrust/cache/tests/self_reproducible.rs; RAYON_NUM_THREADS=1 vs default in the script
2. Readable by BinaryCacheReader.read(), same FORMAT_VERSIONscripts/cache-native-conformance.mjs
3. Scalar sections byte-identical "for the same input"Script, for the same model (not the same IFC file; see "Where this falls short" below). InstancedShards are absent on both sides
4. Geometry: head, directory semantics and decoded chunk bytes identicalScript
5. Storage differences each checked (inflate, byteLength, layout, DeflateRaw under 64 KiB), never maskedScript
6. Empty Properties/Quantities for a STEP-parsed storeScript (both sides write 16-byte empty sections)
7. Negative cases: truncated, bad magic, newer version, corrupt chunk lengthScript

What

New crate rust/cache (ifc-lite-cache, publish = false): writes the browser-readable .ifclite cache at FORMAT_VERSION 28 over the canonical rust/processing pipeline. No second ingest or geometry implementation. In memory and deterministic; no CLI, streaming or spool (slice 3).

pub fn build_cache(source: &[u8], options: CacheOptions) -> Result<(Vec<u8>, CacheStats), CacheError>;
  • Scalar sections from extract_data_model_with(Rooted, properties: false, quantities: false) (#9680). Properties/Quantities are written empty, as the TS writer does for a STEP-parsed store.
  • Geometry from process(...) with meshes chunked in emit order, so the bytes do not depend on batch completion order. Deflate-raw via miniz_oxide directly, so no other crate's features can swap the backend.
  • u32 offsets: a cache past 4 GiB is refused (CacheError::TooLarge), never wrapped.

Fixed relative to the fork prototype (e9ca0bd, v26): SourceHashUnset at bit 3; schema byte per TS SchemaVersion; unmapped type → IfcTypeEnum.Unknown (9999); $ name → null index; shared frame functions instead of a hand-written axis swap; canonical chunk order; plus EntityIndex with its v28 trailer, the #4205 relationship kinds, the shadowed-rel-id trailer, the v27 site origin and finishes.

Conformance (the criterion agreed on #9584)

PropertyTestCI
Byte self-reproducible: 1-thread vs 8-thread rayon pool, and twice on 8rust/cache/tests/self_reproducible.rs (+ RAYON_NUM_THREADS=1 vs default in the script)rust-tests
Scalar sections byte-identical: header incl. xxhash64, section order and offsets, Strings, Entities, Properties, Quantities, Relationships, EntityIndexscripts/cache-native-conformance.mjsBuild job, new step
Geometry: head byte-identical; per chunk AABB bits, uncompressedLength, meshCount equal and inflated payload byte-identical; every decoded mesh record bit-equal. Storage checked per side against its payload: raw stores the payload verbatim; deflated only at ≥ 64 KiB, strictly smaller, and inflating to uncompressedLength. Flags and offsets are checked, not ignored; a raw chunk at or above the floor must not compress strictly smaller under its own writer's compressorsamesame
TS reader acceptance: readHeader, validate(), read({ sourceBuffer }) hash check (changed source rejected); truncated, bad magic, version 29, corrupt chunk-0 length all throwsamesame

Decoded values are also checked against the TS libraries' own tables and the source (IfcTypeEnumFromString, IFC_ENTITY_NAMES, relationshipTypeName, #id=TYPE spans, mesh ids present in the index), so a value both writers would encode identically but wrongly still fails.

Local, with IFC_LITE_REQUIRE_FIXTURES=1: 11 fixtures pass, 7 committed (viewer samples, synthetic finishes/layers/type-map, two georeferenced processing fixtures) and 4 catalogued (AC20-FZK-Haus, MiniBIM, the georeferenced bridge deck). Catalogued AC20-FZK-Haus is read through ifc_lite_testkit::fixture_bytes: it skips locally when absent and fails in CI, where fixtures are required.

Independent oracles (review of 2026-11-15)

Added in 6ab317101..adeb9cba8 (review these on their own). They run in the Build job's conformance step, which now sets IFC_LITE_REQUIRE_FIXTURES=1, so a missing catalogued fixture fails rather than skips.

Review pointCovered by
TS parser as an independent oracle on the same IFC, compared by express ID and decoded valuescripts/lib/cache-native-model-oracle.mjs (compareModelOracle): IfcParser.parseColumnar + EntityExtractor on the same file vs the native cache through the TS reader. No row order or string-pool index is used
GlobalId / Name / Description / ObjectType, absent vs explicit emptyEvery native row against the raw STEP value at the slot its own schema names. Name keeps $ apart from '' (exact match). GlobalId, Description and ObjectType columns hold strings only, so $ and an undeclared slot assert as ''. The TS store's own Description/ObjectType columns are '' on non-group rows, so they are not used as the oracle for those two
Relationship endpoints and classes, both directionsedgeSet: (direction, source, target, kind, rel id, sorted shadowed rel ids) compared as sets, forward and inverse
Schema and unitsSchema byte vs store.schemaVersion; header entityCount vs store.entityCount; lengthUnitScale vs the TS parser, the processing metadata and the browser pre-pass
Row-set difference, stated and testedcompareRowSets. With ROOT = every IfcRoot instance and REF = every TS relationship endpoint plus material leaves: native rows == ROOT ∪ REF exactly; native-only rows are exactly the six classes the TS parser indexes without a row (IfcRelDefinesByProperties, IfcPropertySet, IfcElementQuantity, IfcRelAssociatesClassification/Material/Document) plus referenced non-root resources such as IfcMaterialList; every TS-only row is outside ROOT ∪ REF
Geometry against the canonical processing output, after the frame conversionrust/cache/examples/processing_oracle.rs dumps process() sink events using only processing/core (no writer code). scripts/lib/cache-native-geometry-oracle.mjs applies the Z-up→Y-up conversion itself and requires bit equality: express id, type, class, item/material ids, colour, origin, positions, normals, indices, finish, localBounds, localToWorld. World coordinates must equal MeshFrame::to_world exactly. No tolerances
Georeferenced coverage of CoordinateInfoCommitted: issue_8190_slab_12381.ifc (RTC ~8,000 km, rotated site), issue_8156_wall_43810.ifc (mm, offset site). Catalogued: georeferencer/MiniBIM-3.1-DO_01_VORM.ifc, ifc5/Georeferencing_georeferenced-bridge-deck.ifc (IfcMapConversion). hasLargeCoordinates and wasmRtcOffset vs the pass frame, siteOrigin vs the browser pre-pass, bounds vs the world AABB
Existing payload and storage checks keptUnchanged

Each oracle was checked against deliberate breakage: dropping localToWorld, shifting finishes by one, flipping normals, dropping the unit, and undoing either fix below each fail the gate; the previous round-trip checks alone passed all of them.

Writer bugs the oracles found (fixed in 6ab317101)

  1. An explicit '' Name was written as absent. The data model folds $ and '' into None. The writer now re-reads Name from the source for rows that came back nameless (#4930). Seen on committed issue_8190 #100 IFCPROJECT.
  2. HAS_GEOMETRY was guessed from the class. It is documented as the row's own Representation (#4666); it is now read from attribute 6 of the record. Seen on hello-wall #30 IFCSITE.

Cost: both are recovered with one extra entity index over the source.

Fixed after the CodeRabbit review

  • Rotated sites (fb3cc4a2c): the native pass removes the IfcSite rotation from its vertices, and the cache used to store them without it. The writer now restores it in f64 through MeshFrame::direction_mapper before the f32 cast, so every stored vertex reads back at MeshFrame::to_world with no format change. On the new rotated_site_90.ifc, local (10,0,0) lands at (1000000, 2000010, 0). The 8 non-rotated fixtures write byte-identical caches to before. The geometry oracle now asserts to_world for every tier.
  • Raw storage (0277914f3): every chunk stored raw at or above the 64 KiB floor must not compress strictly smaller under its own writer's compressor (native deflate_raw via conformance_writer --deflated-length; the TS geometry codec for the TS side). A native writer that never compressed passed before; it now fails on infra-bridge. packages/parser/src/** now also runs the gate.
  • Entity index (6f45661cf): a source past 4 GiB or a 65,537th type name is refused instead of wrapping, and a duplicated id keeps every record in file order, as the TS writer stores it.

Gate gap closed

The round trip used to feed the TS writer meshes in chunk order, and grouping is not idempotent on that order (MiniBIM failed at chunk 1's AABB). It now uses the pipeline's emit order, recovered by the geometry oracle, so a changed chunk order is caught (checked by reversing the open-chunk order).

Limitations (asserted, not claimed away)

  1. Not the browser's frame. The native RTC offset and site tier differ from the browser pre-pass; printed per fixture.
  2. Written as absent, not faked, with the absence of the three CoordinateInfo fields asserted: instanced shards / IFNS, v19 appearance provenance (mode 0), v28 selection coverage, v25 shadingColor, wasmRtcFrame, buildingRotation, boundsRecoveryFallbackCount. Every run prints this "Not claimed" list.
  3. Colour updates are applied by the oracle but untested: on_color_update never fires with full_pass.

Revert oracle

The crate is new, so a derived revert cannot compile its tests (INCONCLUSIVE). Eight surgical mutations are registered under tests/evidence/cache-native-*-9584/: string dedupe, the chunk soft-cap close, the $-name null index, the v18 shadow trailer, the absent-source-id sentinel, the SourceHashUnset bit, the own-Representation HAS_GEOMETRY flag, and the site-rotation restore. All eight go red on an assertion locally and restore byte-identically.

CI cost note

To run the conformance step on TS-only format changes, packages/cache/src/** and the conformance scripts (scripts/cache-native-conformance.mjs, scripts/lib/cache-native-*.mjs) were added to the rust paths filter. That arms the Rust lanes for TS-only cache edits. If you'd rather give it its own output, say so.

Size

46 files, +3,781: about 1,880 lines of crate source outside *_tests.rs (doc comments included), about 490 of Rust tests, and about 1,200 of conformance scripts and oracle harnesses (scripts/, rust/cache/examples/). The rest is fixtures and oracle manifests. That is well over the ~1,500 guideline. The oracle commits (6ab317101..adeb9cba8) are separate so they can be reviewed on their own, and slice 3 (#10361) is the natural seam for everything else.

Checks

  • cargo clippy --workspace --all-targets -- -D warnings: clean.
  • cargo test -p ifc-lite-cache: 40 pass (also with IFC_LITE_REQUIRE_FIXTURES=1); cargo test -p ifc-lite-testkit: 21 pass.
  • cargo test -p ifc-lite-processing: 1,392 passed, 0 failed (no file under rust/processing, geometry or core changes; no determinism manifest or golden moved).
  • IFC_LITE_REQUIRE_FIXTURES=1 node scripts/cache-native-conformance.mjs: 12 fixtures pass.
  • Revert oracle: all 8 mutations OBSERVED, tree restored.
  • node scripts/pre-handoff.mjs: all gates pass (retained-free viewer skipped: no viewer build).
  • Cargo.lock: only the new crate entry; no dependency moved.

🤖 Generated with Claude Code

Summary by CodeRabbit

  • New Features
    • Added native Rust support for creating .ifclite cache files from IFC models, including entity, relationship, and geometry data.
    • Cache generation supports optional geometry and source-hash settings, with geometry compression enabled by default.
  • Bug Fixes
    • Improved handling of rotated site coordinates and geometry chunk limits.
  • Tests
    • Added checks for cache consistency, reproducibility, and compatibility across sample models, including validation of cache contents, geometry, and malformed files.
    • Changes to cache-related inputs now trigger Rust validation in CI.