Skip to content

feat(backend): plan B B2 — role-image CI build+probe, train publish, per-service image opt-in - #22971

Merged
Git-on-my-level merged 6 commits into
mainfrom
lane/arch-b2
Oct 21, 2026
Merged

Git-on-my-level merged 6 commits into
mainfrom
lane/arch-b2

Conversation

@Git-on-my-level

@Git-on-my-level Git-on-my-level commented Oct 21, 2026 •

Copy link
Copy Markdown
Member

Summary

Plan B B2 prerequisites: role images become built, probed and published from one SHA, and each backend-stack service can take its role image by digest. Merging changes nothing any service deploys. Every deploy keeps shipping today's image until a dispatch passes service_images.

David named this workflow change on 2026-10-21 (two-lane lead session): role-image build job + per-service image inputs (plan B B2)

  1. CI role-image build job: new .github/workflows/role_images.yml.
    • It builds every backend/Dockerfile.roles target (api, workers, realtime, gateway, pusher) and the new listen-edge image (backend/edge/Dockerfile).
    • It runs on PRs that touch an image input (Dockerfile.roles, locks, registry, contract scripts, backend/edge/**) and on every backend merge to main.
    • Each Python role image runs its offline dependency probe (runtime_image_contracts.py smoke --target). This closes B1's "no built-image probe ran" gap.
    • listen-edge gets an HTTP probe: /healthz and /readyz, the omi_edge_build_info{release_sha} identity, and a clean SIGTERM drain.
    • Each run records image size and cold-start import time (an offline, timed entrypoint import in a fresh container) in the job summary. On main it also records the fat backend image as a baseline.
    • It has no registry access and pushes nothing. PRs build on the public python:3.11-slim base, because no PR workflow holds a GCP credential.
  2. Per-service image inputs in deploy-backend-stack, plus the gcp_backend.yml dispatch input service_images.
    • Format: service=gcr.io/<project>/<role image>@sha256:<digest> pairs for backend, backend-sync, backend-sync-backfill, backend-integration, backend-listen (needs deploy_targets=all) and llm-gateway (needs deploy_gateway=true).
    • Blank, the default, gives today's image everywhere.
    • Validation before any mutation: backend/scripts/resolve_service_images.py checks that each ref is in this project's registry, is the role image the registry maps that service to, carries OMI_ROLE=<role>, and is labelled with the admitted SHA.
    • Release vector: verify_backend_release_vector.py --service-image expects each moved service at its digest and records it in evidence. The default evidence schema is unchanged.
    • Charts: the listen and gateway charts accept image.digest, rendering repo@digest. image.tag is still required and still set.
    • The flag is documented in backend/docs/runbooks/role-image-cutover.md.
  3. Release-train wiring (main only): new job gcp_backend.yml build-role-images in mode=build-only.
    • It shares build-image's boundary, admission, break-glass and Environment, so prod approval and the prod WIF apply.
    • It builds every role image plus listen-edge on the private base at the admitted SHA, stamped with OMI_RELEASE_SHA and the revision label, and probes each one before publish.
    • It pushes gcr.io/<project>/<image>:<sha7>. It refuses to overwrite a tag of another SHA and reuses a same-SHA tag.
    • It prints the digests and a ready-to-paste service_images value, and uploads role-images-<env>.json.
    • It deploys nothing.
  4. Structured logging. main.py, pusher/main.py, llm_gateway/main.py and utils/messaging/maintenance.py adopt omi_logging.configure_logging(..., default_format='text'). Their five pending logging-guard entries are removed, and the role images (no longer build_only) now pass the guard.
    • Text mode keeps today's INFO→stdout / WARNING+→stderr split and textPayload. Several live log metrics are textPayload-only (messaging maintenance failures, daily summary extractors), so JSON is a per-service OMI_LOG_FORMAT=json step after consumer admission (runbook updated).
    • Visible deltas:
      • the line prefix changes from INFO:logger:msg to INFO logger: msg;
      • Uvicorn's own records go through the root handler, so uvicorn.error startup lines move from stderr to stdout;
      • gateway INFO app logs now emit (before, they went to lastResort, WARNING+ only);
      • pusher keeps its access lines (access_policy='keep').

The listen-edge image is in this train for D2 (#22945). Its deploy still needs the GKE Deployment and Service, which is D2's deploy step.

Lane / contract

Swarm label arch-b2 (plan B B2, P8 brief). Owner sign-offs: none needed. B1's files (Dockerfile.roles, runtime_images.json, the contract script and its tests) are this lane's predecessor. The edge Dockerfile adds no crate changes.

Product invariants affected

INV-DATA-1: path match only (.github/workflows/gcp_backend.yml). No desktop-backend deployment authority or customer data-plane route changes; the backend stack keeps its projects and routing.

Verification

All runs were on m5 (shared, high load), through bin/omi-heavy run -- nice -n 19.

Layer Command Result
Unit backend/test.sh on test_role_images, test_resolve_service_images, test_verify_backend_release_vector, test_omi_logging, test_logging_entrypoint_guard, test_runtime_image_contracts, test_backend_listen_helm_defaults (Helm render of digest mode) all passed
Unit (touched contracts) test.sh on test_llm_gateway_deploy_contract, test_rendered_deployment_contract, test_listen_helm_env_overrides, test_internal_gateway_helm, test_messaging_operations, test_messaging_launch_hardening, test_workflow_contracts, test_pusher_deployment_control_workflow, test_logging_config, test_fleet_deployment, and others all passed
Static contract runtime_image_contracts.py check passed, 19 images
Logging guard check_logging_entrypoints.py --base origin/main passed, 20 migrations remain (was 25)
CI budget check_ci_budget.py --base origin/main passed
checks-manifest run_checks.py --lane local all passed except product-invariants, which needed this body (now cited)
Built image this PR's Role Images run (public base) all 5 Python role probes ok; api/workers/realtime 2.63 GB, one shared image, cold import 5.3 s; gateway 1.1 s; pusher 1.44 GB, 4.0 s. listen-edge: see latest run
Review Grok FIX-FIRST at 8501aac; 2 blockers + 3 minors fixed in 106ef2c, 1 minor rebutted (PR comment)

Not run locally: any docker build. m5 has no Docker daemon up, and B1's local amd64 build OOM'd. This PR's own Role Images run is the first built-image probe. The private-base build and the publish path (build-role-images) first run on the lead's next build-only train.

Rollback

Revert this PR. Blank service_images already ships today's images. A logging rollback is OMI_LOG_FORMAT=text (already the default) or a revert.

Next steps (B3 cutover, lead-owned deploys; out of scope here)

  1. gateway / pusher. The production gateway ships through gcp_llm_gateway.yml, and pusher through gcp_backend_pusher.yml with dev-qualified pusher_image_digest. Each needs a role-digest input (backend-gateway, and backend-pusher in the qualification flow) before its production cutover. In development the gateway can cut over now via service_images=llm-gateway=… with deploy_gateway=true.
  2. messaging-maintenance-job. Point the admitted image in deploy/messaging/maintenance-job.json / messaging_operations.py at the backend-workers digest.
  3. backend-listen. service_images=backend-listen=… with deploy_targets=all (development). The prod path is Cloud Run-only today, so listen prod goes via gcp_backend_listen_helm.yml, which needs the same digest input.
  4. Cloud Run four, one train. backend → backend-api, and the other three → backend-workers.
  5. After each cutover, delete the replaced registry entry and Dockerfile (§9f.5).

Failure-Class: none

🤖 Generated with Claude Code

Git-on-my-level and others added 2 commits October 21, 2026 10:18
… image opt-in

Plan B B2 prerequisites (workflow change named by David on 2026-10-21).
Nothing changes what any service deploys until a deploy passes
service_images.

- role_images.yml builds every backend/Dockerfile.roles target and the
  new listen-edge image (backend/edge/Dockerfile) on PRs that touch an
  image input and on every backend merge to main. It runs each role's
  offline dependency probe, an HTTP health/identity/drain probe for the
  edge, and records size and cold-start import time. No registry access.
- gcp_backend.yml build-only gains build-role-images: the same build and
  probe on the private base at the admitted SHA (OMI_RELEASE_SHA stamped,
  revision label), push by short SHA, digests and a ready service_images
  value in the summary, fat-image baseline for comparison.
- deploy-backend-stack takes service_images: per-service role digests for
  the Cloud Run four, listen and the stack gateway, validated (registry,
  role image, OMI_ROLE, revision label) before any mutation. Blank keeps
  today's image everywhere. The release-vector verifier expects each moved
  service at its digest; listen and gateway charts accept image.digest.
- main.py, pusher/main.py, llm_gateway/main.py and
  utils/messaging/maintenance.py adopt omi_logging.configure_logging with
  default_format='text', which keeps today's split streams and textPayload
  filters; their pending logging-guard entries are removed, so the role
  images (no longer build_only) pass the guard.

Runbook: backend/docs/runbooks/role-image-cutover.md.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…make and g++

Drop setup-buildx from build-role-images so docker build loads images for the
probes, and give the edge builder cmake (bundled opus fallback) and g++
(static ONNX Runtime links libstdc++).

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 21, 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-10-21T04:47:05.015820Z b21f952 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.

ort-sys downloads ONNX Runtime at build time through ureq/native-tls, which
builds openssl-sys; the runtime stage needs no OpenSSL.

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: 8501aacb7b

ℹ️ 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".

outputs["llm_gateway"] = gateway or f"gcr.io/{project}/llm-gateway:{short_sha}"
outputs["llm_gateway_repository"] = gateway.split("@")[0] if gateway else ""
outputs["llm_gateway_digest"] = gateway.split("@")[1] if gateway else ""
outputs["release_vector_args"] = " ".join(f"--service-image {s}={r}" for s, r in sorted(pairs.items()))

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 Exclude gateway overrides from backend release-vector args

When service_images includes the advertised llm-gateway opt-in, this output forwards it to every verify_backend_release_vector.py invocation, but that verifier explicitly accepts only the four Cloud Run services and backend-listen; it therefore exits with service images name unknown services: ['llm-gateway']. A development deploy with deploy_gateway=true consequently mutates the gateway and creates Cloud Run candidates, then deterministically fails before promotion. Either omit the gateway pair from these arguments or extend the verifier to evaluate it.

AGENTS.md reference: .github/AGENTS.md:L28-L30

Useful? React with 👍 / 👎.

Comment on lines +646 to +647
python3 .deploy-control/backend/scripts/role_images.py build \
--sha "$ADMITTED_SHA" --registry "gcr.io/${PROJECT_ID}" --baseline --context . --manifest "$MANIFEST"

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 Preserve build-only support for older admitted SHAs

When mode=build-only is dispatched for any valid admitted ancestor from before this change, the runtime checkout does not contain backend/edge/Dockerfile, but the workflow-owned current role_images.py and registry unconditionally try to build listen-edge from it here. The admission logic explicitly permits any merged ancestor, so this new parallel job makes previously supported build-only runs finish red after the ordinary backend image may already have been pushed. Gate the role-image train on source support, constrain admission to compatible SHAs, or use role-image controls from the admitted source.

Useful? React with 👍 / 👎.

Comment on lines +12 to +14
pull_request:
paths:
- "backend/Dockerfile.roles"

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 Run role-image PR checks for copied backend sources

The PR trigger is limited to Dockerfiles, locks, registry/scripts, and edge files, even though every Python role target copies backend application source and probes imports from it. A PR that changes backend/main.py, llm_gateway/, pusher/, or another copied module without touching one of these listed paths skips both role-image builds and dependency probes; for example, a newly imported package missing from the role lock is discovered only after merge when the manual release train fails. Include the copied backend source surface (or derive an equivalent complete selector) in this trigger.

AGENTS.md reference: backend/AGENTS.md:L217-L217

Useful? React with 👍 / 👎.

- listen-edge probe expects the 12-char release_sha label the binary exports
  (sanitize_release_sha), and rejects a full-40 label.
- llm-gateway opt-in leaves the Cloud Run/listen release vector; the gateway
  step proves its Deployment runs the opted-in digest after rollout.
- role-image registry tags use 12 hex chars (no 7-char prefix collisions).
- check-workflows ignores comment lines and accepts role_images.py verify.
- build-role-images forecast at build-image's manual run rate.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@Git-on-my-level

Copy link
Copy Markdown
Member Author

Grok review (FIX-FIRST at 8501aac): disposition

Fixed in 106ef2c2fd0, plus d2e8c5da992 for the CI edge build failure. That failure was openssl-sys: ort's build-time downloader needs libssl-dev in the builder. The runtime image needs no OpenSSL.

# Finding Disposition
B1 The listen-edge identity probe expected the full SHA, but the binary exports sanitize_release_sha (12 hex chars) Fixed. probe_native expects sha[:12].lower(). The unit test uses the 12-char sample, and a new case shows a full-40 label is rejected.
B2 An llm-gateway opt-in reached verify_backend_release_vector.py --service-image, which rejects it after the gateway rollout Fixed. release_vector_args now excludes llm-gateway. The gateway deploy step checks that the rolled-out <env>-omi-llm-gateway Deployment template image equals <repository>@<digest>, and fails otherwise. A new test feeds the resolver's release_vector_args through build_expectation.
m1 Module-level configure_logging in utils/messaging/maintenance.py replaces root handlers on import Rebutted, no change. The guard requires the module-body call, as you note. The only production importer is python -m utils.messaging.maintenance. The test importers do it at collection, before pytest's per-test capture handlers attach. test_messaging_operations.py::test_maintenance_failure_is_redacted_and_nonzero (caplog) still passes. diarizer/main.py and nllb_translation/main.py already follow the same pattern.
m2 A raw 7-char tag slice can collide Fixed. Registry tags are now 12 hex chars. Publish still refuses a tag of another SHA, and deploys consume digests.
m3 check-workflows could be satisfied by a comment Fixed. workflow_contract_errors ignores comment lines and accepts role_images.py verify, which runs the smoke per target. There is a negative test for a commented-out marker.
m4 build-role-images was forecast at zero runs Fixed. It now uses build-image's manual rate (non-pr, 1/day).

Built-image evidence from this PR's first Role Images run (public base, ubuntu-latest):

Image Uncompressed size Offline cold start (container s / import s) Dependency probe
backend-api 2.63 GB 7.1 / 5.3 (main) 387 modules, ok
backend-workers 2.63 GB, same layers 7.0 / 5.2 387, ok
backend-realtime 2.63 GB, same layers 7.1 / 5.3 387, ok
backend-gateway 2.63 GB, same layers 1.4 / 1.1 (llm_gateway.main) 227, ok
backend-pusher 1.44 GB 5.1 / 4.0 (pusher.main) 282, ok

The four app targets were one image's bytes (0.3–0.4 s per extra target).

Git-on-my-level and others added 2 commits October 21, 2026 11:27
…er image input

pusher/Dockerfile now copies backend/omi_logging.py, so the dev qualification
path filter and the pusher source-closure tests include it.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@Git-on-my-level
Git-on-my-level merged commit 933b2f1 into main Oct 21, 2026
59 checks passed
@Git-on-my-level
Git-on-my-level deleted the lane/arch-b2 branch October 21, 2026 05:57
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