Official Codebase of 3DCodeVerse
Python
run hygiene: a spent run cannot start another session, and a hung one can be told to show its stacks
gaoypeng6a3b273124e7
diff --git a/harness/codeverse/cli/main.py b/harness/codeverse/cli/main.pyindex 6166b494..4e7b700c 100644--- a/harness/codeverse/cli/main.py+++ b/harness/codeverse/cli/main.py@@ -13,8 +13,11 @@ sibling ``cli/inspect_cmd.py`` and are registered here, the way ``layout_cmd.py`from __future__ import annotations+import contextlib+import faulthandlerimport jsonimport os+import signalimport sysfrom pathlib import Pathfrom typing import Annotated@@ -264,6 +267,13 @@ RunsDirOpt = Annotated[def _root(ctx: typer.Context, version: Annotated[bool, typer.Option("--version", is_eager=True)] = False) -> None:+ # `kill -USR1 <pid>` dumps every thread's stack to stderr (the run log): the+ # 2026-08-28 scope_tj_r3 hang (futex wait, every socket CLOSE-WAIT, 41 min past+ # its window) was undiagnosable without it — py-spy needs ptrace rights WSL denies.+ if hasattr(signal, "SIGUSR1") and sys.__stderr__ is not None:+ # best-effort: a captured stderr (CliRunner's StringIO) has no fileno+ with contextlib.suppress(Exception):+ faulthandler.register(signal.SIGUSR1, file=sys.__stderr__, all_threads=True)if version:console.print(f"3dcv {__version__}")raise typer.Exit()diff --git a/harness/codeverse/tracks/generation.py b/harness/codeverse/tracks/generation.pyindex 8faad88f..00fab06c 100644--- a/harness/codeverse/tracks/generation.py+++ b/harness/codeverse/tracks/generation.py@@ -545,6 +545,13 @@ def run_agent_task(# clipped this since the greenhouse incident; object/articulated/graphics did not,# so a flat 30-minute session ran 9 minutes PAST a 30-minute ceiling (measured# 2026-08-27: 'elapsed 39.0 min exceeds max_minutes 30.0', round 0 never finished).+ if budget is not None and hasattr(budget, "check"):+ # ...and a run past its HARD ceiling must not start one at all. A timed-out+ # session that produced nothing bills nothing, the accounting-driven check()+ # never fires, and the round loop treadmills on 120 s mercy floors forever+ # (measured 2026-08-28: lamp_bl, 30-min cap, killed by hand at 57 min with+ # round 0 unfinished — silent-bail retries kept getting floor sessions).+ budget.check()if budget is not None and hasattr(budget, "timeout_s"):timeout = budget.timeout_s(timeout, floor_s=120.0)turns_cap = task.max_turns or max_turns or agent_max_turns() # 0 = leave AgentJob's own defaultdiff --git a/harness/tests/orchestrator_tracks/test_round_economics.py b/harness/tests/orchestrator_tracks/test_round_economics.pyindex 077b6bd6..19b35008 100644--- a/harness/tests/orchestrator_tracks/test_round_economics.py+++ b/harness/tests/orchestrator_tracks/test_round_economics.py@@ -523,3 +523,21 @@ def test_fan_out_workers_inherit_the_callers_context():assert set(seen) == {"run-42"}# the caller's own context is untouched by the workersassert var.get() == "run-42"+++def test_a_run_past_its_hard_ceiling_cannot_start_another_session(tmp_ws):+ """Measured 2026-08-28 (lamp_bl, --max-minutes 30, killed by hand at 57 min with+ round 0 unfinished): a timed-out session bills nothing, so the accounting-driven+ check() never fired and silent-bail retries treadmilled on 120 s mercy floors+ forever. run_agent_task now checks the HARD ceiling before starting any session."""+ from codeverse.contracts.spec import Budget+ from codeverse.orchestrator import BudgetExceeded, BudgetGuard++ g = BudgetGuard(Budget(max_usd=10.0, max_minutes=30.0, max_rounds=4), run="t")+ g.start_time -= 36 * 60 # ceiling long crossed, nothing billed along the way+ agent = _TurnAgent(writes_on=1)+ with pytest.raises(BudgetExceeded):+ run_agent_task(tmp_ws, agent=agent,+ task=GenerationTask(label="baseline", prompt="p", round=0, kind="baseline"),+ budget=g)+ assert agent.jobs == [] # the treadmill ends BEFORE the agent is invoked