feat(cache): streaming ifc-build-cache CLI with atomic finalize
Part of #9584 (slice 3 of 3: streaming CLI, atomic finalize, bounds, RSS evidence, docs).
Status (2026-11-20)
- Slice 2 (#10356) is on
mainas4504e7045. This branch is rebased onto it, so the diff is slice 3 alone: 31 files, +1828/−349. - Merge base
ee77162e03a93591765ea574392a02ba7e66da08, head48a4873a0175cdcde959d8389a6572d80dff2223. - Outstanding: the fleet-admitted paired RSS run. The harness (#10751,
scripts/perf/cache-stream-ab.mjs) is onmainas0f22ecfe1. It builds both refs in throwaway worktrees, so it runs frommainagainst this PR's refs without moving the head being measured:
The run report and its verdict get attached here, and the verdict goes into thenode scripts/perf/cache-stream-ab.mjs \ --base ee77162e03a93591765ea574392a02ba7e66da08 \ --head 48a4873a0175cdcde959d8389a6572d80dff2223 \ --iters 5 --json cache-rss.jsonscripts/perf/README.mdledger entry. - CI on this head: one red lane,
Viewer E2E smoke (5/8), wherereopen-held-pick.e2e.spec.ts(#10218) timed out waiting for the model load. The same lane passed ond4658dc8c, and the only commit since changesrust/cache/src/stream_tests.rs; this PR touches no viewer file. It needs a maintainer re-run. - The RSS table below is local, diagnostic evidence. It is not the acceptance result.
Streamed output is byte-identical to the in-memory writer's, so slice 2's conformance against SPEC.md §12 (#10349) applies to the CLI's output as well.
What
ifc-build-cache [--no-geometry] [--omit-source-hash] [--no-compress] <input.ifc> <output.ifclite>: a thin CLI over the library.cargo install --locked --path rust/cache; cargo only, no release wiring. PrintsCacheStatsas JSON; exit 0 ok, 1 failure, 2 usage.build_cache_to_path(source, output, options), beside the unchanged in-memorybuild_cache.- Streaming with canonical order. An incremental
Grouperinchunks.rsnow drives both writers, so there is one grouping implementation (first-insertion cell order; a cell reopened after the cap keeps its slot). A chunk closed by the soft cap is serialized and appended to a spool at once; open chunks flush in slot order at the end. RAM holds the 44-byte directory entries and the open cells. Mesh retention is off. No format or order change was needed. - Memory bound. Each open cell holds under the 8 MiB soft cap plus at most one more mesh of any size, so the open chunks are bounded by
chunkCells× 8 MiB plus the largest mesh in each cell.CacheStatsreportschunkCellsandpeakOpenChunkBytes. - Bounds. Every
u32offset and length goes through a checked conversion; past the limit the build fails withCacheError::TooLarge, never wraps. A chunk's forced head bytes (fixed head fields and its directory entry) are counted before the chunk is written;finishkeeps the exact size check for the remaining metadata. - Atomic finalize. Temp file in the destination directory, fsync, rename, parent-dir fsync on unix. A build that fails with an error removes its temp file and spool (
Drop), and only files it created. - Killed builds. A build that is killed, or that panics under the release profile's
panic = "abort", leaves.<output>.<pid>.<n>.tmp/.spoolbehind. Those files never replace the output. A later build skips a taken staging name and moves to the next sequence (up to 1024) without touching the leftover; both names are reserved withcreate_newbefore the build starts. There is no sweep, because a sweep could delete a concurrent build's live spool. The guide documents the leftover pattern. - Section writer in its own module.
ChunkBody,GeometryHeadandSectionWriterlive inrust/cache/src/geometry/section.rs, re-exported fromgeometry/mod.rs.
Tests
| Claim | Test |
|---|---|
| Streamed bytes == in-memory bytes (and equal stats, nothing else left in the dir) | tests/streamed_matches_in_memory.rs: issue_9584_committed_samples_stream_byte_identical_under_every_option, issue_9584_catalogued_fixtures_stream_byte_identical (catalogued models when fetched) |
| Independent of pipeline batch size | stream_tests::streamed_bytes_do_not_depend_on_the_job_chunk_size (1, 7, 1024 jobs) |
CLI output == build_cache over a stale existing output, no staging file left | scripts/cache-native-conformance.mjs (CLI check in scripts/lib/cache-native-cli.mjs) |
| A chunk past the limit is refused before it is written, counting the head bytes it forces | section_tests::issue_9584_a_chunk_that_crosses_the_limit_is_refused_before_it_is_written, …_the_bytes_a_chunk_forces_into_the_head_are_counted_before_it_is_written |
The exact size check in finish (exactly-at-limit passes, one under is refused) | section_tests::issue_9584_a_head_that_crosses_the_limit_is_refused_at_finish, …_a_head_larger_than_the_smallest_is_refused_at_finish (optional CoordinateInfo fields, so only the finished head crosses the limit) |
| The limit counts from the section start | section_tests::the_limit_counts_from_the_section_start |
| A cache past the limit is refused and leaves nothing | stream_tests::issue_9584_a_cache_past_the_limit_is_refused_and_leaves_nothing (injected Limits, not a 4 GiB write) |
| Mid-geometry failure leaves no output, temp or spool; an existing output keeps its bytes | stream_tests::issue_9584_an_injected_mid_geometry_failure_leaves_no_output_temp_or_spool (fails after a chunk is already spooled), a_missing_output_directory_is_an_error_and_creates_nothing |
| A failure inside the commit, after the temp file is fully written, removes it | stream_tests::issue_9584_a_failed_rename_removes_the_written_temp_file (a directory at the output path fails the rename) |
| Staging removes only files it created; a taken name is left for its owner | stream_tests::issue_9584_a_taken_staging_name_is_not_removed |
| A leftover staging name from a killed build is skipped, not fatal, and survives | stream_tests::issue_9584_a_leftover_staging_name_is_skipped_not_fatal |
The site rotation is restored identically when streaming (on_frame) | tests/streamed_matches_in_memory.rs on rotated_site_90.ifc and issue_8190_slab_12381.ifc |
RSS: local evidence, not acceptance
Apple M2 Pro, 10 cores, 16 GB, macOS, shared host at load 4–6; release; /usr/bin/time -l; 2 interleaved runs each. Base = slice 2 before the rebase (5093d52f3) in-memory, not the merge base ee77162e0; the fleet run measures against the latter. Peak RSS in MiB. Floor = geometry pass alone with meshes dropped (examples/pipeline_floor.rs); data model = --no-geometry.
| Model (source MB) | Meshes | Floor | Data model | Base in-mem | Branch in-mem | Streamed |
|---|---|---|---|---|---|---|
| AC20-FZK-Haus (2.5) | 285 | 20 | 14 | 27 | 27 | 28 |
| ISSUE_129 (12) | 1,402 | 106 | 84 | 158 | 153 | 159 |
| dental_clinic (13) | 5,927 | 87 | 120 | 177 | 174 | 170 |
| FM_ARC_DigitalHub (14) | 4,058 | 100 | 77 | 134 | 150 | 149 |
| 01_BIMcollab_Example_ARC (18) | 7,846 | 106 | 93 | 167 | 163 | 162 |
| advanced_model (35) | 11,472 | 165 | 230 | 463 | 475 | 401 |
| schependomlaan (49) | 6,062 | 128 | 245 | 322 | 246 | 242 |
| ISSUE_068 (56) | 16,777 | 277 | 377 | 646 | 628 | 505 |
| Holter_Tower_10 (177) | 110,633 | 557 | 907 | 1,492 | 1,470 | 1,098 |
- Output bytes identical across base in-memory, branch in-memory and streamed on all 9 models, every run.
- Retention is gone: streamed peak stays at or below data model + floor (8 of 9; 6 MiB over on advanced_model). In-memory exceeds it by the retained mesh set (~370 MiB on Holter).
- Not flat in absolute terms: the data-model phase dominates large models (907 MiB alone on Holter). Running geometry before the data model did not help (one Holter run, 1,110 MiB). No wall-time claim: moves were within noise on this host.
- The
scripts/perf/README.mdledger entry is headed "Measured locally, acceptance pending" and carries the same caveat about the base column. The verdict is recorded there once the fleet run is attached.
Docs
docs/guide/native-cache.md (nav after "Server Guide"): install, flags mapped to BinaryCacheWriter options, guarantees (including what a killed build leaves behind), the per-cell memory bound, and what a native cache leaves out. It links packages/cache/SPEC.md (#10349, merged).
Revert oracle
Slice 2's eight surgical mutations under tests/evidence/cache-native-*-9584/ are already on main. This PR adds two, cache-native-stream-bounds-9584 (the per-chunk u32 bound) and cache-native-stream-cleanup-9584 (staging cleanup), and re-targets two, cache-native-chunks-9584 at the Grouper and cache-native-rotation-9584 at the streaming pipeline.
A hand-written mutation is admitted only for a production file the PR adds. After the rebase geometry/mod.rs is modified rather than added, which is why the section writer moved to the new geometry/section.rs: the bounds mutation targets that file.
Notes
- New dependency
memmap2 = "0.5", already inCargo.lockvia the workspace (+1 lock line). examples/pipeline_floor.rsexists only to make the floor column reproducible; happy to drop it.CacheErroris now#[non_exhaustive]with anIovariant (crate ispublish = false).- Not tried on Windows.
Checks
cargo test -p ifc-lite-cache: 50 unit, 5 self-reproducible, 2 streamed-vs-in-memory.cargo clippy -p ifc-lite-cache --all-targets -- -D warnings: clean atd4658dc8c; the one commit since (48a4873a0) only changesstream_tests.rs.- Native cache conformance: 12/12 fixtures in CI at
e8bd18eea, including AC20-FZK-Haus, the georeferenced MiniBIM model and the IFC5 bridge deck. node scripts/pre-handoff.mjs: 17 gates pass, 1 skipped (retained-free viewer: no viewer build), atd4658dc8c.
🤖 Generated with Claude Code
Summary by CodeRabbit
- New Features
- Added a native command-line tool for building
.ifclitecache files and reporting build statistics. - Added a streaming cache option that writes directly to a file and produces output matching the in-memory builder.
- Cache files are committed through atomic replacement; temporary files created during an unsuccessful build are cleaned up.
- Build options can omit geometry or the source hash, or disable geometry compression.
- Cache statistics now include geometry chunk-cell counts and peak open-chunk memory.
- The command-line tool can be installed with Cargo; prebuilt binaries are not currently provided.
- Added a native command-line tool for building
- Documentation
- Added a guide to installing and using the native cache builder, including its options, output, and limitations.