Official Codebase of 3DCodeVerse
Python
plan contract: a thinking model's self-reference cannot become a part
gaoypeng81f898be917b
diff --git a/harness/codeverse/contracts/plan.py b/harness/codeverse/contracts/plan.pyindex 37596ac7..71007dc9 100644--- a/harness/codeverse/contracts/plan.py+++ b/harness/codeverse/contracts/plan.py@@ -71,6 +71,11 @@ class SubPartPlan(BaseModel):the only complexity metric with a positive partial correlation to geometry_detail."""name: str = Field(description="PascalCase, unique within the parent, e.g. Burr")++ @field_validator("name")+ @classmethod+ def _no_model_leak(cls, v: str) -> str:+ return reject_model_leak(v)role: str = Field(default="", description="what this sub-part is, a few words")description: str = Field(description="shape and construction in numbers")bbox: BBox = Field(description="inside the parent's bbox, same frame")@@ -80,6 +85,11 @@ class SubPartPlan(BaseModel):class PartPlan(BaseModel):name: str = Field(description="PascalCase unique part name, e.g. SeatCushion")++ @field_validator("name")+ @classmethod+ def _no_model_leak(cls, v: str) -> str:+ return reject_model_leak(v)role: str = Field(description="what this part is / does, one line")description: str = Field(description="shape, construction and visible detail the builder must realise")bbox: BBox@@ -166,6 +176,11 @@ class StaticPlan(BaseModel):class JointPlan(BaseModel):name: str++ @field_validator("name")+ @classmethod+ def _no_model_leak(cls, v: str) -> str:+ return reject_model_leak(v)type: Literal["revolute", "prismatic", "continuous", "fixed"]parent: str = Field(description="parent link (part) name")child: str = Field(description="child link (part) name")@@ -406,6 +421,24 @@ class EffectPlan(BaseModel):#: the charset ``render_glb.mjs`` already enforces for view names, plus a length bound.CAMERA_NAME_RE = re.compile(r"[A-Za-z0-9_-]{1,64}")+#: a thinking model's self-reference leaked into structured output: measured 2026-08-28+#: (gear_cq_ss), the PLANNER emitted a part literally named "Gemini25FlashThinking" and+#: the generator faithfully modelled a placeholder pillar for it — judged 0.0. High-+#: precision patterns only: "CameraFlash" or "ModelStand" must stay legal.+_MODEL_NAME_LEAK = re.compile(r"(?i)(gemini|gpt[-_ ]?\d|claude|llama|qwen|deepseek|placeholder)")+++def reject_model_leak(v: str) -> str:+ """Reject (never mangle) part names that are model ids / placeholders — the planner+ is re-asked with this error, exactly like an unsafe camera name."""+ m = _MODEL_NAME_LEAK.search(v)+ if m:+ raise ValueError(+ f"part name {v!r} contains {m.group(1)!r} — a model id or placeholder leaked from "+ "thinking, not a component of the object. Name the real part (e.g. GrinderWheel).")+ return v++class CameraPlan(BaseModel):name: str = Field(description="letters/digits/_/- only; it becomes a render filename")diff --git a/harness/tests/orchestrator_tracks/test_planner_depth.py b/harness/tests/orchestrator_tracks/test_planner_depth.pyindex b57c6b9b..783031fb 100644--- a/harness/tests/orchestrator_tracks/test_planner_depth.py+++ b/harness/tests/orchestrator_tracks/test_planner_depth.py@@ -517,3 +517,27 @@ def test_brief_and_plan_are_one_model_and_the_events_say_so(tmp_path, monkeypatcassert done["brief"] is True and done["target_parts"] == 10 and done["quality_reasks"] == 0assert any(name == "plan.brief" for name, _ in ev.rows)assert [a for a in plan.acceptance if a.id.startswith("sig")]+++def test_a_model_name_leak_is_rejected_not_modelled():+ """Measured 2026-08-28 (gear_cq_ss): the planner emitted a part literally named+ 'Gemini25FlashThinking' — a thinking model's self-reference leaked into structured+ output — and the generator faithfully built a placeholder pillar for it (judged 0.0).+ The contract now rejects such names so the planner is re-asked, like an unsafe+ camera name. Real part names that merely contain 'flash' or 'model' stay legal."""+ import pytest as _pytest+ from pydantic import ValidationError++ from codeverse.contracts.plan import JointPlan, PartPlan, SubPartPlan++ for bad in ("Gemini25FlashThinking", "GPT4Placeholder", "placeholder_arm"):+ with _pytest.raises(ValidationError, match="leaked from"):+ PartPlan(name=bad, role="r", description="d", bbox=_bbox())+ with _pytest.raises(ValidationError, match="leaked from"):+ SubPartPlan(name="ClaudePart", description="d", bbox=_bbox())+ with _pytest.raises(ValidationError, match="leaked from"):+ JointPlan(name="gemini_hinge", type="revolute", parent="A", child="B",+ axis=(0, 0, 1), pivot=(0, 0, 0))+ # high precision: legitimate names that merely contain hot substrings stay legal+ for ok in ("CameraFlash", "ModelStand", "GearHousing"):+ PartPlan(name=ok, role="r", description="d", bbox=_bbox())