Assembly sidecar and STEP import
Issue 50. A sidecar YAML file sits next to one or more STEP files. It names the parts, pins each STEP
file by SHA-256 and declares one joint, one deviation and one requirement. arena assembly validate
turns it into the typed Assembly of src/tolerance_arena/assembly/types.py, or refuses it and
names the field. arena assembly inspect FILE.step prints what a STEP file holds, so the sidecar can
be written by hand. Neither command measures a clearance, moves a part or judges a requirement.
Code: src/tolerance_arena/assembly/sidecar.py, step_import.py and cli.py. Spec:
.kiro/specs/step-assembly/. Samples: fixtures/assembly/, written by
scripts/make_assembly_samples.py.
Schema v1
schema_version: 1
units: {length: mm, angle: deg}
parts:
- id: pin
step: {file: pin.step, sha256: <64 lowercase hex>, solid: 0}
- id: block
step: {file: block.step, sha256: <64 lowercase hex>, solid: block}
joint:
id: hinge
type: revolute # or prismatic
fixed_part: block
moving_part: pin
axis: [0, 0, 1] # a unit vector
origin_mm: [0, 0, 0]
range: [0, 90] # degrees for revolute, millimetres for prismatic
deviation:
id: shift
part: block
direction: [0, 1, 0] # a unit vector
range_mm: [-0.5, 0.5]
requirement:
id: gap
type: minimum_clearance
parts: [pin, block]
minimum_mm: 1.5
Every key is required and no other key is allowed. The file is UTF-8, at most 1 MiB (1,048,576 bytes),
one YAML document. Identifiers are 1 to 64 characters of letters, digits, _, . and - and start
with a letter or a digit. solid is a non-negative index into the solids of the STEP file in the order
arena assembly inspect lists them, or the name of exactly one solid. The assembly id is the sidecar's
file stem, and its source is sidecar <file name> sha256 <hash of the sidecar bytes>.
units.length and units.angle say what the numbers of the sidecar are written in. The importer
converts them with src/tolerance_arena/units.py to millimetres and degrees (length: mm, cm, m, um;
angle: deg, rad) and refuses any other string. The key names keep their _mm suffix; with
length: m a value under origin_mm is read as metres. Sidecar.to_text() writes a sidecar back in
millimetres and degrees.
What is refused
Each refusal names the field. arena assembly validate prints refused: <field>: <reason> on
standard error and exits 2; with --json it prints {"valid": false, "field": ..., "error": ...} on
standard output and exits 2.
| Refusal | Field named |
|---|---|
| a sidecar over 1 MiB, a symbolic link, not a regular file, missing, not UTF-8, not YAML | sidecar |
| an unknown key | the key with its path, such as joint.axs |
| a duplicate key, a YAML alias, a non-text key, a second document | the key, or sidecar |
| a missing key | the key with its path |
schema_version other than the integer 1 | schema_version |
| a number that is a boolean, text, NaN or not finite | the number, such as joint.origin_mm[1] |
| an identifier outside the safe set | parts[i].id, joint.id, ... |
| a unit string the code does not know | units.length or units.angle |
a unit vector that is not one, a reversed range, a range outside the bounds of types.py, a joint that joins a part to itself, a requirement of one part or a minimum that is not positive | the section (joint, deviation, requirement) and the field in the reason |
| an unknown joint or requirement type | joint.type, requirement.type |
a part id that parts does not list | joint.fixed_part, joint.moving_part, deviation.part, requirement.parts[i] |
| one part id twice, fewer than two parts, more than 16 parts | parts[i].id or parts |
a path that is an absolute path, holds .., . or an empty segment, a backslash or a NUL, or runs through a symbolic link | parts[i].step.file |
| a missing file, not a regular file, a symbolic link, over 50,000,000 bytes | parts[i].step.file |
| a hash mismatch | parts[i].step.sha256 |
| a file the importer refuses (see below) | parts[i].step.file |
| an index out of range, a name that matches no solid or several, an invalid solid, a volume that is not finite and positive, a bounding box that is not finite | parts[i].step.solid |
The loader checks and hashes every part file before it hands any of them to the STEP reader, so a hash
mismatch on the second part means the kernel never touched the first. It opens only paths below the
sidecar's folder: the text rules run first, then each directory component is checked with lstat
one at a time. A symbolic link anywhere below that folder is refused, including the last component. A
sidecar reached through a symbolic link in a directory above its own folder still loads.
The loader reads no environment variable.
What the importer does with a unit
arena assembly inspect prints the unit the file declares. OCCT scales every coordinate to its target
unit xstep.cascade.unit, which is MM by default, using that declaration. The importer reads the
declared name with FileUnits and then:
| Declared name | Result |
|---|---|
| millimetre, centimetre, micrometre, metre | accepted, read in millimetres |
INCH (reported as inch) | accepted, 1 unit is 25.4 mm |
FOOT (reported as foot) | accepted, 1 unit is 304.8 mm |
| no unit, or an empty name | refused: it declares no length unit |
any other name, such as kilometre or FURLONG | refused, naming the unit and listing the supported ones |
| two different units in one file | refused |
The importer also refuses to run when xstep.cascade.unit is not MM, because the coordinates would
not be in millimetres. It never sets that value.
tests/assembly/test_assembly_step_import.py and tests/assembly/test_assembly_cli.py write the same
shapes in millimetres, centimetres, metres, micrometres, inches and feet with the OCP writer, and read
them back. Each volume equals the written volume within a relative 1e-6 in millimetres cubed. An
inch file stores 1.5 for a half height of 38.1 mm, and the importer returns 38.1 mm. The unit
behaviour above is what those tests observed on build123d 0.13.0 with cadquery-ocp-novtk 8.0.1.1.0;
another build may differ, and the tests would show it.
A file also has to start with ISO-10303-21, must be read by the STEP reader without a failure
status, and must hold at least one solid. The solids are listed in file order. A solid takes the name
of its label, with the characters OCCT cleans (' ', ., (, )) replaced by _. A solid with no
label has the empty name and is chosen by index.
Limits
- The STEP file is parsed in the calling process.
arena assembly validateandinspectdo not use the supervised worker. A crafted file can crash or stall OCCT. This was measured on 2026-12-02 on the installed build:FileUnitsafter a failedReadFileends the process with a segmentation fault. The importer checks the read status first, checks the header, caps the file at 50,000,000 bytes and runs no timer. Parsing in the worker is not part of this issue. - The SHA-256 is computed over the bytes read first, and the STEP reader then opens the path again. A file replaced between the two reads is not caught.
- STEP export of a sidecar assembly, more than one joint or deviation, and a requirement other than a minimum clearance between two parts are not supported.
- The sample STEP files are reproducible only from a fresh process. The OCCT writer numbers assembly usages from a process-wide counter, so a second export in one process writes different bytes.
Commands
arena assembly validate fixtures/assembly/hinge.assembly.yaml
arena assembly validate --json fixtures/assembly/hinge.assembly.yaml
arena assembly inspect fixtures/assembly/pin.step
arena assembly inspect --json fixtures/assembly/pin.step
.venv/bin/python scripts/make_assembly_samples.py
validate exits 0 when the sidecar loads and 2 when it is refused. inspect exits 0 when the file
is read and 2 when it is refused. An invalid solid does not refuse inspect: it is listed with
valid=no, and a number the kernel could not return reads none (null in JSON).
The text of inspect for the sample pin, as printed on 2026-12-02:
file: pin.step
size_bytes: 7103
sha256: 45cbc81e02b9cf74418eee50192572130f35ec5ad8f6aa0a71710655bda87954
length_unit: millimetre (1 unit = 1 mm)
solids: 1
[0] name='pin' volume_mm3=565.4866776 bbox_min_mm=(27, -3, -10) bbox_max_mm=(33, 3, 10) valid=yes
Clearance commands (issue 53)
Issue 53 runs the verify, sweep, search, replay and report code of the rotating pin on a sidecar
assembly or on a named family. The pin commands and their output do not change. Code:
src/tolerance_arena/assembly/ (context.py, results.py, provenance.py, pipeline.py,
bundle.py, replay.py, report.py, commands.py). Spec: .kiro/specs/assembly-pipeline/.
arena assembly verify --sidecar S.assembly.yaml --q 15 --delta-mm=-0.5
arena assembly sweep --sidecar S.assembly.yaml --four-point --delta-values=-0.5
arena assembly search --sidecar S.assembly.yaml --output runs/s1
arena assembly replay runs/s1
arena assembly report runs/s1 --format html --output runs/s1.html
arena assembly search --family hinged-flap-post --planted --output runs/f1
arena assembly verify --family lever-stop --param swing_deg=90 --param ... --q 45 --delta-mm=-1.2
- Source. Give
--sidecar PATH, or--family IDwith--planted(the planted configuration ofdocs/assembly-families.md) or one--param NAME=VALUEfor every parameter. Both sources, neither, or--plantedwith a sidecar exit 2. - Domain and pair. They come from the assembly: the joint range, the deviation range and the two parts of the requirement. A joint value or a deviation outside its range, a boolean, text or a non-finite number is refused with exit 2 and is not measured, clamped or rounded. The pin domain (0 to 90 degrees, plus or minus 1.2 mm) is not touched.
- Verdict. The decision rule, the 1e-5 mm comparison tolerance and the 1e-5 mm ambiguity band are
the pin's (
verify.classify_clearance); the requirement minimum is the one in the sidecar or the family. A failed query, a placement error or a mismatch isindeterminate. - Reference. A family has a closed-form gap (
reference_source: analytic). A sidecar assembly has none, so a second query of the same pose in a second, independent kernel process stands in (reference_source: remeasure). This catches an unstable placement. It does not catch an error that both queries share, such as a wrong model or a loader error. - Sweep and search.
sweeptakes--q-values a,b,cor--four-point(the joint range in three equal parts) and--delta-values(default: both ends and zero).searchtakes--budget(default 100),--seed(default 42),--strategyand--output. The ledger, the credit rules and the confirmation query are the pin's. With--outputthe directory getsledger.jsonand, on a finding, the bundle. - Exit codes.
exit_code_forof the verdict or conclusion: 0 satisfied and no_failure_found, 1 violated and failure_found, 2 indeterminate, inconclusive, a replay mismatch, a refused input or a refused bundle, 130 a cancelled search. A matching replay of a violated bundle exits 1.
Bundle and replay
A bundle holds specification.json, scenario.json, result.json, provenance.json,
counterexample.json, events.jsonl, report.md and manifest.json. The manifest has
kind: "assembly", so arena replay refuses it, and arena assembly replay refuses a pin bundle.
provenance.json records the SHA-256 of the sidecar and of every STEP file (with the sidecar path as
given), or the family id, version and parameters. The counterexample records the SHA-256 of every
other evidence file, so a manifest recomputed after an edit no longer agrees with it.
replay loads the bundle, re-hashes the sidecar and the STEP files (or compares the family version),
opens the assembly again and compares it with specification.json, all before the first
measurement. It then measures the stored pose once and compares the verdict exactly and the distance
within 1e-5 mm. It imports no agent runtime and makes no network call. The sidecar is looked up at its
recorded path; --sidecar PATH names it elsewhere, and its files are still checked by hash. Nothing
is searched for: a file that is not where the record says is reported missing.
A bundle that was changed and resealed consistently in every document cannot be told from a genuine
one by hashes. Replay then re-measures, and a different verdict or distance reads as a mismatch. A
family version is a constant string in families.py; a geometry change without a version change is
not detected.
Observed on 2026-12-03
One family, hinged-flap-post --planted (the real kernel, one run, a loaded machine):
sweep: q_values_deg: 0.0, 30.0, 60.0, 90.0 delta_values_mm: -1.2
satisfied: 4 minimum_measured_distance_mm: 7.80710776301604 campaign_conclusion: no_failure_found exit 0
search: budget: 100 credits_spent: 100 native_queries: 100 confirmation_queries: 2 findings: 2
q=45.0 delta_mm=-1.2 native_gap_mm=0.9063058585151829 verdict=violated latency_s: 9.305895 exit 1
replay: replay: match stored_distance_mm: 0.9063058585151829 replayed_distance_mm: 0.9063058585151829
reference_source: analytic exit 1
One STEP sidecar, the drawer-carriage sample of assets/step-samples/ written as a sidecar:
verify --q 15.0 --delta-mm=-0.5: native_gap_mm: 1.1999999999999993 reference_source: remeasure verdict: violated exit 1
sweep --four-point --delta-values=-0.5: q_values_mm: 0.0, 10.0, 20.0, 30.0 satisfied: 4
minimum_measured_distance_mm: 2.0 campaign_conclusion: no_failure_found exit 0
search: credits_spent: 100 native_queries: 100 confirmation_queries: 3 findings: 3 latency_s: 55.334919 exit 1
replay: replay: match stored_distance_mm: 1.1999999999999993 replayed_distance_mm: 1.1999999999999993 exit 1
After one byte of the STEP file was changed, replay printed invalid bundle: STEP file drawer-carriage.step of part bracket changed: recorded sha256 14702f77...bed2, current 3a6f3df4...86fd
and exited 2. After one line was added to the sidecar it printed invalid bundle: sidecar drawer-carriage.assembly.yaml changed: recorded sha256 98d9366c...0964, current 3f1c1c88...3c23 and
exited 2. With both files restored it printed replay: match.
The sample truth of issue 56 gives 1.201089 mm for this pose; the kernel gives 1.1999999999999993 mm.
Not covered
- One pair, one joint and one deviation. The viewer is described in
docs/assembly-viewer.mdand the worked sample, with its limits, indocs/bring-your-own-step.md. - A search is a finite sample. It never says an assembly is safe, and the report says so.
- Replay needs the sidecar and the STEP files at the recorded paths (or at
--sidecar). - The two queries of a sidecar assembly share the kernel, the loader and the sidecar. They agree when the placement is stable, not when the model is right.
- The native tests of
tests/assembly/test_assembly_pipeline_native.pystart a kernel child per measurer. On a loaded machinescripts/check-geometry.shneeded 865.71 s, close to its default 900 s limit;GEOMETRY_TIMEOUT_Sraises it.