STEP sample mechanisms: evidence log (issue 56)

Date 2026-12-02. Base commit 7fe0eba on main, worked in the clone runs/par/cs. The method and the numbers are described in docs/assembly-step-samples.md; this log records how they were produced and what the checks found. The machine ran at a load of 25 to 46 on 12 cores for the whole session, so every timing below is several times slower than on an idle machine.

What was built

  • src/tolerance_arena/assembly/sample_truth.py: the sampled reference gap (numpy and scipy only), with SampleTruthError, Mesh, Rigid, place, SamplingSettings, sample_surface, PartSurface, reference_gap and reference_pose_gap.
  • scripts/make_step_samples.py: builds the two mechanisms, writes the STEP files and the truth files.
  • assets/step-samples/: latch-hook.step, latch-hook.truth.json, drawer-carriage.step, drawer-carriage.truth.json.
  • tests/assembly/test_assembly_sample_truth.py (107 tests, no kernel) and tests/assembly/test_assembly_step_samples.py (34 tests, marked native).
  • 43 mutants ST01 to ST43 appended to scripts/mutation_check.py.
  • docs/assembly-step-samples.md and this log.

No MIN_TESTS floor, docs/progress.md or docs/KIRO_USAGE.md was edited. No dependency was added.

How the work went

Tests came first for every module. The first run of test_assembly_sample_truth.py failed at collection because sample_truth did not exist, which is the expected reason.

  1. The first sampler cut each triangle on a barycentric lattice. A sliver triangle of OCCT's fillet meshes (about 70 percent of the triangles of the latch arm have an aspect ratio below 0.1) needs a number of lattice points that grows with the square of its length, and one test needed more than 12 million samples and ran for 130 seconds. The sampler now cuts each triangle into rows parallel to its longest edge, which costs samples in proportion to the length, and the covering radius h / sqrt(3) is argued in the docstring and tested on 60 random triangles with 4000 probe points each (test_every_point_of_a_random_triangle_lies_within_the_covering_radius_of_a_sample).
  2. build123d's Shape.tessellate takes a deflection relative to the size of the part. On a cylinder of radius 40 mm, tessellate(0.005) gave a sag of 0.01243 mm. The script now calls BRepMesh_IncrementalMesh with an absolute deflection, and test_the_tessellation_deflection_is_absolute_not_relative_to_the_size_of_the_part fails on the build123d call.
  3. The first search carried every pose through one pass over the coarse samples. It cost 10 to 42 seconds per latch pose, which would have taken hours for 460 poses. Two changes brought the cost down without changing a result: a pilot search that sets a tight bound, and two coarse sample levels (2 mm and 0.5 mm spacing) that prune before the 0.1 mm samples are queried. Four latch poses gave the same gaps before and after (6.090286, 5.000000, 1.891124 and 2.598277 mm at q = 0, 15, 27 and 30 degrees with no deviation), and the time dropped to 1.1, 5.2, 4.3 and 14.2 seconds.
  4. The first generated latch file scanned only one grid step either side of the lowest pose for the planted dip, so its recorded window started at the first scanned value. The scan now reaches three grid steps either side and the script refuses a dip that touches the end of the scan (test_the_planted_pose_is_refused_when_the_dip_runs_past_the_end_of_the_scan). Both truth files were regenerated with the final code.
  5. The drawer poses where two parallel faces are the closest features (carriage bottom over the bracket plate, carriage front against the stop) cost 30 to 60 CPU seconds each, because all the samples of the face pair lie at nearly the same distance. The first drawer run was killed after 30 minutes at 22 poses. --jobs computes the poses in forked processes, and the drawer finished in 74 minutes with five processes.
  6. test_without_a_pinned_timestamp_two_exports_differ_only_in_the_header_and_the_usage_ids first failed because the usage identifier lines start with a line number (#1824 = NEXT_ASSEMBLY_USAGE_OCCURRENCE(...)) and its first version required the header time to differ, which it does not when both exports fall in the same second. The test now requires a time in the header and that every differing line is a header line or a usage identifier line.

Results

Unit tests of the reference (no kernel)

.venv/bin/python -m pytest -q -p no:cacheprovider tests/assembly/test_assembly_sample_truth.py ran 107 tests and passed all of them (the mutation harness control reports PASS (107 passed) before and after). They cover the guards of every constructor (non-numbers, booleans, NaN, infinity, wrong shapes, empty meshes, zero area, out-of-range joint values and deviations, a part that is not in the joint), the placement order, the sampler density, the caps on the sample count, equality of the reduced search with a brute-force minimum, rigid-motion invariance, and the closed forms. The closed forms are two parallel cylinders at three phases, a box against a cylinder in a tilted frame, and a negative control where a 5 mm lattice breaks the bound.

Mutants

Run: mkdir -p runs/mut_cs && nice -n 10 .venv/bin/python scripts/mutation_check.py --workdir runs/mut_cs --only 'ST[0-9]+' --python "$PWD/.venv/bin/python", with an empty work directory each time. The first run of 38 mutants ended KILLED=32 SURVIVED=6. The survivors were ST04, ST12, ST27, ST34, ST35 and ST37. Each one got a new test: numeric strings and objects as points (ST04), a matrix off a rotation by 1e-6 and 1e-8 (ST12), a triangle that needs 13 million rows, above the cap of 12 million (ST27; the old test asked for 59 million rows and matched the word "samples", which the refusal of the later total contains as well), a part surface built from a non-mesh and from bare settings (ST34, ST35), and a geometry where the closest pair sits in a hole of the coarse samples beside a better aligned pair (ST37). A search over 700 random configurations found none where the ST37 edit changed the result, so the hole case was built by hand. The coarse-level rewrite added ST41 to ST43 and ST41 survived once until the hole case was run at both coarse levels. The final run:

control before: PASS (107 passed) scope=tests/assembly/test_assembly_sample_truth.py
...
control after: PASS (107 passed)
mutants: 43  KILLED=43  SURVIVED=0  CAPPED=0  INVALID=0  BROKEN=0
RESULT: every mutant killed, controls clean

The sha256 of sample_truth.py, of its test file and of scripts/mutation_check.py was the same before that run and when the gates ran. The duplicate check grep -oE '^ "[A-Z]+[0-9]+",$' scripts/mutation_check.py | sort | uniq -d prints nothing. Each mutant and the first test that fails on it:

IdEditFirst failing test
ST01a bool passes as a numbertest_a_malformed_rotation_is_refused[axis2-origin2-True]
ST02a NaN or infinite scalar passestest_a_malformed_rotation_is_refused[axis0-origin0-10.0]
ST03a two-number vector passes as a tripletest_a_malformed_rotation_is_refused[axis3-origin3-10.0]
ST04a non-numeric array passes the dtype checktest_points_that_are_not_numbers_are_refused_even_when_numpy_could_convert_them[strings]
ST05an array with extra rows or columns passestest_a_rigid_transform_refuses_a_matrix_that_is_not_a_rotation
ST06a NaN inside an array passestest_a_rigid_transform_refuses_a_matrix_that_is_not_a_rotation
ST07a mesh with no vertices passestest_a_malformed_mesh_is_refused_with_the_field_named[vertices0-triangles0-vertices]
ST08a mesh with no triangles passestest_a_malformed_mesh_is_refused_with_the_field_named[vertices1-triangles1-triangles]
ST09a triangle index one past the last vertex passestest_a_malformed_mesh_is_refused_with_the_field_named[vertices8-triangles8-triangles]
ST10a mesh of zero area (an empty solid) passestest_a_malformed_mesh_is_refused_with_the_field_named[vertices9-triangles9-area]
ST11float triangle indices passtest_a_malformed_mesh_is_refused_with_the_field_named[vertices5-triangles5-triangles]
ST12a skewed matrix passes as a rotationtest_a_matrix_that_is_slightly_off_a_rotation_is_refused_but_rounding_noise_is_not[1e-06]
ST13a reflection passes as a rotationtest_a_rigid_transform_refuses_a_matrix_that_is_not_a_rotation
ST14a rotation axis that is not a unit vector passestest_a_rotation_axis_that_is_not_a_unit_vector_is_refused[axis0]
ST15a joint value above its range is clamped by silencetest_a_joint_value_outside_its_range_or_malformed_is_refused_never_clamped[90.001]
ST16a deviation above its range passestest_a_deviation_outside_its_range_or_malformed_is_refused_never_clamped[2.001]
ST17a part outside the joint is placedtest_a_part_that_is_neither_fixed_nor_moving_is_refused
ST18the joint motion comes before the deviationtest_the_moving_part_is_placed_with_its_deviation_first_and_the_motion_second
ST19the fixed part loses its deviationtest_the_fixed_part_is_placed_with_its_deviation_only
ST20a zero tessellation tolerance passestest_a_tessellation_tolerance_that_is_not_a_small_positive_number_is_refused[0.0]
ST21a coarse tessellation tolerance passestest_a_tessellation_tolerance_that_is_not_a_small_positive_number_is_refused[0.0505]
ST22a zero spacing passestest_a_spacing_that_is_not_a_small_positive_number_is_refused[0.0]
ST23a coarse spacing passestest_a_spacing_that_is_not_a_small_positive_number_is_refused[0.2525]
ST24the error bound counts the tessellation oncetest_the_error_bound_is_twice_the_tessellation_plus_twice_the_covering_radius
ST25the covering radius is too smalltest_the_error_bound_is_twice_the_tessellation_plus_twice_the_covering_radius
ST26sampling accepts a zero spacingtest_a_spacing_that_is_not_positive_and_finite_is_refused_when_sampling[0.0]
ST27the row cap is ten times too hightest_a_spacing_that_needs_more_rows_than_the_cap_is_refused_before_they_are_allocated
ST28the sample cap is ten times too hightest_the_sample_count_is_capped_before_the_arrays_grow
ST29the rows are too far apart for the covering radiustest_a_triangle_is_cut_into_rows_parallel_to_its_longest_edge
ST30the apex of each triangle is not sampledtest_a_triangle_is_cut_into_rows_parallel_to_its_longest_edge
ST31an empty candidate set is not refusedtest_a_search_that_finds_no_sample_inside_its_bound_is_refused_not_read_as_far
ST32a search with no pair inside the bound returns infinitytest_a_search_that_finds_no_sample_inside_its_bound_is_refused_not_read_as_far
ST33two parts sampled with different settings are comparedtest_a_part_surface_must_share_its_settings_with_the_other_part
ST34a part surface accepts a non-meshtest_a_part_surface_refuses_something_that_is_not_a_mesh_or_not_sampling_settings
ST35a part surface accepts bare settingstest_a_part_surface_refuses_something_that_is_not_a_mesh_or_not_sampling_settings
ST36the pose of the fixed part is ignoredtest_the_gap_equals_the_brute_force_minimum_over_both_placed_clouds
ST37the prefilter drops samples the nearest pair needstest_a_closest_pair_in_a_hole_of_the_coarse_samples_is_found_beside_a_better_aligned_pair[0]
ST38the search bound omits the lattice slacktest_the_coarse_prefilter_keeps_every_sample_the_search_could_need[1]
ST39the final search excludes the pilot pair that sets its boundtest_two_unit_cubes_one_and_a_half_millimetres_apart_read_exactly_that
ST40the pilot search has no samplestest_two_unit_cubes_one_and_a_half_millimetres_apart_read_exactly_that
ST41a finer level is searched too close to the survivors of the coarser onetest_a_closest_pair_in_a_hole_of_the_coarse_samples_is_found_beside_a_better_aligned_pair[0]
ST42the search starts from one sample of the coarsest leveltest_the_gap_equals_the_brute_force_minimum_over_both_placed_clouds
ST43a level keeps only the samples closer than the boundtest_a_closest_pair_in_a_hole_of_the_coarse_samples_is_found_beside_a_better_aligned_pair[0]

Native tests

.venv/bin/python -m pytest -p no:cacheprovider tests/assembly/test_assembly_step_samples.py -s -v selected 34 tests. The first full run ended 1 failed, 33 passed in 145.08s; the failure was the timestamp test described above, and it passed after the fix. The agreement tables and the planted pose numbers are in docs/assembly-step-samples.md: the largest difference between the sampled gap and native.measure_distance is 0.001715 mm on the latch and 0.001091 mm on the drawer, over 231 poses each, with no pose over 0.02 mm.

The slowest native tests on the loaded machine were the kernel agreement of the drawer (66.7 s) and the latch (26.2 s), and the recomputation of four poses from the STEP file (21.2 s and 12.5 s).

STEP bytes

A fresh subprocess run of the script wrote the committed bytes for both files (sha256 prefixes 46faa42d462b724a and 14702f7dd7955746). Two exports in one process differ in the header time and in the NEXT_ASSEMBLY_USAGE_OCCURRENCE identifiers, which come from a process-wide counter, and nowhere else.

Gates

The three gates ran one after another on the final tree, main at 7fe0eba plus the uncommitted work of this issue, each under nice -n 10:

nice -n 10 bash scripts/check-fast.sh
== ruff check ==
All checks passed!
== ruff format --check ==
151 files already formatted
== mypy --strict (src) ==
Success: no issues found in 39 source files
1775 passed, 274 deselected in 106.58s (0:01:46)
OK check-fast: 1775 tests passed, no native query issued

nice -n 10 bash scripts/check-geometry.sh
232 passed, 1817 deselected, 5 warnings in 382.78s (0:06:22)
OK check-geometry: 232 native tests passed

nice -n 10 bash scripts/check-agents.sh
411 passed, 2007 deselected in 97.04s (0:01:37)
OK check-agents: 411 tests passed; all 2418 collected tests belong to a gate

The three counts add up to the 2418 collected tests. The floors in the scripts were not touched (MIN_TESTS 1633 for the fast gate, 198 for the geometry gate). The five warnings of the geometry gate are Python 3.12 DeprecationWarnings from the forked workers of the --jobs tests. An earlier dry run of check-fast.sh on the same tree had one failure, tests/test_kiro_hooks_prompt_facts.py::test_the_module_entrypoint_prints_nothing_and_exits_zero_outside_git, which runs a subprocess with a one second timeout and expired on the loaded machine; it passed in the run quoted above and no file of this issue touches it.

Limits and open points

  • The sampled gap depends on the OCCT mesher. The sag test checks the absolute deflection on a cylinder of radius 40 mm only. On the mechanisms themselves the kernel agrees with the sampled gap within 0.0018 mm on every grid pose.
  • The truth is a surface-to-surface distance and does not detect interpenetration. The lowest gap in either grid is 1.2 mm.
  • The truth files were computed from STEP files whose drawer bytes differ from the committed drawer file in the usage identifiers only: the truth run read the file written by a one-mechanism run, and the committed file comes from a default run. The geometry is the same; the recompute test reads the committed file and matches the truth within 2e-6 mm on the poses it checks (the planted pose and three grid poses per mechanism).
  • The poses whose closest features are parallel faces cost minutes each under load. A larger assembly would need a spatial prune that this module does not have.
  • --jobs uses fork, so it needs Linux or macOS, and Python 3.12 prints a deprecation warning when a process with threads forks.
  • The latch truth file was produced by the single-process run and the drawer file by the five-process run. The pose values do not depend on that choice: test_poses_computed_in_several_processes_come_back_in_order_with_the_same_values checks order and values.