Answer architecture round 1: 0 🔴, 7 🟡 (0 misread); hold one lock per loop for its whole run, group the judge's readings of the items taken in, list them as given

This commit is contained in:
2026-10-29 20:23:07 +01:00
parent 9bcfaebb83
commit dcdb8b5868
16 changed files with 274 additions and 278 deletions
+7 -19
View File
@@ -1,8 +1,7 @@
"""The locks by which loop-inbox tells that a loop-claude still runs.
"""The lock by which loop-inbox tells that a loop-claude still runs.
A loop holds <session>.lock while loop-inbox lists the session's question, and <session>.running.lock for its whole run
(running_loops.py). Each is held with flock, which the kernel frees however the loop ends, killed included. A lock file
stays once the loop ends: docs/decisions.md → `loop-inbox: …` says why.
A loop holds <session>.lock for its whole run (running_loops.py), with flock, which the kernel frees however the loop
ends, killed included. The lock file stays once the loop ends: docs/decisions.md → `loop-inbox: …` says why.
"""
import contextlib
import fcntl
@@ -18,15 +17,9 @@ def lock_file(folder: pathlib.Path, session: str) -> pathlib.Path:
@contextlib.contextmanager
def locked(folder: pathlib.Path, session: str) -> typing.Iterator[Failure | None]:
"""Holds the session's lock while the with block runs, or yields a Failure where it cannot. loop-inbox's drop_ended takes the lock for a moment on each ask still on disk, so a loop may find it held."""
with held(folder, lock_file(folder, session)) as unlocked:
yield unlocked
@contextlib.contextmanager
def held(folder: pathlib.Path, path: pathlib.Path) -> typing.Iterator[Failure | None]:
"""Holds the lock at path, a file in folder, while the with block runs, or yields a Failure where it cannot."""
def held(folder: pathlib.Path, session: str) -> typing.Iterator[Failure | None]:
"""Holds the session's lock while the with block runs, or yields a Failure where it cannot. loop-inbox's drop_ended takes the lock for a moment on each session whose files are still on disk, so a loop may find it held."""
path = lock_file(folder, session)
try:
make_private(folder)
except OSError as failure:
@@ -51,13 +44,8 @@ def held(folder: pathlib.Path, path: pathlib.Path) -> typing.Iterator[Failure |
def running(folder: pathlib.Path, session: str) -> bool:
"""Whether a loop holds the session's lock; False also where the lock file cannot be opened or locked."""
return taken(lock_file(folder, session))
def taken(path: pathlib.Path) -> bool:
"""Whether a process holds the lock at path; False also where it cannot be opened or locked."""
try:
with open(path) as handle:
with open(lock_file(folder, session)) as handle:
fcntl.flock(handle, fcntl.LOCK_SH | fcntl.LOCK_NB)
except BlockingIOError:
return True