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/55] 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/55] 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/55] 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/55] 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/55] =?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/55] 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/55] =?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/55] =?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/55] =?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/55] =?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/55] =?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/55] =?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/55] =?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/55] =?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/55] =?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/55] =?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/55] 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/55] 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 From 4c1ab3f1855c75433c7ec0b3b0bc292d0fd980ec Mon Sep 17 00:00:00 2001 From: Lilleman auf Larv Date: Sat, 24 Oct 2026 01:06:56 +0200 Subject: [PATCH 19/55] Cap the memory of each container a heavy command makes under run-heavy at its slot's share, and have stability-reviewer size a mutation run's concurrency to fit it --- .gitignore | 2 ++ AGENTS.md | 2 +- CHANGELOG.md | 1 + CLAUDE.md | 2 +- README.md | 4 ++-- agents/stability-reviewer.md | 2 +- bin/docker_command.py | 29 +++++++++++++++++++++++------ bin/rule_hook/test_rule_hook.py | 4 ++-- bin/run-heavy | 3 ++- bin/run_heavy/capped_docker.py | 23 +++++++++++++++++++++++ bin/run_heavy/main.py | 19 +++++++++++++++++-- bin/run_heavy/path_entry/docker | 10 ++++++++++ bin/run_heavy/test_run_heavy.py | 32 ++++++++++++++++++++++++++++++++ bin/test_docker_command.py | 28 ++++++++++++++++++++++++++++ docs/decisions.md | 6 ++++-- todo.md | 9 --------- 16 files changed, 149 insertions(+), 27 deletions(-) create mode 100644 bin/run_heavy/capped_docker.py create mode 100755 bin/run_heavy/path_entry/docker create mode 100644 bin/test_docker_command.py diff --git a/.gitignore b/.gitignore index 45938304..9a007c3a 100644 --- a/.gitignore +++ b/.gitignore @@ -71,6 +71,8 @@ !bin/run-heavy !bin/run_heavy/ !bin/run_heavy/*.py +!bin/run_heavy/path_entry/ +!bin/run_heavy/path_entry/docker !bin/score-outcomes !bin/score_outcomes/ !bin/score_outcomes/*.py diff --git a/AGENTS.md b/AGENTS.md index 6300ae92..85b02c5d 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 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 +- 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`; under run-heavy, a container that lacks them gets the slot's share of three quarters of the memory; 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 f297cc5d..74afaf5e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,7 @@ ## Unreleased +- `run-heavy` now caps the memory of each container its command makes. Where a `docker run` or `docker create` sets no limit, it gets a memory limit and a swap limit, both the slot's share: three quarters of the machine's memory, split across the heavy slots. A container that sets its own memory limit keeps it. This covers containers a project's own scripts start, which rule-hook can't see. rule-hook's `docker-run-memory` now lets a `docker run` under run-heavy pass. - 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. diff --git a/CLAUDE.md b/CLAUDE.md index 907f52a3..dd9100f0 100644 --- a/CLAUDE.md +++ b/CLAUDE.md @@ -66,7 +66,7 @@ The rules only reviewers apply, for quality, comments, READMEs and prose, live i - 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. +- 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, and gives each container the command makes without limits the slot's share of memory. 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. 2. An escalated task, below: the rung loop-claude's prompt names for escalation, or case 3's rung where the subagent files or scores `todo.md` items and that rung is higher. diff --git a/README.md b/README.md index 1b8ae7f8..f937581d 100644 --- a/README.md +++ b/README.md @@ -104,7 +104,7 @@ Install puts only `loop-claude` on `PATH`; call the others by their path, such a - `reading-cost [--reset] [record]` appends a figure for each chunk `loop-claude` finished to a project's `docs/reading-cost.md`, and says whether the figures rise; `reading-cost --help` states the measure. - `review-replay ` replays a review pass's archived rounds from the projects run on the model, on the code each reviewed, and prints the lowest rung below the project's that, like each rung above it, finds every 🔴 and 🟡 the project's rung finds again; `review-replay --help` states the replay. Each replayed reviewer skips every permission prompt, stability-reviewer has Bash, and an archived prompt may name paths on the host. - `rule-hook [overrides]` blocks a tool call that breaks a rule a program can check, unless the call overrides the rule; `settings.json` → `hooks` runs it before each Bash, Edit, MultiEdit, Write and Agent call, and `rule-hook --help` states the rules and the override. -- `run-heavy ` runs a heavy command once it holds one of the machine's heavy slots, one per 4 CPUs, which every session shares; `run-heavy --help` states the slots. +- `run-heavy ` runs a heavy command once it holds one of the machine's heavy slots, one per 4 CPUs, which every session shares; `run-heavy --help` states the slots, and the memory share it gives each container the command makes that lacks a limit. - `score-outcomes [L E I S]` lists the finished items whose guessed scores sit nearest the given ones, and the shipped items the project's `docs/score-anchors.md` names for each level of L, E and I, each with what its chunk measured; then the median outcome at each guessed R and S, and how well L, E and I each order the chunks by review rounds and 🔴 findings; then each chunk's 🔴 and 🟡 findings with how many a reviewer marked `[misread]`, code health's counter-signal; `score-outcomes --help` states the measures. - `settings_filter.py` is git's clean filter for `settings.json`: it drops `"model"` and sorts the keys. `.gitattributes` sets the filter `settings` on `settings.json`, and Install's `git config` line makes this script that filter. - `statusline.py` renders Claude Code's status line; `settings.json` → `statusLine` runs it. @@ -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. `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. +`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, `docker_command.py` among them, `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 diff --git a/agents/stability-reviewer.md b/agents/stability-reviewer.md index 748a14e7..1aa56be5 100644 --- a/agents/stability-reviewer.md +++ b/agents/stability-reviewer.md @@ -13,7 +13,7 @@ You are an elite stability-focused code reviewer with deep expertise in defensiv 2. **Read every file under `~/.claude/principles/`**, the shared principles, and `~/.claude/skills/larv-review/standards/quality.md`. These are mandatory org guidelines; all code MUST comply with each that applies. A file's `Applies to` line says what it covers; one without the line covers every change. Re-read each time — they change. Flag violations prominently. 3. **Read README.md, AGENTS.md and `docs/decisions.md`** in the current project for project-specific conventions, build instructions, tooling, and the accepted trade-offs a reviewer should honor rather than re-flag. Note the documented test, lint, and static-analysis commands — you will run them. 4. **Verify, don't just read.** Run the test suite and static analysis/linters through the project's container tooling, unless a decision puts them on the host; tear down test containers afterwards. Run the full suite under `~/.claude/bin/run-heavy`. Run it in the background or with the Bash tool's longest timeout: that timeout includes the wait for a slot. A full-suite run catches broken callers that diff-reading misses. When a suspected bug is cheap to confirm, reproduce it — a scratch script, a targeted test run — before reporting it. Make scratch work with Bash, since Write is for your report alone. Put it in a directory you create for this run, and delete it when done; delete nothing else, since a directory the prompt names may hold other agents' files. Leave the working tree exactly as you found it. Anything you could not run goes in Coverage & Verification, never silently skipped. -5. **Mutation-test the changed lines.** Run the project's documented mutation command, or else a widely deployed mutation tool for the language: cargo-mutants for Rust, Infection for PHP, mutmut for Python, Stryker for JavaScript and TypeScript. Limit it to the lines the change adds or modifies, through the tool's own option where it has one (cargo-mutants `--in-diff `, Infection `--git-diff-lines`, Stryker `--mutate :`); otherwise mutate only the changed files and keep only the mutants on changed lines. Run it through the project's tooling and run-heavy, as in step 4, on a scratch copy: the tools write files. Report its wall time and mutant count in Coverage & Verification, or why nothing was mutated. Ignore a surviving mutant that leaves behaviour unchanged, or changes only message or log text no caller or user depends on. Report one 🟡 per test to add or strengthen, naming the surviving mutants it would catch. +5. **Mutation-test the changed lines.** Run the project's documented mutation command, or else a widely deployed mutation tool for the language: cargo-mutants for Rust, Infection for PHP, mutmut for Python, Stryker for JavaScript and TypeScript. Limit it to the lines the change adds or modifies, through the tool's own option where it has one (cargo-mutants `--in-diff `, Infection `--git-diff-lines`, Stryker `--mutate :`); otherwise mutate only the changed files and keep only the mutants on changed lines. Run it through the project's tooling and run-heavy, as in step 4, on a scratch copy: the tools write files. Under run-heavy, a container that sets no memory limit gets the slot's share, `RUN_HEAVY_MEMORY` in the command's environment: set the tool's concurrency so that many test runs at once fit in it. Report its wall time and mutant count in Coverage & Verification, or why nothing was mutated. Ignore a surviving mutant that leaves behaviour unchanged, or changes only message or log text no caller or user depends on. Report one 🟡 per test to add or strengthen, naming the surviving mutants it would catch. 6. **Two passes minimum, then hunt absences.** - *Breadth:* every hunk in every changed file, no skimming. Track which files you have covered; batch large diffs, never truncate the review. - *Depth:* trace the riskiest data paths end-to-end (input → logic → persistence/response), the interactions between changed pieces, and between the change and config (timeout hierarchies, retries × idempotency, queue worker counts, env parity). diff --git a/bin/docker_command.py b/bin/docker_command.py index 5cc416b8..d8674e47 100644 --- a/bin/docker_command.py +++ b/bin/docker_command.py @@ -35,20 +35,37 @@ 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) - limited = given(arguments, ("-m", "--memory"), SIZE) and given(arguments, ("--memory-swap",), SWAP) + limited = option_value(arguments, ("-m", "--memory"), SIZE) and option_value(arguments, ("--memory-swap",), SWAP) return subcommand in STARTS_CONTAINER and not limited and not helped(arguments, subcommand) -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 capped(arguments: list[str], share: str) -> list[str]: + """docker's arguments with the limits a container they make lacks, put right after the subcommand: share for each, except a swap limit beside the container's own memory limit, which takes that limit, as docker refuses less swap than memory.""" + if not unlimited(arguments): + return arguments + memory = option_value(arguments, ("-m", "--memory"), SIZE) + after = arguments.index(docker_subcommand(arguments)[-1]) + 1 + limits = ["--memory-swap", memory] if memory else ["--memory", share, "--memory-swap", share] + return [*arguments[:after], *limits, *arguments[after:]] + + +def option_value(arguments: list[str], options: tuple[str, ...], pattern: str) -> str | None: + """The value the arguments give one of the options, where pattern matches it, as its next word or attached, as in -m4g or --memory=4g; None where they give none.""" + for word, following in zip(arguments, [*arguments[1:], ""]): + for option in options: + attached = word.removeprefix(option if len(option) == 2 else option + "=") + if attached != word and re.fullmatch(pattern, attached): + return attached + if word == option and re.fullmatch(pattern, following): + return following + return None def unlimited_container(words: list[str]) -> bool: """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) + # Under run-heavy, its docker adds the limits a container lacks. + return docker is not None and "run-heavy" not in docker.launchers and unlimited(docker.arguments) def helped(arguments: list[str], subcommand: list[str]) -> bool: diff --git a/bin/rule_hook/test_rule_hook.py b/bin/rule_hook/test_rule_hook.py index c2dc47e2..77baae68 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'", "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"]: + 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", "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"]) 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 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"]: + 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", "~/.claude/bin/run-heavy docker run alpine:3.22.2 true"]: with self.subTest(command): self.assertEqual(checked(command), []) diff --git a/bin/run-heavy b/bin/run-heavy index fb623b82..ef38f4a2 100755 --- a/bin/run-heavy +++ b/bin/run-heavy @@ -5,7 +5,8 @@ import sys sys.path.insert(0, str(pathlib.Path(__file__).resolve().parent)) +from machine_load.memory import read_memory from machine_load.slots import usable_cpus from run_heavy import main -sys.exit(main.main(sys.argv[1:], os.environ, usable_cpus())) +sys.exit(main.main(sys.argv[1:], os.environ, usable_cpus(), read_memory())) diff --git a/bin/run_heavy/capped_docker.py b/bin/run_heavy/capped_docker.py new file mode 100644 index 00000000..427680f7 --- /dev/null +++ b/bin/run_heavy/capped_docker.py @@ -0,0 +1,23 @@ +"""The docker a heavy command finds first on its PATH: it gives a container the command makes the limits it lacks, the slot's memory share in RUN_HEAVY_MEMORY, then runs the real docker.""" +import os +import pathlib +import shutil +import sys +import typing + +from docker_command import capped + +FOLDER = pathlib.Path(__file__).resolve().parent / "path_entry" +SHARE = "RUN_HEAVY_MEMORY" +NOT_FOUND = 127 + + +def main(argv: list[str], env: typing.Mapping[str, str]) -> int: + """Replaces this process with the real docker; returns only where none is found.""" + path = os.pathsep.join(entry for entry in env.get("PATH", "").split(os.pathsep) if pathlib.Path(entry or ".").resolve() != FOLDER) + docker = shutil.which("docker", path=path) + if docker is None: + print("run-heavy: docker: command not found", file=sys.stderr) + return NOT_FOUND + share = env.get(SHARE) + os.execve(docker, [docker, *(capped(argv, share) if share else argv)], {**env, "PATH": path}) diff --git a/bin/run_heavy/main.py b/bin/run_heavy/main.py index 1a72a596..7bb31cd8 100644 --- a/bin/run_heavy/main.py +++ b/bin/run_heavy/main.py @@ -9,6 +9,12 @@ $XDG_STATE_HOME/run-heavy (default ~/.local/state/run-heavy). While every slot i says so once on stderr and waits. It then replaces itself with the command. The slot's lock stays held until the command, and every process that inherited the lock, exits. Its exit code is the command's. +Each container the command makes with docker run or docker create gets a memory limit and a swap limit, +both the slot's share, where it sets neither: three quarters of the machine's memory, split across the +slots. A docker first on the command's PATH adds them, and passes every other call on unchanged. A +container that sets its own memory limit keeps it, with a swap limit as large. The share is in +RUN_HEAVY_MEMORY. A docker compose service, or a docker named by its full path, gets no limit. + A command it runs carries the slot's number in RUN_HEAVY_SLOT, and run-heavy called with that set runs its command at once, so a gate that wraps its own steps cannot wait on itself. @@ -21,6 +27,8 @@ import sys import typing from failure import Failure +from run_heavy.capped_docker import FOLDER, SHARE +from machine_load.memory import Memory from machine_load.slots import slot_count, slot_folder, waited_slot OWN_FAILURE = 125 @@ -30,7 +38,7 @@ HELD = "RUN_HEAVY_SLOT" USAGE = "usage: run-heavy [...]" -def main(argv: list[str], env: typing.Mapping[str, str], cpus: int | None) -> int: +def main(argv: list[str], env: typing.Mapping[str, str], cpus: int | None, memory: Memory | None) -> int: if argv[:1] in (["-h"], ["--help"]): print(__doc__.strip()) return 0 @@ -42,10 +50,17 @@ def main(argv: list[str], env: typing.Mapping[str, str], cpus: int | None) -> in if isinstance(slot, Failure): print(f"run-heavy: {slot.reason}", file=sys.stderr) return OWN_FAILURE - env = {**env, HELD: str(slot)} + env = {**env, HELD: str(slot), **capping(memory, slot_count(cpus), env)} return run(argv, env) +def capping(memory: Memory | None, slots: int, env: typing.Mapping[str, str]) -> dict[str, str]: + """What the command's environment needs for its docker to cap each container it makes at the slot's share: three quarters of the memory, which the quarter loop-claude keeps free for a worker leaves, split across the slots. Nothing where the memory is unknown, as off Linux.""" + if memory is None: + return {} + return {SHARE: f"{memory.total * 3 // 4 // slots // 1024}m", "PATH": os.pathsep.join([str(FOLDER), env.get("PATH", "")])} + + def held_slot(folder: pathlib.Path, slots: int) -> int | Failure: """The number of the slot this call holds, its lock left for the command to inherit, or why no slot could be taken.""" try: diff --git a/bin/run_heavy/path_entry/docker b/bin/run_heavy/path_entry/docker new file mode 100755 index 00000000..d2eaa6d9 --- /dev/null +++ b/bin/run_heavy/path_entry/docker @@ -0,0 +1,10 @@ +#!/usr/bin/env python3 +import os +import pathlib +import sys + +sys.path.insert(0, str(pathlib.Path(__file__).resolve().parents[2])) + +from run_heavy import capped_docker + +sys.exit(capped_docker.main(sys.argv[1:], os.environ)) diff --git a/bin/run_heavy/test_run_heavy.py b/bin/run_heavy/test_run_heavy.py index b3ebd623..68cb890d 100644 --- a/bin/run_heavy/test_run_heavy.py +++ b/bin/run_heavy/test_run_heavy.py @@ -10,6 +10,7 @@ import unittest sys.path.insert(0, str(pathlib.Path(__file__).resolve().parents[1])) from run_heavy import main +from machine_load.memory import read_memory from machine_load.slots import slot_count, usable_cpus TOOL = pathlib.Path(__file__).resolve().parents[1] / "run-heavy" @@ -82,6 +83,37 @@ class RunHeavy(unittest.TestCase): self.assertEqual((denied.returncode, denied.stdout), (126, "")) self.assertIn(unrunnable.name, denied.stderr) + def fake_docker(self) -> dict[str, str]: + """An environment whose PATH finds, ahead of any real one, a docker that prints the arguments it was given.""" + folder = tempfile.TemporaryDirectory() + self.addCleanup(folder.cleanup) + docker = pathlib.Path(folder.name) / "docker" + docker.write_text("#!/bin/sh\necho \"$@\"\n") + docker.chmod(0o755) + return {**self.env, "PATH": f"{folder.name}:{self.env['PATH']}"} + + def test_a_docker_run_without_limits_gets_three_quarters_of_the_memory_split_across_the_slots(self): + memory = read_memory() + assert memory is not None + share = f"{memory.total * 3 // 4 // slot_count(usable_cpus()) // 1024}m" + result = self.run_tool("docker", "run", "--rm", "img", "true", env=self.fake_docker()) + self.assertEqual((result.returncode, result.stdout), (0, f"run --memory {share} --memory-swap {share} --rm img true\n")) + + def test_a_docker_call_with_its_own_limits_or_that_starts_no_container_is_passed_on_unchanged(self): + env = self.fake_docker() + for args in [["run", "-m", "40g", "--memory-swap", "40g", "img"], ["ps", "-a"], ["build", "."]]: + with self.subTest(args): + result = self.run_tool("docker", *args, env=env) + self.assertEqual((result.returncode, result.stdout), (0, " ".join(args) + "\n")) + + def test_a_capped_docker_that_finds_no_docker_exits_127_saying_so(self): + folder = tempfile.TemporaryDirectory() + self.addCleanup(folder.cleanup) + (pathlib.Path(folder.name) / "python3").symlink_to(sys.executable) + result = self.run_tool("docker", "ps", env={**self.env, "PATH": folder.name}) + self.assertEqual((result.returncode, result.stdout), (127, "")) + self.assertIn("docker", result.stderr) + def test_no_command_exits_125_with_the_usage_and_help_exits_0(self): bare = self.run_tool() self.assertEqual((bare.returncode, bare.stdout), (125, "")) diff --git a/bin/test_docker_command.py b/bin/test_docker_command.py new file mode 100644 index 00000000..57f63fb1 --- /dev/null +++ b/bin/test_docker_command.py @@ -0,0 +1,28 @@ +import unittest + +from docker_command import capped + + +class Capped(unittest.TestCase): + def test_a_container_without_limits_gets_the_share_for_both(self): + for given, expected in [ + (["run", "--rm", "img", "true"], ["run", "--memory", "6144m", "--memory-swap", "6144m", "--rm", "img", "true"]), + (["-H", "unix:///d.sock", "run", "img"], ["-H", "unix:///d.sock", "run", "--memory", "6144m", "--memory-swap", "6144m", "img"]), + (["container", "create", "img"], ["container", "create", "--memory", "6144m", "--memory-swap", "6144m", "img"]), + (["run", "img", "python", "-m", "pytest"], ["run", "--memory", "6144m", "--memory-swap", "6144m", "img", "python", "-m", "pytest"]), + ]: + with self.subTest(given): + self.assertEqual(capped(given, "6144m"), expected) + + def test_a_container_s_own_memory_limit_is_kept_and_caps_its_swap(self): + self.assertEqual(capped(["run", "-m", "10g", "img"], "6144m"), ["run", "--memory-swap", "10g", "-m", "10g", "img"]) + self.assertEqual(capped(["run", "--memory=12g", "img"], "6144m"), ["run", "--memory-swap", "12g", "--memory=12g", "img"]) + + def test_a_container_with_both_limits_or_another_docker_call_is_left_alone(self): + for given in [["run", "-m", "10g", "--memory-swap", "12g", "img"], ["ps"], ["build", "."], ["run", "--help"], ["compose", "run", "app"], ["exec", "box", "true"]]: + with self.subTest(given): + self.assertEqual(capped(given, "6144m"), given) + + +if __name__ == "__main__": + unittest.main() diff --git a/docs/decisions.md b/docs/decisions.md index b4dc0e70..d4e1e689 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 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 +## 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`; under run-heavy, a container that lacks them gets the slot's share of three quarters of the memory; and no daemon-wide cap limits all containers together -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. +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. + +The heavy command in that hang started its container from the project's own script, out of rule-hook's sight. So run-heavy puts first on its command's `PATH` a `docker`, `bin/run_heavy/path_entry/docker`, which gives each `docker run` or `docker create` that lacks a limit the slot's share: three quarters of MemTotal, which the quarter a worker waits for leaves, split evenly across the slots (todo item 227). A container that sets its own memory limit keeps it, with a swap limit as large, since docker refuses less swap than memory. run-heavy cannot place the command in a cgroup instead: none is delegated to the user, and dockerd starts the containers outside the command's process tree. A compose service, and a docker named by its full path, keep no cap. 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. diff --git a/todo.md b/todo.md index e02067cd..170cbd8c 100644 --- a/todo.md +++ b/todo.md @@ -16,7 +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 | -| 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,14 +86,6 @@ 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. -### 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, 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 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. 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 52641079b7655f1040cb049db8a4fac0c8a68cd0 Mon Sep 17 00:00:00 2001 From: Lilleman auf Larv Date: Sat, 24 Oct 2026 11:24:21 +0200 Subject: [PATCH 20/55] =?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);=20keep=20the?= =?UTF-8?q?=20slot's=20share=20beside=20ROOM=5FSHARE=20in=20machine=5Fload?= =?UTF-8?q?,=20move=20the=20rule's=20predicate=20into=20rule=5Fhook,=20and?= =?UTF-8?q?=20have=20capped=20set=20both=20limits=20itself=20instead=20of?= =?UTF-8?q?=20leaning=20on=20docker=20taking=20the=20last=20option?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- CHANGELOG.md | 2 +- bin/docker_command.py | 48 +++++++++++++++++++++++--------------- bin/machine_load/memory.py | 6 ++++- bin/rule_hook/rules.py | 11 +++++++-- bin/run_heavy/main.py | 9 +++---- bin/test_docker_command.py | 13 ++++++++--- docs/decisions.md | 2 +- 7 files changed, 60 insertions(+), 31 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 74afaf5e..0a3ece9f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,7 +2,7 @@ ## Unreleased -- `run-heavy` now caps the memory of each container its command makes. Where a `docker run` or `docker create` sets no limit, it gets a memory limit and a swap limit, both the slot's share: three quarters of the machine's memory, split across the heavy slots. A container that sets its own memory limit keeps it. This covers containers a project's own scripts start, which rule-hook can't see. rule-hook's `docker-run-memory` now lets a `docker run` under run-heavy pass. +- `run-heavy` now caps the memory of each container its command makes. Where a `docker run` or `docker create` sets no limit, it gets a memory limit and a swap limit, both the slot's share: three quarters of the machine's memory, split across the heavy slots. A container that sets one of the two limits keeps it, and gets the other as large. This covers containers a project's own scripts start, which rule-hook can't see. rule-hook's `docker-run-memory` now lets a `docker run` under run-heavy pass. - 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. diff --git a/bin/docker_command.py b/bin/docker_command.py index d8674e47..abc47d86 100644 --- a/bin/docker_command.py +++ b/bin/docker_command.py @@ -1,16 +1,18 @@ -"""What a docker command asks of docker: its subcommand, and whether a container it starts has a memory limit and a swap limit.""" +"""What a docker command asks of docker: its subcommand, whether a container it makes has a memory limit and a swap limit, and those arguments with the limits a container lacks.""" 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 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]?" +MEMORY_OPTIONS = ("-m", "--memory") +SWAP_OPTIONS = ("--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}" +# Any value --memory-swap takes, -1 and 0 among them. +ANY_SWAP = rf"-1|{SIZE}" def docker_subcommand(arguments: list[str]) -> list[str]: @@ -35,39 +37,47 @@ 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) - limited = option_value(arguments, ("-m", "--memory"), SIZE) and option_value(arguments, ("--memory-swap",), SWAP) + limited = option_value(arguments, MEMORY_OPTIONS, SIZE) and option_value(arguments, SWAP_OPTIONS, SWAP) return subcommand in STARTS_CONTAINER and not limited and not helped(arguments, subcommand) def capped(arguments: list[str], share: str) -> list[str]: - """docker's arguments with the limits a container they make lacks, put right after the subcommand: share for each, except a swap limit beside the container's own memory limit, which takes that limit, as docker refuses less swap than memory.""" + """docker's arguments with both limits set right after the subcommand, where a container they make lacks one: the container's own memory limit, or else its swap limit, or else share, for each. Its swap limit stays where it has one; an unlimited or unset one gives way.""" if not unlimited(arguments): return arguments - memory = option_value(arguments, ("-m", "--memory"), SIZE) - after = arguments.index(docker_subcommand(arguments)[-1]) + 1 - limits = ["--memory-swap", memory] if memory else ["--memory", share, "--memory-swap", share] - return [*arguments[:after], *limits, *arguments[after:]] + memory = option_value(arguments, MEMORY_OPTIONS, SIZE) or option_value(arguments, SWAP_OPTIONS, SWAP) or share + swap = option_value(arguments, SWAP_OPTIONS, SWAP) or memory + rest = without(without(arguments, MEMORY_OPTIONS, SIZE), SWAP_OPTIONS, ANY_SWAP) + after = rest.index(docker_subcommand(rest)[-1]) + 1 + return [*rest[:after], "--memory", memory, "--memory-swap", swap, *rest[after:]] def option_value(arguments: list[str], options: tuple[str, ...], pattern: str) -> str | None: """The value the arguments give one of the options, where pattern matches it, as its next word or attached, as in -m4g or --memory=4g; None where they give none.""" - for word, following in zip(arguments, [*arguments[1:], ""]): + found = option_at(arguments, options, pattern) + return found[2] if found else None + + +def without(arguments: list[str], options: tuple[str, ...], pattern: str) -> list[str]: + """The arguments with each of the options removed, with its value, where pattern matches the value.""" + while found := option_at(arguments, options, pattern): + start, length, _ = found + arguments = [*arguments[:start], *arguments[start + length:]] + return arguments + + +def option_at(arguments: list[str], options: tuple[str, ...], pattern: str) -> tuple[int, int, str] | None: + """Where the arguments first give one of the options a value pattern matches: its index, its length in words and the value.""" + for at, (word, following) in enumerate(zip(arguments, [*arguments[1:], ""])): for option in options: attached = word.removeprefix(option if len(option) == 2 else option + "=") if attached != word and re.fullmatch(pattern, attached): - return attached + return at, 1, attached if word == option and re.fullmatch(pattern, following): - return following + return at, 2, following return None -def unlimited_container(words: list[str]) -> bool: - """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"}) - # Under run-heavy, its docker adds the limits a container lacks. - return docker is not None and "run-heavy" not in docker.launchers 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 diff --git a/bin/machine_load/memory.py b/bin/machine_load/memory.py index 7ca25d94..f0f81985 100644 --- a/bin/machine_load/memory.py +++ b/bin/machine_load/memory.py @@ -1,4 +1,4 @@ -"""How much of the machine's memory is available, as /proc/meminfo's MemAvailable and MemTotal state it, and whether at least ROOM_SHARE of it is available, which leaves room for a worker.""" +"""How much of the machine's memory is available, as /proc/meminfo's MemAvailable and MemTotal state it, whether at least ROOM_SHARE of it is available, which leaves room for a worker, and each heavy slot's share of the rest.""" import dataclasses import pathlib import re @@ -17,6 +17,10 @@ class Memory: def has_room(self) -> bool: return self.available >= ROOM_SHARE * self.total + def slot_share(self, slots: int) -> str: + """The memory each heavy slot's containers may take, as docker writes a size: what ROOM_SHARE leaves, split evenly across the slots.""" + return f"{int(self.total * (1 - ROOM_SHARE)) // slots // 1024}m" + def parsed(meminfo: str) -> Memory | None: """The memory a /proc/meminfo text states; None where it lacks MemAvailable or MemTotal.""" diff --git a/bin/rule_hook/rules.py b/bin/rule_hook/rules.py index 02192686..7784ad38 100644 --- a/bin/rule_hook/rules.py +++ b/bin/rule_hook/rules.py @@ -6,9 +6,9 @@ import typing from round_titles import CAP, lacks_counts, past_cap from git_command import commits from rule_hook.heavy_command import heavy +from shell_command import launched, Simple from review_folder import REPORTS -from shell_command import Simple -from docker_command import unlimited_container +from docker_command import unlimited 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"] @@ -151,6 +151,13 @@ def command_breaches(command: str, simples: list[Simple], home: str) -> list[Bre return breaches +def unlimited_container(words: list[str]) -> bool: + """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"}) + # Under run-heavy, its docker adds the limits a container lacks. + return docker is not None and "run-heavy" not in docker.launchers and unlimited(docker.arguments) + + def file_breaches(path: str, before: str, added: str, after: str) -> list[Breach]: """Breaches in an edit of path: added is the text the edit writes, after the whole file it leaves.""" breaches = [Breach("no-ai-attribution", f"{path} would carry an attribution", posixpath.dirname(path))] if ATTRIBUTION.search(added) else [] diff --git a/bin/run_heavy/main.py b/bin/run_heavy/main.py index 7bb31cd8..d2893ea0 100644 --- a/bin/run_heavy/main.py +++ b/bin/run_heavy/main.py @@ -12,8 +12,9 @@ until the command, and every process that inherited the lock, exits. Its exit co Each container the command makes with docker run or docker create gets a memory limit and a swap limit, both the slot's share, where it sets neither: three quarters of the machine's memory, split across the slots. A docker first on the command's PATH adds them, and passes every other call on unchanged. A -container that sets its own memory limit keeps it, with a swap limit as large. The share is in -RUN_HEAVY_MEMORY. A docker compose service, or a docker named by its full path, gets no limit. +container that sets one of the two limits keeps it, and gets the other as large; an unlimited +swap, --memory-swap -1, gives way. The share is in RUN_HEAVY_MEMORY. A docker compose service, +or a docker named by its full path, gets no limit. A command it runs carries the slot's number in RUN_HEAVY_SLOT, and run-heavy called with that set runs its command at once, so a gate that wraps its own steps cannot wait on itself. @@ -55,10 +56,10 @@ def main(argv: list[str], env: typing.Mapping[str, str], cpus: int | None, memor def capping(memory: Memory | None, slots: int, env: typing.Mapping[str, str]) -> dict[str, str]: - """What the command's environment needs for its docker to cap each container it makes at the slot's share: three quarters of the memory, which the quarter loop-claude keeps free for a worker leaves, split across the slots. Nothing where the memory is unknown, as off Linux.""" + """What the command's environment needs for its docker to cap each container it makes at the slot's share of memory; nothing where the memory is unknown, as off Linux.""" if memory is None: return {} - return {SHARE: f"{memory.total * 3 // 4 // slots // 1024}m", "PATH": os.pathsep.join([str(FOLDER), env.get("PATH", "")])} + return {SHARE: memory.slot_share(slots), "PATH": os.pathsep.join([str(FOLDER), env.get("PATH", "")])} def held_slot(folder: pathlib.Path, slots: int) -> int | Failure: diff --git a/bin/test_docker_command.py b/bin/test_docker_command.py index 57f63fb1..a8a44efb 100644 --- a/bin/test_docker_command.py +++ b/bin/test_docker_command.py @@ -14,9 +14,16 @@ class Capped(unittest.TestCase): with self.subTest(given): self.assertEqual(capped(given, "6144m"), expected) - def test_a_container_s_own_memory_limit_is_kept_and_caps_its_swap(self): - self.assertEqual(capped(["run", "-m", "10g", "img"], "6144m"), ["run", "--memory-swap", "10g", "-m", "10g", "img"]) - self.assertEqual(capped(["run", "--memory=12g", "img"], "6144m"), ["run", "--memory-swap", "12g", "--memory=12g", "img"]) + def test_a_container_s_own_limit_is_kept_and_sets_the_limit_it_lacks(self): + for given, expected in [ + (["run", "-m", "10g", "img"], ["run", "--memory", "10g", "--memory-swap", "10g", "img"]), + (["run", "--memory=12g", "img"], ["run", "--memory", "12g", "--memory-swap", "12g", "img"]), + (["run", "--memory-swap", "2g", "img"], ["run", "--memory", "2g", "--memory-swap", "2g", "img"]), + (["run", "-m", "4g", "--memory-swap", "-1", "img"], ["run", "--memory", "4g", "--memory-swap", "4g", "img"]), + (["run", "-m4g", "--memory-swap=0", "img", "python", "-m", "pytest"], ["run", "--memory", "4g", "--memory-swap", "4g", "img", "python", "-m", "pytest"]), + ]: + with self.subTest(given): + self.assertEqual(capped(given, "6144m"), expected) def test_a_container_with_both_limits_or_another_docker_call_is_left_alone(self): for given in [["run", "-m", "10g", "--memory-swap", "12g", "img"], ["ps"], ["build", "."], ["run", "--help"], ["compose", "run", "app"], ["exec", "box", "true"]]: diff --git a/docs/decisions.md b/docs/decisions.md index d4e1e689..873a3055 100644 --- a/docs/decisions.md +++ b/docs/decisions.md @@ -80,7 +80,7 @@ The cap is 5, `bin/todo_table.py`'s `BUNDLE_MAX_R`, from the same chunks: by the 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. -The heavy command in that hang started its container from the project's own script, out of rule-hook's sight. So run-heavy puts first on its command's `PATH` a `docker`, `bin/run_heavy/path_entry/docker`, which gives each `docker run` or `docker create` that lacks a limit the slot's share: three quarters of MemTotal, which the quarter a worker waits for leaves, split evenly across the slots (todo item 227). A container that sets its own memory limit keeps it, with a swap limit as large, since docker refuses less swap than memory. run-heavy cannot place the command in a cgroup instead: none is delegated to the user, and dockerd starts the containers outside the command's process tree. A compose service, and a docker named by its full path, keep no cap. +The heavy command in that hang started its container from the project's own script, out of rule-hook's sight. So run-heavy puts first on its command's `PATH` a `docker`, `bin/run_heavy/path_entry/docker`, which gives each `docker run` or `docker create` that lacks a limit the slot's share: three quarters of MemTotal, which the quarter a worker waits for leaves, split evenly across the slots (todo item 227). A container that sets one of the two limits keeps it, and gets the other as large, since docker refuses less swap than memory; an unlimited swap, `--memory-swap -1`, gives way. run-heavy cannot place the command in a cgroup instead: none is delegated to the user, and dockerd starts the containers outside the command's process tree. A compose service, and a docker named by its full path, keep no cap. 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. From 5649331a5eaea69cca8c9dd3f14b4f4e7fcd9807 Mon Sep 17 00:00:00 2001 From: Lilleman auf Larv Date: Sat, 24 Oct 2026 11:25:58 +0200 Subject: [PATCH 21/55] =?UTF-8?q?Answer=20architecture=20round=202:=200=20?= =?UTF-8?q?=F0=9F=94=B4,=201=20=F0=9F=9F=A1=20(0=20misread);=20capped=20ad?= =?UTF-8?q?ds=20only=20the=20limit=20a=20container=20lacks=20and=20removes?= =?UTF-8?q?=20only=20an=20unset=20or=20unlimited=20swap,=20so=20a=20size?= =?UTF-8?q?=20in=20the=20container's=20own=20command=20stays?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- bin/docker_command.py | 19 ++++++++++--------- bin/test_docker_command.py | 9 +++++---- 2 files changed, 15 insertions(+), 13 deletions(-) diff --git a/bin/docker_command.py b/bin/docker_command.py index abc47d86..a99ea2ad 100644 --- a/bin/docker_command.py +++ b/bin/docker_command.py @@ -9,10 +9,10 @@ STARTS_CONTAINER = (["container", "create"], ["container", "run"], ["create"], [ SIZE = r"\d+(?:\.\d+)*[kKmMgGtTpP]?[iI]?[bB]?" MEMORY_OPTIONS = ("-m", "--memory") SWAP_OPTIONS = ("--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}" -# Any value --memory-swap takes, -1 and 0 among them. -ANY_SWAP = rf"-1|{SIZE}" +# The values with which docker leaves swap without a limit: -1 for unlimited swap, and 0, in any unit, for unset. +UNSET_SWAP = r"-1|0+(?:\.0+)*[kKmMgGtTpP]?[iI]?[bB]?" +# A swap limit is any other size. +SWAP = rf"(?!(?:{UNSET_SWAP})$){SIZE}" def docker_subcommand(arguments: list[str]) -> list[str]: @@ -42,14 +42,15 @@ def unlimited(arguments: list[str]) -> bool: def capped(arguments: list[str], share: str) -> list[str]: - """docker's arguments with both limits set right after the subcommand, where a container they make lacks one: the container's own memory limit, or else its swap limit, or else share, for each. Its swap limit stays where it has one; an unlimited or unset one gives way.""" + """docker's arguments with the limit a container they make lacks put right after the subcommand: the container's other limit, or share where it sets neither, as docker refuses less swap than memory. An unset or unlimited swap value gives way; every other word stays.""" if not unlimited(arguments): return arguments - memory = option_value(arguments, MEMORY_OPTIONS, SIZE) or option_value(arguments, SWAP_OPTIONS, SWAP) or share - swap = option_value(arguments, SWAP_OPTIONS, SWAP) or memory - rest = without(without(arguments, MEMORY_OPTIONS, SIZE), SWAP_OPTIONS, ANY_SWAP) + memory = option_value(arguments, MEMORY_OPTIONS, SIZE) + swap = option_value(arguments, SWAP_OPTIONS, SWAP) + rest = without(arguments, SWAP_OPTIONS, UNSET_SWAP) + limits = ([] if memory else ["--memory", swap or share]) + ([] if swap else ["--memory-swap", memory or share]) after = rest.index(docker_subcommand(rest)[-1]) + 1 - return [*rest[:after], "--memory", memory, "--memory-swap", swap, *rest[after:]] + return [*rest[:after], *limits, *rest[after:]] def option_value(arguments: list[str], options: tuple[str, ...], pattern: str) -> str | None: diff --git a/bin/test_docker_command.py b/bin/test_docker_command.py index a8a44efb..01105663 100644 --- a/bin/test_docker_command.py +++ b/bin/test_docker_command.py @@ -16,11 +16,12 @@ class Capped(unittest.TestCase): def test_a_container_s_own_limit_is_kept_and_sets_the_limit_it_lacks(self): for given, expected in [ - (["run", "-m", "10g", "img"], ["run", "--memory", "10g", "--memory-swap", "10g", "img"]), - (["run", "--memory=12g", "img"], ["run", "--memory", "12g", "--memory-swap", "12g", "img"]), + (["run", "-m", "10g", "img"], ["run", "--memory-swap", "10g", "-m", "10g", "img"]), + (["run", "--memory=12g", "img"], ["run", "--memory-swap", "12g", "--memory=12g", "img"]), (["run", "--memory-swap", "2g", "img"], ["run", "--memory", "2g", "--memory-swap", "2g", "img"]), - (["run", "-m", "4g", "--memory-swap", "-1", "img"], ["run", "--memory", "4g", "--memory-swap", "4g", "img"]), - (["run", "-m4g", "--memory-swap=0", "img", "python", "-m", "pytest"], ["run", "--memory", "4g", "--memory-swap", "4g", "img", "python", "-m", "pytest"]), + (["run", "-m", "4g", "--memory-swap", "-1", "img"], ["run", "--memory-swap", "4g", "-m", "4g", "img"]), + (["run", "-m4g", "--memory-swap=0", "img", "python", "-m", "pytest"], ["run", "--memory-swap", "4g", "-m4g", "img", "python", "-m", "pytest"]), + (["run", "img", "app", "-m", "512m"], ["run", "--memory-swap", "512m", "img", "app", "-m", "512m"]), ]: with self.subTest(given): self.assertEqual(capped(given, "6144m"), expected) From 2eb6fc828f1e5a468cceac469288a9bbf6110e40 Mon Sep 17 00:00:00 2001 From: Lilleman auf Larv Date: Sat, 24 Oct 2026 11:26:42 +0200 Subject: [PATCH 22/55] =?UTF-8?q?Answer=20architecture=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 2fa328a4068cf9f8afb1e3f0092f28af35277fa7 Mon Sep 17 00:00:00 2001 From: Lilleman auf Larv Date: Sat, 24 Oct 2026 11:31:10 +0200 Subject: [PATCH 23/55] =?UTF-8?q?Answer=20principles=20round=201:=200=20?= =?UTF-8?q?=F0=9F=94=B4,=204=20=F0=9F=9F=A1=20(0=20misread);=20exempt=20on?= =?UTF-8?q?ly=20a=20bare=20docker=20under=20run-heavy=20with=20no=20PATH?= =?UTF-8?q?=20of=20its=20own,=20drop=20the=20stale=20item=20citation,=20un?= =?UTF-8?q?it-test=20the=20slot=20share=20in=20MiB,=20place=20the=20limits?= =?UTF-8?q?=20by=20the=20subcommand's=20index;=20also=20a=20named=20Option?= =?UTF-8?q?,=20exit=20126,=20clearer=20names=20and=20the=20launcher's=20im?= =?UTF-8?q?port=20order?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- AGENTS.md | 2 +- CHANGELOG.md | 2 +- CLAUDE.md | 2 +- README.md | 4 +- agents/stability-reviewer.md | 2 +- bin/docker_command.py | 104 +++++++++++++++++--------- bin/machine_load/memory.py | 8 +- bin/machine_load/test_machine_load.py | 6 ++ bin/rule_hook/rules.py | 9 ++- bin/rule_hook/test_rule_hook.py | 4 +- bin/run-heavy | 2 +- bin/run_heavy/capped_docker.py | 26 +++++-- bin/run_heavy/main.py | 27 ++++--- bin/run_heavy/test_run_heavy.py | 11 ++- bin/test_docker_command.py | 3 + docs/decisions.md | 4 +- 16 files changed, 144 insertions(+), 72 deletions(-) diff --git a/AGENTS.md b/AGENTS.md index 85b02c5d..b09427d3 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 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`; under run-heavy, a container that lacks them gets the slot's share of three quarters of the memory; 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; rule-hook's `docker-run-memory` blocks a `docker run` or `docker create` without them outside run-heavy, under which a container that lacks them gets the slot's share of three quarters of the memory; 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 0a3ece9f..c6fbe3a3 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,7 +2,7 @@ ## Unreleased -- `run-heavy` now caps the memory of each container its command makes. Where a `docker run` or `docker create` sets no limit, it gets a memory limit and a swap limit, both the slot's share: three quarters of the machine's memory, split across the heavy slots. A container that sets one of the two limits keeps it, and gets the other as large. This covers containers a project's own scripts start, which rule-hook can't see. rule-hook's `docker-run-memory` now lets a `docker run` under run-heavy pass. +- On Linux, `run-heavy` now caps the memory of a container its command makes with `docker run` or `docker create`. A container that sets no limit gets a memory limit and a swap limit, both the slot's share: three quarters of the machine's memory, split across the heavy slots. A container that sets one of the two limits keeps it, and gets the other as large. This covers containers a project's own scripts start, which rule-hook can't see. A `docker compose` service, and a docker named by its full path, get no cap. rule-hook's `docker-run-memory` now lets a `docker run` under run-heavy pass. - 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. diff --git a/CLAUDE.md b/CLAUDE.md index dd9100f0..ac1b89b3 100644 --- a/CLAUDE.md +++ b/CLAUDE.md @@ -66,7 +66,7 @@ The rules only reviewers apply, for quality, comments, READMEs and prose, live i - 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, and gives each container the command makes without limits the slot's share of memory. Run it in the background, since the wait can outlast the Bash tool's timeout. +- 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. It also caps each container the command makes at the slot's share of memory, where the container sets no limits; give a container that needs more its own. 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. 2. An escalated task, below: the rung loop-claude's prompt names for escalation, or case 3's rung where the subagent files or scores `todo.md` items and that rung is higher. diff --git a/README.md b/README.md index f937581d..764a329c 100644 --- a/README.md +++ b/README.md @@ -104,7 +104,7 @@ Install puts only `loop-claude` on `PATH`; call the others by their path, such a - `reading-cost [--reset] [record]` appends a figure for each chunk `loop-claude` finished to a project's `docs/reading-cost.md`, and says whether the figures rise; `reading-cost --help` states the measure. - `review-replay ` replays a review pass's archived rounds from the projects run on the model, on the code each reviewed, and prints the lowest rung below the project's that, like each rung above it, finds every 🔴 and 🟡 the project's rung finds again; `review-replay --help` states the replay. Each replayed reviewer skips every permission prompt, stability-reviewer has Bash, and an archived prompt may name paths on the host. - `rule-hook [overrides]` blocks a tool call that breaks a rule a program can check, unless the call overrides the rule; `settings.json` → `hooks` runs it before each Bash, Edit, MultiEdit, Write and Agent call, and `rule-hook --help` states the rules and the override. -- `run-heavy ` runs a heavy command once it holds one of the machine's heavy slots, one per 4 CPUs, which every session shares; `run-heavy --help` states the slots, and the memory share it gives each container the command makes that lacks a limit. +- `run-heavy ` runs a heavy command once it holds one of the machine's heavy slots, one per 4 CPUs, which every session shares; `run-heavy --help` states the slots, and the memory cap it gives a container that sets no limit. - `score-outcomes [L E I S]` lists the finished items whose guessed scores sit nearest the given ones, and the shipped items the project's `docs/score-anchors.md` names for each level of L, E and I, each with what its chunk measured; then the median outcome at each guessed R and S, and how well L, E and I each order the chunks by review rounds and 🔴 findings; then each chunk's 🔴 and 🟡 findings with how many a reviewer marked `[misread]`, code health's counter-signal; `score-outcomes --help` states the measures. - `settings_filter.py` is git's clean filter for `settings.json`: it drops `"model"` and sorts the keys. `.gitattributes` sets the filter `settings` on `settings.json`, and Install's `git config` line makes this script that filter. - `statusline.py` renders Claude Code's status line; `settings.json` → `statusLine` runs it. @@ -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, `docker_command.py` among them, `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. 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 diff --git a/agents/stability-reviewer.md b/agents/stability-reviewer.md index 1aa56be5..84ae9ec3 100644 --- a/agents/stability-reviewer.md +++ b/agents/stability-reviewer.md @@ -13,7 +13,7 @@ You are an elite stability-focused code reviewer with deep expertise in defensiv 2. **Read every file under `~/.claude/principles/`**, the shared principles, and `~/.claude/skills/larv-review/standards/quality.md`. These are mandatory org guidelines; all code MUST comply with each that applies. A file's `Applies to` line says what it covers; one without the line covers every change. Re-read each time — they change. Flag violations prominently. 3. **Read README.md, AGENTS.md and `docs/decisions.md`** in the current project for project-specific conventions, build instructions, tooling, and the accepted trade-offs a reviewer should honor rather than re-flag. Note the documented test, lint, and static-analysis commands — you will run them. 4. **Verify, don't just read.** Run the test suite and static analysis/linters through the project's container tooling, unless a decision puts them on the host; tear down test containers afterwards. Run the full suite under `~/.claude/bin/run-heavy`. Run it in the background or with the Bash tool's longest timeout: that timeout includes the wait for a slot. A full-suite run catches broken callers that diff-reading misses. When a suspected bug is cheap to confirm, reproduce it — a scratch script, a targeted test run — before reporting it. Make scratch work with Bash, since Write is for your report alone. Put it in a directory you create for this run, and delete it when done; delete nothing else, since a directory the prompt names may hold other agents' files. Leave the working tree exactly as you found it. Anything you could not run goes in Coverage & Verification, never silently skipped. -5. **Mutation-test the changed lines.** Run the project's documented mutation command, or else a widely deployed mutation tool for the language: cargo-mutants for Rust, Infection for PHP, mutmut for Python, Stryker for JavaScript and TypeScript. Limit it to the lines the change adds or modifies, through the tool's own option where it has one (cargo-mutants `--in-diff `, Infection `--git-diff-lines`, Stryker `--mutate :`); otherwise mutate only the changed files and keep only the mutants on changed lines. Run it through the project's tooling and run-heavy, as in step 4, on a scratch copy: the tools write files. Under run-heavy, a container that sets no memory limit gets the slot's share, `RUN_HEAVY_MEMORY` in the command's environment: set the tool's concurrency so that many test runs at once fit in it. Report its wall time and mutant count in Coverage & Verification, or why nothing was mutated. Ignore a surviving mutant that leaves behaviour unchanged, or changes only message or log text no caller or user depends on. Report one 🟡 per test to add or strengthen, naming the surviving mutants it would catch. +5. **Mutation-test the changed lines.** Run the project's documented mutation command, or else a widely deployed mutation tool for the language: cargo-mutants for Rust, Infection for PHP, mutmut for Python, Stryker for JavaScript and TypeScript. Limit it to the lines the change adds or modifies, through the tool's own option where it has one (cargo-mutants `--in-diff `, Infection `--git-diff-lines`, Stryker `--mutate :`); otherwise mutate only the changed files and keep only the mutants on changed lines. Run it through the project's tooling and run-heavy, as in step 4, on a scratch copy: the tools write files. Under run-heavy, a container that sets neither memory limit gets the slot's share, in MiB in `RUN_HEAVY_MEMORY`. Set the tool's concurrency so that its parallel test runs together fit in that share. Report its wall time and mutant count in Coverage & Verification, or why nothing was mutated. Ignore a surviving mutant that leaves behaviour unchanged, or changes only message or log text no caller or user depends on. Report one 🟡 per test to add or strengthen, naming the surviving mutants it would catch. 6. **Two passes minimum, then hunt absences.** - *Breadth:* every hunk in every changed file, no skimming. Track which files you have covered; batch large diffs, never truncate the review. - *Depth:* trace the riskiest data paths end-to-end (input → logic → persistence/response), the interactions between changed pieces, and between the change and config (timeout hierarchies, retries × idempotency, queue worker counts, env parity). diff --git a/bin/docker_command.py b/bin/docker_command.py index a99ea2ad..eea0a460 100644 --- a/bin/docker_command.py +++ b/bin/docker_command.py @@ -1,32 +1,62 @@ -"""What a docker command asks of docker: its subcommand, whether a container it makes has a memory limit and a swap limit, and those arguments with the limits a container lacks.""" +"""What a docker command asks of docker: its subcommand, and whether a container it makes has a memory limit and a swap limit. capped adds the limits such a container lacks.""" import re +import typing # 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 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]?" +# A size as docker reads one, such as 4g, 512M or 1.5GiB: the pattern go-units' RAMInBytes parses, each unit a power of 1024. +SIZE = r"(\d+(?:\.\d+)*)([kKmMgGtTpP]?)[iI]?[bB]?" +# Docker's documented floor for --memory, 6m: a smaller value, such as grep -m 1's, belongs to the container's own command. +MEMORY_FLOOR = 6 * 1024**2 MEMORY_OPTIONS = ("-m", "--memory") SWAP_OPTIONS = ("--memory-swap",) -# The values with which docker leaves swap without a limit: -1 for unlimited swap, and 0, in any unit, for unset. -UNSET_SWAP = r"-1|0+(?:\.0+)*[kKmMgGtTpP]?[iI]?[bB]?" -# A swap limit is any other size. -SWAP = rf"(?!(?:{UNSET_SWAP})$){SIZE}" + + +class Option(typing.NamedTuple): + """An option the arguments give: where it stands, how many words it takes, and its value.""" + at: int + length: int + value: str + + +def size(value: str) -> float | None: + """The bytes a docker size spells; None for a value that is no size.""" + spelled = re.fullmatch(SIZE, value) + return float(spelled.group(1)) * 1024 ** " kmgtp".index(spelled.group(2).lower() or " ") if spelled else None + + +def memory_limit(value: str) -> bool: + return (size(value) or 0) >= MEMORY_FLOOR + + +def swap_limit(value: str) -> bool: + """Whether a --memory-swap value limits swap: -1 leaves it unlimited, and 0 leaves it unset, which docker reads as twice the memory limit.""" + return bool(size(value)) + + +def unset_swap(value: str) -> bool: + return value == "-1" or size(value) == 0 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] = [] + return [arguments[at] for at in subcommand_at(arguments)] + + +def subcommand_at(arguments: list[str]) -> list[int]: + """Where in docker's arguments each word of its subcommand stands, so a global option's value that spells it, as in --context run, is not taken for it.""" + positional: list[int] = [] skip = False - for word in arguments: + for at, word in enumerate(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: + positional.append(at) + if arguments[positional[0]] not in ("buildx", "compose", "container") or len(positional) == 2: break return positional @@ -34,52 +64,54 @@ def docker_subcommand(arguments: list[str]) -> list[str]: def unlimited(arguments: list[str]) -> bool: """Whether docker's arguments make a container, with docker run or docker create, and leave its memory or its swap without a limit. - 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. + 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 and grep -m 1 do not, since neither is a size docker takes. """ subcommand = docker_subcommand(arguments) - limited = option_value(arguments, MEMORY_OPTIONS, SIZE) and option_value(arguments, SWAP_OPTIONS, SWAP) - return subcommand in STARTS_CONTAINER and not limited and not helped(arguments, subcommand) + limited = option_value(arguments, MEMORY_OPTIONS, memory_limit) and option_value(arguments, SWAP_OPTIONS, swap_limit) + return subcommand in STARTS_CONTAINER and not limited and not helped(arguments) def capped(arguments: list[str], share: str) -> list[str]: - """docker's arguments with the limit a container they make lacks put right after the subcommand: the container's other limit, or share where it sets neither, as docker refuses less swap than memory. An unset or unlimited swap value gives way; every other word stays.""" + """docker's arguments, with each limit a container they make lacks added right after the subcommand. + + A container that sets neither limit gets share for both. One that sets one limit gets the other at the same size, since docker refuses less swap than memory. A --memory-swap of -1 or 0 is dropped; every other word stays. + """ if not unlimited(arguments): return arguments - memory = option_value(arguments, MEMORY_OPTIONS, SIZE) - swap = option_value(arguments, SWAP_OPTIONS, SWAP) - rest = without(arguments, SWAP_OPTIONS, UNSET_SWAP) + memory = option_value(arguments, MEMORY_OPTIONS, memory_limit) + swap = option_value(arguments, SWAP_OPTIONS, swap_limit) + rest = without(arguments, SWAP_OPTIONS, unset_swap) limits = ([] if memory else ["--memory", swap or share]) + ([] if swap else ["--memory-swap", memory or share]) - after = rest.index(docker_subcommand(rest)[-1]) + 1 + after = subcommand_at(rest)[-1] + 1 return [*rest[:after], *limits, *rest[after:]] -def option_value(arguments: list[str], options: tuple[str, ...], pattern: str) -> str | None: - """The value the arguments give one of the options, where pattern matches it, as its next word or attached, as in -m4g or --memory=4g; None where they give none.""" - found = option_at(arguments, options, pattern) - return found[2] if found else None +def option_value(arguments: list[str], options: tuple[str, ...], fits: typing.Callable[[str], bool]) -> str | None: + """The value the arguments give one of the options, where it fits, as its next word or attached, as in -m4g or --memory=4g; None where they give none.""" + found = option_at(arguments, options, fits) + return found.value if found else None -def without(arguments: list[str], options: tuple[str, ...], pattern: str) -> list[str]: - """The arguments with each of the options removed, with its value, where pattern matches the value.""" - while found := option_at(arguments, options, pattern): - start, length, _ = found - arguments = [*arguments[:start], *arguments[start + length:]] +def without(arguments: list[str], options: tuple[str, ...], fits: typing.Callable[[str], bool]) -> list[str]: + """The arguments with each of the options removed, with its value, where the value fits.""" + while found := option_at(arguments, options, fits): + arguments = [*arguments[:found.at], *arguments[found.at + found.length:]] return arguments -def option_at(arguments: list[str], options: tuple[str, ...], pattern: str) -> tuple[int, int, str] | None: - """Where the arguments first give one of the options a value pattern matches: its index, its length in words and the value.""" +def option_at(arguments: list[str], options: tuple[str, ...], fits: typing.Callable[[str], bool]) -> Option | None: + """Where the arguments first give one of the options, with a value that fits.""" for at, (word, following) in enumerate(zip(arguments, [*arguments[1:], ""])): for option in options: attached = word.removeprefix(option if len(option) == 2 else option + "=") - if attached != word and re.fullmatch(pattern, attached): - return at, 1, attached - if word == option and re.fullmatch(pattern, following): - return at, 2, following + if attached != word and fits(attached): + return Option(at, 1, attached) + if word == option and fits(following): + return Option(at, 2, following) return None -def helped(arguments: list[str], subcommand: list[str]) -> bool: +def helped(arguments: 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 + after = subcommand_at(arguments)[-1] + 1 return "--help" in arguments[:after + 1] diff --git a/bin/machine_load/memory.py b/bin/machine_load/memory.py index f0f81985..8a902690 100644 --- a/bin/machine_load/memory.py +++ b/bin/machine_load/memory.py @@ -1,4 +1,4 @@ -"""How much of the machine's memory is available, as /proc/meminfo's MemAvailable and MemTotal state it, whether at least ROOM_SHARE of it is available, which leaves room for a worker, and each heavy slot's share of the rest.""" +"""How much of the machine's memory is available, as /proc/meminfo's MemAvailable and MemTotal state it. A worker starts while at least ROOM_SHARE of it is available. The rest is split across the heavy slots, as the memory limit run-heavy gives each container.""" import dataclasses import pathlib import re @@ -17,9 +17,9 @@ class Memory: def has_room(self) -> bool: return self.available >= ROOM_SHARE * self.total - def slot_share(self, slots: int) -> str: - """The memory each heavy slot's containers may take, as docker writes a size: what ROOM_SHARE leaves, split evenly across the slots.""" - return f"{int(self.total * (1 - ROOM_SHARE)) // slots // 1024}m" + def slot_share(self, slots: int) -> int: + """The memory limit, in MiB, that run-heavy gives each container a slot's command makes: what ROOM_SHARE leaves, split evenly across the slots.""" + return int(self.total * (1 - ROOM_SHARE)) // slots // 1024 def parsed(meminfo: str) -> Memory | None: diff --git a/bin/machine_load/test_machine_load.py b/bin/machine_load/test_machine_load.py index 7bb154b2..a73a720d 100644 --- a/bin/machine_load/test_machine_load.py +++ b/bin/machine_load/test_machine_load.py @@ -39,6 +39,12 @@ class MemoryShare(unittest.TestCase): self.assertIsNone(memory.read_memory(pathlib.Path(temp, "gone"))) +class SlotShare(unittest.TestCase): + def test_splits_the_three_quarters_a_worker_leaves_evenly_across_the_slots_in_mib(self): + self.assertEqual(memory.Memory(available=0, total=32 * 1024 * 1024).slot_share(4), 6144) + self.assertEqual(memory.Memory(available=0, total=8000000).slot_share(2), 2929) + + class SlotFolder(unittest.TestCase): def test_every_session_shares_the_slots_under_the_users_state_folder(self): self.assertEqual(slots.slot_folder({}), pathlib.Path.home() / ".local" / "state" / "run-heavy") diff --git a/bin/rule_hook/rules.py b/bin/rule_hook/rules.py index 7784ad38..6f3d6f36 100644 --- a/bin/rule_hook/rules.py +++ b/bin/rule_hook/rules.py @@ -32,7 +32,7 @@ RULES: dict[RuleName, Rule] = { ), "docker-run-memory": Rule( "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", + "docker run, docker create, docker container run and docker container create, whether direct or through a launcher such as nice or timeout. One under run-heavy passes, as run-heavy's docker adds the limits, unless it names docker by its path or sets its own PATH. 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", @@ -154,8 +154,11 @@ def command_breaches(command: str, simples: list[Simple], home: str) -> list[Bre def unlimited_container(words: list[str]) -> bool: """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"}) - # Under run-heavy, its docker adds the limits a container lacks. - return docker is not None and "run-heavy" not in docker.launchers and unlimited(docker.arguments) + if docker is None or not unlimited(docker.arguments): + return False + # On Linux, run-heavy's docker adds the limits a container lacks, where PATH finds it: docker named bare, with no PATH of the command's own. + capped = "run-heavy" in docker.launchers and words[len(words) - len(docker.arguments) - 1] == "docker" and not any(word.startswith("PATH=") for word in words) + return not capped def file_breaches(path: str, before: str, added: str, after: str) -> list[Breach]: diff --git a/bin/rule_hook/test_rule_hook.py b/bin/rule_hook/test_rule_hook.py index 77baae68..bd0f4265 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'", "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", "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"]: + 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", "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", "~/.claude/bin/run-heavy /usr/bin/docker run alpine:3.22.2 true", "docker run --memory-swap 4g alpine:3.22.2 grep -m 1 x", "run-heavy env PATH=/usr/bin 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 --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", "~/.claude/bin/run-heavy docker run alpine:3.22.2 true"]: + 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 --context run 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", "~/.claude/bin/run-heavy docker run alpine:3.22.2 true"]: with self.subTest(command): self.assertEqual(checked(command), []) diff --git a/bin/run-heavy b/bin/run-heavy index ef38f4a2..5ea922bc 100755 --- a/bin/run-heavy +++ b/bin/run-heavy @@ -5,8 +5,8 @@ import sys sys.path.insert(0, str(pathlib.Path(__file__).resolve().parent)) +from run_heavy import main from machine_load.memory import read_memory from machine_load.slots import usable_cpus -from run_heavy import main sys.exit(main.main(sys.argv[1:], os.environ, usable_cpus(), read_memory())) diff --git a/bin/run_heavy/capped_docker.py b/bin/run_heavy/capped_docker.py index 427680f7..ac89ef2e 100644 --- a/bin/run_heavy/capped_docker.py +++ b/bin/run_heavy/capped_docker.py @@ -1,4 +1,4 @@ -"""The docker a heavy command finds first on its PATH: it gives a container the command makes the limits it lacks, the slot's memory share in RUN_HEAVY_MEMORY, then runs the real docker.""" +"""The docker that run-heavy puts first on its command's PATH. It adds the memory limits a container lacks, from the slot's share, then runs the real docker.""" import os import pathlib import shutil @@ -7,17 +7,29 @@ import typing from docker_command import capped -FOLDER = pathlib.Path(__file__).resolve().parent / "path_entry" -SHARE = "RUN_HEAVY_MEMORY" +# The folder run-heavy puts first on its command's PATH, holding the docker that runs main. +PATH_ENTRY = pathlib.Path(__file__).resolve().parent / "path_entry" +# The environment variable that hands this docker the slot's memory share, in MiB. +SHARE_VARIABLE = "RUN_HEAVY_MEMORY" +CANNOT_RUN = 126 NOT_FOUND = 127 def main(argv: list[str], env: typing.Mapping[str, str]) -> int: - """Replaces this process with the real docker; returns only where none is found.""" - path = os.pathsep.join(entry for entry in env.get("PATH", "").split(os.pathsep) if pathlib.Path(entry or ".").resolve() != FOLDER) + """Replaces this process with the real docker; returns only where none is found or it cannot run.""" + path = without_path_entry(env.get("PATH", "")) docker = shutil.which("docker", path=path) if docker is None: print("run-heavy: docker: command not found", file=sys.stderr) return NOT_FOUND - share = env.get(SHARE) - os.execve(docker, [docker, *(capped(argv, share) if share else argv)], {**env, "PATH": path}) + share = env.get(SHARE_VARIABLE) + try: + os.execve(docker, [docker, *(capped(argv, f"{share}m") if share else argv)], {**env, "PATH": path}) + except OSError as failure: + print(f"run-heavy: cannot run {docker}: {failure.strerror}", file=sys.stderr) + return CANNOT_RUN + + +def without_path_entry(path: str) -> str: + """path less PATH_ENTRY, so the real docker is the one found.""" + return os.pathsep.join(entry for entry in path.split(os.pathsep) if pathlib.Path(entry or ".").resolve() != PATH_ENTRY) diff --git a/bin/run_heavy/main.py b/bin/run_heavy/main.py index d2893ea0..a7ee6e52 100644 --- a/bin/run_heavy/main.py +++ b/bin/run_heavy/main.py @@ -9,12 +9,17 @@ $XDG_STATE_HOME/run-heavy (default ~/.local/state/run-heavy). While every slot i says so once on stderr and waits. It then replaces itself with the command. The slot's lock stays held until the command, and every process that inherited the lock, exits. Its exit code is the command's. -Each container the command makes with docker run or docker create gets a memory limit and a swap limit, -both the slot's share, where it sets neither: three quarters of the machine's memory, split across the -slots. A docker first on the command's PATH adds them, and passes every other call on unchanged. A -container that sets one of the two limits keeps it, and gets the other as large; an unlimited -swap, --memory-swap -1, gives way. The share is in RUN_HEAVY_MEMORY. A docker compose service, -or a docker named by its full path, gets no limit. +On Linux, run-heavy also caps the memory of each container the command makes with docker run or +docker create. The cap is the slot's share: three quarters of the machine's memory, split evenly +across the slots, handed to the command in RUN_HEAVY_MEMORY, in MiB. run-heavy puts its own docker +first on the command's PATH. That docker adds the limits a container lacks, then runs the real one: + +- A container that sets neither limit gets a memory limit and a swap limit, both the share. +- A container that sets one of them keeps it, and gets the other at the same size. +- A --memory-swap of -1, unlimited swap, is dropped and replaced. + +Every other docker call goes through unchanged. A docker compose service, and a docker named by its +full path, get no cap: give those containers their own limits. A command it runs carries the slot's number in RUN_HEAVY_SLOT, and run-heavy called with that set runs its command at once, so a gate that wraps its own steps cannot wait on itself. @@ -24,12 +29,13 @@ folder or a slot file cannot be made or locked; 126 when the command is found bu """ import os import pathlib +import shutil import sys import typing from failure import Failure -from run_heavy.capped_docker import FOLDER, SHARE from machine_load.memory import Memory +from run_heavy.capped_docker import PATH_ENTRY, SHARE_VARIABLE, without_path_entry from machine_load.slots import slot_count, slot_folder, waited_slot OWN_FAILURE = 125 @@ -56,10 +62,11 @@ def main(argv: list[str], env: typing.Mapping[str, str], cpus: int | None, memor def capping(memory: Memory | None, slots: int, env: typing.Mapping[str, str]) -> dict[str, str]: - """What the command's environment needs for its docker to cap each container it makes at the slot's share of memory; nothing where the memory is unknown, as off Linux.""" - if memory is None: + """What the command's environment needs for its docker to cap each container it makes at the slot's share of memory; nothing where the memory is unknown, as off Linux, or where PATH finds no docker to cap.""" + path = env.get("PATH", "") + if memory is None or shutil.which("docker", path=without_path_entry(path)) is None: return {} - return {SHARE: memory.slot_share(slots), "PATH": os.pathsep.join([str(FOLDER), env.get("PATH", "")])} + return {SHARE_VARIABLE: str(memory.slot_share(slots)), "PATH": os.pathsep.join([str(PATH_ENTRY), path])} def held_slot(folder: pathlib.Path, slots: int) -> int | Failure: diff --git a/bin/run_heavy/test_run_heavy.py b/bin/run_heavy/test_run_heavy.py index 68cb890d..1519072a 100644 --- a/bin/run_heavy/test_run_heavy.py +++ b/bin/run_heavy/test_run_heavy.py @@ -94,7 +94,8 @@ class RunHeavy(unittest.TestCase): def test_a_docker_run_without_limits_gets_three_quarters_of_the_memory_split_across_the_slots(self): memory = read_memory() - assert memory is not None + if memory is None: + self.skipTest("no /proc/meminfo to read the share from") share = f"{memory.total * 3 // 4 // slot_count(usable_cpus()) // 1024}m" result = self.run_tool("docker", "run", "--rm", "img", "true", env=self.fake_docker()) self.assertEqual((result.returncode, result.stdout), (0, f"run --memory {share} --memory-swap {share} --rm img true\n")) @@ -106,6 +107,14 @@ class RunHeavy(unittest.TestCase): result = self.run_tool("docker", *args, env=env) self.assertEqual((result.returncode, result.stdout), (0, " ".join(args) + "\n")) + def test_a_command_on_a_machine_without_docker_finds_none(self): + folder = tempfile.TemporaryDirectory() + self.addCleanup(folder.cleanup) + (pathlib.Path(folder.name) / "python3").symlink_to(sys.executable) + (pathlib.Path(folder.name) / "sh").symlink_to("/bin/sh") + result = self.run_tool("sh", "-c", "command -v docker || echo none", env={**self.env, "PATH": folder.name}) + self.assertEqual((result.returncode, result.stdout), (0, "none\n")) + def test_a_capped_docker_that_finds_no_docker_exits_127_saying_so(self): folder = tempfile.TemporaryDirectory() self.addCleanup(folder.cleanup) diff --git a/bin/test_docker_command.py b/bin/test_docker_command.py index 01105663..80b84332 100644 --- a/bin/test_docker_command.py +++ b/bin/test_docker_command.py @@ -9,7 +9,10 @@ class Capped(unittest.TestCase): (["run", "--rm", "img", "true"], ["run", "--memory", "6144m", "--memory-swap", "6144m", "--rm", "img", "true"]), (["-H", "unix:///d.sock", "run", "img"], ["-H", "unix:///d.sock", "run", "--memory", "6144m", "--memory-swap", "6144m", "img"]), (["container", "create", "img"], ["container", "create", "--memory", "6144m", "--memory-swap", "6144m", "img"]), + (["--context", "run", "run", "img"], ["--context", "run", "run", "--memory", "6144m", "--memory-swap", "6144m", "img"]), (["run", "img", "python", "-m", "pytest"], ["run", "--memory", "6144m", "--memory-swap", "6144m", "img", "python", "-m", "pytest"]), + (["run", "img", "grep", "-m", "1", "x"], ["run", "--memory", "6144m", "--memory-swap", "6144m", "img", "grep", "-m", "1", "x"]), + (["run", "img", "stress", "--memory", "2"], ["run", "--memory", "6144m", "--memory-swap", "6144m", "img", "stress", "--memory", "2"]), ]: with self.subTest(given): self.assertEqual(capped(given, "6144m"), expected) diff --git a/docs/decisions.md b/docs/decisions.md index 873a3055..b2b44cd7 100644 --- a/docs/decisions.md +++ b/docs/decisions.md @@ -76,11 +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 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`; under run-heavy, a container that lacks them gets the slot's share of three quarters of the memory; 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; rule-hook's `docker-run-memory` blocks a `docker run` or `docker create` without them outside run-heavy, under which a container that lacks them gets the slot's share of three quarters of the memory; and no daemon-wide cap limits all containers together 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. -The heavy command in that hang started its container from the project's own script, out of rule-hook's sight. So run-heavy puts first on its command's `PATH` a `docker`, `bin/run_heavy/path_entry/docker`, which gives each `docker run` or `docker create` that lacks a limit the slot's share: three quarters of MemTotal, which the quarter a worker waits for leaves, split evenly across the slots (todo item 227). A container that sets one of the two limits keeps it, and gets the other as large, since docker refuses less swap than memory; an unlimited swap, `--memory-swap -1`, gives way. run-heavy cannot place the command in a cgroup instead: none is delegated to the user, and dockerd starts the containers outside the command's process tree. A compose service, and a docker named by its full path, keep no cap. +The heavy command in that hang started its container from the project's own script, out of rule-hook's sight. So run-heavy puts its own `docker`, `bin/run_heavy/path_entry/docker`, first on its command's `PATH`. That docker gives each `docker run` or `docker create` that lacks a limit the slot's share. The share is what a worker's quarter leaves: three quarters of MemTotal, split evenly across the slots. A container that sets one of the two limits keeps it, and gets the other as large, since docker refuses less swap than memory; an unlimited swap, `--memory-swap -1`, gives way. run-heavy cannot place the command in a cgroup instead: none is delegated to the user, and dockerd starts the containers outside the command's process tree. A compose service, and a docker named by its full path, keep no cap. 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. From a12e68fa61f184856d298fd5caa6bc1ce93a46c5 Mon Sep 17 00:00:00 2001 From: Lilleman auf Larv Date: Sat, 24 Oct 2026 11:31:10 +0200 Subject: [PATCH 24/55] =?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);=20answered?= =?UTF-8?q?=20in=20the=20principles=20round=201=20commit:=20a=20memory=20o?= =?UTF-8?q?ption=20below=20docker's=206m=20floor,=20such=20as=20grep=20-m?= =?UTF-8?q?=201,=20belongs=20to=20the=20container's=20command,=20and=20run?= =?UTF-8?q?-heavy=20adds=20its=20docker=20only=20where=20PATH=20finds=20a?= =?UTF-8?q?=20real=20one?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit From 487adc2091264fba27cf7bb5c37ee39bea72eb70 Mon Sep 17 00:00:00 2001 From: Lilleman auf Larv Date: Sat, 24 Oct 2026 11:31:10 +0200 Subject: [PATCH 25/55] =?UTF-8?q?Answer=20prose=20round=201:=200=20?= =?UTF-8?q?=F0=9F=94=B4,=2010=20=F0=9F=9F=A1=20(0=20misread);=20answered?= =?UTF-8?q?=20in=20the=20principles=20round=201=20commit:=20the=20decision?= =?UTF-8?q?=20title=20says=20where=20the=20rule=20passes,=20the=20help=20l?= =?UTF-8?q?ists=20the=20cap's=20cases,=20the=20rule=20text=20names=20the?= =?UTF-8?q?=20run-heavy=20exemption,=20and=20the=20docstrings,=20CLAUDE.md?= =?UTF-8?q?,=20reviewer=20step,=20README=20and=20changelog=20say=20what=20?= =?UTF-8?q?a=20reader=20does?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit From e551a2b5a98b4d3dd436f7f2b46c49df89d2341c Mon Sep 17 00:00:00 2001 From: Lilleman auf Larv Date: Sat, 24 Oct 2026 11:31:10 +0200 Subject: [PATCH 26/55] =?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 c87e9f19d6fae84b778e82cd132bb79254725927 Mon Sep 17 00:00:00 2001 From: Lilleman auf Larv Date: Sat, 24 Oct 2026 11:37:08 +0200 Subject: [PATCH 27/55] =?UTF-8?q?Answer=20stability=20round=201:=201=20?= =?UTF-8?q?=F0=9F=94=B4,=205=20=F0=9F=9F=A1=20(0=20misread);=20the=20?= =?UTF-8?q?=F0=9F=94=B4,=20the=20rule=20text=20and=20the=20PATH=20half=20o?= =?UTF-8?q?f=20the=20exemption=20were=20answered=20in=20the=20principles?= =?UTF-8?q?=20round=201=20commit;=20exempt=20no=20docker=20under=20sudo=20?= =?UTF-8?q?or=20doas,=20test=20unknown=20memory=20and=20the=20shim=20witho?= =?UTF-8?q?ut=20a=20share,=20keep=20helped=20beside=20unlimited,=20drop=20?= =?UTF-8?q?a=20dead=20fallback?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- bin/docker_command.py | 12 ++++++------ bin/rule_hook/rules.py | 9 +++++---- bin/rule_hook/test_rule_hook.py | 2 +- bin/run_heavy/capped_docker.py | 2 +- bin/run_heavy/test_run_heavy.py | 10 ++++++++++ 5 files changed, 23 insertions(+), 12 deletions(-) diff --git a/bin/docker_command.py b/bin/docker_command.py index eea0a460..3c683612 100644 --- a/bin/docker_command.py +++ b/bin/docker_command.py @@ -71,6 +71,12 @@ def unlimited(arguments: list[str]) -> bool: return subcommand in STARTS_CONTAINER and not limited and not helped(arguments) +def helped(arguments: 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 = subcommand_at(arguments)[-1] + 1 + return "--help" in arguments[:after + 1] + + def capped(arguments: list[str], share: str) -> list[str]: """docker's arguments, with each limit a container they make lacks added right after the subcommand. @@ -109,9 +115,3 @@ def option_at(arguments: list[str], options: tuple[str, ...], fits: typing.Calla if word == option and fits(following): return Option(at, 2, following) return None - - -def helped(arguments: 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 = subcommand_at(arguments)[-1] + 1 - return "--help" in arguments[:after + 1] diff --git a/bin/rule_hook/rules.py b/bin/rule_hook/rules.py index 6f3d6f36..f0ad6703 100644 --- a/bin/rule_hook/rules.py +++ b/bin/rule_hook/rules.py @@ -6,7 +6,7 @@ import typing from round_titles import CAP, lacks_counts, past_cap from git_command import commits from rule_hook.heavy_command import heavy -from shell_command import launched, Simple +from shell_command import launched, Simple, tool_name from review_folder import REPORTS from docker_command import unlimited @@ -32,7 +32,7 @@ RULES: dict[RuleName, Rule] = { ), "docker-run-memory": Rule( "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. One under run-heavy passes, as run-heavy's docker adds the limits, unless it names docker by its path or sets its own PATH. A container a script or docker compose starts is not checked", + "docker run, docker create, docker container run and docker container create, whether direct or through a launcher such as nice or timeout. One under run-heavy passes, as run-heavy's docker adds the limits, unless it names docker by its path, sets its own PATH, or runs through sudo or doas. 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", @@ -156,8 +156,9 @@ def unlimited_container(words: list[str]) -> bool: docker = launched(words, {"docker"}) if docker is None or not unlimited(docker.arguments): return False - # On Linux, run-heavy's docker adds the limits a container lacks, where PATH finds it: docker named bare, with no PATH of the command's own. - capped = "run-heavy" in docker.launchers and words[len(words) - len(docker.arguments) - 1] == "docker" and not any(word.startswith("PATH=") for word in words) + # On Linux, run-heavy's docker adds the limits a container lacks, where PATH finds it: docker named bare, with no PATH of the command's own, and no sudo or doas, which reset PATH. + before = words[:len(words) - len(docker.arguments) - 1] + capped = "run-heavy" in docker.launchers and words[len(before)] == "docker" and not any(word.startswith("PATH=") or tool_name(word) in ("doas", "sudo") for word in before) return not capped diff --git a/bin/rule_hook/test_rule_hook.py b/bin/rule_hook/test_rule_hook.py index bd0f4265..6c36d098 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", "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", "~/.claude/bin/run-heavy /usr/bin/docker run alpine:3.22.2 true", "docker run --memory-swap 4g alpine:3.22.2 grep -m 1 x", "run-heavy env PATH=/usr/bin 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", "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", "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", "~/.claude/bin/run-heavy /usr/bin/docker run alpine:3.22.2 true", "docker run --memory-swap 4g alpine:3.22.2 grep -m 1 x", "run-heavy env PATH=/usr/bin docker run alpine:3.22.2 true", "run-heavy sudo docker run alpine:3.22.2 true"]: with self.subTest(command): self.assertEqual(checked(command), ["docker-run-memory"]) diff --git a/bin/run_heavy/capped_docker.py b/bin/run_heavy/capped_docker.py index ac89ef2e..d9d9d199 100644 --- a/bin/run_heavy/capped_docker.py +++ b/bin/run_heavy/capped_docker.py @@ -32,4 +32,4 @@ def main(argv: list[str], env: typing.Mapping[str, str]) -> int: def without_path_entry(path: str) -> str: """path less PATH_ENTRY, so the real docker is the one found.""" - return os.pathsep.join(entry for entry in path.split(os.pathsep) if pathlib.Path(entry or ".").resolve() != PATH_ENTRY) + return os.pathsep.join(entry for entry in path.split(os.pathsep) if pathlib.Path(entry).resolve() != PATH_ENTRY) diff --git a/bin/run_heavy/test_run_heavy.py b/bin/run_heavy/test_run_heavy.py index 1519072a..f028d6b7 100644 --- a/bin/run_heavy/test_run_heavy.py +++ b/bin/run_heavy/test_run_heavy.py @@ -115,6 +115,16 @@ class RunHeavy(unittest.TestCase): result = self.run_tool("sh", "-c", "command -v docker || echo none", env={**self.env, "PATH": folder.name}) self.assertEqual((result.returncode, result.stdout), (0, "none\n")) + def test_the_capped_docker_passes_a_call_on_unchanged_without_a_share(self): + env = self.fake_docker() + env.pop("RUN_HEAVY_MEMORY", None) + shim = pathlib.Path(TOOL).parent / "run_heavy" / "path_entry" / "docker" + result = subprocess.run([str(shim), "run", "img"], capture_output=True, text=True, env=env, timeout=30) + self.assertEqual((result.returncode, result.stdout), (0, "run img\n")) + + def test_no_cap_where_the_memory_is_unknown(self): + self.assertEqual(main.capping(None, 4, self.fake_docker()), {}) + def test_a_capped_docker_that_finds_no_docker_exits_127_saying_so(self): folder = tempfile.TemporaryDirectory() self.addCleanup(folder.cleanup) From 055c2d2df0711421efe6eca3a703a511715b03eb Mon Sep 17 00:00:00 2001 From: Lilleman auf Larv Date: Sat, 24 Oct 2026 11:39:12 +0200 Subject: [PATCH 28/55] =?UTF-8?q?Answer=20product-owner=20round=202:=200?= =?UTF-8?q?=20=F0=9F=94=B4,=201=20=F0=9F=9F=A1=20(0=20misread);=20a=20size?= =?UTF-8?q?=20has=20at=20most=20one=20point,=20so=20-m=201.2.3=20in=20a=20?= =?UTF-8?q?container's=20command=20is=20no=20size=20and=20crashes=20nothin?= =?UTF-8?q?g?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- bin/docker_command.py | 4 ++-- bin/rule_hook/rules.py | 11 ++++++++--- bin/rule_hook/test_rule_hook.py | 2 +- bin/test_docker_command.py | 1 + 4 files changed, 12 insertions(+), 6 deletions(-) diff --git a/bin/docker_command.py b/bin/docker_command.py index 3c683612..8103d105 100644 --- a/bin/docker_command.py +++ b/bin/docker_command.py @@ -6,8 +6,8 @@ import typing 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 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, each unit a power of 1024. -SIZE = r"(\d+(?:\.\d+)*)([kKmMgGtTpP]?)[iI]?[bB]?" +# A size as docker reads one, such as 4g, 512M or 1.5GiB, each unit a power of 1024: go-units' RAMInBytes pattern, less a number with two points, such as 1.2.3, which its float parse refuses. +SIZE = r"(\d+(?:\.\d+)?)([kKmMgGtTpP]?)[iI]?[bB]?" # Docker's documented floor for --memory, 6m: a smaller value, such as grep -m 1's, belongs to the container's own command. MEMORY_FLOOR = 6 * 1024**2 MEMORY_OPTIONS = ("-m", "--memory") diff --git a/bin/rule_hook/rules.py b/bin/rule_hook/rules.py index f0ad6703..42b42f11 100644 --- a/bin/rule_hook/rules.py +++ b/bin/rule_hook/rules.py @@ -32,7 +32,7 @@ RULES: dict[RuleName, Rule] = { ), "docker-run-memory": Rule( "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. One under run-heavy passes, as run-heavy's docker adds the limits, unless it names docker by its path, sets its own PATH, or runs through sudo or doas. A container a script or docker compose starts is not checked", + "docker run, docker create, docker container run and docker container create, whether direct or through a launcher such as nice or timeout. One under run-heavy passes, as run-heavy's docker adds the limits, unless it names docker by its path, or changes or clears PATH, as env -i, sudo or doas do. 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", @@ -156,12 +156,17 @@ def unlimited_container(words: list[str]) -> bool: docker = launched(words, {"docker"}) if docker is None or not unlimited(docker.arguments): return False - # On Linux, run-heavy's docker adds the limits a container lacks, where PATH finds it: docker named bare, with no PATH of the command's own, and no sudo or doas, which reset PATH. + # On Linux, run-heavy's docker adds the limits a container lacks, where PATH finds it: docker named bare, with PATH left as run-heavy set it. before = words[:len(words) - len(docker.arguments) - 1] - capped = "run-heavy" in docker.launchers and words[len(before)] == "docker" and not any(word.startswith("PATH=") or tool_name(word) in ("doas", "sudo") for word in before) + capped = "run-heavy" in docker.launchers and words[len(before)] == "docker" and not any(resets_path(word) for word in before) return not capped +def resets_path(word: str) -> bool: + """Whether a word before docker drops the PATH run-heavy set: a PATH= of its own, env's -i or -u, or sudo or doas, which reset it.""" + return word.startswith(("PATH=", "--unset")) or word in ("-i", "--ignore-environment", "-u") or tool_name(word) in ("doas", "sudo") + + def file_breaches(path: str, before: str, added: str, after: str) -> list[Breach]: """Breaches in an edit of path: added is the text the edit writes, after the whole file it leaves.""" breaches = [Breach("no-ai-attribution", f"{path} would carry an attribution", posixpath.dirname(path))] if ATTRIBUTION.search(added) else [] diff --git a/bin/rule_hook/test_rule_hook.py b/bin/rule_hook/test_rule_hook.py index 6c36d098..26399a4e 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", "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", "~/.claude/bin/run-heavy /usr/bin/docker run alpine:3.22.2 true", "docker run --memory-swap 4g alpine:3.22.2 grep -m 1 x", "run-heavy env PATH=/usr/bin docker run alpine:3.22.2 true", "run-heavy sudo 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", "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", "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", "~/.claude/bin/run-heavy /usr/bin/docker run alpine:3.22.2 true", "docker run --memory-swap 4g alpine:3.22.2 grep -m 1 x", "run-heavy env PATH=/usr/bin docker run alpine:3.22.2 true", "run-heavy sudo docker run alpine:3.22.2 true", "docker run alpine:3.22.2 git tag -m 1.2.3", "run-heavy env -i docker run alpine:3.22.2 true", "run-heavy env -u PATH docker run alpine:3.22.2 true"]: with self.subTest(command): self.assertEqual(checked(command), ["docker-run-memory"]) diff --git a/bin/test_docker_command.py b/bin/test_docker_command.py index 80b84332..fcdc0b97 100644 --- a/bin/test_docker_command.py +++ b/bin/test_docker_command.py @@ -12,6 +12,7 @@ class Capped(unittest.TestCase): (["--context", "run", "run", "img"], ["--context", "run", "run", "--memory", "6144m", "--memory-swap", "6144m", "img"]), (["run", "img", "python", "-m", "pytest"], ["run", "--memory", "6144m", "--memory-swap", "6144m", "img", "python", "-m", "pytest"]), (["run", "img", "grep", "-m", "1", "x"], ["run", "--memory", "6144m", "--memory-swap", "6144m", "img", "grep", "-m", "1", "x"]), + (["run", "img", "git", "tag", "-m", "1.2.3"], ["run", "--memory", "6144m", "--memory-swap", "6144m", "img", "git", "tag", "-m", "1.2.3"]), (["run", "img", "stress", "--memory", "2"], ["run", "--memory", "6144m", "--memory-swap", "6144m", "img", "stress", "--memory", "2"]), ]: with self.subTest(given): From 594b28ff686b71b4aac2cf29ad8be417da18074e Mon Sep 17 00:00:00 2001 From: Lilleman auf Larv Date: Sat, 24 Oct 2026 11:39:12 +0200 Subject: [PATCH 29/55] =?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);=20the=20-m=20?= =?UTF-8?q?1.2.3=20crash=20was=20answered=20in=20the=20product-owner=20rou?= =?UTF-8?q?nd=202=20commit,=20which=20also=20refuses=20the=20exemption=20t?= =?UTF-8?q?o=20env=20-i=20and=20env=20-u?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit From 6a2f29635e1bce402d403d71b87260acba7827de Mon Sep 17 00:00:00 2001 From: Lilleman auf Larv Date: Sat, 24 Oct 2026 11:42:53 +0200 Subject: [PATCH 30/55] =?UTF-8?q?Answer=20stability=20round=202:=201=20?= =?UTF-8?q?=F0=9F=94=B4,=202=20=F0=9F=9F=A1=20(0=20misread);=20drop=20a=20?= =?UTF-8?q?--memory=20of=200=20so=20the=20added=20limit=20stands,=20pin=20?= =?UTF-8?q?the=206m=20floor's=20edge,=20test=20env=20--unset,=20env=20--ig?= =?UTF-8?q?nore-environment=20and=20doas,=20and=20say=20on=20Linux=20in=20?= =?UTF-8?q?the=20rule=20text?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- bin/docker_command.py | 9 +++++++-- bin/rule_hook/rules.py | 2 +- bin/rule_hook/test_rule_hook.py | 2 +- bin/run_heavy/main.py | 2 +- bin/test_docker_command.py | 4 ++++ 5 files changed, 14 insertions(+), 5 deletions(-) diff --git a/bin/docker_command.py b/bin/docker_command.py index 8103d105..4db69996 100644 --- a/bin/docker_command.py +++ b/bin/docker_command.py @@ -40,6 +40,11 @@ def unset_swap(value: str) -> bool: return value == "-1" or size(value) == 0 +def zero(value: str) -> bool: + """Whether a value is 0 in any unit: a -m 0 leaves memory unlimited, and would override the limit capped adds.""" + return size(value) == 0 + + 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"].""" return [arguments[at] for at in subcommand_at(arguments)] @@ -80,13 +85,13 @@ def helped(arguments: list[str]) -> bool: def capped(arguments: list[str], share: str) -> list[str]: """docker's arguments, with each limit a container they make lacks added right after the subcommand. - A container that sets neither limit gets share for both. One that sets one limit gets the other at the same size, since docker refuses less swap than memory. A --memory-swap of -1 or 0 is dropped; every other word stays. + A container that sets neither limit gets share for both. One that sets one limit gets the other at the same size, since docker refuses less swap than memory. A --memory-swap of -1 or 0, and a --memory of 0, is dropped; every other word stays. """ if not unlimited(arguments): return arguments memory = option_value(arguments, MEMORY_OPTIONS, memory_limit) swap = option_value(arguments, SWAP_OPTIONS, swap_limit) - rest = without(arguments, SWAP_OPTIONS, unset_swap) + rest = without(without(arguments, SWAP_OPTIONS, unset_swap), MEMORY_OPTIONS, zero) limits = ([] if memory else ["--memory", swap or share]) + ([] if swap else ["--memory-swap", memory or share]) after = subcommand_at(rest)[-1] + 1 return [*rest[:after], *limits, *rest[after:]] diff --git a/bin/rule_hook/rules.py b/bin/rule_hook/rules.py index 42b42f11..c837c979 100644 --- a/bin/rule_hook/rules.py +++ b/bin/rule_hook/rules.py @@ -32,7 +32,7 @@ RULES: dict[RuleName, Rule] = { ), "docker-run-memory": Rule( "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. One under run-heavy passes, as run-heavy's docker adds the limits, unless it names docker by its path, or changes or clears PATH, as env -i, sudo or doas do. A container a script or docker compose starts is not checked", + "docker run, docker create, docker container run and docker container create, whether direct or through a launcher such as nice or timeout. One under run-heavy passes, as run-heavy's docker adds the limits on Linux, unless it names docker by its path, or changes or clears PATH, as env -i, sudo or doas do. 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", diff --git a/bin/rule_hook/test_rule_hook.py b/bin/rule_hook/test_rule_hook.py index 26399a4e..82f04339 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", "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", "~/.claude/bin/run-heavy /usr/bin/docker run alpine:3.22.2 true", "docker run --memory-swap 4g alpine:3.22.2 grep -m 1 x", "run-heavy env PATH=/usr/bin docker run alpine:3.22.2 true", "run-heavy sudo docker run alpine:3.22.2 true", "docker run alpine:3.22.2 git tag -m 1.2.3", "run-heavy env -i docker run alpine:3.22.2 true", "run-heavy env -u PATH 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", "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", "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", "~/.claude/bin/run-heavy /usr/bin/docker run alpine:3.22.2 true", "docker run --memory-swap 4g alpine:3.22.2 grep -m 1 x", "run-heavy env PATH=/usr/bin docker run alpine:3.22.2 true", "run-heavy sudo docker run alpine:3.22.2 true", "docker run alpine:3.22.2 git tag -m 1.2.3", "run-heavy env -i docker run alpine:3.22.2 true", "run-heavy env -u PATH docker run alpine:3.22.2 true", "run-heavy env --unset=PATH docker run alpine:3.22.2 true", "run-heavy env --ignore-environment docker run alpine:3.22.2 true", "run-heavy doas docker run alpine:3.22.2 true"]: with self.subTest(command): self.assertEqual(checked(command), ["docker-run-memory"]) diff --git a/bin/run_heavy/main.py b/bin/run_heavy/main.py index a7ee6e52..44176e39 100644 --- a/bin/run_heavy/main.py +++ b/bin/run_heavy/main.py @@ -16,7 +16,7 @@ first on the command's PATH. That docker adds the limits a container lacks, then - A container that sets neither limit gets a memory limit and a swap limit, both the share. - A container that sets one of them keeps it, and gets the other at the same size. -- A --memory-swap of -1, unlimited swap, is dropped and replaced. +- A --memory-swap of -1, unlimited swap, or a --memory of 0 is dropped and replaced. Every other docker call goes through unchanged. A docker compose service, and a docker named by its full path, get no cap: give those containers their own limits. diff --git a/bin/test_docker_command.py b/bin/test_docker_command.py index fcdc0b97..1845e291 100644 --- a/bin/test_docker_command.py +++ b/bin/test_docker_command.py @@ -13,6 +13,9 @@ class Capped(unittest.TestCase): (["run", "img", "python", "-m", "pytest"], ["run", "--memory", "6144m", "--memory-swap", "6144m", "img", "python", "-m", "pytest"]), (["run", "img", "grep", "-m", "1", "x"], ["run", "--memory", "6144m", "--memory-swap", "6144m", "img", "grep", "-m", "1", "x"]), (["run", "img", "git", "tag", "-m", "1.2.3"], ["run", "--memory", "6144m", "--memory-swap", "6144m", "img", "git", "tag", "-m", "1.2.3"]), + (["run", "-m", "0", "img"], ["run", "--memory", "6144m", "--memory-swap", "6144m", "img"]), + (["run", "-m", "6143k", "img"], ["run", "--memory", "6144m", "--memory-swap", "6144m", "-m", "6143k", "img"]), + (["run", "img", "tool", "-m", "6"], ["run", "--memory", "6144m", "--memory-swap", "6144m", "img", "tool", "-m", "6"]), (["run", "img", "stress", "--memory", "2"], ["run", "--memory", "6144m", "--memory-swap", "6144m", "img", "stress", "--memory", "2"]), ]: with self.subTest(given): @@ -21,6 +24,7 @@ class Capped(unittest.TestCase): def test_a_container_s_own_limit_is_kept_and_sets_the_limit_it_lacks(self): for given, expected in [ (["run", "-m", "10g", "img"], ["run", "--memory-swap", "10g", "-m", "10g", "img"]), + (["run", "-m", "6m", "img"], ["run", "--memory-swap", "6m", "-m", "6m", "img"]), (["run", "--memory=12g", "img"], ["run", "--memory-swap", "12g", "--memory=12g", "img"]), (["run", "--memory-swap", "2g", "img"], ["run", "--memory", "2g", "--memory-swap", "2g", "img"]), (["run", "-m", "4g", "--memory-swap", "-1", "img"], ["run", "--memory-swap", "4g", "-m", "4g", "img"]), From ed22a48a61b4560d193834685699cca6649544c0 Mon Sep 17 00:00:00 2001 From: Lilleman auf Larv Date: Sat, 24 Oct 2026 11:46:56 +0200 Subject: [PATCH 31/55] =?UTF-8?q?Answer=20product-owner=20round=203:=200?= =?UTF-8?q?=20=F0=9F=94=B4,=201=20=F0=9F=9F=A1=20(0=20misread);=20a=20call?= =?UTF-8?q?=20with=20a=20--memory=20of=200=20anywhere=20passes=20through?= =?UTF-8?q?=20unchanged,=20so=20neither=20docker's=20-m=200=20nor=20a=20co?= =?UTF-8?q?ntainer's=20grep=20-m=200=20is=20dropped=20or=20overridden?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- bin/docker_command.py | 8 ++++---- bin/run_heavy/main.py | 3 ++- bin/test_docker_command.py | 3 +-- 3 files changed, 7 insertions(+), 7 deletions(-) diff --git a/bin/docker_command.py b/bin/docker_command.py index 4db69996..8b47f0c1 100644 --- a/bin/docker_command.py +++ b/bin/docker_command.py @@ -41,7 +41,6 @@ def unset_swap(value: str) -> bool: def zero(value: str) -> bool: - """Whether a value is 0 in any unit: a -m 0 leaves memory unlimited, and would override the limit capped adds.""" return size(value) == 0 @@ -85,13 +84,14 @@ def helped(arguments: list[str]) -> bool: def capped(arguments: list[str], share: str) -> list[str]: """docker's arguments, with each limit a container they make lacks added right after the subcommand. - A container that sets neither limit gets share for both. One that sets one limit gets the other at the same size, since docker refuses less swap than memory. A --memory-swap of -1 or 0, and a --memory of 0, is dropped; every other word stays. + A container that sets neither limit gets share for both. One that sets one limit gets the other at the same size, since docker refuses less swap than memory. A --memory-swap of -1 or 0 is dropped; every other word stays. Arguments with a --memory of 0 anywhere come back unchanged. """ - if not unlimited(arguments): + # A -m 0 asks docker for unlimited memory, and would override an added limit; it may also be the container's own, as in grep -m 0, so it is neither dropped nor capped. + if not unlimited(arguments) or option_value(arguments, MEMORY_OPTIONS, zero): return arguments memory = option_value(arguments, MEMORY_OPTIONS, memory_limit) swap = option_value(arguments, SWAP_OPTIONS, swap_limit) - rest = without(without(arguments, SWAP_OPTIONS, unset_swap), MEMORY_OPTIONS, zero) + rest = without(arguments, SWAP_OPTIONS, unset_swap) limits = ([] if memory else ["--memory", swap or share]) + ([] if swap else ["--memory-swap", memory or share]) after = subcommand_at(rest)[-1] + 1 return [*rest[:after], *limits, *rest[after:]] diff --git a/bin/run_heavy/main.py b/bin/run_heavy/main.py index 44176e39..76ae9c43 100644 --- a/bin/run_heavy/main.py +++ b/bin/run_heavy/main.py @@ -16,7 +16,8 @@ first on the command's PATH. That docker adds the limits a container lacks, then - A container that sets neither limit gets a memory limit and a swap limit, both the share. - A container that sets one of them keeps it, and gets the other at the same size. -- A --memory-swap of -1, unlimited swap, or a --memory of 0 is dropped and replaced. +- A --memory-swap of -1, unlimited swap, is dropped and replaced. +- A --memory of 0, unlimited memory, leaves the call as it is. Every other docker call goes through unchanged. A docker compose service, and a docker named by its full path, get no cap: give those containers their own limits. diff --git a/bin/test_docker_command.py b/bin/test_docker_command.py index 1845e291..d87f8568 100644 --- a/bin/test_docker_command.py +++ b/bin/test_docker_command.py @@ -13,7 +13,6 @@ class Capped(unittest.TestCase): (["run", "img", "python", "-m", "pytest"], ["run", "--memory", "6144m", "--memory-swap", "6144m", "img", "python", "-m", "pytest"]), (["run", "img", "grep", "-m", "1", "x"], ["run", "--memory", "6144m", "--memory-swap", "6144m", "img", "grep", "-m", "1", "x"]), (["run", "img", "git", "tag", "-m", "1.2.3"], ["run", "--memory", "6144m", "--memory-swap", "6144m", "img", "git", "tag", "-m", "1.2.3"]), - (["run", "-m", "0", "img"], ["run", "--memory", "6144m", "--memory-swap", "6144m", "img"]), (["run", "-m", "6143k", "img"], ["run", "--memory", "6144m", "--memory-swap", "6144m", "-m", "6143k", "img"]), (["run", "img", "tool", "-m", "6"], ["run", "--memory", "6144m", "--memory-swap", "6144m", "img", "tool", "-m", "6"]), (["run", "img", "stress", "--memory", "2"], ["run", "--memory", "6144m", "--memory-swap", "6144m", "img", "stress", "--memory", "2"]), @@ -35,7 +34,7 @@ class Capped(unittest.TestCase): self.assertEqual(capped(given, "6144m"), expected) def test_a_container_with_both_limits_or_another_docker_call_is_left_alone(self): - for given in [["run", "-m", "10g", "--memory-swap", "12g", "img"], ["ps"], ["build", "."], ["run", "--help"], ["compose", "run", "app"], ["exec", "box", "true"]]: + for given in [["run", "-m", "0", "img"], ["run", "img", "grep", "-m", "0", "x"], ["run", "-m", "10g", "--memory-swap", "12g", "img"], ["ps"], ["build", "."], ["run", "--help"], ["compose", "run", "app"], ["exec", "box", "true"]]: with self.subTest(given): self.assertEqual(capped(given, "6144m"), given) From 3617498f3351d1a4302a232bd88cc376392c8b10 Mon Sep 17 00:00:00 2001 From: Lilleman auf Larv Date: Sat, 24 Oct 2026 11:46:56 +0200 Subject: [PATCH 32/55] =?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 3ac8c7969409537e65758aca1874d80c2abacd43 Mon Sep 17 00:00:00 2001 From: Lilleman auf Larv Date: Sat, 24 Oct 2026 11:46:56 +0200 Subject: [PATCH 33/55] =?UTF-8?q?Answer=20stability=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 cf961b55f0a1bd57d270ac2ea145f285c5540607 Mon Sep 17 00:00:00 2001 From: Lilleman auf Larv Date: Sat, 24 Oct 2026 11:54:21 +0200 Subject: [PATCH 34/55] Record the comprehension check: paired ruling same against eb7b506 --- bin/machine_load/memory.py | 2 +- docs/comprehension-history.md | 40 +++++++++++++++++++++++++++++++++++ todo.md | 7 +++++- 3 files changed, 47 insertions(+), 2 deletions(-) diff --git a/bin/machine_load/memory.py b/bin/machine_load/memory.py index 8a902690..d432ba47 100644 --- a/bin/machine_load/memory.py +++ b/bin/machine_load/memory.py @@ -4,7 +4,7 @@ import pathlib import re MEMINFO = pathlib.Path("/proc/meminfo") -# A worker starts only while at least this share of the machine's memory is available; the human chose it, as no standard sets one. +# A worker starts only while at least this share of the machine's memory is available; the human chose it, as no standard sets one. The rest is the heavy slots' share, so changing it also changes the memory limit run-heavy gives a container. ROOM_SHARE = 0.25 diff --git a/docs/comprehension-history.md b/docs/comprehension-history.md index 64abee11..90e3fddd 100644 --- a/docs/comprehension-history.md +++ b/docs/comprehension-history.md @@ -2727,3 +2727,43 @@ Junior A, decided by: - 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 + +## 2026-10-24T09:53:49Z, PR #373 at 3ac8c79, against eb7b506 + +Ruling: same + +| Seat | Navigation | Locality | Shape | Self-sufficiency | Overall | +|---|---|---|---|---|---| +| Mid A | same | worse | same | better | same | +| Inherited architect | same | worse | worse | same | worse | +| Maintainability senior | same | worse | worse | same | worse | +| Junior A | same | worse | same | same | same | + +Mid A, decided by: + +- Locality: `bin/rule_hook/rules.py:154` `unlimited_container`: rule-hook now encodes how run-heavy's docker puts itself on PATH, joined to it by a one-line comment +- Locality: `bin/run_heavy/main.py:65` `capping`: a stand-in docker on PATH and RUN_HEAVY_MEMORY make a container's limits depend on the environment, though the help spells it out +- Self-sufficiency: `bin/docker_command.py:24` `size`: named predicates replace a negative-lookahead regex, and swap_limit says what -1 and 0 mean +- Self-sufficiency: `bin/docker_command.py:52` `subcommand_at`: positions replace a first-match lookup that took an option's value for the subcommand +- Shape: `bin/docker_command.py:84` `capped`: the module grows from 5 functions to 13, and one line packs four conditional limit lists + +Inherited architect, decided by: + +- Locality, Shape: `bin/rule_hook/rules.py:154` `unlimited_container`: index arithmetic finds the words before docker, and the rule encodes how another package's PATH shim works +- Locality: `bin/rule_hook/rules.py:165` `resets_path`: reads as a guess about launchers rather than a model of them +- Locality: `bin/run_heavy/main.py:65` `capping`: whether a docker run gets limits depends on PATH order and a variable an ancestor set +- Shape: `bin/docker_command.py:39` `unset_swap`: named unset though -1 is unlimited, beside a generic zero, in a module that now reads and rewrites commands +- Shape: `bin/docker_command.py:24` `size`: replaces a hard negative-lookahead regex, offsetting in part + +Maintainability senior, decided by: + +- Locality: `bin/rule_hook/rules.py:154` `unlimited_container`: repeats how run-heavy's PATH trick works, so a change to run-heavy silently changes the rule, and the index arithmetic takes a second read +- Locality: `bin/machine_load/memory.py:20` `Memory.slot_share`: tuning the worker threshold ROOM_SHARE now also changes every capped container's memory, while its comment names only the worker +- Locality: `bin/run_heavy/main.py:65` `capping`: the share reaches the docker shim through an environment variable and a PATH entry, hidden state between two processes +- Shape: `bin/docker_command.py:24` `size`: the module grows to 13 functions that read and rewrite commands, with predicates named as nouns +- Shape: `bin/docker_command.py:84` `capped`: one line crosses the two limits' values over and needs the docstring + +Junior A, decided by: + +- Locality: `bin/rule_hook/rules.py:154` `unlimited_container`: rule-hook copies run-heavy's PATH trick, and nothing in run_heavy points back to it +- Locality: `bin/run_heavy/main.py:65` `capping`: one process sets RUN_HEAVY_MEMORY and PATH, and another reads them, so a docker run spans two processes diff --git a/todo.md b/todo.md index 170cbd8c..41e919af 100644 --- a/todo.md +++ b/todo.md @@ -6,7 +6,7 @@ `Bar = 0.1` -`Next ID = 229` +`Next ID = 230` ## Items @@ -17,6 +17,7 @@ | 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 | | 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 | +| 229 | 0.5.0 | | | **Keep the rule for which commands reach run-heavy's docker beside that docker in `bin/run_heavy/capped_docker.py`, so rule-hook's `docker-run-memory` asks it instead of repeating run-heavy's PATH rules.** | 2 | 1 | 3 | 4 | 2 | code health by 3 | 18.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 | | 123 | 0.5.0 | | | **Have `bin/comprehension_history.py` parse each history entry once into seats, votes and places, so `latest_places`, `worse_places` and `worse_votes` neither depend on table order nor split a label to find a seat.** | 2 | 1 | 2 | 3 | 5 | code health by 5, 1.4 by 5 | 11.0 | @@ -94,6 +95,10 @@ It lives under `~/.claude`, which `.gitignore` keeps from the remote, so a lost The README line covers the bench's transcripts in `workflow-bench/logs/` too (goal 3). +### 229. Keep the rule for which commands reach run-heavy's docker beside that docker in `bin/run_heavy/capped_docker.py`, so rule-hook's `docker-run-memory` asks it instead of repeating run-heavy's PATH rules. + +The paired ruling of PR #373 found Locality worse with all four seats, and named `bin/rule_hook/rules.py` `unlimited_container` and `resets_path` first. rule-hook exempts a `docker run` under run-heavy only where run-heavy's docker will run it: docker named bare, with PATH left as run-heavy set it. That knowledge of how `run_heavy/main.py` `capping` puts `PATH_ENTRY` first lives in rule-hook, so a change to run-heavy silently changes what the rule lets through. Move the predicate, with its words-before-docker index arithmetic made plain, next to `PATH_ENTRY`, and have the rule call it. Make the two places easier to read, as the seats named them. + ### 219. 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. Item 172 renamed `anchor` to `project` across `bin/loop_claude`, after release 0.3.0's inherited architect named `bin/loop_claude/cycle/judge.py:68` `Reply.bundled`: "the project's rung is also called anchor". Three tools outside it still call the same rung `anchor`: `bin/judge_replay/main.py:54` (`anchor = arguments_or_exit(...)`, a `Rung` parsed from the model argument), `bin/subagent_rung/main.py:26` (`anchor = project_rung(model)`), and `bin/review_replay/main.py:74`, `:100` and `:180`, with `findings_found`'s docstring. While the name differs between tools, a reader works out each time that the two are one rung. The rename keeps behaviour. `bin/score_outcomes/anchors.py` uses `anchor` for score anchors, a different thing, and keeps the name. From 4aa8eb9467a57324789fe65853732afc37ee07ef Mon Sep 17 00:00:00 2001 From: Lilleman auf Larv Date: Mon, 26 Oct 2026 21:47:22 +0100 Subject: [PATCH 35/55] File item 230: an ambitious refactor whenever a scoring run is under 7.0 --- todo.md | 31 ++++++++++++++++++++++++++++++- 1 file changed, 30 insertions(+), 1 deletion(-) diff --git a/todo.md b/todo.md index 41e919af..8b29cf4d 100644 --- a/todo.md +++ b/todo.md @@ -6,7 +6,7 @@ `Bar = 0.1` -`Next ID = 230` +`Next ID = 231` ## Items @@ -28,6 +28,7 @@ | 105 | 0.5.0 | | decision | **Compare review rounds per pass and reading cost for the five chunks before and after the `worker:` decision moved the principles out of the worker's context, and file an item if either rose.** | 1 | 2 | 1 | 2 | 2 | 1.4 by 6 | 8.0 | | 162 | 0.5.0 | | owner | **Script each step that 0.2.0's chunks repeated by hand and a program can compute, filing one item per step, and file this audit again for the next release.** | 2 | 2 | 1 | 3 | 3 | 1.4 by 4, 1.5 by 4 | 7.8 | | 175 | 0.5.0 | | | **Compare the first five chunks loop-claude starts with `chunk-preflight` against the five before them, and file an item where the preflight did not pay off.** | 1 | 2 | 1 | 2 | 2 | 1.4 by 3, 1.5 by 3 | 7.8 | +| 230 | 0.5.0 | | | **File one ambitious refactor of the lowest-scoring dimension whenever a scoring run scores a project under 7.0, so such a project always holds a plan item aimed at reaching 7.0.** | 3 | 2 | 3 | 6 | 4 | 1.1 by 7, 1.2 by 4 | 7.7 | | 184 | 0.5.0 | | | **Rewrap the lines of `loop-claude --help` that run past the column the rest of it wraps at.** | 1 | 1 | 1 | 1 | 1 | code health by 1 | 7.2 | | 221 | 0.5.0 | | | **Parse each transcript entry once, where `bin/claude_code/transcript.py` reads it, into a typed value naming its kind, so no consumer works out an entry's kind from a raw `dict`.** | 3 | 1 | 3 | 5 | 5 | code health by 4 | 7.2 | | 116 | 0.5.0 | | | **Report L by the share of chunks with a 🔴, once 10 chunks that each shipped one item record finding counts and most record no 🔴.** | 1 | 1 | 2 | 2 | 2 | 1.1 by 5 | 7.0 | @@ -141,6 +142,34 @@ The chunk that ships this item files a copy of it in the release after the one i Item 161 put `chunk-preflight`'s facts into a fresh worker's prompt, so the worker no longer finds them itself. Before that, in item 140's chunk, the worker spent 5 min 46 s of 30 min, 16 of its 68 messages and 226k of its 491k fresh tokens before its first edit, through 12 Bash and 5 Read calls. Measure those figures from loop-claude's archive, as medians over the first five chunks that started with the preflight and the five before them: one chunk is too noisy a baseline, as `docs/decisions.md` → `reading cost: a rise is …` records. Measure the counter-signals beside them: goal 1.4's review rounds and unfinished verdicts, and goal 1.5's 🔴 findings, per chunk, since a worker that reads less may start sooner and need more rounds or let more defects through. Where time or tokens did not fall, or a counter-signal rose, file an item naming the facts the workers still found by hand, or what the preflight got wrong. +### 230. File one ambitious refactor of the lowest-scoring dimension whenever a scoring run scores a project under 7.0, so such a project always holds a plan item aimed at reaching 7.0. + +Today `larv-review record-scoring` prints a `Floor:` line naming each mean under 7.0 +(`bin/larv_review/history_commands.py:52`), and larv-review §3 → "Record" only commits the run and +lists its scores. No rule turns that line into plan items. The places seats name reach the plan only +when another item happens to touch one, so a project under 7.0 can stay there with no item aimed at +it. A seat already named the doubt: `docs/comprehension-history.md:1536`, "a reader cannot tell +whether `Floor:` means stop". `~/.claude` has filed such items by hand, such as items 123 and 124; `~/code/log` held one open-ended item, its item 90, and kept no comprehension history. + +The human set the shape on 2026-10-26: the item filed is one ambitious refactor, not touch-ups. It +restructures the area behind the lowest dimension's places, sized to lift that dimension to 7.0, and +quotes the places it answers. Its tagline names the comprehension floor, so its chunk runs a scoring +run, and a run still under 7.0 files the next one. The chain stops when every score reaches 7.0. + +Settle in the change: + +- Where the rule lives: larv-review §3 → "Record", and whether `record-scoring` prints the step + beside `Floor:` so no worker misses it. +- Duplicates: a release ends with two scoring runs, and an earlier run's item may still be open. + While one such item is open, a later run refreshes its places instead of filing another. +- Who files: a session below the project's rung drafts the item for a subagent on or above it, as + `rules/todo-items.md` says. +- Ranking: `docs/decisions.md` → `larv-review: within a chunk lifting a project towards the + comprehension floor, …` moves such an item's goals by 9 and lets it compete like any item. Say + whether an ambitious refactor, likely above R 5 and so shipping alone, keeps that. + +Once it ships, `~/code/log` drops its item 98, which does the same by hand. + ### 184. Rewrap the lines of `loop-claude --help` that run past the column the rest of it wraps at. In `bin/loop_claude/loop/main.py`'s docstring, the line holding "of one PR, is finished" and the one ending "Each of these opens with its UTC time." run to 107 and 159 columns. Raised by the prose review of PR #308. From cd76c1f511eeb55e76b7d098b71e4d068381f6d8 Mon Sep 17 00:00:00 2001 From: Lilleman auf Larv Date: Mon, 26 Oct 2026 21:55:31 +0100 Subject: [PATCH 36/55] Wrap item 230's detail --- todo.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/todo.md b/todo.md index 8b29cf4d..03294910 100644 --- a/todo.md +++ b/todo.md @@ -149,7 +149,8 @@ Today `larv-review record-scoring` prints a `Floor:` line naming each mean under lists its scores. No rule turns that line into plan items. The places seats name reach the plan only when another item happens to touch one, so a project under 7.0 can stay there with no item aimed at it. A seat already named the doubt: `docs/comprehension-history.md:1536`, "a reader cannot tell -whether `Floor:` means stop". `~/.claude` has filed such items by hand, such as items 123 and 124; `~/code/log` held one open-ended item, its item 90, and kept no comprehension history. +whether `Floor:` means stop". `~/.claude` has filed such items by hand, such as items 123 and +124; `~/code/log` held one open-ended item, its item 90, and kept no comprehension history. The human set the shape on 2026-10-26: the item filed is one ambitious refactor, not touch-ups. It restructures the area behind the lowest dimension's places, sized to lift that dimension to 7.0, and From d66c0bb317339daa4192c7dd92613ad92c8cb5fa Mon Sep 17 00:00:00 2001 From: Lilleman auf Larv Date: Mon, 26 Oct 2026 21:57:45 +0100 Subject: [PATCH 37/55] =?UTF-8?q?Answer=20prose=20round=201:=200=20?= =?UTF-8?q?=F0=9F=94=B4,=204=20=F0=9F=9F=A1=20(0=20misread);=20restate=20i?= =?UTF-8?q?tem=20230's=20tagline=20and=20detail?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- todo.md | 31 ++++++++----------------------- 1 file changed, 8 insertions(+), 23 deletions(-) diff --git a/todo.md b/todo.md index 03294910..a967873d 100644 --- a/todo.md +++ b/todo.md @@ -28,7 +28,7 @@ | 105 | 0.5.0 | | decision | **Compare review rounds per pass and reading cost for the five chunks before and after the `worker:` decision moved the principles out of the worker's context, and file an item if either rose.** | 1 | 2 | 1 | 2 | 2 | 1.4 by 6 | 8.0 | | 162 | 0.5.0 | | owner | **Script each step that 0.2.0's chunks repeated by hand and a program can compute, filing one item per step, and file this audit again for the next release.** | 2 | 2 | 1 | 3 | 3 | 1.4 by 4, 1.5 by 4 | 7.8 | | 175 | 0.5.0 | | | **Compare the first five chunks loop-claude starts with `chunk-preflight` against the five before them, and file an item where the preflight did not pay off.** | 1 | 2 | 1 | 2 | 2 | 1.4 by 3, 1.5 by 3 | 7.8 | -| 230 | 0.5.0 | | | **File one ambitious refactor of the lowest-scoring dimension whenever a scoring run scores a project under 7.0, so such a project always holds a plan item aimed at reaching 7.0.** | 3 | 2 | 3 | 6 | 4 | 1.1 by 7, 1.2 by 4 | 7.7 | +| 230 | 0.5.0 | | | **Have larv-review file one ambitious refactor item, aimed at the lowest-scoring dimension, whenever a scoring run leaves any score under 7.0, so such a project always holds a plan item meant to reach 7.0.** | 3 | 2 | 3 | 6 | 4 | 1.1 by 7, 1.2 by 4 | 7.7 | | 184 | 0.5.0 | | | **Rewrap the lines of `loop-claude --help` that run past the column the rest of it wraps at.** | 1 | 1 | 1 | 1 | 1 | code health by 1 | 7.2 | | 221 | 0.5.0 | | | **Parse each transcript entry once, where `bin/claude_code/transcript.py` reads it, into a typed value naming its kind, so no consumer works out an entry's kind from a raw `dict`.** | 3 | 1 | 3 | 5 | 5 | code health by 4 | 7.2 | | 116 | 0.5.0 | | | **Report L by the share of chunks with a 🔴, once 10 chunks that each shipped one item record finding counts and most record no 🔴.** | 1 | 1 | 2 | 2 | 2 | 1.1 by 5 | 7.0 | @@ -142,34 +142,19 @@ The chunk that ships this item files a copy of it in the release after the one i Item 161 put `chunk-preflight`'s facts into a fresh worker's prompt, so the worker no longer finds them itself. Before that, in item 140's chunk, the worker spent 5 min 46 s of 30 min, 16 of its 68 messages and 226k of its 491k fresh tokens before its first edit, through 12 Bash and 5 Read calls. Measure those figures from loop-claude's archive, as medians over the first five chunks that started with the preflight and the five before them: one chunk is too noisy a baseline, as `docs/decisions.md` → `reading cost: a rise is …` records. Measure the counter-signals beside them: goal 1.4's review rounds and unfinished verdicts, and goal 1.5's 🔴 findings, per chunk, since a worker that reads less may start sooner and need more rounds or let more defects through. Where time or tokens did not fall, or a counter-signal rose, file an item naming the facts the workers still found by hand, or what the preflight got wrong. -### 230. File one ambitious refactor of the lowest-scoring dimension whenever a scoring run scores a project under 7.0, so such a project always holds a plan item aimed at reaching 7.0. +### 230. Have larv-review file one ambitious refactor item, aimed at the lowest-scoring dimension, whenever a scoring run leaves any score under 7.0, so such a project always holds a plan item meant to reach 7.0. -Today `larv-review record-scoring` prints a `Floor:` line naming each mean under 7.0 -(`bin/larv_review/history_commands.py:52`), and larv-review §3 → "Record" only commits the run and -lists its scores. No rule turns that line into plan items. The places seats name reach the plan only -when another item happens to touch one, so a project under 7.0 can stay there with no item aimed at -it. A seat already named the doubt: `docs/comprehension-history.md:1536`, "a reader cannot tell -whether `Floor:` means stop". `~/.claude` has filed such items by hand, such as items 123 and -124; `~/code/log` held one open-ended item, its item 90, and kept no comprehension history. +Today `larv-review record-scoring` prints a `Floor:` line naming each mean under 7.0 (`bin/larv_review/history_commands.py:52`), and larv-review §3 → "Record" only commits the run and lists its scores. No rule turns that line into plan items. The places seats name reach the plan only when another item happens to touch one, so a project under 7.0 can stay there with no item aimed at it. -The human set the shape on 2026-10-26: the item filed is one ambitious refactor, not touch-ups. It -restructures the area behind the lowest dimension's places, sized to lift that dimension to 7.0, and -quotes the places it answers. Its tagline names the comprehension floor, so its chunk runs a scoring -run, and a run still under 7.0 files the next one. The chain stops when every score reaches 7.0. +The human set the shape on 2026-10-26: the item filed is one ambitious refactor, not touch-ups. It restructures the area behind the lowest dimension's places, sized to lift that dimension to 7.0, and quotes the places it answers. Its tagline names the comprehension floor, so its chunk runs a scoring run, and a run still under 7.0 files the next one. The chain stops when every score reaches 7.0. Settle in the change: -- Where the rule lives: larv-review §3 → "Record", and whether `record-scoring` prints the step - beside `Floor:` so no worker misses it. -- Duplicates: a release ends with two scoring runs, and an earlier run's item may still be open. - While one such item is open, a later run refreshes its places instead of filing another. -- Who files: a session below the project's rung drafts the item for a subagent on or above it, as - `rules/todo-items.md` says. -- Ranking: `docs/decisions.md` → `larv-review: within a chunk lifting a project towards the - comprehension floor, …` moves such an item's goals by 9 and lets it compete like any item. Say - whether an ambitious refactor, likely above R 5 and so shipping alone, keeps that. +- Where the rule lives: larv-review §3 → "Record", and whether `record-scoring` prints the step beside `Floor:` so no worker misses it. Seats already found `Floor:` unclear: `docs/comprehension-history.md:1536` says decision titles disagree on whether the floor blocks. +- Duplicates: a release ends with two scoring runs, and an earlier run's item may still be open. While one such item is open, a later run refreshes its places instead of filing another. The item a chunk ships doesn't count as open, so its own scoring run files the next one. +- Ranking: `docs/decisions.md` → `larv-review: within a chunk lifting a project towards the comprehension floor, …` moves such an item's goals by 9 and lets it compete like any other item. Say whether an ambitious refactor, likely above R 5 and so shipping alone, keeps both the move by 9 and that ranking. -Once it ships, `~/code/log` drops its item 98, which does the same by hand. +Once it ships, `~/code/log` drops its item 98, which does the same by hand, and revises the decisions that cite it. ### 184. Rewrap the lines of `loop-claude --help` that run past the column the rest of it wraps at. From ea6300a432265241bcff00816d8dfa92d73436f0 Mon Sep 17 00:00:00 2001 From: Lilleman auf Larv Date: Mon, 26 Oct 2026 23:32:03 +0100 Subject: [PATCH 38/55] Move each release forward one, and file items 231 to 234 into 0.4.0: context cost, parallel reviews, one principles auditor, dollar figures --- todo.md | 156 +++++++++++++++++++++++++++++++++++--------------------- 1 file changed, 98 insertions(+), 58 deletions(-) diff --git a/todo.md b/todo.md index a967873d..828a9f0f 100644 --- a/todo.md +++ b/todo.md @@ -6,72 +6,112 @@ `Bar = 0.1` -`Next ID = 231` +`Next ID = 235` ## Items | ID | Release | Blocked by | Exempt | Item | L | E | I | R | S | Moves | Score | |---|---|---|---|---|---|---|---|---|---|---|---| -| 226 | 0.4.0 | | question | **Answer whether rule-hook's `run-heavy` rule should also catch a mutation run or docker build behind `uv run`, `poetry run`, `python3 -m`, `sudo`, `docker image build` and `docker compose up --build`, or narrow the `machine load:` decision's wording.** | 2 | 2 | 3 | 5 | 3 | 1.2 by 2, 1.5 by 2 | 4.0 | -| 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 | -| 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 | -| 229 | 0.5.0 | | | **Keep the rule for which commands reach run-heavy's docker beside that docker in `bin/run_heavy/capped_docker.py`, so rule-hook's `docker-run-memory` asks it instead of repeating run-heavy's PATH rules.** | 2 | 1 | 3 | 4 | 2 | code health by 3 | 18.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 | -| 123 | 0.5.0 | | | **Have `bin/comprehension_history.py` parse each history entry once into seats, votes and places, so `latest_places`, `worse_places` and `worse_votes` neither depend on table order nor split a label to find a seat.** | 2 | 1 | 2 | 3 | 5 | code health by 5, 1.4 by 5 | 11.0 | -| 139 | 0.5.0 | | | **Split `bin/routing_figures/measure.py` by concern, and keep the figures' measured cycle and each raised call as fields loop-claude reads back, not as the prose it renders.** | 3 | 1 | 2 | 4 | 5 | code health by 5, 1.4 by 5 | 11.0 | -| 158 | 0.5.0 | | decision | **Measure the fixed cost of a chunk from loop-claude's archive, in tokens and hours against its items' S, and set F in `Score = 100 * V / (2**S + F)` to it.** | 2 | 2 | 1 | 3 | 3 | 1.1 by 5, 1.4 by 5 | 10.3 | -| 215 | 0.5.0 | | | **Decode a reload's handed JSON with a decoder for `LoopRun` and its `Route`, in place of `decoded_as`'s generic one with its two sentinels and `Route.fits` hook.** | 2 | 1 | 3 | 4 | 3 | code health by 2 | 9.0 | -| 49 | 0.5.0 | | principle | **Check that `AGENTS.md` lists exactly the titles of `docs/decisions.md`.** | 1 | 1 | 1 | 1 | 2 | 1.1 by 6 | 8.4 | -| 105 | 0.5.0 | | decision | **Compare review rounds per pass and reading cost for the five chunks before and after the `worker:` decision moved the principles out of the worker's context, and file an item if either rose.** | 1 | 2 | 1 | 2 | 2 | 1.4 by 6 | 8.0 | -| 162 | 0.5.0 | | owner | **Script each step that 0.2.0's chunks repeated by hand and a program can compute, filing one item per step, and file this audit again for the next release.** | 2 | 2 | 1 | 3 | 3 | 1.4 by 4, 1.5 by 4 | 7.8 | -| 175 | 0.5.0 | | | **Compare the first five chunks loop-claude starts with `chunk-preflight` against the five before them, and file an item where the preflight did not pay off.** | 1 | 2 | 1 | 2 | 2 | 1.4 by 3, 1.5 by 3 | 7.8 | -| 230 | 0.5.0 | | | **Have larv-review file one ambitious refactor item, aimed at the lowest-scoring dimension, whenever a scoring run leaves any score under 7.0, so such a project always holds a plan item meant to reach 7.0.** | 3 | 2 | 3 | 6 | 4 | 1.1 by 7, 1.2 by 4 | 7.7 | -| 184 | 0.5.0 | | | **Rewrap the lines of `loop-claude --help` that run past the column the rest of it wraps at.** | 1 | 1 | 1 | 1 | 1 | code health by 1 | 7.2 | -| 221 | 0.5.0 | | | **Parse each transcript entry once, where `bin/claude_code/transcript.py` reads it, into a typed value naming its kind, so no consumer works out an entry's kind from a raw `dict`.** | 3 | 1 | 3 | 5 | 5 | code health by 4 | 7.2 | -| 116 | 0.5.0 | | | **Report L by the share of chunks with a 🔴, once 10 chunks that each shipped one item record finding counts and most record no 🔴.** | 1 | 1 | 2 | 2 | 2 | 1.1 by 5 | 7.0 | -| 203 | 0.5.0 | | | **Make `bin/repo_checks` fail on a `todo.md` citation of a `docs/decisions.md` title that no heading holds.** | 1 | 1 | 1 | 1 | 2 | 1.1 by 5 | 7.0 | -| 113 | 0.5.0 | | | **Compute an item's S from the code it names, where it names any, and show it beside the finished items `score-outcomes` lists.** | 3 | 2 | 2 | 5 | 4 | 1.1 by 5, 1.4 by 5 | 6.8 | -| 112 | 0.5.0 | | | **Count an item as shipped only where its chunk built it, so an item a chunk dropped from the plan gets no outcome.** | 3 | 2 | 2 | 5 | 3 | 1.1 by 6 | 6.3 | -| 124 | 0.5.0 | | decision | **Group the shared modules at `bin/`'s root into packages named by purpose, so the root holds only launchers and stand-alone tools.** | 4 | 1 | 3 | 6 | 6 | code health by 5, 1.4 by 3 | 5.7 | -| 81 | 0.5.0 | | principle | **Have `workflow-bench/bench.py` return each run's failure as a value, so one failed clone does not hide the later runs' results.** | 1 | 2 | 1 | 2 | 2 | 1.1 by 4 | 5.6 | -| 102 | 0.5.0 | | | **Give loop-claude's retry delay an environment override, so the black-box test stops replacing `time.sleep` through `sitecustomize`.** | 1 | 1 | 2 | 2 | 2 | 1.1 by 4 | 5.6 | -| 173 | 0.5.0 | | | **Have rule-hook's `todo-rank-check` run a worktree's own `bin/rank_todo.py` when the worktree is of this repo, so a branch that changes `todo.md`'s shape commits without an override.** | 2 | 1 | 3 | 4 | 2 | 1.1 by 2, 1.4 by 2 | 5.5 | -| 101 | 0.5.0 | | principle | **Have `larv_review/history_commands.py`'s `read_seats` take the time, the commit check and the history as inputs, so it parses and decides without effects.** | 2 | 1 | 2 | 3 | 3 | 1.1 by 5 | 5.3 | -| 110 | 0.5.0 | | decision | **Count, for each finished chunk, the later changes that fixed code it wrote, and show them beside its guessed E.** | 3 | 2 | 2 | 5 | 5 | 1.1 by 6, 1.4 by 6 | 4.9 | -| 12 | 0.5.0 | | | **Run the test suite in CI on every PR, or record in `docs/decisions.md` why the local run is enough.** | 3 | 2 | 1 | 4 | 4 | 1.1 by 6 | 4.2 | -| 135 | 0.5.0 | | | **Fingerprint only the modules loop-claude imports, so editing another tool's code no longer reloads a running loop.** | 2 | 2 | 3 | 5 | 3 | 1.1 by 4 | 4.2 | -| 171 | 0.5.0 | | decision | **Group the routing figures' review rounds by the reviewers' rung as well as the worker's, so a call blames a rung only for rounds its own reviews raised.** | 3 | 2 | 2 | 5 | 4 | 1.2 by 3, 1.4 by 3 | 4.0 | -| 196 | 0.5.0 | | decision | **Replay the architecture, principles, overrides and product-owner passes with `review-replay` on Opus 5.5 projects, record each run in the review-replay routing decision, and add any rung a run qualifies to `REPLAYED`.** | 2 | 2 | 3 | 5 | 2 | 1.4 by 3 | 4.0 | -| 68 | 0.5.0 | | principle | **Test `workflow-bench/compare.py`'s blinding and `bench.py`'s run plan.** | 2 | 1 | 1 | 2 | 4 | 1.1 by 5 | 3.5 | -| 181 | 0.5.0 | | principle | **Have the test of a quoted answer's step-up assert the stepped rung's facts as literals, not through `prompts.rungs_held`.** | 1 | 1 | 1 | 1 | 1 | 1.1 by 2 | 3.4 | -| 192 | 0.5.0 | | principle | **Sort `.gitignore`'s allowlist block, from `!.claude/` to `!workflow-bench/test_review_git.py`, by code point, so rule-hook's `ignorefile-sorted` checks later edits to it again.** | 1 | 1 | 1 | 1 | 1 | 1.1 by 2 | 3.4 | -| 193 | 0.5.0 | | | **Narrow `readme_goals`'s mark to `Mark` by a typed lookup in place of `typing.cast`, so a mark added to the regex but not the lookup fails at run time, and one added to the lookup but not `Mark` fails mypy.** | 1 | 1 | 3 | 3 | 1 | 1.1 by 2 | 3.4 | -| 194 | 0.5.0 | | | **Make `test_waits_out_a_usage_limit_which_ends_a_run_of_failures` expect a usage-limit wait independent of the wall-clock time that passes during the run.** | 1 | 1 | 1 | 1 | 1 | 1.1 by 2 | 3.4 | -| 202 | 0.5.0 | | | **Add `CLAUDE.md` → "Prose"'s rule "Write negations as people say them", with its examples, to `skills/larv-review/standards/prose.md`, so the prose reviewer holds prose to it.** | 1 | 2 | 2 | 3 | 1 | 1.1 by 2 | 3.4 | -| 77 | 0.5.0 | | | **Teach `bin/metric-bench` Go and TypeScript, rerun it once two projects' comprehension histories name places, and bring into review only a metric that tracks the panel.** | 4 | 2 | 1 | 5 | 6 | 1.1 by 7, 1.4 by 7 | 3.2 | -| 4 | 0.5.0 | | | **Name each chunk's archive folder by the chunk's start time, so `/` lists chunks in the order they ran.** | 3 | 2 | 3 | 6 | 3 | 1.1 by 3 | 3.2 | -| 187 | 0.5.0 | | | **Count the tokens a worker spends reading reviewers' reports, so goal 1.4's signal shows whether report files lowered what a review costs the worker's context.** | 2 | 2 | 1 | 3 | 3 | 1.4 by 3 | 3.0 | -| 220 | 0.5.0 | | decision | **Have rule-hook also count a pass's earlier round commits on the branch, so a fourth commit titled round 3 is refused too.** | 3 | 2 | 3 | 6 | 3 | 1.4 by 3 | 3.0 | -| 149 | 0.5.0 | | decision | **Fill each release by priority up to a capacity it states, in place of the bar, and move what does not fit to a later release.** | 4 | 2 | 3 | 7 | 5 | 1.1 by 7 | 3.0 | -| 165 | 0.5.0 | | | **Make this repo's tests assert the facts a prompt or help text carries in place of its sentences, and drop the tests that scan source or assert a constant.** | 3 | 2 | 1 | 4 | 5 | 1.1 by 4, 1.4 by 3 | 2.9 | -| 151 | 0.5.0 | | decision | **Keep 10 to 20 settled decisions per project as its goals' test set, and rerun them after a goal changes.** | 3 | 2 | 2 | 5 | 5 | 1.2 by 7 | 2.9 | -| 156 | 0.5.0 | | decision | **Drop `rank_todo.py`'s ranking of an old-shape table once no project under `~/code` holds one.** | 2 | 1 | 3 | 4 | 4 | 1.1 by 4 | 2.8 | -| 201 | 0.5.0 | | owner | **Save the human's tmux setups and restore them after a reboot, so work is up and running again quickly.** | 3 | 2 | 1 | 4 | 4 | 1.5 by 4 | 2.6 | -| 5 | 0.5.0 | | decision | **Key a project on its checkout's full path, and refuse to start while another session uses that key.** | 4 | 2 | 3 | 7 | 5 | 1.1 by 6 | 2.5 | -| 155 | 0.5.0 | | | **Lower the reading cost of the files a chunk reads most before its first commit.** | 3 | 2 | 2 | 5 | 5 | 1.4 by 6 | 2.4 | -| 51 | 0.5.0 | | principle | **Hand loop-claude's terminal output to an injected effect, so no storage or retry function prints.** | 2 | 1 | 3 | 4 | 5 | 1.1 by 5 | 2.1 | -| 169 | 0.5.0 | | | **Have rule-hook's `todo-rank-check` catch a `todo.md` that the same Bash call edits and then commits.** | 3 | 1 | 3 | 5 | 3 | 1.1 by 2 | 2.1 | -| 174 | 0.5.0 | | | **In a chunk no item routed, ask the worker to name each todo.md item it takes, with its L and E + I, so loop-claude can route on an item it takes in.** | 1 | 2 | 3 | 4 | 1 | 1.1 by 1 | 1.7 | -| 197 | 0.5.0 | | | **Let the human edit what they type at loop-claude's terminal questions with the arrow keys, so Left moves the cursor in place of printing `^[[D`.** | 2 | 2 | 3 | 5 | 2 | 1.5 by 1 | 1.3 | -| 52 | 0.5.0 | | principle | **Record why this checkout lives in Claude Code's own directory, or move it out and link it in.** | 4 | 3 | 4 | 9 | 6 | 1.1 by 4 | 0.9 | -| 170 | 0.6.0 | | decision | **Re-tune `WORKER_STEPS` and `REVIEW_STEPS` once 50 chunks have shipped under them, from how well L, E and I order their review rounds and 🔴 findings.** | 2 | 2 | 3 | 5 | 2 | 1.1 by 3, 1.4 by 5 | 10.9 | -| 218 | 0.6.0 | 170 | | **Drop `LEGACY_WORKER` from `bin/model_routing/route.py`, so `route_from` reads only JSON worker lines.** | 1 | 2 | 1 | 2 | 1 | code health by 2 | 14.4 | +| 231 | 0.4.0 | | owner | **Lower what each chunk spends on context, in dollars first and hours second, through tooling that pinpoints what a worker or reviewer reads and through fresh or compacted contexts, with review quality unchanged.** | 4 | 2 | 3 | 7 | 8 | 1.4 by 8, 1.5 by 4 | 0.7 | +| 232 | 0.4.0 | 231 | | **Launch together every review pass of a round that waits on no other pass, so a round takes as long as its slowest reviewer, not the sum of them.** | 3 | 2 | 3 | 6 | 3 | 1.5 by 6 | 5.8 | +| 233 | 0.4.0 | 231 | | **Run one principles-auditor per round that checks every yardstick the project meets, in place of one per yardstick, so a round reads the project once.** | 3 | 2 | 3 | 6 | 3 | 1.4 by 3, 1.5 by 2 | 4.9 | +| 234 | 0.4.0 | 231 | | **Report the routing figures in dollars, cache reads included, from the cost each archived run records.** | 2 | 2 | 2 | 4 | 3 | 1.4 by 3 | 3.0 | +| 226 | 0.5.0 | | question | **Answer whether rule-hook's `run-heavy` rule should also catch a mutation run or docker build behind `uv run`, `poetry run`, `python3 -m`, `sudo`, `docker image build` and `docker compose up --build`, or narrow the `machine load:` decision's wording.** | 2 | 2 | 3 | 5 | 3 | 1.2 by 2, 1.5 by 2 | 4.0 | +| 59 | 0.5.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.5.0 | | | **Refuse a `/security-review` or `/claude-security` Skill call below the project's rung, as rule-hook refuses such an Agent call.** | 3 | 2 | 3 | 6 | 2 | 1.1 by 4 | 5.6 | +| 6 | 0.5.0 | | decision | **Move what `loop-claude` writes out of `~/.claude.json`, and ask the human about each write that must stay.** | 3 | 3 | 3 | 7 | 3 | 1.1 by 5 | 5.3 | +| 1 | 0.6.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 | +| 229 | 0.6.0 | | | **Keep the rule for which commands reach run-heavy's docker beside that docker in `bin/run_heavy/capped_docker.py`, so rule-hook's `docker-run-memory` asks it instead of repeating run-heavy's PATH rules.** | 2 | 1 | 3 | 4 | 2 | code health by 3 | 18.0 | +| 219 | 0.6.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.6.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 | +| 123 | 0.6.0 | | | **Have `bin/comprehension_history.py` parse each history entry once into seats, votes and places, so `latest_places`, `worse_places` and `worse_votes` neither depend on table order nor split a label to find a seat.** | 2 | 1 | 2 | 3 | 5 | code health by 5, 1.4 by 5 | 11.0 | +| 139 | 0.6.0 | | | **Split `bin/routing_figures/measure.py` by concern, and keep the figures' measured cycle and each raised call as fields loop-claude reads back, not as the prose it renders.** | 3 | 1 | 2 | 4 | 5 | code health by 5, 1.4 by 5 | 11.0 | +| 158 | 0.6.0 | | decision | **Measure the fixed cost of a chunk from loop-claude's archive, in tokens and hours against its items' S, and set F in `Score = 100 * V / (2**S + F)` to it.** | 2 | 2 | 1 | 3 | 3 | 1.1 by 5, 1.4 by 5 | 10.3 | +| 215 | 0.6.0 | | | **Decode a reload's handed JSON with a decoder for `LoopRun` and its `Route`, in place of `decoded_as`'s generic one with its two sentinels and `Route.fits` hook.** | 2 | 1 | 3 | 4 | 3 | code health by 2 | 9.0 | +| 49 | 0.6.0 | | principle | **Check that `AGENTS.md` lists exactly the titles of `docs/decisions.md`.** | 1 | 1 | 1 | 1 | 2 | 1.1 by 6 | 8.4 | +| 105 | 0.6.0 | | decision | **Compare review rounds per pass and reading cost for the five chunks before and after the `worker:` decision moved the principles out of the worker's context, and file an item if either rose.** | 1 | 2 | 1 | 2 | 2 | 1.4 by 6 | 8.0 | +| 162 | 0.6.0 | | owner | **Script each step that 0.2.0's chunks repeated by hand and a program can compute, filing one item per step, and file this audit again for the next release.** | 2 | 2 | 1 | 3 | 3 | 1.4 by 4, 1.5 by 4 | 7.8 | +| 175 | 0.6.0 | | | **Compare the first five chunks loop-claude starts with `chunk-preflight` against the five before them, and file an item where the preflight did not pay off.** | 1 | 2 | 1 | 2 | 2 | 1.4 by 3, 1.5 by 3 | 7.8 | +| 230 | 0.6.0 | | | **Have larv-review file one ambitious refactor item, aimed at the lowest-scoring dimension, whenever a scoring run leaves any score under 7.0, so such a project always holds a plan item meant to reach 7.0.** | 3 | 2 | 3 | 6 | 4 | 1.1 by 7, 1.2 by 4 | 7.7 | +| 184 | 0.6.0 | | | **Rewrap the lines of `loop-claude --help` that run past the column the rest of it wraps at.** | 1 | 1 | 1 | 1 | 1 | code health by 1 | 7.2 | +| 221 | 0.6.0 | | | **Parse each transcript entry once, where `bin/claude_code/transcript.py` reads it, into a typed value naming its kind, so no consumer works out an entry's kind from a raw `dict`.** | 3 | 1 | 3 | 5 | 5 | code health by 4 | 7.2 | +| 116 | 0.6.0 | | | **Report L by the share of chunks with a 🔴, once 10 chunks that each shipped one item record finding counts and most record no 🔴.** | 1 | 1 | 2 | 2 | 2 | 1.1 by 5 | 7.0 | +| 203 | 0.6.0 | | | **Make `bin/repo_checks` fail on a `todo.md` citation of a `docs/decisions.md` title that no heading holds.** | 1 | 1 | 1 | 1 | 2 | 1.1 by 5 | 7.0 | +| 113 | 0.6.0 | | | **Compute an item's S from the code it names, where it names any, and show it beside the finished items `score-outcomes` lists.** | 3 | 2 | 2 | 5 | 4 | 1.1 by 5, 1.4 by 5 | 6.8 | +| 112 | 0.6.0 | | | **Count an item as shipped only where its chunk built it, so an item a chunk dropped from the plan gets no outcome.** | 3 | 2 | 2 | 5 | 3 | 1.1 by 6 | 6.3 | +| 124 | 0.6.0 | | decision | **Group the shared modules at `bin/`'s root into packages named by purpose, so the root holds only launchers and stand-alone tools.** | 4 | 1 | 3 | 6 | 6 | code health by 5, 1.4 by 3 | 5.7 | +| 81 | 0.6.0 | | principle | **Have `workflow-bench/bench.py` return each run's failure as a value, so one failed clone does not hide the later runs' results.** | 1 | 2 | 1 | 2 | 2 | 1.1 by 4 | 5.6 | +| 102 | 0.6.0 | | | **Give loop-claude's retry delay an environment override, so the black-box test stops replacing `time.sleep` through `sitecustomize`.** | 1 | 1 | 2 | 2 | 2 | 1.1 by 4 | 5.6 | +| 173 | 0.6.0 | | | **Have rule-hook's `todo-rank-check` run a worktree's own `bin/rank_todo.py` when the worktree is of this repo, so a branch that changes `todo.md`'s shape commits without an override.** | 2 | 1 | 3 | 4 | 2 | 1.1 by 2, 1.4 by 2 | 5.5 | +| 101 | 0.6.0 | | principle | **Have `larv_review/history_commands.py`'s `read_seats` take the time, the commit check and the history as inputs, so it parses and decides without effects.** | 2 | 1 | 2 | 3 | 3 | 1.1 by 5 | 5.3 | +| 110 | 0.6.0 | | decision | **Count, for each finished chunk, the later changes that fixed code it wrote, and show them beside its guessed E.** | 3 | 2 | 2 | 5 | 5 | 1.1 by 6, 1.4 by 6 | 4.9 | +| 12 | 0.6.0 | | | **Run the test suite in CI on every PR, or record in `docs/decisions.md` why the local run is enough.** | 3 | 2 | 1 | 4 | 4 | 1.1 by 6 | 4.2 | +| 135 | 0.6.0 | | | **Fingerprint only the modules loop-claude imports, so editing another tool's code no longer reloads a running loop.** | 2 | 2 | 3 | 5 | 3 | 1.1 by 4 | 4.2 | +| 171 | 0.6.0 | | decision | **Group the routing figures' review rounds by the reviewers' rung as well as the worker's, so a call blames a rung only for rounds its own reviews raised.** | 3 | 2 | 2 | 5 | 4 | 1.2 by 3, 1.4 by 3 | 4.0 | +| 196 | 0.6.0 | | decision | **Replay the architecture, principles, overrides and product-owner passes with `review-replay` on Opus 5.5 projects, record each run in the review-replay routing decision, and add any rung a run qualifies to `REPLAYED`.** | 2 | 2 | 3 | 5 | 2 | 1.4 by 3 | 4.0 | +| 68 | 0.6.0 | | principle | **Test `workflow-bench/compare.py`'s blinding and `bench.py`'s run plan.** | 2 | 1 | 1 | 2 | 4 | 1.1 by 5 | 3.5 | +| 181 | 0.6.0 | | principle | **Have the test of a quoted answer's step-up assert the stepped rung's facts as literals, not through `prompts.rungs_held`.** | 1 | 1 | 1 | 1 | 1 | 1.1 by 2 | 3.4 | +| 192 | 0.6.0 | | principle | **Sort `.gitignore`'s allowlist block, from `!.claude/` to `!workflow-bench/test_review_git.py`, by code point, so rule-hook's `ignorefile-sorted` checks later edits to it again.** | 1 | 1 | 1 | 1 | 1 | 1.1 by 2 | 3.4 | +| 193 | 0.6.0 | | | **Narrow `readme_goals`'s mark to `Mark` by a typed lookup in place of `typing.cast`, so a mark added to the regex but not the lookup fails at run time, and one added to the lookup but not `Mark` fails mypy.** | 1 | 1 | 3 | 3 | 1 | 1.1 by 2 | 3.4 | +| 194 | 0.6.0 | | | **Make `test_waits_out_a_usage_limit_which_ends_a_run_of_failures` expect a usage-limit wait independent of the wall-clock time that passes during the run.** | 1 | 1 | 1 | 1 | 1 | 1.1 by 2 | 3.4 | +| 202 | 0.6.0 | | | **Add `CLAUDE.md` → "Prose"'s rule "Write negations as people say them", with its examples, to `skills/larv-review/standards/prose.md`, so the prose reviewer holds prose to it.** | 1 | 2 | 2 | 3 | 1 | 1.1 by 2 | 3.4 | +| 77 | 0.6.0 | | | **Teach `bin/metric-bench` Go and TypeScript, rerun it once two projects' comprehension histories name places, and bring into review only a metric that tracks the panel.** | 4 | 2 | 1 | 5 | 6 | 1.1 by 7, 1.4 by 7 | 3.2 | +| 4 | 0.6.0 | | | **Name each chunk's archive folder by the chunk's start time, so `/` lists chunks in the order they ran.** | 3 | 2 | 3 | 6 | 3 | 1.1 by 3 | 3.2 | +| 187 | 0.6.0 | | | **Count the tokens a worker spends reading reviewers' reports, so goal 1.4's signal shows whether report files lowered what a review costs the worker's context.** | 2 | 2 | 1 | 3 | 3 | 1.4 by 3 | 3.0 | +| 220 | 0.6.0 | | decision | **Have rule-hook also count a pass's earlier round commits on the branch, so a fourth commit titled round 3 is refused too.** | 3 | 2 | 3 | 6 | 3 | 1.4 by 3 | 3.0 | +| 149 | 0.6.0 | | decision | **Fill each release by priority up to a capacity it states, in place of the bar, and move what does not fit to a later release.** | 4 | 2 | 3 | 7 | 5 | 1.1 by 7 | 3.0 | +| 165 | 0.6.0 | | | **Make this repo's tests assert the facts a prompt or help text carries in place of its sentences, and drop the tests that scan source or assert a constant.** | 3 | 2 | 1 | 4 | 5 | 1.1 by 4, 1.4 by 3 | 2.9 | +| 151 | 0.6.0 | | decision | **Keep 10 to 20 settled decisions per project as its goals' test set, and rerun them after a goal changes.** | 3 | 2 | 2 | 5 | 5 | 1.2 by 7 | 2.9 | +| 156 | 0.6.0 | | decision | **Drop `rank_todo.py`'s ranking of an old-shape table once no project under `~/code` holds one.** | 2 | 1 | 3 | 4 | 4 | 1.1 by 4 | 2.8 | +| 201 | 0.6.0 | | owner | **Save the human's tmux setups and restore them after a reboot, so work is up and running again quickly.** | 3 | 2 | 1 | 4 | 4 | 1.5 by 4 | 2.6 | +| 5 | 0.6.0 | | decision | **Key a project on its checkout's full path, and refuse to start while another session uses that key.** | 4 | 2 | 3 | 7 | 5 | 1.1 by 6 | 2.5 | +| 155 | 0.6.0 | | | **Lower the reading cost of the files a chunk reads most before its first commit.** | 3 | 2 | 2 | 5 | 5 | 1.4 by 6 | 2.4 | +| 51 | 0.6.0 | | principle | **Hand loop-claude's terminal output to an injected effect, so no storage or retry function prints.** | 2 | 1 | 3 | 4 | 5 | 1.1 by 5 | 2.1 | +| 169 | 0.6.0 | | | **Have rule-hook's `todo-rank-check` catch a `todo.md` that the same Bash call edits and then commits.** | 3 | 1 | 3 | 5 | 3 | 1.1 by 2 | 2.1 | +| 174 | 0.6.0 | | | **In a chunk no item routed, ask the worker to name each todo.md item it takes, with its L and E + I, so loop-claude can route on an item it takes in.** | 1 | 2 | 3 | 4 | 1 | 1.1 by 1 | 1.7 | +| 197 | 0.6.0 | | | **Let the human edit what they type at loop-claude's terminal questions with the arrow keys, so Left moves the cursor in place of printing `^[[D`.** | 2 | 2 | 3 | 5 | 2 | 1.5 by 1 | 1.3 | +| 52 | 0.6.0 | | principle | **Record why this checkout lives in Claude Code's own directory, or move it out and link it in.** | 4 | 3 | 4 | 9 | 6 | 1.1 by 4 | 0.9 | +| 170 | 0.7.0 | | decision | **Re-tune `WORKER_STEPS` and `REVIEW_STEPS` once 50 chunks have shipped under them, from how well L, E and I order their review rounds and 🔴 findings.** | 2 | 2 | 3 | 5 | 2 | 1.1 by 3, 1.4 by 5 | 10.9 | +| 218 | 0.7.0 | 170 | | **Drop `LEGACY_WORKER` from `bin/model_routing/route.py`, so `route_from` reads only JSON worker lines.** | 1 | 2 | 1 | 2 | 1 | code health by 2 | 14.4 | ## Details +### 231. Lower what each chunk spends on context, in dollars first and hours second, through tooling that pinpoints what a worker or reviewer reads and through fresh or compacted contexts, with review quality unchanged. + +lilleman's call, 2026-10-26: this item runs on Fable 5.1 at max. An L of 4 routes the worker only to Opus 5.5 at high, so the worker hands the evaluation and every edit to one subagent launched with `model fable, effort max`. The priorities, in order: context cost, then speed, and never at a loss of quality. Where the effect on quality is hard to tell, or very close, ask lilleman. + +Measured on 2026-10-26 from loop-claude's archive, over the 104 worker runs and about 720 subagent runs since the reset of 2026-10-21, priced at list prices: + +- The runs cost about $1,940, and cache reads, the context each turn reads again, are $985 of it. The routing figures leave cache reads out (item 234). +- Worker main threads are 53% of the cost. A worker starts at about 40k tokens of context and peaks at a median 189k, one in ten past 490k, the largest at 850k. Its turns above 200k are 64% of what workers cost. +- Bash output is 70% of the tool output a worker reads, most of it `cat`, `sed` and `head` of whole files. Principles auditors read 24M characters of files, each auditor reading the project anew. + +`docs/decisions.md` → `loop-claude: one session per project` gives each chunk a fresh session to keep context small. The growth is within a chunk, so that decision stands in the way of none of the options below. + +Evaluate ambitiously, measuring each option's cost, hours and quality on comparable chunks, at least: + +- Code-structure tooling in place of Bash reads: Claude Code's LSP tool, a code-intelligence MCP server, a symbol or outline lookup. +- Tooling that pinpoints lines: Read with an offset and a limit, Grep with context, in place of `cat`, `sed` and `head` of whole files, and a rule or hook that steers to it. +- Compaction: Claude Code's auto-compact at a lower threshold, or a smaller context window. +- A fresh context for the review phase, handed only the chunk's facts and the reviewers' verdicts. +- What a reviewer reads: the diff and the places it touches, in place of the whole project. + +Quality is review rounds and unfinished verdicts per chunk, 🔴 and 🟡 findings per chunk, and findings a later change fixes, before and after; replay archived rounds with `review-replay` where it applies. Record each choice in `docs/decisions.md`, and file an item for each option worth doing later. + +It blocks items 232 and 233, since what a reviewer reads, and how its report reaches the worker, is part of this evaluation, and item 234, which makes this item's dollar measure the standing figure. + +### 232. Launch together every review pass of a round that waits on no other pass, so a round takes as long as its slowest reviewer, not the sum of them. + +Since 2026-10-21, all 1,372 Agent calls in workers' transcripts were one per message, 94% of them in the foreground, and waiting on subagents took 66% of a worker's active time. larv-review §3 orders the passes so no polish goes into code the architect restructures or the security pass rewrites. Keep that: a pass waits only for a pass whose findings could make its work wasted, and the rest of the round's passes, the principles auditors among them, launch in one message. A round that "Re-entry" reruns launches the same way. + +### 233. Run one principles-auditor per round that checks every yardstick the project meets, in place of one per yardstick, so a round reads the project once. + +Since 2026-10-21, 253 principles-auditor runs cost about $304, 16% of all, and each read the project anew. The merged auditor must find what the separate ones found: replay archived rounds with `review-replay`, and keep one auditor per yardstick where the merged one misses a 🔴 or 🟡. Report files are named `principles--round-.md` today, in larv-review §3 → "Reports". + +### 234. Report the routing figures in dollars, cache reads included, from the cost each archived run records. + +The routing figures count input, cache-written and output tokens, and leave out cache reads, which were 51% of the cost since 2026-10-21. So their tables rank the principles auditor above the worker, while in dollars the worker cost three times as much. Each archived worker transcript ends with a `cost-state` entry holding `totalCostUSD` and each model's cost, and each message's usage attributes the cost to a subagent type. The judge's runs record no cost in the archive: count them too, or say why not. The change touches `bin/routing_figures/measure.py`, which the comprehension seats found hard (item 139): make the places it touches easier to read. + ### 226. Answer whether rule-hook's `run-heavy` rule should also catch a mutation run or docker build behind `uv run`, `poetry run`, `python3 -m`, `sudo`, `docker image build` and `docker compose up --build`, or narrow the `machine load:` decision's wording. Found by review of PR #370. Today `uv run mutmut run`, `poetry run mutmut run`, `python3 -m mutmut run`, `sudo docker build .`, `docker image build .` and `docker compose up --build` pass the rule, which `docs/decisions.md` → `machine load: …` and `RULES["run-heavy"]` describe as blocking docker builds and mutation runs. The rule's own text says a gate script isn't checked since no program can tell it from a light one, so the human decides where the line sits. Say what the rule's "checked" text promises either way. Where the answer widens the rule, the change touches `heavy` in `bin/rule_hook/heavy_command.py`, which the comprehension seats found hard: make it easier to read. From a0458e0a2ca4fc9772d4ccf5985a6a303c12512b Mon Sep 17 00:00:00 2001 From: Lilleman auf Larv Date: Mon, 26 Oct 2026 23:35:12 +0100 Subject: [PATCH 39/55] =?UTF-8?q?Answer=20prose=20round=201:=200=20?= =?UTF-8?q?=F0=9F=94=B4,=205=20=F0=9F=9F=A1=20(0=20misread);=20restate=20i?= =?UTF-8?q?tems=20231=20to=20233's=20taglines=20and=20details?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- todo.md | 30 +++++++++++++++--------------- 1 file changed, 15 insertions(+), 15 deletions(-) diff --git a/todo.md b/todo.md index 828a9f0f..ad25c17d 100644 --- a/todo.md +++ b/todo.md @@ -12,9 +12,9 @@ | ID | Release | Blocked by | Exempt | Item | L | E | I | R | S | Moves | Score | |---|---|---|---|---|---|---|---|---|---|---|---| -| 231 | 0.4.0 | | owner | **Lower what each chunk spends on context, in dollars first and hours second, through tooling that pinpoints what a worker or reviewer reads and through fresh or compacted contexts, with review quality unchanged.** | 4 | 2 | 3 | 7 | 8 | 1.4 by 8, 1.5 by 4 | 0.7 | -| 232 | 0.4.0 | 231 | | **Launch together every review pass of a round that waits on no other pass, so a round takes as long as its slowest reviewer, not the sum of them.** | 3 | 2 | 3 | 6 | 3 | 1.5 by 6 | 5.8 | -| 233 | 0.4.0 | 231 | | **Run one principles-auditor per round that checks every yardstick the project meets, in place of one per yardstick, so a round reads the project once.** | 3 | 2 | 3 | 6 | 3 | 1.4 by 3, 1.5 by 2 | 4.9 | +| 231 | 0.4.0 | | owner | **Lower what each chunk spends on context in dollars, then its hours, by the best means an ambitious evaluation finds, such as tooling that pinpoints what an agent reads and fresh or compacted contexts, with no loss of quality.** | 4 | 2 | 3 | 7 | 8 | 1.4 by 8, 1.5 by 4 | 0.7 | +| 232 | 0.4.0 | 231 | | **Launch a round's review passes in one message, except a pass that must wait for another's findings, so a round lasts about as long as its slowest reviewers, not their sum.** | 3 | 2 | 3 | 6 | 3 | 1.5 by 6 | 5.8 | +| 233 | 0.4.0 | 231 | | **Run one principles-auditor per round that checks the goals and every principles file that applies, in place of one auditor for each, so the principles pass reads the project once per round.** | 3 | 2 | 3 | 6 | 3 | 1.4 by 3, 1.5 by 2 | 4.9 | | 234 | 0.4.0 | 231 | | **Report the routing figures in dollars, cache reads included, from the cost each archived run records.** | 2 | 2 | 2 | 4 | 3 | 1.4 by 3 | 3.0 | | 226 | 0.5.0 | | question | **Answer whether rule-hook's `run-heavy` rule should also catch a mutation run or docker build behind `uv run`, `poetry run`, `python3 -m`, `sudo`, `docker image build` and `docker compose up --build`, or narrow the `machine load:` decision's wording.** | 2 | 2 | 3 | 5 | 3 | 1.2 by 2, 1.5 by 2 | 4.0 | | 59 | 0.5.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 | @@ -76,37 +76,37 @@ ## Details -### 231. Lower what each chunk spends on context, in dollars first and hours second, through tooling that pinpoints what a worker or reviewer reads and through fresh or compacted contexts, with review quality unchanged. +### 231. Lower what each chunk spends on context in dollars, then its hours, by the best means an ambitious evaluation finds, such as tooling that pinpoints what an agent reads and fresh or compacted contexts, with no loss of quality. -lilleman's call, 2026-10-26: this item runs on Fable 5.1 at max. An L of 4 routes the worker only to Opus 5.5 at high, so the worker hands the evaluation and every edit to one subagent launched with `model fable, effort max`. The priorities, in order: context cost, then speed, and never at a loss of quality. Where the effect on quality is hard to tell, or very close, ask lilleman. +lilleman's call, 2026-10-26: this is the plan's most important item, and it goes first. It runs on Fable 5.1 at max. An L of 4 routes the worker at most to Opus 5.5 at high, so the worker hands the evaluation and every edit to one subagent launched with `model fable, effort max`. The priorities, in order: context cost, then speed, and never at a loss of quality. Where the effect on quality is hard to tell, or very close, ask lilleman. -Measured on 2026-10-26 from loop-claude's archive, over the 104 worker runs and about 720 subagent runs since the reset of 2026-10-21, priced at list prices: +Measured on 2026-10-26 from loop-claude's archive, over the 104 worker runs and about 720 subagent runs since the routing figures' last reset on 2026-10-21, priced at list prices: - The runs cost about $1,940, and cache reads, the context each turn reads again, are $985 of it. The routing figures leave cache reads out (item 234). - Worker main threads are 53% of the cost. A worker starts at about 40k tokens of context and peaks at a median 189k, one in ten past 490k, the largest at 850k. Its turns above 200k are 64% of what workers cost. - Bash output is 70% of the tool output a worker reads, most of it `cat`, `sed` and `head` of whole files. Principles auditors read 24M characters of files, each auditor reading the project anew. -`docs/decisions.md` → `loop-claude: one session per project` gives each chunk a fresh session to keep context small. The growth is within a chunk, so that decision stands in the way of none of the options below. +loop-claude starts each chunk in a fresh session, which lilleman meant to keep context small (`docs/decisions.md` → `loop-claude: one session per project`). The context grows within a chunk, so that decision doesn't block any option below. -Evaluate ambitiously, measuring each option's cost, hours and quality on comparable chunks, at least: +Evaluate at least these options, ambitiously, measuring each one's cost, hours and quality on comparable chunks: - Code-structure tooling in place of Bash reads: Claude Code's LSP tool, a code-intelligence MCP server, a symbol or outline lookup. -- Tooling that pinpoints lines: Read with an offset and a limit, Grep with context, in place of `cat`, `sed` and `head` of whole files, and a rule or hook that steers to it. +- Tools that pinpoint lines, such as Read with an offset and a limit and Grep with context, in place of `cat`, `sed` and `head` of whole files, with a rule or hook that steers agents to those tools. - Compaction: Claude Code's auto-compact at a lower threshold, or a smaller context window. - A fresh context for the review phase, handed only the chunk's facts and the reviewers' verdicts. - What a reviewer reads: the diff and the places it touches, in place of the whole project. -Quality is review rounds and unfinished verdicts per chunk, 🔴 and 🟡 findings per chunk, and findings a later change fixes, before and after; replay archived rounds with `review-replay` where it applies. Record each choice in `docs/decisions.md`, and file an item for each option worth doing later. +Judge quality by these figures per chunk, before and after: review rounds, unfinished verdicts, 🔴 and 🟡 findings, and findings that a later change fixes. Replay archived rounds with `review-replay` where it applies. Record each choice where `~/.claude/CLAUDE.md` → "Ask, don't guess" puts it, and file an item for each option worth doing later. -It blocks items 232 and 233, since what a reviewer reads, and how its report reaches the worker, is part of this evaluation, and item 234, which makes this item's dollar measure the standing figure. +Items 232, 233 and 234 wait for this item. Item 233 changes what a reviewer reads, which this item evaluates; items 232 and 234 wait on lilleman's call alone. -### 232. Launch together every review pass of a round that waits on no other pass, so a round takes as long as its slowest reviewer, not the sum of them. +### 232. Launch a round's review passes in one message, except a pass that must wait for another's findings, so a round lasts about as long as its slowest reviewers, not their sum. -Since 2026-10-21, all 1,372 Agent calls in workers' transcripts were one per message, 94% of them in the foreground, and waiting on subagents took 66% of a worker's active time. larv-review §3 orders the passes so no polish goes into code the architect restructures or the security pass rewrites. Keep that: a pass waits only for a pass whose findings could make its work wasted, and the rest of the round's passes, the principles auditors among them, launch in one message. A round that "Re-entry" reruns launches the same way. +Since 2026-10-21, all 1,372 Agent calls in workers' transcripts were one per message, 94% of them in the foreground, and waiting on subagents took 66% of a worker's active time. larv-review §3 orders the passes so no polish goes into code the architect restructures or the security pass rewrites. Keep that: a pass waits only for a pass whose findings could make its review a waste. Launch the rest of the round's passes, the principles auditors among them, in one message. Do the same for the passes a fix reruns, per §3 → "Re-entry". -### 233. Run one principles-auditor per round that checks every yardstick the project meets, in place of one per yardstick, so a round reads the project once. +### 233. Run one principles-auditor per round that checks the goals and every principles file that applies, in place of one auditor for each, so the principles pass reads the project once per round. -Since 2026-10-21, 253 principles-auditor runs cost about $304, 16% of all, and each read the project anew. The merged auditor must find what the separate ones found: replay archived rounds with `review-replay`, and keep one auditor per yardstick where the merged one misses a 🔴 or 🟡. Report files are named `principles--round-.md` today, in larv-review §3 → "Reports". +Since 2026-10-21, 253 principles-auditor runs cost about $304, 16% of all, and each read the project anew. Today larv-review §3 → "Principles" launches one auditor for the README's goals and code health, and one per file in `~/.claude/principles/` that applies. The merged auditor must find what the separate ones found: replay archived rounds with `review-replay`, and keep separate auditors where the merged one misses a 🔴 or 🟡. Rename the report files, `principles--round-.md` today (§3 → "Reports"), to one per round. ### 234. Report the routing figures in dollars, cache reads included, from the cost each archived run records. From f2e239d111d9cb5d06a841c6522d6839da365f67 Mon Sep 17 00:00:00 2001 From: Lilleman auf Larv Date: Tue, 27 Oct 2026 00:13:08 +0100 Subject: [PATCH 40/55] Compact the worker's context above 200k tokens, from item 231's evaluation of context cost, and file items 235 and 236 --- AGENTS.md | 1 + CHANGELOG.md | 1 + CLAUDE.md | 4 ++++ bin/loop_claude/cycle/run.py | 6 +++--- bin/loop_claude/cycle/worker.py | 3 +++ bin/loop_claude/loop/main.py | 4 ++++ bin/loop_claude/test_loop_claude.py | 2 +- docs/decisions.md | 21 +++++++++++++++++++++ todo.md | 18 ++++++++++++++---- 9 files changed, 52 insertions(+), 8 deletions(-) diff --git a/AGENTS.md b/AGENTS.md index b09427d3..0b3970d9 100644 --- a/AGENTS.md +++ b/AGENTS.md @@ -15,6 +15,7 @@ Decisions live in `docs/decisions.md`: - loop-claude: every claude it starts bypasses permissions inside its sandbox - 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 +- loop-claude: the worker's claude compacts its context above 200k tokens, and `CLAUDE.md` → "Compact instructions" says what the summary keeps - 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 has a memory limit and a swap limit as large as its work needs; rule-hook's `docker-run-memory` blocks a `docker run` or `docker create` without them outside run-heavy, under which a container that lacks them gets the slot's share of three quarters of the memory; 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 diff --git a/CHANGELOG.md b/CHANGELOG.md index c6fbe3a3..94f346d8 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,7 @@ ## Unreleased +- loop-claude's worker now compacts its context once it passes 200k tokens, handed as `CLAUDE_CODE_AUTO_COMPACT_WINDOW`; Claude Code compacted it at about 967k before. Since 2026-10-21, a worker's turns above 200k were 55% of what workers cost, and the chunks that compacted took no more review rounds per message than those that did not. `CLAUDE.md` has a new section, "Compact instructions", saying what the summary keeps. - On Linux, `run-heavy` now caps the memory of a container its command makes with `docker run` or `docker create`. A container that sets no limit gets a memory limit and a swap limit, both the slot's share: three quarters of the machine's memory, split across the heavy slots. A container that sets one of the two limits keeps it, and gets the other as large. This covers containers a project's own scripts start, which rule-hook can't see. A `docker compose` service, and a docker named by its full path, get no cap. rule-hook's `docker-run-memory` now lets a `docker run` under run-heavy pass. - 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. diff --git a/CLAUDE.md b/CLAUDE.md index ac1b89b3..0d4e2af4 100644 --- a/CLAUDE.md +++ b/CLAUDE.md @@ -104,6 +104,10 @@ The rules only reviewers apply, for quality, comments, READMEs and prose, live i - **A list or threshold a consumer relies on is sourced.** Deny-lists, defaults, limits: follow a published standard or a widely deployed tool, and cite it in the decision recording the choice; where none exists, ask. Never assemble one from names that seem plausible. - When a page renders client-side and comes back empty/blocked, use the Playwright renderer at `~/code/playwright-for-agents/` — `./pw [options]` (see its README). Don't use claude-in-chrome for this. +## Compact instructions + +When you compact, keep in the summary: the task loop-claude gave and each `todo.md` item the chunk takes, with its L and E + I; the worktree, branch and PR; the rung loop-claude named for each review launch, rerun and escalated subagent; each review pass's rounds so far, each open 🔴 and 🟡, and how the answered ones were answered; every question the human answered, with the answer; each escalation trigger that fired; and what remains before the chunk is finished. + ## Vocabulary - **chunk** — the unit of work, shipped as one PR; "Working loop" says what it holds. diff --git a/bin/loop_claude/cycle/run.py b/bin/loop_claude/cycle/run.py index cf65353b..d7b9ba77 100644 --- a/bin/loop_claude/cycle/run.py +++ b/bin/loop_claude/cycle/run.py @@ -5,6 +5,7 @@ import typing from loop_claude.cycle.states import Active, Archived, Closing, Ended, Event, HumanTalked, HumanTyped, Interrupting, Judging, QUOTED_ANSWERS_PER_CYCLE, Ruled, State, TalkChosen, Talking, transition, TypedAnswer, WorkerRan, Working from loop_claude.routing import after_ruling, judge_rung from transcript_archive.write import archive +from loop_claude.cycle.worker import AUTO_COMPACT_WINDOW, COMPACT_ABOVE, run_worker, worker_args from claude_code.session import delete_session, Session, session_open, transcript_file from loop_claude.effects import Effects from failure import Failure @@ -17,7 +18,6 @@ from loop_claude.cycle.interrupt import put_question, talk, Talk from claude_code.transcript import read_transcript from loop_claude.cycle.retry import retried from model_routing.route import Route -from loop_claude.cycle.worker import run_worker, worker_args from model_routing.ladder import Rung from loop_claude.escalation_mark import StepUp from loop_claude.stop import Stop @@ -116,8 +116,8 @@ def work(cycle: Cycle, answered: QuotedAnswer | TypedAnswer | None, step_up: Ste def worker_environment(cycle: Cycle) -> dict[str, str]: - """The rungs the worker's claude is handed, which rule-hook holds its review launches to.""" - return worker_rungs.environment(cycle.project, cycle.route) + """The rungs the worker's claude is handed, which rule-hook holds its review launches to, and the context size above which it compacts.""" + return {**worker_rungs.environment(cycle.project, cycle.route), AUTO_COMPACT_WINDOW: str(COMPACT_ABOVE)} def worker_start(cycle: Cycle, answered: QuotedAnswer | TypedAnswer | None, step_up: StepUp | None) -> list[str]: diff --git a/bin/loop_claude/cycle/worker.py b/bin/loop_claude/cycle/worker.py index 2a63b85f..8587ef38 100644 --- a/bin/loop_claude/cycle/worker.py +++ b/bin/loop_claude/cycle/worker.py @@ -12,6 +12,9 @@ from claude_code.session import Session PRINTED_TOOL_INPUT = 160 # Seconds between reads of the machine's memory while too little of it is available to start a worker. MEMORY_POLL = 60 +# The context size, in tokens, above which the worker's claude compacts, handed to it in this variable: docs/decisions.md → `loop-claude: the worker's claude compacts its context above 200k tokens`. +AUTO_COMPACT_WINDOW = "CLAUDE_CODE_AUTO_COMPACT_WINDOW" +COMPACT_ABOVE = 200_000 def run_worker(root: str, args: list[str], env: dict[str, str], effects: Effects) -> Failure | Limited | None: diff --git a/bin/loop_claude/loop/main.py b/bin/loop_claude/loop/main.py index 909ed5ec..6bc6c9ea 100644 --- a/bin/loop_claude/loop/main.py +++ b/bin/loop_claude/loop/main.py @@ -47,6 +47,10 @@ time. The layout, and when a copy is replaced, are in bin/transcript_archive/__i Before each worker starts, loop-claude waits until at least a quarter of the machine's memory is available (bin/machine_load/memory.py). +Each worker's claude, and the session /talk opens, compacts its context once it passes 200k tokens, +handed as CLAUDE_CODE_AUTO_COMPACT_WINDOW (bin/loop_claude/cycle/worker.py), so a long chunk +re-reads less each turn; ~/.claude/CLAUDE.md → "Compact instructions" says what the summary keeps. + Every claude loop-claude starts runs the project's model, saved per in ~/.claude/loop-claude-models.json and read each cycle, unless routing, below, puts the worker, the session /talk opens and the judge on another rung, a model at an effort. A project without an diff --git a/bin/loop_claude/test_loop_claude.py b/bin/loop_claude/test_loop_claude.py index e330fc82..c55a5bca 100644 --- a/bin/loop_claude/test_loop_claude.py +++ b/bin/loop_claude/test_loop_claude.py @@ -256,7 +256,7 @@ class Cycles(unittest.TestCase): fake = FakeEffects(streams=[Worker(self.paths.claude_code_transcripts.parent)], claude=[judged("finished")]) cycle = dataclasses.replace(self.cycle(fake), project=Rung("claude-opus-5-5", "medium"), route=Route(Rung("claude-haiku-5-5", "max"), 163, 1, 5)) self.assertEqual(run.run_cycle(cycle).verdict, Finished("working")) - self.assertEqual(fake.worker_environments, [{"LOOP_CLAUDE_PROJECT_RUNG": "claude-opus-5-5 at medium effort", "LOOP_CLAUDE_WORKER_RUNG": "claude-haiku-5-5 at max effort", "LOOP_CLAUDE_ESCAPE_AND_IMPACT": "5"}]) + self.assertEqual(fake.worker_environments, [{"LOOP_CLAUDE_PROJECT_RUNG": "claude-opus-5-5 at medium effort", "LOOP_CLAUDE_WORKER_RUNG": "claude-haiku-5-5 at max effort", "LOOP_CLAUDE_ESCAPE_AND_IMPACT": "5", "CLAUDE_CODE_AUTO_COMPACT_WINDOW": "200000"}]) def test_the_claude_an_interrupt_resumes_is_handed_the_same_rungs_as_the_worker(self): def answer(args): diff --git a/docs/decisions.md b/docs/decisions.md index b2b44cd7..ffba8260 100644 --- a/docs/decisions.md +++ b/docs/decisions.md @@ -72,6 +72,27 @@ The cap is 5, `bin/todo_table.py`'s `BUNDLE_MAX_R`, from the same chunks: by the 2026-09-28, lilleman. Serves goals 1 and 3: saving each transcript locally is the first step of backing it up, and it shows afterwards what an unattended run did. A copy of the `.jsonl`, deduplicated by content hash, with its outcomes beside it; a rendering drops tool results, and a second-resolution stamp names two states within one second as one file. A failed archive exits 1, since a loop that loses its record silently fails the backup goal. Valid while transcripts stay small enough to copy whole. +## loop-claude: the worker's claude compacts its context above 200k tokens, and `CLAUDE.md` → "Compact instructions" says what the summary keeps + +2026-10-27, claude through todo item 231, awaiting lilleman's yes. Serves goal 1.4, under goal 1.1's counter-signal. Item 231 asked for the best means to lower what a chunk spends on context, in dollars, then hours, with no loss of quality. + +Measured from loop-claude's archive over the 90 chunks with messages after the routing figures' reset of 2026-10-21, at the list prices read on 2026-10-26 (Opus 5.5: $4 per million input tokens, $5 and $8 for 5-minute and 1-hour cache writes, $0.20 for cache reads, $20 for output; no model but Haiku 5.5 charges more above 200k): $1,215, which is 0.86 of what the chunks' `cost-state` entries sum to, since some chunks' subagent transcripts are not in the archive. Worker main threads cost $375 (31%): 1-hour cache writes $149, cache reads $153, output $74. Subagents cost $840: 5-minute cache writes $379, output $274, cache reads $187, with the principles auditors at $274 over 342 runs, the stability reviewers $179 and general-purpose subagents $192. A worker starts at 41k tokens of context and peaks at a median 167k, one in ten past 358k, the largest at 848k: Claude Code compacts a model with a native 1M window at about 967k. The worker's messages above 200k were 32% of its messages and 55% of its cost. + +Each option item 231 named, on those chunks: + +- Compaction. Compacting the worker above 200k saves $78 of the workers' $375, 6% of all spend, at 0.5 compactions per chunk; above 150k $75 at 1.0; above 300k $54 at 0.2. It also bounds at 200k the 36 re-writes of a whole context, up to 785k tokens, after a gap longer than the cache's hour or a change of rung, which cost $62. Compacting subagents above 150k costs more than it saves, since a compaction reads the context once more and writes a summary, and subagents are short. A 200k window through `CLAUDE_CODE_DISABLE_1M_CONTEXT` would compact at the same point and also narrow every interactive session. +- A fresh context for the review phase, handed 60k tokens of facts, saves $39, which compaction covers, and loop-claude would need a second session per chunk. +- Read with an offset and a limit, or Grep, in place of `cat`, `sed` and `head`: the worker's tool results were 13.2M characters, 65% of them Bash reads, but only 13% whole files; the rest were ranges. A character a worker reads costs about $8 per million tokens to write to the 1-hour cache and $0.20 per million at each later turn, so all the worker's reads cost about $45 and the whole-file ones about $6. A rule would change the tool, not how much is read. +- Code-intelligence tooling: the `LSP` tool, with a language server per language on PATH, replaces a grep and the reads of candidate files with one lookup. Its ceiling is the same $45, and each machine would need a server per language (goal 2). Not tried. +- What a reviewer reads: the auditors read the project whole by design. Of their 🔴 and 🟡 findings since the reset, 47% named a file the chunk edited and 51% another file, so reading only the change would drop half of them; item 236 asks lilleman about that scope, and item 233 has one auditor read the project once per round. +- The base context: every thread starts with `~/.claude/CLAUDE.md` (19k characters), `~/.claude/AGENTS.md` (11k, this repo's decisions, which Claude Code loads as user instructions into every project's sessions; item 52), the project's `AGENTS.md`, and, for the worker and general-purpose subagents, the skill listing (18k) and the agent listing (12k). Subagents' first messages wrote $97 of it; trimming the listings would save about $20. + +Quality. 19 chunks compacted between 2026-10-10 and 2026-10-22, at 214k to 972k tokens, the windows Claude Code tuned then. Per 100 worker messages they took a median 3.6 review rounds past each pass's first against 4.0 for the 68 uncompacted chunks of 100 messages or more, and 13.9 🔴 and 🟡 findings against 16.6. 4 of 19 had an unfinished verdict against 3 of 68, each 8 to 10 hours after the compaction and followed by a finished verdict within minutes. Two summaries read whole kept the chunk's intent, files, errors and next step in 12k to 20k characters, and the worker resumed without re-reading. A compaction takes 51 to 83 seconds, under a minute per chunk at 0.5 each. + +The window is handed to the worker, and the session /talk opens, as `CLAUDE_CODE_AUTO_COMPACT_WINDOW` (`bin/loop_claude/cycle/worker.py`), not set in `settings.json`: the archive measured loop-claude's workers, and interactive sessions are lilleman's. Subagents inherit it, and at 200k almost none compacts. A probe on 2026-10-27 showed that a `Compact instructions` section in a CLAUDE.md shapes the summary: a session whose CLAUDE.md asked the summary to end with its secret word did. So `CLAUDE.md` → "Compact instructions" names what a worker's summary keeps. Path-scoped rules leave the context at a compaction and return at the next matching read, and rule-hook holds each review launch to its rung whatever the summary keeps. Item 235 compares the first 20 chunks under the window with the 20 before. + +Valid while cache reads cost a twentieth of input and Claude Code's compaction keeps the worker's task. + ## 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. diff --git a/todo.md b/todo.md index ad25c17d..73dab6af 100644 --- a/todo.md +++ b/todo.md @@ -6,7 +6,7 @@ `Bar = 0.1` -`Next ID = 235` +`Next ID = 237` ## Items @@ -16,7 +16,9 @@ | 232 | 0.4.0 | 231 | | **Launch a round's review passes in one message, except a pass that must wait for another's findings, so a round lasts about as long as its slowest reviewers, not their sum.** | 3 | 2 | 3 | 6 | 3 | 1.5 by 6 | 5.8 | | 233 | 0.4.0 | 231 | | **Run one principles-auditor per round that checks the goals and every principles file that applies, in place of one auditor for each, so the principles pass reads the project once per round.** | 3 | 2 | 3 | 6 | 3 | 1.4 by 3, 1.5 by 2 | 4.9 | | 234 | 0.4.0 | 231 | | **Report the routing figures in dollars, cache reads included, from the cost each archived run records.** | 2 | 2 | 2 | 4 | 3 | 1.4 by 3 | 3.0 | +| 236 | 0.5.0 | | question | **Answer whether the principles audit keeps reading the whole project, or reads only the files the chunk changed and their callers, now that half of its 🔴 and 🟡 findings name a file the chunk did not edit.** | 1 | 1 | 1 | 1 | 1 | 1.4 by 4 | 6.4 | | 226 | 0.5.0 | | question | **Answer whether rule-hook's `run-heavy` rule should also catch a mutation run or docker build behind `uv run`, `poetry run`, `python3 -m`, `sudo`, `docker image build` and `docker compose up --build`, or narrow the `machine load:` decision's wording.** | 2 | 2 | 3 | 5 | 3 | 1.2 by 2, 1.5 by 2 | 4.0 | +| 235 | 0.5.0 | | | **Compare review rounds past each pass's first, unfinished verdicts, 🔴, 🟡 and misread findings, and dollars per chunk, for the first 20 chunks whose worker ran under the 200k compaction window against the 20 before them, and file an item where any rose.** | 1 | 2 | 1 | 2 | 2 | 1.1 by 2, 1.4 by 3 | 6.8 | | 59 | 0.5.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.5.0 | | | **Refuse a `/security-review` or `/claude-security` Skill call below the project's rung, as rule-hook refuses such an Agent call.** | 3 | 2 | 3 | 6 | 2 | 1.1 by 4 | 5.6 | | 6 | 0.5.0 | | decision | **Move what `loop-claude` writes out of `~/.claude.json`, and ask the human about each write that must stay.** | 3 | 3 | 3 | 7 | 3 | 1.1 by 5 | 5.3 | @@ -96,7 +98,7 @@ Evaluate at least these options, ambitiously, measuring each one's cost, hours a - A fresh context for the review phase, handed only the chunk's facts and the reviewers' verdicts. - What a reviewer reads: the diff and the places it touches, in place of the whole project. -Judge quality by these figures per chunk, before and after: review rounds, unfinished verdicts, 🔴 and 🟡 findings, and findings that a later change fixes. Replay archived rounds with `review-replay` where it applies. Record each choice where `~/.claude/CLAUDE.md` → "Ask, don't guess" puts it, and file an item for each option worth doing later. +Judge quality by these figures per chunk, before and after: review rounds, unfinished verdicts, 🔴 and 🟡 findings, and findings that a later change fixes. Replay archived rounds with `review-replay` where it applies. Record each choice where `~/.claude/CLAUDE.md` → "Working loop", "Ask, don't guess" puts it, and file an item for each option worth doing later. Items 232, 233 and 234 wait for this item. Item 233 changes what a reviewer reads, which this item evaluates; items 232 and 234 wait on lilleman's call alone. @@ -106,16 +108,24 @@ Since 2026-10-21, all 1,372 Agent calls in workers' transcripts were one per mes ### 233. Run one principles-auditor per round that checks the goals and every principles file that applies, in place of one auditor for each, so the principles pass reads the project once per round. -Since 2026-10-21, 253 principles-auditor runs cost about $304, 16% of all, and each read the project anew. Today larv-review §3 → "Principles" launches one auditor for the README's goals and code health, and one per file in `~/.claude/principles/` that applies. The merged auditor must find what the separate ones found: replay archived rounds with `review-replay`, and keep separate auditors where the merged one misses a 🔴 or 🟡. Rename the report files, `principles--round-.md` today (§3 → "Reports"), to one per round. +Since 2026-10-21, 342 principles-auditor runs cost $274 at list prices, 23% of all spend and 3.8 runs per chunk, and each read the project anew: $129 of 5-minute cache writes, $92 of output and $53 of cache reads. Today larv-review §3 → "Principles" launches one auditor for the README's goals and code health, and one per file in `~/.claude/principles/` that applies. The merged auditor must find what the separate ones found: replay archived rounds with `review-replay`, and keep separate auditors where the merged one misses a 🔴 or 🟡. Rename the report files, `principles--round-.md` today (§3 → "Reports"), to one per round. ### 234. Report the routing figures in dollars, cache reads included, from the cost each archived run records. The routing figures count input, cache-written and output tokens, and leave out cache reads, which were 51% of the cost since 2026-10-21. So their tables rank the principles auditor above the worker, while in dollars the worker cost three times as much. Each archived worker transcript ends with a `cost-state` entry holding `totalCostUSD` and each model's cost, and each message's usage attributes the cost to a subagent type. The judge's runs record no cost in the archive: count them too, or say why not. The change touches `bin/routing_figures/measure.py`, which the comprehension seats found hard (item 139): make the places it touches easier to read. +### 236. Answer whether the principles audit keeps reading the whole project, or reads only the files the chunk changed and their callers, now that half of its 🔴 and 🟡 findings name a file the chunk did not edit. + +Since 2026-10-21, 342 principles-auditor runs cost $274 at list prices, 23% of all spend, and 176 of their 🔴 and 🟡 findings named a file: 83 a file the chunk edited, 90 another. `docs/decisions.md` → `review: the principles audit runs on every chunk…` holds the whole-project audit valid while its findings are drift a chunk would otherwise merge, and calls a repeat a question on the audit's scope for the human. Reading only the changed files and their callers would cut most of the auditors' $129 of cache writes and drop the findings elsewhere, unless those repeat chunk after chunk: read a sample of the 90 before answering. Item 233 merges the auditors either way. + ### 226. Answer whether rule-hook's `run-heavy` rule should also catch a mutation run or docker build behind `uv run`, `poetry run`, `python3 -m`, `sudo`, `docker image build` and `docker compose up --build`, or narrow the `machine load:` decision's wording. Found by review of PR #370. Today `uv run mutmut run`, `poetry run mutmut run`, `python3 -m mutmut run`, `sudo docker build .`, `docker image build .` and `docker compose up --build` pass the rule, which `docs/decisions.md` → `machine load: …` and `RULES["run-heavy"]` describe as blocking docker builds and mutation runs. The rule's own text says a gate script isn't checked since no program can tell it from a light one, so the human decides where the line sits. Say what the rule's "checked" text promises either way. Where the answer widens the rule, the change touches `heavy` in `bin/rule_hook/heavy_command.py`, which the comprehension seats found hard: make it easier to read. +### 235. Compare review rounds past each pass's first, unfinished verdicts, 🔴, 🟡 and misread findings, and dollars per chunk, for the first 20 chunks whose worker ran under the 200k compaction window against the 20 before them, and file an item where any rose. + +`docs/decisions.md` → `loop-claude: the worker's claude compacts its context above 200k tokens…` expects a saving of about 6% of all spend with no rise in these figures. Measure from loop-claude's archive as that decision did: rounds past each pass's first and the 🔴, 🟡 and misread counts from the round commit titles, unfinished verdicts from the outcomes files, and dollars from each message's usage at list prices, cache reads included, which item 234 puts into the routing figures. A chunk ran under the window when its first worker started after that decision merged. + ### 59. Bound a run of unfinished verdicts on one chunk, so a worker and judge that disagree cannot cycle unattended without end. Raised by the product-owner review of PR #211. The resumed worker gets the judge's quote of the work remaining, but a worker that still thinks the chunk done can answer each cycle the same way, and each cycle costs a worker and a judge run (goal 1.4). @@ -386,7 +396,7 @@ The principles pass of PR #301 found that only `routed_by` in `bin/loop_claude/c ### 52. Record why this checkout lives in Claude Code's own directory, or move it out and link it in. -"One owner per value" and "Prefer the vendor-neutral option", in `principles/technical-principles.md`: git, Claude Code and loop-claude all write `~/.claude`, kept apart only by the `.gitignore` allowlist, and the repo's records live in a vendor directory. +"One owner per value" and "Prefer the vendor-neutral option", in `principles/technical-principles.md`: git, Claude Code and loop-claude all write `~/.claude`, kept apart only by the `.gitignore` allowlist, and the repo's records live in a vendor directory. Claude Code also loads `~/.claude/AGENTS.md`, this checkout's decision titles, as the user's instructions into every session of every project: 10.7k characters, about 2.7k tokens, in each of the 1,084 threads since 2026-10-21, about $25 of cache writes and reads at list prices, and a worker on another project reads this repo's decisions as if they held there. ### 170. Re-tune `WORKER_STEPS` and `REVIEW_STEPS` once 50 chunks have shipped under them, from how well L, E and I order their review rounds and 🔴 findings. From 14736e8e6e1f4aec9bd3764aecf29bb94b59deed Mon Sep 17 00:00:00 2001 From: Lilleman auf Larv Date: Tue, 27 Oct 2026 00:32:10 +0100 Subject: [PATCH 41/55] =?UTF-8?q?Answer=20principles=20round=201:=200=20?= =?UTF-8?q?=F0=9F=94=B4,=209=20=F0=9F=9F=A1=20(0=20misread);=20name=20the?= =?UTF-8?q?=20200k=20window's=20compaction=20point,=20read=20a=20compactio?= =?UTF-8?q?n=20summary=20as=20Claude=20Code's,=20remove=20item=20231,=20re?= =?UTF-8?q?fresh=20items=20234,=20235,=2052=20and=20102,=20file=20item=202?= =?UTF-8?q?37?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- AGENTS.md | 2 +- CHANGELOG.md | 2 +- CLAUDE.md | 2 +- bin/claude_code/entries.py | 3 +- bin/claude_code/test_claude_code.py | 1 + bin/loop_claude/cycle/run.py | 6 +-- bin/loop_claude/cycle/worker.py | 4 +- bin/loop_claude/loop/main.py | 7 +-- bin/loop_claude/test_loop_claude.py | 2 +- docs/decisions.md | 16 ++++--- todo.md | 66 ++++++++++------------------- 11 files changed, 48 insertions(+), 63 deletions(-) diff --git a/AGENTS.md b/AGENTS.md index 0b3970d9..aa6f454d 100644 --- a/AGENTS.md +++ b/AGENTS.md @@ -15,7 +15,7 @@ Decisions live in `docs/decisions.md`: - loop-claude: every claude it starts bypasses permissions inside its sandbox - 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 -- loop-claude: the worker's claude compacts its context above 200k tokens, and `CLAUDE.md` → "Compact instructions" says what the summary keeps +- loop-claude: the worker's claude compacts its context before it fills a 200k window, at about 170k tokens, and `CLAUDE.md` → "Compact instructions" says what the summary keeps - 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 has a memory limit and a swap limit as large as its work needs; rule-hook's `docker-run-memory` blocks a `docker run` or `docker create` without them outside run-heavy, under which a container that lacks them gets the slot's share of three quarters of the memory; 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 diff --git a/CHANGELOG.md b/CHANGELOG.md index 94f346d8..ce5f87b3 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,7 +2,7 @@ ## Unreleased -- loop-claude's worker now compacts its context once it passes 200k tokens, handed as `CLAUDE_CODE_AUTO_COMPACT_WINDOW`; Claude Code compacted it at about 967k before. Since 2026-10-21, a worker's turns above 200k were 55% of what workers cost, and the chunks that compacted took no more review rounds per message than those that did not. `CLAUDE.md` has a new section, "Compact instructions", saying what the summary keeps. +- loop-claude's worker now runs with a 200k auto-compact window, handed as `CLAUDE_CODE_AUTO_COMPACT_WINDOW`, so Claude Code compacts its context at about 170k tokens; before, at about 967k. Since 2026-10-21, a worker's turns above 200k were 55% of what workers cost. The 19 chunks that compacted before took no more review rounds or findings per message than those that did not, but 4 of them had an unfinished verdict against 3 of 68; `todo.md` item 235 measures the first 20 chunks under the window. loop-claude's judge no longer reads a compaction summary as words the human typed. `CLAUDE.md` has a new section, "Compact instructions", saying what the summary keeps. - On Linux, `run-heavy` now caps the memory of a container its command makes with `docker run` or `docker create`. A container that sets no limit gets a memory limit and a swap limit, both the slot's share: three quarters of the machine's memory, split across the heavy slots. A container that sets one of the two limits keeps it, and gets the other as large. This covers containers a project's own scripts start, which rule-hook can't see. A `docker compose` service, and a docker named by its full path, get no cap. rule-hook's `docker-run-memory` now lets a `docker run` under run-heavy pass. - 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. diff --git a/CLAUDE.md b/CLAUDE.md index 0d4e2af4..d8453073 100644 --- a/CLAUDE.md +++ b/CLAUDE.md @@ -106,7 +106,7 @@ The rules only reviewers apply, for quality, comments, READMEs and prose, live i ## Compact instructions -When you compact, keep in the summary: the task loop-claude gave and each `todo.md` item the chunk takes, with its L and E + I; the worktree, branch and PR; the rung loop-claude named for each review launch, rerun and escalated subagent; each review pass's rounds so far, each open 🔴 and 🟡, and how the answered ones were answered; every question the human answered, with the answer; each escalation trigger that fired; and what remains before the chunk is finished. +Claude Code reads this section by its heading when it compacts a conversation. When you compact, keep in the summary: the task loop-claude gave and each `todo.md` item the chunk takes, with its L and E + I; the worktree, branch and PR; the rung loop-claude named for each review launch, rerun and escalated subagent; each review pass's rounds so far, each open 🔴 and 🟡, and how the answered ones were answered; every question the human answered, with the answer; each escalation trigger that fired; and what remains before the chunk is finished. ## Vocabulary diff --git a/bin/claude_code/entries.py b/bin/claude_code/entries.py index bea76c7a..7bbfee5c 100644 --- a/bin/claude_code/entries.py +++ b/bin/claude_code/entries.py @@ -36,8 +36,9 @@ def written_by_human(entry: dict) -> bool: # {"type": "user", "isMeta": true, "message": {"content": "Caveat: ..."}} # {"type": "user", "promptSource": "sdk", "message": {"content": "Continue the task; ..."}} # {"type": "user", "promptSource": "system", "message": {"content": "..."}} +# {"type": "user", "isCompactSummary": true, "message": {"content": "This session is being continued from a previous conversation that ran out of context. ..."}} def tagged_as_injected(entry: dict) -> bool: - return bool(entry.get("isMeta")) or entry.get("promptSource") in ("sdk", "system") + return bool(entry.get("isMeta")) or bool(entry.get("isCompactSummary")) or entry.get("promptSource") in ("sdk", "system") # {"type": "user", "promptSource": "typed", "message": {"content": "merge it"}} diff --git a/bin/claude_code/test_claude_code.py b/bin/claude_code/test_claude_code.py index 9ba7db64..ebc8537d 100644 --- a/bin/claude_code/test_claude_code.py +++ b/bin/claude_code/test_claude_code.py @@ -66,6 +66,7 @@ class HumanTurns(unittest.TestCase): {**human([{"type": "text", "text": "done"}]), "promptSource": "system"}, {**human("peer message"), "isMeta": True}, {**human("the loop's own prompt"), "promptSource": "sdk"}, + {**human("This session is being continued from a previous conversation that ran out of context. The summary below covers the earlier portion of the conversation."), "isCompactSummary": True}, human([{"type": "text", "text": "[Request interrupted by user]"}]), human([]), queued("typed while claude worked", "human"), diff --git a/bin/loop_claude/cycle/run.py b/bin/loop_claude/cycle/run.py index d7b9ba77..2020178b 100644 --- a/bin/loop_claude/cycle/run.py +++ b/bin/loop_claude/cycle/run.py @@ -5,7 +5,7 @@ import typing from loop_claude.cycle.states import Active, Archived, Closing, Ended, Event, HumanTalked, HumanTyped, Interrupting, Judging, QUOTED_ANSWERS_PER_CYCLE, Ruled, State, TalkChosen, Talking, transition, TypedAnswer, WorkerRan, Working from loop_claude.routing import after_ruling, judge_rung from transcript_archive.write import archive -from loop_claude.cycle.worker import AUTO_COMPACT_WINDOW, COMPACT_ABOVE, run_worker, worker_args +from loop_claude.cycle.worker import AUTO_COMPACT_WINDOW, COMPACT_WINDOW, run_worker, worker_args from claude_code.session import delete_session, Session, session_open, transcript_file from loop_claude.effects import Effects from failure import Failure @@ -116,8 +116,8 @@ def work(cycle: Cycle, answered: QuotedAnswer | TypedAnswer | None, step_up: Ste def worker_environment(cycle: Cycle) -> dict[str, str]: - """The rungs the worker's claude is handed, which rule-hook holds its review launches to, and the context size above which it compacts.""" - return {**worker_rungs.environment(cycle.project, cycle.route), AUTO_COMPACT_WINDOW: str(COMPACT_ABOVE)} + """The rungs the worker's claude is handed, which rule-hook holds its review launches to, and the auto-compact window of its context.""" + return {**worker_rungs.environment(cycle.project, cycle.route), AUTO_COMPACT_WINDOW: str(COMPACT_WINDOW)} def worker_start(cycle: Cycle, answered: QuotedAnswer | TypedAnswer | None, step_up: StepUp | None) -> list[str]: diff --git a/bin/loop_claude/cycle/worker.py b/bin/loop_claude/cycle/worker.py index 8587ef38..728a80df 100644 --- a/bin/loop_claude/cycle/worker.py +++ b/bin/loop_claude/cycle/worker.py @@ -12,9 +12,9 @@ from claude_code.session import Session PRINTED_TOOL_INPUT = 160 # Seconds between reads of the machine's memory while too little of it is available to start a worker. MEMORY_POLL = 60 -# The context size, in tokens, above which the worker's claude compacts, handed to it in this variable: docs/decisions.md → `loop-claude: the worker's claude compacts its context above 200k tokens`. +# The auto-compact window, in tokens, handed to the worker's claude in this variable. Claude Code compacts before the window fills, at about 170k: docs/decisions.md → `loop-claude: the worker's claude compacts its context before it fills a 200k window`. AUTO_COMPACT_WINDOW = "CLAUDE_CODE_AUTO_COMPACT_WINDOW" -COMPACT_ABOVE = 200_000 +COMPACT_WINDOW = 200_000 def run_worker(root: str, args: list[str], env: dict[str, str], effects: Effects) -> Failure | Limited | None: diff --git a/bin/loop_claude/loop/main.py b/bin/loop_claude/loop/main.py index 6bc6c9ea..c9997b93 100644 --- a/bin/loop_claude/loop/main.py +++ b/bin/loop_claude/loop/main.py @@ -47,9 +47,10 @@ time. The layout, and when a copy is replaced, are in bin/transcript_archive/__i Before each worker starts, loop-claude waits until at least a quarter of the machine's memory is available (bin/machine_load/memory.py). -Each worker's claude, and the session /talk opens, compacts its context once it passes 200k tokens, -handed as CLAUDE_CODE_AUTO_COMPACT_WINDOW (bin/loop_claude/cycle/worker.py), so a long chunk -re-reads less each turn; ~/.claude/CLAUDE.md → "Compact instructions" says what the summary keeps. +Each worker's claude, and the session /talk opens, runs with a 200k auto-compact window, handed as +CLAUDE_CODE_AUTO_COMPACT_WINDOW (bin/loop_claude/cycle/worker.py), so it compacts its context at +about 170k tokens and a long chunk re-reads less each turn. +~/.claude/CLAUDE.md → "Compact instructions" says what the summary keeps. Every claude loop-claude starts runs the project's model, saved per in ~/.claude/loop-claude-models.json and read each cycle, unless routing, below, puts the worker, diff --git a/bin/loop_claude/test_loop_claude.py b/bin/loop_claude/test_loop_claude.py index c55a5bca..3e536840 100644 --- a/bin/loop_claude/test_loop_claude.py +++ b/bin/loop_claude/test_loop_claude.py @@ -252,7 +252,7 @@ class Cycles(unittest.TestCase): self.assertIn("- A preflight fact.", fresh) self.assertNotIn("- A preflight fact.", resumed) - def test_a_worker_is_handed_the_projects_rung_its_own_and_its_reviews_e_plus_i_in_its_environment(self): + def test_a_worker_is_handed_the_projects_rung_its_own_its_reviews_e_plus_i_and_its_compaction_window_in_its_environment(self): fake = FakeEffects(streams=[Worker(self.paths.claude_code_transcripts.parent)], claude=[judged("finished")]) cycle = dataclasses.replace(self.cycle(fake), project=Rung("claude-opus-5-5", "medium"), route=Route(Rung("claude-haiku-5-5", "max"), 163, 1, 5)) self.assertEqual(run.run_cycle(cycle).verdict, Finished("working")) diff --git a/docs/decisions.md b/docs/decisions.md index ffba8260..15716777 100644 --- a/docs/decisions.md +++ b/docs/decisions.md @@ -72,24 +72,26 @@ The cap is 5, `bin/todo_table.py`'s `BUNDLE_MAX_R`, from the same chunks: by the 2026-09-28, lilleman. Serves goals 1 and 3: saving each transcript locally is the first step of backing it up, and it shows afterwards what an unattended run did. A copy of the `.jsonl`, deduplicated by content hash, with its outcomes beside it; a rendering drops tool results, and a second-resolution stamp names two states within one second as one file. A failed archive exits 1, since a loop that loses its record silently fails the backup goal. Valid while transcripts stay small enough to copy whole. -## loop-claude: the worker's claude compacts its context above 200k tokens, and `CLAUDE.md` → "Compact instructions" says what the summary keeps +## loop-claude: the worker's claude compacts its context before it fills a 200k window, at about 170k tokens, and `CLAUDE.md` → "Compact instructions" says what the summary keeps -2026-10-27, claude through todo item 231, awaiting lilleman's yes. Serves goal 1.4, under goal 1.1's counter-signal. Item 231 asked for the best means to lower what a chunk spends on context, in dollars, then hours, with no loss of quality. +2026-10-27, claude through todo item 231, awaiting lilleman's yes before the merge. Serves goal 1.4, under goal 1.1's counter-signal. Item 231 asked for the best means to lower what a chunk spends on context, in dollars, then hours, with no loss of quality. Measured from loop-claude's archive over the 90 chunks with messages after the routing figures' reset of 2026-10-21, at the list prices read on 2026-10-26 (Opus 5.5: $4 per million input tokens, $5 and $8 for 5-minute and 1-hour cache writes, $0.20 for cache reads, $20 for output; no model but Haiku 5.5 charges more above 200k): $1,215, which is 0.86 of what the chunks' `cost-state` entries sum to, since some chunks' subagent transcripts are not in the archive. Worker main threads cost $375 (31%): 1-hour cache writes $149, cache reads $153, output $74. Subagents cost $840: 5-minute cache writes $379, output $274, cache reads $187, with the principles auditors at $274 over 342 runs, the stability reviewers $179 and general-purpose subagents $192. A worker starts at 41k tokens of context and peaks at a median 167k, one in ten past 358k, the largest at 848k: Claude Code compacts a model with a native 1M window at about 967k. The worker's messages above 200k were 32% of its messages and 55% of its cost. Each option item 231 named, on those chunks: -- Compaction. Compacting the worker above 200k saves $78 of the workers' $375, 6% of all spend, at 0.5 compactions per chunk; above 150k $75 at 1.0; above 300k $54 at 0.2. It also bounds at 200k the 36 re-writes of a whole context, up to 785k tokens, after a gap longer than the cache's hour or a change of rung, which cost $62. Compacting subagents above 150k costs more than it saves, since a compaction reads the context once more and writes a summary, and subagents are short. A 200k window through `CLAUDE_CODE_DISABLE_1M_CONTEXT` would compact at the same point and also narrow every interactive session. +- Compaction. Compacting the worker at 167k to 180k saves $77 to $78 of the workers' $375, 6% of all spend, at 0.7 to 0.8 compactions per chunk; at 150k $75 at 1.0, at 200k $78 at 0.5, at 300k $54 at 0.2. It also caps the 36 re-writes of a whole context after a gap longer than the cache's hour or a change of rung, $61 at up to 785k tokens each, at about $34. Compacting subagents at 150k costs more than it saves, since a compaction reads the context once more and writes a summary, and subagents are short. A 200k window through `CLAUDE_CODE_DISABLE_1M_CONTEXT` would compact at the same point and also narrow every interactive session. - A fresh context for the review phase, handed 60k tokens of facts, saves $39, which compaction covers, and loop-claude would need a second session per chunk. - Read with an offset and a limit, or Grep, in place of `cat`, `sed` and `head`: the worker's tool results were 13.2M characters, 65% of them Bash reads, but only 13% whole files; the rest were ranges. A character a worker reads costs about $8 per million tokens to write to the 1-hour cache and $0.20 per million at each later turn, so all the worker's reads cost about $45 and the whole-file ones about $6. A rule would change the tool, not how much is read. -- Code-intelligence tooling: the `LSP` tool, with a language server per language on PATH, replaces a grep and the reads of candidate files with one lookup. Its ceiling is the same $45, and each machine would need a server per language (goal 2). Not tried. +- Code-intelligence tooling: the `LSP` tool, with a language server per language on PATH, replaces a grep and the reads of candidate files with one lookup. Its ceiling is the same $45, and each machine would need a server per language (goal 2). Not tried, and not worth an item while the worker's reads stay under 4% of spend. - What a reviewer reads: the auditors read the project whole by design. Of their 🔴 and 🟡 findings since the reset, 47% named a file the chunk edited and 51% another file, so reading only the change would drop half of them; item 236 asks lilleman about that scope, and item 233 has one auditor read the project once per round. -- The base context: every thread starts with `~/.claude/CLAUDE.md` (19k characters), `~/.claude/AGENTS.md` (11k, this repo's decisions, which Claude Code loads as user instructions into every project's sessions; item 52), the project's `AGENTS.md`, and, for the worker and general-purpose subagents, the skill listing (18k) and the agent listing (12k). Subagents' first messages wrote $97 of it; trimming the listings would save about $20. +- The base context: every thread starts with `~/.claude/CLAUDE.md` (19k characters), `~/.claude/AGENTS.md` (11k, this repo's decisions, which Claude Code loads as user instructions into every project's sessions; item 52), the project's `AGENTS.md`, and, for the worker and general-purpose subagents, the skill listing (18k) and the agent listing (12k). Subagents' first messages wrote $97 of it; trimming the listings would save about $20, 2%, and is not worth an item: `disableBundledSkills` would also drop `/security-review`, the security pass of record. -Quality. 19 chunks compacted between 2026-10-10 and 2026-10-22, at 214k to 972k tokens, the windows Claude Code tuned then. Per 100 worker messages they took a median 3.6 review rounds past each pass's first against 4.0 for the 68 uncompacted chunks of 100 messages or more, and 13.9 🔴 and 🟡 findings against 16.6. 4 of 19 had an unfinished verdict against 3 of 68, each 8 to 10 hours after the compaction and followed by a finished verdict within minutes. Two summaries read whole kept the chunk's intent, files, errors and next step in 12k to 20k characters, and the worker resumed without re-reading. A compaction takes 51 to 83 seconds, under a minute per chunk at 0.5 each. +Quality. 19 chunks compacted between 2026-10-10 and 2026-10-22, at 214k to 972k tokens, the windows Claude Code tuned then. Per 100 worker messages they took a median 3.6 review rounds past each pass's first against 4.0 for the 68 uncompacted chunks of 100 messages or more, and 13.9 🔴 and 🟡 findings against 16.6. 4 of 19 had an unfinished verdict against 3 of 68, each 8 to 10 hours after the compaction and followed by a finished verdict within minutes; the judge quoted the worker's own passages and the human's typed answers in them, never a summary. One cause was possible and is closed here: Claude Code writes the summary as a user entry, which `bin/claude_code/entries.py` read as the human's words, so the judge would see a `[human]` line of thousands of words and `/talk` would count it as typed; it now reads as Claude Code's. Whether compaction raises unfinished verdicts stays open until item 235 measures it. Two summaries read whole kept the chunk's intent, files, errors and next step in 12k to 20k characters, and the worker resumed without re-reading. -The window is handed to the worker, and the session /talk opens, as `CLAUDE_CODE_AUTO_COMPACT_WINDOW` (`bin/loop_claude/cycle/worker.py`), not set in `settings.json`: the archive measured loop-claude's workers, and interactive sessions are lilleman's. Subagents inherit it, and at 200k almost none compacts. A probe on 2026-10-27 showed that a `Compact instructions` section in a CLAUDE.md shapes the summary: a session whose CLAUDE.md asked the summary to end with its secret word did. So `CLAUDE.md` → "Compact instructions" names what a worker's summary keeps. Path-scoped rules leave the context at a compaction and return at the next matching read, and rule-hook holds each review launch to its rung whatever the summary keeps. Item 235 compares the first 20 chunks under the window with the 20 before. +Hours. A chunk ran a median 0.7 hours from its first message to its last, one in ten past 12 hours, mostly waiting for the human or a usage limit. No option here changes that: a compaction takes 51 to 83 seconds, under a minute per chunk at 0.7 each, and a smaller context makes a turn no faster to notice. The hours lever is item 232, since waiting on subagents took 66% of a worker's active time. + +The window is handed to the worker, and the session /talk opens, as `CLAUDE_CODE_AUTO_COMPACT_WINDOW=200000` (`bin/loop_claude/cycle/worker.py`), not set in `settings.json`: the archive measured loop-claude's workers, and interactive sessions are lilleman's. Claude Code compacts before a window fills: a 1M window at about 967k, and in a probe on 2026-10-27 a 100k window at 65k and 80k, so a 200k window compacts at about 170k. Subagents inherit it, and at 170k few compact. Another probe that day showed that a `Compact instructions` section in a CLAUDE.md shapes the summary: a session whose CLAUDE.md asked the summary to end with its secret word did. So `CLAUDE.md` → "Compact instructions" names what a worker's summary keeps. Path-scoped rules leave the context at a compaction and return at the next matching read, and rule-hook holds each review launch to its rung whatever the summary keeps. Item 235 compares the first 20 chunks under the window with the 20 before. Valid while cache reads cost a twentieth of input and Claude Code's compaction keeps the worker's task. diff --git a/todo.md b/todo.md index 73dab6af..a761d7a2 100644 --- a/todo.md +++ b/todo.md @@ -6,19 +6,18 @@ `Bar = 0.1` -`Next ID = 237` +`Next ID = 238` ## Items | ID | Release | Blocked by | Exempt | Item | L | E | I | R | S | Moves | Score | |---|---|---|---|---|---|---|---|---|---|---|---| -| 231 | 0.4.0 | | owner | **Lower what each chunk spends on context in dollars, then its hours, by the best means an ambitious evaluation finds, such as tooling that pinpoints what an agent reads and fresh or compacted contexts, with no loss of quality.** | 4 | 2 | 3 | 7 | 8 | 1.4 by 8, 1.5 by 4 | 0.7 | -| 232 | 0.4.0 | 231 | | **Launch a round's review passes in one message, except a pass that must wait for another's findings, so a round lasts about as long as its slowest reviewers, not their sum.** | 3 | 2 | 3 | 6 | 3 | 1.5 by 6 | 5.8 | -| 233 | 0.4.0 | 231 | | **Run one principles-auditor per round that checks the goals and every principles file that applies, in place of one auditor for each, so the principles pass reads the project once per round.** | 3 | 2 | 3 | 6 | 3 | 1.4 by 3, 1.5 by 2 | 4.9 | -| 234 | 0.4.0 | 231 | | **Report the routing figures in dollars, cache reads included, from the cost each archived run records.** | 2 | 2 | 2 | 4 | 3 | 1.4 by 3 | 3.0 | +| 232 | 0.4.0 | | | **Launch a round's review passes in one message, except a pass that must wait for another's findings, so a round lasts about as long as its slowest reviewers, not their sum.** | 3 | 2 | 3 | 6 | 3 | 1.5 by 6 | 5.8 | +| 233 | 0.4.0 | | | **Run one principles-auditor per round that checks the goals and every principles file that applies, in place of one auditor for each, so the principles pass reads the project once per round.** | 3 | 2 | 3 | 6 | 3 | 1.4 by 3, 1.5 by 2 | 4.9 | +| 234 | 0.4.0 | | | **Report the routing figures in dollars, cache reads included, from the cost each archived run records.** | 2 | 2 | 2 | 4 | 3 | 1.4 by 3 | 3.0 | | 236 | 0.5.0 | | question | **Answer whether the principles audit keeps reading the whole project, or reads only the files the chunk changed and their callers, now that half of its 🔴 and 🟡 findings name a file the chunk did not edit.** | 1 | 1 | 1 | 1 | 1 | 1.4 by 4 | 6.4 | | 226 | 0.5.0 | | question | **Answer whether rule-hook's `run-heavy` rule should also catch a mutation run or docker build behind `uv run`, `poetry run`, `python3 -m`, `sudo`, `docker image build` and `docker compose up --build`, or narrow the `machine load:` decision's wording.** | 2 | 2 | 3 | 5 | 3 | 1.2 by 2, 1.5 by 2 | 4.0 | -| 235 | 0.5.0 | | | **Compare review rounds past each pass's first, unfinished verdicts, 🔴, 🟡 and misread findings, and dollars per chunk, for the first 20 chunks whose worker ran under the 200k compaction window against the 20 before them, and file an item where any rose.** | 1 | 2 | 1 | 2 | 2 | 1.1 by 2, 1.4 by 3 | 6.8 | +| 235 | 0.5.0 | | | **Compare review rounds past each pass's first, unfinished verdicts, 🔴, 🟡 and misread findings, dollars and hours per chunk, for the first 20 chunks whose worker ran under the 200k compaction window against the 20 before them, and file an item where any rose.** | 1 | 2 | 1 | 2 | 2 | 1.1 by 2, 1.4 by 3 | 6.8 | | 59 | 0.5.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.5.0 | | | **Refuse a `/security-review` or `/claude-security` Skill call below the project's rung, as rule-hook refuses such an Agent call.** | 3 | 2 | 3 | 6 | 2 | 1.1 by 4 | 5.6 | | 6 | 0.5.0 | | decision | **Move what `loop-claude` writes out of `~/.claude.json`, and ask the human about each write that must stay.** | 3 | 3 | 3 | 7 | 3 | 1.1 by 5 | 5.3 | @@ -30,6 +29,7 @@ | 139 | 0.6.0 | | | **Split `bin/routing_figures/measure.py` by concern, and keep the figures' measured cycle and each raised call as fields loop-claude reads back, not as the prose it renders.** | 3 | 1 | 2 | 4 | 5 | code health by 5, 1.4 by 5 | 11.0 | | 158 | 0.6.0 | | decision | **Measure the fixed cost of a chunk from loop-claude's archive, in tokens and hours against its items' S, and set F in `Score = 100 * V / (2**S + F)` to it.** | 2 | 2 | 1 | 3 | 3 | 1.1 by 5, 1.4 by 5 | 10.3 | | 215 | 0.6.0 | | | **Decode a reload's handed JSON with a decoder for `LoopRun` and its `Route`, in place of `decoded_as`'s generic one with its two sentinels and `Route.fits` hook.** | 2 | 1 | 3 | 4 | 3 | code health by 2 | 9.0 | +| 237 | 0.6.0 | | principle | **Give `judge` and `judge_once` in `bin/loop_claude/cycle/judge.py` a record of the inputs they share, in place of nine and eight parameters, or record why they stay.** | 2 | 1 | 2 | 3 | 3 | code health by 2 | 9.0 | | 49 | 0.6.0 | | principle | **Check that `AGENTS.md` lists exactly the titles of `docs/decisions.md`.** | 1 | 1 | 1 | 1 | 2 | 1.1 by 6 | 8.4 | | 105 | 0.6.0 | | decision | **Compare review rounds per pass and reading cost for the five chunks before and after the `worker:` decision moved the principles out of the worker's context, and file an item if either rose.** | 1 | 2 | 1 | 2 | 2 | 1.4 by 6 | 8.0 | | 162 | 0.6.0 | | owner | **Script each step that 0.2.0's chunks repeated by hand and a program can compute, filing one item per step, and file this audit again for the next release.** | 2 | 2 | 1 | 3 | 3 | 1.4 by 4, 1.5 by 4 | 7.8 | @@ -43,11 +43,11 @@ | 112 | 0.6.0 | | | **Count an item as shipped only where its chunk built it, so an item a chunk dropped from the plan gets no outcome.** | 3 | 2 | 2 | 5 | 3 | 1.1 by 6 | 6.3 | | 124 | 0.6.0 | | decision | **Group the shared modules at `bin/`'s root into packages named by purpose, so the root holds only launchers and stand-alone tools.** | 4 | 1 | 3 | 6 | 6 | code health by 5, 1.4 by 3 | 5.7 | | 81 | 0.6.0 | | principle | **Have `workflow-bench/bench.py` return each run's failure as a value, so one failed clone does not hide the later runs' results.** | 1 | 2 | 1 | 2 | 2 | 1.1 by 4 | 5.6 | -| 102 | 0.6.0 | | | **Give loop-claude's retry delay an environment override, so the black-box test stops replacing `time.sleep` through `sitecustomize`.** | 1 | 1 | 2 | 2 | 2 | 1.1 by 4 | 5.6 | | 173 | 0.6.0 | | | **Have rule-hook's `todo-rank-check` run a worktree's own `bin/rank_todo.py` when the worktree is of this repo, so a branch that changes `todo.md`'s shape commits without an override.** | 2 | 1 | 3 | 4 | 2 | 1.1 by 2, 1.4 by 2 | 5.5 | | 101 | 0.6.0 | | principle | **Have `larv_review/history_commands.py`'s `read_seats` take the time, the commit check and the history as inputs, so it parses and decides without effects.** | 2 | 1 | 2 | 3 | 3 | 1.1 by 5 | 5.3 | | 110 | 0.6.0 | | decision | **Count, for each finished chunk, the later changes that fixed code it wrote, and show them beside its guessed E.** | 3 | 2 | 2 | 5 | 5 | 1.1 by 6, 1.4 by 6 | 4.9 | | 12 | 0.6.0 | | | **Run the test suite in CI on every PR, or record in `docs/decisions.md` why the local run is enough.** | 3 | 2 | 1 | 4 | 4 | 1.1 by 6 | 4.2 | +| 102 | 0.6.0 | | | **Give loop-claude's retry delay and its memory read environment overrides, so the black-box test stops replacing `time.sleep` and `machine_load.memory.MEMINFO` through `sitecustomize`.** | 1 | 1 | 2 | 2 | 3 | 1.1 by 4 | 4.2 | | 135 | 0.6.0 | | | **Fingerprint only the modules loop-claude imports, so editing another tool's code no longer reloads a running loop.** | 2 | 2 | 3 | 5 | 3 | 1.1 by 4 | 4.2 | | 171 | 0.6.0 | | decision | **Group the routing figures' review rounds by the reviewers' rung as well as the worker's, so a call blames a rung only for rounds its own reviews raised.** | 3 | 2 | 2 | 5 | 4 | 1.2 by 3, 1.4 by 3 | 4.0 | | 196 | 0.6.0 | | decision | **Replay the architecture, principles, overrides and product-owner passes with `review-replay` on Opus 5.5 projects, record each run in the review-replay routing decision, and add any rung a run qualifies to `REPLAYED`.** | 2 | 2 | 3 | 5 | 2 | 1.4 by 3 | 4.0 | @@ -71,37 +71,13 @@ | 51 | 0.6.0 | | principle | **Hand loop-claude's terminal output to an injected effect, so no storage or retry function prints.** | 2 | 1 | 3 | 4 | 5 | 1.1 by 5 | 2.1 | | 169 | 0.6.0 | | | **Have rule-hook's `todo-rank-check` catch a `todo.md` that the same Bash call edits and then commits.** | 3 | 1 | 3 | 5 | 3 | 1.1 by 2 | 2.1 | | 174 | 0.6.0 | | | **In a chunk no item routed, ask the worker to name each todo.md item it takes, with its L and E + I, so loop-claude can route on an item it takes in.** | 1 | 2 | 3 | 4 | 1 | 1.1 by 1 | 1.7 | +| 52 | 0.6.0 | | principle | **Move this checkout out of Claude Code's own directory, or record why it stays, since Claude Code loads its `AGENTS.md` as the user's instructions into every project's sessions.** | 4 | 3 | 4 | 9 | 6 | 1.1 by 4, 1.4 by 2 | 1.4 | | 197 | 0.6.0 | | | **Let the human edit what they type at loop-claude's terminal questions with the arrow keys, so Left moves the cursor in place of printing `^[[D`.** | 2 | 2 | 3 | 5 | 2 | 1.5 by 1 | 1.3 | -| 52 | 0.6.0 | | principle | **Record why this checkout lives in Claude Code's own directory, or move it out and link it in.** | 4 | 3 | 4 | 9 | 6 | 1.1 by 4 | 0.9 | | 170 | 0.7.0 | | decision | **Re-tune `WORKER_STEPS` and `REVIEW_STEPS` once 50 chunks have shipped under them, from how well L, E and I order their review rounds and 🔴 findings.** | 2 | 2 | 3 | 5 | 2 | 1.1 by 3, 1.4 by 5 | 10.9 | | 218 | 0.7.0 | 170 | | **Drop `LEGACY_WORKER` from `bin/model_routing/route.py`, so `route_from` reads only JSON worker lines.** | 1 | 2 | 1 | 2 | 1 | code health by 2 | 14.4 | ## Details -### 231. Lower what each chunk spends on context in dollars, then its hours, by the best means an ambitious evaluation finds, such as tooling that pinpoints what an agent reads and fresh or compacted contexts, with no loss of quality. - -lilleman's call, 2026-10-26: this is the plan's most important item, and it goes first. It runs on Fable 5.1 at max. An L of 4 routes the worker at most to Opus 5.5 at high, so the worker hands the evaluation and every edit to one subagent launched with `model fable, effort max`. The priorities, in order: context cost, then speed, and never at a loss of quality. Where the effect on quality is hard to tell, or very close, ask lilleman. - -Measured on 2026-10-26 from loop-claude's archive, over the 104 worker runs and about 720 subagent runs since the routing figures' last reset on 2026-10-21, priced at list prices: - -- The runs cost about $1,940, and cache reads, the context each turn reads again, are $985 of it. The routing figures leave cache reads out (item 234). -- Worker main threads are 53% of the cost. A worker starts at about 40k tokens of context and peaks at a median 189k, one in ten past 490k, the largest at 850k. Its turns above 200k are 64% of what workers cost. -- Bash output is 70% of the tool output a worker reads, most of it `cat`, `sed` and `head` of whole files. Principles auditors read 24M characters of files, each auditor reading the project anew. - -loop-claude starts each chunk in a fresh session, which lilleman meant to keep context small (`docs/decisions.md` → `loop-claude: one session per project`). The context grows within a chunk, so that decision doesn't block any option below. - -Evaluate at least these options, ambitiously, measuring each one's cost, hours and quality on comparable chunks: - -- Code-structure tooling in place of Bash reads: Claude Code's LSP tool, a code-intelligence MCP server, a symbol or outline lookup. -- Tools that pinpoint lines, such as Read with an offset and a limit and Grep with context, in place of `cat`, `sed` and `head` of whole files, with a rule or hook that steers agents to those tools. -- Compaction: Claude Code's auto-compact at a lower threshold, or a smaller context window. -- A fresh context for the review phase, handed only the chunk's facts and the reviewers' verdicts. -- What a reviewer reads: the diff and the places it touches, in place of the whole project. - -Judge quality by these figures per chunk, before and after: review rounds, unfinished verdicts, 🔴 and 🟡 findings, and findings that a later change fixes. Replay archived rounds with `review-replay` where it applies. Record each choice where `~/.claude/CLAUDE.md` → "Working loop", "Ask, don't guess" puts it, and file an item for each option worth doing later. - -Items 232, 233 and 234 wait for this item. Item 233 changes what a reviewer reads, which this item evaluates; items 232 and 234 wait on lilleman's call alone. - ### 232. Launch a round's review passes in one message, except a pass that must wait for another's findings, so a round lasts about as long as its slowest reviewers, not their sum. Since 2026-10-21, all 1,372 Agent calls in workers' transcripts were one per message, 94% of them in the foreground, and waiting on subagents took 66% of a worker's active time. larv-review §3 orders the passes so no polish goes into code the architect restructures or the security pass rewrites. Keep that: a pass waits only for a pass whose findings could make its review a waste. Launch the rest of the round's passes, the principles auditors among them, in one message. Do the same for the passes a fix reruns, per §3 → "Re-entry". @@ -112,7 +88,7 @@ Since 2026-10-21, 342 principles-auditor runs cost $274 at list prices, 23% of a ### 234. Report the routing figures in dollars, cache reads included, from the cost each archived run records. -The routing figures count input, cache-written and output tokens, and leave out cache reads, which were 51% of the cost since 2026-10-21. So their tables rank the principles auditor above the worker, while in dollars the worker cost three times as much. Each archived worker transcript ends with a `cost-state` entry holding `totalCostUSD` and each model's cost, and each message's usage attributes the cost to a subagent type. The judge's runs record no cost in the archive: count them too, or say why not. The change touches `bin/routing_figures/measure.py`, which the comprehension seats found hard (item 139): make the places it touches easier to read. +The routing figures count input, cache-written and output tokens, and leave out cache reads, which were 28% of the cost since 2026-10-21, $340 of $1,215 at list prices. So their tables rank the principles auditor above the worker, while in dollars the worker cost 1.4 times as much, $375 against $274. Each archived worker transcript ends with a `cost-state` entry holding `totalCostUSD` and each model's cost, and each message's usage attributes the cost to a subagent type. The judge's runs record no cost in the archive: count them too, or say why not. The change touches `bin/routing_figures/measure.py`, which the comprehension seats found hard (item 139): make the places it touches easier to read. ### 236. Answer whether the principles audit keeps reading the whole project, or reads only the files the chunk changed and their callers, now that half of its 🔴 and 🟡 findings name a file the chunk did not edit. @@ -122,9 +98,9 @@ Since 2026-10-21, 342 principles-auditor runs cost $274 at list prices, 23% of a Found by review of PR #370. Today `uv run mutmut run`, `poetry run mutmut run`, `python3 -m mutmut run`, `sudo docker build .`, `docker image build .` and `docker compose up --build` pass the rule, which `docs/decisions.md` → `machine load: …` and `RULES["run-heavy"]` describe as blocking docker builds and mutation runs. The rule's own text says a gate script isn't checked since no program can tell it from a light one, so the human decides where the line sits. Say what the rule's "checked" text promises either way. Where the answer widens the rule, the change touches `heavy` in `bin/rule_hook/heavy_command.py`, which the comprehension seats found hard: make it easier to read. -### 235. Compare review rounds past each pass's first, unfinished verdicts, 🔴, 🟡 and misread findings, and dollars per chunk, for the first 20 chunks whose worker ran under the 200k compaction window against the 20 before them, and file an item where any rose. +### 235. Compare review rounds past each pass's first, unfinished verdicts, 🔴, 🟡 and misread findings, dollars and hours per chunk, for the first 20 chunks whose worker ran under the 200k compaction window against the 20 before them, and file an item where any rose. -`docs/decisions.md` → `loop-claude: the worker's claude compacts its context above 200k tokens…` expects a saving of about 6% of all spend with no rise in these figures. Measure from loop-claude's archive as that decision did: rounds past each pass's first and the 🔴, 🟡 and misread counts from the round commit titles, unfinished verdicts from the outcomes files, and dollars from each message's usage at list prices, cache reads included, which item 234 puts into the routing figures. A chunk ran under the window when its first worker started after that decision merged. +`docs/decisions.md` → `loop-claude: the worker's claude compacts its context before it fills a 200k window…` expects a saving of about 6% of all spend with no rise in the other figures. Measure from loop-claude's archive as that decision did: rounds past each pass's first and the 🔴, 🟡 and misread counts from the round commit titles, unfinished verdicts from the outcomes files, hours from the worker's first message to its last, and dollars at list prices, cache reads included, from the chunk's `cost-state` entry, which counts the compaction calls that no message's usage records; item 234 puts such dollars into the routing figures. A chunk ran under the window when its first worker started after that decision merged. ### 59. Bound a run of unfinished verdicts on one chunk, so a worker and judge that disagree cannot cycle unattended without end. @@ -174,6 +150,10 @@ F is 8 until then, about one S 3 change, lilleman's call in PR #283. A chunk cos Release 0.3.0's Mid A (PR #324 at c713910) named `bin/loop_claude/loop/reload.py:43` `decoded_as`: "a generic decoder with two sentinels and a duck-typed fits hook defined on Route". This lowers Shape: `decoded_as` is generic over any type, yet `decode_handed` calls it with one dataclass, `LoopRun`. Keep what it does today: a field added since the running script started may be missing, and a handed dataclass holding a field its `RETIRED` names decodes as None where its type allows None, and is rejected otherwise. Make `decoded_as` easier to read. +### 237. Give `judge` and `judge_once` in `bin/loop_claude/cycle/judge.py` a record of the inputs they share, in place of nine and eight parameters, or record why they stay. + +Found by the principles audit of PR #376. "About seven things per level" in `principles/technical-principles.md`: `judge` takes nine parameters and `judge_once` eight, past the four or five for things that act on each other, with no recorded reason. Both take root, task, premises, records, entries, escalated_at, rung and effects, which one record could carry. + ### 49. Check that `AGENTS.md` lists exactly the titles of `docs/decisions.md`. DRY, in `principles/technical-principles.md`: the list is copied by hand, and sessions work from the copy. @@ -238,10 +218,6 @@ Shape scored 6.25 in PR #257's run. `bin/` held about 30 entries then: 6 launche "Errors as values", in `principles/technical-principles.md`, raised by the principles audit of PR #224: `bench.py` raises `KeyError` and `CalledProcessError`, and `pool.map` re-raises the first while the other threads run on unreported. -### 102. Give loop-claude's retry delay an environment override, so the black-box test stops replacing `time.sleep` through `sitecustomize`. - -Found by the principles audit of PR #242. `bin/loop_claude/test_black_box.py:113-114` swaps the global `time.sleep`, the shape "Functional core, imperative shell" bans. An override of the delay lets the test run the code as production runs it. - ### 173. Have rule-hook's `todo-rank-check` run a worktree's own `bin/rank_todo.py` when the worktree is of this repo, so a branch that changes `todo.md`'s shape commits without an override. Raised by the overrides pass of PR #296. The hook imports the main checkout's `rank_todo.py`, so while a branch of this repo changes the table's shape, every commit touching `todo.md` needs a `todo-rank-check` override: 33 log lines across four branches, the score-outcomes, plan-136, plan-148 and item-146 ones. The hook then checks nothing, and the rule rests on the worker chaining the branch's own check. Run another repo's `bin/rank_todo.py` never: that would run its code before every commit. @@ -260,6 +236,10 @@ The repo has no CI, so larv-review's gate is the local run, and larv-review's Ga When CI runs a rule check, such as one of `bin/rule-hook`'s, let `` in the PR body override it. +### 102. Give loop-claude's retry delay and its memory read environment overrides, so the black-box test stops replacing `time.sleep` and `machine_load.memory.MEMINFO` through `sitecustomize`. + +Found by the principles audit of PR #242. `bin/loop_claude/test_black_box.py:113-114` swaps the global `time.sleep`, the shape "Functional core, imperative shell" bans, and the audit of PR #376 found the same block swapping `machine_load.memory.MEMINFO` at lines 119-123. An override of each lets the test run the code as production runs it. + ### 135. Fingerprint only the modules loop-claude imports, so editing another tool's code no longer reloads a running loop. The maintainability senior and the inherited architect of PR #257's scoring run named `bin/loop_claude/loop/reload.py:38` `fingerprint` and `:50` `exec_if_edited`: the fingerprint covers every `bin/**/*.py`, so editing `statusline.py` or `rank_todo.py` re-execs a running loop. Make `fingerprint` easier to read. @@ -390,14 +370,14 @@ The hook judges a call before it runs, and `changed` in `bin/rule_hook/todo_chec The principles pass of PR #301 found that only `routed_by` in `bin/loop_claude/cycle/prompts.py` asks the worker to name each item it takes with its L and E + I, and `fresh` uses it only where an item routed the chunk. In an unrouted chunk the judge has no levels to report, so neither the taken-in L nor the taken-in E + I lifts the worker or the judge. +### 52. Move this checkout out of Claude Code's own directory, or record why it stays, since Claude Code loads its `AGENTS.md` as the user's instructions into every project's sessions. + +"One owner per value" and "Prefer the vendor-neutral option", in `principles/technical-principles.md`: git, Claude Code and loop-claude all write `~/.claude`, kept apart only by the `.gitignore` allowlist, and the repo's records live in a vendor directory. Claude Code also loads `~/.claude/AGENTS.md`, this checkout's decision titles, as the user's instructions into every session of every project: 10.7k characters, about 2.7k tokens, in each of the 1,084 threads since 2026-10-21, about $25 of cache writes and reads at list prices, and a worker on another project reads this repo's decisions as if they held there. + ### 197. Let the human edit what they type at loop-claude's terminal questions with the arrow keys, so Left moves the cursor in place of printing `^[[D`. `bin/loop_claude/effects.py` hands loop-claude Python's builtin `input`, and nothing under `bin/` imports `readline`, so the terminal gets no line editing: fixing a typo means erasing back to it. `effects.input` reads the answer to both of loop-claude's questions: the interrupt, in `cycle/interrupt.py`'s `put_question`, and the pick of the project's model, in `project/model_choice.py`'s `ask_for_model`. Importing `readline` in `effects.py` gives both line editing, at two costs. It moves the prompt from stderr to stdout, while the question above it stays on stderr. `test_black_box.py` waits for the prompt on stderr. `readline`'s bracketed paste takes a pasted block whole, so an answer can hold several lines. `prompts.typed_answer` ends the answer at its first blank line, so the judge would read the rest of such a paste as loop-claude's words. The product-owner review of PR #308 raised the interrupt's case. lilleman, 2026-10-18: "Not super-important, but a bit irritating." -### 52. Record why this checkout lives in Claude Code's own directory, or move it out and link it in. - -"One owner per value" and "Prefer the vendor-neutral option", in `principles/technical-principles.md`: git, Claude Code and loop-claude all write `~/.claude`, kept apart only by the `.gitignore` allowlist, and the repo's records live in a vendor directory. Claude Code also loads `~/.claude/AGENTS.md`, this checkout's decision titles, as the user's instructions into every session of every project: 10.7k characters, about 2.7k tokens, in each of the 1,084 threads since 2026-10-21, about $25 of cache writes and reads at list prices, and a worker on another project reads this repo's decisions as if they held there. - ### 170. Re-tune `WORKER_STEPS` and `REVIEW_STEPS` once 50 chunks have shipped under them, from how well L, E and I order their review rounds and 🔴 findings. `docs/decisions.md` → `routing: one ladder…` calls the steps a first guess. Start this item once 50 chunks have merged since PR #339 set today's steps, each shipping one item scored with L, E and I. By 2026-10-23, 15 had: those of items 117, 126, 122, 207, 130, 154, 186, 66, 121, 213, 137, 212, 214, 210 and 216. Then read `score-outcomes`' rank correlations for L, E and I and the routed-chunks table of `routing-figures.md`, and propose new steps to lilleman, whose call they are. From 23fbf853d88c93b47d3bc4aeb69dc58941eb89bd Mon Sep 17 00:00:00 2001 From: Lilleman auf Larv Date: Tue, 27 Oct 2026 00:35:37 +0100 Subject: [PATCH 42/55] =?UTF-8?q?Answer=20principles=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 78837aabc6adf31329f42a257366f9209d4132ef Mon Sep 17 00:00:00 2001 From: Lilleman auf Larv Date: Tue, 27 Oct 2026 00:38:12 +0100 Subject: [PATCH 43/55] =?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);=20file=20item?= =?UTF-8?q?=20238,=20since=20the=20skill=20scans=20nothing=20when=20a=20su?= =?UTF-8?q?bagent=20runs=20it=20outside=20the=20worktree?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- todo.md | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/todo.md b/todo.md index a761d7a2..b5d9992d 100644 --- a/todo.md +++ b/todo.md @@ -6,7 +6,7 @@ `Bar = 0.1` -`Next ID = 238` +`Next ID = 239` ## Items @@ -21,6 +21,7 @@ | 59 | 0.5.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.5.0 | | | **Refuse a `/security-review` or `/claude-security` Skill call below the project's rung, as rule-hook refuses such an Agent call.** | 3 | 2 | 3 | 6 | 2 | 1.1 by 4 | 5.6 | | 6 | 0.5.0 | | decision | **Move what `loop-claude` writes out of `~/.claude.json`, and ask the human about each write that must stay.** | 3 | 3 | 3 | 7 | 3 | 1.1 by 5 | 5.3 | +| 238 | 0.5.0 | | defect | **Run the security pass's skill in the chunk's worktree, so it scans the branch's diff: invoked from a subagent, it runs in the session's working directory, the main checkout, and scans nothing.** | 2 | 2 | 3 | 5 | 3 | 1.1 by 5 | 5.3 | | 1 | 0.6.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 | | 229 | 0.6.0 | | | **Keep the rule for which commands reach run-heavy's docker beside that docker in `bin/run_heavy/capped_docker.py`, so rule-hook's `docker-run-memory` asks it instead of repeating run-heavy's PATH rules.** | 2 | 1 | 3 | 4 | 2 | code health by 3 | 18.0 | | 219 | 0.6.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 | @@ -114,6 +115,10 @@ 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. +### 238. Run the security pass's skill in the chunk's worktree, so it scans the branch's diff: invoked from a subagent, it runs in the session's working directory, the main checkout, and scans nothing. + +Found while reviewing PR #376. larv-review §3 → "Security" launches a general-purpose subagent that invokes `/security-review` through the Skill tool. The skill runs its git commands in the session's working directory, the checkout root, where the branch's diff is empty, and the subagent then reads the worktree's diff itself, which the skill's own text forbids as a substitute. The archived security subagents of items 198 and 223 and of this chunk all report it. Until it is fixed, run `claude -p /security-review` with the worktree as its working directory, on the project's rung, as PR #376 did. A fix may run the skill as a process in the worktree from larv-review, or have the worker enter the worktree with Claude Code's `EnterWorktree` tool so every subagent runs there. + ### 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 56b9077e4c3b3c76a88712b76a1ebb25a65b7a19 Mon Sep 17 00:00:00 2001 From: Lilleman auf Larv Date: Tue, 27 Oct 2026 00:45:38 +0100 Subject: [PATCH 44/55] =?UTF-8?q?Answer=20stability=20round=201:=200=20?= =?UTF-8?q?=F0=9F=94=B4,=202=20=F0=9F=9F=A1=20(0=20misread);=20cut=20the?= =?UTF-8?q?=20help=20paragraph=20to=20one=20sentence=20and=20tie=20its=202?= =?UTF-8?q?00k=20to=20COMPACT=5FWINDOW?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- bin/loop_claude/loop/main.py | 7 +++---- bin/loop_claude/test_loop_claude.py | 1 + 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/bin/loop_claude/loop/main.py b/bin/loop_claude/loop/main.py index c9997b93..3b3c2bf1 100644 --- a/bin/loop_claude/loop/main.py +++ b/bin/loop_claude/loop/main.py @@ -47,10 +47,9 @@ time. The layout, and when a copy is replaced, are in bin/transcript_archive/__i Before each worker starts, loop-claude waits until at least a quarter of the machine's memory is available (bin/machine_load/memory.py). -Each worker's claude, and the session /talk opens, runs with a 200k auto-compact window, handed as -CLAUDE_CODE_AUTO_COMPACT_WINDOW (bin/loop_claude/cycle/worker.py), so it compacts its context at -about 170k tokens and a long chunk re-reads less each turn. -~/.claude/CLAUDE.md → "Compact instructions" says what the summary keeps. +Each worker's claude, and the session /talk opens, runs with a 200k auto-compact window +(CLAUDE_CODE_AUTO_COMPACT_WINDOW, bin/loop_claude/cycle/worker.py), so it compacts its context at +about 170k tokens. Every claude loop-claude starts runs the project's model, saved per in ~/.claude/loop-claude-models.json and read each cycle, unless routing, below, puts the worker, diff --git a/bin/loop_claude/test_loop_claude.py b/bin/loop_claude/test_loop_claude.py index 3e536840..40b7a64c 100644 --- a/bin/loop_claude/test_loop_claude.py +++ b/bin/loop_claude/test_loop_claude.py @@ -1516,6 +1516,7 @@ class HelpLimits(unittest.TestCase): self.assertIn(f"retried {retry.PAST_RESET // 60} minutes after the limit resets, or every {retry.UNKNOWN_RESET_POLL // 60} minutes", said) self.assertIn(f"still running after {PYTHON_TIMEOUT} s", said) self.assertIn(f"Once {measure.CYCLES_PER_CHECK} cycles have closed across all projects", said) + self.assertIn(f"runs with a {worker.COMPACT_WINDOW // 1000}k auto-compact window", said) class ExitContract(unittest.TestCase): From 9abc5f4781d583874484abb2d730f2cd091636bf Mon Sep 17 00:00:00 2001 From: Lilleman auf Larv Date: Tue, 27 Oct 2026 00:46:53 +0100 Subject: [PATCH 45/55] =?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 2b2e18ec6d04e5af154bd2c7d36e2c234f0c83ff Mon Sep 17 00:00:00 2001 From: Lilleman auf Larv Date: Tue, 27 Oct 2026 00:51:39 +0100 Subject: [PATCH 46/55] =?UTF-8?q?Answer=20stability=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 34c13f97cd63ceac6f5c1fc7bf0dd9253e0b2fd2 Mon Sep 17 00:00:00 2001 From: Lilleman auf Larv Date: Tue, 27 Oct 2026 00:57:56 +0100 Subject: [PATCH 47/55] =?UTF-8?q?Answer=20product-owner=20round=201:=200?= =?UTF-8?q?=20=F0=9F=94=B4,=200=20=F0=9F=9F=A1=20(0=20misread);=20say=20su?= =?UTF-8?q?bagents=20inherit=20the=20window=20and=20how=20many=20compact,?= =?UTF-8?q?=20keep=20a=20reviewer's=20drafted=20findings=20through=20a=20c?= =?UTF-8?q?ompaction,=20move=20item=20238=20into=200.4.0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- CHANGELOG.md | 2 +- CLAUDE.md | 2 +- bin/loop_claude/loop/main.py | 6 +++--- bin/loop_claude/test_loop_claude.py | 2 +- docs/decisions.md | 2 +- todo.md | 10 +++++----- 6 files changed, 12 insertions(+), 12 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index ce5f87b3..47624424 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,7 +2,7 @@ ## Unreleased -- loop-claude's worker now runs with a 200k auto-compact window, handed as `CLAUDE_CODE_AUTO_COMPACT_WINDOW`, so Claude Code compacts its context at about 170k tokens; before, at about 967k. Since 2026-10-21, a worker's turns above 200k were 55% of what workers cost. The 19 chunks that compacted before took no more review rounds or findings per message than those that did not, but 4 of them had an unfinished verdict against 3 of 68; `todo.md` item 235 measures the first 20 chunks under the window. loop-claude's judge no longer reads a compaction summary as words the human typed. `CLAUDE.md` has a new section, "Compact instructions", saying what the summary keeps. +- loop-claude's worker, and every subagent it launches, now runs with a 200k auto-compact window, handed as `CLAUDE_CODE_AUTO_COMPACT_WINDOW`, so Claude Code compacts its context at about 170k tokens; before, at about 967k. Since 2026-10-21, a worker's turns above 200k were 55% of what workers cost. The 19 chunks that compacted before took no more review rounds or findings per message than those that did not, but 4 of them had an unfinished verdict against 3 of 68; `todo.md` item 235 measures the first 20 chunks under the window. loop-claude's judge no longer reads a compaction summary as words the human typed. `CLAUDE.md` has a new section, "Compact instructions", saying what the summary keeps. - On Linux, `run-heavy` now caps the memory of a container its command makes with `docker run` or `docker create`. A container that sets no limit gets a memory limit and a swap limit, both the slot's share: three quarters of the machine's memory, split across the heavy slots. A container that sets one of the two limits keeps it, and gets the other as large. This covers containers a project's own scripts start, which rule-hook can't see. A `docker compose` service, and a docker named by its full path, get no cap. rule-hook's `docker-run-memory` now lets a `docker run` under run-heavy pass. - 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. diff --git a/CLAUDE.md b/CLAUDE.md index d8453073..58886075 100644 --- a/CLAUDE.md +++ b/CLAUDE.md @@ -106,7 +106,7 @@ The rules only reviewers apply, for quality, comments, READMEs and prose, live i ## Compact instructions -Claude Code reads this section by its heading when it compacts a conversation. When you compact, keep in the summary: the task loop-claude gave and each `todo.md` item the chunk takes, with its L and E + I; the worktree, branch and PR; the rung loop-claude named for each review launch, rerun and escalated subagent; each review pass's rounds so far, each open 🔴 and 🟡, and how the answered ones were answered; every question the human answered, with the answer; each escalation trigger that fired; and what remains before the chunk is finished. +Claude Code reads this section by its heading when it compacts a conversation. When you compact, keep in the summary: the task loop-claude gave and each `todo.md` item the chunk takes, with its L and E + I; the worktree, branch and PR; the rung loop-claude named for each review launch, rerun and escalated subagent; each review pass's rounds so far, each open 🔴 and 🟡, and how the answered ones were answered; every question the human answered, with the answer; each escalation trigger that fired; and what remains before the chunk is finished. A reviewer or comprehension seat keeps every finding and place it has drafted. ## Vocabulary diff --git a/bin/loop_claude/loop/main.py b/bin/loop_claude/loop/main.py index 3b3c2bf1..ed704ec8 100644 --- a/bin/loop_claude/loop/main.py +++ b/bin/loop_claude/loop/main.py @@ -47,9 +47,9 @@ time. The layout, and when a copy is replaced, are in bin/transcript_archive/__i Before each worker starts, loop-claude waits until at least a quarter of the machine's memory is available (bin/machine_load/memory.py). -Each worker's claude, and the session /talk opens, runs with a 200k auto-compact window -(CLAUDE_CODE_AUTO_COMPACT_WINDOW, bin/loop_claude/cycle/worker.py), so it compacts its context at -about 170k tokens. +Each worker's claude, the session /talk opens and the subagents either launches run with a 200k +auto-compact window (CLAUDE_CODE_AUTO_COMPACT_WINDOW, bin/loop_claude/cycle/worker.py), so each +compacts its context at about 170k tokens. Every claude loop-claude starts runs the project's model, saved per in ~/.claude/loop-claude-models.json and read each cycle, unless routing, below, puts the worker, diff --git a/bin/loop_claude/test_loop_claude.py b/bin/loop_claude/test_loop_claude.py index 40b7a64c..04d93599 100644 --- a/bin/loop_claude/test_loop_claude.py +++ b/bin/loop_claude/test_loop_claude.py @@ -1516,7 +1516,7 @@ class HelpLimits(unittest.TestCase): self.assertIn(f"retried {retry.PAST_RESET // 60} minutes after the limit resets, or every {retry.UNKNOWN_RESET_POLL // 60} minutes", said) self.assertIn(f"still running after {PYTHON_TIMEOUT} s", said) self.assertIn(f"Once {measure.CYCLES_PER_CHECK} cycles have closed across all projects", said) - self.assertIn(f"runs with a {worker.COMPACT_WINDOW // 1000}k auto-compact window", said) + self.assertIn(f"run with a {worker.COMPACT_WINDOW // 1000}k auto-compact window", said) class ExitContract(unittest.TestCase): diff --git a/docs/decisions.md b/docs/decisions.md index 15716777..cf61331e 100644 --- a/docs/decisions.md +++ b/docs/decisions.md @@ -91,7 +91,7 @@ Quality. 19 chunks compacted between 2026-10-10 and 2026-10-22, at 214k to 972k Hours. A chunk ran a median 0.7 hours from its first message to its last, one in ten past 12 hours, mostly waiting for the human or a usage limit. No option here changes that: a compaction takes 51 to 83 seconds, under a minute per chunk at 0.7 each, and a smaller context makes a turn no faster to notice. The hours lever is item 232, since waiting on subagents took 66% of a worker's active time. -The window is handed to the worker, and the session /talk opens, as `CLAUDE_CODE_AUTO_COMPACT_WINDOW=200000` (`bin/loop_claude/cycle/worker.py`), not set in `settings.json`: the archive measured loop-claude's workers, and interactive sessions are lilleman's. Claude Code compacts before a window fills: a 1M window at about 967k, and in a probe on 2026-10-27 a 100k window at 65k and 80k, so a 200k window compacts at about 170k. Subagents inherit it, and at 170k few compact. Another probe that day showed that a `Compact instructions` section in a CLAUDE.md shapes the summary: a session whose CLAUDE.md asked the summary to end with its secret word did. So `CLAUDE.md` → "Compact instructions" names what a worker's summary keeps. Path-scoped rules leave the context at a compaction and return at the next matching read, and rule-hook holds each review launch to its rung whatever the summary keeps. Item 235 compares the first 20 chunks under the window with the 20 before. +The window is handed to the worker, and the session /talk opens, as `CLAUDE_CODE_AUTO_COMPACT_WINDOW=200000` (`bin/loop_claude/cycle/worker.py`), not set in `settings.json`: the archive measured loop-claude's workers, and interactive sessions are lilleman's. Claude Code compacts before a window fills: a 1M window at about 967k, and in a probe on 2026-10-27 a 100k window at 65k and 80k, so a 200k window compacts at about 170k. Subagents inherit it: 68 of the 994 subagent runs since the reset, 7%, passed 170k, 24 of them principles auditors, so about one in fourteen compacts once, and `CLAUDE.md` → "Compact instructions" has a reviewer keep the findings it has drafted. Another probe that day showed that a `Compact instructions` section in a CLAUDE.md shapes the summary: a session whose CLAUDE.md asked the summary to end with its secret word did. So `CLAUDE.md` → "Compact instructions" names what a worker's summary keeps. Path-scoped rules leave the context at a compaction and return at the next matching read, and rule-hook holds each review launch to its rung whatever the summary keeps. Item 235 compares the first 20 chunks under the window with the 20 before. Valid while cache reads cost a twentieth of input and Claude Code's compaction keeps the worker's task. diff --git a/todo.md b/todo.md index b5d9992d..e2bebc99 100644 --- a/todo.md +++ b/todo.md @@ -13,6 +13,7 @@ | ID | Release | Blocked by | Exempt | Item | L | E | I | R | S | Moves | Score | |---|---|---|---|---|---|---|---|---|---|---|---| | 232 | 0.4.0 | | | **Launch a round's review passes in one message, except a pass that must wait for another's findings, so a round lasts about as long as its slowest reviewers, not their sum.** | 3 | 2 | 3 | 6 | 3 | 1.5 by 6 | 5.8 | +| 238 | 0.4.0 | | defect | **Run the security pass's skill in the chunk's worktree, so it scans the branch's diff: invoked from a subagent, it runs in the session's working directory, the main checkout, and scans nothing.** | 2 | 2 | 3 | 5 | 3 | 1.1 by 5 | 5.3 | | 233 | 0.4.0 | | | **Run one principles-auditor per round that checks the goals and every principles file that applies, in place of one auditor for each, so the principles pass reads the project once per round.** | 3 | 2 | 3 | 6 | 3 | 1.4 by 3, 1.5 by 2 | 4.9 | | 234 | 0.4.0 | | | **Report the routing figures in dollars, cache reads included, from the cost each archived run records.** | 2 | 2 | 2 | 4 | 3 | 1.4 by 3 | 3.0 | | 236 | 0.5.0 | | question | **Answer whether the principles audit keeps reading the whole project, or reads only the files the chunk changed and their callers, now that half of its 🔴 and 🟡 findings name a file the chunk did not edit.** | 1 | 1 | 1 | 1 | 1 | 1.4 by 4 | 6.4 | @@ -21,7 +22,6 @@ | 59 | 0.5.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.5.0 | | | **Refuse a `/security-review` or `/claude-security` Skill call below the project's rung, as rule-hook refuses such an Agent call.** | 3 | 2 | 3 | 6 | 2 | 1.1 by 4 | 5.6 | | 6 | 0.5.0 | | decision | **Move what `loop-claude` writes out of `~/.claude.json`, and ask the human about each write that must stay.** | 3 | 3 | 3 | 7 | 3 | 1.1 by 5 | 5.3 | -| 238 | 0.5.0 | | defect | **Run the security pass's skill in the chunk's worktree, so it scans the branch's diff: invoked from a subagent, it runs in the session's working directory, the main checkout, and scans nothing.** | 2 | 2 | 3 | 5 | 3 | 1.1 by 5 | 5.3 | | 1 | 0.6.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 | | 229 | 0.6.0 | | | **Keep the rule for which commands reach run-heavy's docker beside that docker in `bin/run_heavy/capped_docker.py`, so rule-hook's `docker-run-memory` asks it instead of repeating run-heavy's PATH rules.** | 2 | 1 | 3 | 4 | 2 | code health by 3 | 18.0 | | 219 | 0.6.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 | @@ -83,6 +83,10 @@ Since 2026-10-21, all 1,372 Agent calls in workers' transcripts were one per message, 94% of them in the foreground, and waiting on subagents took 66% of a worker's active time. larv-review §3 orders the passes so no polish goes into code the architect restructures or the security pass rewrites. Keep that: a pass waits only for a pass whose findings could make its review a waste. Launch the rest of the round's passes, the principles auditors among them, in one message. Do the same for the passes a fix reruns, per §3 → "Re-entry". +### 238. Run the security pass's skill in the chunk's worktree, so it scans the branch's diff: invoked from a subagent, it runs in the session's working directory, the main checkout, and scans nothing. + +Found while reviewing PR #376. larv-review §3 → "Security" launches a general-purpose subagent that invokes `/security-review` through the Skill tool. The skill runs its git commands in the session's working directory, the checkout root, where the branch's diff is empty, and the subagent then reads the worktree's diff itself, which the skill's own text forbids as a substitute. The archived security subagents of items 198 and 223 and of this chunk all report it. It sits in 0.4.0 so the release's remaining chunks get a scan that reads their diff; until it is fixed, run `claude -p /security-review` with the worktree as its working directory, on the project's rung, as PR #376 did. A fix may run the skill as a process in the worktree from larv-review, or have the worker enter the worktree with Claude Code's `EnterWorktree` tool so every subagent runs there. + ### 233. Run one principles-auditor per round that checks the goals and every principles file that applies, in place of one auditor for each, so the principles pass reads the project once per round. Since 2026-10-21, 342 principles-auditor runs cost $274 at list prices, 23% of all spend and 3.8 runs per chunk, and each read the project anew: $129 of 5-minute cache writes, $92 of output and $53 of cache reads. Today larv-review §3 → "Principles" launches one auditor for the README's goals and code health, and one per file in `~/.claude/principles/` that applies. The merged auditor must find what the separate ones found: replay archived rounds with `review-replay`, and keep separate auditors where the merged one misses a 🔴 or 🟡. Rename the report files, `principles--round-.md` today (§3 → "Reports"), to one per round. @@ -115,10 +119,6 @@ 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. -### 238. Run the security pass's skill in the chunk's worktree, so it scans the branch's diff: invoked from a subagent, it runs in the session's working directory, the main checkout, and scans nothing. - -Found while reviewing PR #376. larv-review §3 → "Security" launches a general-purpose subagent that invokes `/security-review` through the Skill tool. The skill runs its git commands in the session's working directory, the checkout root, where the branch's diff is empty, and the subagent then reads the worktree's diff itself, which the skill's own text forbids as a substitute. The archived security subagents of items 198 and 223 and of this chunk all report it. Until it is fixed, run `claude -p /security-review` with the worktree as its working directory, on the project's rung, as PR #376 did. A fix may run the skill as a process in the worktree from larv-review, or have the worker enter the worktree with Claude Code's `EnterWorktree` tool so every subagent runs there. - ### 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 b569f638ac914c0e5426257b225251a995ea0d7d Mon Sep 17 00:00:00 2001 From: Lilleman auf Larv Date: Tue, 27 Oct 2026 01:06:24 +0100 Subject: [PATCH 48/55] =?UTF-8?q?Answer=20prose=20round=201:=200=20?= =?UTF-8?q?=F0=9F=94=B4,=2012=20=F0=9F=9F=A1=20(0=20misread);=20put=20the?= =?UTF-8?q?=20decision=20first=20in=20its=20entry,=20list=20the=20compact?= =?UTF-8?q?=20instructions,=20write=20the=20changelog=20for=20the=20public?= =?UTF-8?q?,=20and=20restate=20items=2052,=20102,=20233,=20235,=20236=20an?= =?UTF-8?q?d=20238?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- CHANGELOG.md | 2 +- CLAUDE.md | 11 ++++++++++- bin/loop_claude/cycle/worker.py | 2 +- docs/decisions.md | 22 +++++++++++----------- todo.md | 22 +++++++++++----------- 5 files changed, 34 insertions(+), 25 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 47624424..3f436cb9 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,7 +2,7 @@ ## Unreleased -- loop-claude's worker, and every subagent it launches, now runs with a 200k auto-compact window, handed as `CLAUDE_CODE_AUTO_COMPACT_WINDOW`, so Claude Code compacts its context at about 170k tokens; before, at about 967k. Since 2026-10-21, a worker's turns above 200k were 55% of what workers cost. The 19 chunks that compacted before took no more review rounds or findings per message than those that did not, but 4 of them had an unfinished verdict against 3 of 68; `todo.md` item 235 measures the first 20 chunks under the window. loop-claude's judge no longer reads a compaction summary as words the human typed. `CLAUDE.md` has a new section, "Compact instructions", saying what the summary keeps. +- loop-claude's worker, and every subagent it launches, now run with a 200k auto-compact window, handed as `CLAUDE_CODE_AUTO_COMPACT_WINDOW`: Claude Code compacts their context at about 170k tokens, where it used to let it grow to about 967k. loop-claude's judge no longer reads a compaction summary as words you typed. `CLAUDE.md` has a new section, "Compact instructions", saying what a summary keeps. - On Linux, `run-heavy` now caps the memory of a container its command makes with `docker run` or `docker create`. A container that sets no limit gets a memory limit and a swap limit, both the slot's share: three quarters of the machine's memory, split across the heavy slots. A container that sets one of the two limits keeps it, and gets the other as large. This covers containers a project's own scripts start, which rule-hook can't see. A `docker compose` service, and a docker named by its full path, get no cap. rule-hook's `docker-run-memory` now lets a `docker run` under run-heavy pass. - 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. diff --git a/CLAUDE.md b/CLAUDE.md index 58886075..4c6871a4 100644 --- a/CLAUDE.md +++ b/CLAUDE.md @@ -106,7 +106,16 @@ The rules only reviewers apply, for quality, comments, READMEs and prose, live i ## Compact instructions -Claude Code reads this section by its heading when it compacts a conversation. When you compact, keep in the summary: the task loop-claude gave and each `todo.md` item the chunk takes, with its L and E + I; the worktree, branch and PR; the rung loop-claude named for each review launch, rerun and escalated subagent; each review pass's rounds so far, each open 🔴 and 🟡, and how the answered ones were answered; every question the human answered, with the answer; each escalation trigger that fired; and what remains before the chunk is finished. A reviewer or comprehension seat keeps every finding and place it has drafted. +Claude Code reads this section by its heading when it compacts a conversation. Keep in the summary: + +- what remains before the chunk is finished; +- the task loop-claude gave, and each `todo.md` item the chunk takes with its L and E + I; +- the worktree, branch and PR; +- the rung loop-claude named for each review launch, rerun and escalated subagent; +- each review pass's rounds so far, each open 🔴 and 🟡, and how the answered ones were answered; +- every question the human answered, with the answer; +- each escalation trigger that fired; +- for a reviewer or comprehension seat, every finding and place it has drafted. ## Vocabulary diff --git a/bin/loop_claude/cycle/worker.py b/bin/loop_claude/cycle/worker.py index 728a80df..02f051c4 100644 --- a/bin/loop_claude/cycle/worker.py +++ b/bin/loop_claude/cycle/worker.py @@ -12,7 +12,7 @@ from claude_code.session import Session PRINTED_TOOL_INPUT = 160 # Seconds between reads of the machine's memory while too little of it is available to start a worker. MEMORY_POLL = 60 -# The auto-compact window, in tokens, handed to the worker's claude in this variable. Claude Code compacts before the window fills, at about 170k: docs/decisions.md → `loop-claude: the worker's claude compacts its context before it fills a 200k window`. +# The auto-compact window, in tokens, handed to the worker's claude in the environment variable AUTO_COMPACT_WINDOW names. Claude Code compacts before the window fills, at about 170k: docs/decisions.md → `loop-claude: the worker's claude compacts its context before it fills a 200k window`. AUTO_COMPACT_WINDOW = "CLAUDE_CODE_AUTO_COMPACT_WINDOW" COMPACT_WINDOW = 200_000 diff --git a/docs/decisions.md b/docs/decisions.md index cf61331e..17a52653 100644 --- a/docs/decisions.md +++ b/docs/decisions.md @@ -74,24 +74,24 @@ The cap is 5, `bin/todo_table.py`'s `BUNDLE_MAX_R`, from the same chunks: by the ## loop-claude: the worker's claude compacts its context before it fills a 200k window, at about 170k tokens, and `CLAUDE.md` → "Compact instructions" says what the summary keeps -2026-10-27, claude through todo item 231, awaiting lilleman's yes before the merge. Serves goal 1.4, under goal 1.1's counter-signal. Item 231 asked for the best means to lower what a chunk spends on context, in dollars, then hours, with no loss of quality. +2026-10-27, lilleman, through todo item 231; claude measured and implemented. Serves goal 1.4; its counter-signal, review rounds and unfinished verdicts per chunk, is the check. -Measured from loop-claude's archive over the 90 chunks with messages after the routing figures' reset of 2026-10-21, at the list prices read on 2026-10-26 (Opus 5.5: $4 per million input tokens, $5 and $8 for 5-minute and 1-hour cache writes, $0.20 for cache reads, $20 for output; no model but Haiku 5.5 charges more above 200k): $1,215, which is 0.86 of what the chunks' `cost-state` entries sum to, since some chunks' subagent transcripts are not in the archive. Worker main threads cost $375 (31%): 1-hour cache writes $149, cache reads $153, output $74. Subagents cost $840: 5-minute cache writes $379, output $274, cache reads $187, with the principles auditors at $274 over 342 runs, the stability reviewers $179 and general-purpose subagents $192. A worker starts at 41k tokens of context and peaks at a median 167k, one in ten past 358k, the largest at 848k: Claude Code compacts a model with a native 1M window at about 967k. The worker's messages above 200k were 32% of its messages and 55% of its cost. +loop-claude hands each worker's claude `CLAUDE_CODE_AUTO_COMPACT_WINDOW=200000` (`bin/loop_claude/cycle/worker.py`), and the session /talk opens gets it too. Claude Code compacts before a window fills: a 1M window at about 967k tokens, and in a probe on 2026-10-27 a 100k window at 65k and 80k, so a 200k window compacts at about 170k. The window is not set in `settings.json`, since the archive measured loop-claude's workers and interactive sessions are lilleman's. Subagents inherit the variable, which reaches every process of the session: 68 of the 994 subagent runs since 2026-10-21, 7%, passed 170k, 24 of them principles auditors, so about one in fourteen compacts once. Compacting subagents by choice would cost more than it saves, as below, but the variable cannot leave them out, and `CLAUDE.md` → "Compact instructions" has a reviewer keep the findings it has drafted. That section shapes the summary: in another probe that day, a session whose CLAUDE.md asked for its summary to end with a secret word got a summary ending with that word. Path-scoped rules leave the context at a compaction and return at the next matching read, and rule-hook holds each review launch to its rung whatever the summary keeps. `CLAUDE_CODE_DISABLE_1M_CONTEXT=1`, handed the same way, would compact at the same point but also cap the window at 200k, so a run that Claude Code stops compacting, as it does when one tool result refills the context each time, would hit the limit instead of going on. -Each option item 231 named, on those chunks: +Why 200k. Item 231 asked for the best means to lower what a chunk spends on context, in dollars, then hours, with no loss of quality. Measured from loop-claude's archive, the 90 chunks with messages after the routing figures' reset of 2026-10-21 cost $1,215 at the list prices read on 2026-10-26 (Opus 5.5: $4 per million input tokens, $5 and $8 for 5-minute and 1-hour cache writes, $0.20 for cache reads, $20 for output; no model but Haiku 5.5 charges more above 200k). That is 0.86 of what the chunks' `cost-state` entries sum to, since some chunks' subagent transcripts are not in the archive. Worker main threads cost $375 (31%): 1-hour cache writes $149, cache reads $153, output $74. Subagents cost $840: 5-minute cache writes $379, output $274, cache reads $187, with the principles auditors at $274 over 342 runs, the stability reviewers $179 and general-purpose subagents $192. A worker starts at 41k tokens of context and peaks at a median 167k, one in ten past 358k, the largest at 848k. The worker's messages above 200k were 32% of its messages and 55% of its cost. -- Compaction. Compacting the worker at 167k to 180k saves $77 to $78 of the workers' $375, 6% of all spend, at 0.7 to 0.8 compactions per chunk; at 150k $75 at 1.0, at 200k $78 at 0.5, at 300k $54 at 0.2. It also caps the 36 re-writes of a whole context after a gap longer than the cache's hour or a change of rung, $61 at up to 785k tokens each, at about $34. Compacting subagents at 150k costs more than it saves, since a compaction reads the context once more and writes a summary, and subagents are short. A 200k window through `CLAUDE_CODE_DISABLE_1M_CONTEXT` would compact at the same point and also narrow every interactive session. -- A fresh context for the review phase, handed 60k tokens of facts, saves $39, which compaction covers, and loop-claude would need a second session per chunk. -- Read with an offset and a limit, or Grep, in place of `cat`, `sed` and `head`: the worker's tool results were 13.2M characters, 65% of them Bash reads, but only 13% whole files; the rest were ranges. A character a worker reads costs about $8 per million tokens to write to the 1-hour cache and $0.20 per million at each later turn, so all the worker's reads cost about $45 and the whole-file ones about $6. A rule would change the tool, not how much is read. +The options item 231 named, simulated on those chunks: + +- Compaction of the worker. The saving and the compactions per chunk, by the point it compacts at: 150k saves $75 at 1.0 compactions; 167k to 180k, where a 200k window compacts, $77 to $78 at 0.8 to 0.7; 200k $78 at 0.5; 300k $54 at 0.2. $78 is 21% of the workers' $375 and 6% of all spend. Compaction also caps the 36 re-writes of a whole context after a gap longer than the cache's hour or a change of rung: they cost $61, up to 785k tokens each, and would cost about $34. Compacting subagents at 150k costs more than it saves, since a compaction reads the context once more and writes a summary, and subagents are short. +- A fresh context for the review phase, handed 60k tokens of facts, saves $39. A compaction at 170k saves that too, and loop-claude would need a second session per chunk. +- Read with an offset and a limit, or Grep, in place of `cat`, `sed` and `head`. The worker's tool results were 13.2M characters, 65% of them Bash reads, and 13% of those characters came from whole files; the rest were ranges. A token a worker reads costs about $8 per million to write to the 1-hour cache and $0.20 per million at each later turn, so all the worker's reads cost about $45 and the whole-file ones about $6. A rule would change the tool, not how much is read. - Code-intelligence tooling: the `LSP` tool, with a language server per language on PATH, replaces a grep and the reads of candidate files with one lookup. Its ceiling is the same $45, and each machine would need a server per language (goal 2). Not tried, and not worth an item while the worker's reads stay under 4% of spend. - What a reviewer reads: the auditors read the project whole by design. Of their 🔴 and 🟡 findings since the reset, 47% named a file the chunk edited and 51% another file, so reading only the change would drop half of them; item 236 asks lilleman about that scope, and item 233 has one auditor read the project once per round. -- The base context: every thread starts with `~/.claude/CLAUDE.md` (19k characters), `~/.claude/AGENTS.md` (11k, this repo's decisions, which Claude Code loads as user instructions into every project's sessions; item 52), the project's `AGENTS.md`, and, for the worker and general-purpose subagents, the skill listing (18k) and the agent listing (12k). Subagents' first messages wrote $97 of it; trimming the listings would save about $20, 2%, and is not worth an item: `disableBundledSkills` would also drop `/security-review`, the security pass of record. +- The base context: every thread starts with `~/.claude/CLAUDE.md` (19k characters), `~/.claude/AGENTS.md` (11k, this repo's decisions, which Claude Code loads as user instructions into every project's sessions; item 52), the project's `AGENTS.md`, and, for the worker and general-purpose subagents, the skill listing (18k) and the agent listing (12k). Subagents' first messages wrote $97 of it. Trimming the listings would save about $20, 2%, and is not worth an item: `disableBundledSkills` would also drop `/security-review`, the security pass of record. -Quality. 19 chunks compacted between 2026-10-10 and 2026-10-22, at 214k to 972k tokens, the windows Claude Code tuned then. Per 100 worker messages they took a median 3.6 review rounds past each pass's first against 4.0 for the 68 uncompacted chunks of 100 messages or more, and 13.9 🔴 and 🟡 findings against 16.6. 4 of 19 had an unfinished verdict against 3 of 68, each 8 to 10 hours after the compaction and followed by a finished verdict within minutes; the judge quoted the worker's own passages and the human's typed answers in them, never a summary. One cause was possible and is closed here: Claude Code writes the summary as a user entry, which `bin/claude_code/entries.py` read as the human's words, so the judge would see a `[human]` line of thousands of words and `/talk` would count it as typed; it now reads as Claude Code's. Whether compaction raises unfinished verdicts stays open until item 235 measures it. Two summaries read whole kept the chunk's intent, files, errors and next step in 12k to 20k characters, and the worker resumed without re-reading. +Quality. 19 chunks compacted between 2026-10-10 and 2026-10-22, at the compaction points Claude Code set then, 214k to 972k tokens. Per 100 worker messages they took a median 3.6 review rounds past each pass's first against 4.0 for the 68 uncompacted chunks of 100 messages or more, and 13.9 🔴 and 🟡 findings against 16.6. 4 of 19 had an unfinished verdict against 3 of 68, each 8 to 10 hours after the compaction and followed by a finished verdict within minutes; in those four verdicts the judge quoted the worker's own passages and the human's typed answers, never a summary. One cause was possible and is closed here: Claude Code writes the summary as a user entry, which `bin/claude_code/entries.py` read as the human's words, so the judge would see a `[human]` line of thousands of words and `/talk` would count it as typed; it now reads as Claude Code's. Whether compaction raises unfinished verdicts stays open until item 235 measures it. Two summaries read whole kept the chunk's intent, files, errors and next step in 12k to 20k characters, and the worker resumed without re-reading. -Hours. A chunk ran a median 0.7 hours from its first message to its last, one in ten past 12 hours, mostly waiting for the human or a usage limit. No option here changes that: a compaction takes 51 to 83 seconds, under a minute per chunk at 0.7 each, and a smaller context makes a turn no faster to notice. The hours lever is item 232, since waiting on subagents took 66% of a worker's active time. - -The window is handed to the worker, and the session /talk opens, as `CLAUDE_CODE_AUTO_COMPACT_WINDOW=200000` (`bin/loop_claude/cycle/worker.py`), not set in `settings.json`: the archive measured loop-claude's workers, and interactive sessions are lilleman's. Claude Code compacts before a window fills: a 1M window at about 967k, and in a probe on 2026-10-27 a 100k window at 65k and 80k, so a 200k window compacts at about 170k. Subagents inherit it: 68 of the 994 subagent runs since the reset, 7%, passed 170k, 24 of them principles auditors, so about one in fourteen compacts once, and `CLAUDE.md` → "Compact instructions" has a reviewer keep the findings it has drafted. Another probe that day showed that a `Compact instructions` section in a CLAUDE.md shapes the summary: a session whose CLAUDE.md asked the summary to end with its secret word did. So `CLAUDE.md` → "Compact instructions" names what a worker's summary keeps. Path-scoped rules leave the context at a compaction and return at the next matching read, and rule-hook holds each review launch to its rung whatever the summary keeps. Item 235 compares the first 20 chunks under the window with the 20 before. +Hours. A chunk ran a median 0.7 hours from its first message to its last, one in ten past 12 hours, mostly waiting for the human or a usage limit. No option here changes that: a compaction takes 51 to 83 seconds, under a minute per chunk at 0.7 each, and a smaller context saves seconds per turn at most. The hours lever is item 232, since waiting on subagents took 66% of a worker's active time. Valid while cache reads cost a twentieth of input and Claude Code's compaction keeps the worker's task. diff --git a/todo.md b/todo.md index e2bebc99..0a9af5f6 100644 --- a/todo.md +++ b/todo.md @@ -18,7 +18,7 @@ | 234 | 0.4.0 | | | **Report the routing figures in dollars, cache reads included, from the cost each archived run records.** | 2 | 2 | 2 | 4 | 3 | 1.4 by 3 | 3.0 | | 236 | 0.5.0 | | question | **Answer whether the principles audit keeps reading the whole project, or reads only the files the chunk changed and their callers, now that half of its 🔴 and 🟡 findings name a file the chunk did not edit.** | 1 | 1 | 1 | 1 | 1 | 1.4 by 4 | 6.4 | | 226 | 0.5.0 | | question | **Answer whether rule-hook's `run-heavy` rule should also catch a mutation run or docker build behind `uv run`, `poetry run`, `python3 -m`, `sudo`, `docker image build` and `docker compose up --build`, or narrow the `machine load:` decision's wording.** | 2 | 2 | 3 | 5 | 3 | 1.2 by 2, 1.5 by 2 | 4.0 | -| 235 | 0.5.0 | | | **Compare review rounds past each pass's first, unfinished verdicts, 🔴, 🟡 and misread findings, dollars and hours per chunk, for the first 20 chunks whose worker ran under the 200k compaction window against the 20 before them, and file an item where any rose.** | 1 | 2 | 1 | 2 | 2 | 1.1 by 2, 1.4 by 3 | 6.8 | +| 235 | 0.5.0 | | | **Compare the first 20 chunks whose worker ran under the 200k compaction window with the 20 before them, on review rounds past each pass's first, unfinished verdicts, 🔴, 🟡 and misread findings, dollars and hours per chunk, and file an item where any rose.** | 1 | 2 | 1 | 2 | 2 | 1.1 by 2, 1.4 by 3 | 6.8 | | 59 | 0.5.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.5.0 | | | **Refuse a `/security-review` or `/claude-security` Skill call below the project's rung, as rule-hook refuses such an Agent call.** | 3 | 2 | 3 | 6 | 2 | 1.1 by 4 | 5.6 | | 6 | 0.5.0 | | decision | **Move what `loop-claude` writes out of `~/.claude.json`, and ask the human about each write that must stay.** | 3 | 3 | 3 | 7 | 3 | 1.1 by 5 | 5.3 | @@ -48,7 +48,7 @@ | 101 | 0.6.0 | | principle | **Have `larv_review/history_commands.py`'s `read_seats` take the time, the commit check and the history as inputs, so it parses and decides without effects.** | 2 | 1 | 2 | 3 | 3 | 1.1 by 5 | 5.3 | | 110 | 0.6.0 | | decision | **Count, for each finished chunk, the later changes that fixed code it wrote, and show them beside its guessed E.** | 3 | 2 | 2 | 5 | 5 | 1.1 by 6, 1.4 by 6 | 4.9 | | 12 | 0.6.0 | | | **Run the test suite in CI on every PR, or record in `docs/decisions.md` why the local run is enough.** | 3 | 2 | 1 | 4 | 4 | 1.1 by 6 | 4.2 | -| 102 | 0.6.0 | | | **Give loop-claude's retry delay and its memory read environment overrides, so the black-box test stops replacing `time.sleep` and `machine_load.memory.MEMINFO` through `sitecustomize`.** | 1 | 1 | 2 | 2 | 3 | 1.1 by 4 | 4.2 | +| 102 | 0.6.0 | | | **Give loop-claude's retry delay, and the file it reads the machine's memory from, environment overrides, so the black-box test stops replacing `time.sleep` and `machine_load.memory.MEMINFO` through `sitecustomize`.** | 1 | 1 | 2 | 2 | 3 | 1.1 by 4 | 4.2 | | 135 | 0.6.0 | | | **Fingerprint only the modules loop-claude imports, so editing another tool's code no longer reloads a running loop.** | 2 | 2 | 3 | 5 | 3 | 1.1 by 4 | 4.2 | | 171 | 0.6.0 | | decision | **Group the routing figures' review rounds by the reviewers' rung as well as the worker's, so a call blames a rung only for rounds its own reviews raised.** | 3 | 2 | 2 | 5 | 4 | 1.2 by 3, 1.4 by 3 | 4.0 | | 196 | 0.6.0 | | decision | **Replay the architecture, principles, overrides and product-owner passes with `review-replay` on Opus 5.5 projects, record each run in the review-replay routing decision, and add any rung a run qualifies to `REPLAYED`.** | 2 | 2 | 3 | 5 | 2 | 1.4 by 3 | 4.0 | @@ -72,7 +72,7 @@ | 51 | 0.6.0 | | principle | **Hand loop-claude's terminal output to an injected effect, so no storage or retry function prints.** | 2 | 1 | 3 | 4 | 5 | 1.1 by 5 | 2.1 | | 169 | 0.6.0 | | | **Have rule-hook's `todo-rank-check` catch a `todo.md` that the same Bash call edits and then commits.** | 3 | 1 | 3 | 5 | 3 | 1.1 by 2 | 2.1 | | 174 | 0.6.0 | | | **In a chunk no item routed, ask the worker to name each todo.md item it takes, with its L and E + I, so loop-claude can route on an item it takes in.** | 1 | 2 | 3 | 4 | 1 | 1.1 by 1 | 1.7 | -| 52 | 0.6.0 | | principle | **Move this checkout out of Claude Code's own directory, or record why it stays, since Claude Code loads its `AGENTS.md` as the user's instructions into every project's sessions.** | 4 | 3 | 4 | 9 | 6 | 1.1 by 4, 1.4 by 2 | 1.4 | +| 52 | 0.6.0 | | principle | **Move this checkout out of Claude Code's own directory, or record why it stays, since Claude Code loads the checkout's `AGENTS.md` as the user's instructions into every project's sessions.** | 4 | 3 | 4 | 9 | 6 | 1.1 by 4, 1.4 by 2 | 1.4 | | 197 | 0.6.0 | | | **Let the human edit what they type at loop-claude's terminal questions with the arrow keys, so Left moves the cursor in place of printing `^[[D`.** | 2 | 2 | 3 | 5 | 2 | 1.5 by 1 | 1.3 | | 170 | 0.7.0 | | decision | **Re-tune `WORKER_STEPS` and `REVIEW_STEPS` once 50 chunks have shipped under them, from how well L, E and I order their review rounds and 🔴 findings.** | 2 | 2 | 3 | 5 | 2 | 1.1 by 3, 1.4 by 5 | 10.9 | | 218 | 0.7.0 | 170 | | **Drop `LEGACY_WORKER` from `bin/model_routing/route.py`, so `route_from` reads only JSON worker lines.** | 1 | 2 | 1 | 2 | 1 | code health by 2 | 14.4 | @@ -85,11 +85,11 @@ Since 2026-10-21, all 1,372 Agent calls in workers' transcripts were one per mes ### 238. Run the security pass's skill in the chunk's worktree, so it scans the branch's diff: invoked from a subagent, it runs in the session's working directory, the main checkout, and scans nothing. -Found while reviewing PR #376. larv-review §3 → "Security" launches a general-purpose subagent that invokes `/security-review` through the Skill tool. The skill runs its git commands in the session's working directory, the checkout root, where the branch's diff is empty, and the subagent then reads the worktree's diff itself, which the skill's own text forbids as a substitute. The archived security subagents of items 198 and 223 and of this chunk all report it. It sits in 0.4.0 so the release's remaining chunks get a scan that reads their diff; until it is fixed, run `claude -p /security-review` with the worktree as its working directory, on the project's rung, as PR #376 did. A fix may run the skill as a process in the worktree from larv-review, or have the worker enter the worktree with Claude Code's `EnterWorktree` tool so every subagent runs there. +Found while reviewing PR #376. larv-review §3 → "Security" launches a general-purpose subagent that invokes `/security-review` through the Skill tool. The skill runs its git commands in the session's working directory, the checkout root, where the branch's diff is empty, and the subagent then reads the worktree's diff itself, which the skill's own text forbids as a substitute. The archived security subagents of items 198 and 223 and of PR #376 all report it. It sits in 0.4.0 so the release's remaining chunks get a scan that reads their diff; until it is fixed, run `claude -p /security-review` with the worktree as its working directory, on the project's rung, as PR #376 did. A fix may run the skill as a process in the worktree from larv-review, or have the worker enter the worktree with Claude Code's `EnterWorktree` tool so every subagent runs there. ### 233. Run one principles-auditor per round that checks the goals and every principles file that applies, in place of one auditor for each, so the principles pass reads the project once per round. -Since 2026-10-21, 342 principles-auditor runs cost $274 at list prices, 23% of all spend and 3.8 runs per chunk, and each read the project anew: $129 of 5-minute cache writes, $92 of output and $53 of cache reads. Today larv-review §3 → "Principles" launches one auditor for the README's goals and code health, and one per file in `~/.claude/principles/` that applies. The merged auditor must find what the separate ones found: replay archived rounds with `review-replay`, and keep separate auditors where the merged one misses a 🔴 or 🟡. Rename the report files, `principles--round-.md` today (§3 → "Reports"), to one per round. +Since 2026-10-21, 342 principles-auditor runs, 3.8 per chunk, cost $274 at list prices, 23% of all spend: $129 of 5-minute cache writes, $92 of output and $53 of cache reads. Each read the project anew. Today larv-review §3 → "Principles" launches one auditor for the README's goals and code health, and one per file in `~/.claude/principles/` that applies. The merged auditor must find what the separate ones found: replay archived rounds with `review-replay`, and keep separate auditors where the merged one misses a 🔴 or 🟡. Rename the report files, `principles--round-.md` today (§3 → "Reports"), to one per round. ### 234. Report the routing figures in dollars, cache reads included, from the cost each archived run records. @@ -97,13 +97,13 @@ The routing figures count input, cache-written and output tokens, and leave out ### 236. Answer whether the principles audit keeps reading the whole project, or reads only the files the chunk changed and their callers, now that half of its 🔴 and 🟡 findings name a file the chunk did not edit. -Since 2026-10-21, 342 principles-auditor runs cost $274 at list prices, 23% of all spend, and 176 of their 🔴 and 🟡 findings named a file: 83 a file the chunk edited, 90 another. `docs/decisions.md` → `review: the principles audit runs on every chunk…` holds the whole-project audit valid while its findings are drift a chunk would otherwise merge, and calls a repeat a question on the audit's scope for the human. Reading only the changed files and their callers would cut most of the auditors' $129 of cache writes and drop the findings elsewhere, unless those repeat chunk after chunk: read a sample of the 90 before answering. Item 233 merges the auditors either way. +Since 2026-10-21, 342 principles-auditor runs cost $274 at list prices, 23% of all spend, and 176 of their 🔴 and 🟡 findings named a file: 83 a file the chunk edited, 90 another. `docs/decisions.md` → `review: the principles audit runs on every chunk…` holds the whole-project audit valid while its findings are drift a chunk would otherwise merge, and calls a repeat a question on the audit's scope for the human. Reading only the changed files and their callers would cut most of the auditors' $129 of cache writes and drop the findings elsewhere, unless the same findings come back chunk after chunk: read a sample of the 90 before answering. Item 233 merges the auditors either way. ### 226. Answer whether rule-hook's `run-heavy` rule should also catch a mutation run or docker build behind `uv run`, `poetry run`, `python3 -m`, `sudo`, `docker image build` and `docker compose up --build`, or narrow the `machine load:` decision's wording. Found by review of PR #370. Today `uv run mutmut run`, `poetry run mutmut run`, `python3 -m mutmut run`, `sudo docker build .`, `docker image build .` and `docker compose up --build` pass the rule, which `docs/decisions.md` → `machine load: …` and `RULES["run-heavy"]` describe as blocking docker builds and mutation runs. The rule's own text says a gate script isn't checked since no program can tell it from a light one, so the human decides where the line sits. Say what the rule's "checked" text promises either way. Where the answer widens the rule, the change touches `heavy` in `bin/rule_hook/heavy_command.py`, which the comprehension seats found hard: make it easier to read. -### 235. Compare review rounds past each pass's first, unfinished verdicts, 🔴, 🟡 and misread findings, dollars and hours per chunk, for the first 20 chunks whose worker ran under the 200k compaction window against the 20 before them, and file an item where any rose. +### 235. Compare the first 20 chunks whose worker ran under the 200k compaction window with the 20 before them, on review rounds past each pass's first, unfinished verdicts, 🔴, 🟡 and misread findings, dollars and hours per chunk, and file an item where any rose. `docs/decisions.md` → `loop-claude: the worker's claude compacts its context before it fills a 200k window…` expects a saving of about 6% of all spend with no rise in the other figures. Measure from loop-claude's archive as that decision did: rounds past each pass's first and the 🔴, 🟡 and misread counts from the round commit titles, unfinished verdicts from the outcomes files, hours from the worker's first message to its last, and dollars at list prices, cache reads included, from the chunk's `cost-state` entry, which counts the compaction calls that no message's usage records; item 234 puts such dollars into the routing figures. A chunk ran under the window when its first worker started after that decision merged. @@ -241,9 +241,9 @@ The repo has no CI, so larv-review's gate is the local run, and larv-review's Ga When CI runs a rule check, such as one of `bin/rule-hook`'s, let `` in the PR body override it. -### 102. Give loop-claude's retry delay and its memory read environment overrides, so the black-box test stops replacing `time.sleep` and `machine_load.memory.MEMINFO` through `sitecustomize`. +### 102. Give loop-claude's retry delay, and the file it reads the machine's memory from, environment overrides, so the black-box test stops replacing `time.sleep` and `machine_load.memory.MEMINFO` through `sitecustomize`. -Found by the principles audit of PR #242. `bin/loop_claude/test_black_box.py:113-114` swaps the global `time.sleep`, the shape "Functional core, imperative shell" bans, and the audit of PR #376 found the same block swapping `machine_load.memory.MEMINFO` at lines 119-123. An override of each lets the test run the code as production runs it. +Found by the principles audit of PR #242. `bin/loop_claude/test_black_box.py:117-118` swaps the global `time.sleep`, the shape "Functional core, imperative shell" bans, and the audit of PR #376 found the same block swapping `machine_load.memory.MEMINFO` at lines 120-123. An override of each lets the test run the code as production runs it. ### 135. Fingerprint only the modules loop-claude imports, so editing another tool's code no longer reloads a running loop. @@ -375,9 +375,9 @@ The hook judges a call before it runs, and `changed` in `bin/rule_hook/todo_chec The principles pass of PR #301 found that only `routed_by` in `bin/loop_claude/cycle/prompts.py` asks the worker to name each item it takes with its L and E + I, and `fresh` uses it only where an item routed the chunk. In an unrouted chunk the judge has no levels to report, so neither the taken-in L nor the taken-in E + I lifts the worker or the judge. -### 52. Move this checkout out of Claude Code's own directory, or record why it stays, since Claude Code loads its `AGENTS.md` as the user's instructions into every project's sessions. +### 52. Move this checkout out of Claude Code's own directory, or record why it stays, since Claude Code loads the checkout's `AGENTS.md` as the user's instructions into every project's sessions. -"One owner per value" and "Prefer the vendor-neutral option", in `principles/technical-principles.md`: git, Claude Code and loop-claude all write `~/.claude`, kept apart only by the `.gitignore` allowlist, and the repo's records live in a vendor directory. Claude Code also loads `~/.claude/AGENTS.md`, this checkout's decision titles, as the user's instructions into every session of every project: 10.7k characters, about 2.7k tokens, in each of the 1,084 threads since 2026-10-21, about $25 of cache writes and reads at list prices, and a worker on another project reads this repo's decisions as if they held there. +"One owner per value" and "Prefer the vendor-neutral option", in `principles/technical-principles.md`: git, Claude Code and loop-claude all write `~/.claude`, kept apart only by the `.gitignore` allowlist, and the repo's records live in a vendor directory. Claude Code also loads `~/.claude/AGENTS.md`, this checkout's decision titles, as the user's instructions into every session of every project, so a worker on another project reads this repo's decisions as if they held there. That cost about $25 of cache writes and reads at list prices since 2026-10-21: 10.7k characters, about 2.7k tokens, in each of 1,084 threads. ### 197. Let the human edit what they type at loop-claude's terminal questions with the arrow keys, so Left moves the cursor in place of printing `^[[D`. From 34a623e26112a7cef14d0b73d00baae4300efadc Mon Sep 17 00:00:00 2001 From: Lilleman auf Larv Date: Tue, 27 Oct 2026 01:30:34 +0100 Subject: [PATCH 49/55] File item 239, lilleman's call: block a re-read of a file range already in context while the file is unchanged --- todo.md | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/todo.md b/todo.md index 0a9af5f6..aca2051c 100644 --- a/todo.md +++ b/todo.md @@ -6,7 +6,7 @@ `Bar = 0.1` -`Next ID = 239` +`Next ID = 240` ## Items @@ -16,6 +16,7 @@ | 238 | 0.4.0 | | defect | **Run the security pass's skill in the chunk's worktree, so it scans the branch's diff: invoked from a subagent, it runs in the session's working directory, the main checkout, and scans nothing.** | 2 | 2 | 3 | 5 | 3 | 1.1 by 5 | 5.3 | | 233 | 0.4.0 | | | **Run one principles-auditor per round that checks the goals and every principles file that applies, in place of one auditor for each, so the principles pass reads the project once per round.** | 3 | 2 | 3 | 6 | 3 | 1.4 by 3, 1.5 by 2 | 4.9 | | 234 | 0.4.0 | | | **Report the routing figures in dollars, cache reads included, from the cost each archived run records.** | 2 | 2 | 2 | 4 | 3 | 1.4 by 3 | 3.0 | +| 239 | 0.4.0 | | owner | **Block a Read, `cat`, `sed` or `head` of a file range the session already read while the file is unchanged, with a note that the content is in context, and let it through after a compaction or a change to the file.** | 3 | 2 | 3 | 6 | 4 | 1.4 by 3 | 2.0 | | 236 | 0.5.0 | | question | **Answer whether the principles audit keeps reading the whole project, or reads only the files the chunk changed and their callers, now that half of its 🔴 and 🟡 findings name a file the chunk did not edit.** | 1 | 1 | 1 | 1 | 1 | 1.4 by 4 | 6.4 | | 226 | 0.5.0 | | question | **Answer whether rule-hook's `run-heavy` rule should also catch a mutation run or docker build behind `uv run`, `poetry run`, `python3 -m`, `sudo`, `docker image build` and `docker compose up --build`, or narrow the `machine load:` decision's wording.** | 2 | 2 | 3 | 5 | 3 | 1.2 by 2, 1.5 by 2 | 4.0 | | 235 | 0.5.0 | | | **Compare the first 20 chunks whose worker ran under the 200k compaction window with the 20 before them, on review rounds past each pass's first, unfinished verdicts, 🔴, 🟡 and misread findings, dollars and hours per chunk, and file an item where any rose.** | 1 | 2 | 1 | 2 | 2 | 1.1 by 2, 1.4 by 3 | 6.8 | @@ -95,6 +96,10 @@ Since 2026-10-21, 342 principles-auditor runs, 3.8 per chunk, cost $274 at list The routing figures count input, cache-written and output tokens, and leave out cache reads, which were 28% of the cost since 2026-10-21, $340 of $1,215 at list prices. So their tables rank the principles auditor above the worker, while in dollars the worker cost 1.4 times as much, $375 against $274. Each archived worker transcript ends with a `cost-state` entry holding `totalCostUSD` and each model's cost, and each message's usage attributes the cost to a subagent type. The judge's runs record no cost in the archive: count them too, or say why not. The change touches `bin/routing_figures/measure.py`, which the comprehension seats found hard (item 139): make the places it touches easier to read. +### 239. Block a Read, `cat`, `sed` or `head` of a file range the session already read while the file is unchanged, with a note that the content is in context, and let it through after a compaction or a change to the file. + +lilleman's call, 2026-10-27, filed from PR #376's measurement of loop-claude's archive since 2026-10-21: a read of a file the agent read earlier in the thread, more than three messages before and without editing it in between, is 13% of the worker's reading, about $6 of the $45 its reads cost, and 1 to 2% of a reviewer's. A hook on `Read` and on the Bash reads `cat`, `sed` and `head` blocks such a read with a short note that the content is already in context and unchanged. It lets the read through after a compaction, when the content has left the context, or when the file changed since the read; a PreToolUse hook gets the session's `transcript_path`, which holds the earlier reads and each `compact_boundary`, so it needs no state of its own. If scouts ship (item 231's decision records the trial), the same idea applies to scout answers, cached by file and content hash: a scout only cheapens these re-reads and doesn't remove them, which is why this is a separate item. + ### 236. Answer whether the principles audit keeps reading the whole project, or reads only the files the chunk changed and their callers, now that half of its 🔴 and 🟡 findings name a file the chunk did not edit. Since 2026-10-21, 342 principles-auditor runs cost $274 at list prices, 23% of all spend, and 176 of their 🔴 and 🟡 findings named a file: 83 a file the chunk edited, 90 another. `docs/decisions.md` → `review: the principles audit runs on every chunk…` holds the whole-project audit valid while its findings are drift a chunk would otherwise merge, and calls a repeat a question on the audit's scope for the human. Reading only the changed files and their callers would cut most of the auditors' $129 of cache writes and drop the findings elsewhere, unless the same findings come back chunk after chunk: read a sample of the 90 before answering. Item 233 merges the auditors either way. From d96e5c35ef675ca1830fc6e1aa2d3b3cc889352d Mon Sep 17 00:00:00 2001 From: Lilleman auf Larv Date: Tue, 27 Oct 2026 02:11:05 +0100 Subject: [PATCH 50/55] Record the read pricing, precision and tool trials in item 231's decision, and file questions 240 and 241 --- docs/decisions.md | 8 ++++++++ todo.md | 12 +++++++++++- 2 files changed, 19 insertions(+), 1 deletion(-) diff --git a/docs/decisions.md b/docs/decisions.md index 17a52653..48bc305c 100644 --- a/docs/decisions.md +++ b/docs/decisions.md @@ -93,6 +93,14 @@ Quality. 19 chunks compacted between 2026-10-10 and 2026-10-22, at the compactio Hours. A chunk ran a median 0.7 hours from its first message to its last, one in ten past 12 hours, mostly waiting for the human or a usage limit. No option here changes that: a compaction takes 51 to 83 seconds, under a minute per chunk at 0.7 each, and a smaller context saves seconds per turn at most. The hours lever is item 232, since waiting on subagents took 66% of a worker's active time. +Reads and tools, measured the same day at lilleman's ask, on the same 90 chunks: + +- What reads cost. The messages that took in tool results carried $537 of the $1,215, 44%: the worker's $190 (Bash reads $115, Read $12), the principles auditors' $139 (Read $109, Grep $22), the stability reviewers' $106 (Bash reads $79), general-purpose subagents' $97, the prose reviewers' $34, the architects' $31 and the product-owner reviewers' $23. These figures charge a message's new input tokens to the results it took in, so they include what arrives beside a result, such as the agent's own previous reply; the 93M characters read alone are about 27M tokens. +- Precision. Of the characters a principles auditor read, 13% were in a file its report names; a stability reviewer 8%; the worker 4% in a file it later edited; a prose reviewer 18%; an architect 11%. Reading is mostly to find things and to learn what a project holds, as lilleman read it. The worker's `sed` ranges are small, median 25 lines, one in ten over 80. Of the worker's read characters, 49% were of a file it had read earlier in the thread: 36% within three messages, paging through it, and 13% later and unchanged, about $6 of the $45 its reads cost; reviewers 1 to 2% (item 239). +- Tool results. Claude Code caps a Bash result at about 30k characters. Subagents' Read results, 59.9M characters, have 58% of their characters in results over 12k. +- Trials on this repo. Four stability rounds and five principles rounds archived on 2026-10-23, each holding 🔴 or 🟡 findings, replayed on the project's rung as `review-replay` replays them, with the reviewer's definition changed through `--agents`; and three worker-like tasks, a search, a rename and an explanation, run on fresh clones at the project's rung. The baseline reviewers found 4 of their own 6 archived findings in each pass, the spread a sample this small sits in. The LSP tool, through a pyright plugin built from the marketplace manifest with `pyright-langserver` on PATH, answers a file's symbols, a definition or the references in a few hundred characters; the stability reviewers and the workers never called it under a rule telling them to, and the auditors who did read as much or more and missed the one 🔴 (0 of 1 against the baseline's 1 of 1). An `outline` script printing a file's symbols with line ranges: never called by workers; stability reviewers under its rule found 2 of 6 findings. A PostToolUse hook capping a Bash result at 12k characters: 3 of 6, two lost in one round. A scout, Haiku 5.5 reading raw content and returning facts and line ranges: as an in-session agent its first request writes 37k tokens, $0.005, and a read of a 38KB file costs $0.008 in 8 seconds; as a slim headless `claude -p` with its own system prompt, no setting sources and no dynamic sections, 6k tokens, $0.0003 and 3 to 5 seconds of startup, its prefix cached across calls, and the same read $0.004 in 7 seconds. Stability reviewers with the agent scout found 5 of 6 findings and read 29% fewer characters at 6% less cost and 14% more time; with the CLI scout 4 of 6, 38% fewer characters, 17% less cost and 39% more time; the auditors with the agent scout 3 of 6 at the same cost and twice the time. Workers offered the scout never called it, but its reading rule alone, never read more than 80 lines of a file yourself, cut their reading 45% to 60% at the same or lower cost, with all three tasks done as well. +- What follows. On this sample no tool cuts a reviewer's reading without losing a finding, except the scout, whose saving sits within the baseline's own spread; so none of them ships here. lilleman decides two trials: a reading rule for workers (item 240) and a scout for reviewers (item 241). A direct API call and `claude --bare` are out, since both need an API key where lilleman's login is a subscription. + Valid while cache reads cost a twentieth of input and Claude Code's compaction keeps the worker's task. ## 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 diff --git a/todo.md b/todo.md index aca2051c..77cb605f 100644 --- a/todo.md +++ b/todo.md @@ -6,7 +6,7 @@ `Bar = 0.1` -`Next ID = 240` +`Next ID = 242` ## Items @@ -18,7 +18,9 @@ | 234 | 0.4.0 | | | **Report the routing figures in dollars, cache reads included, from the cost each archived run records.** | 2 | 2 | 2 | 4 | 3 | 1.4 by 3 | 3.0 | | 239 | 0.4.0 | | owner | **Block a Read, `cat`, `sed` or `head` of a file range the session already read while the file is unchanged, with a note that the content is in context, and let it through after a compaction or a change to the file.** | 3 | 2 | 3 | 6 | 4 | 1.4 by 3 | 2.0 | | 236 | 0.5.0 | | question | **Answer whether the principles audit keeps reading the whole project, or reads only the files the chunk changed and their callers, now that half of its 🔴 and 🟡 findings name a file the chunk did not edit.** | 1 | 1 | 1 | 1 | 1 | 1.4 by 4 | 6.4 | +| 240 | 0.5.0 | | question | **Answer whether workers get a reading rule in `CLAUDE.md`, never reading more than 80 lines of a file at once, which cut three worker tasks' reading 45% to 60% at the same quality.** | 1 | 2 | 3 | 4 | 1 | 1.4 by 3 | 4.8 | | 226 | 0.5.0 | | question | **Answer whether rule-hook's `run-heavy` rule should also catch a mutation run or docker build behind `uv run`, `poetry run`, `python3 -m`, `sudo`, `docker image build` and `docker compose up --build`, or narrow the `machine load:` decision's wording.** | 2 | 2 | 3 | 5 | 3 | 1.2 by 2, 1.5 by 2 | 4.0 | +| 241 | 0.5.0 | | question | **Answer whether reviewers hand a read over 80 lines to a Haiku scout, which cut a stability reviewer's reading 29% to 38% and its cost 6% to 17% on four replayed rounds, at 14% to 39% more time and findings within the baseline's own spread.** | 2 | 2 | 3 | 5 | 3 | 1.4 by 3 | 3.0 | | 235 | 0.5.0 | | | **Compare the first 20 chunks whose worker ran under the 200k compaction window with the 20 before them, on review rounds past each pass's first, unfinished verdicts, 🔴, 🟡 and misread findings, dollars and hours per chunk, and file an item where any rose.** | 1 | 2 | 1 | 2 | 2 | 1.1 by 2, 1.4 by 3 | 6.8 | | 59 | 0.5.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.5.0 | | | **Refuse a `/security-review` or `/claude-security` Skill call below the project's rung, as rule-hook refuses such an Agent call.** | 3 | 2 | 3 | 6 | 2 | 1.1 by 4 | 5.6 | @@ -104,10 +106,18 @@ lilleman's call, 2026-10-27, filed from PR #376's measurement of loop-claude's a Since 2026-10-21, 342 principles-auditor runs cost $274 at list prices, 23% of all spend, and 176 of their 🔴 and 🟡 findings named a file: 83 a file the chunk edited, 90 another. `docs/decisions.md` → `review: the principles audit runs on every chunk…` holds the whole-project audit valid while its findings are drift a chunk would otherwise merge, and calls a repeat a question on the audit's scope for the human. Reading only the changed files and their callers would cut most of the auditors' $129 of cache writes and drop the findings elsewhere, unless the same findings come back chunk after chunk: read a sample of the 90 before answering. Item 233 merges the auditors either way. +### 240. Answer whether workers get a reading rule in `CLAUDE.md`, never reading more than 80 lines of a file at once, which cut three worker tasks' reading 45% to 60% at the same quality. + +lilleman's question, from PR #376's trials (`docs/decisions.md` → `loop-claude: the worker's claude compacts its context before it fills a 200k window…`, "Reads and tools"). Three worker-like tasks on this repo, a search, a rename and an explanation, run under the rule "never read more than 80 lines of a file yourself, and never take a tool output you expect to exceed 3,000 characters into your context" read 45% to 60% fewer characters at the same or lower cost and answered as well; the rename under it was the only one that also kept the import names sorted. Only 4% of what a worker reads is in a file it later edits. The rule is one line in `CLAUDE.md` that every session loads, so its effect on real chunks, misread findings above all, is unmeasured: a yes trials it and item 235's figures over the next 20 chunks measure it. + ### 226. Answer whether rule-hook's `run-heavy` rule should also catch a mutation run or docker build behind `uv run`, `poetry run`, `python3 -m`, `sudo`, `docker image build` and `docker compose up --build`, or narrow the `machine load:` decision's wording. Found by review of PR #370. Today `uv run mutmut run`, `poetry run mutmut run`, `python3 -m mutmut run`, `sudo docker build .`, `docker image build .` and `docker compose up --build` pass the rule, which `docs/decisions.md` → `machine load: …` and `RULES["run-heavy"]` describe as blocking docker builds and mutation runs. The rule's own text says a gate script isn't checked since no program can tell it from a light one, so the human decides where the line sits. Say what the rule's "checked" text promises either way. Where the answer widens the rule, the change touches `heavy` in `bin/rule_hook/heavy_command.py`, which the comprehension seats found hard: make it easier to read. +### 241. Answer whether reviewers hand a read over 80 lines to a Haiku scout, which cut a stability reviewer's reading 29% to 38% and its cost 6% to 17% on four replayed rounds, at 14% to 39% more time and findings within the baseline's own spread. + +lilleman's question, from PR #376's trials (`docs/decisions.md` → `loop-claude: the worker's claude compacts its context before it fills a 200k window…`, "Reads and tools"). A scout is Haiku 5.5 reading raw content, whole files or long output, and returning facts as path:line and the ranges worth reading. In session, as an agent under `agents/`, its first request writes 37k tokens, $0.005, and a read of a 38KB file costs $0.008 in 8 seconds; as a slim headless `claude -p --model claude-haiku-5-5 --system-prompt … --tools "" --setting-sources "" --no-session-persistence`, which keeps the subscription login, 6k tokens, $0.0003, 3 to 5 seconds of startup with its prefix cached across calls, and the same read $0.004 in 7 seconds. On four replayed stability rounds the agent scout found 5 of 6 archived findings against the baseline's 4 and read 29% fewer characters at 6% less cost and 14% more time; the CLI scout 4 of 6, 38% fewer, 17% less, 39% more; the auditors with the agent scout 3 of 6 at the same cost and twice the time. The reviewers' spend is $840 of $1,215, so a 10% cut is about $85 per 90 chunks. `AGENTS.md` makes a change to the delegation rule lilleman's call. A yes names the shape, agent or CLI, and which reviewers; item 235's figures then measure it. + ### 235. Compare the first 20 chunks whose worker ran under the 200k compaction window with the 20 before them, on review rounds past each pass's first, unfinished verdicts, 🔴, 🟡 and misread findings, dollars and hours per chunk, and file an item where any rose. `docs/decisions.md` → `loop-claude: the worker's claude compacts its context before it fills a 200k window…` expects a saving of about 6% of all spend with no rise in the other figures. Measure from loop-claude's archive as that decision did: rounds past each pass's first and the 🔴, 🟡 and misread counts from the round commit titles, unfinished verdicts from the outcomes files, hours from the worker's first message to its last, and dollars at list prices, cache reads included, from the chunk's `cost-state` entry, which counts the compaction calls that no message's usage records; item 234 puts such dollars into the routing figures. A chunk ran under the window when its first worker started after that decision merged. From 172e72ae070b44221b0afabca5d6bac5e0407be1 Mon Sep 17 00:00:00 2001 From: Lilleman auf Larv Date: Tue, 27 Oct 2026 02:17:30 +0100 Subject: [PATCH 51/55] =?UTF-8?q?Answer=20prose=20round=202:=200=20?= =?UTF-8?q?=F0=9F=94=B4,=2012=20=F0=9F=9F=A1=20(0=20misread);=20pair=20eac?= =?UTF-8?q?h=20option=20with=20its=20trial=20and=20put=20the=20conclusion?= =?UTF-8?q?=20first,=20tell=20the=20two=20read=20measures=20apart,=20move?= =?UTF-8?q?=20the=20security=20workaround=20into=20the=20skill,=20and=20re?= =?UTF-8?q?state=20items=20238=20to=20241?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- docs/decisions.md | 18 +++++++----------- skills/larv-review/SKILL.md | 2 +- todo.md | 20 ++++++++++---------- 3 files changed, 18 insertions(+), 22 deletions(-) diff --git a/docs/decisions.md b/docs/decisions.md index 48bc305c..6cbce885 100644 --- a/docs/decisions.md +++ b/docs/decisions.md @@ -80,12 +80,16 @@ loop-claude hands each worker's claude `CLAUDE_CODE_AUTO_COMPACT_WINDOW=200000` Why 200k. Item 231 asked for the best means to lower what a chunk spends on context, in dollars, then hours, with no loss of quality. Measured from loop-claude's archive, the 90 chunks with messages after the routing figures' reset of 2026-10-21 cost $1,215 at the list prices read on 2026-10-26 (Opus 5.5: $4 per million input tokens, $5 and $8 for 5-minute and 1-hour cache writes, $0.20 for cache reads, $20 for output; no model but Haiku 5.5 charges more above 200k). That is 0.86 of what the chunks' `cost-state` entries sum to, since some chunks' subagent transcripts are not in the archive. Worker main threads cost $375 (31%): 1-hour cache writes $149, cache reads $153, output $74. Subagents cost $840: 5-minute cache writes $379, output $274, cache reads $187, with the principles auditors at $274 over 342 runs, the stability reviewers $179 and general-purpose subagents $192. A worker starts at 41k tokens of context and peaks at a median 167k, one in ten past 358k, the largest at 848k. The worker's messages above 200k were 32% of its messages and 55% of its cost. -The options item 231 named, simulated on those chunks: +What reads cost, and whether a tool cuts them, measured at lilleman's ask after those figures: no tool cut a reviewer's reading without losing a finding, except a scout, whose findings stayed within what the same reviewer finds twice; so none of them ships here, and items 240 and 241 ask lilleman about two trials. Two measures of reading: the characters a thread read, 93M in all, about 27M tokens; and the new input tokens of the messages that took results in, charged to those results, which also count what arrives beside a result, such as the agent's own previous reply. By the second measure tool results caused $620 of the $1,215, and reads (Read, Bash reads, Grep, Glob and git's diff, show and log) $537 of that: the worker's reads $140 (Bash reads $115, Read $12) of its $190 of results, the principles auditors' $133 (Read $109, Grep $22) of $139, the stability reviewers' $97 (Bash reads $79) of $106, general-purpose subagents' $84 of $97, the prose reviewers' $32, the architects' $30 and the product-owner reviewers' $21. By the first measure the worker's reads are about $45. Precision is low everywhere: of the characters a principles auditor read, 13% were in a file its report names; a stability reviewer 8%; a prose reviewer 18%; an architect 11%; the worker 4% in a file it later edited. Reading is mostly to find things and to learn what a project holds. The worker's `sed` ranges are small, median 25 lines, one in ten over 80. Of the worker's read characters, 49% were of a file it had read earlier in the thread: 36% within three messages, paging through it, and 13% later, with the file unchanged, about $6 of the $45; a reviewer's later reads of an unchanged file it had read are 1 to 2% (item 239). + +The trials: four stability rounds and five principles rounds archived on 2026-10-23, each holding 🔴 or 🟡 findings, replayed on the project's rung as `review-replay` replays them, with the reviewer's definition changed through `--agents`; and three worker-like tasks, a search, a rename and an explanation, run on fresh clones at the project's rung. The baseline, the reviewer as it is, found 4 of its own 6 archived findings in each pass, so a variant that finds 4 or 5 of 6 does what the same reviewer does twice. The options item 231 named, each simulated on the 90 chunks and, where lilleman asked, tried: - Compaction of the worker. The saving and the compactions per chunk, by the point it compacts at: 150k saves $75 at 1.0 compactions; 167k to 180k, where a 200k window compacts, $77 to $78 at 0.8 to 0.7; 200k $78 at 0.5; 300k $54 at 0.2. $78 is 21% of the workers' $375 and 6% of all spend. Compaction also caps the 36 re-writes of a whole context after a gap longer than the cache's hour or a change of rung: they cost $61, up to 785k tokens each, and would cost about $34. Compacting subagents at 150k costs more than it saves, since a compaction reads the context once more and writes a summary, and subagents are short. - A fresh context for the review phase, handed 60k tokens of facts, saves $39. A compaction at 170k saves that too, and loop-claude would need a second session per chunk. -- Read with an offset and a limit, or Grep, in place of `cat`, `sed` and `head`. The worker's tool results were 13.2M characters, 65% of them Bash reads, and 13% of those characters came from whole files; the rest were ranges. A token a worker reads costs about $8 per million to write to the 1-hour cache and $0.20 per million at each later turn, so all the worker's reads cost about $45 and the whole-file ones about $6. A rule would change the tool, not how much is read. -- Code-intelligence tooling: the `LSP` tool, with a language server per language on PATH, replaces a grep and the reads of candidate files with one lookup. Its ceiling is the same $45, and each machine would need a server per language (goal 2). Not tried, and not worth an item while the worker's reads stay under 4% of spend. +- Read with an offset and a limit, or Grep, in place of `cat`, `sed` and `head`. Steering the tool would not change how much is read: the worker's `sed` ranges are small already, and only 13% of its Bash-read characters came from whole files. A rule on how much to read did change it: under "never read more than 80 lines of a file at once, nor take a tool output over 3,000 characters into your context", the three worker tasks read 45% to 60% fewer characters at the same or lower cost, every task done as well, and the rename was the one run of four that also kept the import names sorted; item 240 asks whether workers get the rule. A stability reviewer under the same rule with an `outline` script on PATH, which prints a file's symbols with their line ranges, read 4% less and found 2 of 6 findings, and the workers never ran the script. +- Code-intelligence tooling: the `LSP` tool, through a pyright plugin built from the marketplace manifest with `pyright-langserver` on PATH, answers a file's symbols, a definition or the references in a few hundred characters. Under a rule telling them to use it, the stability reviewers and the workers never called it; the auditors did, read as much or more, and missed the one 🔴, 0 of 1 against the baseline's 1 of 1. Each machine would also need a server per language (goal 2). Not worth an item. +- A cap on tool results. Claude Code caps a Bash result at about 30k characters already. A PostToolUse hook capping it at 12k, which `updatedToolOutput` allows, left the stability reviewers 3 of 6 findings, two lost in one round. Read results, 59.9M characters in subagents' threads with 58% of their characters in results over 12k, are out of such a hook's reach. Not worth an item. +- A scout: Haiku 5.5 reading raw content, whole files or long output, and returning facts as path:line and the ranges worth reading, so the agent's own context holds the summary and the chosen lines. In session, as an agent under `agents/`, its first request writes 37k tokens, $0.005, and a read of a 38KB file costs $0.008 in 8 seconds. As a slim headless `claude -p` with its own system prompt, no setting sources and no dynamic sections, which keeps the subscription login, it starts at 6k tokens and $0.0003 in 3 to 5 seconds, its prefix cached across calls, and the same read costs $0.004 in 7 seconds; a direct API call and `claude --bare` need an API key, so they are out. Stability reviewers with the agent scout found 5 of 6 findings and read 29% fewer characters at 6% less cost and 14% more time; with the CLI scout 4 of 6, 38% fewer, 17% less and 39% more; the auditors with the agent scout 3 of 6, the 🔴 among the lost, at the same cost and twice the time. Workers offered the scout never called it. Item 241 asks whether reviewers get one; `AGENTS.md` makes a change to the delegation rule lilleman's call. - What a reviewer reads: the auditors read the project whole by design. Of their 🔴 and 🟡 findings since the reset, 47% named a file the chunk edited and 51% another file, so reading only the change would drop half of them; item 236 asks lilleman about that scope, and item 233 has one auditor read the project once per round. - The base context: every thread starts with `~/.claude/CLAUDE.md` (19k characters), `~/.claude/AGENTS.md` (11k, this repo's decisions, which Claude Code loads as user instructions into every project's sessions; item 52), the project's `AGENTS.md`, and, for the worker and general-purpose subagents, the skill listing (18k) and the agent listing (12k). Subagents' first messages wrote $97 of it. Trimming the listings would save about $20, 2%, and is not worth an item: `disableBundledSkills` would also drop `/security-review`, the security pass of record. @@ -93,14 +97,6 @@ Quality. 19 chunks compacted between 2026-10-10 and 2026-10-22, at the compactio Hours. A chunk ran a median 0.7 hours from its first message to its last, one in ten past 12 hours, mostly waiting for the human or a usage limit. No option here changes that: a compaction takes 51 to 83 seconds, under a minute per chunk at 0.7 each, and a smaller context saves seconds per turn at most. The hours lever is item 232, since waiting on subagents took 66% of a worker's active time. -Reads and tools, measured the same day at lilleman's ask, on the same 90 chunks: - -- What reads cost. The messages that took in tool results carried $537 of the $1,215, 44%: the worker's $190 (Bash reads $115, Read $12), the principles auditors' $139 (Read $109, Grep $22), the stability reviewers' $106 (Bash reads $79), general-purpose subagents' $97, the prose reviewers' $34, the architects' $31 and the product-owner reviewers' $23. These figures charge a message's new input tokens to the results it took in, so they include what arrives beside a result, such as the agent's own previous reply; the 93M characters read alone are about 27M tokens. -- Precision. Of the characters a principles auditor read, 13% were in a file its report names; a stability reviewer 8%; the worker 4% in a file it later edited; a prose reviewer 18%; an architect 11%. Reading is mostly to find things and to learn what a project holds, as lilleman read it. The worker's `sed` ranges are small, median 25 lines, one in ten over 80. Of the worker's read characters, 49% were of a file it had read earlier in the thread: 36% within three messages, paging through it, and 13% later and unchanged, about $6 of the $45 its reads cost; reviewers 1 to 2% (item 239). -- Tool results. Claude Code caps a Bash result at about 30k characters. Subagents' Read results, 59.9M characters, have 58% of their characters in results over 12k. -- Trials on this repo. Four stability rounds and five principles rounds archived on 2026-10-23, each holding 🔴 or 🟡 findings, replayed on the project's rung as `review-replay` replays them, with the reviewer's definition changed through `--agents`; and three worker-like tasks, a search, a rename and an explanation, run on fresh clones at the project's rung. The baseline reviewers found 4 of their own 6 archived findings in each pass, the spread a sample this small sits in. The LSP tool, through a pyright plugin built from the marketplace manifest with `pyright-langserver` on PATH, answers a file's symbols, a definition or the references in a few hundred characters; the stability reviewers and the workers never called it under a rule telling them to, and the auditors who did read as much or more and missed the one 🔴 (0 of 1 against the baseline's 1 of 1). An `outline` script printing a file's symbols with line ranges: never called by workers; stability reviewers under its rule found 2 of 6 findings. A PostToolUse hook capping a Bash result at 12k characters: 3 of 6, two lost in one round. A scout, Haiku 5.5 reading raw content and returning facts and line ranges: as an in-session agent its first request writes 37k tokens, $0.005, and a read of a 38KB file costs $0.008 in 8 seconds; as a slim headless `claude -p` with its own system prompt, no setting sources and no dynamic sections, 6k tokens, $0.0003 and 3 to 5 seconds of startup, its prefix cached across calls, and the same read $0.004 in 7 seconds. Stability reviewers with the agent scout found 5 of 6 findings and read 29% fewer characters at 6% less cost and 14% more time; with the CLI scout 4 of 6, 38% fewer characters, 17% less cost and 39% more time; the auditors with the agent scout 3 of 6 at the same cost and twice the time. Workers offered the scout never called it, but its reading rule alone, never read more than 80 lines of a file yourself, cut their reading 45% to 60% at the same or lower cost, with all three tasks done as well. -- What follows. On this sample no tool cuts a reviewer's reading without losing a finding, except the scout, whose saving sits within the baseline's own spread; so none of them ships here. lilleman decides two trials: a reading rule for workers (item 240) and a scout for reviewers (item 241). A direct API call and `claude --bare` are out, since both need an API key where lilleman's login is a subscription. - Valid while cache reads cost a twentieth of input and Claude Code's compaction keeps the worker's task. ## 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 diff --git a/skills/larv-review/SKILL.md b/skills/larv-review/SKILL.md index efb530f9..d15ba69a 100644 --- a/skills/larv-review/SKILL.md +++ b/skills/larv-review/SKILL.md @@ -136,7 +136,7 @@ The comprehension check records how hard the project is for its contributor to r ### Security -`/security-review` over the branch diff is the pass of record, except where the full scan runs on the same change and replaces it. Where the full scan fires but does not run — skipped on a precedent, declined at its cost prompt, or unavailable — `/security-review` runs. Launch a general-purpose subagent that invokes it through the Skill tool, edits nothing, and replies with the skill's report, or that the skill is unavailable. Invoked in your own context, the skill ends your turn on that report. Open its prompt, and that of any subagent that runs the full scan, with `You are the security pass for this chunk.`: rule-hook reads that sentence as a security launch. +`/security-review` over the branch diff is the pass of record, except where the full scan runs on the same change and replaces it. Where the full scan fires but does not run — skipped on a precedent, declined at its cost prompt, or unavailable — `/security-review` runs. Launch a general-purpose subagent that invokes it through the Skill tool, edits nothing, and replies with the skill's report, or that the skill is unavailable. The skill runs in the session's working directory, so where the chunk's worktree is another directory, run `claude -p /security-review` in the worktree on the project's rung instead (`todo.md` item 238 fixes the launch). Invoked in your own context, the skill ends your turn on that report. Open its prompt, and that of any subagent that runs the full scan, with `You are the security pass for this chunk.`: rule-hook reads that sentence as a security launch. A verified HIGH inside this chunk's blast radius is fixed here, outside it on its own branch and PR with this chunk waiting behind it. Say which. diff --git a/todo.md b/todo.md index 77cb605f..a8cee2d5 100644 --- a/todo.md +++ b/todo.md @@ -16,11 +16,11 @@ | 238 | 0.4.0 | | defect | **Run the security pass's skill in the chunk's worktree, so it scans the branch's diff: invoked from a subagent, it runs in the session's working directory, the main checkout, and scans nothing.** | 2 | 2 | 3 | 5 | 3 | 1.1 by 5 | 5.3 | | 233 | 0.4.0 | | | **Run one principles-auditor per round that checks the goals and every principles file that applies, in place of one auditor for each, so the principles pass reads the project once per round.** | 3 | 2 | 3 | 6 | 3 | 1.4 by 3, 1.5 by 2 | 4.9 | | 234 | 0.4.0 | | | **Report the routing figures in dollars, cache reads included, from the cost each archived run records.** | 2 | 2 | 2 | 4 | 3 | 1.4 by 3 | 3.0 | -| 239 | 0.4.0 | | owner | **Block a Read, `cat`, `sed` or `head` of a file range the session already read while the file is unchanged, with a note that the content is in context, and let it through after a compaction or a change to the file.** | 3 | 2 | 3 | 6 | 4 | 1.4 by 3 | 2.0 | +| 239 | 0.4.0 | | owner | **Block a Read, `cat`, `sed` or `head` of a file range already in the session's context, with a note saying so, and let it through once a compaction dropped the range or the file changed.** | 3 | 2 | 3 | 6 | 4 | 1.4 by 3 | 2.0 | | 236 | 0.5.0 | | question | **Answer whether the principles audit keeps reading the whole project, or reads only the files the chunk changed and their callers, now that half of its 🔴 and 🟡 findings name a file the chunk did not edit.** | 1 | 1 | 1 | 1 | 1 | 1.4 by 4 | 6.4 | -| 240 | 0.5.0 | | question | **Answer whether workers get a reading rule in `CLAUDE.md`, never reading more than 80 lines of a file at once, which cut three worker tasks' reading 45% to 60% at the same quality.** | 1 | 2 | 3 | 4 | 1 | 1.4 by 3 | 4.8 | +| 240 | 0.5.0 | | question | **Answer whether workers get a reading rule in `CLAUDE.md`: never read more than 80 lines of a file at once, nor take a tool output over 3,000 characters into your context.** | 1 | 2 | 3 | 4 | 1 | 1.4 by 3 | 4.8 | | 226 | 0.5.0 | | question | **Answer whether rule-hook's `run-heavy` rule should also catch a mutation run or docker build behind `uv run`, `poetry run`, `python3 -m`, `sudo`, `docker image build` and `docker compose up --build`, or narrow the `machine load:` decision's wording.** | 2 | 2 | 3 | 5 | 3 | 1.2 by 2, 1.5 by 2 | 4.0 | -| 241 | 0.5.0 | | question | **Answer whether reviewers hand a read over 80 lines to a Haiku scout, which cut a stability reviewer's reading 29% to 38% and its cost 6% to 17% on four replayed rounds, at 14% to 39% more time and findings within the baseline's own spread.** | 2 | 2 | 3 | 5 | 3 | 1.4 by 3 | 3.0 | +| 241 | 0.5.0 | | question | **Answer whether reviewers hand a read over 80 lines to a Haiku scout, which on four replayed stability rounds cut the reviewer's reading by a third and its cost by a tenth, slowed it, and found as many findings as the reviewer finds on its own.** | 2 | 2 | 3 | 5 | 3 | 1.4 by 3 | 3.0 | | 235 | 0.5.0 | | | **Compare the first 20 chunks whose worker ran under the 200k compaction window with the 20 before them, on review rounds past each pass's first, unfinished verdicts, 🔴, 🟡 and misread findings, dollars and hours per chunk, and file an item where any rose.** | 1 | 2 | 1 | 2 | 2 | 1.1 by 2, 1.4 by 3 | 6.8 | | 59 | 0.5.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.5.0 | | | **Refuse a `/security-review` or `/claude-security` Skill call below the project's rung, as rule-hook refuses such an Agent call.** | 3 | 2 | 3 | 6 | 2 | 1.1 by 4 | 5.6 | @@ -88,7 +88,7 @@ Since 2026-10-21, all 1,372 Agent calls in workers' transcripts were one per mes ### 238. Run the security pass's skill in the chunk's worktree, so it scans the branch's diff: invoked from a subagent, it runs in the session's working directory, the main checkout, and scans nothing. -Found while reviewing PR #376. larv-review §3 → "Security" launches a general-purpose subagent that invokes `/security-review` through the Skill tool. The skill runs its git commands in the session's working directory, the checkout root, where the branch's diff is empty, and the subagent then reads the worktree's diff itself, which the skill's own text forbids as a substitute. The archived security subagents of items 198 and 223 and of PR #376 all report it. It sits in 0.4.0 so the release's remaining chunks get a scan that reads their diff; until it is fixed, run `claude -p /security-review` with the worktree as its working directory, on the project's rung, as PR #376 did. A fix may run the skill as a process in the worktree from larv-review, or have the worker enter the worktree with Claude Code's `EnterWorktree` tool so every subagent runs there. +Found while reviewing PR #376. larv-review §3 → "Security" launches a general-purpose subagent that invokes `/security-review` through the Skill tool. The skill runs its git commands in the session's working directory, the checkout root, where the branch's diff is empty, and the subagent then reads the worktree's diff itself, which the skill's own text forbids as a substitute. The archived security subagents of items 198 and 223 and of PR #376 all report it. It sits in 0.4.0 so the release's remaining chunks get a scan that reads their diff; until then larv-review §3 → "Security" says to run the skill in the worktree. A fix may run the skill as a process in the worktree from larv-review, or have the worker enter the worktree with Claude Code's `EnterWorktree` tool so every subagent runs there. ### 233. Run one principles-auditor per round that checks the goals and every principles file that applies, in place of one auditor for each, so the principles pass reads the project once per round. @@ -98,25 +98,25 @@ Since 2026-10-21, 342 principles-auditor runs, 3.8 per chunk, cost $274 at list The routing figures count input, cache-written and output tokens, and leave out cache reads, which were 28% of the cost since 2026-10-21, $340 of $1,215 at list prices. So their tables rank the principles auditor above the worker, while in dollars the worker cost 1.4 times as much, $375 against $274. Each archived worker transcript ends with a `cost-state` entry holding `totalCostUSD` and each model's cost, and each message's usage attributes the cost to a subagent type. The judge's runs record no cost in the archive: count them too, or say why not. The change touches `bin/routing_figures/measure.py`, which the comprehension seats found hard (item 139): make the places it touches easier to read. -### 239. Block a Read, `cat`, `sed` or `head` of a file range the session already read while the file is unchanged, with a note that the content is in context, and let it through after a compaction or a change to the file. +### 239. Block a Read, `cat`, `sed` or `head` of a file range already in the session's context, with a note saying so, and let it through once a compaction dropped the range or the file changed. -lilleman's call, 2026-10-27, filed from PR #376's measurement of loop-claude's archive since 2026-10-21: a read of a file the agent read earlier in the thread, more than three messages before and without editing it in between, is 13% of the worker's reading, about $6 of the $45 its reads cost, and 1 to 2% of a reviewer's. A hook on `Read` and on the Bash reads `cat`, `sed` and `head` blocks such a read with a short note that the content is already in context and unchanged. It lets the read through after a compaction, when the content has left the context, or when the file changed since the read; a PreToolUse hook gets the session's `transcript_path`, which holds the earlier reads and each `compact_boundary`, so it needs no state of its own. If scouts ship (item 231's decision records the trial), the same idea applies to scout answers, cached by file and content hash: a scout only cheapens these re-reads and doesn't remove them, which is why this is a separate item. +lilleman's call, 2026-10-27, filed from PR #376's measurement of loop-claude's archive since 2026-10-21: a read of a file the agent read earlier in the thread, more than three messages before and without editing it in between, is 13% of the worker's reading, about $6 of the $45 its reads cost, and 1 to 2% of a reviewer's. How many of those repeat a range exactly is unmeasured, so the figures are a ceiling. A hook on `Read` and on the Bash reads `cat`, `sed` and `head` blocks such a read with a short note that the content is already in context and unchanged. It lets the read through after a compaction, when the content has left the context, or when the file changed since the read. A PreToolUse hook gets a `transcript_path`, which holds the earlier reads and each `compact_boundary`, so it may need no state of its own; check whether a hook inside a subagent gets the subagent's own transcript. A scout only cheapens these re-reads and doesn't remove them, which is why this is a separate item. If scouts ship (`docs/decisions.md` → `loop-claude: the worker's claude compacts its context before it fills a 200k window…` records the trial, and item 241 asks), the same idea applies to scout answers, cached by file and content hash. ### 236. Answer whether the principles audit keeps reading the whole project, or reads only the files the chunk changed and their callers, now that half of its 🔴 and 🟡 findings name a file the chunk did not edit. Since 2026-10-21, 342 principles-auditor runs cost $274 at list prices, 23% of all spend, and 176 of their 🔴 and 🟡 findings named a file: 83 a file the chunk edited, 90 another. `docs/decisions.md` → `review: the principles audit runs on every chunk…` holds the whole-project audit valid while its findings are drift a chunk would otherwise merge, and calls a repeat a question on the audit's scope for the human. Reading only the changed files and their callers would cut most of the auditors' $129 of cache writes and drop the findings elsewhere, unless the same findings come back chunk after chunk: read a sample of the 90 before answering. Item 233 merges the auditors either way. -### 240. Answer whether workers get a reading rule in `CLAUDE.md`, never reading more than 80 lines of a file at once, which cut three worker tasks' reading 45% to 60% at the same quality. +### 240. Answer whether workers get a reading rule in `CLAUDE.md`: never read more than 80 lines of a file at once, nor take a tool output over 3,000 characters into your context. -lilleman's question, from PR #376's trials (`docs/decisions.md` → `loop-claude: the worker's claude compacts its context before it fills a 200k window…`, "Reads and tools"). Three worker-like tasks on this repo, a search, a rename and an explanation, run under the rule "never read more than 80 lines of a file yourself, and never take a tool output you expect to exceed 3,000 characters into your context" read 45% to 60% fewer characters at the same or lower cost and answered as well; the rename under it was the only one that also kept the import names sorted. Only 4% of what a worker reads is in a file it later edits. The rule is one line in `CLAUDE.md` that every session loads, so its effect on real chunks, misread findings above all, is unmeasured: a yes trials it and item 235's figures over the next 20 chunks measure it. +lilleman's question, from PR #376's trials, recorded in `docs/decisions.md` → `loop-claude: the worker's claude compacts its context before it fills a 200k window…`. Three worker-like tasks on this repo, a search, a rename and an explanation, each ran once as workers run today and once under the rule. Under the rule each task read 45% to 60% fewer characters, cost the same or less, and came out as well; of the four runs of the rename, the one under the rule was the only one that also kept the import names sorted. Only 4% of what a worker reads is in a file it later edits. Three tasks say little about real chunks, where a worker that reads less may misread more, and the rule is one line in `CLAUDE.md` that every session loads. A yes ships the line and measures the 20 chunks after it against the 20 before, as item 235 measures the compaction window: review rounds, unfinished verdicts, 🔴, 🟡 and misread findings, dollars and hours per chunk. ### 226. Answer whether rule-hook's `run-heavy` rule should also catch a mutation run or docker build behind `uv run`, `poetry run`, `python3 -m`, `sudo`, `docker image build` and `docker compose up --build`, or narrow the `machine load:` decision's wording. Found by review of PR #370. Today `uv run mutmut run`, `poetry run mutmut run`, `python3 -m mutmut run`, `sudo docker build .`, `docker image build .` and `docker compose up --build` pass the rule, which `docs/decisions.md` → `machine load: …` and `RULES["run-heavy"]` describe as blocking docker builds and mutation runs. The rule's own text says a gate script isn't checked since no program can tell it from a light one, so the human decides where the line sits. Say what the rule's "checked" text promises either way. Where the answer widens the rule, the change touches `heavy` in `bin/rule_hook/heavy_command.py`, which the comprehension seats found hard: make it easier to read. -### 241. Answer whether reviewers hand a read over 80 lines to a Haiku scout, which cut a stability reviewer's reading 29% to 38% and its cost 6% to 17% on four replayed rounds, at 14% to 39% more time and findings within the baseline's own spread. +### 241. Answer whether reviewers hand a read over 80 lines to a Haiku scout, which on four replayed stability rounds cut the reviewer's reading by a third and its cost by a tenth, slowed it, and found as many findings as the reviewer finds on its own. -lilleman's question, from PR #376's trials (`docs/decisions.md` → `loop-claude: the worker's claude compacts its context before it fills a 200k window…`, "Reads and tools"). A scout is Haiku 5.5 reading raw content, whole files or long output, and returning facts as path:line and the ranges worth reading. In session, as an agent under `agents/`, its first request writes 37k tokens, $0.005, and a read of a 38KB file costs $0.008 in 8 seconds; as a slim headless `claude -p --model claude-haiku-5-5 --system-prompt … --tools "" --setting-sources "" --no-session-persistence`, which keeps the subscription login, 6k tokens, $0.0003, 3 to 5 seconds of startup with its prefix cached across calls, and the same read $0.004 in 7 seconds. On four replayed stability rounds the agent scout found 5 of 6 archived findings against the baseline's 4 and read 29% fewer characters at 6% less cost and 14% more time; the CLI scout 4 of 6, 38% fewer, 17% less, 39% more; the auditors with the agent scout 3 of 6 at the same cost and twice the time. The reviewers' spend is $840 of $1,215, so a 10% cut is about $85 per 90 chunks. `AGENTS.md` makes a change to the delegation rule lilleman's call. A yes names the shape, agent or CLI, and which reviewers; item 235's figures then measure it. +lilleman's question, from PR #376's trials, recorded with the scout's shapes and costs in `docs/decisions.md` → `loop-claude: the worker's claude compacts its context before it fills a 200k window…`. A scout is Haiku 5.5 reading raw content, whole files or long output, and returning facts as path:line and the ranges worth reading; in session it is an agent under `agents/`, and as a slim headless `claude -p` on the subscription login it starts at 6k tokens in 3 to 5 seconds. On four replayed stability rounds the agent scout found 5 of 6 archived findings against the baseline's 4 and read 29% fewer characters at 6% less cost and 14% more time; the CLI scout 4 of 6, 38% fewer, 17% less and 39% more; the auditors with the agent scout 3 of 6, the 🔴 among the lost, at the same cost and twice the time. The reviewers under `agents/` spent $646 of the $1,215 since 2026-10-21, so a tenth off is about $65 per 90 chunks. `AGENTS.md` makes a change to the delegation rule lilleman's call. A yes names the shape, agent or CLI, and which reviewers, and measures the 20 chunks after it against the 20 before, as item 235 measures the compaction window. ### 235. Compare the first 20 chunks whose worker ran under the 200k compaction window with the 20 before them, on review rounds past each pass's first, unfinished verdicts, 🔴, 🟡 and misread findings, dollars and hours per chunk, and file an item where any rose. From b46d5374ff95e19bc2e33c593416bd7f6e2e093d Mon Sep 17 00:00:00 2001 From: Lilleman auf Larv Date: Tue, 27 Oct 2026 09:08:18 +0100 Subject: [PATCH 52/55] Record lilleman's answers: merge the window, trial the reading rule as item 240, no scout for reviewers, and the audit keeps reading the project whole --- docs/decisions.md | 12 +++++++----- todo.md | 20 +++++--------------- 2 files changed, 12 insertions(+), 20 deletions(-) diff --git a/docs/decisions.md b/docs/decisions.md index 6cbce885..28e1cada 100644 --- a/docs/decisions.md +++ b/docs/decisions.md @@ -74,23 +74,23 @@ The cap is 5, `bin/todo_table.py`'s `BUNDLE_MAX_R`, from the same chunks: by the ## loop-claude: the worker's claude compacts its context before it fills a 200k window, at about 170k tokens, and `CLAUDE.md` → "Compact instructions" says what the summary keeps -2026-10-27, lilleman, through todo item 231; claude measured and implemented. Serves goal 1.4; its counter-signal, review rounds and unfinished verdicts per chunk, is the check. +2026-10-27, lilleman's yes, typed that day, to the evaluation claude made through todo item 231. Serves goal 1.4; its counter-signal, review rounds and unfinished verdicts per chunk, is the check. loop-claude hands each worker's claude `CLAUDE_CODE_AUTO_COMPACT_WINDOW=200000` (`bin/loop_claude/cycle/worker.py`), and the session /talk opens gets it too. Claude Code compacts before a window fills: a 1M window at about 967k tokens, and in a probe on 2026-10-27 a 100k window at 65k and 80k, so a 200k window compacts at about 170k. The window is not set in `settings.json`, since the archive measured loop-claude's workers and interactive sessions are lilleman's. Subagents inherit the variable, which reaches every process of the session: 68 of the 994 subagent runs since 2026-10-21, 7%, passed 170k, 24 of them principles auditors, so about one in fourteen compacts once. Compacting subagents by choice would cost more than it saves, as below, but the variable cannot leave them out, and `CLAUDE.md` → "Compact instructions" has a reviewer keep the findings it has drafted. That section shapes the summary: in another probe that day, a session whose CLAUDE.md asked for its summary to end with a secret word got a summary ending with that word. Path-scoped rules leave the context at a compaction and return at the next matching read, and rule-hook holds each review launch to its rung whatever the summary keeps. `CLAUDE_CODE_DISABLE_1M_CONTEXT=1`, handed the same way, would compact at the same point but also cap the window at 200k, so a run that Claude Code stops compacting, as it does when one tool result refills the context each time, would hit the limit instead of going on. Why 200k. Item 231 asked for the best means to lower what a chunk spends on context, in dollars, then hours, with no loss of quality. Measured from loop-claude's archive, the 90 chunks with messages after the routing figures' reset of 2026-10-21 cost $1,215 at the list prices read on 2026-10-26 (Opus 5.5: $4 per million input tokens, $5 and $8 for 5-minute and 1-hour cache writes, $0.20 for cache reads, $20 for output; no model but Haiku 5.5 charges more above 200k). That is 0.86 of what the chunks' `cost-state` entries sum to, since some chunks' subagent transcripts are not in the archive. Worker main threads cost $375 (31%): 1-hour cache writes $149, cache reads $153, output $74. Subagents cost $840: 5-minute cache writes $379, output $274, cache reads $187, with the principles auditors at $274 over 342 runs, the stability reviewers $179 and general-purpose subagents $192. A worker starts at 41k tokens of context and peaks at a median 167k, one in ten past 358k, the largest at 848k. The worker's messages above 200k were 32% of its messages and 55% of its cost. -What reads cost, and whether a tool cuts them, measured at lilleman's ask after those figures: no tool cut a reviewer's reading without losing a finding, except a scout, whose findings stayed within what the same reviewer finds twice; so none of them ships here, and items 240 and 241 ask lilleman about two trials. Two measures of reading: the characters a thread read, 93M in all, about 27M tokens; and the new input tokens of the messages that took results in, charged to those results, which also count what arrives beside a result, such as the agent's own previous reply. By the second measure tool results caused $620 of the $1,215, and reads (Read, Bash reads, Grep, Glob and git's diff, show and log) $537 of that: the worker's reads $140 (Bash reads $115, Read $12) of its $190 of results, the principles auditors' $133 (Read $109, Grep $22) of $139, the stability reviewers' $97 (Bash reads $79) of $106, general-purpose subagents' $84 of $97, the prose reviewers' $32, the architects' $30 and the product-owner reviewers' $21. By the first measure the worker's reads are about $45. Precision is low everywhere: of the characters a principles auditor read, 13% were in a file its report names; a stability reviewer 8%; a prose reviewer 18%; an architect 11%; the worker 4% in a file it later edited. Reading is mostly to find things and to learn what a project holds. The worker's `sed` ranges are small, median 25 lines, one in ten over 80. Of the worker's read characters, 49% were of a file it had read earlier in the thread: 36% within three messages, paging through it, and 13% later, with the file unchanged, about $6 of the $45; a reviewer's later reads of an unchanged file it had read are 1 to 2% (item 239). +What reads cost, and whether a tool cuts them, measured at lilleman's ask after those figures: no tool cut a reviewer's reading without losing a finding, except a scout, whose findings stayed within what the same reviewer finds twice; so none of them ships here. lilleman chose on 2026-10-27: workers trial a reading rule (item 240), and reviewers get no scout. Two measures of reading: the characters a thread read, 93M in all, about 27M tokens; and the new input tokens of the messages that took results in, charged to those results, which also count what arrives beside a result, such as the agent's own previous reply. By the second measure tool results caused $620 of the $1,215, and reads (Read, Bash reads, Grep, Glob and git's diff, show and log) $537 of that: the worker's reads $140 (Bash reads $115, Read $12) of its $190 of results, the principles auditors' $133 (Read $109, Grep $22) of $139, the stability reviewers' $97 (Bash reads $79) of $106, general-purpose subagents' $84 of $97, the prose reviewers' $32, the architects' $30 and the product-owner reviewers' $21. By the first measure the worker's reads are about $45. Precision is low everywhere: of the characters a principles auditor read, 13% were in a file its report names; a stability reviewer 8%; a prose reviewer 18%; an architect 11%; the worker 4% in a file it later edited. Reading is mostly to find things and to learn what a project holds. The worker's `sed` ranges are small, median 25 lines, one in ten over 80. Of the worker's read characters, 49% were of a file it had read earlier in the thread: 36% within three messages, paging through it, and 13% later, with the file unchanged, about $6 of the $45; a reviewer's later reads of an unchanged file it had read are 1 to 2% (item 239). The trials: four stability rounds and five principles rounds archived on 2026-10-23, each holding 🔴 or 🟡 findings, replayed on the project's rung as `review-replay` replays them, with the reviewer's definition changed through `--agents`; and three worker-like tasks, a search, a rename and an explanation, run on fresh clones at the project's rung. The baseline, the reviewer as it is, found 4 of its own 6 archived findings in each pass, so a variant that finds 4 or 5 of 6 does what the same reviewer does twice. The options item 231 named, each simulated on the 90 chunks and, where lilleman asked, tried: - Compaction of the worker. The saving and the compactions per chunk, by the point it compacts at: 150k saves $75 at 1.0 compactions; 167k to 180k, where a 200k window compacts, $77 to $78 at 0.8 to 0.7; 200k $78 at 0.5; 300k $54 at 0.2. $78 is 21% of the workers' $375 and 6% of all spend. Compaction also caps the 36 re-writes of a whole context after a gap longer than the cache's hour or a change of rung: they cost $61, up to 785k tokens each, and would cost about $34. Compacting subagents at 150k costs more than it saves, since a compaction reads the context once more and writes a summary, and subagents are short. - A fresh context for the review phase, handed 60k tokens of facts, saves $39. A compaction at 170k saves that too, and loop-claude would need a second session per chunk. -- Read with an offset and a limit, or Grep, in place of `cat`, `sed` and `head`. Steering the tool would not change how much is read: the worker's `sed` ranges are small already, and only 13% of its Bash-read characters came from whole files. A rule on how much to read did change it: under "never read more than 80 lines of a file at once, nor take a tool output over 3,000 characters into your context", the three worker tasks read 45% to 60% fewer characters at the same or lower cost, every task done as well, and the rename was the one run of four that also kept the import names sorted; item 240 asks whether workers get the rule. A stability reviewer under the same rule with an `outline` script on PATH, which prints a file's symbols with their line ranges, read 4% less and found 2 of 6 findings, and the workers never ran the script. +- Read with an offset and a limit, or Grep, in place of `cat`, `sed` and `head`. Steering the tool would not change how much is read: the worker's `sed` ranges are small already, and only 13% of its Bash-read characters came from whole files. A rule on how much to read did change it: under "never read more than 80 lines of a file at once, nor take a tool output over 3,000 characters into your context", the three worker tasks read 45% to 60% fewer characters at the same or lower cost, every task done as well, and the rename was the one run of four that also kept the import names sorted; item 240 trials the rule on workers. A stability reviewer under the same rule with an `outline` script on PATH, which prints a file's symbols with their line ranges, read 4% less and found 2 of 6 findings, and the workers never ran the script. - Code-intelligence tooling: the `LSP` tool, through a pyright plugin built from the marketplace manifest with `pyright-langserver` on PATH, answers a file's symbols, a definition or the references in a few hundred characters. Under a rule telling them to use it, the stability reviewers and the workers never called it; the auditors did, read as much or more, and missed the one 🔴, 0 of 1 against the baseline's 1 of 1. Each machine would also need a server per language (goal 2). Not worth an item. - A cap on tool results. Claude Code caps a Bash result at about 30k characters already. A PostToolUse hook capping it at 12k, which `updatedToolOutput` allows, left the stability reviewers 3 of 6 findings, two lost in one round. Read results, 59.9M characters in subagents' threads with 58% of their characters in results over 12k, are out of such a hook's reach. Not worth an item. -- A scout: Haiku 5.5 reading raw content, whole files or long output, and returning facts as path:line and the ranges worth reading, so the agent's own context holds the summary and the chosen lines. In session, as an agent under `agents/`, its first request writes 37k tokens, $0.005, and a read of a 38KB file costs $0.008 in 8 seconds. As a slim headless `claude -p` with its own system prompt, no setting sources and no dynamic sections, which keeps the subscription login, it starts at 6k tokens and $0.0003 in 3 to 5 seconds, its prefix cached across calls, and the same read costs $0.004 in 7 seconds; a direct API call and `claude --bare` need an API key, so they are out. Stability reviewers with the agent scout found 5 of 6 findings and read 29% fewer characters at 6% less cost and 14% more time; with the CLI scout 4 of 6, 38% fewer, 17% less and 39% more; the auditors with the agent scout 3 of 6, the 🔴 among the lost, at the same cost and twice the time. Workers offered the scout never called it. Item 241 asks whether reviewers get one; `AGENTS.md` makes a change to the delegation rule lilleman's call. -- What a reviewer reads: the auditors read the project whole by design. Of their 🔴 and 🟡 findings since the reset, 47% named a file the chunk edited and 51% another file, so reading only the change would drop half of them; item 236 asks lilleman about that scope, and item 233 has one auditor read the project once per round. +- A scout: Haiku 5.5 reading raw content, whole files or long output, and returning facts as path:line and the ranges worth reading, so the agent's own context holds the summary and the chosen lines. In session, as an agent under `agents/`, its first request writes 37k tokens, $0.005, and a read of a 38KB file costs $0.008 in 8 seconds. As a slim headless `claude -p` with its own system prompt, no setting sources and no dynamic sections, which keeps the subscription login, it starts at 6k tokens and $0.0003 in 3 to 5 seconds, its prefix cached across calls, and the same read costs $0.004 in 7 seconds; a direct API call and `claude --bare` need an API key, so they are out. Stability reviewers with the agent scout found 5 of 6 findings and read 29% fewer characters at 6% less cost and 14% more time; with the CLI scout 4 of 6, 38% fewer, 17% less and 39% more; the auditors with the agent scout 3 of 6, the 🔴 among the lost, at the same cost and twice the time. Workers offered the scout never called it. On 2026-10-27 lilleman said no to a scout for reviewers: the saving sits within the reviewer's own spread, the auditors lost the 🔴, and every round ran slower. The delegation rule stands as `routing: a worker delegates a task only where it needs just the task's conclusion…` records. +- What a reviewer reads: the auditors read the project whole by design. Of their 🔴 and 🟡 findings since the reset, 47% named a file the chunk edited and 51% another file, so reading only the change would drop half of them; on 2026-10-27 lilleman kept the whole-project reading (`review: the principles audit runs on every chunk that changes code, config or tests, and on no other chunk`), and item 233 has one auditor read the project once per round. - The base context: every thread starts with `~/.claude/CLAUDE.md` (19k characters), `~/.claude/AGENTS.md` (11k, this repo's decisions, which Claude Code loads as user instructions into every project's sessions; item 52), the project's `AGENTS.md`, and, for the worker and general-purpose subagents, the skill listing (18k) and the agent listing (12k). Subagents' first messages wrote $97 of it. Trimming the listings would save about $20, 2%, and is not worth an item: `disableBundledSkills` would also drop `/security-review`, the security pass of record. Quality. 19 chunks compacted between 2026-10-10 and 2026-10-22, at the compaction points Claude Code set then, 214k to 972k tokens. Per 100 worker messages they took a median 3.6 review rounds past each pass's first against 4.0 for the 68 uncompacted chunks of 100 messages or more, and 13.9 🔴 and 🟡 findings against 16.6. 4 of 19 had an unfinished verdict against 3 of 68, each 8 to 10 hours after the compaction and followed by a finished verdict within minutes; in those four verdicts the judge quoted the worker's own passages and the human's typed answers, never a summary. One cause was possible and is closed here: Claude Code writes the summary as a user entry, which `bin/claude_code/entries.py` read as the human's words, so the judge would see a `[human]` line of thousands of words and `/talk` would count it as typed; it now reads as Claude Code's. Whether compaction raises unfinished verdicts stays open until item 235 measures it. Two summaries read whole kept the chunk's intent, files, errors and next step in 12k to 20k characters, and the worker resumed without re-reading. @@ -227,6 +227,8 @@ The base is the last measured commit: the default branch's newest merged change 2026-10-16, lilleman, answering the question on the audit's trigger that the plan held. Serves goal 1.1: a principle that no chunk checks drifts, as the stability reviewer's own copy of the principles drifted from them, until it applied `principles/technical-principles.md` as written. It costs goal 1.4: a chunk that changes code, config or tests launches one auditor for the goals and one per applicable principles file, and a code fix re-enters them. The human accepted that cost. The cost shows in tokens per finished chunk and in review rounds per chunk. Valid while the audit's findings are drift a chunk would otherwise merge, not the same whole-project findings repeated chunk after chunk: a repeat is a question on the audit's scope for the human. +2026-10-27, lilleman, asked through PR #376: the audit keeps reading the project whole. Since 2026-10-21, 342 auditor runs cost $274 at list prices, and of their 176 🔴 and 🟡 findings that named a file, 90 named one the chunk did not edit; reading only the changed files and their callers would have dropped those, and lilleman keeps them. Item 233 still has one auditor read the project once per round. + ## review: the stability pass mutation-tests the lines a chunk changes, in place of measuring test coverage 2026-10-13, lilleman through todo item 108, implemented by claude. Serves goals 1.1 and 1.4. Coverage counts the lines a test runs, so a test without a meaningful assertion still raises it. A surviving mutant shows a test that would let behaviour break. Every mutant of an untested changed line survives, so mutation testing of the changed lines also shows what a coverage drop on them would. Coverage would also catch a deleted test; the stability reviewer sees one in the diff without it. Measuring coverage beside it would add cost without raising quality, so todo item 69 was dropped and `principles/technical-principles.md` replaced "Test coverage should not decline" with the mutant rule. diff --git a/todo.md b/todo.md index a8cee2d5..b9f8bf9c 100644 --- a/todo.md +++ b/todo.md @@ -17,14 +17,12 @@ | 233 | 0.4.0 | | | **Run one principles-auditor per round that checks the goals and every principles file that applies, in place of one auditor for each, so the principles pass reads the project once per round.** | 3 | 2 | 3 | 6 | 3 | 1.4 by 3, 1.5 by 2 | 4.9 | | 234 | 0.4.0 | | | **Report the routing figures in dollars, cache reads included, from the cost each archived run records.** | 2 | 2 | 2 | 4 | 3 | 1.4 by 3 | 3.0 | | 239 | 0.4.0 | | owner | **Block a Read, `cat`, `sed` or `head` of a file range already in the session's context, with a note saying so, and let it through once a compaction dropped the range or the file changed.** | 3 | 2 | 3 | 6 | 4 | 1.4 by 3 | 2.0 | -| 236 | 0.5.0 | | question | **Answer whether the principles audit keeps reading the whole project, or reads only the files the chunk changed and their callers, now that half of its 🔴 and 🟡 findings name a file the chunk did not edit.** | 1 | 1 | 1 | 1 | 1 | 1.4 by 4 | 6.4 | -| 240 | 0.5.0 | | question | **Answer whether workers get a reading rule in `CLAUDE.md`: never read more than 80 lines of a file at once, nor take a tool output over 3,000 characters into your context.** | 1 | 2 | 3 | 4 | 1 | 1.4 by 3 | 4.8 | | 226 | 0.5.0 | | question | **Answer whether rule-hook's `run-heavy` rule should also catch a mutation run or docker build behind `uv run`, `poetry run`, `python3 -m`, `sudo`, `docker image build` and `docker compose up --build`, or narrow the `machine load:` decision's wording.** | 2 | 2 | 3 | 5 | 3 | 1.2 by 2, 1.5 by 2 | 4.0 | -| 241 | 0.5.0 | | question | **Answer whether reviewers hand a read over 80 lines to a Haiku scout, which on four replayed stability rounds cut the reviewer's reading by a third and its cost by a tenth, slowed it, and found as many findings as the reviewer finds on its own.** | 2 | 2 | 3 | 5 | 3 | 1.4 by 3 | 3.0 | | 235 | 0.5.0 | | | **Compare the first 20 chunks whose worker ran under the 200k compaction window with the 20 before them, on review rounds past each pass's first, unfinished verdicts, 🔴, 🟡 and misread findings, dollars and hours per chunk, and file an item where any rose.** | 1 | 2 | 1 | 2 | 2 | 1.1 by 2, 1.4 by 3 | 6.8 | | 59 | 0.5.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.5.0 | | | **Refuse a `/security-review` or `/claude-security` Skill call below the project's rung, as rule-hook refuses such an Agent call.** | 3 | 2 | 3 | 6 | 2 | 1.1 by 4 | 5.6 | | 6 | 0.5.0 | | decision | **Move what `loop-claude` writes out of `~/.claude.json`, and ask the human about each write that must stay.** | 3 | 3 | 3 | 7 | 3 | 1.1 by 5 | 5.3 | +| 240 | 0.5.0 | | | **Add a reading rule for workers to `CLAUDE.md` → "Working with the codebase", never read more than 80 lines of a file at once nor take a tool output over 3,000 characters into your context, and compare the 20 chunks after it with the 20 before on review rounds, unfinished verdicts, 🔴, 🟡 and misread findings, dollars and hours per chunk.** | 1 | 2 | 3 | 4 | 2 | 1.4 by 3 | 4.0 | | 1 | 0.6.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 | | 229 | 0.6.0 | | | **Keep the rule for which commands reach run-heavy's docker beside that docker in `bin/run_heavy/capped_docker.py`, so rule-hook's `docker-run-memory` asks it instead of repeating run-heavy's PATH rules.** | 2 | 1 | 3 | 4 | 2 | code health by 3 | 18.0 | | 219 | 0.6.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 | @@ -102,22 +100,10 @@ The routing figures count input, cache-written and output tokens, and leave out lilleman's call, 2026-10-27, filed from PR #376's measurement of loop-claude's archive since 2026-10-21: a read of a file the agent read earlier in the thread, more than three messages before and without editing it in between, is 13% of the worker's reading, about $6 of the $45 its reads cost, and 1 to 2% of a reviewer's. How many of those repeat a range exactly is unmeasured, so the figures are a ceiling. A hook on `Read` and on the Bash reads `cat`, `sed` and `head` blocks such a read with a short note that the content is already in context and unchanged. It lets the read through after a compaction, when the content has left the context, or when the file changed since the read. A PreToolUse hook gets a `transcript_path`, which holds the earlier reads and each `compact_boundary`, so it may need no state of its own; check whether a hook inside a subagent gets the subagent's own transcript. A scout only cheapens these re-reads and doesn't remove them, which is why this is a separate item. If scouts ship (`docs/decisions.md` → `loop-claude: the worker's claude compacts its context before it fills a 200k window…` records the trial, and item 241 asks), the same idea applies to scout answers, cached by file and content hash. -### 236. Answer whether the principles audit keeps reading the whole project, or reads only the files the chunk changed and their callers, now that half of its 🔴 and 🟡 findings name a file the chunk did not edit. - -Since 2026-10-21, 342 principles-auditor runs cost $274 at list prices, 23% of all spend, and 176 of their 🔴 and 🟡 findings named a file: 83 a file the chunk edited, 90 another. `docs/decisions.md` → `review: the principles audit runs on every chunk…` holds the whole-project audit valid while its findings are drift a chunk would otherwise merge, and calls a repeat a question on the audit's scope for the human. Reading only the changed files and their callers would cut most of the auditors' $129 of cache writes and drop the findings elsewhere, unless the same findings come back chunk after chunk: read a sample of the 90 before answering. Item 233 merges the auditors either way. - -### 240. Answer whether workers get a reading rule in `CLAUDE.md`: never read more than 80 lines of a file at once, nor take a tool output over 3,000 characters into your context. - -lilleman's question, from PR #376's trials, recorded in `docs/decisions.md` → `loop-claude: the worker's claude compacts its context before it fills a 200k window…`. Three worker-like tasks on this repo, a search, a rename and an explanation, each ran once as workers run today and once under the rule. Under the rule each task read 45% to 60% fewer characters, cost the same or less, and came out as well; of the four runs of the rename, the one under the rule was the only one that also kept the import names sorted. Only 4% of what a worker reads is in a file it later edits. Three tasks say little about real chunks, where a worker that reads less may misread more, and the rule is one line in `CLAUDE.md` that every session loads. A yes ships the line and measures the 20 chunks after it against the 20 before, as item 235 measures the compaction window: review rounds, unfinished verdicts, 🔴, 🟡 and misread findings, dollars and hours per chunk. - ### 226. Answer whether rule-hook's `run-heavy` rule should also catch a mutation run or docker build behind `uv run`, `poetry run`, `python3 -m`, `sudo`, `docker image build` and `docker compose up --build`, or narrow the `machine load:` decision's wording. Found by review of PR #370. Today `uv run mutmut run`, `poetry run mutmut run`, `python3 -m mutmut run`, `sudo docker build .`, `docker image build .` and `docker compose up --build` pass the rule, which `docs/decisions.md` → `machine load: …` and `RULES["run-heavy"]` describe as blocking docker builds and mutation runs. The rule's own text says a gate script isn't checked since no program can tell it from a light one, so the human decides where the line sits. Say what the rule's "checked" text promises either way. Where the answer widens the rule, the change touches `heavy` in `bin/rule_hook/heavy_command.py`, which the comprehension seats found hard: make it easier to read. -### 241. Answer whether reviewers hand a read over 80 lines to a Haiku scout, which on four replayed stability rounds cut the reviewer's reading by a third and its cost by a tenth, slowed it, and found as many findings as the reviewer finds on its own. - -lilleman's question, from PR #376's trials, recorded with the scout's shapes and costs in `docs/decisions.md` → `loop-claude: the worker's claude compacts its context before it fills a 200k window…`. A scout is Haiku 5.5 reading raw content, whole files or long output, and returning facts as path:line and the ranges worth reading; in session it is an agent under `agents/`, and as a slim headless `claude -p` on the subscription login it starts at 6k tokens in 3 to 5 seconds. On four replayed stability rounds the agent scout found 5 of 6 archived findings against the baseline's 4 and read 29% fewer characters at 6% less cost and 14% more time; the CLI scout 4 of 6, 38% fewer, 17% less and 39% more; the auditors with the agent scout 3 of 6, the 🔴 among the lost, at the same cost and twice the time. The reviewers under `agents/` spent $646 of the $1,215 since 2026-10-21, so a tenth off is about $65 per 90 chunks. `AGENTS.md` makes a change to the delegation rule lilleman's call. A yes names the shape, agent or CLI, and which reviewers, and measures the 20 chunks after it against the 20 before, as item 235 measures the compaction window. - ### 235. Compare the first 20 chunks whose worker ran under the 200k compaction window with the 20 before them, on review rounds past each pass's first, unfinished verdicts, 🔴, 🟡 and misread findings, dollars and hours per chunk, and file an item where any rose. `docs/decisions.md` → `loop-claude: the worker's claude compacts its context before it fills a 200k window…` expects a saving of about 6% of all spend with no rise in the other figures. Measure from loop-claude's archive as that decision did: rounds past each pass's first and the 🔴, 🟡 and misread counts from the round commit titles, unfinished verdicts from the outcomes files, hours from the worker's first message to its last, and dollars at list prices, cache reads included, from the chunk's `cost-state` entry, which counts the compaction calls that no message's usage records; item 234 puts such dollars into the routing figures. A chunk ran under the window when its first worker started after that decision merged. @@ -134,6 +120,10 @@ 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. +### 240. Add a reading rule for workers to `CLAUDE.md` → "Working with the codebase", never read more than 80 lines of a file at once nor take a tool output over 3,000 characters into your context, and compare the 20 chunks after it with the 20 before on review rounds, unfinished verdicts, 🔴, 🟡 and misread findings, dollars and hours per chunk. + +lilleman's call, 2026-10-27, answering PR #376's trials, recorded in `docs/decisions.md` → `loop-claude: the worker's claude compacts its context before it fills a 200k window…`. Three worker-like tasks on this repo, a search, a rename and an explanation, each ran once as workers run today and once under the rule: under it each task read 45% to 60% fewer characters, cost the same or less, and came out as well, and of the four runs of the rename, the one under the rule was the only one that also kept the import names sorted. Only 4% of what a worker reads is in a file it later edits. The line goes to `CLAUDE.md` → "Working with the codebase", which every session loads, so a worker that reads less may misread more: measure the 20 chunks after the line merges against the 20 before, as item 235 measures the compaction window, and drop the line where any of those figures rose. + ### 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 c36d7a2f9c352a299b33ea1780c0bf9cd291e44a Mon Sep 17 00:00:00 2001 From: Lilleman auf Larv Date: Tue, 27 Oct 2026 09:13:00 +0100 Subject: [PATCH 53/55] =?UTF-8?q?Answer=20prose=20round=203:=200=20?= =?UTF-8?q?=F0=9F=94=B4,=208=20=F0=9F=9F=A1=20(0=20misread);=20put=20the?= =?UTF-8?q?=20reading=20rule=20in=20the=20worker's=20prompt,=20quote=20it,?= =?UTF-8?q?=20mark=20the=20items=20the=20decision=20cites,=20name=20the=20?= =?UTF-8?q?whole-project=20reading=20in=20the=20audit=20decision's=20title?= =?UTF-8?q?,=20and=20state=20each=20answer=20once?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- AGENTS.md | 2 +- docs/decisions.md | 22 +++++++++++----------- todo.md | 14 +++++++------- 3 files changed, 19 insertions(+), 19 deletions(-) diff --git a/AGENTS.md b/AGENTS.md index aa6f454d..2cf8cb51 100644 --- a/AGENTS.md +++ b/AGENTS.md @@ -35,7 +35,7 @@ Decisions live in `docs/decisions.md`: - review: stability and product-owner report only a defect, a broken requirement of the plan or the goals, a breach of a technical principle, or for stability a hard place the change touches; each architect finding names a later change the PR makes harder; prose runs only on a chunk that changes prose - review: the comprehension check records how hard a project is to read and blocks no merge: a paired ruling against the last measured commit where the architecture pass ran, and the four-seat scoring run, once when an item names the floor and twice on one head when a release's items run out - review: the premises chunk's whole review is the human's approval -- review: the principles audit runs on every chunk that changes code, config or tests, and on no other chunk +- review: the principles audit runs on every chunk that changes code, config or tests, reads the project whole, and runs on no other chunk - review: the stability pass mutation-tests the lines a chunk changes, in place of measuring test coverage - routing: a chunk's worker runs on the rung its item's L picks, below the project's rung too; its reviewers run on the highest of the worker's rung, the project's and the one picked by the highest E + I among the chunk's items, unless a replay lowered their pass; the seats and the security pass always on the project's - routing: a review pass runs below the project's rung only on a rung that a replay of its rounds shows finding every 🔴 and 🟡 the project's rung finds, and only where the E + I steps no review up and the worker runs no higher than the project's rung, then even below the worker's; no pass has such a rung diff --git a/docs/decisions.md b/docs/decisions.md index 28e1cada..73072a3f 100644 --- a/docs/decisions.md +++ b/docs/decisions.md @@ -74,28 +74,28 @@ The cap is 5, `bin/todo_table.py`'s `BUNDLE_MAX_R`, from the same chunks: by the ## loop-claude: the worker's claude compacts its context before it fills a 200k window, at about 170k tokens, and `CLAUDE.md` → "Compact instructions" says what the summary keeps -2026-10-27, lilleman's yes, typed that day, to the evaluation claude made through todo item 231. Serves goal 1.4; its counter-signal, review rounds and unfinished verdicts per chunk, is the check. +2026-10-27, lilleman's yes to claude's evaluation through todo todo item 231. Serves goal 1.4; its counter-signal, review rounds and unfinished verdicts per chunk, is the check. loop-claude hands each worker's claude `CLAUDE_CODE_AUTO_COMPACT_WINDOW=200000` (`bin/loop_claude/cycle/worker.py`), and the session /talk opens gets it too. Claude Code compacts before a window fills: a 1M window at about 967k tokens, and in a probe on 2026-10-27 a 100k window at 65k and 80k, so a 200k window compacts at about 170k. The window is not set in `settings.json`, since the archive measured loop-claude's workers and interactive sessions are lilleman's. Subagents inherit the variable, which reaches every process of the session: 68 of the 994 subagent runs since 2026-10-21, 7%, passed 170k, 24 of them principles auditors, so about one in fourteen compacts once. Compacting subagents by choice would cost more than it saves, as below, but the variable cannot leave them out, and `CLAUDE.md` → "Compact instructions" has a reviewer keep the findings it has drafted. That section shapes the summary: in another probe that day, a session whose CLAUDE.md asked for its summary to end with a secret word got a summary ending with that word. Path-scoped rules leave the context at a compaction and return at the next matching read, and rule-hook holds each review launch to its rung whatever the summary keeps. `CLAUDE_CODE_DISABLE_1M_CONTEXT=1`, handed the same way, would compact at the same point but also cap the window at 200k, so a run that Claude Code stops compacting, as it does when one tool result refills the context each time, would hit the limit instead of going on. Why 200k. Item 231 asked for the best means to lower what a chunk spends on context, in dollars, then hours, with no loss of quality. Measured from loop-claude's archive, the 90 chunks with messages after the routing figures' reset of 2026-10-21 cost $1,215 at the list prices read on 2026-10-26 (Opus 5.5: $4 per million input tokens, $5 and $8 for 5-minute and 1-hour cache writes, $0.20 for cache reads, $20 for output; no model but Haiku 5.5 charges more above 200k). That is 0.86 of what the chunks' `cost-state` entries sum to, since some chunks' subagent transcripts are not in the archive. Worker main threads cost $375 (31%): 1-hour cache writes $149, cache reads $153, output $74. Subagents cost $840: 5-minute cache writes $379, output $274, cache reads $187, with the principles auditors at $274 over 342 runs, the stability reviewers $179 and general-purpose subagents $192. A worker starts at 41k tokens of context and peaks at a median 167k, one in ten past 358k, the largest at 848k. The worker's messages above 200k were 32% of its messages and 55% of its cost. -What reads cost, and whether a tool cuts them, measured at lilleman's ask after those figures: no tool cut a reviewer's reading without losing a finding, except a scout, whose findings stayed within what the same reviewer finds twice; so none of them ships here. lilleman chose on 2026-10-27: workers trial a reading rule (item 240), and reviewers get no scout. Two measures of reading: the characters a thread read, 93M in all, about 27M tokens; and the new input tokens of the messages that took results in, charged to those results, which also count what arrives beside a result, such as the agent's own previous reply. By the second measure tool results caused $620 of the $1,215, and reads (Read, Bash reads, Grep, Glob and git's diff, show and log) $537 of that: the worker's reads $140 (Bash reads $115, Read $12) of its $190 of results, the principles auditors' $133 (Read $109, Grep $22) of $139, the stability reviewers' $97 (Bash reads $79) of $106, general-purpose subagents' $84 of $97, the prose reviewers' $32, the architects' $30 and the product-owner reviewers' $21. By the first measure the worker's reads are about $45. Precision is low everywhere: of the characters a principles auditor read, 13% were in a file its report names; a stability reviewer 8%; a prose reviewer 18%; an architect 11%; the worker 4% in a file it later edited. Reading is mostly to find things and to learn what a project holds. The worker's `sed` ranges are small, median 25 lines, one in ten over 80. Of the worker's read characters, 49% were of a file it had read earlier in the thread: 36% within three messages, paging through it, and 13% later, with the file unchanged, about $6 of the $45; a reviewer's later reads of an unchanged file it had read are 1 to 2% (item 239). +What reads cost, and whether a tool cuts them, measured at lilleman's ask after those figures: no tool cut a reviewer's reading without losing a finding, except a scout, which kept the stability reviewers' findings but lost the auditors' 🔴 and slowed every round; so none of them ships here. lilleman chose on 2026-10-27: workers trial a reading rule (`todo.md` item 240), reviewers get no scout, and the principles audit keeps reading the project whole. Two measures of reading: the characters a thread read, 93M in all, about 27M tokens; and the new input tokens of the messages that took results in, charged to those results, which also count what arrives beside a result, such as the agent's own previous reply. By the second measure tool results caused $620 of the $1,215, and reads (Read, Bash reads, Grep, Glob and git's diff, show and log) $537 of that: the worker's reads $140 (Bash reads $115, Read $12) of its $190 of results, the principles auditors' $133 (Read $109, Grep $22) of $139, the stability reviewers' $97 (Bash reads $79) of $106, general-purpose subagents' $84 of $97, the prose reviewers' $32, the architects' $30 and the product-owner reviewers' $21. By the first measure the worker's reads are about $45. Precision is low everywhere: of the characters a principles auditor read, 13% were in a file its report names; a stability reviewer 8%; a prose reviewer 18%; an architect 11%; the worker 4% in a file it later edited. Reading is mostly to find things and to learn what a project holds. The worker's `sed` ranges are small, median 25 lines, one in ten over 80. Of the worker's read characters, 49% were of a file it had read earlier in the thread: 36% within three messages, paging through it, and 13% later, with the file unchanged, about $6 of the $45; a reviewer's later reads of an unchanged file it had read are 1 to 2% (`todo.md` item 239). -The trials: four stability rounds and five principles rounds archived on 2026-10-23, each holding 🔴 or 🟡 findings, replayed on the project's rung as `review-replay` replays them, with the reviewer's definition changed through `--agents`; and three worker-like tasks, a search, a rename and an explanation, run on fresh clones at the project's rung. The baseline, the reviewer as it is, found 4 of its own 6 archived findings in each pass, so a variant that finds 4 or 5 of 6 does what the same reviewer does twice. The options item 231 named, each simulated on the 90 chunks and, where lilleman asked, tried: +The trials: four stability rounds and five principles rounds archived on 2026-10-23, each holding 🔴 or 🟡 findings, replayed on the project's rung as `review-replay` replays them, with the reviewer's definition changed through `--agents`; and three worker-like tasks, a search, a rename and an explanation, run on fresh clones at the project's rung. The baseline, the reviewer as it is, found 4 of its own 6 archived findings in each pass, so a variant that finds 4 or 5 of 6 does what the same reviewer does twice. The options todo item 231 named, each simulated on the 90 chunks and, where lilleman asked, tried: - Compaction of the worker. The saving and the compactions per chunk, by the point it compacts at: 150k saves $75 at 1.0 compactions; 167k to 180k, where a 200k window compacts, $77 to $78 at 0.8 to 0.7; 200k $78 at 0.5; 300k $54 at 0.2. $78 is 21% of the workers' $375 and 6% of all spend. Compaction also caps the 36 re-writes of a whole context after a gap longer than the cache's hour or a change of rung: they cost $61, up to 785k tokens each, and would cost about $34. Compacting subagents at 150k costs more than it saves, since a compaction reads the context once more and writes a summary, and subagents are short. - A fresh context for the review phase, handed 60k tokens of facts, saves $39. A compaction at 170k saves that too, and loop-claude would need a second session per chunk. -- Read with an offset and a limit, or Grep, in place of `cat`, `sed` and `head`. Steering the tool would not change how much is read: the worker's `sed` ranges are small already, and only 13% of its Bash-read characters came from whole files. A rule on how much to read did change it: under "never read more than 80 lines of a file at once, nor take a tool output over 3,000 characters into your context", the three worker tasks read 45% to 60% fewer characters at the same or lower cost, every task done as well, and the rename was the one run of four that also kept the import names sorted; item 240 trials the rule on workers. A stability reviewer under the same rule with an `outline` script on PATH, which prints a file's symbols with their line ranges, read 4% less and found 2 of 6 findings, and the workers never ran the script. +- Read with an offset and a limit, or Grep, in place of `cat`, `sed` and `head`. Steering the tool would not change how much is read: the worker's `sed` ranges are small already, and only 13% of its Bash-read characters came from whole files. A rule on how much to read did change it: under "never read more than 80 lines of a file at once, nor take a tool output over 3,000 characters into your context", the three worker tasks read 45% to 60% fewer characters at the same or lower cost, every task done as well, and the rename was the one run of four that also kept the import names sorted (`todo.md` item 240). A stability reviewer under the same rule with an `outline` script on PATH, which prints a file's symbols with their line ranges, read 4% less and found 2 of 6 findings, and the workers never ran the script. - Code-intelligence tooling: the `LSP` tool, through a pyright plugin built from the marketplace manifest with `pyright-langserver` on PATH, answers a file's symbols, a definition or the references in a few hundred characters. Under a rule telling them to use it, the stability reviewers and the workers never called it; the auditors did, read as much or more, and missed the one 🔴, 0 of 1 against the baseline's 1 of 1. Each machine would also need a server per language (goal 2). Not worth an item. - A cap on tool results. Claude Code caps a Bash result at about 30k characters already. A PostToolUse hook capping it at 12k, which `updatedToolOutput` allows, left the stability reviewers 3 of 6 findings, two lost in one round. Read results, 59.9M characters in subagents' threads with 58% of their characters in results over 12k, are out of such a hook's reach. Not worth an item. -- A scout: Haiku 5.5 reading raw content, whole files or long output, and returning facts as path:line and the ranges worth reading, so the agent's own context holds the summary and the chosen lines. In session, as an agent under `agents/`, its first request writes 37k tokens, $0.005, and a read of a 38KB file costs $0.008 in 8 seconds. As a slim headless `claude -p` with its own system prompt, no setting sources and no dynamic sections, which keeps the subscription login, it starts at 6k tokens and $0.0003 in 3 to 5 seconds, its prefix cached across calls, and the same read costs $0.004 in 7 seconds; a direct API call and `claude --bare` need an API key, so they are out. Stability reviewers with the agent scout found 5 of 6 findings and read 29% fewer characters at 6% less cost and 14% more time; with the CLI scout 4 of 6, 38% fewer, 17% less and 39% more; the auditors with the agent scout 3 of 6, the 🔴 among the lost, at the same cost and twice the time. Workers offered the scout never called it. On 2026-10-27 lilleman said no to a scout for reviewers: the saving sits within the reviewer's own spread, the auditors lost the 🔴, and every round ran slower. The delegation rule stands as `routing: a worker delegates a task only where it needs just the task's conclusion…` records. -- What a reviewer reads: the auditors read the project whole by design. Of their 🔴 and 🟡 findings since the reset, 47% named a file the chunk edited and 51% another file, so reading only the change would drop half of them; on 2026-10-27 lilleman kept the whole-project reading (`review: the principles audit runs on every chunk that changes code, config or tests, and on no other chunk`), and item 233 has one auditor read the project once per round. -- The base context: every thread starts with `~/.claude/CLAUDE.md` (19k characters), `~/.claude/AGENTS.md` (11k, this repo's decisions, which Claude Code loads as user instructions into every project's sessions; item 52), the project's `AGENTS.md`, and, for the worker and general-purpose subagents, the skill listing (18k) and the agent listing (12k). Subagents' first messages wrote $97 of it. Trimming the listings would save about $20, 2%, and is not worth an item: `disableBundledSkills` would also drop `/security-review`, the security pass of record. +- A scout: Haiku 5.5 reading raw content, whole files or long output, and returning facts as path:line and the ranges worth reading, so the agent's own context holds the summary and the chosen lines. In session, as an agent under `agents/`, its first request writes 37k tokens, $0.005, and a read of a 38KB file costs $0.008 in 8 seconds. As a slim headless `claude -p` with its own system prompt, no setting sources and no dynamic sections, which keeps the subscription login, it starts at 6k tokens and $0.0003 in 3 to 5 seconds, its prefix cached across calls, and the same read costs $0.004 in 7 seconds; a direct API call and `claude --bare` need an API key, so they are out. Stability reviewers with the agent scout found 5 of 6 findings and read 29% fewer characters at 6% less cost and 14% more time; with the CLI scout 4 of 6, 38% fewer, 17% less and 39% more; the auditors with the agent scout 3 of 6, the 🔴 among the lost, at the same cost and twice the time. Workers offered the scout never called it. +- What a reviewer reads: the auditors read the project whole by design. Of their 🔴 and 🟡 findings since the reset, 47% named a file the chunk edited and 51% another file, so reading only the change would drop half of them (`review: the principles audit runs on every chunk that changes code, config or tests, reads the project whole, and runs on no other chunk`); `todo.md` item 233 has one auditor read the project once per round. +- The base context: every thread starts with `~/.claude/CLAUDE.md` (19k characters), `~/.claude/AGENTS.md` (11k, this repo's decisions, which Claude Code loads as user instructions into every project's sessions; `todo.md` item 52), the project's `AGENTS.md`, and, for the worker and general-purpose subagents, the skill listing (18k) and the agent listing (12k). Subagents' first messages wrote $97 of it. Trimming the listings would save about $20, 2%, and is not worth an item: `disableBundledSkills` would also drop `/security-review`, the security pass of record. -Quality. 19 chunks compacted between 2026-10-10 and 2026-10-22, at the compaction points Claude Code set then, 214k to 972k tokens. Per 100 worker messages they took a median 3.6 review rounds past each pass's first against 4.0 for the 68 uncompacted chunks of 100 messages or more, and 13.9 🔴 and 🟡 findings against 16.6. 4 of 19 had an unfinished verdict against 3 of 68, each 8 to 10 hours after the compaction and followed by a finished verdict within minutes; in those four verdicts the judge quoted the worker's own passages and the human's typed answers, never a summary. One cause was possible and is closed here: Claude Code writes the summary as a user entry, which `bin/claude_code/entries.py` read as the human's words, so the judge would see a `[human]` line of thousands of words and `/talk` would count it as typed; it now reads as Claude Code's. Whether compaction raises unfinished verdicts stays open until item 235 measures it. Two summaries read whole kept the chunk's intent, files, errors and next step in 12k to 20k characters, and the worker resumed without re-reading. +Quality. 19 chunks compacted between 2026-10-10 and 2026-10-22, at the compaction points Claude Code set then, 214k to 972k tokens. Per 100 worker messages they took a median 3.6 review rounds past each pass's first against 4.0 for the 68 uncompacted chunks of 100 messages or more, and 13.9 🔴 and 🟡 findings against 16.6. 4 of 19 had an unfinished verdict against 3 of 68, each 8 to 10 hours after the compaction and followed by a finished verdict within minutes; in those four verdicts the judge quoted the worker's own passages and the human's typed answers, never a summary. One cause was possible and is closed here: Claude Code writes the summary as a user entry, which `bin/claude_code/entries.py` read as the human's words, so the judge would see a `[human]` line of thousands of words and `/talk` would count it as typed; it now reads as Claude Code's. Whether compaction raises unfinished verdicts stays open until `todo.md` item 235 measures it. Two summaries read whole kept the chunk's intent, files, errors and next step in 12k to 20k characters, and the worker resumed without re-reading. -Hours. A chunk ran a median 0.7 hours from its first message to its last, one in ten past 12 hours, mostly waiting for the human or a usage limit. No option here changes that: a compaction takes 51 to 83 seconds, under a minute per chunk at 0.7 each, and a smaller context saves seconds per turn at most. The hours lever is item 232, since waiting on subagents took 66% of a worker's active time. +Hours. A chunk ran a median 0.7 hours from its first message to its last, one in ten past 12 hours, mostly waiting for the human or a usage limit. No option here changes that: a compaction takes 51 to 83 seconds, under a minute per chunk at 0.7 each, and a smaller context saves seconds per turn at most. The hours lever is `todo.md` item 232, since waiting on subagents took 66% of a worker's active time. Valid while cache reads cost a twentieth of input and Claude Code's compaction keeps the worker's task. @@ -223,11 +223,11 @@ The base is the last measured commit: the default branch's newest merged change 2026-09-20, lilleman. Serves goal 1.1. A reviewer's finding on that chunk could only be declined by citing the goals the chunk exists to write. Valid while every decline must name a goal or a technical principle. -## review: the principles audit runs on every chunk that changes code, config or tests, and on no other chunk +## review: the principles audit runs on every chunk that changes code, config or tests, reads the project whole, and runs on no other chunk 2026-10-16, lilleman, answering the question on the audit's trigger that the plan held. Serves goal 1.1: a principle that no chunk checks drifts, as the stability reviewer's own copy of the principles drifted from them, until it applied `principles/technical-principles.md` as written. It costs goal 1.4: a chunk that changes code, config or tests launches one auditor for the goals and one per applicable principles file, and a code fix re-enters them. The human accepted that cost. The cost shows in tokens per finished chunk and in review rounds per chunk. Valid while the audit's findings are drift a chunk would otherwise merge, not the same whole-project findings repeated chunk after chunk: a repeat is a question on the audit's scope for the human. -2026-10-27, lilleman, asked through PR #376: the audit keeps reading the project whole. Since 2026-10-21, 342 auditor runs cost $274 at list prices, and of their 176 🔴 and 🟡 findings that named a file, 90 named one the chunk did not edit; reading only the changed files and their callers would have dropped those, and lilleman keeps them. Item 233 still has one auditor read the project once per round. +2026-10-27, lilleman, answering the question PR #376 raised: the audit keeps reading the project whole. Since 2026-10-21, 342 auditor runs cost $274 at list prices, and of their 176 🔴 and 🟡 findings that named a file, 90 named one the chunk did not edit, which reading only the change would drop; lilleman keeps them. ## review: the stability pass mutation-tests the lines a chunk changes, in place of measuring test coverage diff --git a/todo.md b/todo.md index b9f8bf9c..022f0307 100644 --- a/todo.md +++ b/todo.md @@ -12,17 +12,17 @@ | ID | Release | Blocked by | Exempt | Item | L | E | I | R | S | Moves | Score | |---|---|---|---|---|---|---|---|---|---|---|---| -| 232 | 0.4.0 | | | **Launch a round's review passes in one message, except a pass that must wait for another's findings, so a round lasts about as long as its slowest reviewers, not their sum.** | 3 | 2 | 3 | 6 | 3 | 1.5 by 6 | 5.8 | +| 232 | 0.4.0 | | decision | **Launch a round's review passes in one message, except a pass that must wait for another's findings, so a round lasts about as long as its slowest reviewers, not their sum.** | 3 | 2 | 3 | 6 | 3 | 1.5 by 6 | 5.8 | | 238 | 0.4.0 | | defect | **Run the security pass's skill in the chunk's worktree, so it scans the branch's diff: invoked from a subagent, it runs in the session's working directory, the main checkout, and scans nothing.** | 2 | 2 | 3 | 5 | 3 | 1.1 by 5 | 5.3 | -| 233 | 0.4.0 | | | **Run one principles-auditor per round that checks the goals and every principles file that applies, in place of one auditor for each, so the principles pass reads the project once per round.** | 3 | 2 | 3 | 6 | 3 | 1.4 by 3, 1.5 by 2 | 4.9 | +| 233 | 0.4.0 | | decision | **Run one principles-auditor per round that checks the goals and every principles file that applies, in place of one auditor for each, so the principles pass reads the project once per round.** | 3 | 2 | 3 | 6 | 3 | 1.4 by 3, 1.5 by 2 | 4.9 | | 234 | 0.4.0 | | | **Report the routing figures in dollars, cache reads included, from the cost each archived run records.** | 2 | 2 | 2 | 4 | 3 | 1.4 by 3 | 3.0 | | 239 | 0.4.0 | | owner | **Block a Read, `cat`, `sed` or `head` of a file range already in the session's context, with a note saying so, and let it through once a compaction dropped the range or the file changed.** | 3 | 2 | 3 | 6 | 4 | 1.4 by 3 | 2.0 | | 226 | 0.5.0 | | question | **Answer whether rule-hook's `run-heavy` rule should also catch a mutation run or docker build behind `uv run`, `poetry run`, `python3 -m`, `sudo`, `docker image build` and `docker compose up --build`, or narrow the `machine load:` decision's wording.** | 2 | 2 | 3 | 5 | 3 | 1.2 by 2, 1.5 by 2 | 4.0 | -| 235 | 0.5.0 | | | **Compare the first 20 chunks whose worker ran under the 200k compaction window with the 20 before them, on review rounds past each pass's first, unfinished verdicts, 🔴, 🟡 and misread findings, dollars and hours per chunk, and file an item where any rose.** | 1 | 2 | 1 | 2 | 2 | 1.1 by 2, 1.4 by 3 | 6.8 | +| 235 | 0.5.0 | | decision | **Compare the first 20 chunks whose worker ran under the 200k compaction window with the 20 before them, on review rounds past each pass's first, unfinished verdicts, 🔴, 🟡 and misread findings, dollars and hours per chunk, and file an item where any rose.** | 1 | 2 | 1 | 2 | 2 | 1.1 by 2, 1.4 by 3 | 6.8 | | 59 | 0.5.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.5.0 | | | **Refuse a `/security-review` or `/claude-security` Skill call below the project's rung, as rule-hook refuses such an Agent call.** | 3 | 2 | 3 | 6 | 2 | 1.1 by 4 | 5.6 | | 6 | 0.5.0 | | decision | **Move what `loop-claude` writes out of `~/.claude.json`, and ask the human about each write that must stay.** | 3 | 3 | 3 | 7 | 3 | 1.1 by 5 | 5.3 | -| 240 | 0.5.0 | | | **Add a reading rule for workers to `CLAUDE.md` → "Working with the codebase", never read more than 80 lines of a file at once nor take a tool output over 3,000 characters into your context, and compare the 20 chunks after it with the 20 before on review rounds, unfinished verdicts, 🔴, 🟡 and misread findings, dollars and hours per chunk.** | 1 | 2 | 3 | 4 | 2 | 1.4 by 3 | 4.0 | +| 240 | 0.5.0 | | decision | **Give loop-claude's worker prompt the reading rule "never read more than 80 lines of a file at once, nor take a tool output over 3,000 characters into your context", and keep it only where the 20 chunks after it hold the 20 before's review rounds, unfinished verdicts, 🔴, 🟡 and misread findings, dollars and hours per chunk.** | 1 | 2 | 3 | 4 | 2 | 1.4 by 3 | 4.0 | | 1 | 0.6.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 | | 229 | 0.6.0 | | | **Keep the rule for which commands reach run-heavy's docker beside that docker in `bin/run_heavy/capped_docker.py`, so rule-hook's `docker-run-memory` asks it instead of repeating run-heavy's PATH rules.** | 2 | 1 | 3 | 4 | 2 | code health by 3 | 18.0 | | 219 | 0.6.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 | @@ -98,7 +98,7 @@ The routing figures count input, cache-written and output tokens, and leave out ### 239. Block a Read, `cat`, `sed` or `head` of a file range already in the session's context, with a note saying so, and let it through once a compaction dropped the range or the file changed. -lilleman's call, 2026-10-27, filed from PR #376's measurement of loop-claude's archive since 2026-10-21: a read of a file the agent read earlier in the thread, more than three messages before and without editing it in between, is 13% of the worker's reading, about $6 of the $45 its reads cost, and 1 to 2% of a reviewer's. How many of those repeat a range exactly is unmeasured, so the figures are a ceiling. A hook on `Read` and on the Bash reads `cat`, `sed` and `head` blocks such a read with a short note that the content is already in context and unchanged. It lets the read through after a compaction, when the content has left the context, or when the file changed since the read. A PreToolUse hook gets a `transcript_path`, which holds the earlier reads and each `compact_boundary`, so it may need no state of its own; check whether a hook inside a subagent gets the subagent's own transcript. A scout only cheapens these re-reads and doesn't remove them, which is why this is a separate item. If scouts ship (`docs/decisions.md` → `loop-claude: the worker's claude compacts its context before it fills a 200k window…` records the trial, and item 241 asks), the same idea applies to scout answers, cached by file and content hash. +lilleman's call, 2026-10-27, filed from PR #376's measurement of loop-claude's archive since 2026-10-21: a read of a file the agent read earlier in the thread, more than three messages before and without editing it in between, is 13% of the worker's reading, about $6 of the $45 its reads cost, and 1 to 2% of a reviewer's. How many of those repeat a range exactly is unmeasured, so the figures are a ceiling. A hook on `Read` and on the Bash reads `cat`, `sed` and `head` blocks such a read with a short note that the content is already in context and unchanged. It lets the read through after a compaction, when the content has left the context, or when the file changed since the read. A PreToolUse hook gets a `transcript_path`, which holds the earlier reads and each `compact_boundary`, so it may need no state of its own; check whether a hook inside a subagent gets the subagent's own transcript. ### 226. Answer whether rule-hook's `run-heavy` rule should also catch a mutation run or docker build behind `uv run`, `poetry run`, `python3 -m`, `sudo`, `docker image build` and `docker compose up --build`, or narrow the `machine load:` decision's wording. @@ -120,9 +120,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. -### 240. Add a reading rule for workers to `CLAUDE.md` → "Working with the codebase", never read more than 80 lines of a file at once nor take a tool output over 3,000 characters into your context, and compare the 20 chunks after it with the 20 before on review rounds, unfinished verdicts, 🔴, 🟡 and misread findings, dollars and hours per chunk. +### 240. Give loop-claude's worker prompt the reading rule "never read more than 80 lines of a file at once, nor take a tool output over 3,000 characters into your context", and keep it only where the 20 chunks after it hold the 20 before's review rounds, unfinished verdicts, 🔴, 🟡 and misread findings, dollars and hours per chunk. -lilleman's call, 2026-10-27, answering PR #376's trials, recorded in `docs/decisions.md` → `loop-claude: the worker's claude compacts its context before it fills a 200k window…`. Three worker-like tasks on this repo, a search, a rename and an explanation, each ran once as workers run today and once under the rule: under it each task read 45% to 60% fewer characters, cost the same or less, and came out as well, and of the four runs of the rename, the one under the rule was the only one that also kept the import names sorted. Only 4% of what a worker reads is in a file it later edits. The line goes to `CLAUDE.md` → "Working with the codebase", which every session loads, so a worker that reads less may misread more: measure the 20 chunks after the line merges against the 20 before, as item 235 measures the compaction window, and drop the line where any of those figures rose. +lilleman's call, 2026-10-27, answering PR #376's trials, recorded in `docs/decisions.md` → `loop-claude: the worker's claude compacts its context before it fills a 200k window…`: three worker-like tasks each ran four ways, as workers run today, with an outline tool, with the LSP tool and under the rule, and only the rule cut reading, by 45% to 60%, at the same or lower cost and with the tasks done as well. The rule is for workers, so it goes into the prompt loop-claude gives a chunk's worker (`bin/loop_claude/cycle/prompts.py`), not into `CLAUDE.md`, which reviewers load too and where the one reviewer run under a like rule found 2 of 6 findings. A worker that reads less may misread more, so measure the 20 chunks after the rule merges against the 20 before, as item 235 measures the compaction window, and drop the rule where any of those figures rose. ### 1. Say in README → Install how the transcript archive is backed up, once bender-infra backs up ai-sandbox's data volume. From 9accc68ec35e815193300ab02321c6c6a0766ff2 Mon Sep 17 00:00:00 2001 From: Lilleman auf Larv Date: Wed, 28 Oct 2026 02:17:15 +0100 Subject: [PATCH 54/55] Launch a round's reviewers in up to three waves, each in one message, in place of one at a time --- CHANGELOG.md | 1 + docs/decisions.md | 2 +- skills/larv-review/SKILL.md | 14 +++++++++++--- todo.md | 5 ----- 4 files changed, 13 insertions(+), 9 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 3f436cb9..f475bebc 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,7 @@ ## Unreleased +- larv-review now launches a round's reviewers in up to three waves, each wave's reviewers in one message, in place of one reviewer at a time: first the architect, then the principles auditors with the security and overrides passes, then the stability, product-owner and prose passes. A round now lasts about as long as its slowest reviewer in each wave, not the sum of all of them. - loop-claude's worker, and every subagent it launches, now run with a 200k auto-compact window, handed as `CLAUDE_CODE_AUTO_COMPACT_WINDOW`: Claude Code compacts their context at about 170k tokens, where it used to let it grow to about 967k. loop-claude's judge no longer reads a compaction summary as words you typed. `CLAUDE.md` has a new section, "Compact instructions", saying what a summary keeps. - On Linux, `run-heavy` now caps the memory of a container its command makes with `docker run` or `docker create`. A container that sets no limit gets a memory limit and a swap limit, both the slot's share: three quarters of the machine's memory, split across the heavy slots. A container that sets one of the two limits keeps it, and gets the other as large. This covers containers a project's own scripts start, which rule-hook can't see. A `docker compose` service, and a docker named by its full path, get no cap. rule-hook's `docker-run-memory` now lets a `docker run` under run-heavy pass. - 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. diff --git a/docs/decisions.md b/docs/decisions.md index 73072a3f..781c9731 100644 --- a/docs/decisions.md +++ b/docs/decisions.md @@ -95,7 +95,7 @@ The trials: four stability rounds and five principles rounds archived on 2026-10 Quality. 19 chunks compacted between 2026-10-10 and 2026-10-22, at the compaction points Claude Code set then, 214k to 972k tokens. Per 100 worker messages they took a median 3.6 review rounds past each pass's first against 4.0 for the 68 uncompacted chunks of 100 messages or more, and 13.9 🔴 and 🟡 findings against 16.6. 4 of 19 had an unfinished verdict against 3 of 68, each 8 to 10 hours after the compaction and followed by a finished verdict within minutes; in those four verdicts the judge quoted the worker's own passages and the human's typed answers, never a summary. One cause was possible and is closed here: Claude Code writes the summary as a user entry, which `bin/claude_code/entries.py` read as the human's words, so the judge would see a `[human]` line of thousands of words and `/talk` would count it as typed; it now reads as Claude Code's. Whether compaction raises unfinished verdicts stays open until `todo.md` item 235 measures it. Two summaries read whole kept the chunk's intent, files, errors and next step in 12k to 20k characters, and the worker resumed without re-reading. -Hours. A chunk ran a median 0.7 hours from its first message to its last, one in ten past 12 hours, mostly waiting for the human or a usage limit. No option here changes that: a compaction takes 51 to 83 seconds, under a minute per chunk at 0.7 each, and a smaller context saves seconds per turn at most. The hours lever is `todo.md` item 232, since waiting on subagents took 66% of a worker's active time. +Hours. A chunk ran a median 0.7 hours from its first message to its last, one in ten past 12 hours, mostly waiting for the human or a usage limit. No option here changes that: a compaction takes 51 to 83 seconds, under a minute per chunk at 0.7 each, and a smaller context saves seconds per turn at most. The hours lever was launching a round's reviewers together, since waiting on subagents took 66% of a worker's active time: larv-review §3 → "Waves" now does, through todo item 232. Valid while cache reads cost a twentieth of input and Claude Code's compaction keeps the worker's task. diff --git a/skills/larv-review/SKILL.md b/skills/larv-review/SKILL.md index d15ba69a..b1b05751 100644 --- a/skills/larv-review/SKILL.md +++ b/skills/larv-review/SKILL.md @@ -5,7 +5,7 @@ description: Ship a work chunk through review to a merged PR; decisions land in # larv-review — ship the chunk, review until clean, gate green, merge -You orchestrate, fix, and ship; reviewers only report. Run every reviewer synchronously (`run_in_background: false`) and watch CI in the foreground: a headless run exits when the turn ends, and a background watcher dies with it. Never schedule a wakeup: a pending one keeps a headless run from exiting, so loop-claude neither runs its judge nor asks the human. The turn runs on until §6. +You orchestrate, fix, and ship; reviewers only report. Run every reviewer synchronously (`run_in_background: false`), a wave's in one message (§3 → "Waves"), and watch CI in the foreground: a headless run exits when the turn ends, and a background watcher dies with it. Never schedule a wakeup: a pending one keeps a headless run from exiting, so loop-claude neither runs its judge nor asks the human. The turn runs on until §6. **Forge-neutral.** Five PR operations recur below: read a PR's diff, open a draft PR, read check status, mark ready, merge. Resolve the tooling from the remote per `~/.claude/CLAUDE.md` → "Git, commits, and PRs"; on any other forge, achieve the same intents through its CLI or API — discover how rather than assuming. A forge without a native draft state gets the closest equivalent (a `WIP:`/`Draft:` title prefix); note any approximation in the summary. @@ -41,7 +41,15 @@ A pass is one kind of review, a row of the table, named by its first column. Its | Product-owner | product-owner-reviewer | changes an external surface: API, CLI, UI, error or deprecation text a consumer reads, README and docs an outside reader lands on | | Prose | prose-reviewer | changes prose a reader reads, such as docs, comments, help or error text, or the plan; one round | -A comment is prose, not code. Passes run in this order: line-level polish on code the architect wants restructured, or on a call the security pass will rewrite, is wasted work. +A comment is prose, not code. + +**Waves.** A round's passes launch in up to three waves, each wave's reviewers in one message, since line-level polish on code the architect wants restructured, or on a call the security pass will rewrite, is wasted work. A wave waits until every pass of the waves before it is done, and a wave with no pass whose trigger fired is skipped. + +1. Architecture. +2. Principles, every auditor, with Full scan or Security, and Overrides. +3. Stability, Product-owner and Prose. + +Foreground calls in one message run together, so a wave lasts as long as its slowest reviewer. Give a reviewer without Bash the branch diff and `git ls-files`'s output in its prompt: some harnesses grant it Read alone. @@ -70,7 +78,7 @@ Give a reviewer without Bash the branch diff and `git ls-files`'s output in its - **Cap.** A pass takes at most three rounds per chunk. Instead of a fourth, list what is open and ask the user. For the auto-reviewer, ask before the push that would summon its fourth, and hold the fixes unpushed until the answer. - **Answer.** A yes grants that pass one more round, after which the ask repeats; a no leaves the PR unmerged. rule-hook refuses a round commit titled past round 3 unless its `round-cap` override quotes the yes. -**Re-entry.** A fix is a change no pass has seen. A fix for a 🟢, a ❓ or a prose finding reruns no pass, whatever it changes. A round's fixes for 🔴 and 🟡 findings re-enter together: run, in the pass table's order, every pass that a row below names for any of them, a done pass included, then §4. A pass at its cap gets "Round cap" → "Cap"'s ask instead. +**Re-entry.** A fix is a change no pass has seen. A fix for a 🟢, a ❓ or a prose finding reruns no pass, whatever it changes. A round's fixes for 🔴 and 🟡 findings re-enter together: run, in "Waves", every pass that a row below names for any of them, a done pass included, then §4. A pass at its cap gets "Round cap" → "Cap"'s ask instead. | The fix | Reruns | |---------|--------| diff --git a/todo.md b/todo.md index 022f0307..ddef1b92 100644 --- a/todo.md +++ b/todo.md @@ -12,7 +12,6 @@ | ID | Release | Blocked by | Exempt | Item | L | E | I | R | S | Moves | Score | |---|---|---|---|---|---|---|---|---|---|---|---| -| 232 | 0.4.0 | | decision | **Launch a round's review passes in one message, except a pass that must wait for another's findings, so a round lasts about as long as its slowest reviewers, not their sum.** | 3 | 2 | 3 | 6 | 3 | 1.5 by 6 | 5.8 | | 238 | 0.4.0 | | defect | **Run the security pass's skill in the chunk's worktree, so it scans the branch's diff: invoked from a subagent, it runs in the session's working directory, the main checkout, and scans nothing.** | 2 | 2 | 3 | 5 | 3 | 1.1 by 5 | 5.3 | | 233 | 0.4.0 | | decision | **Run one principles-auditor per round that checks the goals and every principles file that applies, in place of one auditor for each, so the principles pass reads the project once per round.** | 3 | 2 | 3 | 6 | 3 | 1.4 by 3, 1.5 by 2 | 4.9 | | 234 | 0.4.0 | | | **Report the routing figures in dollars, cache reads included, from the cost each archived run records.** | 2 | 2 | 2 | 4 | 3 | 1.4 by 3 | 3.0 | @@ -80,10 +79,6 @@ ## Details -### 232. Launch a round's review passes in one message, except a pass that must wait for another's findings, so a round lasts about as long as its slowest reviewers, not their sum. - -Since 2026-10-21, all 1,372 Agent calls in workers' transcripts were one per message, 94% of them in the foreground, and waiting on subagents took 66% of a worker's active time. larv-review §3 orders the passes so no polish goes into code the architect restructures or the security pass rewrites. Keep that: a pass waits only for a pass whose findings could make its review a waste. Launch the rest of the round's passes, the principles auditors among them, in one message. Do the same for the passes a fix reruns, per §3 → "Re-entry". - ### 238. Run the security pass's skill in the chunk's worktree, so it scans the branch's diff: invoked from a subagent, it runs in the session's working directory, the main checkout, and scans nothing. Found while reviewing PR #376. larv-review §3 → "Security" launches a general-purpose subagent that invokes `/security-review` through the Skill tool. The skill runs its git commands in the session's working directory, the checkout root, where the branch's diff is empty, and the subagent then reads the worktree's diff itself, which the skill's own text forbids as a substitute. The archived security subagents of items 198 and 223 and of PR #376 all report it. It sits in 0.4.0 so the release's remaining chunks get a scan that reads their diff; until then larv-review §3 → "Security" says to run the skill in the worktree. A fix may run the skill as a process in the worktree from larv-review, or have the worker enter the worktree with Claude Code's `EnterWorktree` tool so every subagent runs there. From 83cf3897a7976d704099df57baf5efa7a8c70eb2 Mon Sep 17 00:00:00 2001 From: Lilleman auf Larv Date: Wed, 28 Oct 2026 02:19:40 +0100 Subject: [PATCH 55/55] =?UTF-8?q?Answer=20prose=20round=201:=200=20?= =?UTF-8?q?=F0=9F=94=B4,=207=20=F0=9F=9F=A1=20(0=20misread);=20state=20the?= =?UTF-8?q?=20waves=20in=20the=20imperative,=20cite=20Done,=20skip=20a=20w?= =?UTF-8?q?ave=20none=20of=20whose=20passes=20runs,=20narrow=20the=20claim?= =?UTF-8?q?=20to=20Agent=20calls,=20and=20fix=20the=20changelog's=20timing?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- CHANGELOG.md | 2 +- docs/decisions.md | 2 +- skills/larv-review/SKILL.md | 8 +++----- 3 files changed, 5 insertions(+), 7 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index f475bebc..1378bfc1 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,7 +2,7 @@ ## Unreleased -- larv-review now launches a round's reviewers in up to three waves, each wave's reviewers in one message, in place of one reviewer at a time: first the architect, then the principles auditors with the security and overrides passes, then the stability, product-owner and prose passes. A round now lasts about as long as its slowest reviewer in each wave, not the sum of all of them. +- larv-review now launches a round's reviewers in up to three waves, each wave's reviewers in one message, in place of one reviewer at a time: first the architect, then the principles auditors with the security and overrides passes, then the stability, product-owner and prose passes. Each wave now lasts as long as its slowest reviewer, where a round used to last as long as all its reviewers one after another. - loop-claude's worker, and every subagent it launches, now run with a 200k auto-compact window, handed as `CLAUDE_CODE_AUTO_COMPACT_WINDOW`: Claude Code compacts their context at about 170k tokens, where it used to let it grow to about 967k. loop-claude's judge no longer reads a compaction summary as words you typed. `CLAUDE.md` has a new section, "Compact instructions", saying what a summary keeps. - On Linux, `run-heavy` now caps the memory of a container its command makes with `docker run` or `docker create`. A container that sets no limit gets a memory limit and a swap limit, both the slot's share: three quarters of the machine's memory, split across the heavy slots. A container that sets one of the two limits keeps it, and gets the other as large. This covers containers a project's own scripts start, which rule-hook can't see. A `docker compose` service, and a docker named by its full path, get no cap. rule-hook's `docker-run-memory` now lets a `docker run` under run-heavy pass. - 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. diff --git a/docs/decisions.md b/docs/decisions.md index 781c9731..2480685c 100644 --- a/docs/decisions.md +++ b/docs/decisions.md @@ -95,7 +95,7 @@ The trials: four stability rounds and five principles rounds archived on 2026-10 Quality. 19 chunks compacted between 2026-10-10 and 2026-10-22, at the compaction points Claude Code set then, 214k to 972k tokens. Per 100 worker messages they took a median 3.6 review rounds past each pass's first against 4.0 for the 68 uncompacted chunks of 100 messages or more, and 13.9 🔴 and 🟡 findings against 16.6. 4 of 19 had an unfinished verdict against 3 of 68, each 8 to 10 hours after the compaction and followed by a finished verdict within minutes; in those four verdicts the judge quoted the worker's own passages and the human's typed answers, never a summary. One cause was possible and is closed here: Claude Code writes the summary as a user entry, which `bin/claude_code/entries.py` read as the human's words, so the judge would see a `[human]` line of thousands of words and `/talk` would count it as typed; it now reads as Claude Code's. Whether compaction raises unfinished verdicts stays open until `todo.md` item 235 measures it. Two summaries read whole kept the chunk's intent, files, errors and next step in 12k to 20k characters, and the worker resumed without re-reading. -Hours. A chunk ran a median 0.7 hours from its first message to its last, one in ten past 12 hours, mostly waiting for the human or a usage limit. No option here changes that: a compaction takes 51 to 83 seconds, under a minute per chunk at 0.7 each, and a smaller context saves seconds per turn at most. The hours lever was launching a round's reviewers together, since waiting on subagents took 66% of a worker's active time: larv-review §3 → "Waves" now does, through todo item 232. +Hours. A chunk ran a median 0.7 hours from its first message to its last, one in ten past 12 hours, mostly waiting for the human or a usage limit. No option here changes that: a compaction takes 51 to 83 seconds, under a minute per chunk at 0.7 each, and a smaller context saves seconds per turn at most. Waiting on subagents took 66% of a worker's active time, so the hours lever is launching a round's reviewers together: larv-review §3 → "Waves" now launches each wave's reviewers in one message. Valid while cache reads cost a twentieth of input and Claude Code's compaction keeps the worker's task. diff --git a/skills/larv-review/SKILL.md b/skills/larv-review/SKILL.md index b1b05751..a9969d1f 100644 --- a/skills/larv-review/SKILL.md +++ b/skills/larv-review/SKILL.md @@ -5,7 +5,7 @@ description: Ship a work chunk through review to a merged PR; decisions land in # larv-review — ship the chunk, review until clean, gate green, merge -You orchestrate, fix, and ship; reviewers only report. Run every reviewer synchronously (`run_in_background: false`), a wave's in one message (§3 → "Waves"), and watch CI in the foreground: a headless run exits when the turn ends, and a background watcher dies with it. Never schedule a wakeup: a pending one keeps a headless run from exiting, so loop-claude neither runs its judge nor asks the human. The turn runs on until §6. +You orchestrate, fix, and ship; reviewers only report. Run every reviewer in the foreground (`run_in_background: false`), each wave's reviewers in one message (§3 → "Waves"), and watch CI in the foreground: a headless run exits when the turn ends, and a background watcher dies with it. Never schedule a wakeup: a pending one keeps a headless run from exiting, so loop-claude neither runs its judge nor asks the human. The turn runs on until §6. **Forge-neutral.** Five PR operations recur below: read a PR's diff, open a draft PR, read check status, mark ready, merge. Resolve the tooling from the remote per `~/.claude/CLAUDE.md` → "Git, commits, and PRs"; on any other forge, achieve the same intents through its CLI or API — discover how rather than assuming. A forge without a native draft state gets the closest equivalent (a `WIP:`/`Draft:` title prefix); note any approximation in the summary. @@ -43,14 +43,12 @@ A pass is one kind of review, a row of the table, named by its first column. Its A comment is prose, not code. -**Waves.** A round's passes launch in up to three waves, each wave's reviewers in one message, since line-level polish on code the architect wants restructured, or on a call the security pass will rewrite, is wasted work. A wave waits until every pass of the waves before it is done, and a wave with no pass whose trigger fired is skipped. +**Waves.** Launch a round's passes in up to three waves. Launch each wave's reviewers in one message: Agent calls in one message run together, so a wave lasts as long as its slowest reviewer. Start a wave only once every pass of the waves before it is done ("Round cap" → "Done"): line-level polish on code the architect wants restructured, or on a call the security pass will rewrite, is wasted work. Skip a wave none of whose passes runs. 1. Architecture. 2. Principles, every auditor, with Full scan or Security, and Overrides. 3. Stability, Product-owner and Prose. -Foreground calls in one message run together, so a wave lasts as long as its slowest reviewer. - Give a reviewer without Bash the branch diff and `git ls-files`'s output in its prompt: some harnesses grant it Read alone. `~/.claude/bin/larv-review` holds this section's mechanical rules: the chunk's review folder, the round count, the paired ruling's base and vote count, the scoring run's trigger, and the history's format and latest places, and its count of how often seats agree. Run it in the chunk's worktree; `~/.claude/bin/larv-review --help` states each rule. On exit 1, repair what its message names and run it again; when you cannot, ask the user. @@ -78,7 +76,7 @@ Give a reviewer without Bash the branch diff and `git ls-files`'s output in its - **Cap.** A pass takes at most three rounds per chunk. Instead of a fourth, list what is open and ask the user. For the auto-reviewer, ask before the push that would summon its fourth, and hold the fixes unpushed until the answer. - **Answer.** A yes grants that pass one more round, after which the ask repeats; a no leaves the PR unmerged. rule-hook refuses a round commit titled past round 3 unless its `round-cap` override quotes the yes. -**Re-entry.** A fix is a change no pass has seen. A fix for a 🟢, a ❓ or a prose finding reruns no pass, whatever it changes. A round's fixes for 🔴 and 🟡 findings re-enter together: run, in "Waves", every pass that a row below names for any of them, a done pass included, then §4. A pass at its cap gets "Round cap" → "Cap"'s ask instead. +**Re-entry.** A fix is a change no pass has seen. A fix for a 🟢, a ❓ or a prose finding reruns no pass, whatever it changes. A round's fixes for 🔴 and 🟡 findings re-enter together: run every pass that a row below names for any of them, a done pass included, in the waves of "Waves", then §4. A pass at its cap gets "Round cap" → "Cap"'s ask instead. | The fix | Reruns | |---------|--------|