Repository navigation
legacy-retire: lane-1 contract stubs (outbox, workers consumer, retry, reasons, runtime percent) - #22420
Conversation
…, retry, reasons, runtime percent)
Lane-1 stubs for the legacy-sync retirement swarm (contracts (a), (b), (d), (e), (f)):
- database/outbox.py: OutboxKind, Outcome, Claim, EnqueueResult, SweepCounts, Outbox protocol,
outbox_for selector (NotImplementedError until lane 9's Firestore outbox).
- utils/workers/consumer.py: Role, Result (validated), QueueConsumer protocol, run_push/run_pull
drivers and the 200/409-only http_response mapping; re-exports Outcome/Claim.
- utils/workers/retry.py: ExpectedRetry and retry_response (409 {"status":"retry","reason":...}).
- utils/observability/reasons.py: ReasonFamily, RetryReason, ConsumerReason, RampReason,
reason_label with omi_reason_unknown_total{family}.
- utils/rollout/runtime_percent.py: signatures only (lane 6).
- routers/enrichment.py, routers/batch_provider_stt.py: empty routers (lanes 9 and 8); mounted
after #22388's main.py edit reaches integration.
- scripts/cross_service_contract.py: TaskEdges enrichment and provider-stt; registrations of
task-target-retry-semantics (lane 4) and staging-mirrors-prod (lane 2) via a lazy loader of
scripts/cross_service_checks/<module>.py. Known edge-declared gaps until lane 7's ops file.
No behaviour change: nothing on main calls the new modules.
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.
ℹ️ 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".
| if result.outcome in (Outcome.DONE, Outcome.DISCARDED): | ||
| settled = outbox.ack(claim, reason, now=now) | ||
| elif result.outcome is Outcome.DEFERRED: | ||
| settled = outbox.defer(claim, float(result.available_at), reason, now=now) is not None # type: ignore[arg-type] |
There was a problem hiding this comment.
Preserve the replacement wake after deferring
When a push consumer returns DEFERRED, Outbox.defer returns the new wake token required to re-arm the row, but this line reduces it to a boolean and discards it. The current Cloud Tasks delivery is then answered with 200 and removed, while no caller can create the replacement task for available_at; the row therefore remains unprocessed until a sweep happens, or indefinitely if the sweep is unavailable. Propagate the token so the replacement wake can be scheduled after the durable defer.
Useful? React with 👍 / 👎.
| available_at: float | None = None # required for DEFERRED and RETRY | ||
|
|
||
| def __post_init__(self) -> None: | ||
| outcome = Outcome(self.outcome) |
There was a problem hiding this comment.
Store the normalized outcome in Result
When a caller constructs Result from a decoded string such as Result('retry', RetryReason.LOCKED, ...), this conversion validates successfully but leaves self.outcome as a plain string. The later identity checks for RETRY/DEFERRED then miss, and metrics or http_response attempt result.outcome.value, raising instead of settling the row and returning the intended response. Either store the converted enum with object.__setattr__ or reject non-Outcome inputs.
Useful? React with 👍 / 👎.
| elif result.outcome is Outcome.RETRY: | ||
| settled = outbox.release(claim, reason, now=now) |
There was a problem hiding this comment.
Apply the retry availability before releasing pull work
When run_pull processes a transient failure, Result requires a future available_at, but the RETRY branch discards that value and calls release, whose contract immediately sets lease_until=0 without changing availability. A polling worker can therefore reclaim the same row on its next iteration and hot-loop against a locked or warming dependency instead of waiting until the requested retry time. Persist result.available_at as part of the retry settlement, or otherwise distinguish push retries managed by Cloud Tasks from pull retries.
Useful? React with 👍 / 👎.
| verify_audience_env='ENRICHMENT_TASKS_OIDC_AUDIENCE', | ||
| verify_audience_fallback_env='ENRICHMENT_TASKS_HANDLER_URL', | ||
| deadline_seconds=1500, |
There was a problem hiding this comment.
Enable the declared audience fallback
The new enrichment edge declares ENRICHMENT_TASKS_HANDLER_URL as the verifier fallback but omits audience_fallback=True; _check_edge_audience only substitutes verify_audience_fallback_env when that flag is enabled. Consequently, when the target leaves its explicit audience unset and verifies against the handler URL, the checker models the verified audience as empty and rejects an otherwise matching dispatcher audience. The provider-STT edge has the same omission, so enable the fallback for both declarations.
Useful? React with 👍 / 👎.
…importers land The lane-1 stubs (#22420) are imported only by tests and by lanes' in-flight PRs. Whether they pass the backend dead-code ratchet depended on incidental docstring mentions, so a lane that rewrote reasons.py (#22422) made utils/rollout/runtime_percent.py dead and every lane push failed. Allowlist all seven stub files explicitly. Each reason carries an expiry: delete at the M3 merge. Data allowlist only; no workflow change. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Keep lane 6's runtime_percent implementation (the stub was handed over per swarm-plan §3). The controller now uses utils.observability.reasons.RampReason. Co-Authored-By: Claude Opus 5.5 <[email protected]>
…ry invariant (#22453) * test(staging): F1 Cloud Tasks throttle model + task-target retry invariant (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]> * chore(contract): accept the 12 existing task-target retry violators (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]> * fix(staging): mirror run record no longer deep-copies the stats lock 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]> --------- Co-authored-by: Claude Opus 5.5 <[email protected]>
…ce on integration #22446 (main) allowed the reason-ratio alert to land before its producers, with a test that fails once a producer is declared. The lane-1 stub (#22420) already declares omi_reason_unknown_total, so after the #22388 sync every integration PR failed test_pending_backend_alert_metric_allowances_expire_when_the_producer_lands. Keep only omi_reason_total pending; lane 14 (#22422) removes it when it lands the denominator. Verified: pytest tests/unit/test_monitoring_alert_rule_contract.py, 60 passed (unit). Co-Authored-By: Claude Opus 5.5 <[email protected]>
…ad selection (#22475) * test(staging): F1 Cloud Tasks throttle model + task-target retry invariant (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]> * chore(contract): accept the 12 existing task-target retry violators (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]> * fix(staging): mirror run record no longer deep-copies the stats lock 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]> * feat(staging): archive mirror reads only chunks/<owner>/ and can spread across history David's 10-19 grant is conditioned to chunks/<uid>/ in omi-private-cloud-sync; the mirror no longer lists raw-sync/ or raw-mobile-batch/ there. --family, --spread and --max-group-mb pick parity conversations evenly across his capture history (rows 1b/2) instead of only the newest. Co-Authored-By: Claude Opus 5.5 <[email protected]> --------- Co-authored-by: Claude Opus 5.5 <[email protected]>
Summary
Lane-1 (integration captain) contract stubs for the legacy-sync retirement swarm, targeting
integration/legacy-retire. Contracts: omi-knowledge-baseprojects/backend-target-architecture/contracts.md(a), (b), (d), (e), (f).database/outbox.py:OutboxKind,Outcome,Claim,EnqueueResult,SweepCounts, theOutboxprotocol (withpolicy_id/coalesce/txonenqueue) and theoutbox_forselector (raises until lane 9's Firestore outbox). Imports nothing fromutils.workers.utils/workers/consumer.py:Role, a validatedResult(RETRY needs aRetryReasonandavailable_at; DEFERRED needsavailable_at), theQueueConsumerprotocol, workingrun_push/run_pulldrivers, and the 200/409-onlyhttp_response. Re-exportsOutcome/Claim. Unexpected exceptions propagate (route answers 500) and countomi_consumer_unexpected_total{kind}.utils/workers/retry.py:ExpectedRetryandretry_response-> 409{"status":"retry","reason":...}.utils/observability/reasons.py:ReasonFamily,RetryReason,ConsumerReason,RampReason,reason_labelwithomi_reason_unknown_total{family}(passes to lane 14).utils/rollout/runtime_percent.py: signatures only (passes to lane 6). No package__init__yet (dead-code ratchet); lane 6 adds it with the first importer.routers/enrichment.py,routers/batch_provider_stt.py: empty routers (lanes 9, 8). Not mounted yet:main.pyis frozen by fix: make cap-held recovery durable across restarts #22388; the one mount block lands after fix: make cap-held recovery durable across restarts #22388 reaches integration.scripts/cross_service_contract.py: TaskEdgesenrichmentandprovider-stt; registrationstask-target-retry-semantics(body: lane 4,scripts/cross_service_checks/task_targets.py::check_task_target_retry_semantics) andstaging-mirrors-prod(body: lane 2,scripts/cross_service_checks/staging.py::check_staging_mirrors_prod) via a lazy loader. Fouredge-declaredknown gaps until lane 7's ops file declares the dispatch modes.config/policy/**(Sol/E1 owns it from day one).No behaviour change: nothing on main imports the new modules.
Verification
pytest tests/unit/test_workers_consumer_contract.py: 21 passed (unit; fake outbox).python scripts/cross_service_contract.py: 0 new violations, 23 known gaps, 0 stale.pytest tests/unit/test_cross_service_deploy_contract.py: 18 passed, 3 skipped (replay opt-in).check_dead_code.pyok;check_lifecycle_headers.pyok; pre-push preflight.🤖 Generated with Claude Code