docs(cache): specify the .ifclite v28 format and reader compatibility
Merged
NI
15d ago+606+606+012345678901234567890123456789-1-1-0123456789
Part of #9584 (slice 1 of 3: spec only, TS/docs, no behaviour change).
What
packages/cache/SPEC.md: the .ifclite compatibility contract at the current FORMAT_VERSION 28, written from the code with a file:line citation for every claim.
- Wire layout of every section: header and flags, section table, strings, entities, properties/quantities, relationships incl. the v18 shadowed-rel-ids trailer, entity index incl. the v28 relationship-coverage trailer (#9947), geometry head / CoordinateInfo (RTC frame, recovery count,
lengthUnitScale, v27 site origin), the 44-byte chunk directory, chunk storage rule (chooseStoredGeometryChunk), grouping policy, mesh records and trailers, instanced shards (IFNS referenced, not restated). - What the reader actually does with older, truncated and corrupt input (§10, §11): a per-field version-gate table, including fields that have no gate.
- Property/quantity tables from a STEP parse are empty by design; stated as the correct encoding, not a gap (§6).
- §12 states the cross-writer criterion as agreed on the issue: byte self-reproducibility across thread counts; scalar sections byte-identical; geometry compared by exact decoded payload and directory semantics, with storage differences (offsets, lengths,
DeflateRaw) checked explicitly against the inflated payload, never masked. Counts alone are insufficient.
src/spec.test.ts keeps it from going stale: it fails if the declared version, the HeaderFlags / GeometryChunkFlags bit tables or the SectionType values drift from src/types.ts. Mutation-checked: moving SourceHashUnset to bit 4 and the version line to 27 turns it red.
Found while writing it (not fixed here; spec-only)
Each is documented as current behaviour in the spec. Happy to file separately:
- The section table's
sizeis never used by the reader, so a section that overruns decodes into the next one (contradicts the comment atrelationships.ts:29-31). - Quantities
qsetGlobalId(v17) and propertiespsetGlobalIdare not version-gated, so an old cache with non-empty tables is misread. Empty tables (the STEP case) are unaffected. - The reader has no lower version bound except geometry < v13.
StringTable.fromArrayprepends''if entry 0 is not empty, shifting every index; a second writer must emit''first.- The appearance-provenance pool deduplicates by JS object identity, not content; a second writer needs an agreed content rule for head byte identity.
- The TS writer does not filter NaN vertices, but its reader rejects them.
Checks
@ifc-lite/cachetests via turbo:spec.test.ts4/4. The rest of the package passes exceptinstanced-shards.test.ts, which cannot load locally without a built wasm runtime (unrelated, untouched).turbo typecheck --filter=@ifc-lite/cache,pnpm docs:check-samples,pnpm lint: pass.node scripts/pre-handoff.mjs: all gates pass (retained-free viewer skipped: no viewer build).
No changeset: no code or export change.
🤖 Generated with Claude Code
Summary by CodeRabbit
- Documentation
- Added a detailed
.ifcliteversion 28 format specification covering file structure, compatibility, malformed-input handling, geometry encoding, and writer requirements. - Updated the cache documentation to point readers to the specification for byte-level details and conformance guidance.
- Included the specification in the published cache package.
- Added a detailed
- Tests
- Added checks to keep documented format versions, flags, and section types aligned with the implementation.