Skip to content

Official Codebase of 3DCodeVerse

Python

plan: a root_link that names no part is repaired to the one link no joint moves

ziyao67a5c0c4e332
diff --git a/harness/codeverse/contracts/plan.py b/harness/codeverse/contracts/plan.py
index 71007dc9..a787b026 100644
--- a/harness/codeverse/contracts/plan.py
+++ b/harness/codeverse/contracts/plan.py
@@ -301,6 +301,17 @@ class ArticulatedPlan(StaticPlan):
j[side] = by_name[hits[0]].get("name")
notes.append(f"joint {j.get('name')}.{side} '{raw_name}' resolved to the one part it names: {j[side]}")
+ # 1c. a root_link that names no part (compare ab_repairs grand_piano, 2026-08-29: flash
+ # wrote a UUID string there, three times): the root is the one part no joint names
+ # as a child — when that part is unique the repair is unambiguous
+ root_key = to_snake(str(data.get("root_link", "")))
+ if root_key and root_key not in by_name:
+ children = {to_snake(str(j.get("child", ""))) for j in joints}
+ roots = [p for k, p in by_name.items() if k not in children]
+ if len(roots) == 1:
+ notes.append(f"root_link '{data.get('root_link')}' is not a part → {roots[0].get('name')} (the one link no joint moves)")
+ data["root_link"] = roots[0].get("name")
+
# 2. revolute joints with a > 2π range: degrees written for radians → radians; a radian
# range over 2π → continuous
for j in joints:
diff --git a/harness/tests/core/test_plan_normalise.py b/harness/tests/core/test_plan_normalise.py
index f38bcad3..6697449e 100644
--- a/harness/tests/core/test_plan_normalise.py
+++ b/harness/tests/core/test_plan_normalise.py
@@ -163,3 +163,22 @@ def test_an_ambiguous_joint_reference_is_rejected_and_names_the_real_parts():
msg = str(e.value)
assert f"unknown link(s) {fragment}" in msg
assert "chest_drawer" in msg and "spare_drawer" in msg, "the planner must be told the real names"
+
+
+def test_a_root_link_that_names_no_part_becomes_the_one_link_no_joint_moves():
+ """ab_repairs grand_piano, 2026-08-29: flash wrote a UUID as root_link three times and
+ the pinned plan died with 'root_link … is not a part'."""
+ d = _raw()
+ d["root_link"] = "040fbba3-b0f3-42e1-85b3-f61b0c034293"
+ plan = ArticulatedPlan.model_validate(d)
+ assert plan.root_link == "Cabinet"
+ assert any("is not a part" in n and "Cabinet" in n for n in plan.normalisations)
+
+
+def test_an_ambiguous_root_is_still_rejected():
+ d = _raw()
+ d["root_link"] = "nowhere"
+ d["parts"].append({"name": "Pedestal", "role": "base", "description": "a plinth", "material": "oak",
+ "bbox": {"center": [0, 0, -0.05], "extents": [0.5, 0.6, 0.1]}})
+ with pytest.raises(ValidationError, match="root_link nowhere is not a part"):
+ ArticulatedPlan.model_validate(d)