Skip to content

Let API v1 staging's Cloud Run requests run for 900 seconds - #4375

Merged
anth-volk merged 10 commits into
masterfrom
v2plan/d2-1a-staging-request-timeout
Dec 1, 2026
Merged

anth-volk merged 10 commits into
masterfrom
v2plan/d2-1a-staging-request-timeout

Conversation

@anth-volk

Copy link
Copy Markdown
Collaborator

Fixes #4372

Summary

  • API v1's staging Cloud Run service (policyengine-api-staging) lets a request run for up to 900 seconds instead of 300. push.yml's deploy-cloud-run-staging job pins CLOUD_RUN_TIMEOUT: "900" beside its CLOUD_RUN_MAX_INSTANCES: "1", and deploy_cloud_run_candidate.sh already passes CLOUD_RUN_TIMEOUT to gcloud run deploy --timeout.
  • Why: on 2026-11-30 app v3's Household tab on a Vercel preview failed against staging. Staging's single instance, with two worker processes, was calculating the tab's households, and a reform calculation took about 600 seconds. Cloud Run answered 504 at 300 seconds on every attempt while the calculation went on: Flask handles the request on a thread of the worker (a2wsgi's WSGIMiddleware), and a closed connection doesn't stop that thread. The retries added calculations until gunicorn reported a worker killed by SIGKILL, most likely for running out of memory.
  • Production's deploy-cloud-run-candidate job sets no timeout and keeps cloud_run_env.sh's 300 seconds. Staging's maximum instances stay at 1.
  • The live parity check (test_live_v2_household_parity), which runs against the staging candidate before promotion, now waits 920 seconds instead of 320 for API v1's /calculate or /calculate-full answer. It stays longer than the candidate's request timeout, so the check still gets the candidate's own answer, a 504 included. Its guard test now reads the staging deploy step's CLOUD_RUN_TIMEOUT instead of cloud_run_env.sh's default. Normal answers take about 224 seconds.
  • The live staging job (parallel-live-simulation-tests-staging-cloud-run) gets timeout-minutes: 45 instead of 30. It took 18 to 20 minutes in the last three release runs, so with 30 minutes a single API v1 answer near 900 seconds would end the job before the test reported it. Normal runs are unchanged; only a slow run uses the extra runner time.
  • docs/migration/cloud-run-operations.md gains a "Request timeout" paragraph under "Runtime shape and scaling"; the parity wait is updated in run_live_staging_tests.sh and docs/migration/stage-11-v2-households.md.
  • Not covered: app v3's own 240-second browser limit for a household calculation (app/src/api/householdCalculation.ts in policyengine-app-v2) still applies, so this change alone doesn't make the Household tab work on staging. A household calculation still has no deadline of its own.

Environment variables

Variable Provider Wiring
CLOUD_RUN_TIMEOUT The deploy-cloud-run-staging job's own env: block in push.yml, a literal "900" (no GitHub variable or secret) Job-level env: reaches every step of the job; the "Deploy tagged Cloud Run staging candidate" step's own env: doesn't set it. That step runs deploy_cloud_run_candidate.sh, which sources cloud_run_env.sh (CLOUD_RUN_TIMEOUT="${CLOUD_RUN_TIMEOUT:-300}", exported) and passes --timeout "${CLOUD_RUN_TIMEOUT}" to gcloud run deploy. validate_cloud_run_deploy_env.sh doesn't read it. No reusable workflow or secrets: passing is involved.
  • Production doesn't pick it up: no workflow-level env: sets it, and no other job or step does (the new test checks every job and step). The same script therefore deploys policyengine-api with the default 300.
  • Promotion keeps it: promote-cloud-run-staging runs set_cloud_run_revision.sh, which only moves traffic (gcloud run services update-traffic). The timeout belongs to the revision the deploy step creates.
  • Nothing in front of staging: read-only gcloud checks show staging is reached at its run.app URL, with no domain mapping and no load-balancer backend service (the only one, bs-cloud-run, is production's). So Cloud Run's request timeout is staging's only server-side limit.
  • CLOUD_RUN_MAX_INSTANCES is unchanged.

Unverified:

  • That app v3 previews' VITE_API_URL points at staging's run.app URL. This comes from the 2026-11-30 investigation; it wasn't read from Vercel.
  • The live service: staging still shows timeoutSeconds 300. The new value takes effect when the next release deploys staging after this merges.

Testing

Red-green: d1f967b13 added the workflow tests and they failed, then 6f4eb88b4 made them pass. 320535be5 changed the parity guard test and it failed (320.0 > 900.0), then 0dec24d54 made it pass. 19ee0b2d5 changed the live job's limit assertion to 45 minutes and it failed, then c19c3b8b1 made it pass.

  • tests/unit/test_cloud_run_push_workflow.py::test_only_the_staging_deploy_raises_the_cloud_run_request_timeout: no workflow-level env: sets CLOUD_RUN_TIMEOUT, the only job whose own or step env: sets it is deploy-cloud-run-staging, and the value is "900".
  • tests/unit/test_cloud_run_push_workflow.py::test_each_deploy_job_passes_its_request_timeout_to_gcloud: a dry run of deploy_cloud_run_candidate.sh with each deploy step's timeout setting (workflow, job and step env: combined) passes --timeout 900 for staging and --timeout 300 for production. Adding CLOUD_RUN_TIMEOUT: "300" to the staging deploy step by hand makes it fail.
  • tests/unit/v2/test_live_household_parity_requests.py::test_the_check_waits_longer_than_the_candidate_lets_a_request_run: the parity check's wait is longer than the staging candidate's request timeout.
  • tests/unit/test_cloud_run_push_workflow.py::test_push_workflow_tests_the_staging_candidate_before_promoting_it: the live staging job has timeout-minutes: 45.
  • make quality, lint-imports, python -m scripts.rules validate, python scripts/run_quality_guards.py, ruff check, ruff format --check, check_changelog_fragment.sh and actionlint .github/workflows/push.yml pass.

🤖 Generated with Claude Code

anth-volk and others added 9 commits December 1, 2026 04:07
…imeout

Staging's deploy job should set CLOUD_RUN_TIMEOUT to 900 and the deploy
script should pass it to gcloud as --timeout; production sets none and keeps
cloud_run_env.sh's 300. Fails until the staging job sets it.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Pin CLOUD_RUN_TIMEOUT: "900" in push.yml's deploy-cloud-run-staging job.
deploy_cloud_run_candidate.sh passes it to gcloud run deploy as --timeout.
Staging's single instance shares app v3 previews' household calculations
between two workers, so a reform calculation took about 600 s there, and at
300 s Cloud Run answered 504 while the worker went on calculating.
Production sets no timeout and keeps cloud_run_env.sh's 300.

Fixes #4372

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…on goes on

The dry-run test now lays the deploy step's env over its job's, so a
step-level CLOUD_RUN_TIMEOUT that GitHub Actions would deploy with fails it.

The calculation outlives a 504 because Flask handles the request on a2wsgi's
thread pool and a closed connection doesn't stop that thread, not because of
gunicorn's --timeout 0. The incident account now lives only in the operations
document; the workflow comment and the test point to it.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…est timeout

The guard test compared the check's 320 s wait with cloud_run_env.sh's
default, not with the timeout of the candidate the check runs against. It now
reads the CLOUD_RUN_TIMEOUT that deploy-cloud-run-staging's deploy step gets,
through a shared deploy_step_environment helper, and fails: 320 s is not
longer than staging's 900 s.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The check runs against the staging candidate, whose requests may now run for
900 s. Waiting 920 s keeps it longer than that timeout, so the check still
gets the candidate's own answer, a 504 included, as its guard test requires.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…y the parity check outwaits it

deploy_step_request_timeout_setting returns the CLOUD_RUN_TIMEOUT a deploy
step gets as script env, so the three timeout tests read it the same way;
deploy_step_environment says which job lacks one deploy step and returns
YAML's values as parsed. The parity wait's comments give its reason, the
candidate's own answer, and the rewrapped paragraphs read as whole lines.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The parity check now waits up to 920 s for one API v1 answer, and the job's
two pytest runs take about 20 minutes, so 30 minutes would end the job before
an answer at the staging candidate's 900 s limit is reported. Fails until the
job's timeout-minutes is 45.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
So an API v1 answer at the staging candidate's 900 s request timeout, which
the parity check now waits for, is reported before the job's limit.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The live job test now reads timeout-minutes from the parsed workflow and checks
it leaves room for the two pytest runs and one API v1 answer that takes the
full V1_CALCULATION_TIMEOUT_SECONDS, so raising the wait alone fails it. The
comments say the runs take about 20 minutes together and that two full-length
answers in a row on one worker don't fit.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@codecov

codecov Bot commented Dec 1, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 94.03%. Comparing base (9fa521b) to head (94fbfd5).

Additional details and impacted files
@@            Coverage Diff             @@
##           master    #4375      +/-   ##
==========================================
- Coverage   94.04%   94.03%   -0.02%     
==========================================
  Files         449      449              
  Lines       25349    25349              
  Branches     3905     3930      +25     
==========================================
- Hits        23840    23837       -3     
- Misses        860      865       +5     
+ Partials      649      647       -2     
Flag Coverage Δ
integration 60.14% <ø> (ø)
unit 91.42% <ø> (-0.02%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@anth-volk
anth-volk marked this pull request as ready for review December 1, 2026 19:48
@anth-volk
anth-volk merged commit 86faaa8 into master Dec 1, 2026
23 checks passed
@anth-volk
anth-volk deleted the v2plan/d2-1a-staging-request-timeout branch December 1, 2026 19:49

This branch was previously deployed

1 inactive deployment
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.

API v1 staging: let Cloud Run requests run for 900 seconds

1 participant