Skip to content

fix(elem_table): the declared ids include the table's first record (#152, #421) - #553

Merged
DrunkOnJava merged 2 commits into
mainfrom
re/re142-elemtable-first-record
Oct 1, 2026
Merged

DrunkOnJava merged 2 commits into
mainfrom
re/re142-elemtable-first-record

Conversation

@DrunkOnJava

@DrunkOnJava DrunkOnJava commented Oct 1, 2026 •

Copy link
Copy Markdown
Owner

The ElemTable's frames, as parse_records reads them, start 24 bytes into their records, so none holds the table's first record (it starts at 0x06) and the declared ElementIds miss it. puzzbobb reported this on #421; the RE-140 runs confirm it on every file.

Measured on GitHub's runners (Measure runs 36900586913 and 36901574754) on Autodesk's own rac_basic, rst_basic and rac_advanced sample projects of 2019 to 2027 and its sample families of 2016 to 2026, 38 files:

  • the ids read from 0x06 (both ids of each record) are exactly the ids of a strict walk of the partitions' leading chain (the header tag and a trailer that repeats the size) on every file, with the 2021 rac_advanced sample's 6 chain ids that no table record declares the one exception;
  • parse_records' ids leave out exactly that one record on every file, so one chain record per file had no declared id.

The change keeps parse_records' records as they are (tests/elem_table_corpus.rs pins them), reads the first record's ids from 0x06 into ElemRecord::previous_ids on records[0], and has declared_ids add them, so every reader's declared set holds them.

Measure, head against main (run 36903065866, with the family corpus): the IFC of Core Interior, Einhoven and the four RE1 models and the rvt-info output of every file are byte-identical; the only difference is RE1 Architecture's diagnostics.json, where decoded_element_fraction moves from 0.03299764 to 0.032990575 (one more declared id in the denominator).

, #421)

The frames parse_records reads start 24 bytes into their records, so each carries the ids of the record after the one it opens in, and the table's first record, which starts at 0x06, is in none of them. On all 38 Autodesk sample projects and families of 2016 to 2027 measured, exactly one id the table declares was missing from the declared set and had a record in the partitions' chain. The first record's ids are now read from 0x06 and kept on records[0], and declared_ids adds them, so every reader's declared set holds them; parse_records returns what it did.
@cursor

cursor Bot commented Oct 1, 2026

Copy link
Copy Markdown

Bugbot couldn't run - usage limit reached

Bugbot is counted against Cursor usage for this user or team, and this run hit a usage or spend limit.

A user or team admin can review and increase usage limits in the Cursor dashboard.

(requestId: serverGenReqId_7b390317-b64f-4d44-94d3-ebbb39b791a1)

@DrunkOnJava
DrunkOnJava merged commit edb8f15 into main Oct 1, 2026
27 checks passed
@DrunkOnJava
DrunkOnJava deleted the re/re142-elemtable-first-record branch October 1, 2026 18:00
DrunkOnJava added a commit that referenced this pull request Oct 1, 2026
… and puzzbobb's measurements (#421) (#554)

RE-140 for #421: Autodesk publishes its rac_basic, rst_basic and
rac_advanced sample projects for every Revit release from 2016 to 2027
on the host the family corpus comes from (36 files), so the pre-2024
projects RE-136 said the corpus lacked can be measured. This adds them
to the Measure workflow and reports what they show.

- `measure.yml` has a `samples` input; `tools/fetch-autodesk-samples.sh`
fetches the files by hash from `research/autodesk-sample-projects.tsv`
(hashes measured on the VPS; the 2017 `rac_basic` hash equals the one
STE1200's file has in `docs/reference-models.md`). They are fetched for
a run and never stored.
- `tools/ci/measure-reference-models.sh` reads them with rvt-info, the
export's diagnostics and the probe; the RE-135 probe now also prints the
trailer flags, the marker checks, the ElemTable's ids from `0x06`, a
strict chain walk, where each record holds its marker, and, with
`--records`, every chain record's id, class, category and box.
- `reports/element-framing/RE-140-sample-projects-2016-2027.md`: every
measurement puzzbobb posted on #421 that these files can test reproduces
(the strict chain covers every table id on 47 files, the 0x01001269 flag
is once per structural project of 2016 to 2023, every marker has its
header and a well-formed box, 2027's tag and chain), and the same model
in 2016 to 2022 agrees with 2024's reading of it on class, category and
box (99.9 to 100 per cent on category and 89.6 to 100 on box over the
records with a marker). The `parse_records` first-record finding is
fixed in #553.
- No release is admitted: there is no Revit export of any of the files.

Runs: 36899534445, 36900586913, 36901574754, 36903389204, 36904178406.

<!-- CURSOR_SUMMARY -->
---

> [!NOTE]
> **Low Risk**
> Changes are CI fetch/measure scripts, research pins, docs, and a
diagnostic example probe—not production export or release-gating logic
in the library.
> 
> **Overview**
> Adds **RE-140** measurement of Autodesk’s published `rac_basic` /
`rst_basic` / `rac_advanced` sample projects (2016–2027, 36 files)
without checking them into the repo.
> 
> The **Measure** workflow gains a `samples` dispatch input:
`tools/fetch-autodesk-samples.sh` downloads and hash-verifies rows from
`research/autodesk-sample-projects.tsv`, and
`measure-reference-models.sh` runs `rvt-info`, `rvt-ifc` diagnostics,
and the partition probe on each file under `OUT_DIR/sample-*` (probe
invoked with `--records`).
> 
> The **`probe_re135_undeclared_records`** example is extended for
RE-140: trailer flag histograms and size-echo checks, 2023
marker/header/box scans, ElemTable ids from stream offset `0x06`, a
strict chain walk, per-record marker placement, optional `--records`
lines for cross-release comparison, and releases after 2026 are analyzed
with the 2024 layout instead of skipping.
> 
> Docs and
**`reports/element-framing/RE-140-sample-projects-2016-2027.md`**
document puzzbobb’s #421 checks on 47 files and same-model agreement vs
2024; **no Revit export** means this does not admit new releases.
> 
> <sup>Reviewed by [Cursor Bugbot](https://cursor.com/bugbot) for commit
f32910c. Configure
[here](https://www.cursor.com/dashboard/bugbot).</sup>
<!-- /CURSOR_SUMMARY -->
DrunkOnJava added a commit that referenced this pull request Oct 3, 2026
`Global/ElemTable` is now read as the table it is (#152). After the
`u16` tag and the `u32` record count at `0x02`, the records start at
`0x06` and close with their owner:

| Releases | Record | Layout |
|---|---|---|
| 2008 to 2023 | 28 B | `[u32 id][u32 id][16 B][u32 owner]` |
| 2024 on | 40 B | `[u64 id][12 B][u64 id][u64 owner][u32]` |

This is STE1200's frame. puzzbobb measured it on 30 files from 2008 to
2027 (#152, issuecomment-5939876282 and 5951500722).

## What was wrong

`elem_table::parse_records` framed records from `0x1E`, 24 bytes into
each record:

- It never returned the table's first record.
- On every 2024 and later file and on every family, it returned a last
record read from the bytes after the table: `(0, 0)` on the projects,
and id 18 after 7,259 on the 2016 family. That declared an id 0 that no
record holds.
- On 28-byte projects it returned one record too few: 2,614 of
Einhoven's 2,615.

## What changes

- `parse_records` returns exactly the stated count from `0x06`, ids
rising over the whole table, each record with its own owner. A family's
first record is owned by element 17.
- `detect_layout` takes the record size (28 or 40) at which the stated
records fit with rising ids, with the shorter tail breaking a tie. That
also reads the 2008 to 2012 projects, where the marker scan took an
84-byte stride; no such file is in our corpora.
- `revit_global_ids`: the episode is at `+8` of the record on both
sizes. These are the same bytes as `+0x18` and `+0x0c` of the old
frames, so no GlobalId changes.
- `ElemRecord::previous_ids` (from #553, unreleased) is always `None`,
because the first record is `records[0]`.
- `header.record_count` stays a `u16`, the low half of the count; no
measured file has 65,536 records. `parse_records` reads the full `u32`.

## Tests

The commits are separate, so each can be reviewed on its own:

1. `test(elem_table)`: the new real-file target
`tests/elem_table_frame.rs`, written from the table's description. Its
red run on `main` (draft PR #558, run 37115866869) is in the commit
message:
- 2016 family: `ids rise strictly, but record 1595 has id 18 after 7259
(of 1596)`
- Einhoven: `parse_records returns the 2615 records the table states,
left: 2614, right: 2615`
2. Five existing tests in `tests/elem_table_corpus.rs` move to the
`0x06` reading. The maintainer approved this before the reader changed,
and each changed value is listed in the commit.
3. The inline mirror suite of `src/elem_table.rs` is deleted (336 lines;
unit-test option (c), B23). One pure-logic test stays.
4. The fix.

Reported by puzzbobb and STE1200 (#152, #421).

## One consequence, fixed here

`partition_type_parameters::value_blocks` ended a value block at a mark
only when the u64 before it was a declared id. The old reader declared a
false id 0 on every 2024 and later file, so marks owned by 0 ended
blocks. Once 0 is declared only where it is an element, RE1
Architecture's curtain wall type (474504) took the next block's `Type
Mark` '2'. Measure run 37116833078 showed this as the only output
difference across 6 models, 11 families and 36 samples. Revit's export
writes no Type Mark, so it cannot decide the value.

A mark owned by 0 now starts an unowned block unless 0 is declared. It
still ends the block before it, and its values go to no type.

## Measured

Measure run 37117234625 compared head against `main`, with the families
and samples:

- the IFC of all 6 reference models is byte-identical;
- every scorer, `rvt-info` and `diagnostics.json` output is identical on
all 6 models, 11 families and 36 sample projects.

The new reading's invariants on 54 files (2014 to 2027) are in RE-147
(run 37117029420): every file reads its stated count, ids rise, and
every set owner is declared, with no self-owner or loop.
@puzzbobb puzzbobb mentioned this pull request Oct 26, 2026
DrunkOnJava pushed a commit that referenced this pull request Oct 26, 2026
Acceptance item 1 of #421: "`bbox_marker` derives the marker from
`RevitFile::schema_classes` and is cross-checked against the 2024 and
2025 constants". On all 84 2024 to 2027 files I have, the marker from
each file's own schema equals the release's constant.

**What changes.** Every scan that needs the bbox marker now gets it from
`file_bbox_marker(rf, release)`:

- The marker is the one the file's schema gives (`schema_bbox_marker`,
RE-80: `[tag of Outline][0xFF x4][tag of ElementParents]`).
- The release's measured constant (`bbox_marker`) is the cross-check. If
the schema and the constant disagree, the file isn't scanned (fail
closed).
- If the schema doesn't parse, the constant is used. A release with no
constant needs the schema.
- `supports_revit_version` no longer depends on a constant being
recorded. It is only the proven-shape list (2024 to 2027).

`file_bbox_marker` already existed, but it returned the constant, and
only some scans called it. Before this patch, these callers read the
per-release table directly:

- `partition_names::compute_element_names`
- `partition_schema_mvp::attach_stair_names`
- `partition_type_records::scan_type_records`
- `partition_level_records::level_records` (64-bit path)
- `partition_type_parameters` / `partition_type_materials`, which only
use it as a "supported?" test and now call `supports_revit_version`

The `BBOX_MARKER*` constants and `bbox_marker` stay as the cross-check
table. The 2024-only legacy helpers that take `&BBOX_MARKER` are left
alone.

**Measurement.** The probe below, on 93 files (the phi-ag/Autodesk
samples, Core Interior, the RE1 set, Einhoven and 68 2025 projects):

| release | files | schema marker | `ElementHeader` | = constant | =
`file_bbox_marker` |
|---|---:|---|---:|:---:|:---:|
| 2024 | 5 | `46 01 ff ff ff ff ab 05` | 1439 | ✓ | ✓ |
| 2025 | 68 | `59 01 ff ff ff ff d3 05` | 1479 | ✓ | ✓ |
| 2026 | 4 | `61 01 ff ff ff ff f1 05` | 1509 | ✓ | ✓ |
| 2027 | 7 | `64 01 ff ff ff ff 10 06` | 1540 | ✓ | ✓ |

On every one of the 84 files, `record_prologue_constant(schema marker)`
(ElementParents x12) is the schema's `ElementHeader` tag, the `u16` that
each record chain header carries (RE-35).

**One finding for older releases.** That a 12 rule doesn't hold before
2019:

| release | ElementParents | ElementHeader | difference |
|---|---:|---:|---:|
| 2016 | 1210 | 1201 | 9 |
| 2017 | 1227 | 1218 | 9 |
| 2018 | 1268 | 1259 | 9 |
| 2019–2023 | | | 12 |

This is harmless today, because the 32-bit path
(`partition_element_records_2023`) takes the header tag from the schema.
But `record_prologue_constant` shouldn't be used for a 2016 to 2018
file. The patch says so in its doc comment, and the test below pins the
gap on each 2016 to 2023 family.

**Test.** `tests/schema_bbox_marker.rs` (registered in
`tests/integration/main.rs` and `tools/ci/test-targets.txt`) asserts
three things on each file:

- schema marker == `bbox_marker(release)`;
- `file_bbox_marker` returns it;
- the prologue == `ElementHeader`.

It runs on the 2024 to 2026 phi-ag families (`RVT_SAMPLES_DIR`, so CI
runs it) and on every project in `RVT_PROJECT_CORPUS_DIR`. A third test
checks the ElementParents − ElementHeader gap on the 2016 to 2023
families: 9 on 2016 to 2018, 12 from 2019. All three skip absent files.

**Checks**, on `3d2df24`, with the changelog fragment
`changelog.d/changed/re421-schema-marker.md`:

- rustfmt `--check`: clean;
- clippy `--all-features -D warnings` (lib, integration, probe): clean;
- `cargo check` with `-D warnings -D unnameable_types`: clean;
- `cargo test -p rvt --lib --test integration` on the local corpora: 134
+ 290 passed, the one failure being the stale test below;
- `tools/check-local.sh`: all gates passed.

**Also in this PR: a stale test.** On the full suite one test failed, on
unpatched `3d2df24` too:
`elem_table_corpus::declared_element_ids_returns_sorted_deduped_set`.
Since #553 and #559 the declared ids include the table's first record,
at `0x06`, which on Einhoven is id 0, but the test still expected the
first id to be 1. CI hadn't caught it because
`tools/ci/test-targets.txt` skipped the test by name (added in #428,
before the fix). The second commit makes the test expect ids 0 and 1
first and removes the skip, so CI runs it again. All six
`elem_table_corpus` tests pass.

**Still per-release tables:**

- `elevation_marker`;
- the Level `record_marker(revit_version)` table. `level_records` no
longer uses it on the 64-bit path, but it's still pub.

`schema_elevation_marker` exists, so the same change could be made for
those. Also, `schema_classes` isn't memoised, so each scan re-reads the
schema. That costs about 0.1 s per file in a debug build (Core Interior
0.10 s, Snowdon 0.14 s), which is small, but caching it on `RevitFile`
would be a tidy follow-up.

<details>
<summary>Probe: <code>examples/probe_421_schema_marker.rs</code> (one
JSON line per file)</summary>

```rust
//! #421, item 1: the element-record marker each file's schema gives, against
//! the release's measured constant.
//!
//! One JSON object per file: `release`, `schema` (the marker from
//! `Outline` and `ElementParents`, RE-80), `constant` (`bbox_marker`),
//! `header_tag` (the schema's `ElementHeader`) and `prologue`
//! (`record_prologue_constant` of the schema's marker), and `scanned`, the
//! marker `file_bbox_marker` hands the scans.
//!
//! Usage:
//!   cargo run --profile ci --example probe_421_schema_marker -- FILE.rvt ...

use rvt::RevitFile;
use rvt::research::partition_element_records as per;
use rvt::research::partition_element_records_2023::record_marker;

fn hex(marker: Option<[u8; 8]>) -> String {
    marker.map_or_else(
        || "null".into(),
        |m| format!("\"{}\"", m.map(|b| format!("{b:02x}")).join(" ")),
    )
}

fn main() {
    for path in std::env::args().skip(1) {
        let file = std::path::Path::new(&path)
            .file_name()
            .map(|n| n.to_string_lossy().into_owned())
            .unwrap_or_default();
        let mut rf = match RevitFile::open(&path) {
            Ok(rf) => rf,
            Err(e) => {
                println!("{{\"file\":{file:?},\"error\":{:?}}}", e.to_string());
                continue;
            }
        };
        let release = rf.basic_file_info().map(|i| i.version).unwrap_or(0);
        let schema = record_marker(&mut rf);
        let marker = schema.map(|(m, _)| m);
        println!(
            "{{\"file\":{file:?},\"release\":{release},\"schema\":{},\"constant\":{},\
             \"header_tag\":{},\"prologue\":{},\"scanned\":{}}}",
            hex(marker),
            hex(per::bbox_marker(release)),
            schema.map_or_else(|| "null".into(), |(_, t)| t.to_string()),
            marker.map_or_else(
                || "null".into(),
                |m| per::record_prologue_constant(&m).to_string()
            ),
            hex(per::file_bbox_marker(&mut rf, release)),
        );
    }
}
```

</details>
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