Answer principles round 1: 0 🔴, 5 🟡; enforce run-heavy in rule-hook, take slots through one tested function, exit 125 on lock errors, fake meminfo in black-box tests

This commit is contained in:
2026-10-23 10:55:55 +02:00
parent 6725ee4c9d
commit c7dbd56f39
14 changed files with 136 additions and 59 deletions
+4 -10
View File
@@ -1,10 +1,4 @@
"""How much of the machine's memory is available, so loop-claude starts a worker only while a quarter is.
loop-claude reads MemAvailable and MemTotal from /proc/meminfo before each worker starts. While less
than a quarter is available, it says so once on stderr and reads again each minute, so loops running
at once do not push the machine into swap. Where the file cannot be read, as off Linux, the worker
starts at once.
"""
"""How much of the machine's memory is available, as /proc/meminfo's MemAvailable and MemTotal state it, and whether that leaves room for a worker: a quarter of it."""
import dataclasses
import pathlib
import re
@@ -32,9 +26,9 @@ def parsed(meminfo: str) -> Memory | None:
return Memory(available=int(fields["MemAvailable"]), total=int(fields["MemTotal"]))
def read_memory(meminfo: pathlib.Path = MEMINFO) -> Memory | None:
"""The machine's memory; None where meminfo cannot be read, as off Linux."""
def read_memory(meminfo: pathlib.Path | None = None) -> Memory | None:
"""The machine's memory, read from meminfo or else MEMINFO; None where it cannot be read, as off Linux."""
try:
return parsed(meminfo.read_text())
return parsed((meminfo or MEMINFO).read_text())
except OSError:
return None