Repository navigation
ci(runtime-images): offline third-party closure gate per image lock - #24673
Conversation
The pre-merge runtime-image gate only checked first-party source closure. Third-party (pip) closure was checked only by the deploy-time image smoke. #24490 and #24366 made deepgram and langdetect reachable from the batch-pipeline-worker while its lock lacked them. Unit CI syncs the full backend lock, so it stayed green, and the break surfaced at the 11-04 worker roll. Add `runtime_image_contracts.py check-third-party` and a matching checks-manifest entry in both the local and ci lanes: - Trace each installer RUN in the image's stage chain back through its COPY to the repository lock or requirements file. Follow `-r` includes, inline pins and `COPY --from` stages. - Map every reachable third-party import to a distribution: longest import prefix first, PEP 503 normalization, API-version suffixes dropped, and a small table for names that differ (PIL->pillow, deepgram->deepgram-sdk, ...). Bare namespace packages are skipped only as the whole import path, so an unmapped submodule fails closed. - Fail only on closed sets: a pylock, or requirements pinned with `==`. Open sets (ranges, path installs) may pull a module in transitively, so they are reported, not judged. On main it checks 11 of 19 images and reports 8 open sets. It fails e089cc3 (#24490) and e113f0c (#24366) on batch-pipeline-worker, and passes their parent and 660ee8a (#24613). It is offline, needs no docker or GCP, and takes about 30s for all 19 images with a shared AST cache. Co-Authored-By: Claude Opus 5.5 <[email protected]>
… check The 30s whole-registry walk tripped the fast-unit CPU guard (1s). The backend-runtime-image-third-party-closure manifest check already runs it on every PR in the local and ci lanes. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Codex Review SummaryThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
There was a problem hiding this comment.
All reported issues were addressed across 3 files
Reply with feedback, questions, or to request a fix.
View guided diff | Turn on auto-fix | Re-trigger cubic
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 721bc9f848
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| names.add(normalize_distribution(match.group(1))) | ||
| specifier = line[match.end() :].split(";", 1)[0] | ||
| if "==" not in specifier and " @ " not in line: | ||
| open_reasons.append(f"{relative}: unpinned {line}") |
There was a problem hiding this comment.
Distinguish pinned requirements from a closed dependency lock
When a requirements file pins only direct dependencies, this treats it as closed even though the installer also installs their transitive dependencies. For example, fastapi==0.121.0 with a reachable import starlette produces a closure error, although FastAPI installs Starlette. The inspected pip install --help describes --no-deps as “Don't install package dependencies”; the registered Dockerfiles do not use that option. Requiring == therefore does not establish that an absent distribution is absent from the image. Require an explicitly complete lock or report such requirements sets as open rather than rejecting valid images.
Useful? React with 👍 / 👎.
|
|
||
|
|
||
| def _pylock_distributions(path: Path) -> set[str]: | ||
| import tomllib |
There was a problem hiding this comment.
Move the TOML import to module scope
The new function-local tomllib import violates the backend guide's explicit requirement that all imports occur at module top level, never inside functions. Move it alongside the other standard-library imports; the backend already requires Python 3.11, so this does not need a conditional dependency-loading seam.
AGENTS.md reference: backend/AGENTS.md:L166-L168
Useful? React with 👍 / 👎.
| payload = tomllib.loads(path.read_text(encoding="utf-8")) | ||
| except (OSError, tomllib.TOMLDecodeError) as exc: | ||
| raise ContractError(f"cannot read lock {_repository_relative(path)}: {exc}") from exc | ||
| return {normalize_distribution(package["name"]) for package in payload.get("packages", []) if "name" in package} |
There was a problem hiding this comment.
Filter locked packages by the image's environment markers
When a pylock contains a package whose environment marker excludes the runtime image, this still counts that package as installed because it collects every package name without inspecting marker. The repository's locks already contain platform and Python-version markers. A reproduced contract with a reachable import deepgram and a deepgram-sdk entry marked sys_platform == 'win32' passes with no errors or open-set notes, although the Linux image will not install that distribution. Evaluate markers against the target image's Python/platform environment, or report unsupported marker evaluation as unchecked, rather than certifying dependencies that the installer excludes.
Useful? React with 👍 / 👎.
These fixes come from the Luna review of the third-party closure gate. - Follow a `COPY --from` stage only when the copy carries a Python environment (venv, site-packages). A binary copied from a stage no longer credits that stage's installs. - Make explicit MODULE_DISTRIBUTIONS entries authoritative. An ordinary package is owned by its top-level name. Longer prefixes, and dropping an API-version suffix, apply only under namespace packages, which now include `pyannote`. - Evaluate lock and requirements markers for the images' Linux x86_64 CPython 3.11. An undecidable marker never credits a distribution. - Treat a requirements list as closed only when a resolver wrote it. A hand-pinned `==` list, or a direct URL reference, is open. This moves diarizer to the noted set. - Add a fast test that pins which registered images are judged. Re-measured with this script on archive snapshots: e089cc3 fails (batch-pipeline-worker: deepgram). e113f0c fails on the worker and also on pusher and backend-pusher (soundfile, which cac4f62 later added). e089cc3^ and 660ee8a pass, and so does main. Co-Authored-By: Claude Opus 5.5 <[email protected]>
…odule runtime_image_contracts.py is frozen by the product line-count ratchet. The new gate now lives in runtime_image_dependencies.py. The contracts script keeps only the CLI entry, the shared AST cache hook, and a __main__ alias so both modules raise the same ContractError. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Fixes from the Luna round-2 review of the third-party closure gate: - A copied-from stage credits only installs into the environment the image copies out of it: the command names the path, or a prior ENV PATH/VIRTUAL_ENV activates it. The backend builder's system-python `uv` install is no longer credited. - Under a namespace package, only the provider component below the namespace levels names the distribution, plus its API-version variant. A deeper submodule name can no longer match an unrelated distribution. - `python_full_version` comparisons are decided only when every 3.11.x answers alike, because the base tags float on the patch. Otherwise the entry is not credited. Re-validated on archive snapshots: e089cc3 and e113f0c fail as before (worker deepgram; pusher soundfile), e089cc3^ and 660ee8a pass, and main passes. Co-Authored-By: Claude Opus 5.5 <[email protected]>
…11.x Luna round 3 found two gaps. `python_full_version == '3.11'` skipped the floating-patch check, and sampling only patches 0 and 99 missed boundaries such as `<= '3.11.99'`. A comparison against X.Y.Z can only change its answer at Z, so evaluate patches 0, Z-1, Z, Z+1 and a large patch, and decide only when all of them agree. Co-Authored-By: Claude Opus 5.5 <[email protected]>
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: d4453ce3f9
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| expression = _MARKER_COMPARISON.sub(compare, marker) | ||
| if undecidable or not re.fullmatch(r"(?:\s|\(|\)|True|False|and|or|not)*", expression): | ||
| return False |
There was a problem hiding this comment.
Treat undecidable dependency markers as unchecked
When a lock contains a valid marker this evaluator cannot handle, returning False removes the package while leaving the dependency set classified as closed. For example, a reachable import langdetect with a locked langdetect entry marked python_version ~= '3.11' or 'linux' == sys_platform produces a closure error, although both markers apply to the declared Linux/Python 3.11 environment. I reproduced both cases through third_party_closure_errors. Distinguish an undecidable marker from a definitively false one and mark the dependency set unchecked, or evaluate the full marker syntax, so the new blocking gate does not reject valid images.
Useful? React with 👍 / 👎.
| if environments is not None and not (active or any(path in command for path in environments)): | ||
| continue # installs into an interpreter the image does not copy |
There was a problem hiding this comment.
Honor explicit interpreter overrides when crediting builder installs
When a builder activates /opt/venv through ENV PATH, active makes every subsequent installer count toward the copied environment, even if the command explicitly targets another interpreter. The inspected uv pip sync --help defines --python as “The Python interpreter into which packages should be installed.” I reproduced a builder that syncs its runtime lock into /opt/venv/bin/python, then syncs a tools lock containing deepgram-sdk with --python /usr/local/bin/python: copying only /opt/venv into the final image still lets a reachable import deepgram pass with no errors or unchecked notes. Resolve explicit installer destinations before falling back to the activated environment, so packages left in the builder's system interpreter cannot satisfy the runtime closure.
Useful? React with 👍 / 👎.
| if source.suffix == ".toml": | ||
| distributions |= _pylock_distributions(source) | ||
| else: | ||
| names, reasons = _requirement_distributions(source) | ||
| distributions |= names |
There was a problem hiding this comment.
Account for packages removed by subsequent sync commands
When an image runs multiple uv pip sync commands against the same interpreter, unioning their distributions retains packages that a later sync removes. I reproduced a Dockerfile that first syncs a lock containing deepgram-sdk, then runs uv pip sync --system --allow-empty-requirements requirements.final.txt against an empty compiled requirements file: third_party_closure_errors still accepts import deepgram with no unchecked notes. The inspected uv pip sync --help explicitly says this option will “clear the environment of all packages.” Preserve installer operation semantics and replace the tracked inventory for the affected environment on sync, rather than treating every operation as an additive install.
Useful? React with 👍 / 👎.
Why
On 11-04 the batch-pipeline-worker roll failed its deploy-time image smoke:
missing installed dependency modules: deepgram, … langdetect.backend/diarizer/pylock.batch-pipeline.tomllacked the distributions.runtime_image_contracts.py checkcovers first-party source closure only, and backend unit CI syncs the fullbackend/pylock.toml, which does have both.What
python3 backend/scripts/runtime_image_contracts.py check-third-party(logic in the newbackend/scripts/runtime_image_dependencies.py), wired as the checks-manifest entrybackend-runtime-image-third-party-closure(local and ci lanes). Its triggers includebackend/**/pylock*.tomlandrequirements*.txt, so a lock-only edit that drops a dist also runs it.RUN(uv pip sync,pip install -r, inline pins) in the image's stage chain, includingCOPY --fromstages, is traced back through itsCOPYandWORKDIRto the repo file.-rincludes are followed.third_party_dependency_modulesresolves to distribution candidates:google.cloud.firestore→google-cloud-firestore);google.cloud.tasks_v2→google-cloud-tasks);MODULE_DISTRIBUTIONScovers names that differ (PIL→pillow, deepgram→deepgram-sdk, yaml→pyyaml, …).google,google.cloud) are skipped only as the whole import path. An unmapped submodule under them fails closed.==. Open sets (range pins, path installs) can pull a module in transitively, so it prints a note instead of judging them.tomllib).Measured (m5, this branch's script run on
git archivesnapshots)The unit tests for
test_runtime_image_contracts.pypass viatest.sh(70 passed). The registry-wide walk is deliberately left to the manifest check, because the fast-unit CPU guard is 1s per test.Review (Luna, r1: SHIP-WITH-FIXES, all addressed)
COPY --fromnow credits a stage's installs only when the copy carries a venv or site-packages, not a binary.google,pyannote).Review (Luna rounds 2-4)
uvis no longer credited).python_full_versionis decided only when every 3.11.x agrees.== '3.11'and<= '3.11.99'.Extra finding from re-validation: at e113f0c the gate also fails
pusher/backend-pusheronsoundfile, which was missing frombackend/pusher/pylock.tomluntil cac4f62. That's a second real break it would have caught.Line-Count-Exception: backend/scripts/runtime_image_contracts.py | 1113 -> 1134 | CLI entry, shared AST cache and module alias for the third-party gate; the gate itself lives in the new runtime_image_dependencies.py
Not in this PR (follow-ups from the GLM ciimage scope)
batch-pipeline-workertorole_images.yml --imagesand widening its PR paths: that's a faithful docker build, but it has runner cost and cl2-cost sizes it first.backend/requirements.txt's two range lines, nllb) so those images become checkable.Rollback: revert this PR. It only adds a check.
Failure-Class: FC-runtime-image-boundary
🤖 Generated with Claude Code