Skip to content

Official Codebase of 3DCodeVerse

Python

planner: tell the model which links exist, and resolve a joint that names one

gaoypeng88681a1483d3
diff --git a/harness/codeverse/contracts/plan.py b/harness/codeverse/contracts/plan.py
index a89cece2..37596ac7 100644
--- a/harness/codeverse/contracts/plan.py
+++ b/harness/codeverse/contracts/plan.py
@@ -270,6 +270,22 @@ class ArticulatedPlan(StaticPlan):
kept.append(child)
part["children"] = kept
+ # 1b. a joint that names a link by a UNIQUE fragment of a real part ("Lid" for
+ # "ChestLid"): a naming slip, not a design decision. Measured 2026-08-27
+ # (art_med_tool_chest, 3.6-flash): 'joint LidHinge references unknown link(s)
+ # Carcass/Lid' three times in a row, killing the run at the planner with 0 rounds.
+ known = set(by_name)
+ for j in joints:
+ for side in ("parent", "child"):
+ raw_name = str(j.get(side, ""))
+ key = to_snake(raw_name)
+ if not key or key in known:
+ continue
+ hits = [n for n in known if key in n.split("_") or n.endswith(f"_{key}") or n.startswith(f"{key}_")]
+ if len(hits) == 1:
+ 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]}")
+
# 2. revolute joints with a > 2π range: degrees written for radians → radians; a radian
# range over 2π → continuous
for j in joints:
@@ -342,7 +358,10 @@ class ArticulatedPlan(StaticPlan):
for j in self.joints:
p, c = to_snake(j.parent), to_snake(j.child)
if p not in links or c not in links:
- raise ValueError(f"joint {j.name} references unknown link(s) {j.parent}/{j.child}")
+ unknown = ", ".join(n for n, k in ((j.parent, p), (j.child, c)) if k not in links)
+ raise ValueError(
+ f"joint {j.name} references unknown link(s) {unknown} — the parts in this plan are: "
+ f"{', '.join(sorted(links))}. Use those exact names (or add the missing part).")
if c in parent_of:
raise ValueError(f"link {j.child} has two parent joints")
if c == root:
diff --git a/harness/tests/core/test_plan_normalise.py b/harness/tests/core/test_plan_normalise.py
index 07f62219..f38bcad3 100644
--- a/harness/tests/core/test_plan_normalise.py
+++ b/harness/tests/core/test_plan_normalise.py
@@ -133,3 +133,33 @@ def test_planner_text_in_normalisations_is_dropped():
"joints": [{"name": "j", "parent": "A", "child": "A", "type": "revolute", "lower": 0, "upper": 1}],
"normalisations": ["rest pose set to 0.15 m (planner prose)"]})
assert raw["normalisations"] == []
+
+
+def test_a_joint_naming_a_part_by_a_unique_fragment_is_resolved():
+ """art_med_tool_chest, 2026-08-27: the planner named parts one way and referenced
+ them another in the joints, then repeated the identical mistake through both
+ re-asks — the run died at the planner with 0 rounds in 8 min."""
+ d = _raw()
+ d["parts"][1]["name"] = "ChestDrawer" # the plan's own name ...
+ d["joints"][0]["child"] = "Drawer" # ... referenced by one word of it
+ part = "ChestDrawer"
+ plan = ArticulatedPlan.model_validate(d)
+ assert _joint(plan, d["joints"][0]).child == part
+ assert any("resolved to the one part it names" in n for n in plan.normalisations)
+
+
+def test_an_ambiguous_joint_reference_is_rejected_and_names_the_real_parts():
+ """Two parts match the fragment → no safe repair; the message must then tell the
+ planner what the real names are, which is what the two re-asks were missing."""
+ d = _raw()
+ d["parts"][1]["name"] = "ChestDrawer"
+ twin = dict(d["parts"][1])
+ twin["name"] = "SpareDrawer"
+ d["parts"].append(twin)
+ fragment = "Drawer"
+ d["joints"][0]["child"] = fragment
+ with pytest.raises(ValidationError) as e:
+ ArticulatedPlan.model_validate(d)
+ 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"