Skip to content

Official Codebase of 3DCodeVerse

Python

cli: resume refuses a run whose clock is already spent until --max-minutes is raised — --force included

gaoypeng5f71e7d5a4db
diff --git a/harness/codeverse3d/cli/main.py b/harness/codeverse3d/cli/main.py
index fe1c0474..f8c6c8cf 100644
--- a/harness/codeverse3d/cli/main.py
+++ b/harness/codeverse3d/cli/main.py
@@ -590,6 +590,22 @@ def _finished_reason(ws, raised: dict) -> str:
return detail if status in finished else ""
+def _clock_spent(ws, max_minutes: float) -> str:
+ """Why a resume would stop before doing anything, or "": the run's clock (the budget snapshot's
+ ACTIVE minutes, which a resume — ``--force`` included — keeps counting) is already at the cap.
+ Resumed anyway, a plain resume stopped at `budget` at once, and ``--force`` first archived every
+ paid round and then did so (live, 2026-09-23)."""
+ from codeverse3d.orchestrator import BudgetSnapshot, RunState, StateCorrupt
+
+ try:
+ state = RunState.load(ws)
+ except StateCorrupt:
+ return ""
+ snap = (state.extra.get("budget_snapshot") if state is not None else None) or {}
+ used = BudgetSnapshot.model_validate(snap).active_s / 60.0
+ return f"its clock is spent ({used:.1f} of {max_minutes:g} active minutes)" if used >= max_minutes else ""
+
+
@app.command()
def resume(
slug: str,
@@ -644,6 +660,9 @@ def resume(
for k, v in {"max_minutes": max_minutes, "max_rounds": rounds}.items()
if v is not None
}
+ if spent := _clock_spent(ws, raised.get("max_minutes", spec.budget.max_minutes)):
+ raise C.CliError(f"run {ws.root.name}: {spent} — raise --max-minutes to continue it"
+ + (" (--force keeps the clock: it would archive every round and stop at once)" if force else ""))
if not force and (why := _finished_reason(ws, raised)):
raise C.CliError(
f"run {ws.root.name} already finished ({why}); nothing to resume. "
diff --git a/harness/docs/RUNBOOK.md b/harness/docs/RUNBOOK.md
index dac6273a..21c23f5c 100644
--- a/harness/docs/RUNBOOK.md
+++ b/harness/docs/RUNBOOK.md
@@ -145,7 +145,9 @@ unless you type `--host` yourself; it never serves a path outside the declared r
# (its last round is re-judged) or failed run resumes as is; the other stops
# are finished. The budget
# SNAPSHOT is restored: the active minutes already spent still count, so a
- # raised --max-minutes grants only the difference (downtime never counts);
+ # raised --max-minutes grants only the difference (downtime never counts), and
+ # a run whose clock is already spent is refused until one is (--force too: it
+ # keeps the clock);
# the money is the ledger's, and the step log (the run's minutes) carries on.
# Once rounds exist a recorded stage never runs again: one whose key drifted (a
# code change to what it hashes) serves its recorded result (`stage.frozen`); only
diff --git a/harness/tests/flywheel_cli/test_cli.py b/harness/tests/flywheel_cli/test_cli.py
index 888d9152..74c8ce37 100644
--- a/harness/tests/flywheel_cli/test_cli.py
+++ b/harness/tests/flywheel_cli/test_cli.py
@@ -591,3 +591,22 @@ def test_an_option_that_would_be_dropped_is_refused(tmp_path: Path, runs_dir: Pa
"--slug", "g"]).exit_code == 0
r = runner.invoke(app, ["render", "g", "--width", "64", "--runs-dir", str(runs)])
assert r.exit_code == 2 and "graphics run" in r.output
+
+
+def test_resume_refuses_a_run_whose_clock_is_spent_even_with_force(made_run, stub_track):
+ """Live 2026-09-23: `resume --force` on a budget-stopped run archived its paid round, kept the
+ spent clock and stopped at once with 0 rounds. A spent clock needs a raised --max-minutes."""
+ from codeverse3d.contracts.run import RunStatus
+ from codeverse3d.orchestrator import RunState
+ from codeverse3d.workspace import Workspace
+
+ runs, run_dir = made_run("--max-minutes", "20")
+ RunState(status=RunStatus.BUDGET, stop_reason="budget", extra={"budget_snapshot": {"active_s": 20.5 * 60}}).save(
+ Workspace(run_dir))
+ entered = []
+ stub_track(lambda spec, resume, force: entered.append(force))
+ for extra in ([], ["--force"], ["--rounds", "3"], ["--max-minutes", "20.2"]):
+ r = runner.invoke(app, ["resume", run_dir.name, "--runs-dir", str(runs), *extra])
+ assert r.exit_code == 1 and "clock is spent" in r.output, extra
+ assert entered == []
+ assert runner.invoke(app, ["resume", run_dir.name, "--runs-dir", str(runs), "--max-minutes", "40"]).exit_code == 130