End a worker that lingers after its final result by stopping the quiet background shells it left
CI / tests (pull_request) Failing after 4m10s
CI / tests (pull_request) Failing after 4m10s
This commit is contained in:
@@ -1,4 +1,7 @@
|
||||
import pathlib
|
||||
|
||||
from claude_code.entries import AssistantTurn, ends_stream, entry_from, hit_limit, json_object, limit_said, rejected_until
|
||||
from loop_claude.cycle.lingering_workers import CHECK_EVERY, RECORD, stopped_shells
|
||||
from loop_effects.effects import Effects, say
|
||||
from failure import Failure
|
||||
from claude_code.reply import Limited
|
||||
@@ -15,16 +18,22 @@ AUTO_COMPACT_WINDOW = "CLAUDE_CODE_AUTO_COMPACT_WINDOW"
|
||||
COMPACT_WINDOW = 200_000
|
||||
|
||||
|
||||
def run_worker(root: str, args: list[str], env: dict[str, str], effects: Effects) -> Failure | Limited | None:
|
||||
def run_worker(root: str, args: list[str], env: dict[str, str], project_archive: pathlib.Path, effects: Effects) -> Failure | Limited | None:
|
||||
wait_for_memory(effects)
|
||||
try:
|
||||
proc = effects.stream_claude(args, root, env)
|
||||
except OSError as failure:
|
||||
return Failure(f"could not start claude: {failure.strerror}")
|
||||
result: dict | None = None
|
||||
# When the last line the worker printed, if it is a result: a worker that prints on is working.
|
||||
settled_at: float | None = None
|
||||
resets: list[int] = []
|
||||
for raw in proc.lines():
|
||||
for raw in proc.lines(CHECK_EVERY):
|
||||
if raw is None:
|
||||
stopped_shells(proc, settled_at, project_archive / RECORD, effects)
|
||||
continue
|
||||
event = json_object(raw) or {}
|
||||
settled_at = effects.now() if ends_stream(event) else None
|
||||
if ends_stream(event):
|
||||
result = event
|
||||
if (resets_at := rejected_until(event)) is not None:
|
||||
|
||||
Reference in New Issue
Block a user