From 51e7389a437084c433b11e6c3331673b2ed952d0 Mon Sep 17 00:00:00 2001 From: Scott McCarty Date: Wed, 4 Nov 2026 07:29:05 -0500 Subject: [PATCH 1/2] fix: v0.2.2 the launcher no longer hangs inside a container The CPU budget walked the cgroup tree up to /sys/fs/cgroup with dirname and stopped only on an exact match. Inside a container with its own cgroup namespace -- podman's default, and the self-hosted GitHub runner -- the path is "/", so the walk began at "/sys/fs/cgroup/", passed it, reached "/" and dirname'd "/" forever, before any output. trentina's first `sdlc ci` on gloval sat for 30 minutes doing nothing. The walk now ends at the root or anywhere outside it, and reads the root too, which is where a container's own cpu.max lives: a 4-CPU container budgets 2 instead of half the host. tests/contract.sh runs the launcher in a container with a 20-second limit. Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_01R7Y1jfy8tZHovMEJUNjjD2 --- CHANGELOG.md | 20 +++++++++++++++++++- Containerfile | 2 +- IMAGE_TAG | 2 +- README.md | 2 +- bin/sdlc | 20 ++++++++++++++++---- pyproject.toml | 2 +- tests/contract.sh | 23 +++++++++++++++++++++++ 7 files changed, 62 insertions(+), 9 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 3392eaf..d922535 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,6 +6,23 @@ All notable changes to this project are documented here, following ## [Unreleased] +## [0.2.2] - 2026-11-04 + +### Fixed + +- **Every command hung inside a container.** The CPU budget walks the cgroup + tree up to `/sys/fs/cgroup` with `dirname`, and stopped only on an exact + match. Inside a container with its own cgroup namespace -- podman's default, + and the self-hosted GitHub runner -- `/proc/self/cgroup` says `0::/`, so the + walk started at `/sys/fs/cgroup/`, passed it, reached `/` and dirname'd `/` + forever, before printing a line. trentina's first `sdlc ci` on that runner sat + for 30 minutes. The walk now ends at the root or anywhere outside it. +- **A container's CPU quota was never read.** The walk skipped the namespace + root, which is exactly where a container's own `cpu.max` lives; it now reads + it, so a run in a 4-CPU container budgets 2 rather than half the host. +- `tests/contract.sh` runs the launcher inside a container and fails if it does + not finish in 20 seconds. + ## [0.2.1] - 2026-11-04 ### Fixed @@ -165,7 +182,8 @@ cached tag was never refreshed — that gate had been running a two-week-old reviewer while CI pulled fresh. Local and CI were different reviewers on the same diff. -[Unreleased]: https://github.com/crunchtools/python-sdlc/compare/v0.2.1...HEAD +[Unreleased]: https://github.com/crunchtools/python-sdlc/compare/v0.2.2...HEAD +[0.2.2]: https://github.com/crunchtools/python-sdlc/releases/tag/v0.2.2 [0.2.1]: https://github.com/crunchtools/python-sdlc/releases/tag/v0.2.1 [0.2.0]: https://github.com/crunchtools/python-sdlc/releases/tag/v0.2.0 [0.1.0]: https://github.com/crunchtools/python-sdlc/releases/tag/v0.1.0 diff --git a/Containerfile b/Containerfile index b15bb3d..2586ab5 100644 --- a/Containerfile +++ b/Containerfile @@ -44,7 +44,7 @@ LABEL description="Every CrunchTools Python SDLC check in one image: ruff, mypy, LABEL org.opencontainers.image.source="https://github.com/crunchtools/python-sdlc" LABEL org.opencontainers.image.description="Every CrunchTools Python SDLC check in one image." LABEL org.opencontainers.image.licenses="AGPL-3.0-or-later" -LABEL version="0.2.1" +LABEL version="0.2.2" # What the image carries, readable without starting anything. `sdlc versions` # prints these and a consuming repo's CI pins them. diff --git a/IMAGE_TAG b/IMAGE_TAG index 0c62199..ee1372d 100644 --- a/IMAGE_TAG +++ b/IMAGE_TAG @@ -1 +1 @@ -0.2.1 +0.2.2 diff --git a/README.md b/README.md index 557cdcd..44f835d 100644 --- a/README.md +++ b/README.md @@ -36,7 +36,7 @@ default_install_hook_types: [pre-commit, pre-push] repos: - repo: https://github.com/crunchtools/python-sdlc - rev: v0.2.1 + rev: v0.2.2 hooks: - id: sdlc-commit - id: sdlc-push diff --git a/bin/sdlc b/bin/sdlc index 32b7329..27f3bb3 100755 --- a/bin/sdlc +++ b/bin/sdlc @@ -76,10 +76,19 @@ _cpus_in_list() { # "0-3,7,10-11" -> 7 _cgroup_cpu_ceiling() { # cpu.max from leaf to root, smallest quota wins _dir=$(awk -F: '$2=="" {print $3; exit}' /proc/self/cgroup 2>/dev/null) || _dir= - [ -n "${_dir:-}" ] || { printf '0'; return; } + # Inside a container with its own cgroup namespace -- podman's default, and + # the GitHub runner on gloval -- the path is "/" or climbs with "..". Both + # mean "the namespace root", which is /sys/fs/cgroup itself, and the root is + # exactly where a container's quota lives, so it is read, not skipped. + case "$_dir" in /|*..*) _dir= ;; esac + _path="/sys/fs/cgroup${_dir%/}" _best=0 - _path="/sys/fs/cgroup$_dir" - while [ -n "$_path" ] && [ "$_path" != "/sys/fs/cgroup" ]; do + # The walk ends AT /sys/fs/cgroup or anywhere outside it, never by hoping + # dirname lands there exactly. It used to stop only on an exact match, so + # "/sys/fs/cgroup/" walked to "/" and then dirname'd "/" forever: every + # command, `--help` included, hung inside a container before printing a + # line. That was 30 minutes of a CI job doing nothing. + while :; do if [ -r "$_path/cpu.max" ]; then _q=$(awk '{print $1}' "$_path/cpu.max" 2>/dev/null) || _q=max _p=$(awk '{print $2}' "$_path/cpu.max" 2>/dev/null) || _p=100000 @@ -89,7 +98,10 @@ _cgroup_cpu_ceiling() { # cpu.max from leaf to root, smallest quota wins if [ "$_best" -eq 0 ] || [ "$_n" -lt "$_best" ]; then _best=$_n; fi fi fi - _path=$(dirname "$_path") + case "$_path" in + /sys/fs/cgroup/*) _path=$(dirname "$_path") ;; + *) break ;; + esac done printf '%s' "$_best" } diff --git a/pyproject.toml b/pyproject.toml index 8cf8088..582a207 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -10,7 +10,7 @@ [project] name = "python-sdlc" -version = "0.2.1" +version = "0.2.2" description = "One container image and one script for every CrunchTools Python SDLC check" requires-python = ">=3.14" license = "AGPL-3.0-or-later" diff --git a/tests/contract.sh b/tests/contract.sh index f99a058..8806ccf 100755 --- a/tests/contract.sh +++ b/tests/contract.sh @@ -275,6 +275,29 @@ else ok "semgrep fails on code its rule forbids" fi +# ---------------------------------- the launcher runs inside a container +# +# bin/sdlc's CPU budget walks the cgroup tree, and inside a container with its +# own cgroup namespace -- podman's default, and the self-hosted GitHub runner -- +# /proc/self/cgroup says "0::/". The walk once never terminated there, so every +# command hung before printing a line; a CI job sat for 30 minutes. Run it in a +# container, with shims for the two programs it checks for, and give it 20 +# seconds. +LSHIM=$(mktemp -d) +printf '#!/bin/sh\ncase "$*" in *show-toplevel*) pwd ;; esac\nexit 0\n' > "$LSHIM/git" +printf '#!/bin/sh\nexit 0\n' > "$LSHIM/podman" +chmod +x "$LSHIM/git" "$LSHIM/podman" +rc=0 +podman run --rm -v "$PWD:/s:ro,z" -v "$LSHIM:/shim:ro,z" -w /s \ + -e PATH=/shim:/usr/bin:/bin registry.fedoraproject.org/fedora:43 \ + timeout 20 sh bin/sdlc --help >/dev/null 2>&1 || rc=$? +rm -rf "$LSHIM" +if [ "$rc" -eq 0 ]; then + ok "bin/sdlc runs inside a container (cgroup namespace root)" +else + bad "bin/sdlc inside a container exited $rc (124 means it hung)" +fi + # --------------------------------------- `sdlc versions` matches the build pins # # The version table is the image's central promise: a consuming repo pins this From 5b2c33fc1d4e9b0fb921e35d75a38b5108bf440c Mon Sep 17 00:00:00 2001 From: Scott McCarty Date: Wed, 4 Nov 2026 07:31:21 -0500 Subject: [PATCH 2/2] fix: treat only a ".." component as the namespace root `*..*` also matched a legal cgroup name with two dots in it, such as `job..scope`, and would have skipped that path's quota. Gatehouse found it. Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_01R7Y1jfy8tZHovMEJUNjjD2 --- bin/sdlc | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/bin/sdlc b/bin/sdlc index 27f3bb3..c6ebdc4 100755 --- a/bin/sdlc +++ b/bin/sdlc @@ -80,7 +80,8 @@ _cgroup_cpu_ceiling() { # cpu.max from leaf to root, smallest quota wins # the GitHub runner on gloval -- the path is "/" or climbs with "..". Both # mean "the namespace root", which is /sys/fs/cgroup itself, and the root is # exactly where a container's quota lives, so it is read, not skipped. - case "$_dir" in /|*..*) _dir= ;; esac + # A ".." COMPONENT, not any two dots: `job..scope` is a legal cgroup name. + case "$_dir" in /|/..|/../*|*/../*|*/..) _dir= ;; esac _path="/sys/fs/cgroup${_dir%/}" _best=0 # The walk ends AT /sys/fs/cgroup or anywhere outside it, never by hoping