From 0f993d192942452ece548e1d66615239bb49fa74 Mon Sep 17 00:00:00 2001 From: Scott McCarty Date: Fri, 6 Nov 2026 09:33:54 +0000 Subject: [PATCH 1/4] fix: the host clones the constitution, so the gate needs no warm cache validate cloned crunchtools/constitution from inside the gate container. On a gateway seat that clone goes through a CONNECT proxy that refuses github.com; the route to GitHub is a git insteadOf in the host's config, which the container never reads. A warm cache volume hid it; an empty one was a gate that could not run (claude-agent#9, developer3). bin/sdlc now clones the pinned tag with the host's git, once per tag under ~/.cache/python-sdlc/constitution, and mounts it read-only where validate already looks. No git config or credentials cross into the container. A failed host clone changes nothing: validate tries its own and reports a 2. Release 0.5.1. Co-Authored-By: Claude Opus 5.5 --- CHANGELOG.md | 16 ++++++++++++++++ Containerfile | 2 +- IMAGE_TAG | 2 +- bin/sdlc | 38 ++++++++++++++++++++++++++++++++++++++ pyproject.toml | 2 +- 5 files changed, 57 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index e351e03..ed68e0d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,6 +6,22 @@ All notable changes to this project are documented here, following ## [Unreleased] +## [0.5.1] - 2026-11-06 + +### Fixed + +- **The constitution gate no longer depends on a warm cache.** `validate` + clones crunchtools/constitution from inside the container, which on a gateway + seat goes through a CONNECT proxy that refuses github.com -- the route to + GitHub there is a git `insteadOf` in the host's git config, which the + container never reads. A seat whose cache volume already held the pinned tag + passed; an empty volume, or a repo moving to a tag nobody had fetched, was a + gate that could not run. `bin/sdlc` now makes that clone with the host's git, + once per tag under `~/.cache/python-sdlc/constitution/`, and mounts it + read-only where `validate` already looks. The container still gets no git + config or credentials. If the host clone fails, nothing changes: `validate` + tries its own and reports a 2 as before. + ## [0.5.0] - 2026-11-05 ### Changed diff --git a/Containerfile b/Containerfile index 22c1f68..270b3cc 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.5.0" +LABEL version="0.5.1" # 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 8f0916f..4b9fcbe 100644 --- a/IMAGE_TAG +++ b/IMAGE_TAG @@ -1 +1 @@ -0.5.0 +0.5.1 diff --git a/bin/sdlc b/bin/sdlc index 9879d60..00850d5 100755 --- a/bin/sdlc +++ b/bin/sdlc @@ -172,6 +172,43 @@ need_volume() { podman volume exists "$1" 2>/dev/null || die "cannot create the podman volume $1" } +# ------------------------------------------------- the constitution, by the host +# +# `validate` clones crunchtools/constitution at the tag the repo pins, into the +# cache volume. From inside the container that clone takes whatever route the +# network gives a container, and on a gateway seat that is a CONNECT proxy that +# refuses github.com: the route to GitHub there is a git `insteadOf` in the +# HOST's git config, which the container never reads. A warm cache volume hid +# it; an empty one, or a repo moving to a tag nobody has fetched, was a gate +# that could not run (claude-agent#9, developer3, 2026-11-06). +# +# So the host's git makes the clone, once per tag, and the checkout is mounted +# read-only at the path `validate` already looks in. The container still gets +# no git config and no credentials -- what crosses is a public repo's files. +# Done once here, before any lane forks, so two lanes never race one clone. +# Every failure is silent on purpose: without the mount `validate` tries its +# own clone and reports a 2 exactly as it did before. +CONSTITUTION_MOUNT= +host_constitution() { + _manifest=$REPO/.specify/memory/constitution.md + [ -f "$_manifest" ] || return 0 + _tag=$(awk '/^>[ \t]*\*\*Inherits:\*\*/ { + if (match($0, /v[0-9]+\.[0-9]+\.[0-9]+/)) print substr($0, RSTART, RLENGTH) + exit + }' "$_manifest") + [ -n "$_tag" ] || return 0 + _dir=${XDG_CACHE_HOME:-$HOME/.cache}/python-sdlc/constitution/$_tag + if [ ! -f "$_dir/constitution.md" ]; then + rm -rf "$_dir" + mkdir -p "$_dir" 2>/dev/null || return 0 + git clone --quiet --depth 1 --branch "$_tag" \ + https://github.com/crunchtools/constitution "$_dir" >/dev/null 2>&1 \ + || { rm -rf "$_dir"; return 0; } + fi + CONSTITUTION_MOUNT="$_dir:/cache/constitution/$_tag:ro,z" +} +host_constitution + # ------------------------------------------------------------------ podman run # # `z`, not `Z`: more than one of these can mount the same tree at once, and `Z` @@ -221,6 +258,7 @@ run_in_image() { --cpus "$GATE_CPUS" --memory "$GATE_MEMORY" --cpu-shares 256 \ -v "$REPO:/repo:$_mode,z" -w /repo \ -v "$CACHE_VOLUME:/cache" \ + ${CONSTITUTION_MOUNT:+-v "$CONSTITUTION_MOUNT"} \ --tmpfs /tmp:rw,exec,size=4g,mode=1777 \ -e HOME=/tmp \ -e PYTHONPYCACHEPREFIX=/tmp/pycache \ diff --git a/pyproject.toml b/pyproject.toml index 7b034c8..b73a6b8 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -10,7 +10,7 @@ [project] name = "python-sdlc" -version = "0.5.0" +version = "0.5.1" description = "One container image and one script for every CrunchTools Python SDLC check" requires-python = ">=3.14" license = "AGPL-3.0-or-later" From 0e58fd491d1a2b785fd2a1154475ca80f1edb8df Mon Sep 17 00:00:00 2001 From: Scott McCarty Date: Fri, 6 Nov 2026 09:49:51 +0000 Subject: [PATCH 2/4] fix: concurrent runs publish the constitution clone with ln -sn, not rm -rf Two sdlc runs on one tag could delete each other's clone in progress. Each now clones into its own mktemp directory and publishes it with ln -sn; the loser removes only its own copy and uses the winner's. Co-Authored-By: Claude Opus 5.5 --- bin/sdlc | 21 +++++++++++++-------- 1 file changed, 13 insertions(+), 8 deletions(-) diff --git a/bin/sdlc b/bin/sdlc index 00850d5..40c7a30 100755 --- a/bin/sdlc +++ b/bin/sdlc @@ -185,9 +185,11 @@ need_volume() { # So the host's git makes the clone, once per tag, and the checkout is mounted # read-only at the path `validate` already looks in. The container still gets # no git config and no credentials -- what crosses is a public repo's files. -# Done once here, before any lane forks, so two lanes never race one clone. -# Every failure is silent on purpose: without the mount `validate` tries its -# own clone and reports a 2 exactly as it did before. +# Done once here, before any lane forks. Two sdlc runs -- two repos on one tag +# -- can still meet, so each clones into its own directory and publishes it +# with `ln -sn`, which only one of them can win; the loser removes only its own +# copy and uses the winner's. Every failure is silent on purpose: without the +# mount `validate` tries its own clone and reports a 2 exactly as it did before. CONSTITUTION_MOUNT= host_constitution() { _manifest=$REPO/.specify/memory/constitution.md @@ -197,13 +199,16 @@ host_constitution() { exit }' "$_manifest") [ -n "$_tag" ] || return 0 - _dir=${XDG_CACHE_HOME:-$HOME/.cache}/python-sdlc/constitution/$_tag + _root=${XDG_CACHE_HOME:-$HOME/.cache}/python-sdlc/constitution + _dir=$_root/$_tag if [ ! -f "$_dir/constitution.md" ]; then - rm -rf "$_dir" - mkdir -p "$_dir" 2>/dev/null || return 0 + mkdir -p "$_root" 2>/dev/null || return 0 + _own=$(mktemp -d "$_root/.$_tag.XXXXXX" 2>/dev/null) || return 0 git clone --quiet --depth 1 --branch "$_tag" \ - https://github.com/crunchtools/constitution "$_dir" >/dev/null 2>&1 \ - || { rm -rf "$_dir"; return 0; } + https://github.com/crunchtools/constitution "$_own" >/dev/null 2>&1 \ + || { rm -rf "$_own"; return 0; } + ln -sn "${_own##*/}" "$_dir" 2>/dev/null || rm -rf "$_own" + [ -f "$_dir/constitution.md" ] || return 0 fi CONSTITUTION_MOUNT="$_dir:/cache/constitution/$_tag:ro,z" } From ccaf13b47b6244f0a049073a88866c28706dc0f7 Mon Sep 17 00:00:00 2001 From: Scott McCarty Date: Fri, 6 Nov 2026 09:53:14 +0000 Subject: [PATCH 3/4] test: concurrent runs on a cold cache leave one constitution checkout Three bin/sdlc runs start at once against an offline git whose clone is slow. Passes with ln -sn; fails on the ln -s that nested the losers' links. Co-Authored-By: Claude Opus 5.5 --- tests/test_host_contract.sh | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) diff --git a/tests/test_host_contract.sh b/tests/test_host_contract.sh index 52e87bd..d3f19a8 100755 --- a/tests/test_host_contract.sh +++ b/tests/test_host_contract.sh @@ -607,6 +607,40 @@ else bad "$locked of ${runs:-0} gate containers dropped capabilities" fi +# The constitution is cloned by the HOST's git and published with `ln -sn`, so +# runs that meet on a cold cache never delete each other's clone. Three run at +# once against a git whose clone is slow and offline; what must be left is one +# checkout, one link to it, and no loser's copy. +CLONESHIM=$(mktemp -d) +CLONECACHE=$(mktemp -d) +for prog in $POSIX_UTILS podman pre-commit gh; do + [ -e "$SHIM/$prog" ] && ln -s "$(readlink -f "$SHIM/$prog")" "$CLONESHIM/$prog" +done +REALGIT=$(command -v git) +cat > "$CLONESHIM/git" < "\$dest/constitution.md" ;; + *) exec "$REALGIT" "\$@" ;; +esac +EOF +chmod +x "$CLONESHIM/git" +for _ in 1 2 3; do + PATH="$CLONESHIM" XDG_CACHE_HOME="$CLONECACHE" sh bin/sdlc hooks-installed >/dev/null 2>&1 & +done +wait +_root="$CLONECACHE/python-sdlc/constitution" +_links=$(find "$_root" -mindepth 1 -maxdepth 1 -type l | wc -l | tr -d ' ') +_dirs=$(find "$_root" -mindepth 1 -maxdepth 1 -type d | wc -l | tr -d ' ') +_nested=$(find "$_root" -mindepth 2 -name '.v*' | wc -l | tr -d ' ') +if [ "$_links" = 1 ] && [ "$_dirs" = 1 ] && [ "$_nested" = 0 ] \ + && [ -f "$(find "$_root" -mindepth 1 -maxdepth 1 -type l)/constitution.md" ]; then + ok "three runs on a cold cache leave one constitution checkout and one link" +else + bad "concurrent constitution clones left $_links link(s), $_dirs dir(s), $_nested nested" +fi +rm -rf "$CLONESHIM" "$CLONECACHE" + printf '\n' if [ "$FAILED" -eq 0 ]; then printf 'host contract PASSED\n'; exit 0 From b6fc416841470b2403e40d9e8629bb20e995deac Mon Sep 17 00:00:00 2001 From: Scott McCarty Date: Fri, 6 Nov 2026 09:59:45 +0000 Subject: [PATCH 4/4] test: racing constitution runs must exit as a run alone does Co-Authored-By: Claude Opus 5.5 --- tests/test_host_contract.sh | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/tests/test_host_contract.sh b/tests/test_host_contract.sh index d3f19a8..1b17cca 100755 --- a/tests/test_host_contract.sh +++ b/tests/test_host_contract.sh @@ -625,10 +625,27 @@ case "\$1" in esac EOF chmod +x "$CLONESHIM/git" +# The check's own verdict depends on the checkout (CI has no pre-push hook), so +# each concurrent run must match one that had a cache to itself. +_solo=$(mktemp -d) +PATH="$CLONESHIM" XDG_CACHE_HOME="$_solo" sh bin/sdlc hooks-installed >/dev/null 2>&1 \ + && _want=0 || _want=$? +rm -rf "$_solo" +_pids= for _ in 1 2 3; do PATH="$CLONESHIM" XDG_CACHE_HOME="$CLONECACHE" sh bin/sdlc hooks-installed >/dev/null 2>&1 & + _pids="$_pids $!" done -wait +_odd=0 +for _pid in $_pids; do + wait "$_pid" && _got=0 || _got=$? + [ "$_got" = "$_want" ] || _odd=$((_odd + 1)) +done +if [ "$_odd" = 0 ]; then + ok "three runs racing one cold cache each exit $_want, as a run alone does" +else + bad "$_odd of 3 runs racing one cold cache did not exit $_want" +fi _root="$CLONECACHE/python-sdlc/constitution" _links=$(find "$_root" -mindepth 1 -maxdepth 1 -type l | wc -l | tr -d ' ') _dirs=$(find "$_root" -mindepth 1 -maxdepth 1 -type d | wc -l | tr -d ' ')