diff --git a/CHANGELOG b/CHANGELOG index 0eee1a0..1e0ce1c 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -18,6 +18,10 @@ Unreleased volume, own checkouts over the baked trees. It is copied into the image. + • scripts/docker/spear bounds the container's memory and processes + and tells the harness so. Without it the terminal of a session + started from that launcher refused every command. + • In an image, Claude Code starts from what a SPEAR request starts from: beside the rules and skills, the learned rules, the corpus's map and the project's build and test commands are laid out as rule diff --git a/client/tests/test_reds_image.py b/client/tests/test_reds_image.py index a1c3d47..515f16e 100644 --- a/client/tests/test_reds_image.py +++ b/client/tests/test_reds_image.py @@ -549,6 +549,15 @@ def test_the_image_gives_a_prompt_of_the_other_assistant_what_a_turn_gets(self): self.assertIn("spear-claude-setup", (REPO / "docker" / "claude-launcher").read_text()) self.assertIn("spear-claude-setup", (REPO / "docker" / "spear-shell").read_text()) + def test_the_container_is_bounded_and_the_harness_told(self): + """The harness refuses a command nothing bounds; the limits and the + word that they exist are on the same docker run.""" + run = self.SCRIPT.read_text().split("exec docker run", 1)[1] + + for flag in ('--memory "$MEMORY"', "--pids-limit", + "-e SPEAR_RESOURCE_CONTROL=delegated"): + self.assertIn(flag, run) + def test_the_image_carries_it(self): dockerfile = (REPO / "docker" / "Dockerfile").read_text() diff --git a/doc/source/start/container_run.rst b/doc/source/start/container_run.rst index f022623..6586e6b 100644 --- a/doc/source/start/container_run.rst +++ b/doc/source/start/container_run.rst @@ -118,6 +118,8 @@ container reaches it through an SSH tunnel you open on your machine. --security-opt seccomp=unconfined \ --security-opt apparmor=unconfined \ --security-opt systempaths=unconfined \ + --memory 16g --memory-swap 16g --pids-limit 4096 \ + -e SPEAR_RESOURCE_CONTROL=delegated \ --network host \ --user "$(id -u):$(id -g)" \ -e SPEAR_API_BASE=http://127.0.0.1:8082/v1 \ @@ -127,6 +129,12 @@ container reaches it through an SSH tunnel you open on your machine. -w /corpora/opencn/opencn-ng \ ghcr.io/smartobjectoriented/spear-reds:-reds --ask + The limits and ``SPEAR_RESOURCE_CONTROL=delegated`` go together: the + harness refuses to run a command that nothing bounds, and in a container + Docker is what bounds it (:ref:`resource_control`). The launcher gives + the container three quarters of the machine's memory; + ``SPEAR_CONTAINER_MEMORY`` in the configuration file names another bound. + The paths under ``/corpora`` are those of the building machine, relative to its home: ``opencn/opencn-ng`` (and ``opencn/opencn-ng/linux/usr``), ``soo/so3/so3``, ``soo/so3/doc``, ``sye/sye_sol``, diff --git a/scripts/docker/spear b/scripts/docker/spear index 8f6f920..6491ddd 100755 --- a/scripts/docker/spear +++ b/scripts/docker/spear @@ -320,12 +320,23 @@ TTY=(-i); [ -t 0 ] && TTY=(-i -t) NAME="spear-$(printf '%s' "${WORKDIR##*/}" | tr -c 'A-Za-z0-9_.-' '-')-$$" +# The harness bounds what each command may take, and refuses to run one when +# nothing does. A container has no systemd to do it per command, so Docker +# bounds the container and the harness is told so: the limits and the variable +# go together. They hold your own builds too, hence most of the machine; +# SPEAR_CONTAINER_MEMORY in the configuration file names another bound. + +MEMORY="${SPEAR_CONTAINER_MEMORY:-$(awk '/^MemTotal:/ { printf "%dm", $2 * 3 / 4 / 1024 }' /proc/meminfo)}" + # The three --security-opt are what bubblewrap, the harness's sandbox, needs # to start inside a container; without them it refuses every command. + exec docker run --rm --name "$NAME" "${TTY[@]}" \ --security-opt seccomp=unconfined \ --security-opt apparmor=unconfined \ --security-opt systempaths=unconfined \ + --memory "$MEMORY" --memory-swap "$MEMORY" --pids-limit 4096 \ + -e SPEAR_RESOURCE_CONTROL=delegated \ --network host \ --user "$(id -u):$(id -g)" \ "${BACKEND[@]}" \