Skip to content

test(staging): lane 4 F1 Cloud Tasks throttle model + task-target retry invariant - #22453

Merged
Git-on-my-level merged 6 commits into
integration/legacy-retirefrom
lr/04-f1
Oct 19, 2026
Merged

Git-on-my-level merged 6 commits into
integration/legacy-retirefrom
lr/04-f1

Conversation

@Git-on-my-level

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

Copy link
Copy Markdown
Member

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.py is 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.
  • Scenarios drive the real routers.batch_pipeline.enrichment_response with an expected first-summary wait (FirstSummaryCallbackPending):
    • enrichment_fast_500_throttle reproduces the 10-18 18:14Z sync-jobs stall: 25/s, 160 concurrent, ~191 direct jobs/min plus ~37 sr- wakes/min.
    • sync_backfill_0452 reproduces the 10-19 04:52Z sync-backfill stall.
  • scripts/cross_service_checks/task_targets.py adds check_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 each TaskEdge handler and the router helpers it calls, two levels deep. It flags 429/503 anywhere, a 500 outside an except Exception fallback, and an except ExpectedRetry that does not answer retry_response.

Reproduction (1 h virtual runs, python -m testing.fakes.cloud_tasks_queue)

Code Route answer enrichment_fast_500_throttle sync_backfill_0452
733a74ab^ (before #22371) 500 FAIL: 0.1/s, 10,002 of 11,396 direct jobs stuck (prod 10-18: 10,399 at 0.1/s) FAIL: 0.1/s, 2,322 stuck (prod 04:52Z: 3,552)
733a74ab (#22371) 409 PASS: 25/s, 55 pending PASS: 30/s, 22 pending

Throttle calibration comes from ro-prod Monitoring. On 10-19 04:30–07:15Z, sync-jobs-fresh held 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 FirstSummaryCallbackPending to utils.enrichment.outbox, which silently turned #22371's 409 back into a 500 on integration (EXPECTED_RETRIES matches on the defining module). This PR was held until lane 1's fix restored 409.

test_enrichment_fast_500_throttle_passes_on_current_route_code asserts the current route answers 409. It fails until #22371 (main 733a74ab) is synced into integration, which is exactly the regression it guards.

Known violators (added to deploy/cross_service_known_gaps.json in this PR, per lane 1's ruling)

Each key is task-target-retry-semantics|code|<scope>:

account-deletion/routers/users.py:run_account_deletion_wipe/500
batch-quarantine-recovery/routers/batch_pipeline.py:recover_quarantine/503
listen-finalization/routers/conversation_finalization.py:run_listen_finalization_job/500
listen-finalization/routers/conversation_finalization.py:run_listen_finalization_job/503
sync-backfill/routers/sync.py:_run_sync_job_body/500
sync-backfill/routers/sync.py:_run_sync_job_body/503
sync-backfill/routers/sync.py:run_sync_job/500
sync-backfill/routers/sync.py:run_sync_job/503
sync-jobs/routers/sync.py:_run_sync_job_body/500
sync-jobs/routers/sync.py:_run_sync_job_body/503
sync-jobs/routers/sync.py:run_sync_job/500
sync-jobs/routers/sync.py:run_sync_job/503

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.asdict deep-copied a threading.Lock while 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):
  • Scenario CLI was run at 733a74ab^ and 733a74ab from git archive trees (table above).
  • check_dead_code.py --area backend ok; import-purity scan clean.

🤖 Generated with Claude Code

View guided diff Turn on auto-fix

Git-on-my-level and others added 6 commits October 19, 2026 14:24
…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]>
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 19, 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-19T08:37:57.219516Z 95dc6d1 PR opened
ℹ️ 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.

@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: 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".

Comment on lines +244 to +248
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)

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

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

Comment on lines +150 to +155
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))

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

Comment on lines +281 to +284
return 200, rng.uniform(*sync_latency_s)

queue = CloudTasksQueue(handler, config, throttle)
arrivals = _poisson_arrivals(rng, {'sync': sync_per_min, 'enrichment': enrichment_per_min})

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

Comment on lines +251 to +252
expected = per_min / 60.0 * (t1 - t0)
n = int(expected) + (1 if rng.random() < expected - int(expected) else 0)

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

@Git-on-my-level
Git-on-my-level merged commit 60fee3c into integration/legacy-retire Oct 19, 2026
25 checks passed
@Git-on-my-level
Git-on-my-level deleted the lr/04-f1 branch October 19, 2026 08:44
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