Answer stability round 1: 1 🔴, 11 🟡 (0 misread); drop keys typed ahead on leaving an answer, wrap every line to the drawn width, list the routing calls, test the paths mutants survived

This commit is contained in:
2026-10-29 01:27:23 +01:00
parent 192b36fada
commit e3cd8ae0cf
15 changed files with 413 additions and 151 deletions
+11 -9
View File
@@ -1,9 +1,11 @@
"""The files by which a loop-claude that waits for the human shows its question in loop-inbox, and takes an answer typed there.
"""The files by which a loop-claude shows its interrupt in loop-inbox, and takes an answer typed there.
A waiting loop keeps one file per session, <session id>.json, in Paths.waiting, and removes it once answered or stopped.
Its state says whether it 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 id>.answer. The answer names the ask it answers by its 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.
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, or the ask's own id for the routing calls, which have no worker session.
The loop removes the file once the question is answered or the loop stops. 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.
/talk from loop-inbox goes in three steps, so that only one claude ever holds the worker's session:
1. loop-inbox's claim_talk sends ClaudeOpening, with its pid.
@@ -24,7 +26,7 @@ from file_writes import make_private, replace_json
POLL_SECONDS = 0.5
# 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
# What the human types, on the loop's terminal or in loop-inbox, to open claude for the ask; interrupt.py says who picked it.
# What the human types, on the loop's terminal or in loop-inbox, to open claude for the ask; picked on 2026-10-17 by a bench of three readers seated as the README's audience.
TALK = "/talk"
@@ -44,7 +46,7 @@ class Asking:
@dataclasses.dataclass(frozen=True)
class OpenOnTerminal:
"""claude is open for the ask on the loop's own terminal, and takes no answer from loop-inbox."""
"""claude is open for the ask on the loop's own terminal; the loop takes no answer from loop-inbox."""
@dataclasses.dataclass(frozen=True)
@@ -118,7 +120,7 @@ def withdraw(folder: pathlib.Path, session: str) -> Failure | None:
def waiting(folder: pathlib.Path, alive: typing.Callable[[int], bool]) -> list[Ask]:
"""The asks of loops still running, oldest first. A file that cannot be read or parsed is left out, as is one being replaced."""
"""The asks of loops still running, oldest first. A file that cannot be read or parsed is left out."""
try:
paths = sorted(folder.glob("*.json"))
except OSError:
@@ -188,7 +190,7 @@ def received(folder: pathlib.Path, ask: Ask) -> Message | None:
def claim_talk(folder: pathlib.Path, ask: Ask, pid: int, now: typing.Callable[[], float], sleep: typing.Callable[[float], None]) -> bool | Failure:
"""loop-inbox's side of /talk: asks the loop to make way for a claude that the loop-inbox whose process is pid opens for ask. True once the loop shows it has stopped reading its terminal, within MAKE_WAY_SECONDS; False where it was answered first, or stopped, or didn't make way in time."""
"""loop-inbox's side of /talk, where pid is loop-inbox's process: asks the loop to make way for the claude loop-inbox opens for ask. True once the loop shows it has stopped reading its terminal, within MAKE_WAY_SECONDS; False where it was answered first, stopped, made way for another loop-inbox, or didn't make way in time."""
if unsent := send(folder, ask, ClaudeOpening(pid)):
return unsent
deadline = now() + MAKE_WAY_SECONDS