Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
64 changes: 64 additions & 0 deletions .github/workflows/simulation-deploy.reusable.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,14 @@ on:
entrypoint_max_instances:
required: true
type: number
household_function_min_containers:
required: true
type: number
description: "Containers each v2 household function keeps running"
household_function_scaledown_window_seconds:
required: true
type: number
description: "Seconds an extra v2 household container stays idle before Modal stops it"
promote_entrypoint:
required: true
type: boolean
Expand Down Expand Up @@ -645,6 +653,11 @@ jobs:
OBSERVABILITY_GOOGLE_SERVICE_ACCOUNT_EMAIL: ${{ vars.OBSERVABILITY_GOOGLE_SERVICE_ACCOUNT_EMAIL }}
OTEL_EXPORTER_OTLP_ENDPOINT: ${{ vars.OBSERVABILITY_OTLP_ENDPOINT }}
POLICYENGINE_OTEL_GOOGLE_AUDIENCE: ${{ vars.OBSERVABILITY_OTLP_GOOGLE_AUDIENCE }}
# The containers each household function keeps running, and how
# long extra ones stay idle, read when the app is deployed
# (src/modal/v2_household_scaling.py).
HOUSEHOLD_FUNCTION_MIN_CONTAINERS: ${{ inputs.household_function_min_containers }}
HOUSEHOLD_FUNCTION_SCALEDOWN_WINDOW_SECONDS: ${{ inputs.household_function_scaledown_window_seconds }}
run: uv run --frozen modal deploy --env="${{ inputs.modal_environment }}" src/modal/v2_app.py

- name: Validate installed bundles, secrets, datasets, and calculations
Expand Down Expand Up @@ -1236,6 +1249,57 @@ jobs:
MODAL_ENVIRONMENT: ${{ inputs.modal_environment }}
run: ../../.github/scripts/stage12-v2-default-restore.sh

lower_replaced_household_containers:
name: Keep household containers running only in the v2 default's app
# Each .py version's v2 app stays deployed, and a deploy gives its
# household functions the environment's minimum container count, one in
# production. The simulation service calls only the v2 default's, so once
# the default has moved, this sets the default's household functions to
# that minimum (an earlier run may have set them to 0, and a rerun of
# failed jobs can make them the default without deploying them) and every
# other deployed v2 app's to 0. Its own job, after the default job
# succeeded, so a failed run puts back no Stage 12 default. A failure
# fails this workflow call, so in the beta deployment it skips the
# production deployment and the client publishing, as a failed runtime
# estimates deploy does; in the production deployment it fails the run,
# which also stops the client publishing.
if: >-
${{
!cancelled() &&
inputs.deploy_stage12_v2 &&
needs.publish_stage12_v2_default.result == 'success'
}}
needs: [publish_stage12_v2_default]
runs-on: ubuntu-latest
defaults:
run:
shell: bash
environment: ${{ inputs.release_environment }}
steps:
- uses: actions/checkout@v6

- uses: actions/setup-python@v6
with:
python-version: "3.13"

- uses: astral-sh/setup-uv@v8.1.0
with:
version: "0.13.6"

- name: Install the household container script's dependencies
working-directory: projects/policyengine-simulation-executor
run: uv sync --frozen

# Reads the default from the environment's v2 manifest and lists the
# environment's apps with modal app list; only Modal's tokens. The
# default's functions get the minimum the v2 deploy step gave the app.
- name: Keep household containers running only in the v2 default's app
working-directory: projects/policyengine-simulation-executor
env:
MODAL_TOKEN_ID: ${{ secrets.MODAL_TOKEN_ID }}
MODAL_TOKEN_SECRET: ${{ secrets.MODAL_TOKEN_SECRET }}
run: uv run --frozen python -m src.modal.utils.lower_replaced_household_containers --environment "${{ inputs.modal_environment }}" --manifest-name simulation-api-v2-version-manifest --default-min-containers "${{ inputs.household_function_min_containers }}"

deploy_runtime_estimates:
name: Deploy the scheduled runtime estimates app after every check
# An unversioned app, one per Modal environment, whose daily schedule
Expand Down
9 changes: 9 additions & 0 deletions .github/workflows/simulation-deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,10 @@ jobs:
entrypoint_revision_prefix: s-
entrypoint_min_instances: 0
entrypoint_max_instances: 2
# Staging keeps no household container running, with Modal's
# 60-second idle window.
household_function_min_containers: 0
household_function_scaledown_window_seconds: 60
# Staging's stable URL must serve the revision this deployment tested,
# because staging callers such as the Public API's staging service use
# that URL. Only a run from main promotes: a manual run from another
Expand Down Expand Up @@ -127,6 +131,11 @@ jobs:
entrypoint_revision_prefix: p-
entrypoint_min_instances: 1
entrypoint_max_instances: 20
# One household container per country stays running, so a
# calculation after idle doesn't wait for one to start; extra
# containers stop after ten idle minutes.
household_function_min_containers: 1
household_function_scaledown_window_seconds: 600
promote_entrypoint: true
run_full_integration: false
deploy_existing_stack: true
Expand Down
9 changes: 9 additions & 0 deletions .github/workflows/stage12-deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,10 @@ jobs:
entrypoint_revision_prefix: s-
entrypoint_min_instances: 0
entrypoint_max_instances: 2
# Staging keeps no household container running, with Modal's
# 60-second idle window.
household_function_min_containers: 0
household_function_scaledown_window_seconds: 60
# Like the main deployment, promote the tested staging revision, and
# only from main. Rule: sim.deploy.staging-promotes-tested-revision.
promote_entrypoint: ${{ github.ref == 'refs/heads/main' }}
Expand All @@ -79,6 +83,11 @@ jobs:
entrypoint_revision_prefix: p-
entrypoint_min_instances: 1
entrypoint_max_instances: 20
# One household container per country stays running, so a
# calculation after idle doesn't wait for one to start; extra
# containers stop after ten idle minutes.
household_function_min_containers: 1
household_function_scaledown_window_seconds: 600
promote_entrypoint: true
run_full_integration: false
deploy_existing_stack: false
Expand Down
2 changes: 1 addition & 1 deletion AGENTS.md
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ To add or change a rule, read `docs/engineering/skills/rules-registry.md`.

### Deployment pipeline

- Checked: `sim.deploy.container-context-minimal`, `sim.deploy.docker-images-build`, `sim.deploy.gcloud-without-terraform`, `sim.deploy.latest-moves-after-checks`, `sim.deploy.modal-image-smoke`, `sim.deploy.numerical-sentinel-gate`, `sim.deploy.permission-enforcement-wired`, `sim.deploy.promotion-order-explicit`, `sim.deploy.release-commit-deploys-once`, `sim.deploy.release-identity-smoke`, `sim.deploy.revision-tags-valid`, `sim.deploy.routing-publication-journaled`, `sim.deploy.shell-scripts-valid`, `sim.deploy.smoke-tests-strict`, `sim.deploy.stage12-default-moves-after-checks`, `sim.deploy.stage12-manifest-read-daily`, `sim.deploy.staging-promotes-tested-revision`, `sim.deploy.traffic-changes-exact`, `sim.deploy.workflow-shell-safety`
- Checked: `sim.deploy.container-context-minimal`, `sim.deploy.docker-images-build`, `sim.deploy.gcloud-without-terraform`, `sim.deploy.household-containers-follow-the-default`, `sim.deploy.latest-moves-after-checks`, `sim.deploy.modal-image-smoke`, `sim.deploy.numerical-sentinel-gate`, `sim.deploy.permission-enforcement-wired`, `sim.deploy.promotion-order-explicit`, `sim.deploy.release-commit-deploys-once`, `sim.deploy.release-identity-smoke`, `sim.deploy.revision-tags-valid`, `sim.deploy.routing-publication-journaled`, `sim.deploy.shell-scripts-valid`, `sim.deploy.smoke-tests-strict`, `sim.deploy.stage12-default-moves-after-checks`, `sim.deploy.stage12-manifest-read-daily`, `sim.deploy.staging-promotes-tested-revision`, `sim.deploy.traffic-changes-exact`, `sim.deploy.workflow-shell-safety`
- `sim.deploy.image-smoke-covers-every-image-lib`: The image smoke path filter includes every library mounted into a Modal image, so a change to any of them runs the smoke. (doc-only, not checked: follow it yourself)

### API contracts and integration
Expand Down
1 change: 1 addition & 0 deletions changelog.d/v2-household-containers.changed.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
In production, the API v2 simulation app's household calculation functions (`calculate_household_us` and `calculate_household_uk`) keep one container running at all times, so a household calculation after a quiet period doesn't wait for a container to start, and extra containers stop after ten idle minutes instead of one; staging keeps none, as before. After each deploy moves the v2 default, a new deploy job sets the default's household functions to that minimum and every other deployed v2 app's to 0, so only the default's containers keep running (about $92 a month per container at list price).
Loading
Loading