Skip to content

ci(runtime-images): offline third-party closure gate per image lock - #24673

Merged
Git-on-my-level merged 6 commits into
mainfrom
lane/ciimage-rc1
Nov 5, 2026
Merged

Git-on-my-level merged 6 commits into
mainfrom
lane/ciimage-rc1

Conversation

@Git-on-my-level

@Git-on-my-level Git-on-my-level commented Nov 5, 2026 •

Copy link
Copy Markdown
Member

Why

On 11-04 the batch-pipeline-worker roll failed its deploy-time image smoke: missing installed dependency modules: deepgram, … langdetect.

What

python3 backend/scripts/runtime_image_contracts.py check-third-party (logic in the new backend/scripts/runtime_image_dependencies.py), wired as the checks-manifest entry backend-runtime-image-third-party-closure (local and ci lanes). Its triggers include backend/**/pylock*.toml and requirements*.txt, so a lock-only edit that drops a dist also runs it.

  • Installed set: each installer RUN (uv pip sync, pip install -r, inline pins) in the image's stage chain, including COPY --from stages, is traced back through its COPY and WORKDIR to the repo file. -r includes are followed.
  • Mapping: each reachable third-party import from the existing third_party_dependency_modules resolves to distribution candidates:
    • longest prefix first, with PEP 503 normalization (google.cloud.firestore → google-cloud-firestore);
    • an API-version suffix is dropped (google.cloud.tasks_v2 → google-cloud-tasks);
    • MODULE_DISTRIBUTIONS covers names that differ (PIL→pillow, deepgram→deepgram-sdk, yaml→pyyaml, …).
    • Bare namespaces (google, google.cloud) are skipped only as the whole import path. An unmapped submodule under them fails closed.
  • Scope: it fails only on closed sets, meaning a pylock or requirements pinned entirely with ==. Open sets (range pins, path installs) can pull a module in transitively, so it prints a note instead of judging them.
  • Speed: a shared AST cache keeps it at about 30s for all 19 images. It runs offline, with no docker or GCP and only stdlib (tomllib).

Measured (m5, this branch's script run on git archive snapshots)

Snapshot Result
main 2ccfc47 (this base) pass. 11 images checked, 8 noted as open (models, 4 jobs, parakeet, nllb, plugins)
e089cc3 (#24490) FAIL batch-pipeline-worker: deepgram
e113f0c (#24366) FAIL batch-pipeline-worker: deepgram
e089cc3^ pass
660ee8a (#24613 fix) pass

The unit tests for test_runtime_image_contracts.py pass via test.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)

  1. COPY --from now credits a stage's installs only when the copy carries a venv or site-packages, not a binary.
  2. Explicit mappings are authoritative. An ordinary package is owned by its top-level name. API-version suffix stripping and longer prefixes apply only under namespace packages (google, pyannote).
  3. Lock and requirements markers are evaluated for Linux x86_64 CPython 3.11, and undecidable markers never credit a distribution. A requirements list counts as closed only if a resolver compiled it, so hand-pinned and direct-URL sets are open. This moves diarizer to the noted set: 10 images are checked on main, 9 are noted.
  4. A fast test pins which registered images are judged.
  5. Runtime: 19s locally on an idle host (17s CPU). Luna measured 75s wall / 36s CPU under load.

Review (Luna rounds 2-4)

  • r2, SHIP-WITH-FIXES:
    • Builder stages now credit only installs into the environment the image copies (the backend builder's system-python uv is no longer credited).
    • Namespace matching stops at the provider component.
    • python_full_version is decided only when every 3.11.x agrees.
  • r3, SHIP-WITH-FIXES: patch-boundary sampling (0, Z-1, Z, Z+1, 9999) also covers == '3.11' and <= '3.11.99'.
  • r4: SHIP at d4453ce.

Extra finding from re-validation: at e113f0c the gate also fails pusher/backend-pusher on soundfile, which was missing from backend/pusher/pylock.toml until 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)

  • Adding batch-pipeline-worker to role_images.yml --images and widening its PR paths: that's a faithful docker build, but it has runner cost and cl2-cost sizes it first.
  • Closing the open dependency sets (pin backend/requirements.txt's two range lines, nllb) so those images become checkable.
  • Making backend checks required at merge, which is David's call.

Rollback: revert this PR. It only adds a check.

Failure-Class: FC-runtime-image-boundary

🤖 Generated with Claude Code

View guided diff Turn on auto-fix

Git-on-my-level and others added 2 commits November 5, 2026 11:47
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]>
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 5, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-05T06:24:38.471894Z d4453ce New commits
ℹ️ 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" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@cubic-dev-ai cubic-dev-ai Bot left a comment •

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 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".

Comment on lines +824 to +827
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}")

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge 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

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge 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}

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge 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 👍 / 👎.

Git-on-my-level and others added 4 commits November 5, 2026 12:10
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]>

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 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".

Comment on lines +181 to +183
expression = _MARKER_COMPARISON.sub(compare, marker)
if undecidable or not re.fullmatch(r"(?:\s|\(|\)|True|False|and|or|not)*", expression):
return False

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge 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 👍 / 👎.

Comment on lines +358 to +359
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

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge 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 👍 / 👎.

Comment on lines +391 to +395
if source.suffix == ".toml":
distributions |= _pylock_distributions(source)
else:
names, reasons = _requirement_distributions(source)
distributions |= names

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge 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 👍 / 👎.

@Git-on-my-level
Git-on-my-level merged commit 7829535 into main Nov 5, 2026
74 of 76 checks passed
@Git-on-my-level
Git-on-my-level deleted the lane/ciimage-rc1 branch November 5, 2026 07:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant