Answer prose round 1: 0 🔴, 5 🟡 (0 misread); drop the warning that loop-inbox may still list a question, and make the lock's docstrings, decision, test names and items 253 and 254 true and plain
This commit is contained in:
@@ -1,8 +1,7 @@
|
||||
"""The lock a loop-claude holds on its worker's session while loop-inbox lists its question, which tells loop-inbox the loop still runs.
|
||||
"""The lock a loop-claude holds on its worker's session while loop-inbox lists the session's question. loop-inbox reads a held lock as a loop that still runs.
|
||||
|
||||
The lock is <session>.lock, held with flock. The kernel frees it however the loop ends, killed included, where a process
|
||||
id the system may hand out again cannot tell a loop that runs from one that was killed. The lock file stays once the
|
||||
loop ends: docs/decisions.md → `loop-inbox: …` says why.
|
||||
The lock is <session>.lock, held 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
|
||||
@@ -19,7 +18,7 @@ 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; a Failure where it cannot. loop-inbox holds it for a moment where it finds the session's question still listed, so a loop starting after another was killed may meet it held."""
|
||||
"""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."""
|
||||
try:
|
||||
make_private(folder)
|
||||
except OSError as failure:
|
||||
@@ -44,7 +43,7 @@ def locked(folder: pathlib.Path, session: str) -> typing.Iterator[Failure | None
|
||||
|
||||
|
||||
def running(folder: pathlib.Path, session: str) -> bool:
|
||||
"""Whether a loop holds the session's lock; False also where the lock cannot be read."""
|
||||
"""Whether a loop holds the session's lock; False also where the lock file cannot be opened or locked."""
|
||||
try:
|
||||
with open(lock_file(folder, session)) as handle:
|
||||
fcntl.flock(handle, fcntl.LOCK_SH | fcntl.LOCK_NB)
|
||||
|
||||
@@ -68,7 +68,7 @@ def human(content):
|
||||
|
||||
|
||||
def asks_and_answers(folder):
|
||||
"""What loop-inbox could still read in folder; the session's lock file stays once the loop lets it go."""
|
||||
"""folder's files but the session's lock file, which stays once the loop lets go of the lock."""
|
||||
return [path for path in sorted(folder.iterdir()) if path.suffix != ".lock"]
|
||||
|
||||
|
||||
@@ -1285,7 +1285,7 @@ class SessionLock(unittest.TestCase):
|
||||
self.addCleanup(shutil.rmtree, self.folder)
|
||||
self.path = session_lock.lock_file(self.folder, "s1")
|
||||
|
||||
def test_a_loop_cannot_take_the_lock_another_holds_and_runs_until_it_lets_it_go(self):
|
||||
def test_a_held_lock_refuses_a_second_taker_and_reads_as_running_until_let_go(self):
|
||||
self.assertFalse(session_lock.running(self.folder, "s1"))
|
||||
with session_lock.locked(self.folder, "s1") as first:
|
||||
self.assertIsNone(first)
|
||||
|
||||
+10
-10
@@ -1,12 +1,12 @@
|
||||
"""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, as
|
||||
session_lock.py describes, 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 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.
|
||||
<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
|
||||
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.
|
||||
@@ -121,7 +121,7 @@ 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 only warns: the question is still answered on the loop's terminal, and loop-inbox drops the ask once the loop's process ends."""
|
||||
"""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)
|
||||
@@ -131,8 +131,8 @@ def listed(folder: pathlib.Path, ask: Ask, effects: Effects) -> typing.Iterator[
|
||||
try:
|
||||
yield
|
||||
finally:
|
||||
if unwithdrawn := withdraw(folder, ask.session):
|
||||
say(f"loop-inbox may still list this question: {unwithdrawn.reason}", effects)
|
||||
# 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]:
|
||||
@@ -209,7 +209,7 @@ def received(folder: pathlib.Path, ask: Ask) -> Message | None:
|
||||
match data:
|
||||
case {"kind": "Typed", "text": str(text)}:
|
||||
return Typed(text)
|
||||
# A pid of 0 or below would name a process group to the loop's alive.
|
||||
# alive is always True for a pid of 0 or below, which names a process group or every process, so the loop would wait for claude forever.
|
||||
case {"kind": "ClaudeOpening", "pid": int(pid)} if pid > 0:
|
||||
return ClaudeOpening(pid)
|
||||
case {"kind": "ClaudeEnded"}:
|
||||
|
||||
@@ -127,7 +127,7 @@ def draw(window: curses.window, screen: Screen, effects: Effects) -> None:
|
||||
|
||||
|
||||
def still_waits(folder: pathlib.Path, ask: Ask) -> bool:
|
||||
"""Whether ask still waits for an answer from loop-inbox, from a loop that still runs."""
|
||||
"""Whether ask's loop still runs and still waits for an answer from loop-inbox."""
|
||||
now = read_ask(ask_file(folder, ask.session))
|
||||
return now is not None and now.id == ask.id and isinstance(now.state, Asking) and running(folder, ask.session)
|
||||
|
||||
|
||||
@@ -319,7 +319,7 @@ class Waiting(unittest.TestCase):
|
||||
pathlib.Path(folder, "s6.json").write_text(pathlib.Path(folder, "s2.json").read_text().replace('"Asking"', '"Waiting"'))
|
||||
self.assertEqual(waiting.waiting(pathlib.Path(folder)), [early, late])
|
||||
|
||||
def test_drops_and_removes_the_ask_of_a_loop_killed_before_it_took_it_out_whatever_its_pid_now_names(self):
|
||||
def test_drops_and_removes_the_ask_a_killed_loop_left_behind(self):
|
||||
with tempfile.TemporaryDirectory() as temp:
|
||||
folder = pathlib.Path(temp)
|
||||
lists_and_waits = "import pathlib, sys, time\nfrom test_loop_inbox import asked, system_effects, waiting\nwith waiting.listed(pathlib.Path(sys.argv[1]), asked('s1', '/a'), system_effects()):\n\tprint(flush=True); time.sleep(60)"
|
||||
@@ -329,7 +329,7 @@ class Waiting(unittest.TestCase):
|
||||
loop.stdout.readline()
|
||||
waiting.send(folder, asked("s1", "/a"), Typed("Use A."))
|
||||
self.assertEqual(waiting.waiting(folder), [asked("s1", "/a")])
|
||||
# SIGKILL runs none of the loop's cleanup, and the system may hand its pid to another process at once.
|
||||
# SIGKILL runs none of the loop's cleanup.
|
||||
loop.kill()
|
||||
loop.wait()
|
||||
self.assertEqual(waiting.waiting(folder), [])
|
||||
|
||||
+1
-1
@@ -109,7 +109,7 @@ Valid while cache reads cost a twentieth of input and Claude Code's compaction k
|
||||
- While claude is open for a question, as for a release ready to cut, the routing calls or a `/talk`, loop-inbox lists the loop and where claude is open, but takes no answer for it.
|
||||
- loop-inbox runs the claude command the loop wrote, `bypassPermissions` included, so that claude runs in the same sandbox as the loop. Since loop-inbox runs a command read from a file, the folder is private to the user.
|
||||
- Files, read by polling, need no daemon and only the standard library, and a loop with no loop-inbox running is answered on its terminal as before.
|
||||
- loop-inbox lists a question only while its loop holds the session's lock file with flock, and removes a question whose lock is free. The kernel frees the lock however the loop ends, killed included. A process id could not tell: on 2026-10-29 this machine's kernel handed out its 32,768 ids again every 30 to 75 minutes, so a killed loop's question came back whenever another process got its id. The lock file stays once the loop ends, one per project: removing it while another process has it open could let loop-inbox lock a file no loop holds. Todo item 252.
|
||||
- loop-inbox lists a question only while its loop holds the session's lock file with flock, and removes a question whose lock is free. The kernel frees the lock however the loop ends, killed included. A process id could not tell a running loop from a killed one: on 2026-10-29 this machine's kernel handed out its 32,768 ids again every 30 to 75 minutes, so a killed loop's question came back whenever another process got its id. The lock file stays once the loop ends, one per project: removing it while another process has it open could let loop-inbox lock a file no loop holds. Todo item 252.
|
||||
|
||||
A bench of three readers seated as the README's audience picked the name `loop-inbox`, 3–0.
|
||||
|
||||
|
||||
@@ -17,7 +17,7 @@
|
||||
| 250 | 0.5.0 | | | **Move the repeat-read rule's transcript, mtime and file reads from `bin/rule_hook/main.py` into `bin/rule_hook/repeat_read.py`, behind one `*_breaches` entry point like the other rules, and name the tuple `results_on` returns.** | 2 | 1 | 3 | 4 | 3 | code health by 3 | 13.5 |
|
||||
| 253 | 0.5.0 | | principle | **Group `bin/loop_claude/waiting.py`'s 29 top-level names, such as the ask's states, the answers and the /talk handshake, so each level holds about seven.** | 2 | 1 | 3 | 4 | 3 | code health by 3 | 13.5 |
|
||||
| 235 | 0.5.0 | | decision | **Compare the first 20 chunks whose worker ran under the 200k compaction window with the 20 before them, on review rounds past each pass's first, unfinished verdicts, 🔴, 🟡 and misread findings, dollars and hours per chunk, and file an item where any rose.** | 1 | 2 | 1 | 2 | 2 | 1.1 by 2, 1.4 by 3 | 6.8 |
|
||||
| 254 | 0.5.0 | | principle | **Store when a loop asked as an ISO UTC datetime in loop-inbox's ask files, in place of seconds since the epoch.** | 1 | 1 | 2 | 2 | 2 | code health by 1 | 6.0 |
|
||||
| 254 | 0.5.0 | | principle | **Store when a loop asked as an ISO UTC datetime in loop-inbox's ask files.** | 1 | 1 | 2 | 2 | 2 | code health by 1 | 6.0 |
|
||||
| 167 | 0.5.0 | | | **Refuse a `/security-review` or `/claude-security` Skill call below the project's rung, as rule-hook refuses such an Agent call.** | 3 | 2 | 3 | 6 | 2 | 1.1 by 4 | 5.6 |
|
||||
| 6 | 0.5.0 | | decision | **Move what `loop-claude` writes out of `~/.claude.json`, and ask the human about each write that must stay.** | 3 | 3 | 3 | 7 | 3 | 1.1 by 5 | 5.3 |
|
||||
| 240 | 0.5.0 | | decision | **Give loop-claude's worker prompt the reading rule "never read more than 80 lines of a file at once, nor take a tool output over 3,000 characters into your context", and keep it only where the 20 chunks after it hold the 20 before's review rounds, unfinished verdicts, 🔴, 🟡 and misread findings, dollars and hours per chunk.** | 1 | 2 | 3 | 4 | 2 | 1.4 by 3 | 4.0 |
|
||||
@@ -92,15 +92,15 @@ Found by the paired ruling of PR #387: all four seats ruled Locality worse at `r
|
||||
|
||||
### 253. Group `bin/loop_claude/waiting.py`'s 29 top-level names, such as the ask's states, the answers and the /talk handshake, so each level holds about seven.
|
||||
|
||||
Found by the principles review of item 252, against the technical principles' "about seven things per level". The module held 28 names before item 252, which moved its lock into `bin/loop_claude/session_lock.py` and added `drop_ended`. A split by role is one way: the ask's file and states, the answers loop-inbox sends, and the /talk handshake, `claim_talk` and `make_way`.
|
||||
Found by the principles review of item 252, against the technical principles' "about seven things per level". A split by role is one way: the ask's file and states, the answers loop-inbox sends, and the /talk handshake, `claim_talk` and `make_way`.
|
||||
|
||||
### 235. Compare the first 20 chunks whose worker ran under the 200k compaction window with the 20 before them, on review rounds past each pass's first, unfinished verdicts, 🔴, 🟡 and misread findings, dollars and hours per chunk, and file an item where any rose.
|
||||
|
||||
`docs/decisions.md` → `loop-claude: the worker's claude compacts its context before it fills a 200k window…` expects a saving of about 6% of all spend with no rise in the other figures. Measure from loop-claude's archive as that decision did: rounds past each pass's first and the 🔴, 🟡 and misread counts from the round commit titles, unfinished verdicts from the outcomes files, hours from the worker's first message to its last, and dollars at list prices, cache reads included, from the chunk's `cost-state` entry, which counts the compaction calls that no message's usage records; the routing figures now put such dollars in. A chunk ran under the window when its first worker started after that decision merged.
|
||||
|
||||
### 254. Store when a loop asked as an ISO UTC datetime in loop-inbox's ask files, in place of seconds since the epoch.
|
||||
### 254. Store when a loop asked as an ISO UTC datetime in loop-inbox's ask files.
|
||||
|
||||
Found by the principles review of item 252, against the technical principles' rule that timestamps are ISO UTC. `Ask.asked` in `bin/loop_claude/waiting.py` is a float of seconds since the epoch, which `publish` writes to `<session>.json` and `read_ask` reads back. loop-inbox shows it as a local time and a wait, so change those readers too.
|
||||
Found by the principles review of item 252, against the technical principles' rule that timestamps are ISO UTC. `Ask.asked` in `bin/loop_claude/waiting.py` is a float of seconds since the epoch, which `publish` writes to `<session>.json` and `read_ask` reads back. loop-inbox shows it as a local time and a wait, so change the code that shows it too.
|
||||
|
||||
### 167. Refuse a `/security-review` or `/claude-security` Skill call below the project's rung, as rule-hook refuses such an Agent call.
|
||||
|
||||
|
||||
Reference in New Issue
Block a user