Repository navigation
Bound sync backfill inputs before reducing Cloud Run memory to 4 GiB - #20662
Git-on-my-level wants to merge 8 commits into
Conversation
|
Parking this PR. Luna's round-2 review found that the new input limits return 413 before the server takes custody of the upload. The app treats 413 as a terminal 🤖 Generated with Claude Code |
|
Superseded by #22452, which lands only the input-limit guards (admission 413, bounded worker download/expansion, 503 deferral, runbook, tests) on current main. The 4 GiB / concurrency 3 / max 18 / 1 GiB tmpfs sizing is dropped: main runs 8 GiB / concurrency 6 with live max-scale (#20661, #21959), and that sizing would need its own qualification. Closing. |
|
Hey @Git-on-my-level 👋 Thank you so much for taking the time to contribute to Omi! We truly appreciate you putting in the effort to submit this pull request. After careful review, we've decided not to merge this particular PR. Please don't take this personally — we genuinely try to merge as many contributions as possible, but sometimes we have to make tough calls based on:
Before your next PR, please skim:
If this was declined for direction or taste, maintainers should cite an invariant ID or open a proposed one — ask if that citation is missing. Your contribution is still valuable to us, and we'd love to see you contribute again in the future! If you'd like feedback on how to improve this PR or want to discuss alternative approaches, please don't hesitate to reach out. Thank you for being part of the Omi community! |
… 9, C2 slices 2-3; absorbs #21968) (#22444) * refactor(enrichment): move the sr- outbox into utils/enrichment (C2 slice 1) Plan C2, swarm lane 9. Pure move, no behaviour change: - utils/sync/reprocess.py -> utils/enrichment/outbox.py - utils/sync/enrichment_custody.py -> utils/enrichment/custody.py - utils/sync/enrichment_scan.py -> utils/enrichment/scan.py The old paths become sys.modules aliases of the new modules, so every importer, mock.patch target and monkeypatch keeps reaching the same module object. A star import gives pyright the public names. Batch projection imports the new path; the frozen prod-track files (serving.py, routers/batch_pipeline.py, batch_pipeline/enrichment.py) keep the shim until their PRs reach integration. Collection, document ids, field names and the sr- task prefix are unchanged (contract (b) invariant 7). The query-shape driver and background-task baseline follow the moved function. Co-Authored-By: Claude Opus 5.5 <[email protected]> * refactor(enrichment): drop the test-only custody and scan aliases Only tests imported utils.sync.enrichment_custody and enrichment_scan, so the dead-code ratchet counts the aliases as new dead files. The tests now import utils.enrichment.scan directly; utils.sync.reprocess keeps its alias for the production importers. Co-Authored-By: Claude Opus 5.5 <[email protected]> * test(enrichment): import the probe modules at collection time The fast-unit CPU guard charged utils.cloud_tasks' first import to the probe test's call phase (0.53s > 0.30s) once this file was selected. Module-level imports keep the assertions unchanged and the call phase cheap. Co-Authored-By: Claude Opus 5.5 <[email protected]> * fix(enrichment): own the sr- callback and absorb lifecycle fences (C2 slice 3) Plan C2, swarm lane 9. Batch enrichment no longer imports legacy transcription (utils/sync/pipeline.py): - utils/enrichment/callback.py: enrich_conversation, extracted verbatim from pipeline._reprocess_conversation_after_update with its webhook helper, persistence fence and lineage sentinel. pipeline.py is frozen behind #21932/#20662 and keeps its copy for the non-coalescing direct path, so test_enrichment_callback_parity.py (a static tripwire, labelled as such) keeps the two bodies identical until C11 deletes the legacy one. The new copy logs no conversation id. - utils/enrichment/custody.py now owns discard_blocked. The batch adapter re-exports it for its existing importers. - Absorbs #21968 (lead ruling 10-19): a SyncConversationPersistenceFenced from the callback settles the claim as superseded. The obligation is retired when no newer mark landed and re-armed when one did, and the handler ACKs 200 instead of answering 500 to a delivery that can never win. Other errors keep their taxonomy. #21968's conversation_id log line is not carried; the event is logged without identifiers. Failure-Class: none Verification (local unit, serial, nice 19): - test_enrichment_callback_fence 4 passed (fenced+unchanged -> retired; fenced+newer mark -> re-armed; ValueError propagates; the default callback is the package) - test_enrichment_callback_parity 3 passed - test_batch_pipeline_serving 31 passed - test_listen_finalization_cloud_tasks 278 passed - test_sync_reprocess_coalesce 88 passed - test_sync_enrichment_custody 10 passed - test_background_task_ratchet, test_llm_gateway_coverage_guardrails and test_generated_compute_inventory_guardrails passed - pyright 0 errors - test_sync_reprocess_emulator now patches the package callback (CI emulator lane) Co-Authored-By: Claude Opus 5.5 <[email protected]> * feat(enrichment): Firestore Outbox for OutboxKind.ENRICHMENT (C2 slice 2) Plan C2 / contract (b), swarm lane 9. database/outbox_firestore.py implements the Outbox protocol over sync_reprocess_outbox, row-compatible with mark/run: same collection, document ids, field names and sr- names. Additive fields: policy_id, claim_attempts, a transient summary_seen_by. - lease_token is the per-claim owner uuid and wake_token is task_token. heartbeat/ack/defer/release are fenced on both (invariant 1). - claim_key: privacy discard first (invariant 6), then demand admission, a stale or busy check, and a not-due re-arm that wakes itself and returns DEFERRED. Wake ownership follows the lead's 10-19 ruling: this implementation creates the tasks through the existing _enqueue. - ack keeps today's finish rules: retire when unchanged, a dormant receipt when record_summary marked the lease, re-arm when the version moved. - enqueue shares mark's CAS operation (mark_update), with explicit available_at and min/max coalescing (invariant 3). With tx= it writes in the caller's transaction and returns the wake token; the caller calls wake() after commit (invariants 4-5). wake() is idempotent per token. - sweep delegates to the existing sweep with a privacy discard hook. Pull claim() goes through the new utils.enrichment.outbox.due_rows (single-field due_at index), registered in the query-shape drivers. Batch projection's mark_enrichment now calls enqueue(tx=...) and then wake(), using its own client for both. A backfill binding is still resolved only for a new row (new_dispatch callable), so a coalesced append never raises on a missing backfill env, as before. database.outbox.outbox_for is lane 1's stub; firestore_outbox(kind) is the implementation it should return (wiring requested from the captain). Verification (local unit, serial, nice 19): - test_outbox_firestore 13 passed - test_batch_pipeline_projection 40 passed - test_sync_reprocess_coalesce 88 passed - test_firestore_query_shapes 481 passed - the outside-query, runtime-witness and index-oracle suites passed - test_listen_finalization_cloud_tasks 278 passed - pyright 0 errors The emulator conformance suite is lane 12's and has not landed yet. Co-Authored-By: Claude Opus 5.5 <[email protected]> * feat(enrichment): outbox_for selects the Firestore enrichment outbox Lane 1 signed off on this one-function edit of its stub (10-19): in this window the selector always returns the Firestore implementation; the BATCH_JOBSTORE_MODE switch is lane 12's. Co-Authored-By: Claude Opus 5.5 <[email protected]> * fix(enrichment): match moved retry classes so callback-pending stays 409 #22371 classifies expected enrichment retries by (defining module, class name). #22431 moved FirstSummaryCallbackPending to utils.enrichment.outbox, so on integration a callback-pending delivery fell through to the unexpected branch and answered 500. That is the fast-5xx shape that throttled the queues on 10-18 and 10-19. Match the new defining modules, and keep the legacy pipeline fence until pipeline.py is deleted. Failure-Class: none Verification: test_batch_pipeline_serving 38 passed (it failed with 500 != 409 before this change on the merged integration tree). Co-Authored-By: Claude Opus 5.5 <[email protected]> * feat(enrichment): FirestoreOutbox factory with injected client, privacy check and wake For lane 12's outbox conformance suite (build_outbox_backend('emulator')): FirestoreOutbox(kind, client=, privacy_blocked=, create_wake=) binds every CAS, the sweep and every wake to the injected seams. The default instance keeps the production paths (discard_blocked, _enqueue, the shared client). outbox._cas is the client-explicit CAS behind _mutate, and sweep takes client=/wake= for the same purpose. A not-due claim_key deferral leaves claim_attempts untouched (attempt stays 1 on the first real claim), as reprocess does today; there is a test for it. Verification: test_outbox_firestore 16 passed, test_batch_pipeline_projection 40, test_sync_reprocess_coalesce 88, test_firestore_query_shapes 481, test_sync_enrichment_custody 10; pyright 0 errors. Co-Authored-By: Claude Opus 5.5 <[email protected]> --------- Co-authored-by: Claude Opus 5.5 <[email protected]>
… retries (lane 9, C3) (#22462) * refactor(enrichment): move the sr- outbox into utils/enrichment (C2 slice 1) Plan C2, swarm lane 9. Pure move, no behaviour change: - utils/sync/reprocess.py -> utils/enrichment/outbox.py - utils/sync/enrichment_custody.py -> utils/enrichment/custody.py - utils/sync/enrichment_scan.py -> utils/enrichment/scan.py The old paths become sys.modules aliases of the new modules, so every importer, mock.patch target and monkeypatch keeps reaching the same module object. A star import gives pyright the public names. Batch projection imports the new path; the frozen prod-track files (serving.py, routers/batch_pipeline.py, batch_pipeline/enrichment.py) keep the shim until their PRs reach integration. Collection, document ids, field names and the sr- task prefix are unchanged (contract (b) invariant 7). The query-shape driver and background-task baseline follow the moved function. Co-Authored-By: Claude Opus 5.5 <[email protected]> * refactor(enrichment): drop the test-only custody and scan aliases Only tests imported utils.sync.enrichment_custody and enrichment_scan, so the dead-code ratchet counts the aliases as new dead files. The tests now import utils.enrichment.scan directly; utils.sync.reprocess keeps its alias for the production importers. Co-Authored-By: Claude Opus 5.5 <[email protected]> * test(enrichment): import the probe modules at collection time The fast-unit CPU guard charged utils.cloud_tasks' first import to the probe test's call phase (0.53s > 0.30s) once this file was selected. Module-level imports keep the assertions unchanged and the call phase cheap. Co-Authored-By: Claude Opus 5.5 <[email protected]> * fix(enrichment): own the sr- callback and absorb lifecycle fences (C2 slice 3) Plan C2, swarm lane 9. Batch enrichment no longer imports legacy transcription (utils/sync/pipeline.py): - utils/enrichment/callback.py: enrich_conversation, extracted verbatim from pipeline._reprocess_conversation_after_update with its webhook helper, persistence fence and lineage sentinel. pipeline.py is frozen behind #21932/#20662 and keeps its copy for the non-coalescing direct path, so test_enrichment_callback_parity.py (a static tripwire, labelled as such) keeps the two bodies identical until C11 deletes the legacy one. The new copy logs no conversation id. - utils/enrichment/custody.py now owns discard_blocked. The batch adapter re-exports it for its existing importers. - Absorbs #21968 (lead ruling 10-19): a SyncConversationPersistenceFenced from the callback settles the claim as superseded. The obligation is retired when no newer mark landed and re-armed when one did, and the handler ACKs 200 instead of answering 500 to a delivery that can never win. Other errors keep their taxonomy. #21968's conversation_id log line is not carried; the event is logged without identifiers. Failure-Class: none Verification (local unit, serial, nice 19): - test_enrichment_callback_fence 4 passed (fenced+unchanged -> retired; fenced+newer mark -> re-armed; ValueError propagates; the default callback is the package) - test_enrichment_callback_parity 3 passed - test_batch_pipeline_serving 31 passed - test_listen_finalization_cloud_tasks 278 passed - test_sync_reprocess_coalesce 88 passed - test_sync_enrichment_custody 10 passed - test_background_task_ratchet, test_llm_gateway_coverage_guardrails and test_generated_compute_inventory_guardrails passed - pyright 0 errors - test_sync_reprocess_emulator now patches the package callback (CI emulator lane) Co-Authored-By: Claude Opus 5.5 <[email protected]> * feat(enrichment): Firestore Outbox for OutboxKind.ENRICHMENT (C2 slice 2) Plan C2 / contract (b), swarm lane 9. database/outbox_firestore.py implements the Outbox protocol over sync_reprocess_outbox, row-compatible with mark/run: same collection, document ids, field names and sr- names. Additive fields: policy_id, claim_attempts, a transient summary_seen_by. - lease_token is the per-claim owner uuid and wake_token is task_token. heartbeat/ack/defer/release are fenced on both (invariant 1). - claim_key: privacy discard first (invariant 6), then demand admission, a stale or busy check, and a not-due re-arm that wakes itself and returns DEFERRED. Wake ownership follows the lead's 10-19 ruling: this implementation creates the tasks through the existing _enqueue. - ack keeps today's finish rules: retire when unchanged, a dormant receipt when record_summary marked the lease, re-arm when the version moved. - enqueue shares mark's CAS operation (mark_update), with explicit available_at and min/max coalescing (invariant 3). With tx= it writes in the caller's transaction and returns the wake token; the caller calls wake() after commit (invariants 4-5). wake() is idempotent per token. - sweep delegates to the existing sweep with a privacy discard hook. Pull claim() goes through the new utils.enrichment.outbox.due_rows (single-field due_at index), registered in the query-shape drivers. Batch projection's mark_enrichment now calls enqueue(tx=...) and then wake(), using its own client for both. A backfill binding is still resolved only for a new row (new_dispatch callable), so a coalesced append never raises on a missing backfill env, as before. database.outbox.outbox_for is lane 1's stub; firestore_outbox(kind) is the implementation it should return (wiring requested from the captain). Verification (local unit, serial, nice 19): - test_outbox_firestore 13 passed - test_batch_pipeline_projection 40 passed - test_sync_reprocess_coalesce 88 passed - test_firestore_query_shapes 481 passed - the outside-query, runtime-witness and index-oracle suites passed - test_listen_finalization_cloud_tasks 278 passed - pyright 0 errors The emulator conformance suite is lane 12's and has not landed yet. Co-Authored-By: Claude Opus 5.5 <[email protected]> * feat(enrichment): outbox_for selects the Firestore enrichment outbox Lane 1 signed off on this one-function edit of its stub (10-19): in this window the selector always returns the Firestore implementation; the BATCH_JOBSTORE_MODE switch is lane 12's. Co-Authored-By: Claude Opus 5.5 <[email protected]> * feat(enrichment): /v2/enrichment/run on the outbox consumer, 409-only retries (C3) Plan C3 / contracts (a) and (d), swarm lane 9. - utils/enrichment/consumer.py: EnrichmentConsumer, a QueueConsumer for OutboxKind.ENRICHMENT (workers role; 120s lease, 30s heartbeat on every lease). It mirrors reprocess.run outcome for outcome, with settlement through the Outbox calls: - processed -> DONE (ack; a dormant receipt via record_summary); - superseded or lifecycle fence -> DISCARDED; - repair race -> outbox.repair; - live target or missing conversation -> DEFERRED +120s; - redirect -> custody transfer; - empty budget spent -> retired; - callback pending or empty output -> RETRY callback_pending (409; release keeps the wake for the queue retry). - routers/enrichment.py: POST /v2/enrichment/run with OIDC for the enrichment queue (TaskEdge enrichment). It accepts the legacy {"kind":"sync_reprocess",...} payload, so rows bound to either handler drain. 400 for a malformed task; 500 only for unexpected exceptions. - config/enrichment.py: ENRICHMENT_ROUTE (sync_handler | enrichment_queue, default sync_handler) is the deployment default for the policy field enrichment_route until E1 records it per unit. ENRICHMENT_TASKS_* is the queue binding. An incomplete binding falls back to the sync handler and is counted through record_fallback. - valid_dispatch_binding and _enqueue accept both handler paths (contract (b) invariant 7). The router mount in main.py is lane 1's. Queue spec for lane 7: enrichment, max-concurrent 50, 25/s, backoff 10-300s, unlimited attempts. Verification (local unit, serial, nice 19): - test_enrichment_route 12 passed (409 callback_pending keeps the wake; fence -> superseded; live defer -> new wake; 400s; stale wake -> 200; unexpected -> 5xx with the lease kept; route binding with fallback) - test_outbox_firestore 14 passed - test_sync_reprocess_coalesce 88 passed - test_cross_service_deploy_contract and test_background_task_ratchet passed - pyright 0 errors Co-Authored-By: Claude Opus 5.5 <[email protected]> * fix(enrichment): match moved retry classes so callback-pending stays 409 #22371 classifies expected enrichment retries by (defining module, class name). #22431 moved FirstSummaryCallbackPending to utils.enrichment.outbox, so on integration a callback-pending delivery fell through to the unexpected branch and answered 500. That is the fast-5xx shape that throttled the queues on 10-18 and 10-19. Match the new defining modules, and keep the legacy pipeline fence until pipeline.py is deleted. Failure-Class: none Verification: test_batch_pipeline_serving 38 passed (it failed with 500 != 409 before this change on the merged integration tree). Co-Authored-By: Claude Opus 5.5 <[email protected]> * feat(enrichment): FirestoreOutbox factory with injected client, privacy check and wake For lane 12's outbox conformance suite (build_outbox_backend('emulator')): FirestoreOutbox(kind, client=, privacy_blocked=, create_wake=) binds every CAS, the sweep and every wake to the injected seams. The default instance keeps the production paths (discard_blocked, _enqueue, the shared client). outbox._cas is the client-explicit CAS behind _mutate, and sweep takes client=/wake= for the same purpose. A not-due claim_key deferral leaves claim_attempts untouched (attempt stays 1 on the first real claim), as reprocess does today; there is a test for it. Verification: test_outbox_firestore 16 passed, test_batch_pipeline_projection 40, test_sync_reprocess_coalesce 88, test_firestore_query_shapes 481, test_sync_enrichment_custody 10; pyright 0 errors. Co-Authored-By: Claude Opus 5.5 <[email protected]> * test(enrichment): a not-due wake re-arms and answers 200 not_due Exercises #22437's claim_key DEFERRED mapping end to end through /v2/enrichment/run: the outbox re-arms with a new wake and the delivery is consumed, not retried. Co-Authored-By: Claude Opus 5.5 <[email protected]> * test(enrichment): load the callback at collection time in the route tests The fast-unit CPU guard charged process_conversation's first import to the first route test (6.8s > 0.30s). Co-Authored-By: Claude Opus 5.5 <[email protected]> --------- Co-authored-by: Claude Opus 5.5 <[email protected]>
…legates to the consumer (lane 9) (#22476) * refactor(enrichment): move the sr- outbox into utils/enrichment (C2 slice 1) Plan C2, swarm lane 9. Pure move, no behaviour change: - utils/sync/reprocess.py -> utils/enrichment/outbox.py - utils/sync/enrichment_custody.py -> utils/enrichment/custody.py - utils/sync/enrichment_scan.py -> utils/enrichment/scan.py The old paths become sys.modules aliases of the new modules, so every importer, mock.patch target and monkeypatch keeps reaching the same module object. A star import gives pyright the public names. Batch projection imports the new path; the frozen prod-track files (serving.py, routers/batch_pipeline.py, batch_pipeline/enrichment.py) keep the shim until their PRs reach integration. Collection, document ids, field names and the sr- task prefix are unchanged (contract (b) invariant 7). The query-shape driver and background-task baseline follow the moved function. Co-Authored-By: Claude Opus 5.5 <[email protected]> * refactor(enrichment): drop the test-only custody and scan aliases Only tests imported utils.sync.enrichment_custody and enrichment_scan, so the dead-code ratchet counts the aliases as new dead files. The tests now import utils.enrichment.scan directly; utils.sync.reprocess keeps its alias for the production importers. Co-Authored-By: Claude Opus 5.5 <[email protected]> * test(enrichment): import the probe modules at collection time The fast-unit CPU guard charged utils.cloud_tasks' first import to the probe test's call phase (0.53s > 0.30s) once this file was selected. Module-level imports keep the assertions unchanged and the call phase cheap. Co-Authored-By: Claude Opus 5.5 <[email protected]> * fix(enrichment): own the sr- callback and absorb lifecycle fences (C2 slice 3) Plan C2, swarm lane 9. Batch enrichment no longer imports legacy transcription (utils/sync/pipeline.py): - utils/enrichment/callback.py: enrich_conversation, extracted verbatim from pipeline._reprocess_conversation_after_update with its webhook helper, persistence fence and lineage sentinel. pipeline.py is frozen behind #21932/#20662 and keeps its copy for the non-coalescing direct path, so test_enrichment_callback_parity.py (a static tripwire, labelled as such) keeps the two bodies identical until C11 deletes the legacy one. The new copy logs no conversation id. - utils/enrichment/custody.py now owns discard_blocked. The batch adapter re-exports it for its existing importers. - Absorbs #21968 (lead ruling 10-19): a SyncConversationPersistenceFenced from the callback settles the claim as superseded. The obligation is retired when no newer mark landed and re-armed when one did, and the handler ACKs 200 instead of answering 500 to a delivery that can never win. Other errors keep their taxonomy. #21968's conversation_id log line is not carried; the event is logged without identifiers. Failure-Class: none Verification (local unit, serial, nice 19): - test_enrichment_callback_fence 4 passed (fenced+unchanged -> retired; fenced+newer mark -> re-armed; ValueError propagates; the default callback is the package) - test_enrichment_callback_parity 3 passed - test_batch_pipeline_serving 31 passed - test_listen_finalization_cloud_tasks 278 passed - test_sync_reprocess_coalesce 88 passed - test_sync_enrichment_custody 10 passed - test_background_task_ratchet, test_llm_gateway_coverage_guardrails and test_generated_compute_inventory_guardrails passed - pyright 0 errors - test_sync_reprocess_emulator now patches the package callback (CI emulator lane) Co-Authored-By: Claude Opus 5.5 <[email protected]> * feat(enrichment): Firestore Outbox for OutboxKind.ENRICHMENT (C2 slice 2) Plan C2 / contract (b), swarm lane 9. database/outbox_firestore.py implements the Outbox protocol over sync_reprocess_outbox, row-compatible with mark/run: same collection, document ids, field names and sr- names. Additive fields: policy_id, claim_attempts, a transient summary_seen_by. - lease_token is the per-claim owner uuid and wake_token is task_token. heartbeat/ack/defer/release are fenced on both (invariant 1). - claim_key: privacy discard first (invariant 6), then demand admission, a stale or busy check, and a not-due re-arm that wakes itself and returns DEFERRED. Wake ownership follows the lead's 10-19 ruling: this implementation creates the tasks through the existing _enqueue. - ack keeps today's finish rules: retire when unchanged, a dormant receipt when record_summary marked the lease, re-arm when the version moved. - enqueue shares mark's CAS operation (mark_update), with explicit available_at and min/max coalescing (invariant 3). With tx= it writes in the caller's transaction and returns the wake token; the caller calls wake() after commit (invariants 4-5). wake() is idempotent per token. - sweep delegates to the existing sweep with a privacy discard hook. Pull claim() goes through the new utils.enrichment.outbox.due_rows (single-field due_at index), registered in the query-shape drivers. Batch projection's mark_enrichment now calls enqueue(tx=...) and then wake(), using its own client for both. A backfill binding is still resolved only for a new row (new_dispatch callable), so a coalesced append never raises on a missing backfill env, as before. database.outbox.outbox_for is lane 1's stub; firestore_outbox(kind) is the implementation it should return (wiring requested from the captain). Verification (local unit, serial, nice 19): - test_outbox_firestore 13 passed - test_batch_pipeline_projection 40 passed - test_sync_reprocess_coalesce 88 passed - test_firestore_query_shapes 481 passed - the outside-query, runtime-witness and index-oracle suites passed - test_listen_finalization_cloud_tasks 278 passed - pyright 0 errors The emulator conformance suite is lane 12's and has not landed yet. Co-Authored-By: Claude Opus 5.5 <[email protected]> * feat(enrichment): outbox_for selects the Firestore enrichment outbox Lane 1 signed off on this one-function edit of its stub (10-19): in this window the selector always returns the Firestore implementation; the BATCH_JOBSTORE_MODE switch is lane 12's. Co-Authored-By: Claude Opus 5.5 <[email protected]> * feat(enrichment): /v2/enrichment/run on the outbox consumer, 409-only retries (C3) Plan C3 / contracts (a) and (d), swarm lane 9. - utils/enrichment/consumer.py: EnrichmentConsumer, a QueueConsumer for OutboxKind.ENRICHMENT (workers role; 120s lease, 30s heartbeat on every lease). It mirrors reprocess.run outcome for outcome, with settlement through the Outbox calls: - processed -> DONE (ack; a dormant receipt via record_summary); - superseded or lifecycle fence -> DISCARDED; - repair race -> outbox.repair; - live target or missing conversation -> DEFERRED +120s; - redirect -> custody transfer; - empty budget spent -> retired; - callback pending or empty output -> RETRY callback_pending (409; release keeps the wake for the queue retry). - routers/enrichment.py: POST /v2/enrichment/run with OIDC for the enrichment queue (TaskEdge enrichment). It accepts the legacy {"kind":"sync_reprocess",...} payload, so rows bound to either handler drain. 400 for a malformed task; 500 only for unexpected exceptions. - config/enrichment.py: ENRICHMENT_ROUTE (sync_handler | enrichment_queue, default sync_handler) is the deployment default for the policy field enrichment_route until E1 records it per unit. ENRICHMENT_TASKS_* is the queue binding. An incomplete binding falls back to the sync handler and is counted through record_fallback. - valid_dispatch_binding and _enqueue accept both handler paths (contract (b) invariant 7). The router mount in main.py is lane 1's. Queue spec for lane 7: enrichment, max-concurrent 50, 25/s, backoff 10-300s, unlimited attempts. Verification (local unit, serial, nice 19): - test_enrichment_route 12 passed (409 callback_pending keeps the wake; fence -> superseded; live defer -> new wake; 400s; stale wake -> 200; unexpected -> 5xx with the lease kept; route binding with fallback) - test_outbox_firestore 14 passed - test_sync_reprocess_coalesce 88 passed - test_cross_service_deploy_contract and test_background_task_ratchet passed - pyright 0 errors Co-Authored-By: Claude Opus 5.5 <[email protected]> * fix(enrichment): match moved retry classes so callback-pending stays 409 #22371 classifies expected enrichment retries by (defining module, class name). #22431 moved FirstSummaryCallbackPending to utils.enrichment.outbox, so on integration a callback-pending delivery fell through to the unexpected branch and answered 500. That is the fast-5xx shape that throttled the queues on 10-18 and 10-19. Match the new defining modules, and keep the legacy pipeline fence until pipeline.py is deleted. Failure-Class: none Verification: test_batch_pipeline_serving 38 passed (it failed with 500 != 409 before this change on the merged integration tree). Co-Authored-By: Claude Opus 5.5 <[email protected]> * feat(enrichment): FirestoreOutbox factory with injected client, privacy check and wake For lane 12's outbox conformance suite (build_outbox_backend('emulator')): FirestoreOutbox(kind, client=, privacy_blocked=, create_wake=) binds every CAS, the sweep and every wake to the injected seams. The default instance keeps the production paths (discard_blocked, _enqueue, the shared client). outbox._cas is the client-explicit CAS behind _mutate, and sweep takes client=/wake= for the same purpose. A not-due claim_key deferral leaves claim_attempts untouched (attempt stays 1 on the first real claim), as reprocess does today; there is a test for it. Verification: test_outbox_firestore 16 passed, test_batch_pipeline_projection 40, test_sync_reprocess_coalesce 88, test_firestore_query_shapes 481, test_sync_enrichment_custody 10; pyright 0 errors. Co-Authored-By: Claude Opus 5.5 <[email protected]> * test(enrichment): a not-due wake re-arms and answers 200 not_due Exercises #22437's claim_key DEFERRED mapping end to end through /v2/enrichment/run: the outbox re-arms with a new wake and the delivery is consumed, not retried. Co-Authored-By: Claude Opus 5.5 <[email protected]> * test(enrichment): load the callback at collection time in the route tests The fast-unit CPU guard charged process_conversation's first import to the first route test (6.8s > 0.30s). Co-Authored-By: Claude Opus 5.5 <[email protected]> * fix(batch): recover-quarantine kill switch answers 409; legacy sr- delegates to the consumer Contract (d), swarm lane 9: - /v2/batch-pipeline/recover-quarantine returned 503 for "recovery disabled" (host or owner). Cloud Tasks system-throttles a queue that sees fast 5xx/503 (10-18 18:14Z, 10-19 04:52Z stalls). A switched-off target now answers 409 {"status":"retry","reason":"kill_switch_off"}. Behaviour is otherwise unchanged: the intent stays prepared, nothing is spent, and the queue retries. - enrichment_response (the legacy /v2/sync-jobs/run sync_reprocess delivery) runs through the C3 EnrichmentConsumer when ENRICHMENT_ROUTE=enrichment_queue, so one lever moves new rows onto the enrichment queue and drains old bindings through the same state machine. Default sync_handler keeps today's reprocess.run path. Failure-Class: none Verification (local unit, serial, nice 19): - test_batch_pipeline_quarantine_recovery 67 passed (the disabled-host, -cohort and -missing cases assert 409 kill_switch_off) - test_enrichment_route 14 passed (incl. legacy-handler delegation) - test_batch_pipeline_serving 39 passed - test_revision_drain_harness 7 passed - test_cross_service_deploy_contract 18 passed Co-Authored-By: Claude Opus 5.5 <[email protected]> --------- Co-authored-by: Claude Opus 5.5 <[email protected]>
…cy work (#22452) * fix(sync): bound historical backfill inputs and defer over-limit legacy work Admission (V1/V2) rejects over-limit backfill batches with 413 before custody transfer; the Cloud Tasks worker bounds each staged download and decode expansion, and answers 503 (job re-queued, audio and content claims preserved) for legacy over-limit work or retryable tmpfs pressure. No Cloud Run sizing change: supersedes the input-guard portion of #20662. Failure-Class: none Co-Authored-By: Claude Sonnet 5.5 <[email protected]> * test: backfill staged downloads now pass bounded_backfill=True Co-Authored-By: Claude Sonnet 5.5 <[email protected]> * fix(sync): defer over-limit backfill work with 409, keep V1 on its 503, harden prefetch/opus/batch pressure paths Failure-Class: none Co-Authored-By: Claude Sonnet 5.5 <[email protected]> * test: allowlist import-amortized first tests in test_sync_input_limits Co-Authored-By: Claude Sonnet 5.5 <[email protected]> * fix(sync): keep decode cleanup on one path so capacity pressure re-raises without new path sinks Co-Authored-By: Claude Sonnet 5.5 <[email protected]> --------- Co-authored-by: Claude Sonnet 5.5 <[email protected]>
…weep (lane 9, C4) (#22517) * refactor(enrichment): move the sr- outbox into utils/enrichment (C2 slice 1) Plan C2, swarm lane 9. Pure move, no behaviour change: - utils/sync/reprocess.py -> utils/enrichment/outbox.py - utils/sync/enrichment_custody.py -> utils/enrichment/custody.py - utils/sync/enrichment_scan.py -> utils/enrichment/scan.py The old paths become sys.modules aliases of the new modules, so every importer, mock.patch target and monkeypatch keeps reaching the same module object. A star import gives pyright the public names. Batch projection imports the new path; the frozen prod-track files (serving.py, routers/batch_pipeline.py, batch_pipeline/enrichment.py) keep the shim until their PRs reach integration. Collection, document ids, field names and the sr- task prefix are unchanged (contract (b) invariant 7). The query-shape driver and background-task baseline follow the moved function. Co-Authored-By: Claude Opus 5.5 <[email protected]> * refactor(enrichment): drop the test-only custody and scan aliases Only tests imported utils.sync.enrichment_custody and enrichment_scan, so the dead-code ratchet counts the aliases as new dead files. The tests now import utils.enrichment.scan directly; utils.sync.reprocess keeps its alias for the production importers. Co-Authored-By: Claude Opus 5.5 <[email protected]> * test(enrichment): import the probe modules at collection time The fast-unit CPU guard charged utils.cloud_tasks' first import to the probe test's call phase (0.53s > 0.30s) once this file was selected. Module-level imports keep the assertions unchanged and the call phase cheap. Co-Authored-By: Claude Opus 5.5 <[email protected]> * fix(enrichment): own the sr- callback and absorb lifecycle fences (C2 slice 3) Plan C2, swarm lane 9. Batch enrichment no longer imports legacy transcription (utils/sync/pipeline.py): - utils/enrichment/callback.py: enrich_conversation, extracted verbatim from pipeline._reprocess_conversation_after_update with its webhook helper, persistence fence and lineage sentinel. pipeline.py is frozen behind #21932/#20662 and keeps its copy for the non-coalescing direct path, so test_enrichment_callback_parity.py (a static tripwire, labelled as such) keeps the two bodies identical until C11 deletes the legacy one. The new copy logs no conversation id. - utils/enrichment/custody.py now owns discard_blocked. The batch adapter re-exports it for its existing importers. - Absorbs #21968 (lead ruling 10-19): a SyncConversationPersistenceFenced from the callback settles the claim as superseded. The obligation is retired when no newer mark landed and re-armed when one did, and the handler ACKs 200 instead of answering 500 to a delivery that can never win. Other errors keep their taxonomy. #21968's conversation_id log line is not carried; the event is logged without identifiers. Failure-Class: none Verification (local unit, serial, nice 19): - test_enrichment_callback_fence 4 passed (fenced+unchanged -> retired; fenced+newer mark -> re-armed; ValueError propagates; the default callback is the package) - test_enrichment_callback_parity 3 passed - test_batch_pipeline_serving 31 passed - test_listen_finalization_cloud_tasks 278 passed - test_sync_reprocess_coalesce 88 passed - test_sync_enrichment_custody 10 passed - test_background_task_ratchet, test_llm_gateway_coverage_guardrails and test_generated_compute_inventory_guardrails passed - pyright 0 errors - test_sync_reprocess_emulator now patches the package callback (CI emulator lane) Co-Authored-By: Claude Opus 5.5 <[email protected]> * feat(enrichment): Firestore Outbox for OutboxKind.ENRICHMENT (C2 slice 2) Plan C2 / contract (b), swarm lane 9. database/outbox_firestore.py implements the Outbox protocol over sync_reprocess_outbox, row-compatible with mark/run: same collection, document ids, field names and sr- names. Additive fields: policy_id, claim_attempts, a transient summary_seen_by. - lease_token is the per-claim owner uuid and wake_token is task_token. heartbeat/ack/defer/release are fenced on both (invariant 1). - claim_key: privacy discard first (invariant 6), then demand admission, a stale or busy check, and a not-due re-arm that wakes itself and returns DEFERRED. Wake ownership follows the lead's 10-19 ruling: this implementation creates the tasks through the existing _enqueue. - ack keeps today's finish rules: retire when unchanged, a dormant receipt when record_summary marked the lease, re-arm when the version moved. - enqueue shares mark's CAS operation (mark_update), with explicit available_at and min/max coalescing (invariant 3). With tx= it writes in the caller's transaction and returns the wake token; the caller calls wake() after commit (invariants 4-5). wake() is idempotent per token. - sweep delegates to the existing sweep with a privacy discard hook. Pull claim() goes through the new utils.enrichment.outbox.due_rows (single-field due_at index), registered in the query-shape drivers. Batch projection's mark_enrichment now calls enqueue(tx=...) and then wake(), using its own client for both. A backfill binding is still resolved only for a new row (new_dispatch callable), so a coalesced append never raises on a missing backfill env, as before. database.outbox.outbox_for is lane 1's stub; firestore_outbox(kind) is the implementation it should return (wiring requested from the captain). Verification (local unit, serial, nice 19): - test_outbox_firestore 13 passed - test_batch_pipeline_projection 40 passed - test_sync_reprocess_coalesce 88 passed - test_firestore_query_shapes 481 passed - the outside-query, runtime-witness and index-oracle suites passed - test_listen_finalization_cloud_tasks 278 passed - pyright 0 errors The emulator conformance suite is lane 12's and has not landed yet. Co-Authored-By: Claude Opus 5.5 <[email protected]> * feat(enrichment): outbox_for selects the Firestore enrichment outbox Lane 1 signed off on this one-function edit of its stub (10-19): in this window the selector always returns the Firestore implementation; the BATCH_JOBSTORE_MODE switch is lane 12's. Co-Authored-By: Claude Opus 5.5 <[email protected]> * feat(enrichment): /v2/enrichment/run on the outbox consumer, 409-only retries (C3) Plan C3 / contracts (a) and (d), swarm lane 9. - utils/enrichment/consumer.py: EnrichmentConsumer, a QueueConsumer for OutboxKind.ENRICHMENT (workers role; 120s lease, 30s heartbeat on every lease). It mirrors reprocess.run outcome for outcome, with settlement through the Outbox calls: - processed -> DONE (ack; a dormant receipt via record_summary); - superseded or lifecycle fence -> DISCARDED; - repair race -> outbox.repair; - live target or missing conversation -> DEFERRED +120s; - redirect -> custody transfer; - empty budget spent -> retired; - callback pending or empty output -> RETRY callback_pending (409; release keeps the wake for the queue retry). - routers/enrichment.py: POST /v2/enrichment/run with OIDC for the enrichment queue (TaskEdge enrichment). It accepts the legacy {"kind":"sync_reprocess",...} payload, so rows bound to either handler drain. 400 for a malformed task; 500 only for unexpected exceptions. - config/enrichment.py: ENRICHMENT_ROUTE (sync_handler | enrichment_queue, default sync_handler) is the deployment default for the policy field enrichment_route until E1 records it per unit. ENRICHMENT_TASKS_* is the queue binding. An incomplete binding falls back to the sync handler and is counted through record_fallback. - valid_dispatch_binding and _enqueue accept both handler paths (contract (b) invariant 7). The router mount in main.py is lane 1's. Queue spec for lane 7: enrichment, max-concurrent 50, 25/s, backoff 10-300s, unlimited attempts. Verification (local unit, serial, nice 19): - test_enrichment_route 12 passed (409 callback_pending keeps the wake; fence -> superseded; live defer -> new wake; 400s; stale wake -> 200; unexpected -> 5xx with the lease kept; route binding with fallback) - test_outbox_firestore 14 passed - test_sync_reprocess_coalesce 88 passed - test_cross_service_deploy_contract and test_background_task_ratchet passed - pyright 0 errors Co-Authored-By: Claude Opus 5.5 <[email protected]> * fix(enrichment): match moved retry classes so callback-pending stays 409 #22371 classifies expected enrichment retries by (defining module, class name). #22431 moved FirstSummaryCallbackPending to utils.enrichment.outbox, so on integration a callback-pending delivery fell through to the unexpected branch and answered 500. That is the fast-5xx shape that throttled the queues on 10-18 and 10-19. Match the new defining modules, and keep the legacy pipeline fence until pipeline.py is deleted. Failure-Class: none Verification: test_batch_pipeline_serving 38 passed (it failed with 500 != 409 before this change on the merged integration tree). Co-Authored-By: Claude Opus 5.5 <[email protected]> * feat(enrichment): FirestoreOutbox factory with injected client, privacy check and wake For lane 12's outbox conformance suite (build_outbox_backend('emulator')): FirestoreOutbox(kind, client=, privacy_blocked=, create_wake=) binds every CAS, the sweep and every wake to the injected seams. The default instance keeps the production paths (discard_blocked, _enqueue, the shared client). outbox._cas is the client-explicit CAS behind _mutate, and sweep takes client=/wake= for the same purpose. A not-due claim_key deferral leaves claim_attempts untouched (attempt stays 1 on the first real claim), as reprocess does today; there is a test for it. Verification: test_outbox_firestore 16 passed, test_batch_pipeline_projection 40, test_sync_reprocess_coalesce 88, test_firestore_query_shapes 481, test_sync_enrichment_custody 10; pyright 0 errors. Co-Authored-By: Claude Opus 5.5 <[email protected]> * test(enrichment): a not-due wake re-arms and answers 200 not_due Exercises #22437's claim_key DEFERRED mapping end to end through /v2/enrichment/run: the outbox re-arms with a new wake and the delivery is consumed, not retried. Co-Authored-By: Claude Opus 5.5 <[email protected]> * test(enrichment): load the callback at collection time in the route tests The fast-unit CPU guard charged process_conversation's first import to the first route test (6.8s > 0.30s). Co-Authored-By: Claude Opus 5.5 <[email protected]> * fix(batch): recover-quarantine kill switch answers 409; legacy sr- delegates to the consumer Contract (d), swarm lane 9: - /v2/batch-pipeline/recover-quarantine returned 503 for "recovery disabled" (host or owner). Cloud Tasks system-throttles a queue that sees fast 5xx/503 (10-18 18:14Z, 10-19 04:52Z stalls). A switched-off target now answers 409 {"status":"retry","reason":"kill_switch_off"}. Behaviour is otherwise unchanged: the intent stays prepared, nothing is spent, and the queue retries. - enrichment_response (the legacy /v2/sync-jobs/run sync_reprocess delivery) runs through the C3 EnrichmentConsumer when ENRICHMENT_ROUTE=enrichment_queue, so one lever moves new rows onto the enrichment queue and drains old bindings through the same state machine. Default sync_handler keeps today's reprocess.run path. Failure-Class: none Verification (local unit, serial, nice 19): - test_batch_pipeline_quarantine_recovery 67 passed (the disabled-host, -cohort and -missing cases assert 409 kill_switch_off) - test_enrichment_route 14 passed (incl. legacy-handler delegation) - test_batch_pipeline_serving 39 passed - test_revision_drain_harness 7 passed - test_cross_service_deploy_contract 18 passed Co-Authored-By: Claude Opus 5.5 <[email protected]> * feat(enrichment): enrichment-maintenance scheduler + /v2/enrichment/sweep (C4) Plan C4, swarm lane 9. One maintenance owner for the enrichment outbox on the workers role: - POST /v2/enrichment/sweep (OIDC as /v2/enrichment/run) runs the outbox sweep (lost-wake repair, privacy discard), then summary_debt_repair.tick. It answers 200 with counts; a summary-debt failure is counted, never 5xx. - deploy/scheduler/jobs.yaml: enrichment-maintenance (*/2) against backend-integration, lifecycle: planned until the route serves there. Prod ENABLED; dev PAUSED (dev shares prod Firestore, as the sequencer). Both halves are safe beside the legacy sequencer sweep: the outbox sweep is per-row CAS and the summary-debt tick holds its own cursor lease. The sequencer sweep's reprocess.sweep and summary_debt_repair.tick calls (routers/sync.py:1958) are deleted by lane 10's slice. Summary-debt repair on backend-integration needs SUMMARY_DEBT_REPAIR_ENABLED in lane 7's ops file (today it is set on backend-sync only). Verification: test_enrichment_route 16 passed; test_scheduler_reconcile 24 passed (job sets plus lifecycle/state pinned). Co-Authored-By: Claude Opus 5.5 <[email protected]> * refactor(outbox): selector returns the Outbox protocol; one shared provider-STT instance Follow-up nits from lane 9's sign-off on #22467: FirestoreOutbox and firestore_outbox are annotated as returning the Outbox protocol, which drops the type-ignore (both implementations satisfy it under pyright), and the provider-STT branch caches one lazily built instance like enrichment's module singleton. Verification: pyright 0 errors; test_outbox_firestore 16, test_provider_stt_outbox 11, test_enrichment_route 16, test_batch_pipeline_projection 40, test_scheduler_reconcile 24 passed. Co-Authored-By: Claude Opus 5.5 <[email protected]> * chore(enrichment): route policy for /v2/enrichment/sweep Mirrors /v2/enrichment/run: service OIDC, internal task surface, no rate limit, sync_job timeout class, conversations data domain. Co-Authored-By: Claude Opus 5.5 <[email protected]> --------- Co-authored-by: Claude Opus 5.5 <[email protected]>
Bounds historical sync admission and each worker attempt before reducing the backfill worker memory limit from 8 GiB to 4 GiB. Explicitly pins concurrency 3: main now includes PR #20661 at concurrency 6/8 GiB, and the combined 6/4-GiB configuration is not qualified. New batch limits cover encoded/decoded/VAD bytes, frame count, duration and codec metadata; a 1-GiB tmpfs mount bounds retained retry files. Over-limit uploads return 413 before acknowledgement, and legacy worker limits/storage pressure return 503 preserving cloud audio and content claims. Production rollout follows observability acceptance and Luna review through the normal deploy path.
Full-range aggregate memory evidence includes an Oct 1 peak bucket upper bound of 1.76 GiB: 4 GiB leaves 2.24 GiB relative to that sample; 2 GiB would leave just 0.24 GiB (12%). Minute samples cannot prove absence of transient peaks, so 2 GiB is rejected.
Estimated gross active-memory saving: $195–291/month at Oct 2–3 billed time. Risk: legacy over-limit inputs require prompt operator recovery within the existing staging/task lifetime; filesystem pressure can increase retries. Rollback: restore the previous serving revision to remove the new input/storage policy; 8 GiB alone retains those guards. Do not combine with concurrency 6 until separately qualified.
Local synthetic concurrency-3 runs include immediate retries and retained cancelled-attempt files: 64-MiB file envelope 2.041 GiB, maximum-duration file 1.232 GiB, and 20-file batch 0.941 GiB. Former 200-MiB files reached 6.139 GiB. Full dev candidate/container acceptance remains required before promotion.
Validation and staged acceptance:
backend/docs/runbooks/sync-backfill-memory.md.Failure-Class: none
INV-MEM-4: resource bounds preserve content claims and defer over-limit legacy work rather than completing or invalidating it.
Line-Count-Exception: backend/routers/sync.py | 2498 -> 2533 | Enforce batch resource bounds and preserve raw audio and claims on capacity pressure.
Line-Count-Exception: backend/utils/sync/pipeline.py | 3021 -> 3052 | Enforce batch resource bounds and preserve raw audio and claims on capacity pressure.
Line-Count-Exception: backend/utils/other/storage.py | 1981 -> 2003 | Enforce batch resource bounds and preserve raw audio and claims on capacity pressure.