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
+8 -14
View File
@@ -22,10 +22,9 @@ import typing
from loop_claude.hand_over import ClaudeCommand
from loop_claude.effects import Effects, POLL_SECONDS, say
from loop_claude.session_lock import ended, running
from failure import Failure
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
@@ -121,7 +120,10 @@ 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."""
"""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.
loop-inbox lists the ask only while the loop holds the session's lock, which it doesn't take here: folder must be the one running_loops.shown_running yields, which holds the lock for the loop's whole run.
"""
shown(folder, ask, effects)
try:
yield
@@ -141,17 +143,9 @@ def waiting(folder: pathlib.Path) -> list[Ask]:
def drop_ended(folder: pathlib.Path) -> None:
"""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:
sessions = {path.stem for pattern in ("*.json", "*.running") for path in folder.glob(pattern)}
except OSError:
return
for session in sessions:
with held(folder, session) as unlocked:
if not unlocked:
withdraw(folder, session)
with contextlib.suppress(OSError):
running_file(folder, session).unlink(missing_ok=True)
"""Removes each ask, with any answer, whose session's lock no loop holds: a loop that was killed leaves its ask behind. An ask it cannot remove stays on disk, and waiting leaves it out all the same."""
for session in ended(folder, "*.json"):
withdraw(folder, session)
def read_ask(path: pathlib.Path) -> Ask | None: