Judge a worker that stalls before its result with a headless claude, and report the verdict without a kill
CI / tests (pull_request) Failing after 4m3s

This commit is contained in:
2026-11-19 08:55:14 +01:00
parent a559bbfcbf
commit 08038d93eb
10 changed files with 327 additions and 20 deletions
+10 -6
View File
@@ -9,6 +9,7 @@ from claude_code.transcript import part_line
from machine_load.memory import ROOM_SHARE
from model_routing.ladder import Rung
from claude_code.session import Session
from agent_cycle.stuck_workers import Watch
PRINTED_TOOL_INPUT = 160
# Seconds between reads of the machine's memory while too little of it is available to start a worker.
@@ -18,13 +19,14 @@ AUTO_COMPACT_WINDOW = "CLAUDE_CODE_AUTO_COMPACT_WINDOW"
COMPACT_WINDOW = 200_000
def run_worker(root: str, args: list[str], env: dict[str, str], project_archive: pathlib.Path, effects: Effects) -> Failure | Limited | None:
def run_worker(root: str, args: list[str], env: dict[str, str], project_archive: pathlib.Path, investigator: Rung, effects: Effects) -> Failure | Limited | None:
"""Runs the worker's claude once the machine has room for it, as run_claude does with a Watch whose stuck checks run on investigator, the project's rung."""
wait_for_memory(effects)
return run_claude(root, args, env, effects, project_archive / RECORD)
return run_claude(root, args, env, effects, Watch(investigator, project_archive))
def run_claude(root: str, args: list[str], env: dict[str, str], effects: Effects, record: pathlib.Path | None = None) -> Failure | Limited | None:
"""Runs a headless claude at once, printing what it says, and returns how it failed, or None. Where record is given, a claude that lingers after its final result loses its quiet shells, as `lingering_workers.stopped_shells` says, and each stop is appended to record."""
def run_claude(root: str, args: list[str], env: dict[str, str], effects: Effects, watch: Watch | None = None) -> Failure | Limited | None:
"""Runs a headless claude at once, printing what it says, and returns how it failed, or None. Where watch is given, a claude that lingers after its final result loses its quiet shells, as `lingering_workers.stopped_shells` says, each stop appended to RECORD in watch's archive; and a silent claude that has printed no result is checked for stuck shells, as `stuck_workers` says."""
try:
proc = effects.stream_claude(args, root, env)
except OSError as failure:
@@ -35,8 +37,10 @@ def run_claude(root: str, args: list[str], env: dict[str, str], effects: Effects
resets: list[int] = []
for raw in proc.lines(CHECK_EVERY):
if raw is None:
if record is not None:
stopped_shells(proc, printed_result, record, effects)
if watch is not None:
stopped_shells(proc, printed_result, watch.archive / RECORD, effects)
if not printed_result:
watch.check(proc, root, effects)
continue
event = json_object(raw) or {}
printed_result = ends_stream(event)