Repository navigation
test(staging): lane 4 F1 Cloud Tasks throttle model + task-target retry invariant - #22453
Conversation
…riant (lane 4) Contract (d), plan F F1, cross-plan L5. First merges after the stubs. - testing/fakes/cloud_tasks_queue.py: virtual-clock Cloud Tasks queue (token bucket, concurrency, retry backoff/max attempts, named-task dedupe) with an AIMD system throttle on 429/503 or a high fast-5xx share; a config PATCH caps but never resets it. Scenarios enrichment_fast_500_throttle (10-18 18:14Z sync-jobs) and sync_backfill_0452 (10-19 04:52Z sync-backfill) drive the REAL routers.batch_pipeline.enrichment_response for an expected first-summary wait. At 733a74a^ (pre-#22371, 500) the 1h run strands 10,002 direct jobs at 0.1/s (prod 10-18: 10,399 at 0.1/s) and 2,322 backfill jobs (prod 04:52Z: 3,552); at 733a74a (409) both keep the configured rate and drain. - scripts/cross_service_checks/task_targets.py: check_task_target_retry_semantics(ctx), registered by #22420. AST scan of each TaskEdge handler and the router helpers it calls: 429/503 anywhere, 500 outside an except-Exception fallback, ExpectedRetry not answered by retry_response. Keys carry no line numbers. Co-Authored-By: Claude Opus 5.5 <[email protected]>
…lane 4, contract (d)) Lane 1 ruling: F1 carries its own known-gap entries. Keys are the contract (d) violator table plus the audit-only finalization and account-deletion targets; new keys still fail. Co-Authored-By: Claude Opus 5.5 <[email protected]>
dataclasses.asdict deep-copies a threading.Lock and raised after the copy finished, so the first live run wrote objects and the manifest but no workspace record. Idempotent rerun fills it in. 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.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 95dc6d164e
ℹ️ 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".
| def check_task_target_retry_semantics(ctx) -> list: | ||
| """Registered in scripts/cross_service_contract.py INVARIANTS by lane 1.""" | ||
| from scripts.cross_service_contract import TASK_EDGES, Violation | ||
|
|
||
| return violations_for(TASK_EDGES, load_router_modules(ctx.source), Violation) |
There was a problem hiding this comment.
Register the new invariant in the checks manifest
Register this check in .github/checks-manifest.yaml with both local and ci lanes and triggers for every router tree it scans. The PR workflow uses changed-file selection, and I verified that changes limited to backend/routers/users.py, sync.py, or conversation_finalization.py select neither test_task_target_retry_semantics.py nor test_cross_service_deploy_contract.py; therefore a new forbidden 429/503/unguarded-500 response in those task targets can merge without this invariant running. The repository routes new-check requirements through its dedicated guidance.
AGENTS.md reference: AGENTS.md:L27-L27
Useful? React with 👍 / 👎.
| INVARIANT = 'task-target-retry-semantics' | ||
| ENV = 'code' | ||
| ROUTERS_DIR = 'backend/routers' | ||
| FORBIDDEN = {429, 503} |
There was a problem hiding this comment.
Reject every non-fallback 5xx status
Expand the forbidden-status logic beyond 503. The queue model below treats every fast status >= 500 as a throttle signal, and the stated contract permits only a guarded 500, but this set lets explicit 501, 502, 504, and other 5xx responses pass the invariant anywhere in a task target. For example, changing a target to JSONResponse(status_code=504, ...) would leave this check green while repeated deliveries can collapse the shared queue in exactly the failure mode this change is intended to prevent.
Useful? React with 👍 / 👎.
| if _catches_expected_retry(handler): | ||
| answers = any( | ||
| isinstance(n, ast.Call) and _call_name(n.func) == 'retry_response' for n in ast.walk(handler) | ||
| ) | ||
| if not answers: | ||
| findings.append(Finding(rel, fn.name, 'expected-retry-shape', handler.lineno)) |
There was a problem hiding this comment.
Verify that every expected-retry path returns the retry response
Do not treat the mere presence of a retry_response call anywhere under the handler as proof that the exception is answered correctly. An except ExpectedRetry block can call and discard retry_response, or return it in one conditional branch while another branch returns 200, and any(ast.walk(handler)) accepts the whole handler. In those cases an expected retry is consumed instead of retried while the new invariant remains green; inspect returned expressions and require all reachable exits to return the retry response.
Useful? React with 👍 / 👎.
| return 200, rng.uniform(*sync_latency_s) | ||
|
|
||
| queue = CloudTasksQueue(handler, config, throttle) | ||
| arrivals = _poisson_arrivals(rng, {'sync': sync_per_min, 'enrichment': enrichment_per_min}) |
There was a problem hiding this comment.
Separate arrival and latency random streams
Use independent RNGs, or pre-generate one arrival trace, for the 500-versus-409 counterfactual. The sync handler consumes this same rng once per dispatch, so a throttled run makes fewer uniform() calls and consequently changes all subsequent arrival draws; with the committed seed and a 600-second run, the 500 and 409 scenarios create 1,953 and 1,910 sync tasks respectively. The experiment therefore changes both the response behavior and workload, weakening its claimed causal comparison.
Useful? React with 👍 / 👎.
| expected = per_min / 60.0 * (t1 - t0) | ||
| n = int(expected) + (1 if rng.random() < expected - int(expected) else 0) |
There was a problem hiding this comment.
Generate Poisson arrivals instead of stochastic rounding
Replace this floor-plus-Bernoulli calculation with an actual Poisson process. At the committed 0.1-second tick and current rates, it permits at most one arrival of each kind per tick, whereas a Poisson stream can have multiple simultaneous arrivals; more generally its per-tick variance is at most 0.25 rather than the mean. That suppresses the burstiness which exercises the token bucket and concurrency cap, so the supposedly Poisson workload can make the healthy scenario materially easier than the production-shaped workload.
Useful? React with 👍 / 👎.
Summary
Swarm lane 4, contract (d), plan F F1, cross-plan L5. These are the first merges after the stubs. Test-only and check code; deploy class none.
testing/fakes/cloud_tasks_queue.pyis a virtual-clock Cloud Tasks queue. It models the token bucket (rate and burst), max concurrent dispatches, retry backoff (min·2^k, capped) with max attempts, and named-task dedupe. It also models a system throttle: an AIMD cut on any 429/503, or on a fast-5xx share above 25% of the last 60 s. Recovery is slow and happens only with successful completions. A config PATCH caps the rate but never resets the throttle.routers.batch_pipeline.enrichment_responsewith an expected first-summary wait (FirstSummaryCallbackPending):enrichment_fast_500_throttlereproduces the 10-18 18:14Zsync-jobsstall: 25/s, 160 concurrent, ~191 direct jobs/min plus ~37sr-wakes/min.sync_backfill_0452reproduces the 10-19 04:52Zsync-backfillstall.scripts/cross_service_checks/task_targets.pyaddscheck_task_target_retry_semantics(ctx), already registered by legacy-retire: lane-1 contract stubs (outbox, workers consumer, retry, reasons, runtime percent) #22420. It AST-scans eachTaskEdgehandler and the router helpers it calls, two levels deep. It flags 429/503 anywhere, a 500 outside anexcept Exceptionfallback, and anexcept ExpectedRetrythat does not answerretry_response.Reproduction (1 h virtual runs,
python -m testing.fakes.cloud_tasks_queue)enrichment_fast_500_throttlesync_backfill_0452733a74ab^(before #22371)733a74ab(#22371)Throttle calibration comes from ro-prod Monitoring. On 10-19 04:30–07:15Z,
sync-jobs-freshheld 8–15% non-ok attempts without collapsing. On 10-18, the queue collapsed at 53% fast 500s.Merge dependency and the regression this caught
#22431 (lane 9) moved
FirstSummaryCallbackPendingtoutils.enrichment.outbox, which silently turned #22371's 409 back into a 500 on integration (EXPECTED_RETRIESmatches on the defining module). This PR was held until lane 1's fix restored 409.test_enrichment_fast_500_throttle_passes_on_current_route_codeasserts the current route answers 409. It fails until #22371 (main733a74ab) is synced into integration, which is exactly the regression it guards.Known violators (added to
deploy/cross_service_known_gaps.jsonin this PR, per lane 1's ruling)Each key is
task-target-retry-semantics|code|<scope>:These match contract (d)'s violator table: recover-quarantine 503 (lane 9), legacy sync (lane 10 deletes), finalization and account deletion (audit only).
Failure class (fixes)
Failure-Class: none
The one
fix:commit in this lane's range (28bed4fd) repairs a crash in lane 4's own operator tool after a completed copy (dataclasses.asdictdeep-copied athreading.Lockwhile writing the run record). It is local to new tooling and is not a recurring product failure class.Product invariants affected
none
Also in this PR
fix(staging): the mirror run record no longer crashes after a copy. The first live run wrote 620 objects and the manifest but no workspace record; an idempotent rerun wrote it.Test plan
BACKEND_UNIT_TEST_FILE_LIST=<file> bash test.sh(via omi-heavy, one file at a time):tests/unit/test_task_target_retry_semantics.py: 6 passed.tests/unit/test_cloud_tasks_queue_model.py: 8 passed; the route test is pending the fix(batch): multi-replica hardening and non-5xx enrichment retries #22371 sync.733a74ab^and733a74abfromgit archivetrees (table above).check_dead_code.py --area backendok; import-purity scan clean.🤖 Generated with Claude Code