From b6954e5aa7b010181f1652e7d1175fddcd100cfe Mon Sep 17 00:00:00 2001 From: Lilleman auf Larv Date: Sat, 24 Oct 2026 00:13:26 +0200 Subject: [PATCH 01/18] File items 227 and 228: cap a heavy command's containers at its slot's memory share, and block a docker run without a memory limit --- todo.md | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/todo.md b/todo.md index c5133e4c..9f7ff6b6 100644 --- a/todo.md +++ b/todo.md @@ -6,7 +6,7 @@ `Bar = 0.1` -`Next ID = 227` +`Next ID = 229` ## Items @@ -16,7 +16,9 @@ | 59 | 0.4.0 | | | **Bound a run of unfinished verdicts on one chunk, so a worker and judge that disagree cannot cycle unattended without end.** | 2 | 1 | 3 | 4 | 3 | 1.4 by 6 | 6.0 | | 167 | 0.4.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.4.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 | +| 228 | 0.4.0 | | | **Block a `docker run` or `docker create` that sets no memory limit outside run-heavy, in a rule-hook rule `docker-run-memory`.** | 2 | 1 | 3 | 4 | 3 | 1.5 by 3 | 2.9 | | 225 | 0.4.0 | | | **Add the value-taking options of docker that `DOCKER_VALUED` lacks, so rule-hook's `run-heavy` rule reads their value as a value and not as the subcommand.** | 1 | 1 | 3 | 3 | 2 | 1.5 by 2 | 2.6 | +| 227 | 0.4.0 | | | **Cap the memory of each container a heavy command starts under run-heavy at its slot's share, and have stability-reviewer size a mutation run's concurrency to fit that cap.** | 3 | 2 | 3 | 6 | 5 | 1.5 by 5 | 1.9 | | 1 | 0.5.0 | | question | **Say in README → Install how the transcript archive is backed up, once bender-infra backs up ai-sandbox's data volume.** | 1 | 2 | 1 | 2 | 1 | | 0.0 | | 219 | 0.5.0 | | | **Name the project's rung `project` in `bin/judge_replay/main.py`, `bin/subagent_rung/main.py` and `bin/review_replay/main.py`, in place of `anchor`, as `bin/model_routing/ladder.py` and `bin/loop_claude` name it.** | 1 | 1 | 3 | 3 | 2 | code health by 2 | 12.0 | | 224 | 0.5.0 | | | **Split `docs/decisions.md` → `todo.md: one table of items, …`'s 420-word scoring paragraph into one paragraph per choice, and drop the sentences that tell how the goal weights changed.** | 1 | 1 | 1 | 1 | 2 | code health by 2 | 12.0 | @@ -87,10 +89,20 @@ rule-hook checks Agent calls (item 163) but no Skill calls. A worker that invoke Claude Code owns that file and writes it. `trust` reads it, changes it and writes it back, so a write that lands in between is lost. +### 228. Block a `docker run` or `docker create` that sets no memory limit outside run-heavy, in a rule-hook rule `docker-run-memory`. + +Part of the 2026-10-23 hang item 227 describes: a reviewer's probes ran in `docker run` with no `--memory`, and each grew to 2 GiB. The rule reads `-m`, `--memory` and `--memory=…`, through the launchers and docker options `bin/rule_hook/heavy_command.py` already reads. A command under run-heavy passes, as item 227 caps it there. A container a script starts, such as a project's `in_image` function, is out of the rule's sight. Test first in `bin/rule_hook/test_rule_hook.py`. + ### 225. Add the value-taking options of docker that `DOCKER_VALUED` lacks, so rule-hook's `run-heavy` rule reads their value as a value and not as the subcommand. Found by review of PR #370, against code that moved unchanged into `bin/rule_hook/heavy_command.py`. `DOCKER_VALUED` there lacks `--tlscacert`, `--tlscert` and `--tlskey`, so `docker --tlscacert ca.pem build .` is not blocked outside run-heavy, although `RULES["run-heavy"]` in `bin/rule_hook/rules.py` says a docker build is. It also lacks buildx's `--builder`, so `docker buildx --builder x build` gets through. Test first in `bin/rule_hook/test_rule_hook.py`. Also no test checks the "within two words" limit of `mutation_run`: a mutant that widens it survives mutmut; add one. +### 227. Cap the memory of each container a heavy command starts under run-heavy at its slot's share, and have stability-reviewer size a mutation run's concurrency to fit that cap. + +On 2026-10-23 ai-sandbox, with 8 CPUs and 7.6 GiB, hung in swap until a hard reset. One heavy command held its slot as the `machine load:` decision asks: adf-codec's stability reviewer ran Stryker with concurrency 4, each copy running the whole `node --test` suite, in one container that reached 4 GiB. Beside it, the same reviewer ran stress probes in `docker run` outside run-heavy, each to V8's 2 GiB heap limit. The slots cap how many heavy commands run at once, not how much memory one takes. + +run-heavy cannot place the command in a cgroup: none is delegated to the user, and dockerd starts the containers outside the command's process tree. So run-heavy puts first on the command's `PATH` a `docker` that adds `--memory` and `--memory-swap`, both at the slot's share, to each `docker run`, `docker create` and `docker container run|create` that sets neither, then runs the real docker. The share is the memory the `machine load:` decision leaves to heavy commands, three quarters of MemTotal, split evenly across the slots. A `docker compose` service, and a docker named by its full path, keep no cap. Update the `machine load:` decision, run-heavy's help and stability-reviewer's mutation step, which sizes Stryker's or mutmut's concurrency so the run fits the cap. Test first in `bin/run_heavy/test_run_heavy.py`. + ### 1. Say in README → Install how the transcript archive is backed up, once bender-infra backs up ai-sandbox's data volume. It lives under `~/.claude`, which `.gitignore` keeps from the remote, so a lost disk loses every unattended run's record. Back it up only to a destination private to me and encrypted at rest: the worker runs with permissions bypassed, so the archived tool results can hold credentials it read. From fbaa3075c432f2710cf5ad54deb65667818106df Mon Sep 17 00:00:00 2001 From: Lilleman auf Larv Date: Sat, 24 Oct 2026 00:15:44 +0200 Subject: [PATCH 02/18] Block a docker run or docker create that sets no memory limit, and read docker's TLS and buildx --builder options as taking a value --- bin/rule_hook/docker_command.py | 53 +++++++++++++++++++++++++++++++++ bin/rule_hook/heavy_command.py | 43 +++++--------------------- bin/rule_hook/rules.py | 9 +++++- bin/rule_hook/test_rule_hook.py | 16 ++++++++-- docs/decisions.md | 2 +- todo.md | 8 ++--- 6 files changed, 86 insertions(+), 45 deletions(-) create mode 100644 bin/rule_hook/docker_command.py diff --git a/bin/rule_hook/docker_command.py b/bin/rule_hook/docker_command.py new file mode 100644 index 00000000..bfdd8062 --- /dev/null +++ b/bin/rule_hook/docker_command.py @@ -0,0 +1,53 @@ +"""What a simple command asks of docker, for rule-hook's rules: its subcommand, and whether a container it starts has a memory limit.""" +import posixpath +import re + +# Launchers that run the tool named later in their words, such as uvx --with pytest mutmut run. +LAUNCHERS = frozenset({"bunx", "env", "nice", "npx", "pipx", "pnpm", "run-heavy", "time", "uvx", "yarn"}) +# The options of docker, docker buildx and docker compose that take a value, so the value is not read as a subcommand. +DOCKER_VALUED = frozenset({"--ansi", "--builder", "--config", "--context", "--env-file", "--file", "--host", "--log-level", "--parallel", "--profile", "--progress", "--project-directory", "--project-name", "--tlscacert", "--tlscert", "--tlskey", "-c", "-f", "-H", "-l", "-p"}) +# The subcommands that start a container, which takes the memory limit docker run's -m sets. +STARTS_CONTAINER = (["run"], ["create"], ["container", "run"], ["container", "create"]) +# -m4g is -m with its value attached; --memory-swap alone sets no limit. +MEMORY_LIMIT = re.compile(r"-m.*|--memory(=.*)?") + + +def tool_name(word: str) -> str: + """The tool a word names, such as mutmut for `mutmut>=3,<4` or `.venv/bin/mutmut`; empty for a word that names none, such as a file name.""" + named = re.fullmatch(r"([A-Za-z_-]+)(?:[<>=!~@].*)?", posixpath.basename(word)) + return named.group(1) if named else "" + + +def docker_arguments(words: list[str]) -> list[str] | None: + """The words after docker where the simple command runs it directly or through a launcher, as in nice -n 19 docker build .; None where it runs no docker.""" + names = [tool_name(word) for word in words] + # Past a launcher, docker may follow the launcher's own options and assignments; without one, the command itself is the tool. + reachable = names if names[:1] and names[0] in LAUNCHERS else names[:1] + return words[reachable.index("docker") + 1:] if "docker" in reachable else None + + +def docker_subcommand(words: list[str]) -> list[str]: + """The subcommand docker's words name, past its options: such as ["build"], ["compose", "run"] or ["buildx", "build"].""" + positional: list[str] = [] + skip = False + for word in words: + if skip: + skip = False + elif word.startswith("-"): + skip = word in DOCKER_VALUED + else: + positional.append(word) + if positional[0] not in ("buildx", "compose", "container") or len(positional) == 2: + break + return positional + + +def unlimited_container(words: list[str]) -> bool: + """Whether the simple command starts a container through docker run or docker create, directly or through a launcher, and sets no memory limit. + + A --memory among the container's own arguments, past its image, reads as the limit too: telling it apart needs every value-taking option of docker run. + """ + arguments = docker_arguments(words) + if arguments is None or "--help" in arguments: + return False + return docker_subcommand(arguments) in STARTS_CONTAINER and not any(MEMORY_LIMIT.fullmatch(word) for word in arguments) diff --git a/bin/rule_hook/heavy_command.py b/bin/rule_hook/heavy_command.py index 635e7c26..a8b85175 100644 --- a/bin/rule_hook/heavy_command.py +++ b/bin/rule_hook/heavy_command.py @@ -1,21 +1,10 @@ """Whether a simple command is a heavy one, for the `run-heavy` rule: a docker build, or a run of a mutation tool.""" -import posixpath -import re +from rule_hook.docker_command import LAUNCHERS, docker_arguments, docker_subcommand, tool_name -# Launchers that run the tool named later in their words, such as uvx --with pytest mutmut run. -LAUNCHERS = frozenset({"bunx", "env", "nice", "npx", "pipx", "pnpm", "time", "uvx", "yarn"}) # Each mutation tool, and the words that make its call a mutation run when one of them follows it within two words; where the set is empty, every call is one. MUTATORS = {"cargo": {"mutants"}, "infection": set(), "mutmut": {"run"}, "stryker": {"run"}} # Flags with which a tool only prints its help, version or list, so a call that carries one is light. Not -h, which docker run reads as the container's hostname. LIGHT_FLAGS = frozenset({"--help", "--list", "--version"}) -# The options of docker and docker compose that take a value, so the value is not read as a subcommand. -DOCKER_VALUED = frozenset({"--ansi", "--config", "--context", "--env-file", "--file", "--host", "--log-level", "--parallel", "--profile", "--progress", "--project-directory", "--project-name", "-c", "-f", "-H", "-l", "-p"}) - - -def tool_name(word: str) -> str: - """The tool a word names, such as mutmut for `mutmut>=3,<4` or `.venv/bin/mutmut`; empty for a word that names none, such as a file name.""" - named = re.fullmatch(r"([A-Za-z_-]+)(?:[<>=!~@].*)?", posixpath.basename(word)) - return named.group(1) if named else "" def heavy(words: list[str]) -> bool: @@ -23,31 +12,13 @@ def heavy(words: list[str]) -> bool: names = [tool_name(word) for word in words] if not names or "run-heavy" in names or LIGHT_FLAGS & set(words): return False - # Past a launcher, the tool may follow the launcher's own options and assignments, as in nice -n 19 docker build or uvx --with pytest mutmut run; without one, the command itself is the tool. - launched = names[0] in LAUNCHERS - reachable = names if launched else names[:1] - docker_at = reachable.index("docker") if "docker" in reachable else None - if docker_at is not None: - subcommand = docker_subcommand(words[docker_at + 1:]) - return subcommand in (["build"], ["buildx", "build"], ["compose", "build"]) or (subcommand[-1:] in (["run"], ["exec"]) and mutation_run(names[docker_at + 1:])) - return (launched or names[0] in MUTATORS) and mutation_run(names) + docker = docker_arguments(words) + if docker is not None: + subcommand = docker_subcommand(docker) + return subcommand in (["build"], ["buildx", "build"], ["compose", "build"]) or (subcommand[-1:] in (["run"], ["exec"]) and mutation_run(names[len(words) - len(docker):])) + # Past a launcher, the mutation tool may follow the launcher's own options, as in uvx --with pytest mutmut run. + return (names[0] in LAUNCHERS or names[0] in MUTATORS) and mutation_run(names) def mutation_run(names: list[str]) -> bool: return any(name in MUTATORS and (not MUTATORS[name] or MUTATORS[name] & set(names[i + 1:i + 3])) for i, name in enumerate(names)) - - -def docker_subcommand(words: list[str]) -> list[str]: - """The subcommand docker's words name, past its options: such as ["build"], ["compose", "run"] or ["buildx", "build"].""" - positional: list[str] = [] - skip = False - for word in words: - if skip: - skip = False - elif word.startswith("-"): - skip = word in DOCKER_VALUED - else: - positional.append(word) - if positional[0] not in ("buildx", "compose") or len(positional) == 2: - break - return positional diff --git a/bin/rule_hook/rules.py b/bin/rule_hook/rules.py index 178d00f4..cd039cd5 100644 --- a/bin/rule_hook/rules.py +++ b/bin/rule_hook/rules.py @@ -5,11 +5,12 @@ import typing from round_titles import CAP, lacks_counts, past_cap from git_command import commits +from rule_hook.docker_command import unlimited_container from rule_hook.heavy_command import heavy from review_folder import REPORTS from shell_command import Simple -RuleName = typing.Literal["action-pin", "commit-one-line", "ignorefile-sorted", "image-pin", "no-ai-attribution", "reviewer-report", "reviewer-rung", "round-cap", "round-title-counts", "run-heavy", "todo-rank-check"] +RuleName = typing.Literal["action-pin", "commit-one-line", "docker-run-memory", "ignorefile-sorted", "image-pin", "no-ai-attribution", "reviewer-report", "reviewer-rung", "round-cap", "round-title-counts", "run-heavy", "todo-rank-check"] @dataclasses.dataclass(frozen=True) @@ -29,6 +30,10 @@ RULES: dict[RuleName, Rule] = { "a commit message is one line, prefixed with the ticket ID when the work has one", "git commit takes its message as one -m with no line break; -F, a second -m and a heredoc are blocked", ), + "docker-run-memory": Rule( + "a container started with docker run or docker create has a memory limit, such as `--memory 4g --memory-swap 4g`, so one runaway container cannot starve the machine; --memory-swap equal to --memory keeps it out of swap", + "docker run, docker create, docker container run and docker container create, whether direct or through a launcher such as nice. A container a script or docker compose starts is not checked", + ), "ignorefile-sorted": Rule( "each block of an ignore file is sorted in code-point order, as LC_ALL=C sort does, since its order carries no meaning; where order matters, such as a re-include after its exclude, split the block with a blank line or a comment", "a .*ignore file; a block already unsorted before the edit is left alone", @@ -132,6 +137,8 @@ def command_breaches(command: str, simples: list[Simple], home: str) -> list[Bre for simple in simples: if heavy(simple.words): breaches.append(Breach("run-heavy", f"run `{' '.join(simple.words)[:80]}` under `~/.claude/bin/run-heavy`, in the background", simple.directory)) + if unlimited_container(simple.words): + breaches.append(Breach("docker-run-memory", f"give `{' '.join(simple.words)[:80]}` a memory limit, such as `--memory 4g --memory-swap 4g`", simple.directory)) for commit in found: if commit.from_file: breaches.append(Breach("commit-one-line", "pass the message as one -m '', not from a file", commit.directory)) diff --git a/bin/rule_hook/test_rule_hook.py b/bin/rule_hook/test_rule_hook.py index 8925758c..850dd441 100644 --- a/bin/rule_hook/test_rule_hook.py +++ b/bin/rule_hook/test_rule_hook.py @@ -107,12 +107,22 @@ class CommandBreaches(unittest.TestCase): self.assertEqual(checked("git commit -m 'Answer the question in the README'"), []) def test_a_docker_build_or_a_mutation_run_outside_run_heavy_breaks_run_heavy(self): - for command in ["docker build -t x .", "cd /w && docker buildx build .", "docker compose build", "docker compose -f x.yml --verbose build app", "uvx --with pytest 'mutmut>=3,<4' run", "cargo mutants --in-diff d", "npx stryker run", "vendor/bin/infection --git-diff-lines", "docker compose run --rm app mutmut run", "docker run --rm -v /w:/w rust:1.90.0 cargo mutants", "docker compose exec app npx stryker run", "docker run -h box rust:1.90.0 cargo mutants", "nice -n 19 docker build .", "env DOCKER_BUILDKIT=1 docker build .", "time -p docker compose build"]: + for command in ["docker build -t x .", "cd /w && docker buildx build .", "docker compose build", "docker compose -f x.yml --verbose build app", "uvx --with pytest 'mutmut>=3,<4' run", "cargo mutants --in-diff d", "npx stryker run", "vendor/bin/infection --git-diff-lines", "docker compose run --rm app mutmut run", "docker run --rm -m 4g -v /w:/w rust:1.90.0 cargo mutants", "docker compose exec app npx stryker run", "docker run -h box -m 4g rust:1.90.0 cargo mutants", "nice -n 19 docker build .", "env DOCKER_BUILDKIT=1 docker build .", "time -p docker compose build", "docker --tlscacert ca.pem build .", "docker --tlscert c.pem --tlskey k.pem build .", "docker buildx --builder b build .", "docker container run -m 4g rust:1.90.0 cargo mutants", "uvx mutmut --verbose run"]: with self.subTest(command): self.assertEqual(checked(command), ["run-heavy"]) def test_a_heavy_command_under_run_heavy_or_a_light_docker_or_mutmut_call_passes(self): - for command in ["~/.claude/bin/run-heavy docker build -t x .", "/home/me/.claude/bin/run-heavy uvx mutmut run", "nice -n 19 ~/.claude/bin/run-heavy docker build .", "env X=1 run-heavy docker compose run app mutmut run", "docker images", "docker compose run --rm app go vet", "docker compose run app make build", "uvx 'mutmut>=3,<4' results", "echo docker build", "npx prettier --check infection.json5", "echo mutmut run", "env", "docker build --help", "cargo mutants --list", "infection --version"]: + for command in ["~/.claude/bin/run-heavy docker build -t x .", "/home/me/.claude/bin/run-heavy uvx mutmut run", "nice -n 19 ~/.claude/bin/run-heavy docker build .", "env X=1 run-heavy docker compose run app mutmut run", "docker images", "docker compose run --rm app go vet", "docker compose run app make build", "uvx 'mutmut>=3,<4' results", "echo docker build", "npx prettier --check infection.json5", "echo mutmut run", "env", "docker build --help", "cargo mutants --list", "infection --version", "uvx mutmut a b run"]: + with self.subTest(command): + self.assertEqual(checked(command), []) + + def test_a_docker_run_or_create_without_a_memory_limit_breaks_docker_run_memory(self): + for command in ["docker run --rm node:24.22.1-alpine3.24 node x.js", "cd /w && docker run -v /w:/w alpine:3.22.2 true", "docker create alpine:3.22.2", "docker container run alpine:3.22.2 true", "docker container create alpine:3.22.2", "nice -n 19 docker run alpine:3.22.2 true", "docker -H unix:///d.sock run alpine:3.22.2 true", "docker run --memory-swap 4g alpine:3.22.2 true", "~/.claude/bin/run-heavy docker run alpine:3.22.2 true"]: + with self.subTest(command): + self.assertEqual(checked(command), ["docker-run-memory"]) + + def test_a_docker_run_with_a_memory_limit_or_another_docker_call_passes_docker_run_memory(self): + for command in ["docker run -m 4g alpine:3.22.2 true", "docker run -m4g alpine:3.22.2 true", "docker run --memory 4g alpine:3.22.2 true", "docker run --rm --memory=4g --memory-swap=4g alpine:3.22.2 true", "docker container create -m 1g alpine:3.22.2", "docker run --help", "docker ps", "docker images", "docker container ls", "docker compose run --rm app go vet", "docker exec box true", "echo docker run alpine:3.22.2"]: with self.subTest(command): self.assertEqual(checked(command), []) @@ -467,7 +477,7 @@ class Hook(unittest.TestCase): def test_help_lists_every_rule(self): helped = subprocess.run([str(HOOK), "--help"], capture_output=True, check=True, env=isolated_env(), text=True).stdout - for rule in ["action-pin", "commit-one-line", "ignorefile-sorted", "image-pin", "no-ai-attribution", "reviewer-report", "reviewer-rung", "round-cap", "round-title-counts", "run-heavy", "todo-rank-check"]: + for rule in ["action-pin", "commit-one-line", "docker-run-memory", "ignorefile-sorted", "image-pin", "no-ai-attribution", "reviewer-report", "reviewer-rung", "round-cap", "round-title-counts", "run-heavy", "todo-rank-check"]: self.assertIn(f" {rule}\n The rule: ", helped) self.assertIn("reviewer-report\n The rule: a reviewer writes nothing but its report", helped) self.assertRegex(helped, r" reviewer-report\n( .*\n){2} Takes no override\.\n") diff --git a/docs/decisions.md b/docs/decisions.md index 290f7dde..848847a4 100644 --- a/docs/decisions.md +++ b/docs/decisions.md @@ -74,7 +74,7 @@ The cap is 5, `bin/todo_table.py`'s `BUNDLE_MAX_R`, from the same chunks: by the ## machine load: a heavy command waits for one of the machine's heavy slots, one for every 4 CPUs, which every session shares, and loop-claude starts a worker only while at least a quarter of the machine's memory is available -2026-10-23, lilleman. Serves goal 1.5. On 2026-10-22 ai-sandbox, with 8 CPUs and 16 GiB, thrashed for hours: four to six loops ran mutation tests, full gates, `docker build`s and QEMU-booting e2e tests at once, and nothing told one loop how busy the machine was. lilleman chose both limits; no standard sets either, and GNU parallel's `--memfree`, which does the memory wait's job, has no default. A slot is a file lock, so a session that dies frees its slot. The memory wait reads `/proc/meminfo` only, and off Linux a worker starts at once. `bin/machine_load/` holds the slots and the memory share, `bin/run-heavy` takes a slot, `CLAUDE.md` → "Working with the codebase" has every session use it, and loop-claude's worker waits for the share. rule-hook's rule `run-heavy` blocks a `docker build`, and a run of a mutation tool stability-reviewer names, outside run-heavy, whether direct or inside a container. No program can tell a gate script from a light one, so only `CLAUDE.md` asks a session to run a gate under run-heavy. Valid while one machine runs several loops at once. +2026-10-23, lilleman. Serves goal 1.5. On 2026-10-22 ai-sandbox, with 8 CPUs and 16 GiB, thrashed for hours: four to six loops ran mutation tests, full gates, `docker build`s and QEMU-booting e2e tests at once, and nothing told one loop how busy the machine was. lilleman chose both limits; no standard sets either, and GNU parallel's `--memfree`, which does the memory wait's job, has no default. A slot is a file lock, so a session that dies frees its slot. The memory wait reads `/proc/meminfo` only, and off Linux a worker starts at once. `bin/machine_load/` holds the slots and the memory share, `bin/run-heavy` takes a slot, `CLAUDE.md` → "Working with the codebase" has every session use it, and loop-claude's worker waits for the share. rule-hook's rule `run-heavy` blocks a `docker build`, and a run of a mutation tool stability-reviewer names, outside run-heavy, whether direct or inside a container. No program can tell a gate script from a light one, so only `CLAUDE.md` asks a session to run a gate under run-heavy. On 2026-10-23 a slot alone did not stop a hang: a reviewer's stress probes ran in `docker run` with no memory limit, each to 2 GiB, beside a mutation run in its slot. So rule-hook's rule `docker-run-memory` blocks a `docker run` or `docker create` a session types without `--memory` (todo item 228); a container a script starts is out of its sight. Valid while one machine runs several loops at once. ## principles: about seven things per level, four or five where they act on each other, more where a reader finds them by name; crossing a limit asks for a grouping or a recorded reason diff --git a/todo.md b/todo.md index 9f7ff6b6..cc6f6dc0 100644 --- a/todo.md +++ b/todo.md @@ -16,7 +16,7 @@ | 59 | 0.4.0 | | | **Bound a run of unfinished verdicts on one chunk, so a worker and judge that disagree cannot cycle unattended without end.** | 2 | 1 | 3 | 4 | 3 | 1.4 by 6 | 6.0 | | 167 | 0.4.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.4.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 | -| 228 | 0.4.0 | | | **Block a `docker run` or `docker create` that sets no memory limit outside run-heavy, in a rule-hook rule `docker-run-memory`.** | 2 | 1 | 3 | 4 | 3 | 1.5 by 3 | 2.9 | +| 228 | 0.4.0 | | | **Block a `docker run` or `docker create` that sets no memory limit, in a rule-hook rule `docker-run-memory`.** | 2 | 1 | 3 | 4 | 3 | 1.5 by 3 | 2.9 | | 225 | 0.4.0 | | | **Add the value-taking options of docker that `DOCKER_VALUED` lacks, so rule-hook's `run-heavy` rule reads their value as a value and not as the subcommand.** | 1 | 1 | 3 | 3 | 2 | 1.5 by 2 | 2.6 | | 227 | 0.4.0 | | | **Cap the memory of each container a heavy command starts under run-heavy at its slot's share, and have stability-reviewer size a mutation run's concurrency to fit that cap.** | 3 | 2 | 3 | 6 | 5 | 1.5 by 5 | 1.9 | | 1 | 0.5.0 | | question | **Say in README → Install how the transcript archive is backed up, once bender-infra backs up ai-sandbox's data volume.** | 1 | 2 | 1 | 2 | 1 | | 0.0 | @@ -89,9 +89,9 @@ rule-hook checks Agent calls (item 163) but no Skill calls. A worker that invoke Claude Code owns that file and writes it. `trust` reads it, changes it and writes it back, so a write that lands in between is lost. -### 228. Block a `docker run` or `docker create` that sets no memory limit outside run-heavy, in a rule-hook rule `docker-run-memory`. +### 228. Block a `docker run` or `docker create` that sets no memory limit, in a rule-hook rule `docker-run-memory`. -Part of the 2026-10-23 hang item 227 describes: a reviewer's probes ran in `docker run` with no `--memory`, and each grew to 2 GiB. The rule reads `-m`, `--memory` and `--memory=…`, through the launchers and docker options `bin/rule_hook/heavy_command.py` already reads. A command under run-heavy passes, as item 227 caps it there. A container a script starts, such as a project's `in_image` function, is out of the rule's sight. Test first in `bin/rule_hook/test_rule_hook.py`. +Part of the 2026-10-23 hang item 227 describes: a reviewer's probes ran in `docker run` with no `--memory`, and each grew to 2 GiB. The rule reads `-m`, `--memory` and `--memory=…`, through the launchers and docker options `bin/rule_hook/heavy_command.py` already reads. A container a script starts, such as a project's `in_image` function, is out of the rule's sight. Test first in `bin/rule_hook/test_rule_hook.py`. ### 225. Add the value-taking options of docker that `DOCKER_VALUED` lacks, so rule-hook's `run-heavy` rule reads their value as a value and not as the subcommand. @@ -101,7 +101,7 @@ Found by review of PR #370, against code that moved unchanged into `bin/rule_hoo On 2026-10-23 ai-sandbox, with 8 CPUs and 7.6 GiB, hung in swap until a hard reset. One heavy command held its slot as the `machine load:` decision asks: adf-codec's stability reviewer ran Stryker with concurrency 4, each copy running the whole `node --test` suite, in one container that reached 4 GiB. Beside it, the same reviewer ran stress probes in `docker run` outside run-heavy, each to V8's 2 GiB heap limit. The slots cap how many heavy commands run at once, not how much memory one takes. -run-heavy cannot place the command in a cgroup: none is delegated to the user, and dockerd starts the containers outside the command's process tree. So run-heavy puts first on the command's `PATH` a `docker` that adds `--memory` and `--memory-swap`, both at the slot's share, to each `docker run`, `docker create` and `docker container run|create` that sets neither, then runs the real docker. The share is the memory the `machine load:` decision leaves to heavy commands, three quarters of MemTotal, split evenly across the slots. A `docker compose` service, and a docker named by its full path, keep no cap. Update the `machine load:` decision, run-heavy's help and stability-reviewer's mutation step, which sizes Stryker's or mutmut's concurrency so the run fits the cap. Test first in `bin/run_heavy/test_run_heavy.py`. +run-heavy cannot place the command in a cgroup: none is delegated to the user, and dockerd starts the containers outside the command's process tree. So run-heavy puts first on the command's `PATH` a `docker` that adds `--memory` and `--memory-swap`, both at the slot's share, to each `docker run`, `docker create` and `docker container run|create` that sets neither, then runs the real docker. The share is the memory the `machine load:` decision leaves to heavy commands, three quarters of MemTotal, split evenly across the slots. A `docker compose` service, and a docker named by its full path, keep no cap. Update the `machine load:` decision, run-heavy's help and stability-reviewer's mutation step, which sizes Stryker's or mutmut's concurrency so the run fits the cap. Once run-heavy caps them, let rule-hook's `docker-run-memory` pass a `docker run` under run-heavy. Test first in `bin/run_heavy/test_run_heavy.py`. ### 1. Say in README → Install how the transcript archive is backed up, once bender-infra backs up ai-sandbox's data volume. From b6d8fe48afea1d7dc7fe8f53d90e71db2f2e62b2 Mon Sep 17 00:00:00 2001 From: Lilleman auf Larv Date: Sat, 24 Oct 2026 00:16:05 +0200 Subject: [PATCH 03/18] Record the reading cost of the chunks before item 228, and refresh item 155 with its rise --- docs/reading-cost.md | 4 ++++ todo.md | 2 +- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/docs/reading-cost.md b/docs/reading-cost.md index 2fe1084a..7b7d9a1e 100644 --- a/docs/reading-cost.md +++ b/docs/reading-cost.md @@ -863,3 +863,7 @@ Read most (opens and searches): Read most (opens and searches): - `rules/decisions.md` 1 + +## Reading cost, chunk e94dd7a98ff8, finished 2026-10-23T12:59:22Z + +71809 new input tokens before the first commit. diff --git a/todo.md b/todo.md index cc6f6dc0..5e5c0927 100644 --- a/todo.md +++ b/todo.md @@ -323,7 +323,7 @@ The key names the project's session, archive folder and models entry. `project_k ### 155. Lower the reading cost of the files a chunk reads most before its first commit. -`bin/reading-cost` on 2026-10-22: the median of the last 5 chunks is 100,386 new input tokens before their first commit, up from 73,910 for the 5 before them. The files read most over the last 5 were `skills/larv-review/SKILL.md`, 3 times, and `rules/todo-items.md`, 2 times. The chunk that ships this item runs `bin/reading-cost --reset`. +`bin/reading-cost` on 2026-10-24: the median of the last 5 chunks is 125,323 new input tokens before their first commit, up from 123,377 for the 5 before them. The files read most over the last 5 were `bin/score_outcomes/main.py`, 3 times, then `bin/score_outcomes/outcomes.py`, `docs/decisions.md`, `rules/todo-items.md` and `skills/larv-review/SKILL.md`, 2 times each. The chunk that ships this item runs `bin/reading-cost --reset`. ### 51. Hand loop-claude's terminal output to an injected effect, so no storage or retry function prints. From 7b61fd5b4b7b48dd913d6cbe2f030d57d885aa80 Mon Sep 17 00:00:00 2001 From: Lilleman auf Larv Date: Sat, 24 Oct 2026 00:18:50 +0200 Subject: [PATCH 04/18] Sort rule_hook's imports by their first binding --- bin/rule_hook/heavy_command.py | 2 +- bin/rule_hook/rules.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/bin/rule_hook/heavy_command.py b/bin/rule_hook/heavy_command.py index a8b85175..1c816465 100644 --- a/bin/rule_hook/heavy_command.py +++ b/bin/rule_hook/heavy_command.py @@ -1,5 +1,5 @@ """Whether a simple command is a heavy one, for the `run-heavy` rule: a docker build, or a run of a mutation tool.""" -from rule_hook.docker_command import LAUNCHERS, docker_arguments, docker_subcommand, tool_name +from rule_hook.docker_command import docker_arguments, docker_subcommand, LAUNCHERS, tool_name # Each mutation tool, and the words that make its call a mutation run when one of them follows it within two words; where the set is empty, every call is one. MUTATORS = {"cargo": {"mutants"}, "infection": set(), "mutmut": {"run"}, "stryker": {"run"}} diff --git a/bin/rule_hook/rules.py b/bin/rule_hook/rules.py index cd039cd5..7ecfc6ce 100644 --- a/bin/rule_hook/rules.py +++ b/bin/rule_hook/rules.py @@ -5,10 +5,10 @@ import typing from round_titles import CAP, lacks_counts, past_cap from git_command import commits -from rule_hook.docker_command import unlimited_container from rule_hook.heavy_command import heavy from review_folder import REPORTS from shell_command import Simple +from rule_hook.docker_command import unlimited_container RuleName = typing.Literal["action-pin", "commit-one-line", "docker-run-memory", "ignorefile-sorted", "image-pin", "no-ai-attribution", "reviewer-report", "reviewer-rung", "round-cap", "round-title-counts", "run-heavy", "todo-rank-check"] From a292ec4cae05d56a53e68f2cf734ff51869b7195 Mon Sep 17 00:00:00 2001 From: Lilleman auf Larv Date: Sat, 24 Oct 2026 00:31:41 +0200 Subject: [PATCH 05/18] =?UTF-8?q?Answer=20architecture=20round=201:=200=20?= =?UTF-8?q?=F0=9F=94=B4,=203=20=F0=9F=9F=A1=20(0=20misread);=20move=20dock?= =?UTF-8?q?er's=20parsing=20to=20bin/=20for=20item=20227's=20shim,=20read?= =?UTF-8?q?=20launchers=20once=20in=20shell=5Fcommand.launched,=20and=20gi?= =?UTF-8?q?ve=20the=20memory=20limit=20its=20own=20decision,=20sized=20to?= =?UTF-8?q?=20what=20the=20work=20needs?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .gitignore | 1 + AGENTS.md | 1 + bin/docker_command.py | 41 +++++++++++++++++++++++++ bin/rule_hook/docker_command.py | 53 --------------------------------- bin/rule_hook/heavy_command.py | 18 +++++------ bin/rule_hook/rules.py | 6 ++-- bin/shell_command.py | 28 +++++++++++++++++ docs/decisions.md | 6 +++- todo.md | 2 +- 9 files changed, 89 insertions(+), 67 deletions(-) create mode 100644 bin/docker_command.py delete mode 100644 bin/rule_hook/docker_command.py diff --git a/.gitignore b/.gitignore index 2bcf7f05..45938304 100644 --- a/.gitignore +++ b/.gitignore @@ -25,6 +25,7 @@ !bin/claude_code/ !bin/claude_code/*.py !bin/comprehension_history.py +!bin/docker_command.py !bin/failure.py !bin/file_writes.py !bin/git_command.py diff --git a/AGENTS.md b/AGENTS.md index 534811e5..cdfa1df2 100644 --- a/AGENTS.md +++ b/AGENTS.md @@ -16,6 +16,7 @@ Decisions live in `docs/decisions.md`: - loop-claude: one session per project, its id derived from the checkout's path relative to `~/code`, or to `/` outside it - loop-claude: the archive keeps the raw transcript, and a failed archive stops the loop - machine load: a heavy command waits for one of the machine's heavy slots, one for every 4 CPUs, which every session shares, and loop-claude starts a worker only while at least a quarter of the machine's memory is available +- machine load: every container a session starts with `docker run` or `docker create` sets a memory limit as large as its work needs, which rule-hook's `docker-run-memory` enforces, and no daemon-wide cap limits all containers together - principles: about seven things per level, four or five where they act on each other, more where a reader finds them by name; crossing a limit asks for a grouping or a recorded reason - reading cost and `score-outcomes`: each waits for 10 finished chunks before it shows a median - reading cost: a rise is the last 5 chunks' median above the 5 before them, and files or refreshes one plan item diff --git a/bin/docker_command.py b/bin/docker_command.py new file mode 100644 index 00000000..eb2004dc --- /dev/null +++ b/bin/docker_command.py @@ -0,0 +1,41 @@ +"""What a docker command asks of docker: its subcommand, and whether a container it starts has a memory limit.""" +import re + +from shell_command import launched + +# The options of docker, docker buildx and docker compose that take a value, so the value is not read as a subcommand. +DOCKER_VALUED = frozenset({"--ansi", "--builder", "--config", "--context", "--env-file", "--file", "--host", "--log-level", "--parallel", "--profile", "--progress", "--project-directory", "--project-name", "--tlscacert", "--tlscert", "--tlskey", "-c", "-f", "-H", "-l", "-p"}) +# The subcommands that start a container, which takes the memory limit docker run's -m sets. +STARTS_CONTAINER = (["run"], ["create"], ["container", "run"], ["container", "create"]) +# -m4g is -m with its value attached; --memory-swap alone sets no limit. +MEMORY_LIMIT = re.compile(r"-m.*|--memory(=.*)?") + + +def docker_subcommand(arguments: list[str]) -> list[str]: + """The subcommand docker's arguments name, past its options: such as ["build"], ["compose", "run"] or ["buildx", "build"].""" + positional: list[str] = [] + skip = False + for word in arguments: + if skip: + skip = False + elif word.startswith("-"): + skip = word in DOCKER_VALUED + else: + positional.append(word) + if positional[0] not in ("buildx", "compose", "container") or len(positional) == 2: + break + return positional + + +def unlimited(arguments: list[str]) -> bool: + """Whether docker's arguments start a container, with docker run or docker create, and set it no memory limit. + + A --memory among the container's own arguments, past its image, reads as the limit too: telling it apart needs every value-taking option of docker run. + """ + return "--help" not in arguments and docker_subcommand(arguments) in STARTS_CONTAINER and not any(MEMORY_LIMIT.fullmatch(word) for word in arguments) + + +def unlimited_container(words: list[str]) -> bool: + """Whether the simple command, directly or through a launcher, starts a container that has no memory limit.""" + docker = launched(words, {"docker"}) + return docker is not None and unlimited(docker.arguments) diff --git a/bin/rule_hook/docker_command.py b/bin/rule_hook/docker_command.py deleted file mode 100644 index bfdd8062..00000000 --- a/bin/rule_hook/docker_command.py +++ /dev/null @@ -1,53 +0,0 @@ -"""What a simple command asks of docker, for rule-hook's rules: its subcommand, and whether a container it starts has a memory limit.""" -import posixpath -import re - -# Launchers that run the tool named later in their words, such as uvx --with pytest mutmut run. -LAUNCHERS = frozenset({"bunx", "env", "nice", "npx", "pipx", "pnpm", "run-heavy", "time", "uvx", "yarn"}) -# The options of docker, docker buildx and docker compose that take a value, so the value is not read as a subcommand. -DOCKER_VALUED = frozenset({"--ansi", "--builder", "--config", "--context", "--env-file", "--file", "--host", "--log-level", "--parallel", "--profile", "--progress", "--project-directory", "--project-name", "--tlscacert", "--tlscert", "--tlskey", "-c", "-f", "-H", "-l", "-p"}) -# The subcommands that start a container, which takes the memory limit docker run's -m sets. -STARTS_CONTAINER = (["run"], ["create"], ["container", "run"], ["container", "create"]) -# -m4g is -m with its value attached; --memory-swap alone sets no limit. -MEMORY_LIMIT = re.compile(r"-m.*|--memory(=.*)?") - - -def tool_name(word: str) -> str: - """The tool a word names, such as mutmut for `mutmut>=3,<4` or `.venv/bin/mutmut`; empty for a word that names none, such as a file name.""" - named = re.fullmatch(r"([A-Za-z_-]+)(?:[<>=!~@].*)?", posixpath.basename(word)) - return named.group(1) if named else "" - - -def docker_arguments(words: list[str]) -> list[str] | None: - """The words after docker where the simple command runs it directly or through a launcher, as in nice -n 19 docker build .; None where it runs no docker.""" - names = [tool_name(word) for word in words] - # Past a launcher, docker may follow the launcher's own options and assignments; without one, the command itself is the tool. - reachable = names if names[:1] and names[0] in LAUNCHERS else names[:1] - return words[reachable.index("docker") + 1:] if "docker" in reachable else None - - -def docker_subcommand(words: list[str]) -> list[str]: - """The subcommand docker's words name, past its options: such as ["build"], ["compose", "run"] or ["buildx", "build"].""" - positional: list[str] = [] - skip = False - for word in words: - if skip: - skip = False - elif word.startswith("-"): - skip = word in DOCKER_VALUED - else: - positional.append(word) - if positional[0] not in ("buildx", "compose", "container") or len(positional) == 2: - break - return positional - - -def unlimited_container(words: list[str]) -> bool: - """Whether the simple command starts a container through docker run or docker create, directly or through a launcher, and sets no memory limit. - - A --memory among the container's own arguments, past its image, reads as the limit too: telling it apart needs every value-taking option of docker run. - """ - arguments = docker_arguments(words) - if arguments is None or "--help" in arguments: - return False - return docker_subcommand(arguments) in STARTS_CONTAINER and not any(MEMORY_LIMIT.fullmatch(word) for word in arguments) diff --git a/bin/rule_hook/heavy_command.py b/bin/rule_hook/heavy_command.py index 1c816465..106b61a7 100644 --- a/bin/rule_hook/heavy_command.py +++ b/bin/rule_hook/heavy_command.py @@ -1,23 +1,23 @@ """Whether a simple command is a heavy one, for the `run-heavy` rule: a docker build, or a run of a mutation tool.""" -from rule_hook.docker_command import docker_arguments, docker_subcommand, LAUNCHERS, tool_name +from docker_command import docker_subcommand +from shell_command import launched, tool_name # Each mutation tool, and the words that make its call a mutation run when one of them follows it within two words; where the set is empty, every call is one. MUTATORS = {"cargo": {"mutants"}, "infection": set(), "mutmut": {"run"}, "stryker": {"run"}} # Flags with which a tool only prints its help, version or list, so a call that carries one is light. Not -h, which docker run reads as the container's hostname. LIGHT_FLAGS = frozenset({"--help", "--list", "--version"}) +BUILDS = (["build"], ["buildx", "build"], ["compose", "build"]) def heavy(words: list[str]) -> bool: """Whether the simple command, run directly or through a launcher, is a docker build or a mutation run, or runs one in a container, and is not under run-heavy.""" - names = [tool_name(word) for word in words] - if not names or "run-heavy" in names or LIGHT_FLAGS & set(words): + launch = launched(words, {"docker", *MUTATORS}) + if launch is None or "run-heavy" in launch.launchers or LIGHT_FLAGS & set(words): return False - docker = docker_arguments(words) - if docker is not None: - subcommand = docker_subcommand(docker) - return subcommand in (["build"], ["buildx", "build"], ["compose", "build"]) or (subcommand[-1:] in (["run"], ["exec"]) and mutation_run(names[len(words) - len(docker):])) - # Past a launcher, the mutation tool may follow the launcher's own options, as in uvx --with pytest mutmut run. - return (names[0] in LAUNCHERS or names[0] in MUTATORS) and mutation_run(names) + if launch.tool == "docker": + subcommand = docker_subcommand(launch.arguments) + return subcommand in BUILDS or (subcommand[-1:] in (["run"], ["exec"]) and mutation_run([tool_name(word) for word in launch.arguments])) + return mutation_run([launch.tool, *(tool_name(word) for word in launch.arguments)]) def mutation_run(names: list[str]) -> bool: diff --git a/bin/rule_hook/rules.py b/bin/rule_hook/rules.py index 7ecfc6ce..864b6e04 100644 --- a/bin/rule_hook/rules.py +++ b/bin/rule_hook/rules.py @@ -8,7 +8,7 @@ from git_command import commits from rule_hook.heavy_command import heavy from review_folder import REPORTS from shell_command import Simple -from rule_hook.docker_command import unlimited_container +from docker_command import unlimited_container RuleName = typing.Literal["action-pin", "commit-one-line", "docker-run-memory", "ignorefile-sorted", "image-pin", "no-ai-attribution", "reviewer-report", "reviewer-rung", "round-cap", "round-title-counts", "run-heavy", "todo-rank-check"] @@ -31,7 +31,7 @@ RULES: dict[RuleName, Rule] = { "git commit takes its message as one -m with no line break; -F, a second -m and a heredoc are blocked", ), "docker-run-memory": Rule( - "a container started with docker run or docker create has a memory limit, such as `--memory 4g --memory-swap 4g`, so one runaway container cannot starve the machine; --memory-swap equal to --memory keeps it out of swap", + "a container started with docker run or docker create has a memory limit, as large as its work needs, such as `--memory 4g --memory-swap 4g`, so one runaway container cannot starve the machine; --memory-swap equal to --memory keeps it out of swap", "docker run, docker create, docker container run and docker container create, whether direct or through a launcher such as nice. A container a script or docker compose starts is not checked", ), "ignorefile-sorted": Rule( @@ -138,7 +138,7 @@ def command_breaches(command: str, simples: list[Simple], home: str) -> list[Bre if heavy(simple.words): breaches.append(Breach("run-heavy", f"run `{' '.join(simple.words)[:80]}` under `~/.claude/bin/run-heavy`, in the background", simple.directory)) if unlimited_container(simple.words): - breaches.append(Breach("docker-run-memory", f"give `{' '.join(simple.words)[:80]}` a memory limit, such as `--memory 4g --memory-swap 4g`", simple.directory)) + breaches.append(Breach("docker-run-memory", f"give `{' '.join(simple.words)[:80]}` a memory limit as large as its work needs, such as `--memory 4g --memory-swap 4g`", simple.directory)) for commit in found: if commit.from_file: breaches.append(Breach("commit-one-line", "pass the message as one -m '', not from a file", commit.directory)) diff --git a/bin/shell_command.py b/bin/shell_command.py index 294bd554..38b2f562 100644 --- a/bin/shell_command.py +++ b/bin/shell_command.py @@ -3,7 +3,10 @@ import dataclasses import posixpath import re import shlex +import typing +# Launchers that run the tool named later in their words, such as uvx --with pytest mutmut run. +LAUNCHERS = frozenset({"bunx", "env", "nice", "npx", "pipx", "pnpm", "run-heavy", "time", "uvx", "yarn"}) HEREDOC = re.compile(r"<<-?[ \t]*([\"']?)([A-Za-z_]\w*)\1[^\n]*\n.*?^[ \t]*\2[ \t]*$", re.DOTALL | re.MULTILINE) ASSIGNMENT = re.compile(r"[A-Za-z_][A-Za-z0-9_]*=") OPERATOR = set("\n();&|<>") @@ -13,6 +16,14 @@ REDIRECT = re.compile(r"&>>?|[<>]+[&|]?") PIECE = re.compile(r"""'[^']*'|"(?:\\.|[^"\\])*"|\\.|(? str: def resolved(base: str, path: str, home: str) -> str: return posixpath.normpath(posixpath.join(base, home + path[1:] if path == "~" or path.startswith("~/") else path)) + + +def tool_name(word: str) -> str: + """The tool a word names, such as mutmut for `mutmut>=3,<4` or `.venv/bin/mutmut`; empty for a word that names none, such as a file name.""" + named = re.fullmatch(r"([A-Za-z_-]+)(?:[<>=!~@].*)?", posixpath.basename(word)) + return named.group(1) if named else "" + + +def launched(words: list[str], tools: typing.Collection[str]) -> Launch | None: + """The first of tools that the simple command runs, directly or through launchers; None where it runs none of them.""" + names = [tool_name(word) for word in words] + # Past a launcher, the tool may follow the launcher's own options and assignments, as in nice -n 19 docker build; without one, the command itself is the tool. + reachable = names if names[:1] and names[0] in LAUNCHERS else names[:1] + at = next((i for i, name in enumerate(reachable) if name in tools), None) + if at is None: + return None + return Launch(frozenset(LAUNCHERS.intersection(names[:at])), names[at], words[at + 1:]) diff --git a/docs/decisions.md b/docs/decisions.md index 848847a4..bcf2a971 100644 --- a/docs/decisions.md +++ b/docs/decisions.md @@ -74,7 +74,11 @@ The cap is 5, `bin/todo_table.py`'s `BUNDLE_MAX_R`, from the same chunks: by the ## machine load: a heavy command waits for one of the machine's heavy slots, one for every 4 CPUs, which every session shares, and loop-claude starts a worker only while at least a quarter of the machine's memory is available -2026-10-23, lilleman. Serves goal 1.5. On 2026-10-22 ai-sandbox, with 8 CPUs and 16 GiB, thrashed for hours: four to six loops ran mutation tests, full gates, `docker build`s and QEMU-booting e2e tests at once, and nothing told one loop how busy the machine was. lilleman chose both limits; no standard sets either, and GNU parallel's `--memfree`, which does the memory wait's job, has no default. A slot is a file lock, so a session that dies frees its slot. The memory wait reads `/proc/meminfo` only, and off Linux a worker starts at once. `bin/machine_load/` holds the slots and the memory share, `bin/run-heavy` takes a slot, `CLAUDE.md` → "Working with the codebase" has every session use it, and loop-claude's worker waits for the share. rule-hook's rule `run-heavy` blocks a `docker build`, and a run of a mutation tool stability-reviewer names, outside run-heavy, whether direct or inside a container. No program can tell a gate script from a light one, so only `CLAUDE.md` asks a session to run a gate under run-heavy. On 2026-10-23 a slot alone did not stop a hang: a reviewer's stress probes ran in `docker run` with no memory limit, each to 2 GiB, beside a mutation run in its slot. So rule-hook's rule `docker-run-memory` blocks a `docker run` or `docker create` a session types without `--memory` (todo item 228); a container a script starts is out of its sight. Valid while one machine runs several loops at once. +2026-10-23, lilleman. Serves goal 1.5. On 2026-10-22 ai-sandbox, with 8 CPUs and 16 GiB, thrashed for hours: four to six loops ran mutation tests, full gates, `docker build`s and QEMU-booting e2e tests at once, and nothing told one loop how busy the machine was. lilleman chose both limits; no standard sets either, and GNU parallel's `--memfree`, which does the memory wait's job, has no default. A slot is a file lock, so a session that dies frees its slot. The memory wait reads `/proc/meminfo` only, and off Linux a worker starts at once. `bin/machine_load/` holds the slots and the memory share, `bin/run-heavy` takes a slot, `CLAUDE.md` → "Working with the codebase" has every session use it, and loop-claude's worker waits for the share. rule-hook's rule `run-heavy` blocks a `docker build`, and a run of a mutation tool stability-reviewer names, outside run-heavy, whether direct or inside a container. No program can tell a gate script from a light one, so only `CLAUDE.md` asks a session to run a gate under run-heavy. Valid while one machine runs several loops at once. + +## machine load: every container a session starts with `docker run` or `docker create` sets a memory limit as large as its work needs, which rule-hook's `docker-run-memory` enforces, and no daemon-wide cap limits all containers together + +2026-10-24, lilleman. Serves goal 1.5. On 2026-10-23 ai-sandbox, with 8 CPUs and 7.6 GiB, hung until a hard reset, although its one heavy command held a slot: beside that mutation run, a reviewer's stress probes ran in `docker run` with no memory limit, each to 2 GiB. A limit makes a runaway container fail alone instead of taking the machine with it. The session sizes the limit, since lilleman wants a project to run heavier work where it needs to. rule-hook's rule reads only the commands a session types (todo item 228): a container a script or docker compose starts is out of its sight. lilleman turned down a daemon-wide cap, a dockerd `cgroup-parent` with a memory limit, which would see every container, on 2026-10-24: it is host config, and it would cap a project's heavy work too. Valid while sessions start their work in containers on a machine they share. ## principles: about seven things per level, four or five where they act on each other, more where a reader finds them by name; crossing a limit asks for a grouping or a recorded reason diff --git a/todo.md b/todo.md index 5e5c0927..655087f9 100644 --- a/todo.md +++ b/todo.md @@ -101,7 +101,7 @@ Found by review of PR #370, against code that moved unchanged into `bin/rule_hoo On 2026-10-23 ai-sandbox, with 8 CPUs and 7.6 GiB, hung in swap until a hard reset. One heavy command held its slot as the `machine load:` decision asks: adf-codec's stability reviewer ran Stryker with concurrency 4, each copy running the whole `node --test` suite, in one container that reached 4 GiB. Beside it, the same reviewer ran stress probes in `docker run` outside run-heavy, each to V8's 2 GiB heap limit. The slots cap how many heavy commands run at once, not how much memory one takes. -run-heavy cannot place the command in a cgroup: none is delegated to the user, and dockerd starts the containers outside the command's process tree. So run-heavy puts first on the command's `PATH` a `docker` that adds `--memory` and `--memory-swap`, both at the slot's share, to each `docker run`, `docker create` and `docker container run|create` that sets neither, then runs the real docker. The share is the memory the `machine load:` decision leaves to heavy commands, three quarters of MemTotal, split evenly across the slots. A `docker compose` service, and a docker named by its full path, keep no cap. Update the `machine load:` decision, run-heavy's help and stability-reviewer's mutation step, which sizes Stryker's or mutmut's concurrency so the run fits the cap. Once run-heavy caps them, let rule-hook's `docker-run-memory` pass a `docker run` under run-heavy. Test first in `bin/run_heavy/test_run_heavy.py`. +run-heavy cannot place the command in a cgroup: none is delegated to the user, and dockerd starts the containers outside the command's process tree. So run-heavy puts first on the command's `PATH` a `docker` that adds `--memory` and `--memory-swap`, both at the slot's share, to each `docker run`, `docker create` and `docker container run|create` that sets neither, then runs the real docker. It tells such a call apart with `bin/docker_command.py`'s `unlimited`, which rule-hook's `docker-run-memory` reads too. A container that sets its own `--memory` keeps it, so a project runs heavier work where it needs to (lilleman, 2026-10-24). The share is the memory the `machine load:` decision leaves to heavy commands, three quarters of MemTotal, split evenly across the slots. A `docker compose` service, and a docker named by its full path, keep no cap. Update the `machine load:` decision, run-heavy's help and stability-reviewer's mutation step, which sizes Stryker's or mutmut's concurrency so the run fits the cap. Once run-heavy caps them, let rule-hook's `docker-run-memory` pass a `docker run` under run-heavy, which `shell_command.launched` reports among a call's launchers. Test first in `bin/run_heavy/test_run_heavy.py`. ### 1. Say in README → Install how the transcript archive is backed up, once bender-infra backs up ai-sandbox's data volume. From f7ad418b20c851c61f32be2ac4b9cfd79306342e Mon Sep 17 00:00:00 2001 From: Lilleman auf Larv Date: Sat, 24 Oct 2026 00:32:30 +0200 Subject: [PATCH 06/18] Name the launcher reading in shell_command's docstring --- bin/shell_command.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bin/shell_command.py b/bin/shell_command.py index 38b2f562..3be290ac 100644 --- a/bin/shell_command.py +++ b/bin/shell_command.py @@ -1,4 +1,4 @@ -"""A shell command's simple commands, each as its words and the directory it runs in.""" +"""A shell command's simple commands, each as its words and the directory it runs in, and the tool each runs, through which launchers.""" import dataclasses import posixpath import re From 500e2c2947dcb29b9d86d50316857f16391715d8 Mon Sep 17 00:00:00 2001 From: Lilleman auf Larv Date: Sat, 24 Oct 2026 00:32:30 +0200 Subject: [PATCH 07/18] =?UTF-8?q?Answer=20architecture=20round=202:=200=20?= =?UTF-8?q?=F0=9F=94=B4,=200=20=F0=9F=9F=A1=20(0=20misread)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit From 2d219ff6c8c5f71a7e2e1ea1a9274c32d6ef1362 Mon Sep 17 00:00:00 2001 From: Lilleman auf Larv Date: Sat, 24 Oct 2026 00:36:19 +0200 Subject: [PATCH 08/18] =?UTF-8?q?Answer=20product-owner=20round=201:=200?= =?UTF-8?q?=20=F0=9F=94=B4,=201=20=F0=9F=9F=A1=20(0=20misread);=20read=20-?= =?UTF-8?q?m=20and=20--memory=20as=20a=20limit=20only=20with=20a=20size,?= =?UTF-8?q?=20so=20python=20-m=20pytest=20in=20the=20container=20is=20no?= =?UTF-8?q?=20limit,=20and=20read=20timeout=20as=20a=20launcher;=20also=20?= =?UTF-8?q?take=20the=20technical=20principles'=20nits:=20--help=20counts?= =?UTF-8?q?=20only=20beside=20docker's=20subcommand,=20sort=20STARTS=5FCON?= =?UTF-8?q?TAINER,=20print=20the=20example=20limit=20once,=20and=20name=20?= =?UTF-8?q?item=20227=20in=20the=20decision?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- bin/docker_command.py | 22 ++++++++++++++++++---- bin/rule_hook/rules.py | 2 +- bin/rule_hook/test_rule_hook.py | 4 ++-- bin/shell_command.py | 2 +- docs/decisions.md | 2 +- 5 files changed, 23 insertions(+), 9 deletions(-) diff --git a/bin/docker_command.py b/bin/docker_command.py index eb2004dc..d01b35bd 100644 --- a/bin/docker_command.py +++ b/bin/docker_command.py @@ -6,9 +6,11 @@ from shell_command import launched # The options of docker, docker buildx and docker compose that take a value, so the value is not read as a subcommand. DOCKER_VALUED = frozenset({"--ansi", "--builder", "--config", "--context", "--env-file", "--file", "--host", "--log-level", "--parallel", "--profile", "--progress", "--project-directory", "--project-name", "--tlscacert", "--tlscert", "--tlskey", "-c", "-f", "-H", "-l", "-p"}) # The subcommands that start a container, which takes the memory limit docker run's -m sets. -STARTS_CONTAINER = (["run"], ["create"], ["container", "run"], ["container", "create"]) +STARTS_CONTAINER = (["container", "create"], ["container", "run"], ["create"], ["run"]) +# A size as docker reads one, such as 4g, 512M or 1.5GiB: the pattern go-units' RAMInBytes parses. +SIZE = r"\d+(?:\.\d+)*[kKmMgGtTpP]?[iI]?[bB]?" # -m4g is -m with its value attached; --memory-swap alone sets no limit. -MEMORY_LIMIT = re.compile(r"-m.*|--memory(=.*)?") +ATTACHED_LIMIT = re.compile(rf"(?:-m|--memory=){SIZE}") def docker_subcommand(arguments: list[str]) -> list[str]: @@ -30,12 +32,24 @@ def docker_subcommand(arguments: list[str]) -> list[str]: def unlimited(arguments: list[str]) -> bool: """Whether docker's arguments start a container, with docker run or docker create, and set it no memory limit. - A --memory among the container's own arguments, past its image, reads as the limit too: telling it apart needs every value-taking option of docker run. + A -m or --memory with a size among the container's own arguments, past its image, reads as the limit too: telling it apart needs every value-taking option of docker run. Taking only a size keeps python -m pytest from reading as one. """ - return "--help" not in arguments and docker_subcommand(arguments) in STARTS_CONTAINER and not any(MEMORY_LIMIT.fullmatch(word) for word in arguments) + subcommand = docker_subcommand(arguments) + return subcommand in STARTS_CONTAINER and not limited(arguments) and not helped(arguments, subcommand) + + +def limited(arguments: list[str]) -> bool: + """Whether the arguments carry a memory limit: -m or --memory with a size, as its next word or attached.""" + return any(ATTACHED_LIMIT.fullmatch(word) or (word in ("-m", "--memory") and re.fullmatch(SIZE, value)) for word, value in zip(arguments, [*arguments[1:], ""])) def unlimited_container(words: list[str]) -> bool: """Whether the simple command, directly or through a launcher, starts a container that has no memory limit.""" docker = launched(words, {"docker"}) return docker is not None and unlimited(docker.arguments) + + +def helped(arguments: list[str], subcommand: list[str]) -> bool: + """Whether docker only prints its help: a --help before the subcommand or as the first word after it, not one the container's own command takes.""" + after = arguments.index(subcommand[-1]) + 1 + return "--help" in arguments[:after + 1] diff --git a/bin/rule_hook/rules.py b/bin/rule_hook/rules.py index 864b6e04..a90a037b 100644 --- a/bin/rule_hook/rules.py +++ b/bin/rule_hook/rules.py @@ -138,7 +138,7 @@ def command_breaches(command: str, simples: list[Simple], home: str) -> list[Bre if heavy(simple.words): breaches.append(Breach("run-heavy", f"run `{' '.join(simple.words)[:80]}` under `~/.claude/bin/run-heavy`, in the background", simple.directory)) if unlimited_container(simple.words): - breaches.append(Breach("docker-run-memory", f"give `{' '.join(simple.words)[:80]}` a memory limit as large as its work needs, such as `--memory 4g --memory-swap 4g`", simple.directory)) + breaches.append(Breach("docker-run-memory", f"give `{' '.join(simple.words)[:80]}` a memory limit as large as its work needs", simple.directory)) for commit in found: if commit.from_file: breaches.append(Breach("commit-one-line", "pass the message as one -m '', not from a file", commit.directory)) diff --git a/bin/rule_hook/test_rule_hook.py b/bin/rule_hook/test_rule_hook.py index 850dd441..b764aabf 100644 --- a/bin/rule_hook/test_rule_hook.py +++ b/bin/rule_hook/test_rule_hook.py @@ -117,12 +117,12 @@ class CommandBreaches(unittest.TestCase): self.assertEqual(checked(command), []) def test_a_docker_run_or_create_without_a_memory_limit_breaks_docker_run_memory(self): - for command in ["docker run --rm node:24.22.1-alpine3.24 node x.js", "cd /w && docker run -v /w:/w alpine:3.22.2 true", "docker create alpine:3.22.2", "docker container run alpine:3.22.2 true", "docker container create alpine:3.22.2", "nice -n 19 docker run alpine:3.22.2 true", "docker -H unix:///d.sock run alpine:3.22.2 true", "docker run --memory-swap 4g alpine:3.22.2 true", "~/.claude/bin/run-heavy docker run alpine:3.22.2 true"]: + for command in ["docker run --rm node:24.22.1-alpine3.24 node x.js", "cd /w && docker run -v /w:/w alpine:3.22.2 true", "docker create alpine:3.22.2", "docker container run alpine:3.22.2 true", "docker container create alpine:3.22.2", "nice -n 19 docker run alpine:3.22.2 true", "docker -H unix:///d.sock run alpine:3.22.2 true", "docker run --memory-swap 4g alpine:3.22.2 true", "~/.claude/bin/run-heavy docker run alpine:3.22.2 true", "docker run --rm python:3.13.1 python -m pytest", "docker run alpine:3.22.2 git commit -m x", "timeout 60 docker run alpine:3.22.2 true", "docker run node:24.22.1-alpine3.24 node --help"]: with self.subTest(command): self.assertEqual(checked(command), ["docker-run-memory"]) def test_a_docker_run_with_a_memory_limit_or_another_docker_call_passes_docker_run_memory(self): - for command in ["docker run -m 4g alpine:3.22.2 true", "docker run -m4g alpine:3.22.2 true", "docker run --memory 4g alpine:3.22.2 true", "docker run --rm --memory=4g --memory-swap=4g alpine:3.22.2 true", "docker container create -m 1g alpine:3.22.2", "docker run --help", "docker ps", "docker images", "docker container ls", "docker compose run --rm app go vet", "docker exec box true", "echo docker run alpine:3.22.2"]: + for command in ["docker run -m 4g alpine:3.22.2 true", "docker run -m4g alpine:3.22.2 true", "docker run --memory 4g alpine:3.22.2 true", "docker run -m 512M alpine:3.22.2 true", "docker run -m 1073741824 alpine:3.22.2 true", "timeout 60 docker run -m 4g alpine:3.22.2 true", "docker run --rm --memory=4g --memory-swap=4g alpine:3.22.2 true", "docker container create -m 1g alpine:3.22.2", "docker run --help", "docker container run --help", "docker --help", "docker ps", "docker images", "docker container ls", "docker compose run --rm app go vet", "docker exec box true", "echo docker run alpine:3.22.2"]: with self.subTest(command): self.assertEqual(checked(command), []) diff --git a/bin/shell_command.py b/bin/shell_command.py index 3be290ac..69061760 100644 --- a/bin/shell_command.py +++ b/bin/shell_command.py @@ -6,7 +6,7 @@ import shlex import typing # Launchers that run the tool named later in their words, such as uvx --with pytest mutmut run. -LAUNCHERS = frozenset({"bunx", "env", "nice", "npx", "pipx", "pnpm", "run-heavy", "time", "uvx", "yarn"}) +LAUNCHERS = frozenset({"bunx", "env", "nice", "npx", "pipx", "pnpm", "run-heavy", "time", "timeout", "uvx", "yarn"}) HEREDOC = re.compile(r"<<-?[ \t]*([\"']?)([A-Za-z_]\w*)\1[^\n]*\n.*?^[ \t]*\2[ \t]*$", re.DOTALL | re.MULTILINE) ASSIGNMENT = re.compile(r"[A-Za-z_][A-Za-z0-9_]*=") OPERATOR = set("\n();&|<>") diff --git a/docs/decisions.md b/docs/decisions.md index bcf2a971..7bde67ce 100644 --- a/docs/decisions.md +++ b/docs/decisions.md @@ -78,7 +78,7 @@ The cap is 5, `bin/todo_table.py`'s `BUNDLE_MAX_R`, from the same chunks: by the ## machine load: every container a session starts with `docker run` or `docker create` sets a memory limit as large as its work needs, which rule-hook's `docker-run-memory` enforces, and no daemon-wide cap limits all containers together -2026-10-24, lilleman. Serves goal 1.5. On 2026-10-23 ai-sandbox, with 8 CPUs and 7.6 GiB, hung until a hard reset, although its one heavy command held a slot: beside that mutation run, a reviewer's stress probes ran in `docker run` with no memory limit, each to 2 GiB. A limit makes a runaway container fail alone instead of taking the machine with it. The session sizes the limit, since lilleman wants a project to run heavier work where it needs to. rule-hook's rule reads only the commands a session types (todo item 228): a container a script or docker compose starts is out of its sight. lilleman turned down a daemon-wide cap, a dockerd `cgroup-parent` with a memory limit, which would see every container, on 2026-10-24: it is host config, and it would cap a project's heavy work too. Valid while sessions start their work in containers on a machine they share. +2026-10-24, lilleman. Serves goal 1.5. On 2026-10-23 ai-sandbox, with 8 CPUs and 7.6 GiB, hung until a hard reset, although its one heavy command held a slot: beside that mutation run, a reviewer's stress probes ran in `docker run` with no memory limit, each to 2 GiB. A limit makes a runaway container fail alone instead of taking the machine with it. The session sizes the limit, since lilleman wants a project to run heavier work where it needs to. rule-hook's rule reads only the commands a session types: a container a script or docker compose starts is out of its sight, and todo item 227 caps the ones a heavy command starts under run-heavy. lilleman turned down a daemon-wide cap, a dockerd `cgroup-parent` with a memory limit, which would see every container, on 2026-10-24: it is host config, and it would cap a project's heavy work too. Valid while sessions start their work in containers on a machine they share. ## principles: about seven things per level, four or five where they act on each other, more where a reader finds them by name; crossing a limit asks for a grouping or a recorded reason From 196abe18a94bfb735a48be3878b999a4caf32013 Mon Sep 17 00:00:00 2001 From: Lilleman auf Larv Date: Sat, 24 Oct 2026 00:42:39 +0200 Subject: [PATCH 09/18] =?UTF-8?q?Answer=20principles=20round=201:=200=20?= =?UTF-8?q?=F0=9F=94=B4,=205=20=F0=9F=9F=A1=20(0=20misread);=20require=20a?= =?UTF-8?q?=20swap=20limit=20beside=20the=20memory=20limit,=20ask=20in=20C?= =?UTF-8?q?LAUDE.md=20for=20both=20where=20rule-hook=20can't=20see=20the?= =?UTF-8?q?=20container,=20remove=20items=20225=20and=20228=20with=20a=20c?= =?UTF-8?q?hangelog=20entry;=20the=20-m=20finding=20was=20answered=20in=20?= =?UTF-8?q?the=20product-owner=20round=201=20commit?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- AGENTS.md | 2 +- CHANGELOG.md | 1 + CLAUDE.md | 1 + bin/docker_command.py | 12 +++++++----- bin/rule_hook/rules.py | 6 +++--- bin/rule_hook/test_rule_hook.py | 6 +++--- bin/shell_command.py | 4 ++-- docs/decisions.md | 6 ++++-- todo.md | 16 ++++------------ 9 files changed, 26 insertions(+), 28 deletions(-) diff --git a/AGENTS.md b/AGENTS.md index cdfa1df2..6300ae92 100644 --- a/AGENTS.md +++ b/AGENTS.md @@ -16,7 +16,7 @@ Decisions live in `docs/decisions.md`: - loop-claude: one session per project, its id derived from the checkout's path relative to `~/code`, or to `/` outside it - loop-claude: the archive keeps the raw transcript, and a failed archive stops the loop - machine load: a heavy command waits for one of the machine's heavy slots, one for every 4 CPUs, which every session shares, and loop-claude starts a worker only while at least a quarter of the machine's memory is available -- machine load: every container a session starts with `docker run` or `docker create` sets a memory limit as large as its work needs, which rule-hook's `docker-run-memory` enforces, and no daemon-wide cap limits all containers together +- machine load: every container a session starts has a memory limit and a swap limit as large as its work needs, which rule-hook's `docker-run-memory` enforces on `docker run` and `docker create`, and no daemon-wide cap limits all containers together - principles: about seven things per level, four or five where they act on each other, more where a reader finds them by name; crossing a limit asks for a grouping or a recorded reason - reading cost and `score-outcomes`: each waits for 10 finished chunks before it shows a median - reading cost: a rise is the last 5 chunks' median above the 5 before them, and files or refreshes one plan item diff --git a/CHANGELOG.md b/CHANGELOG.md index b6aedd80..b01ebffe 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,7 @@ ## Unreleased +- rule-hook has a new rule, `docker-run-memory`. It blocks a `docker run` or `docker create` with no memory limit and no swap limit, such as `--memory 4g --memory-swap 4g`, sized to what the work needs. `CLAUDE.md` asks for the same limits on a container a script or a compose file starts, which rule-hook can't see. rule-hook's `run-heavy` rule also now reads docker's `--tlscacert`, `--tlscert`, `--tlskey` and buildx's `--builder` as options that take a value, and reads `docker container run` as a run: `docker --tlscacert ca.pem build .` was not blocked outside run-heavy before. - Reviewers now mark a 🔴 or 🟡 `[misread]` where it arose because the implementer misread code that had already shipped. A round's commit title now counts the marked findings, as in `Answer stability round 1: 1 🔴, 2 🟡 (1 misread); …`, and rule-hook's `round-title-counts` blocks a round title without that count. `score-outcomes` shows the count on each finished item, and lists it after the medians for each chunk whose round titles carry it, newest first. A chunk whose round titles predate this change reads as unknown. - Sessions running at once no longer starve the machine. A new tool, `run-heavy `, runs a heavy command, such as a full gate, mutation tests, an e2e run or a `docker build`, once it holds one of the machine's heavy slots: one per 4 CPUs, shared by every session. `CLAUDE.md` has every session run its heavy commands under it, and rule-hook blocks a `docker build` or a mutation run outside it. loop-claude now waits to start a worker while less than a quarter of the machine's memory is available. - larv-review's skill now says a commit answering the external auto-reviewer takes no `Answer round` title, and that `larv-review round-count` doesn't list the auto-reviewer. A worker who followed the skill used to get a "not a pass" warning. diff --git a/CLAUDE.md b/CLAUDE.md index d3a7d3f2..907f52a3 100644 --- a/CLAUDE.md +++ b/CLAUDE.md @@ -65,6 +65,7 @@ The rules only reviewers apply, for quality, comments, READMEs and prose, live i - Keep the project's main checkout (e.g. `~/code/log`, never a worktree) current: when it is behind `origin` — a merge landed, or a fetch shows it — run `git pull --ff-only` there instead of reporting the lag, never with `--autostash`: a dirty checkout is a finding to report, not to carry along. - Run a project's language runtime, package manager, and task runner through its container/tooling setup, never directly on the host unless a decision puts them there. Example: `docker compose run --rm app …`. - Tear down test containers after a run. +- Give every container you start a memory limit and a swap limit, as large as its work needs: `--memory 4g --memory-swap 4g` on `docker run`, or `mem_limit` and `memswap_limit` in a compose file, scripts included. rule-hook checks only the `docker run` and `docker create` in your Bash commands. - A heavy command loads the machine for minutes: a full gate, mutation tests, an e2e run, a `docker build`. Run each one under `~/.claude/bin/run-heavy`, as in `~/.claude/bin/run-heavy ./ci.sh`. run-heavy waits for one of the heavy slots that every session on the machine shares. Run it in the background, since the wait can outlast the Bash tool's timeout. - Delegate a task to a subagent only when you need just its conclusion: a search or read across many files, or work independent enough to run in parallel. Keep edits, and whatever you must check line by line, in your own thread: you would read a delegated diff again to check it. Score the task's L as for a `todo.md` item; a task that changes no file, such as a search, is L 1. `` below is the project's model id, such as `claude-opus-5-5`: the one loop-claude's prompt names as the project's, or else your own. Launch the subagent with the model and effort of the first case that fits: 1. A reviewer, a comprehension seat or the security pass: those loop-claude's prompt gives it. Given none, pass no model or effort, so it runs on your model. diff --git a/bin/docker_command.py b/bin/docker_command.py index d01b35bd..f2ea8976 100644 --- a/bin/docker_command.py +++ b/bin/docker_command.py @@ -5,12 +5,14 @@ from shell_command import launched # The options of docker, docker buildx and docker compose that take a value, so the value is not read as a subcommand. DOCKER_VALUED = frozenset({"--ansi", "--builder", "--config", "--context", "--env-file", "--file", "--host", "--log-level", "--parallel", "--profile", "--progress", "--project-directory", "--project-name", "--tlscacert", "--tlscert", "--tlskey", "-c", "-f", "-H", "-l", "-p"}) -# The subcommands that start a container, which takes the memory limit docker run's -m sets. +# The subcommands that make a container, whose memory limits docker reads from the same options. STARTS_CONTAINER = (["container", "create"], ["container", "run"], ["create"], ["run"]) # A size as docker reads one, such as 4g, 512M or 1.5GiB: the pattern go-units' RAMInBytes parses. SIZE = r"\d+(?:\.\d+)*[kKmMgGtTpP]?[iI]?[bB]?" -# -m4g is -m with its value attached; --memory-swap alone sets no limit. +# -m4g is -m with its value attached. ATTACHED_LIMIT = re.compile(rf"(?:-m|--memory=){SIZE}") +# --memory-swap takes a size, or -1 for unlimited swap. +SWAP_LIMIT = re.compile(r"--memory-swap(=.*)?") def docker_subcommand(arguments: list[str]) -> list[str]: @@ -30,12 +32,12 @@ def docker_subcommand(arguments: list[str]) -> list[str]: def unlimited(arguments: list[str]) -> bool: - """Whether docker's arguments start a container, with docker run or docker create, and set it no memory limit. + """Whether docker's arguments make a container, with docker run or docker create, and leave its memory or its swap without a limit. - A -m or --memory with a size among the container's own arguments, past its image, reads as the limit too: telling it apart needs every value-taking option of docker run. Taking only a size keeps python -m pytest from reading as one. + The container's own arguments, past its image, are read too: telling them apart needs every value-taking option of docker run. So a -m 4g there reads as a limit, while python -m pytest does not, since pytest is no size. """ subcommand = docker_subcommand(arguments) - return subcommand in STARTS_CONTAINER and not limited(arguments) and not helped(arguments, subcommand) + return subcommand in STARTS_CONTAINER and not (limited(arguments) and any(SWAP_LIMIT.fullmatch(word) for word in arguments)) and not helped(arguments, subcommand) def limited(arguments: list[str]) -> bool: diff --git a/bin/rule_hook/rules.py b/bin/rule_hook/rules.py index a90a037b..02192686 100644 --- a/bin/rule_hook/rules.py +++ b/bin/rule_hook/rules.py @@ -31,8 +31,8 @@ RULES: dict[RuleName, Rule] = { "git commit takes its message as one -m with no line break; -F, a second -m and a heredoc are blocked", ), "docker-run-memory": Rule( - "a container started with docker run or docker create has a memory limit, as large as its work needs, such as `--memory 4g --memory-swap 4g`, so one runaway container cannot starve the machine; --memory-swap equal to --memory keeps it out of swap", - "docker run, docker create, docker container run and docker container create, whether direct or through a launcher such as nice. A container a script or docker compose starts is not checked", + "a container made with docker run or docker create has a memory limit and a swap limit, as large as its work needs, such as `--memory 4g --memory-swap 4g`, so a runaway container fails alone instead of starving the machine; a swap limit equal to the memory limit keeps it out of swap", + "docker run, docker create, docker container run and docker container create, whether direct or through a launcher such as nice or timeout. A container a script or docker compose starts is not checked", ), "ignorefile-sorted": Rule( "each block of an ignore file is sorted in code-point order, as LC_ALL=C sort does, since its order carries no meaning; where order matters, such as a re-include after its exclude, split the block with a blank line or a comment", @@ -138,7 +138,7 @@ def command_breaches(command: str, simples: list[Simple], home: str) -> list[Bre if heavy(simple.words): breaches.append(Breach("run-heavy", f"run `{' '.join(simple.words)[:80]}` under `~/.claude/bin/run-heavy`, in the background", simple.directory)) if unlimited_container(simple.words): - breaches.append(Breach("docker-run-memory", f"give `{' '.join(simple.words)[:80]}` a memory limit as large as its work needs", simple.directory)) + breaches.append(Breach("docker-run-memory", f"give `{' '.join(simple.words)[:80]}` a memory limit and a swap limit as large as its work needs", simple.directory)) for commit in found: if commit.from_file: breaches.append(Breach("commit-one-line", "pass the message as one -m '', not from a file", commit.directory)) diff --git a/bin/rule_hook/test_rule_hook.py b/bin/rule_hook/test_rule_hook.py index b764aabf..707db4fb 100644 --- a/bin/rule_hook/test_rule_hook.py +++ b/bin/rule_hook/test_rule_hook.py @@ -107,7 +107,7 @@ class CommandBreaches(unittest.TestCase): self.assertEqual(checked("git commit -m 'Answer the question in the README'"), []) def test_a_docker_build_or_a_mutation_run_outside_run_heavy_breaks_run_heavy(self): - for command in ["docker build -t x .", "cd /w && docker buildx build .", "docker compose build", "docker compose -f x.yml --verbose build app", "uvx --with pytest 'mutmut>=3,<4' run", "cargo mutants --in-diff d", "npx stryker run", "vendor/bin/infection --git-diff-lines", "docker compose run --rm app mutmut run", "docker run --rm -m 4g -v /w:/w rust:1.90.0 cargo mutants", "docker compose exec app npx stryker run", "docker run -h box -m 4g rust:1.90.0 cargo mutants", "nice -n 19 docker build .", "env DOCKER_BUILDKIT=1 docker build .", "time -p docker compose build", "docker --tlscacert ca.pem build .", "docker --tlscert c.pem --tlskey k.pem build .", "docker buildx --builder b build .", "docker container run -m 4g rust:1.90.0 cargo mutants", "uvx mutmut --verbose run"]: + for command in ["docker build -t x .", "cd /w && docker buildx build .", "docker compose build", "docker compose -f x.yml --verbose build app", "uvx --with pytest 'mutmut>=3,<4' run", "cargo mutants --in-diff d", "npx stryker run", "vendor/bin/infection --git-diff-lines", "docker compose run --rm app mutmut run", "docker run --rm -m 4g --memory-swap 4g -v /w:/w rust:1.90.0 cargo mutants", "docker compose exec app npx stryker run", "docker run -h box -m 4g --memory-swap 4g rust:1.90.0 cargo mutants", "nice -n 19 docker build .", "env DOCKER_BUILDKIT=1 docker build .", "time -p docker compose build", "docker --tlscacert ca.pem build .", "docker --tlscert c.pem --tlskey k.pem build .", "docker buildx --builder b build .", "docker container run -m 4g --memory-swap 4g rust:1.90.0 cargo mutants", "uvx mutmut --verbose run"]: with self.subTest(command): self.assertEqual(checked(command), ["run-heavy"]) @@ -117,12 +117,12 @@ class CommandBreaches(unittest.TestCase): self.assertEqual(checked(command), []) def test_a_docker_run_or_create_without_a_memory_limit_breaks_docker_run_memory(self): - for command in ["docker run --rm node:24.22.1-alpine3.24 node x.js", "cd /w && docker run -v /w:/w alpine:3.22.2 true", "docker create alpine:3.22.2", "docker container run alpine:3.22.2 true", "docker container create alpine:3.22.2", "nice -n 19 docker run alpine:3.22.2 true", "docker -H unix:///d.sock run alpine:3.22.2 true", "docker run --memory-swap 4g alpine:3.22.2 true", "~/.claude/bin/run-heavy docker run alpine:3.22.2 true", "docker run --rm python:3.13.1 python -m pytest", "docker run alpine:3.22.2 git commit -m x", "timeout 60 docker run alpine:3.22.2 true", "docker run node:24.22.1-alpine3.24 node --help"]: + for command in ["docker run --rm node:24.22.1-alpine3.24 node x.js", "cd /w && docker run -v /w:/w alpine:3.22.2 true", "docker create alpine:3.22.2", "docker container run alpine:3.22.2 true", "docker container create alpine:3.22.2", "nice -n 19 docker run alpine:3.22.2 true", "docker -H unix:///d.sock run alpine:3.22.2 true", "docker run --memory-swap 4g alpine:3.22.2 true", "docker run -m 4g alpine:3.22.2 true", "docker run --memory=4g alpine:3.22.2 sh -c 'x --memory-swap 4g'", "~/.claude/bin/run-heavy docker run alpine:3.22.2 true", "docker run --rm python:3.13.1 python -m pytest", "docker run alpine:3.22.2 git commit -m x", "timeout 60 docker run alpine:3.22.2 true", "docker run node:24.22.1-alpine3.24 node --help"]: with self.subTest(command): self.assertEqual(checked(command), ["docker-run-memory"]) def test_a_docker_run_with_a_memory_limit_or_another_docker_call_passes_docker_run_memory(self): - for command in ["docker run -m 4g alpine:3.22.2 true", "docker run -m4g alpine:3.22.2 true", "docker run --memory 4g alpine:3.22.2 true", "docker run -m 512M alpine:3.22.2 true", "docker run -m 1073741824 alpine:3.22.2 true", "timeout 60 docker run -m 4g alpine:3.22.2 true", "docker run --rm --memory=4g --memory-swap=4g alpine:3.22.2 true", "docker container create -m 1g alpine:3.22.2", "docker run --help", "docker container run --help", "docker --help", "docker ps", "docker images", "docker container ls", "docker compose run --rm app go vet", "docker exec box true", "echo docker run alpine:3.22.2"]: + for command in ["docker run -m 4g --memory-swap 4g alpine:3.22.2 true", "docker run -m4g --memory-swap=4g alpine:3.22.2 true", "docker run --memory 512M --memory-swap -1 alpine:3.22.2 true", "docker run -m 1073741824 --memory-swap 2g alpine:3.22.2 true", "timeout 60 docker run -m 4g --memory-swap 4g alpine:3.22.2 true", "docker run --rm --memory=1.5GiB --memory-swap=1.5GiB alpine:3.22.2 true", "docker container create -m 1g --memory-swap 1g alpine:3.22.2", "docker run --help", "docker container run --help", "docker --help", "docker ps", "docker images", "docker container ls", "docker compose run --rm app go vet", "docker exec box true", "echo docker run alpine:3.22.2"]: with self.subTest(command): self.assertEqual(checked(command), []) diff --git a/bin/shell_command.py b/bin/shell_command.py index 69061760..49537e5e 100644 --- a/bin/shell_command.py +++ b/bin/shell_command.py @@ -1,4 +1,4 @@ -"""A shell command's simple commands, each as its words and the directory it runs in, and the tool each runs, through which launchers.""" +"""A shell command's simple commands, each as its words and the directory it runs in, and which tool a simple command runs through which launchers.""" import dataclasses import posixpath import re @@ -100,7 +100,7 @@ def tool_name(word: str) -> str: def launched(words: list[str], tools: typing.Collection[str]) -> Launch | None: - """The first of tools that the simple command runs, directly or through launchers; None where it runs none of them.""" + """Which of the given tools the simple command runs, directly or through launchers, taking the first one named; None where it doesn't run any of them.""" names = [tool_name(word) for word in words] # Past a launcher, the tool may follow the launcher's own options and assignments, as in nice -n 19 docker build; without one, the command itself is the tool. reachable = names if names[:1] and names[0] in LAUNCHERS else names[:1] diff --git a/docs/decisions.md b/docs/decisions.md index 7bde67ce..b4dc0e70 100644 --- a/docs/decisions.md +++ b/docs/decisions.md @@ -76,9 +76,11 @@ The cap is 5, `bin/todo_table.py`'s `BUNDLE_MAX_R`, from the same chunks: by the 2026-10-23, lilleman. Serves goal 1.5. On 2026-10-22 ai-sandbox, with 8 CPUs and 16 GiB, thrashed for hours: four to six loops ran mutation tests, full gates, `docker build`s and QEMU-booting e2e tests at once, and nothing told one loop how busy the machine was. lilleman chose both limits; no standard sets either, and GNU parallel's `--memfree`, which does the memory wait's job, has no default. A slot is a file lock, so a session that dies frees its slot. The memory wait reads `/proc/meminfo` only, and off Linux a worker starts at once. `bin/machine_load/` holds the slots and the memory share, `bin/run-heavy` takes a slot, `CLAUDE.md` → "Working with the codebase" has every session use it, and loop-claude's worker waits for the share. rule-hook's rule `run-heavy` blocks a `docker build`, and a run of a mutation tool stability-reviewer names, outside run-heavy, whether direct or inside a container. No program can tell a gate script from a light one, so only `CLAUDE.md` asks a session to run a gate under run-heavy. Valid while one machine runs several loops at once. -## machine load: every container a session starts with `docker run` or `docker create` sets a memory limit as large as its work needs, which rule-hook's `docker-run-memory` enforces, and no daemon-wide cap limits all containers together +## machine load: every container a session starts has a memory limit and a swap limit as large as its work needs, which rule-hook's `docker-run-memory` enforces on `docker run` and `docker create`, and no daemon-wide cap limits all containers together -2026-10-24, lilleman. Serves goal 1.5. On 2026-10-23 ai-sandbox, with 8 CPUs and 7.6 GiB, hung until a hard reset, although its one heavy command held a slot: beside that mutation run, a reviewer's stress probes ran in `docker run` with no memory limit, each to 2 GiB. A limit makes a runaway container fail alone instead of taking the machine with it. The session sizes the limit, since lilleman wants a project to run heavier work where it needs to. rule-hook's rule reads only the commands a session types: a container a script or docker compose starts is out of its sight, and todo item 227 caps the ones a heavy command starts under run-heavy. lilleman turned down a daemon-wide cap, a dockerd `cgroup-parent` with a memory limit, which would see every container, on 2026-10-24: it is host config, and it would cap a project's heavy work too. Valid while sessions start their work in containers on a machine they share. +2026-10-24, lilleman. Serves goal 1.5. On 2026-10-23 ai-sandbox, then with 8 CPUs and 7.6 GiB of memory, hung until a hard reset, although its one heavy command held a slot. Beside that mutation run, a reviewer's stress probes ran in `docker run` with no memory limit, each to 2 GiB. A limit makes a runaway container fail alone instead of taking the machine with it. A swap limit is needed too: without one, docker lets a container swap as much again as its memory limit, and swapping is how the machine hung. The session sizes both limits, since lilleman wants a project to run heavier work where it needs to. rule-hook reads only the `docker run` and `docker create` in a session's Bash commands. A container a script starts is out of its sight, and so is a compose service, whose limits live in its compose file. `CLAUDE.md` → "Working with the codebase" asks a session for limits there, and todo item 227 caps the containers a heavy command starts under run-heavy. + +A daemon-wide cap would see every container: dockerd's `cgroup-parent`, given a memory limit. lilleman turned it down, since it is host config and would cap a project's heavy work too. Valid while sessions start their work in containers on a machine they share. ## principles: about seven things per level, four or five where they act on each other, more where a reader finds them by name; crossing a limit asks for a grouping or a recorded reason diff --git a/todo.md b/todo.md index 655087f9..e02067cd 100644 --- a/todo.md +++ b/todo.md @@ -16,8 +16,6 @@ | 59 | 0.4.0 | | | **Bound a run of unfinished verdicts on one chunk, so a worker and judge that disagree cannot cycle unattended without end.** | 2 | 1 | 3 | 4 | 3 | 1.4 by 6 | 6.0 | | 167 | 0.4.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.4.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 | -| 228 | 0.4.0 | | | **Block a `docker run` or `docker create` that sets no memory limit, in a rule-hook rule `docker-run-memory`.** | 2 | 1 | 3 | 4 | 3 | 1.5 by 3 | 2.9 | -| 225 | 0.4.0 | | | **Add the value-taking options of docker that `DOCKER_VALUED` lacks, so rule-hook's `run-heavy` rule reads their value as a value and not as the subcommand.** | 1 | 1 | 3 | 3 | 2 | 1.5 by 2 | 2.6 | | 227 | 0.4.0 | | | **Cap the memory of each container a heavy command starts under run-heavy at its slot's share, and have stability-reviewer size a mutation run's concurrency to fit that cap.** | 3 | 2 | 3 | 6 | 5 | 1.5 by 5 | 1.9 | | 1 | 0.5.0 | | question | **Say in README → Install how the transcript archive is backed up, once bender-infra backs up ai-sandbox's data volume.** | 1 | 2 | 1 | 2 | 1 | | 0.0 | | 219 | 0.5.0 | | | **Name the project's rung `project` in `bin/judge_replay/main.py`, `bin/subagent_rung/main.py` and `bin/review_replay/main.py`, in place of `anchor`, as `bin/model_routing/ladder.py` and `bin/loop_claude` name it.** | 1 | 1 | 3 | 3 | 2 | code health by 2 | 12.0 | @@ -89,19 +87,13 @@ rule-hook checks Agent calls (item 163) but no Skill calls. A worker that invoke Claude Code owns that file and writes it. `trust` reads it, changes it and writes it back, so a write that lands in between is lost. -### 228. Block a `docker run` or `docker create` that sets no memory limit, in a rule-hook rule `docker-run-memory`. - -Part of the 2026-10-23 hang item 227 describes: a reviewer's probes ran in `docker run` with no `--memory`, and each grew to 2 GiB. The rule reads `-m`, `--memory` and `--memory=…`, through the launchers and docker options `bin/rule_hook/heavy_command.py` already reads. A container a script starts, such as a project's `in_image` function, is out of the rule's sight. Test first in `bin/rule_hook/test_rule_hook.py`. - -### 225. Add the value-taking options of docker that `DOCKER_VALUED` lacks, so rule-hook's `run-heavy` rule reads their value as a value and not as the subcommand. - -Found by review of PR #370, against code that moved unchanged into `bin/rule_hook/heavy_command.py`. `DOCKER_VALUED` there lacks `--tlscacert`, `--tlscert` and `--tlskey`, so `docker --tlscacert ca.pem build .` is not blocked outside run-heavy, although `RULES["run-heavy"]` in `bin/rule_hook/rules.py` says a docker build is. It also lacks buildx's `--builder`, so `docker buildx --builder x build` gets through. Test first in `bin/rule_hook/test_rule_hook.py`. Also no test checks the "within two words" limit of `mutation_run`: a mutant that widens it survives mutmut; add one. - ### 227. Cap the memory of each container a heavy command starts under run-heavy at its slot's share, and have stability-reviewer size a mutation run's concurrency to fit that cap. -On 2026-10-23 ai-sandbox, with 8 CPUs and 7.6 GiB, hung in swap until a hard reset. One heavy command held its slot as the `machine load:` decision asks: adf-codec's stability reviewer ran Stryker with concurrency 4, each copy running the whole `node --test` suite, in one container that reached 4 GiB. Beside it, the same reviewer ran stress probes in `docker run` outside run-heavy, each to V8's 2 GiB heap limit. The slots cap how many heavy commands run at once, not how much memory one takes. +On 2026-10-23 ai-sandbox, then with 8 CPUs and 7.6 GiB, hung in swap until a hard reset. One heavy command held its slot, as the decision `machine load: a heavy command waits for one of the machine's heavy slots, …` asks: adf-codec's stability reviewer ran Stryker with concurrency 4, each copy running the whole `node --test` suite, in one container that reached 4 GiB. The container was started by the project's own script, so rule-hook's `docker-run-memory` can't see one like it. The slots cap how many heavy commands run at once, not how much memory one takes. -run-heavy cannot place the command in a cgroup: none is delegated to the user, and dockerd starts the containers outside the command's process tree. So run-heavy puts first on the command's `PATH` a `docker` that adds `--memory` and `--memory-swap`, both at the slot's share, to each `docker run`, `docker create` and `docker container run|create` that sets neither, then runs the real docker. It tells such a call apart with `bin/docker_command.py`'s `unlimited`, which rule-hook's `docker-run-memory` reads too. A container that sets its own `--memory` keeps it, so a project runs heavier work where it needs to (lilleman, 2026-10-24). The share is the memory the `machine load:` decision leaves to heavy commands, three quarters of MemTotal, split evenly across the slots. A `docker compose` service, and a docker named by its full path, keep no cap. Update the `machine load:` decision, run-heavy's help and stability-reviewer's mutation step, which sizes Stryker's or mutmut's concurrency so the run fits the cap. Once run-heavy caps them, let rule-hook's `docker-run-memory` pass a `docker run` under run-heavy, which `shell_command.launched` reports among a call's launchers. Test first in `bin/run_heavy/test_run_heavy.py`. +run-heavy cannot place the command in a cgroup: none is delegated to the user, and dockerd starts the containers outside the command's process tree. So run-heavy puts first on the command's `PATH` a `docker` that adds `--memory` and `--memory-swap`, both at the slot's share, to each `docker run`, `docker create` and `docker container run|create` that leaves either without a limit, then runs the real docker. It tells such a call apart with `bin/docker_command.py`'s `unlimited`, which rule-hook's `docker-run-memory` reads too. A container that sets its own limits keeps them, so a project runs heavier work where it needs to (lilleman, 2026-10-24). A compose service, and a docker named by its full path, keep no cap. + +The slot's share is a new choice, to record in the decision `machine load: every container a session starts has …`: that decision's elder, `machine load: a heavy command waits …`, starts a worker only while a quarter of the memory is available, so the share is the other three quarters of MemTotal, split evenly across the slots. Update both decisions, run-heavy's help and stability-reviewer's mutation step, which sizes Stryker's or mutmut's concurrency so the run fits the cap. Once run-heavy caps them, let `docker-run-memory` pass a `docker run` under run-heavy, which `shell_command.launched` reports among a call's launchers. Test first in `bin/run_heavy/test_run_heavy.py`. ### 1. Say in README → Install how the transcript archive is backed up, once bender-infra backs up ai-sandbox's data volume. From e2606b8dab188a89dc9170d1abbbbef67a08542b Mon Sep 17 00:00:00 2001 From: Lilleman auf Larv Date: Sat, 24 Oct 2026 00:42:39 +0200 Subject: [PATCH 10/18] =?UTF-8?q?Answer=20prose=20round=201:=200=20?= =?UTF-8?q?=F0=9F=94=B4,=206=20=F0=9F=9F=A1=20(0=20misread);=20answered=20?= =?UTF-8?q?in=20the=20principles=20round=201=20commit:=20the=20shipped=20i?= =?UTF-8?q?tems=20leave=20the=20plan,=20the=20decision=20names=20Bash=20co?= =?UTF-8?q?mmands,=20compose=20and=20its=20scripts,=20splits=20the=20cgrou?= =?UTF-8?q?p-parent=20sentence,=20item=20227=20names=20each=20machine=20lo?= =?UTF-8?q?ad=20decision=20in=20full,=20and=20the=20docstrings=20say=20wha?= =?UTF-8?q?t=20-m=20and=20--help=20do?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit From 951f166c79e104a45e5d2bc166c83297fed95078 Mon Sep 17 00:00:00 2001 From: Lilleman auf Larv Date: Sat, 24 Oct 2026 00:42:39 +0200 Subject: [PATCH 11/18] =?UTF-8?q?Answer=20stability=20round=201:=200=20?= =?UTF-8?q?=F0=9F=94=B4,=201=20=F0=9F=9F=A1=20(0=20misread);=20answered=20?= =?UTF-8?q?in=20the=20product-owner=20round=201=20commit:=20-m=20and=20--m?= =?UTF-8?q?emory=20count=20only=20with=20a=20size?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit From 1ae40181016d83efddd215c0bca154c30ba25e46 Mon Sep 17 00:00:00 2001 From: Lilleman auf Larv Date: Sat, 24 Oct 2026 00:42:39 +0200 Subject: [PATCH 12/18] =?UTF-8?q?Answer=20security=20round=201:=200=20?= =?UTF-8?q?=F0=9F=94=B4,=200=20=F0=9F=9F=A1=20(0=20misread)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit From e1a67eff2a9219dc0b507835f6150fa763841429 Mon Sep 17 00:00:00 2001 From: Lilleman auf Larv Date: Sat, 24 Oct 2026 00:44:13 +0200 Subject: [PATCH 13/18] =?UTF-8?q?Answer=20principles=20round=202:=200=20?= =?UTF-8?q?=F0=9F=94=B4,=201=20=F0=9F=9F=A1=20(0=20misread);=20a=20swap=20?= =?UTF-8?q?limit=20is=20a=20size=20other=20than=200,=20so=20--memory-swap?= =?UTF-8?q?=20-1=20is=20no=20limit,=20read=20like=20the=20memory=20limit?= =?UTF-8?q?=20and=20not=20from=20any=20word;=20the=20docstrings=20and=20ch?= =?UTF-8?q?angelog=20name=20both=20limits?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- CHANGELOG.md | 2 +- bin/docker_command.py | 20 ++++++++++---------- bin/rule_hook/test_rule_hook.py | 4 ++-- 3 files changed, 13 insertions(+), 13 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index b01ebffe..f297cc5d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,7 +2,7 @@ ## Unreleased -- rule-hook has a new rule, `docker-run-memory`. It blocks a `docker run` or `docker create` with no memory limit and no swap limit, such as `--memory 4g --memory-swap 4g`, sized to what the work needs. `CLAUDE.md` asks for the same limits on a container a script or a compose file starts, which rule-hook can't see. rule-hook's `run-heavy` rule also now reads docker's `--tlscacert`, `--tlscert`, `--tlskey` and buildx's `--builder` as options that take a value, and reads `docker container run` as a run: `docker --tlscacert ca.pem build .` was not blocked outside run-heavy before. +- rule-hook has a new rule, `docker-run-memory`. It blocks a `docker run` or `docker create` that lacks a memory limit or a swap limit, such as `--memory 4g --memory-swap 4g`, sized to what the work needs. `--memory-swap -1`, unlimited swap, counts as none. `CLAUDE.md` asks for the same limits on a container a script or a compose file starts, which rule-hook can't see. rule-hook's `run-heavy` rule also now reads docker's `--tlscacert`, `--tlscert`, `--tlskey` and buildx's `--builder` as options that take a value, and reads `docker container run` as a run: `docker --tlscacert ca.pem build .` was not blocked outside run-heavy before. - Reviewers now mark a 🔴 or 🟡 `[misread]` where it arose because the implementer misread code that had already shipped. A round's commit title now counts the marked findings, as in `Answer stability round 1: 1 🔴, 2 🟡 (1 misread); …`, and rule-hook's `round-title-counts` blocks a round title without that count. `score-outcomes` shows the count on each finished item, and lists it after the medians for each chunk whose round titles carry it, newest first. A chunk whose round titles predate this change reads as unknown. - Sessions running at once no longer starve the machine. A new tool, `run-heavy `, runs a heavy command, such as a full gate, mutation tests, an e2e run or a `docker build`, once it holds one of the machine's heavy slots: one per 4 CPUs, shared by every session. `CLAUDE.md` has every session run its heavy commands under it, and rule-hook blocks a `docker build` or a mutation run outside it. loop-claude now waits to start a worker while less than a quarter of the machine's memory is available. - larv-review's skill now says a commit answering the external auto-reviewer takes no `Answer round` title, and that `larv-review round-count` doesn't list the auto-reviewer. A worker who followed the skill used to get a "not a pass" warning. diff --git a/bin/docker_command.py b/bin/docker_command.py index f2ea8976..e56c7f66 100644 --- a/bin/docker_command.py +++ b/bin/docker_command.py @@ -1,4 +1,4 @@ -"""What a docker command asks of docker: its subcommand, and whether a container it starts has a memory limit.""" +"""What a docker command asks of docker: its subcommand, and whether a container it starts has a memory limit and a swap limit.""" import re from shell_command import launched @@ -9,10 +9,8 @@ DOCKER_VALUED = frozenset({"--ansi", "--builder", "--config", "--context", "--en STARTS_CONTAINER = (["container", "create"], ["container", "run"], ["create"], ["run"]) # A size as docker reads one, such as 4g, 512M or 1.5GiB: the pattern go-units' RAMInBytes parses. SIZE = r"\d+(?:\.\d+)*[kKmMgGtTpP]?[iI]?[bB]?" -# -m4g is -m with its value attached. -ATTACHED_LIMIT = re.compile(rf"(?:-m|--memory=){SIZE}") -# --memory-swap takes a size, or -1 for unlimited swap. -SWAP_LIMIT = re.compile(r"--memory-swap(=.*)?") +# A swap limit is a size other than 0: docker reads --memory-swap -1 as unlimited swap, and 0 as unset. +SWAP = rf"(?!0+(?:\.0+)*[kKmMgGtTpP]?[iI]?[bB]?$){SIZE}" def docker_subcommand(arguments: list[str]) -> list[str]: @@ -37,16 +35,18 @@ def unlimited(arguments: list[str]) -> bool: The container's own arguments, past its image, are read too: telling them apart needs every value-taking option of docker run. So a -m 4g there reads as a limit, while python -m pytest does not, since pytest is no size. """ subcommand = docker_subcommand(arguments) - return subcommand in STARTS_CONTAINER and not (limited(arguments) and any(SWAP_LIMIT.fullmatch(word) for word in arguments)) and not helped(arguments, subcommand) + limited = given(arguments, ("-m", "--memory"), SIZE) and given(arguments, ("--memory-swap",), SWAP) + return subcommand in STARTS_CONTAINER and not limited and not helped(arguments, subcommand) -def limited(arguments: list[str]) -> bool: - """Whether the arguments carry a memory limit: -m or --memory with a size, as its next word or attached.""" - return any(ATTACHED_LIMIT.fullmatch(word) or (word in ("-m", "--memory") and re.fullmatch(SIZE, value)) for word, value in zip(arguments, [*arguments[1:], ""])) +def given(arguments: list[str], options: tuple[str, ...], value: str) -> bool: + """Whether the arguments give one of the options a value value matches, as its next word or attached, as in -m4g or --memory=4g.""" + attached = re.compile("|".join(re.escape(option) + ("" if len(option) == 2 else "=") + f"(?:{value})" for option in options)) + return any(attached.fullmatch(word) or (word in options and re.fullmatch(value, following)) for word, following in zip(arguments, [*arguments[1:], ""])) def unlimited_container(words: list[str]) -> bool: - """Whether the simple command, directly or through a launcher, starts a container that has no memory limit.""" + """Whether the simple command, directly or through a launcher, starts a container that lacks a memory limit or a swap limit.""" docker = launched(words, {"docker"}) return docker is not None and unlimited(docker.arguments) diff --git a/bin/rule_hook/test_rule_hook.py b/bin/rule_hook/test_rule_hook.py index 707db4fb..59400eca 100644 --- a/bin/rule_hook/test_rule_hook.py +++ b/bin/rule_hook/test_rule_hook.py @@ -117,12 +117,12 @@ class CommandBreaches(unittest.TestCase): self.assertEqual(checked(command), []) def test_a_docker_run_or_create_without_a_memory_limit_breaks_docker_run_memory(self): - for command in ["docker run --rm node:24.22.1-alpine3.24 node x.js", "cd /w && docker run -v /w:/w alpine:3.22.2 true", "docker create alpine:3.22.2", "docker container run alpine:3.22.2 true", "docker container create alpine:3.22.2", "nice -n 19 docker run alpine:3.22.2 true", "docker -H unix:///d.sock run alpine:3.22.2 true", "docker run --memory-swap 4g alpine:3.22.2 true", "docker run -m 4g alpine:3.22.2 true", "docker run --memory=4g alpine:3.22.2 sh -c 'x --memory-swap 4g'", "~/.claude/bin/run-heavy docker run alpine:3.22.2 true", "docker run --rm python:3.13.1 python -m pytest", "docker run alpine:3.22.2 git commit -m x", "timeout 60 docker run alpine:3.22.2 true", "docker run node:24.22.1-alpine3.24 node --help"]: + for command in ["docker run --rm node:24.22.1-alpine3.24 node x.js", "cd /w && docker run -v /w:/w alpine:3.22.2 true", "docker create alpine:3.22.2", "docker container run alpine:3.22.2 true", "docker container create alpine:3.22.2", "nice -n 19 docker run alpine:3.22.2 true", "docker -H unix:///d.sock run alpine:3.22.2 true", "docker run --memory-swap 4g alpine:3.22.2 true", "docker run -m 4g alpine:3.22.2 true", "docker run --memory=4g alpine:3.22.2 sh -c 'x --memory-swap 4g'", "docker run -m 4g alpine:3.22.2 tool --memory-swap", "docker run -m 4g --memory-swap -1 alpine:3.22.2 true", "docker run -m 4g --memory-swap=0 alpine:3.22.2 true", "~/.claude/bin/run-heavy docker run alpine:3.22.2 true", "docker run --rm python:3.13.1 python -m pytest", "docker run alpine:3.22.2 git commit -m x", "timeout 60 docker run alpine:3.22.2 true", "docker run node:24.22.1-alpine3.24 node --help"]: with self.subTest(command): self.assertEqual(checked(command), ["docker-run-memory"]) def test_a_docker_run_with_a_memory_limit_or_another_docker_call_passes_docker_run_memory(self): - for command in ["docker run -m 4g --memory-swap 4g alpine:3.22.2 true", "docker run -m4g --memory-swap=4g alpine:3.22.2 true", "docker run --memory 512M --memory-swap -1 alpine:3.22.2 true", "docker run -m 1073741824 --memory-swap 2g alpine:3.22.2 true", "timeout 60 docker run -m 4g --memory-swap 4g alpine:3.22.2 true", "docker run --rm --memory=1.5GiB --memory-swap=1.5GiB alpine:3.22.2 true", "docker container create -m 1g --memory-swap 1g alpine:3.22.2", "docker run --help", "docker container run --help", "docker --help", "docker ps", "docker images", "docker container ls", "docker compose run --rm app go vet", "docker exec box true", "echo docker run alpine:3.22.2"]: + for command in ["docker run -m 4g --memory-swap 4g alpine:3.22.2 true", "docker run -m4g --memory-swap=4g alpine:3.22.2 true", "docker run --memory 512M --memory-swap 1g alpine:3.22.2 true", "docker run -m 1073741824 --memory-swap 2g alpine:3.22.2 true", "timeout 60 docker run -m 4g --memory-swap 4g alpine:3.22.2 true", "docker run --rm --memory=1.5GiB --memory-swap=1.5GiB alpine:3.22.2 true", "docker container create -m 1g --memory-swap 1g alpine:3.22.2", "docker run --help", "docker container run --help", "docker --help", "docker ps", "docker images", "docker container ls", "docker compose run --rm app go vet", "docker exec box true", "echo docker run alpine:3.22.2"]: with self.subTest(command): self.assertEqual(checked(command), []) From e17ed74fc2d336e5d9e03c465bb8f8f3df5243c5 Mon Sep 17 00:00:00 2001 From: Lilleman auf Larv Date: Sat, 24 Oct 2026 00:45:13 +0200 Subject: [PATCH 14/18] =?UTF-8?q?Answer=20stability=20round=202:=200=20?= =?UTF-8?q?=F0=9F=94=B4,=202=20=F0=9F=9F=A1=20(0=20misread);=20--memory-sw?= =?UTF-8?q?ap=20-1=20was=20answered=20in=20the=20principles=20round=202=20?= =?UTF-8?q?commit,=20and=20requiring=20a=20swap=20limit=20stays,=20as=20th?= =?UTF-8?q?e=20decision=20says=20docker's=20default=20swaps=20as=20much=20?= =?UTF-8?q?again=20as=20the=20limit;=20test=20a=20--help=20past=20the=20im?= =?UTF-8?q?age?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- bin/rule_hook/test_rule_hook.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bin/rule_hook/test_rule_hook.py b/bin/rule_hook/test_rule_hook.py index 59400eca..be26f9ab 100644 --- a/bin/rule_hook/test_rule_hook.py +++ b/bin/rule_hook/test_rule_hook.py @@ -117,7 +117,7 @@ class CommandBreaches(unittest.TestCase): self.assertEqual(checked(command), []) def test_a_docker_run_or_create_without_a_memory_limit_breaks_docker_run_memory(self): - for command in ["docker run --rm node:24.22.1-alpine3.24 node x.js", "cd /w && docker run -v /w:/w alpine:3.22.2 true", "docker create alpine:3.22.2", "docker container run alpine:3.22.2 true", "docker container create alpine:3.22.2", "nice -n 19 docker run alpine:3.22.2 true", "docker -H unix:///d.sock run alpine:3.22.2 true", "docker run --memory-swap 4g alpine:3.22.2 true", "docker run -m 4g alpine:3.22.2 true", "docker run --memory=4g alpine:3.22.2 sh -c 'x --memory-swap 4g'", "docker run -m 4g alpine:3.22.2 tool --memory-swap", "docker run -m 4g --memory-swap -1 alpine:3.22.2 true", "docker run -m 4g --memory-swap=0 alpine:3.22.2 true", "~/.claude/bin/run-heavy docker run alpine:3.22.2 true", "docker run --rm python:3.13.1 python -m pytest", "docker run alpine:3.22.2 git commit -m x", "timeout 60 docker run alpine:3.22.2 true", "docker run node:24.22.1-alpine3.24 node --help"]: + for command in ["docker run --rm node:24.22.1-alpine3.24 node x.js", "cd /w && docker run -v /w:/w alpine:3.22.2 true", "docker create alpine:3.22.2", "docker container run alpine:3.22.2 true", "docker container create alpine:3.22.2", "nice -n 19 docker run alpine:3.22.2 true", "docker -H unix:///d.sock run alpine:3.22.2 true", "docker run --memory-swap 4g alpine:3.22.2 true", "docker run -m 4g alpine:3.22.2 true", "docker run --memory=4g alpine:3.22.2 sh -c 'x --memory-swap 4g'", "docker run -m 4g alpine:3.22.2 tool --memory-swap", "docker run -m 4g --memory-swap -1 alpine:3.22.2 true", "docker run -m 4g --memory-swap=0 alpine:3.22.2 true", "~/.claude/bin/run-heavy docker run alpine:3.22.2 true", "docker run --rm python:3.13.1 python -m pytest", "docker run alpine:3.22.2 git commit -m x", "timeout 60 docker run alpine:3.22.2 true", "docker run node:24.22.1-alpine3.24 node --help", "docker run alpine:3.22.2 --help"]: with self.subTest(command): self.assertEqual(checked(command), ["docker-run-memory"]) From a622d19280a1b2ad83e3cfa6220b319ab430cbb9 Mon Sep 17 00:00:00 2001 From: Lilleman auf Larv Date: Sat, 24 Oct 2026 00:47:57 +0200 Subject: [PATCH 15/18] =?UTF-8?q?Answer=20stability=20round=203:=200=20?= =?UTF-8?q?=F0=9F=94=B4,=201=20=F0=9F=9F=A1=20(0=20misread);=20test=20that?= =?UTF-8?q?=20a=20size=20after=20the=20image's=20command=20is=20no=20limit?= =?UTF-8?q?;=20name=20given's=20regex=20parameter=20pattern?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- bin/docker_command.py | 8 ++++---- bin/rule_hook/test_rule_hook.py | 2 +- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/bin/docker_command.py b/bin/docker_command.py index e56c7f66..5cc416b8 100644 --- a/bin/docker_command.py +++ b/bin/docker_command.py @@ -39,10 +39,10 @@ def unlimited(arguments: list[str]) -> bool: return subcommand in STARTS_CONTAINER and not limited and not helped(arguments, subcommand) -def given(arguments: list[str], options: tuple[str, ...], value: str) -> bool: - """Whether the arguments give one of the options a value value matches, as its next word or attached, as in -m4g or --memory=4g.""" - attached = re.compile("|".join(re.escape(option) + ("" if len(option) == 2 else "=") + f"(?:{value})" for option in options)) - return any(attached.fullmatch(word) or (word in options and re.fullmatch(value, following)) for word, following in zip(arguments, [*arguments[1:], ""])) +def given(arguments: list[str], options: tuple[str, ...], pattern: str) -> bool: + """Whether the arguments give one of the options a value pattern matches, as its next word or attached, as in -m4g or --memory=4g.""" + attached = re.compile("|".join(re.escape(option) + ("" if len(option) == 2 else "=") + f"(?:{pattern})" for option in options)) + return any(attached.fullmatch(word) or (word in options and re.fullmatch(pattern, following)) for word, following in zip(arguments, [*arguments[1:], ""])) def unlimited_container(words: list[str]) -> bool: diff --git a/bin/rule_hook/test_rule_hook.py b/bin/rule_hook/test_rule_hook.py index be26f9ab..c2dc47e2 100644 --- a/bin/rule_hook/test_rule_hook.py +++ b/bin/rule_hook/test_rule_hook.py @@ -117,7 +117,7 @@ class CommandBreaches(unittest.TestCase): self.assertEqual(checked(command), []) def test_a_docker_run_or_create_without_a_memory_limit_breaks_docker_run_memory(self): - for command in ["docker run --rm node:24.22.1-alpine3.24 node x.js", "cd /w && docker run -v /w:/w alpine:3.22.2 true", "docker create alpine:3.22.2", "docker container run alpine:3.22.2 true", "docker container create alpine:3.22.2", "nice -n 19 docker run alpine:3.22.2 true", "docker -H unix:///d.sock run alpine:3.22.2 true", "docker run --memory-swap 4g alpine:3.22.2 true", "docker run -m 4g alpine:3.22.2 true", "docker run --memory=4g alpine:3.22.2 sh -c 'x --memory-swap 4g'", "docker run -m 4g alpine:3.22.2 tool --memory-swap", "docker run -m 4g --memory-swap -1 alpine:3.22.2 true", "docker run -m 4g --memory-swap=0 alpine:3.22.2 true", "~/.claude/bin/run-heavy docker run alpine:3.22.2 true", "docker run --rm python:3.13.1 python -m pytest", "docker run alpine:3.22.2 git commit -m x", "timeout 60 docker run alpine:3.22.2 true", "docker run node:24.22.1-alpine3.24 node --help", "docker run alpine:3.22.2 --help"]: + for command in ["docker run --rm node:24.22.1-alpine3.24 node x.js", "cd /w && docker run -v /w:/w alpine:3.22.2 true", "docker create alpine:3.22.2", "docker container run alpine:3.22.2 true", "docker container create alpine:3.22.2", "nice -n 19 docker run alpine:3.22.2 true", "docker -H unix:///d.sock run alpine:3.22.2 true", "docker run --memory-swap 4g alpine:3.22.2 true", "docker run -m 4g alpine:3.22.2 true", "docker run --memory=4g alpine:3.22.2 sh -c 'x --memory-swap 4g'", "docker run -m 4g alpine:3.22.2 tool --memory-swap", "docker run -m 4g --memory-swap -1 alpine:3.22.2 true", "docker run -m 4g --memory-swap=0 alpine:3.22.2 true", "~/.claude/bin/run-heavy docker run alpine:3.22.2 true", "docker run --rm python:3.13.1 python -m pytest", "docker run alpine:3.22.2 git commit -m x", "timeout 60 docker run alpine:3.22.2 true", "docker run node:24.22.1-alpine3.24 node --help", "docker run alpine:3.22.2 --help", "docker run -m 4g alpine:3.22.2 sleep 60"]: with self.subTest(command): self.assertEqual(checked(command), ["docker-run-memory"]) From 899e8ed55c41f0b151b6031d84bfb1b2742a9ca3 Mon Sep 17 00:00:00 2001 From: Lilleman auf Larv Date: Sat, 24 Oct 2026 00:47:57 +0200 Subject: [PATCH 16/18] =?UTF-8?q?Answer=20principles=20round=203:=200=20?= =?UTF-8?q?=F0=9F=94=B4,=200=20=F0=9F=9F=A1=20(0=20misread)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit From f4d25691d677aca7f544f71c7af50c21915b54f8 Mon Sep 17 00:00:00 2001 From: Lilleman auf Larv Date: Sat, 24 Oct 2026 01:00:31 +0200 Subject: [PATCH 17/18] Record the comprehension check: paired ruling better against d1733a2 --- docs/comprehension-history.md | 40 +++++++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) diff --git a/docs/comprehension-history.md b/docs/comprehension-history.md index 69942d9e..64abee11 100644 --- a/docs/comprehension-history.md +++ b/docs/comprehension-history.md @@ -2687,3 +2687,43 @@ Inherited architect, decided by: - Navigation, Shape: `bin/rule_hook/heavy_command.py:1` `heavy_command`: a file name in the `rule_hook/` listing points straight at the unit, which the base buried in the 256-line `rules.py:103-150` - Locality: `bin/rule_hook/heavy_command.py:27` `heavy`: the rule "past a launcher docker can come anywhere, otherwise only first" reads from two plain lines, where the base held a nested conditional - Locality, Shape: `bin/rule_hook/heavy_command.py:5` `LAUNCHERS`: the tables sit beside their only consumer, so extending them needs no search for other readers + +## 2026-10-23T23:00:27Z, PR #372 at 899e8ed, against d1733a2 + +Ruling: better + +| Seat | Navigation | Locality | Shape | Self-sufficiency | Overall | +|---|---|---|---|---|---| +| Mid A | same | better | better | same | better | +| Inherited architect | worse | better | same | same | same | +| Maintainability senior | same | better | better | same | better | +| Junior A | same | better | better | same | better | + +Mid A, decided by: + +- Locality, Shape: `bin/shell_command.py:102` `launched`: one place finds the tool a command runs past its launchers, where heavy held launched, reachable, docker_at and a MUTATORS special case at once +- Shape, Locality: `bin/rule_hook/heavy_command.py:12` `heavy`: two cases and one early exit, with run-heavy read as a launcher instead of a stray word +- Shape, Navigation: `bin/docker_command.py:1` `docker_command`: named by what it holds and serving both docker rules, but at bin's root while only rule_hook reads it, against README's map +- Locality: `bin/docker_command.py:54` `helped`: unlimited leans on helpers defined below it, and helped finds the subcommand by its first occurrence + +Inherited architect, decided by: + +- Locality: `bin/rule_hook/heavy_command.py:12` `heavy`: four lines on launched and docker_subcommand, though LAUNCHERS now changes both docker rules together +- Navigation: `bin/docker_command.py:1` `docker_command`: README says root modules serve more than one tool, yet it serves only rule_hook, so a reader looks in rule_hook/ first +- Locality: `bin/docker_command.py:32` `unlimited`: the docstring states that the container's own arguments are read, and why python -m pytest is no limit +- Shape: `bin/shell_command.py:1` `shell_command`: the module now does two things, parsing and launcher reading, which only rule_hook uses + +Maintainability senior, decided by: + +- Locality, Shape: `bin/shell_command.py:102` `launched`: one function, returning a Launch, finds the tool past its launchers, where heavy did it inline with index arithmetic +- Locality, Shape: `bin/rule_hook/heavy_command.py:12` `heavy`: one branch, docker or a mutation tool, with the module no longer holding general shell and docker parsing +- Shape: `bin/docker_command.py:1` `docker_command`: README says root modules serve more than one tool, yet only rule_hook imports it +- Shape: `bin/docker_command.py:32` `unlimited`: the entry point sits between helpers, and unlimited and unlimited_container differ by an unstated input +- Locality: `bin/docker_command.py:54` `helped`: reads --help by position while heavy's LIGHT_FLAGS reads it anywhere, and neither says whether that is meant + +Junior A, decided by: + +- Locality, Shape: `bin/shell_command.py:102` `launched`: the steps that find a command's tool past its launchers live in one function both rules share +- Shape, Locality: `bin/rule_hook/heavy_command.py:12` `heavy`: from 13 lines mixing three parsings to 8 with a clear docker-or-mutator branch +- Shape: `bin/docker_command.py:1` `docker_command`: a truthful name and docstring, though it sits at bin's root rather than beside rule_hook's rules +- Locality: `bin/rule_hook/rules.py:140` `command_breaches`: the new rule plugs in beside run-heavy as one parallel if From 7fb8c61c5eaa8388ab51169014247102dc55aad3 Mon Sep 17 00:00:00 2001 From: Lilleman auf Larv Date: Sat, 24 Oct 2026 01:00:35 +0200 Subject: [PATCH 18/18] Say in README why docker_command.py sits at bin's root --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 2f7c35bb..1b8ae7f8 100644 --- a/README.md +++ b/README.md @@ -125,7 +125,7 @@ pytest_add_cli_args=-k Then, in the copy: `uvx --with pytest 'mutmut>=3,<4' run && uvx --with pytest 'mutmut>=3,<4' results`, and `uvx --with pytest 'mutmut>=3,<4' show ` to see a mutant's change. The config keys are mutmut 3's. -`bin/` is the import root: each launcher puts it on `sys.path`, so a module imports another by its path under `bin/`, such as `from claude_code.entries import parse_entry`. Each tool's package holds its tests; `rank_todo.py`, `settings_filter.py` and `statusline.py` are tools of one file each, tested beside them, `rule_hook` imports `rank_todo.py`'s check, `larv_review` imports `rank_todo.py`'s ranking, `score_outcomes` imports `reading_cost`'s record path, `judge_replay` imports `loop_claude`'s judge, and `loop_claude` runs `chunk-preflight` as a process of its own. `judge_replay` and `review_replay` share `rung_replay/`: the rung search, the argument reader, the candidate rungs and the exits. `rung_replay/` reads `loop_claude`'s retry count and models file. The other non-test modules at `bin/`'s root, `claude_code/` and `transcript_archive/` serve more than one tool; `model_routing/` holds the routing ladder, which loop-claude, `rule_hook`, both replay tools and `subagent-rung` read. `routing_figures/` measures loop-claude's archive for loop-claude's routing calls. `machine_load/` takes the machine's heavy slots, its shared lock files, for `run_heavy`, and reads the memory share that loop-claude waits for. `test_env.py` serves the tests, and `repo_checks/` tests the repo itself. +`bin/` is the import root: each launcher puts it on `sys.path`, so a module imports another by its path under `bin/`, such as `from claude_code.entries import parse_entry`. Each tool's package holds its tests; `rank_todo.py`, `settings_filter.py` and `statusline.py` are tools of one file each, tested beside them, `rule_hook` imports `rank_todo.py`'s check, `larv_review` imports `rank_todo.py`'s ranking, `score_outcomes` imports `reading_cost`'s record path, `judge_replay` imports `loop_claude`'s judge, and `loop_claude` runs `chunk-preflight` as a process of its own. `judge_replay` and `review_replay` share `rung_replay/`: the rung search, the argument reader, the candidate rungs and the exits. `rung_replay/` reads `loop_claude`'s retry count and models file. `docker_command.py` reads a docker command's subcommand and memory limits for `rule_hook`, and sits at the root so `run_heavy` can read them too. The other non-test modules at `bin/`'s root, `claude_code/` and `transcript_archive/` serve more than one tool; `model_routing/` holds the routing ladder, which loop-claude, `rule_hook`, both replay tools and `subagent-rung` read. `routing_figures/` measures loop-claude's archive for loop-claude's routing calls. `machine_load/` takes the machine's heavy slots, its shared lock files, for `run_heavy`, and reads the memory share that loop-claude waits for. `test_env.py` serves the tests, and `repo_checks/` tests the repo itself. ## Tracking a new file