Skip to content

fix(ifc): type objects, hosted cuts, piece sets, wall joins, family blocks and unit registries find what they need through an index, not a scan per element (#1845, #1833) - #1847

Merged
DrunkOnJava merged 2 commits into
mainfrom
fix/1845-1833-linear-scans-to-maps
Nov 12, 2026
Merged

DrunkOnJava merged 2 commits into
mainfrom
fix/1845-1833-linear-scans-to-maps

Conversation

@DrunkOnJava

@DrunkOnJava DrunkOnJava commented Nov 12, 2026 •

Copy link
Copy Markdown
Owner

Summary

Six passes searched a list once for every element where an index answers at once, so a crafted file with many elements took time in their square. Each now builds its index once and gives the same answers in the same order. Nothing here is a budget: no input is refused that was not before. The budgets for the remaining sites follow in their own PR, so a moved hash in either says which kind of change moved it.

Motivation

Part of #1845 (class 3, the linear searches) and #1833 (sites J, O and P, whose designs a challenger found sound). Tendrils audit workers found them, a second worker confirmed each, a challenger tested each design's premises, and I re-read each against main.

Changes

  • src/ifc/step_writer.rs, type_objects: each group's index by its key (type, entity, predefined tail, GlobalId). A key is indexed only when its group is first pushed, so every element joins the group find would have found, and the groups keep their order.
  • src/ifc/mod.rs, attach_hosted_cut_openings: the one building element carrying each tag (None where several do, which the "exactly one host" rule refused before). The openings join entities only after the loop, so an index made before it is exact.
  • src/ifc/export_content.rs, add_piece_sets: each owner's sets as entity indices. A set given to a piece is indexed as it is pushed, as the old rescan of entities would have seen it, so the order is the same.
  • src/research/element_record_wall_joins.rs, Solver::candidates: the walls a wall names are looked up by ElementId, then sorted back into the runs' order. The first candidate, whose thickness is taken, is the same.
  • src/research/native_family_forms.rs, blocks_of:
    • Past 16 keys, one pass over each body's 16-byte windows answers every key. A key is in a body exactly where a window is the key.
    • Up to 16, the per-key memchr search stays, as it is faster there, and skips keys already found.
    • No body is searched once every key has its block.
  • src/research/native_parameter_definitions.rs, ingest_units:
    • A registry equal to the one held returns at once. A definition inserted since was enriched against the same formats on insert.
    • builtin_definitions is never filled during ingestion: nothing inserts into it.
  • changelog.d/security/1845-1833-linear-scans.md.

Testing

  • Unfiltered Measure against the merge-base 8421e655 on c7d668d5 (samples, families, Nordic, Revit 2025, BIMcollab, rac_advanced, held-out, timing): 43316271048. Every export and diagnostics hash should equal the base's. These are hot paths of every export, and type_objects now clones its key and blocks_of has an unmeasured threshold (16 keys), so the timing row is: median head/base at or below 1.00 over the 2023 to 2027 samples, and no file above 1.03.

  • No repro. Each blow-up needs a crafted file with tens of thousands of elements. Each change was verified by reading.

  • tools/check-local.sh: not run locally (no local builds); CI runs it

  • Real files: the unfiltered Measure

Audit-honesty checklist

Legal and contribution hygiene

  • Apache-2.0; no Autodesk source

Breaking changes

None. Every changed function is private.

https://claude.ai/code/session_01L1QUmYwb7cHmeCQU8FD2Ge

…locks and unit registries find what they need through an index, not a scan per element (#1845, #1833)

Each pass searched a list once for every element, so a crafted file with
many elements took time in their square. Each now builds its index once and
gives the same answers in the same order:
- step_writer::type_objects: a group per key, by key.
- attach_hosted_cut_openings: the one element carrying each tag.
- add_piece_sets: each owner's sets, including those pushed to pieces.
- wall_joins: each ElementId's runs, taken in run order.
- native_family_forms::blocks_of: past 16 keys, one pass over each body;
  and no body is searched once every key has its block.
- ingest_units: a registry equal to the one held changes nothing.

Claude-Session: https://claude.ai/code/session_01L1QUmYwb7cHmeCQU8FD2Ge
@DrunkOnJava
DrunkOnJava marked this pull request as ready for review November 12, 2026 23:00
DrunkOnJava added a commit that referenced this pull request Nov 12, 2026
…ene graph's host depth, wall-top parts, roof envelope points, mullion grid cells and space containment are bounded (#1845) (#1848)

## Summary

This takes #1845's classes 2 and 4: recursion depth a crafted file sets,
and work with no cap before the allocation.

- **Profile-cut chains:** written and meshed by a loop, not by
recursion. That is a change of structure, in the same order, so no
output moves.
- **Bounds:** the scene graph's host depth and five counts each get one,
set far above any real model. Past one, that one step is left undone and
the export carries on.

No real file should change; the Measure run checks that.

## Motivation

Part of #1845 (classes 2 and 4; class 1 is #1846, class 3 #1847).
Tendrils audit workers found these, a second worker confirmed each, and
I re-read each against `main`. The cut chain's verifiers marked it
UNSURE: `SKETCH_MAX_CURVES` caps it near 2,048 levels, and whether that
overflows the viewer's stack needs a build. A loop removes the question.

## Changes

- **`src/ifc/step_writer.rs`** `emit_solid_shape`,
**`src/ifc/body_geometry.rs`** `solid_mesh`: a `BooleanResult` chain is
walked down its first operand in a loop.
- The writer writes the innermost operand, then each level's second
operand and result, outward: the ids and order recursion gave.
- The mesher keeps the innermost mesh and appends each union's second
operand, innermost first, as recursion did.
- **`src/ifc/scene_graph.rs`**: an element more than `MAX_HOST_DEPTH`
(16, the bound `step_writer::storey_of` already follows) hosts below its
storey hangs from its storey.
- Before, a crafted file could chain doors through each other: the tree
was built by recursion as deep as the chain, after a walk of the whole
chain from every element in it.
  - Rings are broken as before.
- **`src/ifc/export_content/wall_tops.rs`**:
- `covered_pieces` stops at `MAX_COVERED_PARTS` (1,024, 32 ×
`MAX_RISERS`) parts, before `join_pieces`, which is quadratic in them.
The check after joining stays `MAX_RISERS`.
- `embedded` stops at `4 × MAX_RISERS`, the bound `steps` gives its own
pieces, and returns as soon as nothing is left.
- **`src/ifc/body_geometry.rs`** `envelope_slab_mesh`:
`MAX_ENVELOPE_POINTS` (16 a piece at the piece cap). A sliver split adds
points but no piece.
- **`src/ifc/mesh_volume.rs`** `partner_ends`: a grid cell holding more
than 64 mullion ends is no evidence, and its ends count as continued by
none.
- **`src/ifc/export_content.rs`** `contain_in_spaces`: each storey's
spaces are indexed, where each content scanned the model's. The outline
vertices tested are held to `SPACE_CONTAINMENT_BUDGET` (1e9, five times
a storey of 1,000 rooms under 10,000 pieces); past it nothing is
contained in a space.
- **`changelog.d/security/1845-depth-and-caps.md`**.

## Testing

- Unfiltered Measure against the merge-base `8421e655` on `62ade122`
(samples, families, Nordic, Revit 2025, BIMcollab, rac_advanced,
held-out):
[43317002875](https://github.com/DrunkOnJava/rvt-rs/actions/runs/43317002875).
  - Every export and diagnostics hash should equal the base's.
- A bound a real file reaches would move one: the walls' and roofs'
bodies, the mullions' areas, the space containment.
- Not measured: the scene graph, which the viewer and the tree JSON
read. No run hashes it. A real model's host chains are one or two deep.
- No repro. Each needs a crafted file of thousands of elements. Each was
verified by reading.

- [ ] `tools/check-local.sh`: not run locally (no local builds); CI runs
it
- [x] Real files: the unfiltered Measure

## Audit-honesty checklist

- [x] No claim beyond what ships; the scene graph is unmeasured, stated
- [x] Security changelog fragment
- [x] No emojis or private paths

## Legal and contribution hygiene

- [x] Apache-2.0; no Autodesk source

## Breaking changes

None. `MAX_ENVELOPE_POINTS` is a new public constant beside
`MAX_ENVELOPE_PIECES`. The rest is private.

https://claude.ai/code/session_01L1QUmYwb7cHmeCQU8FD2Ge
@DrunkOnJava
DrunkOnJava merged commit f30f340 into main Nov 12, 2026
64 checks passed
@DrunkOnJava
DrunkOnJava deleted the fix/1845-1833-linear-scans-to-maps branch November 12, 2026 23:44
DrunkOnJava added a commit that referenced this pull request Nov 12, 2026
…ids, sketch loops, empty faces, parameter bindings and family mesh checks are read through an index or under a work budget, so a crafted file cannot hang them (#1833) (#1849)

## Summary

This bounds the rest of #1833: the readers that did work growing with
the square or more of a count a crafted file sets. Each is fixed at its
root. Where an index answers, the reader builds it once. Where none can,
the reader counts its work against a budget no real model comes near.
Past the budget, it leaves the element as an unread stream leaves it.

Every remaining #1833 site is here. The final unfiltered Measure runs on
the head.

## Motivation

Part of #1833. A and B are #1835; J, O and P are #1847. The designs came
from Tendrils workers, a challenger tested each one's premises, and I
re-read and reworked each against `main`. The challengers found eight of
the sixteen designs flawed, and their cases shaped what is here. The
plan with each site's repair is kept with the batch.

## Changes

- **C, D, E** `src/research/partition_pipe_axes.rs`:
- `scan_pipe_end_keys` keeps each end's keys in order with a set beside
them, where a `contains` made it quadratic.
- `BoxGrid::new` stops, giving `None`, past `MAX_GRID_CELLS` (1,024
boxes at the per-box cap). Before, the per-box cap had no total.
- The connector scans count each entry's near boxes or ends against
`MAX_CONNECTOR_TESTS` (1e8). Past it they give nothing for the file.
They do not truncate, since a match never reached could have decided a
pipe (the challenger's case: a tie).
- **F** `src/research/partition_curve_fields.rs`: the windows' entries
and the boxes each is tested against count against the same budget, and
a grid over its cells is skipped. The window is not narrowed: the
challenger showed that could move a real element.
- **G** `src/research/partition_room_parameters.rs`:
- The three text, integer and name scans find each hit's data object in
the stream's listed objects (`memoised_partition_data_objects`,
`data_object_owner`), where each hit searched 200,000 bytes back. On the
local corpus no verified header lies inside a listed object, so the
owner is the one `enclosing_data_object` found.
- `data_objects` reads each header's Adler-32 from sums kept every 256
bytes along the stream, so a header costs at most two blocks of reading
whatever its size, and the pass is linear with no budget.
- The first version capped verification at four times the stream. That
cap was never measured, and real streams pass it. Headers that pass the
size checks and fail their checksum cover Core Interior's
`Partitions/46` 31.7 times over, one of them 94 MB of 99 MB. RE1
Architecture and Electrical reach 12.7x. The cap dropped nearly every
data object (Corpus health, 9 tests).
- Checked by a replica: 3,006 random ranges equal zlib's Adler-32, and
the listing equals the full-checksum listing on every partition of Core
Interior and RE1 Electrical.
- **H** `src/research/partition_room_boundaries.rs`: the export reads
`solid_headers_for`, which keeps headers for the stream's rooms alone,
at most `MAX_SOLIDS_PER_ROOM` (16) each. A room is stored once or twice;
past that it keeps its box. Probes keep the unbounded
`solid_headers_by_id`.
- **I** `src/research/element_record_plan_profiles.rs`: the loop solve
charges each vertex lookup, edge check and candidate pair against
`SOLVE_WORK_BUDGET` (1e8 a sketch owner) before it is spent.
- A slab's sketch has tens of lines (Core Interior's plates own 57,
RE-95).
- Past it the owner has no plan profile and keeps its box. Each owner
needs its own records, so the whole is linear in the file.
- **K** `src/research/native_empty_faces.rs`: `EmptyTrimIndex` walks a
graph once and answers every face. The saved-mesh pass keeps one per
owner graph. Each answer is the one the per-face walk gave, which the
challenger checked case by case.
- **M** `src/reader.rs`: the `header_hits` memo is held under 64 MiB,
dropped whole past it (RE-144: 0.4 MiB at most on the reference models).
A reader keeps its `Arc`.
- **Each stop is reported** (`src/budget.rs`, `src/reader.rs`,
`src/ifc/mod.rs` `record_work_budget_stops`). A budget site notes its
stop (`budget::stopped("pipe_connector_tests")`, and so on). The export
writes a `work_budget_reached` skipped item counting each reader's
stops, and a `Work budget reached:` warning per reader, as it does for a
stream a limit kept out.
- The readers that stop hold no handle, so each notes on its thread. A
`budget::Notes` collects what is noted under the walk and under each
export, and the handle keeps it, as it keeps its unread streams. The
walk is memoised on the handle and holds every site here, so a second
export, or an export after `elements()`, reads it back and still reports
the stops.
- A note under no `Notes` is dropped: a reader called on its own, or on
a saved-mesh worker thread. Every site here runs on the export's thread.
- `ExportDiagnostics::is_partial` is the one test of an incomplete
export: an unread stream or a budget stop. `rvt-ifc` and `rvt-gltf`
print the readers that stopped and exit 3 unless `--allow-partial`, as
for an unread stream. Python's `write_ifc` raises `ValueError` unless
`allow_partial=True`. The MCP server's exports refuse unless
`allow_partial`, and list the readers in `notes` and `partial`.
- The export-decisions count contract
(`tests/export_decisions_counts.rs`, the schema text and
`docs/export-diagnostics.md`) exempts the item, as it exempts
`stream_not_read_resource_limit`: it counts stops, not elements.
- **`changelog.d/security/1833-work-budgets.md`**.

- **N** `src/research/native_parameter_definitions.rs`:
- `seal_bindings`, called where the definitions pass ends, matches each
(category, kind) a binding names once, with its backlink check.
`matching_bindings` reads that answer.
- Before, every record of a category rebuilt every matching definition's
backlinks. Same order, same keys.
- A failure keeps the message `error.to_string()` gave, which is all the
record's diagnostic keeps. An unsealed registry computes as before.
- **Q** `src/research/native_form_geometry.rs`:
- The mesh comparison counts `surface_samples`' points and makes only
the ones its stride takes, each from its place in that order
(`SurfacePlan`). The points and the max are the same.
- Before, every point was made first, up to millions for a crafted
family. The probe keeps `surface_samples`.
- **R** `src/research/partition_scanner.rs`: each stream scan takes the
cap's remainder, the pattern `partition_arc_walls` uses. The candidates
kept are the same first ones, and a stream can no longer double the cap.
- The default stays `None` (the caller's choice; a research API with no
in-tree caller). Setting one needs per-file totals over the corpus
first, which the challenger asked for.

- **L** `src/reader.rs`: the inflated-partition memo is held under
`INFLATED_MEMO_BUDGET_BYTES`, 16 GiB (Griffin, 2026-11-12, "Bound it at
16 GiB").
  - Each stream's inflate was capped, but not their sum.
- No real file comes near: the 1.13 GB client model peaks at 5.1 GB in
all (docs/viewer-api.md).
- Past it the memo is let go before the next stream joins, and a reader
keeps its `Arc`.
- Partition progress now counts each stream inflated once, held or not,
so a release no longer lowers it (the challenger's note on
`release_inflated_partitions`).

## Testing

- Unfiltered Measure, timed, against the merge-base `8421e655` on
`13324f32`:
[43324820431](https://github.com/DrunkOnJava/rvt-rs/actions/runs/43324820431).
It replaces 43320809907, cancelled once Corpus health showed the first
data-object cap dropping data on real files.
- Every export and diagnostics hash equals the base's: `ifc.sha256` on
146 of 146 models and `diagnostics.json` on 121 of 121. Every scorer
file is equal too; the only difference is output the head alone writes
(`probe.txt`, `areas_across_saves*`). No real file reaches a budget: one
that did would move its pipes' ports, curve fields, room parameters,
room outlines, slab profiles, saved-mesh counts, the parameter sets of
`--revit-property-sets` or the family extrusions' mesh agreement, and
its diagnostics would name the stop.
- Timing row, registered before the run: median head/base at or below
1.00 over the 2023 to 2027 samples, no file above 1.03. **It holds:**
median 0.962 (0.917 to 1.007) over those 29 samples, and none more than
3% slower. The models' median is 0.958, since the range sums read each
data object's checksum from two blocks instead of its whole payload.
- Peak memory was not a registered row. Every group's median is 1.000.
Snowdon Plumbing reads 473 MiB at the base and 497 at the head (1.051),
and Snowdon HVAC 250 and 235 (0.94). The base commit `8421e655` itself
reads 474 and 496 for Plumbing and 235 for HVAC in run 43317496752, so
both files land in one of two peaks run by run, whatever the code.
- No repro. Each site needs a crafted file of thousands of elements.
Each was verified by reading. No run exercises the new exit-3 path,
since no real file stops.

- [ ] `tools/check-local.sh`: not run locally (no local builds); CI runs
it
- [x] Real files: the unfiltered Measure

## Audit-honesty checklist

- [x] No claim beyond what ships; R's default stays open on #1833, with
why; the exit-3 path for a budget stop is not exercised by any run
- [x] Security changelog fragment
- [x] No emojis or private paths

## Legal and contribution hygiene

- [x] Apache-2.0; no Autodesk source

## Breaking changes

None. Two new stable methods, `ExportDiagnostics::is_partial` and
`ExportDiagnostics::work_budget_stops`, and
`rvt::cli::work_budget_report`. In `rvt::research` there are two new
items, `solid_headers_for` and `EmptyTrimIndex`, plus
`MAX_SOLIDS_PER_ROOM`. `rvt-ifc` and `rvt-gltf` exit 3 where a reader
stopped at a work budget, which no real file does.

https://claude.ai/code/session_01L1QUmYwb7cHmeCQU8FD2Ge
DrunkOnJava added a commit that referenced this pull request Nov 15, 2026
…y default and says so, from what the 28 real files of Revit 2023 and 2024 keep (#1833) (#2031)

## Summary

`ScanOptions::default()` now stops at 16,777,216 candidates (2^24), and
`PartitionScan::truncated` says when a scan reached the cap. It was the
one site of #1833 left: the research API's partition scanner, which kept
every schema tag followed by two zero bytes with no limit.

## Motivation

#1833 site R: a stream holds up to one candidate for every four of its
bytes, and each takes about 250 bytes (160 inline, and three short
strings), so a crafted stream could take about 67 GB of candidates from
the 1 GiB the reader lets a stream inflate to. The comment on #1833 said
a default cap needs the candidate totals of real files first, so that it
never cuts a real scan. This is that measurement.

**Measured** (Measure
[43663157788](https://github.com/DrunkOnJava/rvt-rs/actions/runs/43663157788),
`probe_1833_scan_candidates`, the 28 files of Revit 2023 and 2024 it
read; the scanner returns nothing on other releases):

- The most candidates in one file: 9,675,757 (the BIM4LCA timber office
at building permit, 696 MB inflated, 59 streams).
- The most in one stream: 6,531,651 (Autodesk's Snowdon Towers
architectural sample).
- The fullest stream holds 14.7% of the one-in-four-bytes maximum (the
BIM4LCA office at permit). The median file holds one candidate for every
82 bytes, and the range is 57 to 171.
- A candidate is 160 bytes inline (printed by the probe). The strings'
heap is counted at 3 x 32 bytes and is not measured.

So the default is 2^24, 1.7 times the most any of them keeps. A real
file at that figure takes about 2.4 GB of candidates today, so the cap
does not make the research scan cheap; it stops a crafted stream at
about 4 GB where it could take 67 GB.

## Changes

- `src/research/partition_scanner.rs`: `DEFAULT_MAX_CANDIDATES` (2^24)
with the measurement in its doc comment, the default `ScanOptions` and
`arcwall_2023_only` use it, `PartitionScan::truncated`
(`#[serde(default)]`), a "Budget" section in the module docs.
- `examples/partition_scanner_json.rs`: keeps the default cap unless
`--max-candidates` or the new `--no-cap` is given (it set `None` when
the flag was absent), and prints `truncated`.
- `probes/examples/probe_1833_scan_candidates.rs`: the probe, which
prints `truncated` too.
- `tests/partition_scanner.rs`: a real-file check
(`einhoven_scan_says_when_it_reached_the_cap`): Einhoven's default scan
is not truncated, and with `max_candidates` 10 the scan is truncated and
lists the first 10 candidates of the whole scan.
- `changelog.d/security/1833-scan-candidates-cap.md`.

## Testing

Measure
[43664481547](https://github.com/DrunkOnJava/rvt-rs/actions/runs/43664481547),
unfiltered against the merge base, with samples, nordic, r2025 and
holdout, and the probe run
[43664485165](https://github.com/DrunkOnJava/rvt-rs/actions/runs/43664485165)
on the 2023 and 2024 files. Rows registered before they are read:

1. Every export and every `diagnostics.json` is byte for byte the merge
base's: nothing in the export or the CLIs calls the scanner. **Held**
(run 43664481547, head `0dd5143c`, the commit holding every `src`
change; the later commit adds a test): 120 of 120 exports and 102 of 102
`diagnostics.json` identical to the merge base.
2. The probe reports `truncated=0` on all 28 files and the same
candidate counts as run 43663157788. **Held** (run 43664485165, head
`0dd5143c`): `truncated=0` on all 28 supported files, and release, scan,
streams, inflated bytes, candidates, largest stream and fill are
identical to run 43663157788 on all 33 models, the most candidates in a
file still 9,675,757.
3. `same-project gates` pass. **Held** on `0dd5143c`: 15 samples held to
their earlier saves, and the Areas on 4 saves and on the 2021 save; the
semantic diff finds no difference in 42 models.

- [ ] `tools/check-local.sh`: no local builds; `rustfmt --check` passes;
CI runs the rest.

## Audit-honesty checklist

- [x] The figures above are from the run named; the 250 bytes per
candidate is arithmetic on the measured 160 plus an assumed 96 for the
strings, and the changelog says "about".
- [x] A changelog fragment.
- [x] No emojis, private paths or jargon.

## Legal and contribution hygiene

- [x] Apache-2.0; no Autodesk source; no fixtures.

## Breaking changes

`PartitionScan` gains a field, and `ScanOptions::default()` now caps the
scan. Both are in `rvt::research` (behind `unstable-research`). A caller
that needs more than 2^24 candidates sets `max_candidates` to `None`.

Closes #1833: sites A to Q landed in #1835, #1847 and #1849, and this is
R.
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