Answer principles round 1: 0 🔴, 3 🟡 (0 misread); state listed's lock, let each module drop its own ended files, test run_loop's listing end to end

This commit is contained in:
2026-10-29 20:33:52 +01:00
parent 9f71b9aa91
commit 326866e85b
9 changed files with 79 additions and 33 deletions
+10 -2
View File
@@ -4,7 +4,8 @@ A running loop holds its session's lock (session_lock.py) in Paths.waiting for i
beside it: its checkout, and the ID and tagline of each item its chunk takes. Those are the item it was routed on, then
the items the judge's latest ruling found the worker took in, each once, with its tagline on the default branch as last
fetched. loop-inbox lists a loop, and its questions (waiting.py), only while its lock is held, so a killed loop drops off
the list though its files stay; loop-inbox removes them.
the list though its files stay. loop-inbox removes them: <session>.running through drop_ended_loops here, and the
question through waiting.drop_ended.
"""
import contextlib
import dataclasses
@@ -14,8 +15,8 @@ import shutil
import typing
from loop_claude.effects import Effects, say
from loop_claude.session_lock import ended, held, running
from failure import Failure
from loop_claude.session_lock import held, running
from todo_table import items
from file_writes import replace_json
@@ -102,6 +103,13 @@ def running_loops(folder: pathlib.Path) -> list[RunningLoop]:
return sorted(loops, key=lambda loop: loop.root)
def drop_ended_loops(folder: pathlib.Path) -> None:
"""Removes each running file whose session's lock no loop holds: a loop that was killed leaves it behind. A file it cannot remove stays on disk, and running_loops leaves it out all the same."""
for session in ended(folder, "*.running"):
with contextlib.suppress(OSError):
running_file(folder, session).unlink(missing_ok=True)
def read_running(path: pathlib.Path) -> RunningLoop | None:
try:
data = json.loads(path.read_text(encoding="utf-8"))