Geometric Tracebacks: Refining Shape Programs with Localized Error Feedback

When a clinician estimates a brain bleed's volume with the Tada formula (multiply three diameters and halve the result), they are running a one-line shape program. That program describes the bleed as an ellipsoid, and it is wrong in a systematic way. Against thin-slice CT angiography it overestimates volume by 4.65 mL on average, and its agreement with the reference (intraclass correlation, ICC) falls to 0.516 for bleeds larger than 60 mL (Retrospective validation of 3D Slicer…). Voxel networks remove most of that error, but they return a frozen grid of labeled pixels that nobody can edit parameter by parameter (Deep Network for the Automatic Segmentation and Quantification of Intracranial Hemorrhage on CT). This proposal asks whether a language model can start from the crude program and edit it step by step, adding a lobe here and carving a concavity there, until the program's geometric error approaches voxel-level accuracy while the program stays short and readable.

The key ingredient is the form of the feedback. Code-repair loops that run on compiler messages tend to stop improving after two or three rounds (Yan et al.). Our hypothesis is that a single overlap score is the geometric equivalent of "test failed": it says the shape is wrong but not where or why. We propose a geometric traceback. The system renders the program, finds connected regions of excess or missing volume against the target, and assigns each region to the program statement whose primitive produces that surface. The model then receives something like "line 4 (posterior lobe) overshoots by up to 3.8 mm inferiorly, 1.9 mL excess." The claim to test is that this localized, statement-level feedback, combined with a numeric optimizer that tunes continuous parameters, keeps improving fit past the usual plateau. Scalar feedback, we expect, will not.

Core Claim and How It Differs From Prior Work

Three papers already connect geometry and code, and each leaves a specific gap that this work fills. GIFT runs a CAD kernel offline to filter and augment training data for image-to-CadQuery synthesis. It deliberately avoids test-time search and needs ground-truth CAD programs. MeshCoder translates point clouds into Blender Python in a single forward pass, with no execution feedback, and its authors say it cannot model organic shapes. Don't Mesh with Me generates exact constructive-solid-geometry code limited to axis-aligned planes and cylinders, and it cannot revise parameters after generation.

These three papers supply the motivation, a baseline, and a vocabulary constraint respectively. None of them runs a multi-turn loop at test time driven by spatial error. None of them targets shapes for which no ground-truth program exists.

Two lines of work supply the loop machinery we reuse. One is execution-feedback refinement, as in OpenCodeInterpreter and the review-gated loop in MAGIS, whose ablations show that the review step matters. The other is rollback to the last stable checkpoint, from hardware-design agents (Fang et al.). What we add is a feedback signal that is spatial and tied to individual statements, rather than textual or scalar.

Research Program

The shape language. We will build a small Python language for organic shapes based on signed distance functions. A signed distance function is a formula that returns, for any point in space, its distance to the surface, negative inside and positive outside. The primitives are ellipsoids, superquadrics (rounded boxes and cylinders), and swept tubes along spline curves, plus low-order smooth radial bumps on a primitive. The bumps borrow the idea, from geometric-informed basis functions, that folded surfaces are best captured with smooth basis functions rather than raw vertices. Primitives combine through smooth union and smooth subtraction.

Every program is executable, can be converted to voxels, and is differentiable in its continuous parameters. The Tada ellipsoid is the minimal program in this language.

Splitting the work between the model and the optimizer. At each round the language model proposes structural edits: add, delete, or re-anchor a primitive, or change how primitives combine. A gradient optimizer then fits the continuous parameters of the edited program to the target mask. The model is never asked to guess numbers, which is a known weakness of language models. This separation is also what makes the strongest non-language-model baseline, described below, a fair comparison.

Building the traceback. For each round, the system computes the signed error volume between the program and the target. It extracts connected error components above a size threshold. For each component it records the volume, the maximum surface deviation, the anatomical direction, and the responsible statement, defined as the primitive with the smallest distance in that region. If an edit worsens a combined objective (error plus a cost per statement), the program rolls back to the previous version.

Measuring the accuracy–length trade-off. We will record the full curve of accuracy against program length, so that "editable" is a measured quantity rather than a slogan.

Targets. Development uses public rigid shapes with known programs: Fusion360 Gallery and the curated ABC subset. These give clean comparisons with GIFT, which reports +12.4% mean 3D IoU over supervised fine-tuning and 26% more problems solved on Fusion360. Biological evaluation uses two sources. The first is whole-cell masks from the public CytoNuke dataset (Cyto R-CNN and CytoNuke), which is 2D but has a ready morphometric metric. The second is intracerebral-hemorrhage masks, contingent on access to a cohort with thin-slice reference volumes like the 118-patient cohort above. We found no public hemorrhage dataset on Lacuna. If access fails, the hemorrhage claim is dropped rather than replaced with a weaker one.

Baselines

The naive reference is the one-primitive program: the Tada ellipsoid for hemorrhages and radial nucleus expansion for cells. The reported numbers are ICC 0.887 with +4.65 mL bias for Tada (Retrospective validation…), and Kolmogorov–Smirnov distance D = 0.22–0.25 against manual morphometry for expansion heuristics, compared with D = 0.15 for Cyto R-CNN (Cyto R-CNN and CytoNuke). Beating this reference is necessary but not interesting.

The strongest competitor on the actual question is greedy primitive addition with gradient fitting and no language model. This baseline repeatedly adds the primitive that most reduces error, placed at the largest error component. It uses the same optimizer and the same per-statement cost, and stops by the same criterion. It is the strongest competitor because it uses exactly the traceback's localization signal without any language model. It runs on the same targets with the same number of renders and optimizer steps.

The proposal beats it only if it reaches lower error at equal program length, or equal error with fewer statements, on irregular and large shapes. We will test this with paired comparisons per shape. No reported result was found on Lacuna for this baseline, so we will establish it ourselves.

The strongest published code-generation method is GIFT-style offline amortization: a model fine-tuned on traceback-verified programs and deployed single-shot. We will train it on the same synthetic shape corpus and compute budget, and compare at matched inference compute. This is important because GIFT reports an 80% reduction in inference compute relative to best-of-N. For point-cloud input on rigid shapes we also report against MeshCoder, which reaches 86.75% voxel IoU and Chamfer distance 0.063 on Infinigen-Indoor.

Compute-matched best-of-N sampling draws N programs from the same model with the same render budget, each fitted with the inner optimizer, and keeps the best one.

Two accuracy ceilings, not editability competitors. These are the voxel networks and semi-automatic 3D Slicer. Reported figures are ICC 0.99 for Dense U-Net volumetry and ICC 0.997 with +0.77 mL bias for Slicer. The target is to close most of the gap from 0.887 toward these ceilings using programs of roughly ten statements or fewer.

Ablations that isolate the key ingredient. We will run four versions of the loop:

  • feedback reduced to a scalar IoU,
  • error regions reported without statement attribution,
  • no inner optimizer, so the model edits numbers directly,
  • no rollback.

Why not just…?

Why not just fit primitives by gradient descent and skip the language model? This is the real threat, and the greedy-addition baseline exists to settle it. A greedy method chooses edits myopically. We expect the model to help where the right edit is non-local: replacing two overlapping lobes with one swept tube, or carving a concavity where bone presses against a subdural collection rather than adding volume elsewhere. If greedy addition matches the model's error-versus-length curve, we will report that the traceback plus optimizer is the contribution and the language model is unnecessary. That would still be a useful result, but a different paper.

Why not just use the voxel segmentation? For volume alone, a voxel network is already near the ceiling (ICC 0.99), and we do not claim to beat it on accuracy. The program is valuable only if it is compact and editable. We will measure this directly with a follow-up-scan task: starting from the baseline-scan program, how many statement edits are needed to fit the follow-up mask, and how stable are the parameters? Compare this with re-segmenting from scratch. If programs offer no stability or edit-economy advantage, the case for them weakens, and we will say so.

Why not just amortize offline like GIFT? GIFT's own results show amortization works well in-distribution. Its authors note a drop on real images, and its recipe needs ground-truth programs, which do not exist for patient anatomy. Our compute-matched comparison on out-of-distribution biological shapes will show whether test-time refinement adds anything beyond a model trained on verified data. A combined variant, the amortized model plus a few traceback rounds, is included in case the two approaches turn out to be complementary.

Decisive Checks

Three outcomes decide the project. The first and central one concerns the plateau. Plot fit improvement against refinement round. If the traceback condition is still improving at rounds 5–8 while scalar-IoU feedback flattens by round 3, as Yan et al. found for compiler feedback, the hypothesis is supported. If both flatten together, it is refuted.

The second is whether the language-model loop beats greedy addition at equal program length on irregular shapes. Without this, the model's role is not justified.

The third is whether, on hemorrhage masks (if data access permits), short programs move the volume ICC substantially from Tada's 0.887 toward 0.99, with bias near zero, on the large-bleed subgroup where Tada collapses to 0.516.

On CytoNuke, the corresponding target is a morphometric distance at or below Cyto R-CNN's D = 0.15. This test asks whether short programs preserve cell shape statistics; it does not compete with Cyto R-CNN as a segmenter.