Skip to content

Official Codebase of 3DCodeVerse

Python

planner: the restart fires on the measured class and stops paying for it twice

ziyaoc20d5d755eb8
diff --git a/harness/codeverse/tracks/planner.py b/harness/codeverse/tracks/planner.py
index 1589cd59..098832ff 100644
--- a/harness/codeverse/tracks/planner.py
+++ b/harness/codeverse/tracks/planner.py
@@ -709,16 +709,25 @@ def restart_enabled() -> bool:
return env_flag(PLAN_RESTART_ENV, True)
+def degenerate_plan(raw: Any, budget: PlanBudget) -> bool:
+ """A plan too small to be an attempt at this request: a third of the floor or less.
+
+ The quality complaint owns everything above that line — this is only the collapsed
+ answer (usually ONE top-level part) that the in-context re-ask reproduces instead of
+ fixing, which is why it is also the restart's trigger."""
+ parts = raw.get("parts") if isinstance(raw, dict) else None
+ return isinstance(parts, list) and len(parts) <= max(2, budget.min_parts // 3)
+
+
def _thin_plan_note(raw: Any, budget: PlanBudget) -> str:
"""A second line for the validation re-ask when the invalid plan is also far too small.
compare_art_v4_pf0 (2026-08-28): flash answered an architect-lamp brief with ONE part
("base") and a joint naming a link it never listed, three times in a row — the re-ask
only echoed the unknown-link error, so the model kept fixing the wrong thing."""
- parts = raw.get("parts") if isinstance(raw, dict) else None
- # only a degenerate plan (a third of the floor or less) — the quality complaint owns the rest
- if not isinstance(parts, list) or len(parts) > max(2, budget.min_parts // 3):
+ if not degenerate_plan(raw, budget):
return ""
+ parts = raw.get("parts")
return (f"\nAlso: this plan lists only {len(parts)} part(s) but the request needs about {budget.target_parts} "
f"({budget.reason}). Put EVERY link a joint references under `parts` with its own bbox.")
@@ -832,7 +841,8 @@ def plan_with_usage[P: BaseModel](spec: Spec, model_id: str, plan_model: type[P]
thinking = "medium"
wait_scale = 1.0
geo_reasked = 0
- for attempt in range(2 + MAX_VALIDATION_REASKS + MAX_QUALITY_REASKS + MAX_GEOMETRY_REASKS):
+ for attempt in range(2 + MAX_VALIDATION_REASKS + MAX_QUALITY_REASKS + MAX_GEOMETRY_REASKS
+ + MAX_PLAN_RESTARTS):
req = ChatRequest(messages=messages, system=system, response_schema=schema, temperature=temperature,
thinking=thinking, max_output_tokens=tokens, label=f"planner{'-retry' if attempt else ''}",
max_wait_s=plan_wait_s(tokens, guard, scale=wait_scale))
@@ -868,16 +878,19 @@ def plan_with_usage[P: BaseModel](spec: Spec, model_id: str, plan_model: type[P]
result = plan_model.model_validate(raw)
except (ValidationError, ValueError) as e:
last_error = str(e)[:4000]
- invalid += 1
if events is not None:
events.emit("plan.invalid", attempt=attempt, error=last_error[:500])
- if invalid > MAX_VALIDATION_REASKS:
- break
missing = missing_link_names(raw)
- if missing and restarts < MAX_PLAN_RESTARTS and restart_enabled():
+ # The measured class is BOTH conditions: a collapsed plan (one top-level part)
+ # whose joints name links it never listed. A full plan with one misspelled
+ # link is the re-ask's job — restarting throws away parts that were right.
+ if (missing and degenerate_plan(raw, budget)
+ and restarts < MAX_PLAN_RESTARTS and restart_enabled()):
# Editing a degenerate answer in context reproduces it: the model reads its
# own one-part plan and returns it again (measured, both re-asks, 2026-09-02).
- # Re-sample from the original request instead, with the rule it broke.
+ # Re-sample from the original request instead, with the rule it broke. This
+ # replaces the conversation rather than extending it, so it spends an
+ # ATTEMPT, not one of the two re-ask slots the next invalid answer needs.
restarts += 1
if events is not None:
events.emit("plan.restart", attempt=attempt, n_parts=len(raw.get("parts") or []),
@@ -887,6 +900,9 @@ def plan_with_usage[P: BaseModel](spec: Spec, model_id: str, plan_model: type[P]
images=images or None),
]
continue
+ invalid += 1
+ if invalid > MAX_VALIDATION_REASKS:
+ break
messages = messages + [
_echo(raw, resp.text),
ChatMessage.user("Your plan failed validation. Fix EXACTLY these problems and return the full corrected "
@@ -1083,4 +1099,5 @@ __all__ = ["MAX_GEOMETRY_REASKS", "MAX_PLAN_RESTARTS", "MAX_QUALITY_REASKS", "MA
"PLAN_GEOMETRY_ENV", "PLAN_RESTART_ENV", "PLAN_TOKENS_MAX", "PlanningError", "add_acceptance_item",
"articulation_acceptance", "build_system_prompt", "build_user_prompt", "default_event_stats",
"ensure_acceptance", "geometry_check_enabled", "missing_link_names", "normalise_names", "plan",
- "plan_example", "plan_tokens", "plan_with_usage", "restart_enabled", "restart_note"]
+ "degenerate_plan", "plan_example", "plan_tokens", "plan_with_usage", "restart_enabled",
+ "restart_note"]
diff --git a/harness/tests/orchestrator_tracks/test_planner_restart.py b/harness/tests/orchestrator_tracks/test_planner_restart.py
index fdb0b0df..e3fe824a 100644
--- a/harness/tests/orchestrator_tracks/test_planner_restart.py
+++ b/harness/tests/orchestrator_tracks/test_planner_restart.py
@@ -89,12 +89,33 @@ def test_the_kill_switch_restores_the_in_context_reask(tmp_ws, monkeypatch):
assert isinstance(p, ArticulatedPlan) and len(model.requests[1].messages) == 3
-def test_one_restart_per_plan_then_the_normal_reask_budget(tmp_ws):
- """Two degenerate answers: restart once, then edit in context, then give up as before."""
+def test_a_restart_costs_an_attempt_not_one_of_the_two_reask_slots(tmp_ws):
+ """Every answer degenerate: restart once, then still get BOTH in-context re-asks.
+
+ The restart used to increment the same counter as a re-ask, so a run that restarted
+ had one re-ask left instead of two — visible in the recorded battery as deaths with
+ ``restarts=1`` at the validation cap (bench/data/plan_stage/restart_on.jsonl)."""
model = FakeChatModel(lambda req: _degenerate())
with pytest.raises(PlanningError):
plan(_spec(), "fake:planner", ArticulatedPlan, tmp_ws, model=model,
runtime=FakeRuntime(Language.URDF_BLENDER))
- assert len(model.requests) == 3 # first + one restart + one in-context re-ask
assert MAX_PLAN_RESTARTS == 1
- assert len(model.requests[1].messages) == 1 and len(model.requests[2].messages) == 3
+ assert len(model.requests) == 4 # first + restart + two re-asks
+ # 1 = the request alone (a restart replaces the conversation), then one echo+complaint pair each
+ assert [len(r.messages) for r in model.requests] == [1, 1, 3, 5]
+
+
+def test_a_full_plan_with_one_dangling_link_is_edited_in_context_not_resampled(tmp_ws):
+ """The restart's trigger is the MEASURED class: collapsed AND dangling. A plan with
+ every part in place and one misspelled link is what the re-ask is good at, and
+ re-sampling it throws away the parts that were right."""
+ typo = _good()
+ for i in range(4): # a full-sized plan, well over the degeneracy floor
+ typo["parts"].append({"name": f"Filler{i}", "role": "trim", "description": "a rail",
+ "bbox": {"center": [0, 0, 0.1 * i], "extents": [0.02, 0.4, 0.02]},
+ "material": "oak", "attach_to": "Cabinet"})
+ typo["joints"][0]["child"] = "Drawerr"
+ p, model = _run(tmp_ws, [typo, _good()])
+ assert isinstance(p, ArticulatedPlan) and len(model.requests) == 2
+ assert len(model.requests[1].messages) == 3 # user + echoed answer + complaint, no restart
+ assert "failed validation" in model.requests[1].messages[-1].text