Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
a718707
SEL-286: Gateway images omit `b2a_sdk`, so app import crashes
PetrefiedThunder Oct 19, 2026
512fa3f
SEL-285: Production image build copies a gitignored file that is not …
PetrefiedThunder Oct 19, 2026
904dde3
Validate root release stamp separately from image output
PetrefiedThunder Oct 19, 2026
cfbe6a6
Merge SDK image contract with validated release stamp
PetrefiedThunder Oct 19, 2026
9b3ab29
Cover stamp-free development image
PetrefiedThunder Oct 19, 2026
dfadd75
SEL-286: Gateway images omit `b2a_sdk`, so app import crashes
PetrefiedThunder Oct 19, 2026
45ef252
ci: smoke-test gateway image imports
PetrefiedThunder Oct 19, 2026
26313c1
Merge updated SDK image smoke proof into stamped image branch
PetrefiedThunder Oct 19, 2026
aa5c214
Prove release metadata stamp inputs in image smoke job
PetrefiedThunder Oct 19, 2026
3a9e744
Merge main Postgres proof gate into PR #127
PetrefiedThunder Oct 19, 2026
9437b41
Merge commit '3a9e744b1ad88ba29c6337a8a8fe3cc5257eca55' into repair-p…
PetrefiedThunder Oct 19, 2026
f0069b5
ci: keep local gateway state out of image contexts
PetrefiedThunder Oct 19, 2026
62000ac
Merge gateway context canary repair into build stamp image
PetrefiedThunder Oct 19, 2026
8d167c7
ci: exclude nested local tooling from image context
PetrefiedThunder Oct 19, 2026
843205f
Merge commit '8d167c78ce0b11db392f9a5fb0f64b83d0aa3ffb' into repair-p…
PetrefiedThunder Oct 19, 2026
144faea
Test nested workstation exclusions in gateway context
PetrefiedThunder Oct 19, 2026
1261fa0
Merge latest main packaging changes into PR #127
PetrefiedThunder Oct 19, 2026
16c511f
Merge commit '1261fa08a7fa5a473daf2425f52a0c4abe616027' into repair-p…
PetrefiedThunder Oct 19, 2026
380caee
fix: validate gateway image commit stamp
PetrefiedThunder Oct 19, 2026
c41d177
Merge published #143 history into refreshed candidate
PetrefiedThunder Oct 19, 2026
f8c55ad
fix: retain gateway image and stamp proof on current main
PetrefiedThunder Oct 19, 2026
53b012b
Merge published #143 history into current-main candidate
PetrefiedThunder Oct 19, 2026
0620c1a
Merge remote-tracking branch 'origin/main' into fix/SEL-285
PetrefiedThunder Oct 19, 2026
b46086f
fix: resolve CI and update with main (SEL-285 retry pass, codex)
PetrefiedThunder Oct 19, 2026
02a0d5a
ci: retrigger checks after GitHub startup_failure (SEL-285)
PetrefiedThunder Oct 19, 2026
a199929
Merge branch 'main' into agent/cursor/sel-285
PetrefiedThunder Oct 20, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 13 additions & 10 deletions .dockerignore
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,18 @@
**/.vercel
.railway
**/.railway
.aws
**/.aws
.ssh
**/.ssh
.npmrc
**/.npmrc
.pypirc
**/.pypirc
.netrc
**/.netrc
.secrets
**/.secrets
.venv
**/.venv
.venv-local
Expand All @@ -21,16 +33,6 @@ env
**/env
node_modules
**/node_modules
.aws
**/.aws
.ssh
**/.ssh
.netrc
**/.netrc
.npmrc
**/.npmrc
.pypirc
**/.pypirc
.pytest_cache
**/.pytest_cache
.ruff_cache
Expand Down Expand Up @@ -63,6 +65,7 @@ railway.json
**/railway.json
railway.toml
**/railway.toml
gateway/.build_commit_sha
gateway/tests
gateway/data
gateway/docker-compose.yml
Expand Down
67 changes: 66 additions & 1 deletion .github/scripts/smoke_gateway_image.sh
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@ if [[ -e .build_commit_sha || -L .build_commit_sha ]]; then
echo '.build_commit_sha already exists; refusing to replace it' >&2
exit 1
fi
if [[ -e gateway/.build_commit_sha || -L gateway/.build_commit_sha ]]; then
echo 'gateway/.build_commit_sha already exists; refusing to replace it' >&2
exit 1
fi

canary_paths=(
gateway/data/quickstart/signing-seed.b64
Expand Down Expand Up @@ -71,19 +75,38 @@ image_canaries=(
/sdk/python/.amw-image-smoke.key
)
stamp="$(git rev-parse HEAD)"
other=bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb
printf '%s\n' "$stamp" > .build_commit_sha
printf '%s\n' "$other" > gateway/.build_commit_sha
stamp_created=true
created_files+=(gateway/.build_commit_sha)

docker build -f gateway/Dockerfile -t amw-gateway:ci-release .
docker run --rm --network none --read-only --entrypoint python amw-gateway:ci-release -c '
import sys
from pathlib import Path
import app.main
import b2a_sdk.receipt_verifier
assert Path("/app/.build_commit_sha").read_text().strip() == sys.argv[1]
assert Path("/app/.build_commit_sha").read_bytes() == (sys.argv[1] + "\n").encode()
assert all(not Path(path).exists() for path in sys.argv[2:])
' "$stamp" "${image_canaries[@]}"

docker build --target build-metadata -f gateway/Dockerfile -t amw-gateway:ci-metadata .
docker run --rm --network none --read-only --user 65534:65534 \
--entrypoint python amw-gateway:ci-metadata -c '
import sys
from pathlib import Path
root = Path("/context")
expected = (sys.argv[1] + "\n").encode()
assert (root / ".build_commit_sha").read_bytes() == expected
assert Path("/stamp/.build_commit_sha").read_bytes() == expected
assert (root / "sdk/python/src/b2a_sdk/receipt_verifier.py").is_file()
assert (root / "gateway/scripts/write_build_commit_sha.py").is_file()
assert not (root / "gateway/data").exists()
assert not (root / "gateway/.build_commit_sha").exists()
assert all(not (root / path).exists() for path in sys.argv[2:])
' "$stamp" "${canary_paths[@]}"

rm .build_commit_sha
docker build -f gateway/Dockerfile.dev -t amw-gateway:ci-dev .
docker run --rm --network none --read-only --entrypoint python amw-gateway:ci-dev -c '
Expand All @@ -94,3 +117,45 @@ import b2a_sdk.receipt_verifier
assert not Path("/app/.build_commit_sha").exists()
assert all(not Path(path).exists() for path in sys.argv[1:])
' "${image_canaries[@]}"

# Negative cases build only the small metadata stage. The nested stamp remains
# on disk but is excluded from the root Docker context by .dockerignore.
expect_metadata_failure() {
if docker build --target build-metadata -f gateway/Dockerfile "$@" .; then
echo "metadata stage accepted invalid provenance: $*" >&2
exit 1
fi
}

check_metadata_stamp() {
local image="$1"
docker run --rm --network none --read-only --user 65534:65534 \
--entrypoint python "$image" -c '
import sys
from pathlib import Path
assert Path("/stamp/.build_commit_sha").read_bytes() == (sys.argv[1] + "\n").encode()
' "$stamp"
}

# A gateway-local stamp cannot supply provenance, even when valid.
expect_metadata_failure

# Argument-only provenance is accepted and written in canonical lowercase.
docker build --target build-metadata -f gateway/Dockerfile \
--build-arg "RELEASE_COMMIT_SHA=${stamp^^}" -t amw-gateway:ci-metadata .
check_metadata_stamp amw-gateway:ci-metadata

rm gateway/.build_commit_sha
expect_metadata_failure # neither root stamp nor argument exists
COMMIT_SHA="$stamp" BUILD_COMMIT_SHA="$stamp" expect_metadata_failure

printf '%s\n' "${stamp^^}" > .build_commit_sha
docker build --target build-metadata -f gateway/Dockerfile \
--build-arg "RELEASE_COMMIT_SHA=$stamp" -t amw-gateway:ci-metadata .
check_metadata_stamp amw-gateway:ci-metadata

expect_metadata_failure --build-arg "RELEASE_COMMIT_SHA=$other"
expect_metadata_failure --build-arg RELEASE_COMMIT_SHA=not-a-sha

printf 'not-a-sha\n' > .build_commit_sha
expect_metadata_failure --build-arg "RELEASE_COMMIT_SHA=$stamp"
18 changes: 16 additions & 2 deletions gateway/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,3 +1,16 @@
FROM python:3.12-slim AS build-metadata

# The release archive may carry a gitignored stamp at its context root.
# Copying the context lets the writer validate that optional input without a
# named COPY that fails on clean trees. .dockerignore excludes local secrets.
WORKDIR /context
COPY . /context/
ARG RELEASE_COMMIT_SHA
RUN mkdir /stamp \
&& STAGED_SHA_PATH=/context/.build_commit_sha \
BUILD_SHA_PATH=/stamp/.build_commit_sha \
python /context/gateway/scripts/write_build_commit_sha.py

FROM python:3.12-slim

WORKDIR /app
Expand All @@ -24,8 +37,9 @@ RUN pip install --no-cache-dir -r /tmp/requirements.txt \
# Copy application code
COPY gateway/ /app/

# Release contexts must carry a commit stamp generated from the exact Git tree.
COPY .build_commit_sha /app/.build_commit_sha
# Transfer only the validated stamp, after the app copy. A stale stamp under
# gateway/ cannot bypass validation or overwrite this output.
COPY --from=build-metadata /stamp/.build_commit_sha /app/.build_commit_sha

RUN chmod +x scripts/docker_entrypoint.sh \
&& groupadd --system app \
Expand Down
4 changes: 3 additions & 1 deletion gateway/app/core/build_metadata.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,9 @@ def get_build_provenance() -> str:

The documented Railway release path builds a temporary context from
``git archive`` at the exact release SHA and adds a stamp file before
upload. The Dockerfile requires that file at build time. Railway sets
upload. The production image build writes that same path from the staged
file or, when the file is absent, from the ``RELEASE_COMMIT_SHA`` build
arg. A missing, invalid, or disagreeing stamp fails the build. Railway sets
``RAILWAY_GIT_COMMIT_SHA`` only for GitHub-triggered deployments, so a
local ``railway up`` release relies on the baked stamp. A disagreement —
or a missing stamp — is the signature of a build that did not come through
Expand Down
4 changes: 2 additions & 2 deletions gateway/app/services/mcp_dispatch_reconciliation.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@
}
)
_LEGACY_UNSNAPSHOTTED_OUTCOMES = frozenset(
{"failed_refunded", "delivery_uncertain", "response_rejected"}
{"success", "failed_refunded", "delivery_uncertain", "response_rejected"}
)


Expand Down Expand Up @@ -842,7 +842,7 @@ def _assert_receipt_match(
signed_constraints = receipt.constraints_evaluated
expected_constraints = constraints_evaluated or {}
if canonical_json(signed_constraints) != canonical_json(expected_constraints):
# Older direct failure paths signed valid receipts before permit-v2
# Older direct finalization paths signed valid receipts before permit-v2
# snapshots were attached. Recover only that exact legacy shape;
# a receipt with any signed permit evidence must match in full.
legacy_omission = (
Expand Down
85 changes: 85 additions & 0 deletions gateway/scripts/write_build_commit_sha.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
"""Validate a repository-root release stamp for the production image.

``.build_commit_sha`` is gitignored. A named Docker COPY of that path fails on a
clean tree before the build starts, and no workflow in this repo creates the
file. The production Dockerfile runs this script instead.

Sources:

1. A stamp at the repository build-context root (release archive). It is authoritative.
2. The ``RELEASE_COMMIT_SHA`` build arg, for ``docker build`` on a clean tree.

The build fails when neither source is a 7–64 character hex SHA, when the
staged file is present but invalid, or when both sources are valid and
disagree. The arg is not named COMMIT_SHA or ``BUILD_COMMIT_SHA`` so a
stale Railway service variable is not picked up as the stamp.

``STAGED_SHA_PATH`` and ``BUILD_SHA_PATH`` select the input and output paths
for the image metadata stage and tests. The two paths must be distinct in the
image so a stray ``gateway/.build_commit_sha`` cannot become an input.
"""

from __future__ import annotations

import os
import re
import sys
from pathlib import Path

# Same shape as app.core.build_metadata._GIT_SHA_RE. Kept local so image
# build does not import application settings.
_GIT_SHA_RE = re.compile(r"^[0-9a-fA-F]{7,64}$")
_DEFAULT_PATH = Path("/app/.build_commit_sha")
_MISSING = (
"Release commit stamp missing. Stage .build_commit_sha in the build "
"context or pass --build-arg RELEASE_COMMIT_SHA=$(git rev-parse HEAD)."
)


def _valid(value: str) -> bool:
return _GIT_SHA_RE.fullmatch(value) is not None


def resolve_stamp(staged: str | None, build_arg: str) -> str:
"""Return the lowercase SHA to write.

``staged`` is the file contents, or ``None`` when the file is absent.
"""

arg = build_arg.strip()
if arg and not _valid(arg):
raise SystemExit("RELEASE_COMMIT_SHA is not a 7-64 character hex git SHA.")

if staged is None:
if not _valid(arg):
raise SystemExit(_MISSING)
return arg.lower()

staged_sha = staged.strip()
if not _valid(staged_sha):
raise SystemExit(
"Staged .build_commit_sha is not a 7-64 character hex git SHA."
)
if arg and arg.lower() != staged_sha.lower():
raise SystemExit("RELEASE_COMMIT_SHA disagrees with staged .build_commit_sha.")
return staged_sha.lower()


def main() -> int:
path = Path(os.environ.get("BUILD_SHA_PATH", str(_DEFAULT_PATH)))
staged_path = Path(os.environ.get("STAGED_SHA_PATH", str(path)))
staged: str | None
try:
staged = staged_path.read_text(encoding="utf-8")
except FileNotFoundError:
staged = None
except OSError as exc:
raise SystemExit(f"Cannot read {staged_path}: {exc}") from exc

sha = resolve_stamp(staged, os.environ.get("RELEASE_COMMIT_SHA", ""))
path.write_text(sha + "\n", encoding="utf-8")
return 0


if __name__ == "__main__":
sys.exit(main())
2 changes: 1 addition & 1 deletion gateway/tests/test_build_provenance.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ def test_stamped_is_case_insensitive(baked, monkeypatch):


def test_stamped_tolerates_trailing_newline(baked, monkeypatch):
# The Dockerfile writes the stamp with `echo`, so it carries a newline.
# The image stamp is written with a trailing newline.
baked(SHA_A + "\n")
monkeypatch.setenv("RAILWAY_GIT_COMMIT_SHA", SHA_A)
assert get_build_provenance() == "stamped"
Expand Down
34 changes: 31 additions & 3 deletions gateway/tests/test_gateway_image_sdk.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,10 +73,24 @@ def test_images_install_sdk_and_put_it_on_pythonpath(name: str):
assert requirements < install


def test_release_dockerfile_still_requires_the_context_root_stamp():
def test_release_dockerfile_validates_root_stamp_before_final_copy():
text = _dockerfile("Dockerfile")
assert "COPY .build_commit_sha /app/.build_commit_sha" in text
assert "COPY .build_commit_sha" not in _dockerfile("Dockerfile.dev")
assert "COPY . /context/" in text
assert "STAGED_SHA_PATH=/context/.build_commit_sha" in text
assert "BUILD_SHA_PATH=/stamp/.build_commit_sha" in text
assert "python /context/gateway/scripts/write_build_commit_sha.py" in text
assert "COPY .build_commit_sha /app/.build_commit_sha" not in text
assert text.index("COPY gateway/ /app/") < text.index(
"COPY --from=build-metadata /stamp/.build_commit_sha /app/.build_commit_sha"
)


def test_development_image_does_not_require_or_copy_a_stamp():
text = _dockerfile("Dockerfile.dev")
assert "RELEASE_COMMIT_SHA" not in text
assert "write_build_commit_sha.py" not in text
assert "COPY --from=build-metadata" not in text
assert "COPY .build_commit_sha" not in text


def test_root_dockerignore_keeps_sdk_sources_and_the_stamp():
Expand All @@ -91,6 +105,20 @@ def test_root_dockerignore_keeps_sdk_sources_and_the_stamp():
assert ".build_commit_sha" not in lines
assert "gateway/tests" in lines
assert ".env" in lines
assert "**/.env" in lines
assert "gateway/.build_commit_sha" in lines
assert "*.pem" in lines
assert "**/*.key" in lines
assert "gateway/data" in lines
assert "*.db-wal" in lines
assert "**/.agents" in lines
assert "**/.claude" in lines
assert "**/.envrc" in lines
assert "**/*.db-wal" in lines
assert "*.db-shm" in lines
assert "**/*.db-shm" in lines
assert "*.log" in lines
assert "**/*.log" in lines


def _package_not_installed(_name: str):
Expand Down
Loading
Loading