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
+18 -21
View File
@@ -1,10 +1,9 @@
"""The files by which a loop-claude shows its interrupt in loop-inbox, and takes an answer typed there.
A waiting loop keeps its ask in <session>.json in Paths.waiting: the question, with an id new for each question.
<session> is the worker's session id, so a loop lists one question at a time. The loop holds the session's lock while it
lists the ask, and removes the ask once the question is answered or the loop stops. loop-inbox lists an ask only while
its lock is held, and removes one whose lock is free. The ask's state says whether the loop waits for an answer, or has
claude open for it, on the loop's own terminal or in loop-inbox. loop-inbox answers by replacing <session>.answer, which
<session> is the worker's session id, so a loop lists one question at a time. The loop removes the ask once the question
is answered or the loop stops. loop-inbox lists an ask only while the loop holds the session's lock (running_loops.py),
and removes one whose lock is free. The ask's state says whether the loop waits for an answer, or has claude open for it, on the loop's own terminal or in loop-inbox. loop-inbox answers by replacing <session>.answer, which
names the ask's id. So an answer meant for an earlier question, or sent as the loop took an answer on its terminal,
never answers a later one.
@@ -24,8 +23,9 @@ import typing
from loop_claude.hand_over import ClaudeCommand
from loop_claude.effects import Effects, POLL_SECONDS, say
from failure import Failure
from loop_claude.session_lock import locked, running
from loop_claude.session_lock import held, running
from file_writes import make_private, replace_json
from loop_claude.running_loops import running_file
# Seconds loop-inbox waits for a loop to make way for its claude: ten of the loop's looks, so a loop slow for a moment still makes way.
MAKE_WAY_SECONDS = 10 * POLL_SECONDS
@@ -122,17 +122,12 @@ def shown(folder: pathlib.Path, ask: Ask, effects: Effects) -> None:
@contextlib.contextmanager
def listed(folder: pathlib.Path, ask: Ask, effects: Effects) -> typing.Iterator[None]:
"""Lists ask in loop-inbox while the with block runs, then takes it out, with any answer. A failure to list it only warns: the question is still answered on the loop's terminal."""
with locked(folder, ask.session) as unlocked:
if unlocked:
say(f"loop-inbox cannot show this question: {unlocked.reason}", effects)
yield
return
shown(folder, ask, effects)
try:
yield
finally:
# An ask this fails to remove is left to loop-inbox, which stops listing it once the lock is let go, and removes it.
withdraw(folder, ask.session)
shown(folder, ask, effects)
try:
yield
finally:
# An ask this fails to remove is left to loop-inbox, which stops listing it once the lock is let go, and removes it.
withdraw(folder, ask.session)
def waiting(folder: pathlib.Path) -> list[Ask]:
@@ -146,15 +141,17 @@ def waiting(folder: pathlib.Path) -> list[Ask]:
def drop_ended(folder: pathlib.Path) -> None:
"""Removes each ask, with any answer, whose session's lock no loop holds: a loop that was killed leaves its ask behind. It removes one while holding the lock, so a loop that lists a new ask meanwhile keeps it. An ask it cannot remove stays on disk, and waiting leaves it out all the same."""
"""Removes the ask, any answer and the running file of each session whose lock no loop holds: a loop that was killed leaves them behind. It removes them while holding the lock, so a loop that starts meanwhile keeps its own. A file it cannot remove stays on disk, and loop-inbox leaves it out all the same."""
try:
paths = list(folder.glob("*.json"))
sessions = {path.stem for pattern in ("*.json", "*.running") for path in folder.glob(pattern)}
except OSError:
return
for path in paths:
with locked(folder, path.stem) as unlocked:
for session in sessions:
with held(folder, session) as unlocked:
if not unlocked:
withdraw(folder, path.stem)
withdraw(folder, session)
with contextlib.suppress(OSError):
running_file(folder, session).unlink(missing_ok=True)
def read_ask(path: pathlib.Path) -> Ask | None: