Official Codebase of 3DCodeVerse
Python
articulated: repair a root_link that names no part — the af_excavator death
gaoypenga02d53aaa89d
diff --git a/harness/codeverse/contracts/plan.py b/harness/codeverse/contracts/plan.pyindex 92ddea89..7dd77a0e 100644--- a/harness/codeverse/contracts/plan.py+++ b/harness/codeverse/contracts/plan.py@@ -250,6 +250,10 @@ class ArticulatedPlan(StaticPlan):after two re-asks, and neither is a design decision worth a dead run;3. a sub-part sticking out of its parent's bbox by more than the slack: the parent bboxgrows to enclose it (planner boxes are design intent, not measurements).+ 4. a ``root_link`` that names no part but loosely matches exactly ONE (af_excavator+ 2026-08-31, 3.7-flash: ``root_link: chassis`` over a part list that spelt it+ differently — two re-asks did not fix it and the run died at the planner): the+ root is rewritten to that part. Zero or several candidates still raise.Every repair is recorded in ``normalisations`` so the record shows what the planneractually wrote. Anything else still fails validation and is re-asked."""@@ -384,6 +388,19 @@ class ArticulatedPlan(StaticPlan):part["bbox"] = {"center": [(lo[a] + hi[a]) / 2 for a in range(3)],"extents": [hi[a] - lo[a] for a in range(3)]}+ # 4. root_link that names no part: loose word-match against the part list+ root = data.get("root_link")+ if isinstance(root, str) and root.strip():+ names = {to_snake(p.get("name", "")): p.get("name") for p in parts if p.get("name")}+ rk = to_snake(root)+ if rk not in names:+ # same word-boundary rule as repair 1b, never bare substring ("arm" != "alarm")+ hits = [orig for k, orig in names.items()+ if rk in k.split("_") or k.endswith(f"_{rk}") or k.startswith(f"{rk}_")]+ if len(hits) == 1:+ notes.append(f"root_link '{root}' named no part; rewrote to '{hits[0]}'")+ data["root_link"] = hits[0]+data["parts"], data["joints"], data["normalisations"] = parts, joints, notesreturn datadiff --git a/harness/tests/core/test_plan_normalise.py b/harness/tests/core/test_plan_normalise.pyindex a15584d8..388ef5d3 100644--- a/harness/tests/core/test_plan_normalise.py+++ b/harness/tests/core/test_plan_normalise.py@@ -186,3 +186,41 @@ def test_a_zero_axis_still_fails_validation():with pytest.raises(ValidationError):ArticulatedPlan.model_validate(d)++def _rename_part(d: dict, old: str, new: str) -> None:+ for part in d["parts"]:+ if part["name"] == old:+ part["name"] = new+ if part.get("attach_to") == old:+ part["attach_to"] = new+ for j in d["joints"]:+ for side in ("parent", "child"):+ if j.get(side) == old:+ j[side] = new+ if d.get("root_link") == old:+ d["root_link"] = new+++def test_a_root_link_naming_no_part_is_resolved_by_the_1b_word_rule():+ """af_excavator (2026-08-31, 3.7-flash): root_link 'chassis' over a part list that+ spelt it differently killed the run after two re-asks. Same word-boundary match as+ the joint-fragment repair — never a bare substring."""+ d = _raw()+ real_root = d["root_link"]+ _rename_part(d, real_root, "TrackedChassis")+ d["root_link"] = "Chassis"+ p = ArticulatedPlan.model_validate(d)+ assert p.root_link == "TrackedChassis"+ assert any("root_link 'Chassis'" in n and "TrackedChassis" in n for n in p.normalisations)+++def test_an_ambiguous_root_link_still_fails_validation():+ d = _raw()+ real_root = d["root_link"]+ _rename_part(d, real_root, "TrackedChassis")+ other = next(x["name"] for x in d["parts"] if x["name"] != "TrackedChassis")+ _rename_part(d, other, "ChassisMount")+ d["root_link"] = "Chassis"+ with pytest.raises(ValidationError, match="root_link"):+ ArticulatedPlan.model_validate(d)+