Repository navigation
perf(batch): dark per-row finish backoff for projection replay - #25122
Merged
Merged
Conversation
The projection finish page re-reads and re-fences every persisted/ready result on every serving tick whether or not anything changed. That replay is 287.0M reads/day across the projection callers (579 reads per completed projection, about 89x what a first projection needs). Add a durable per-row next-attempt clock (`projection_finish_due_at`, plus an escalation step), written only when `BATCH_PROJECTION_FINISH_BACKOFF_ENABLED` is on. A walk that changed nothing defers the row 60 s, then 300 s, then 900 s (capped); the page asks for states in (persisted, ready) and a clock that has passed. The pending assignment page is untouched, so new work is never delayed, and every projection_state write stamps the clock as due now in the same transaction, so no obligation waits on a stale one. The range filter must lead the ordering, so that page gets its own composite index (projection_state, projection_finish_due_at, committed_at, __name__) and a (due_at, committed_at, key) cursor. Rows written before the lever carry no clock, so the first pass after enablement is the unfiltered legacy page, which stamps them. OFF is the current query shape with no field writes. Rollback is one env flip, no backfill, and no projection output, job store or Postgres route changes. Also satisfies the strict Pyright boundary for the touched files (the cursor parameter is typed, the summary state is normalized for the field helper, and the new store/cursor locals carry annotations) and re-reviews the digest pin for `FirestoreStore.projection_page`: the adapter body changed only in that annotation, and the forwarded shape is still the recorded driver.
Stamp the finish clock on the blocked/error survey path, reset the survey on OFF->ON, keep the lever default-off in serve mode, stamp the ghost-hold repair, clear the clock on the privacy-replay pending write, and add a finish reads-per-completion guard. Tighten the test doubles to Firestore semantics and cover the filtered parity path.
The survey flipped `surveyed` as soon as the legacy page came back short, before those rows were stamped. A failed `defer_finish` was logged as a deferral error and the loop moved on; the row then carried no clock, and the filtered page cannot see a missing field, so that obligation vanished from finish discovery until restart. The survey now records that the short page was reached and closes only from `survey_done()` at the end of the sweep, which is skipped when any stamp raised. The next tick stays on the unfiltered legacy page and re-discovers the row.
A full survey page advances discovery past the row whose stamp failed, so clearing the failure after that page let a later short page close the survey behind an unstamped row; the clock-filtered page cannot see a row without a clock, so that obligation vanished until restart. The failure is now tracked per row for the whole survey, and a short page that ends the walk with an unstamped row restarts the unfiltered walk from the front so the row is discovered again.
Git-on-my-level
added a commit
that referenced
this pull request
Nov 21, 2026
…scrape (#25145) ## What Export the two projection finish guard counters on the backend-integration GMP scrape and the in-cluster Prometheus bridge. `OmiBatchProjectionFinishReadsPerCompletion` is the only movable guard on the projection finish-backoff lever (`BATCH_PROJECTION_FINISH_BACKOFF_ENABLED`, #25122): threshold 1200, baseline ~579 reads per completion. Its ratio needs both `omi_batch_projection_finish_reads_total` and `omi_batch_projection_finish_completed_total`. The projection sweep runs on backend-sync and backend-integration. The existing Cloud Run GMP keep rule already admits both counters. The missing sync exporter prefixes prevented the in-cluster Prometheus bridge from importing them. - `backend/deploy/cloud_run_gmp_sync.yaml`: document that the existing `__name__` keep regex covers both counters. - `backend/charts/monitoring/prometheus-stackdriver-exporter/{prod,dev}_sync_omi_cloud_run_metrics_exporter.yaml`: import both families. The checked-in guard is a `PrometheusRule`; the in-cluster Prometheus imports backend-integration through this bridge. Production has no live alert route for this guard, so qualification must prove the ratio is computable rather than claim active alerting. - `backend/tests/unit/test_projection_finish_guard_metrics_are_scraped.py`: derives the names from the producer registrations and pins them against both filters, the alert expression, the metric inventory, and the test selector. - `backend/charts/monitoring/batch-projection/README.md`: documents the export requirement. Scrape/config only: no flag flips, no deploy, no runtime change. `BATCH_PROJECTION_FINISH_BACKOFF_ENABLED` is untouched. ## Verification - `backend/.venv/bin/python -m pytest tests/unit/test_projection_finish_guard_metrics_are_scraped.py tests/unit/test_monitoring_telemetry_contract.py tests/unit/test_timeliness_metrics_are_scraped.py tests/unit/test_monitoring_alert_backtest.py tests/unit/test_monitoring_alert_rule_contract.py tests/unit/test_attach_cloud_run_gmp_sidecar.py` — all pass locally. - Deploy-lane readback (cl2-deploy, not this PR) must show both counters present in the backend-integration scrape with non-null values and the alert baseline computable. ## Main integration validation Current head: `2a952b746a9b04f1b445b578523cf7f8e2141688`, integrated with main at `d9be505b41a79ca7d7e2d3ab0d4558f0f5bd4278`. - The merge kept main's HPA contract test refactor from `2c0451b5b5146ca4adf4d8b7cf30388dbe41c4c5` for the sole conflict. The other eight files preserve the reviewed additions and deletions. - All 124 targeted tests and the bounded repository pre-push gate passed on M1. The shallow checkout deferred the 90-day failure-class history check. - Guarded admission requires Luna's carry-forward check and passing required CI at this head. The rollout lead conditionally authorized the three monitoring Helm upgrades. Release owns the three rollback revisions, live diffs at merged main, and dispatch window clear of production Prometheus guards. SCA-1799 remains open pending serving and counter readback. ### Prior integration receipts Earlier integration commit: `6fab6d70c8e050e02d8b232508f2254fbfbc7408`, integrated with main at `ce9e045e2f2fc5c99944aa1ab98d20ed249a252e`. - **R28 release handoff.** The overnight manager's decision on SCA-1799 (comment `01a1fa1e-1489-76e9-9073-03da580d956d`, delegation `event:ev-838b55485a1d03458a8c`) closed the two review rounds and directed the refreshed head to Release. Luna's SHIP at `6d1d73d68fdda8a3f6a5e4e475a72f27f53d27be` is the review of record. SCA-3420 tracks the remaining test-maintenance findings. - **Verification at the refreshed head.** The repository pre-push gate and 124 targeted tests passed (8 projection finish, 59 HPA, 57 telemetry). Required GitHub CI passed, including the [backend unit suite](https://github.com/BasedHardware/omi/actions/runs/44790145809/job/136483452651) and [Mobile Release Eligibility](https://github.com/BasedHardware/omi/actions/runs/44790145076/job/136475913213). Release reported [no connector findings](#25145 (comment)) and a clear release hold reader for SCA-3425. - **Prior release gates.** Release owns guarded merge admission. The R28 production handoff covers the sync exporter. Production rollout remains gated on confirmation of the monitoring workflow's scope or a reviewed sync-only route. SCA-1799 remains open pending production serving and counter readback. Earlier integration commit: `6655885a68d94237420beb1af8e34c78e0584820`, based on clean main integration `58994ac2d5aa880272a8d1669b7b983cc93fbdd5`. It retains the merged #25473 Stripe initialization repair and the finish-counter contract / exact AST selection. Owner disposition `01a1e538-98fb-7846-a271-76f374358b8b` authorizes the isolated HPA test correction: each owned source now has an independent selection assertion; a module-scoped fixture supplies the complete real discovered inventory. No production selector/runner, marker, guard, allowlist, assertion or Helm contract was changed. - **M1 equivalence proof passed:** baseline enumeration and owned assignments are AST-identical; the same ordered, multiplicity-preserving 21 owned paths come from the full 27-source enumeration. Actual parameter collection matches. The module-scoped fixture invokes real discovery once and returns its exact full object, equal to independent discovery: 2,923 paths. Other contract functions and the selection assertion are AST-identical. - **M1 validation at `c710ead1d1924917d4870cc71068753eed56364c`: exit 0; 470 passed across nine files, zero failures/skips or CPU-guard warnings/failures.** Python 3.11.15, Helm v4.2.3; full HPA file 59 passed, including all 21 independent selector cases and every Helm render. The prior eight-file affected set also passes with file isolation and unchanged 1.00s CPU limit. - Command: `BACKEND_UNIT_TEST_FILE_LIST="$PWD/selected-tests-c710ead1.txt" omi-workspace/bin/omi-heavy run --timeout 600 -- bash omi/backend/test.sh`. - [Full guarded worker log](https://multica-01.tail76ea03.ts.net/api/attachments/01a1e53c-185e-7b51-830e-98173b672138/download) and [source/inventory proof](https://multica-01.tail76ea03.ts.net/api/attachments/01a1e53c-1856-729a-b5b2-bc2329750edb/download), issue receipt `01a1e53c-1867-7d41-b9d6-768178a495be`. - Diff hygiene and lightweight AST equivalence checks passed on control; no backend suites/builds/type checkers ran there. - Completed [backend CI at `c710ead1`](https://github.com/BasedHardware/omi/actions/runs/43909722101): shard 2/8 passes; shard 5/8 and aggregate fail on unrelated `tests/unit/test_mcp_conversation_detail_paging.py::test_walk_1200_segments_once_with_one_existing_read_per_page` (1.12s CPU > unchanged 1.00s limit). Stopped at this different blocker; no paging-test repair or blind rerun. - Repo Checks also rejected formatting in the HPA helper. `6655885a` applies the repository's pinned formatter only (complete Python AST identical to worker-tested `c710ead1`); formatter check and diff hygiene pass. No worker rerun is claimed for this formatting-only head. Its [backend CI run](https://github.com/BasedHardware/omi/actions/runs/43912099995) was pending when that receipt was recorded. - **Prior release disposition.** At that head, the owner/22:00Z qualification hold was still in place. Exact-head CI, Release qualification and the original cl2-deploy production scrape readback were still required. - That validation round stopped before merge and deploy. Its test-correction inverse was to revert the isolated HPA change. $0 booked. ## Rollback Revert the PR. Allowlist-only change; no runtime behavior. Failure-Class: FC-metric-dropped-by-scrape-allowlist Tracks SCA-1799. Closure requires production readback. <!-- This is an auto-generated description by cubic. --> <a href="https://cubic.dev/pr/BasedHardware/omi/pull/25145?utm_source=github" target="_blank" rel="noopener noreferrer" data-no-image-dialog="true"><picture><source media="(prefers-color-scheme: dark)" srcset="https://www.cubic.dev/buttons/review-in-cubic-dark.svg"><source media="(prefers-color-scheme: light)" srcset="https://www.cubic.dev/buttons/review-in-cubic-light.svg"><img alt="View guided diff" src="https://www.cubic.dev/buttons/review-in-cubic-light.svg"></picture></a> <!-- End of auto-generated description by cubic. -->
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Dark: cut projection replay reads with a per-row finish backoff (A-1)
Requested by lead2 (job-state polling vs event dequeue,
648669): the 23–26% no-move cut as one dark PR,kill switch through the normal path. Source packet:
data/run-2026-11-08-pipeline-refactor/findings-jobstate-vs-dequeue-20261111.md.What changed and why
The projection finish page re-reads and re-fences every
persisted/readyresult on every serving tickwhether or not anything changed. That replay is most of the projection family: 287.0M reads/day for 495,593
completed projections = 579 reads per completion, about 89× what a first projection needs (findings §3.2).
95–99% of it is replay of already-projected work.
This adds a durable per-row next-attempt clock, so a walk that changed nothing is not re-read every tick:
projection_finish_due_at(epoch seconds) andprojection_finish_backoff_step.projection_state in (persisted, ready)andprojection_finish_due_at <= now.it re-reads the row and refuses if
projection_statemoved.projection_statewrite stamps the clock as due now in the same transaction (session receipts andpart summaries, quarantine hold/restore, release, sibling wake, completion). A state move is therefore never
deferred, and no obligation waits on a stale clock.
pendingassignment page is untouched, so new work is never delayed.this page gets its own composite index
(projection_state, projection_finish_due_at, committed_at, __name__)and a
(due_at, committed_at, key)cursor. The legacy page, its cursor and its index are unchanged.after enablement is therefore the unfiltered legacy page, which stamps those rows; only then does the page
filter. Each process does that one survey pass (today's read cost) and then saves.
Read path only: no projection output, routing, UI, credential/IAM or workflow change. Alternate job-store backends mirror the Firestore projection-page contract.
Line-Count-Exception: backend/utils/batch_pipeline/projection.py | 1722 -> 1751 | every new decision
(page selection, the one survey pass, defer-or-skip, and closing the survey only after its page is durably
stamped) lives in
backend/utils/batch_pipeline/projection_finish_backoff.py; the frozen file gains thesurvey/deferral call, the blocked/error stamp in a
finally, the one post-loop survey close, and the finishreads/completion counters so the sweep's error/count/logging path is untouched.
Kill switch, default, rollback
BATCH_PROJECTION_FINISH_BACKOFF_ENABLED, default OFF (KILL_SWITCHES→False, read throughconfig.policy.kill_switch; registry rowconfig/feature-flags.yamllifecyclerollout,fail: closed,owner
firestore-lead).ORDER BY committed_at, __name__, same cursor), no field iswritten, and the sweep makes the legacy
next(limit=size)call unchanged.false/0. The fields are additive and unread when off, and the next tick isthe legacy page. No backfill, no data migration, no index removal.
Scope items not in this PR (named follow-ups)
leader-elected (
batch_metrics_oldest_leaderdefaults to 100); the remaining 20.9M+4.1M reads/day onoldest/oldest_retryare the up-to-500-doc policy-hold walk, i.e. a gauge cache/aggregate, not election.lifecycle_record_pending_headlever on for the emitters — not config-only in this repo's sense: thelever is already at 5% on backend services, and the emitters that miss it are the GKE worker fleet, whose
FIRESTORE_READ_LEVERScomes from the deployment overlays. Turning it on changes production behaviour atdeploy instead of staying dark, and its correctness proof was not read (findings §6.8). It should ride its own
PR with its own percentage ramp.
Metric
Primary: reads per completed projection =
sum(increase(omi_firestore_billed_reads_by_caller_total{caller=~"database.batch_pipeline_projection.*|database.batch_pipeline_store:projection_page"}[24h]))÷
sum(increase(omi_batch_pipeline_correctness_transitions_total{event="projection_completed"}[24h])).Today 579; target after A-1 116–261. Expected saving 55–80% of the 287.0M/day pool = 158–230M
reads/day ≈ $85–124/day at the $0.54/M marginal read price.
Guards (all must stay flat):
omi_batch_timeliness_new_over_sla_units{leg="projection"}(395,407 today, mustnot rise),
omi_batch_projection_obligation_oldest_age_seconds(2,068,400 s, must not rise),projection_completedwithin ±2%, summary-debt legs unchanged,omi_firestore_caller_label_overflow_totalflat.
Parity evidence (identical output)
backend/tests/unit/test_batch_projection_finish_backoff.py::test_same_output_with_the_flag_on_and_offruns thesame result log through the real sweep twice, flag off and flag on, and asserts identical sweep counts and an
identical walk order on the second tick, after the survey, so the flag-on run exercises the clock-filtered
page rather than only the unfiltered first pass. Other tests in that file prove:
due_beforeabsent), no field is written, no deferral call;ready, quarantine hold) and retired otherwise, and thesame write is unchanged when the lever is off;
pendingrow;The Firestore query-shape guard re-recorded
projection_pagewith the newdue_beforeparameter and confirmsevery serving shape is covered by the checked-in manifest (
test_firestore_query_shapes: 572 passed). TheFirestoreStore.projection_pagedigest pin was re-reviewed for the typed cursor parameter and the newdue_beforeargument: the adapter gained that parameter and forwards it unchanged, no query/read/bound changed,and the forwarded shape is still the recorded driver.
Tests
Original qualification, before the CI correction below, with GCP credentials unset (
env -u GOOGLE_APPLICATION_CREDENTIALS -u SERVICE_ACCOUNT_JSON), throughbin/omi-heavy run --, baseorigin/main72d5dfdc671a, earlier head21a9ba6357bb1b2021ea46c533353cb52303335b. The fix-batch rerun ata9c89fac5105is in the section below.test_batch_pipeline_sweep_owner_chain,test_batch_pipeline_serving_config,test_batch_pipeline_owner_chain_projection,test_batch_pipeline_owner_drain,test_batch_pipeline_followup_reads,test_batch_pipeline_projection,test_batch_pipeline_quarantine,test_batch_pipeline_quarantine_recovery,test_batch_projection_privacy_hold,test_batch_pipeline_projection_release,test_batch_projection_finish_backoff,test_firestore_query_shapes,test_flag_budget,test_batch_unit_policy,test_reconcile_firestore_indexestest_batch_pipeline_scheduler,test_batch_pipeline_metrics,test_batch_pipeline_serving,test_batch_pipeline_timeliness,test_batch_timeliness_all_time,test_lifecycle_alarm_metrics,test_config_refactor_w6,test_runtime_env_sources,test_batch_held_contract,test_vad_cache_ttl_config,test_omi_flagstest_batch_projection_finish_backoffscripts/backend-python-format --check)backend/scripts/typecheck.sh)git push, runs the pre-push hook:scripts/pr-preflight --lane local, typecheck and the changed-file suite)Product invariants affected
none — read-path only, kill switch OFF by default.
UI evidence
UI-Evidence: none -- backend read-path only
Failure class
Failure-Class: none
This is a dark read-path lever with a kill switch, not a fix for a failing behaviour: the defect it removes
(per-tick replay of already-projected rows) is cost, not correctness, and the default-OFF path is byte-identical.
Rollback: one env flip (
BATCH_PROJECTION_FINISH_BACKOFF_ENABLED=false). No backfill, no data change, no indexremoval; the next tick is the current page.
CI correction (2026-11-11)
Earlier head:
600b44baeb044221d555a96686d82f1421a363b4(parent21a9ba6357bb1b2021ea46c533353cb52303335b).ProjectionSession.persistlifecycle inventory with the actual summary-state payload introduced alongside the finish clock. Keep the lifecycle guard unchanged.FirestoreStore.projection_pagein PostgresStore, SimStore and PgSimStore: the typed cursor,due_before, states/defaults, due-clock ordering, inclusive seed cursors, stable continuation cursors and 200-row bound. PgSim forwards the whole contract. No protocol exclusion.Fresh local validation used the worktree's own Python 3.11 environment, stripped inherited GCP/GOOGLE/GCLOUD/CLOUDSDK/FIREBASE credentials, private HOME/config/cache/temp and disabled metadata discovery, through
bin/omi-heavy run --. All source changes are confined to these two fixes and their tests.backend/scripts/typecheck.shThe requested original
/Volumes/Ephemeral/...checkout was absent on this host. The same branch was recreated from the exact published head under/Volumes/scratch/worktrees/omi/omi-lane-jobstate-cut-upstream-keep-clean; no rebase or merge was performed. Local checks establish static/synthetic behavior; remote CI and deployed behavior remain separate. Stop after this correction for delta-only review; no merge or deploy.Fix batch (2026-11-12)
Earlier head:
a9c89fac5105321db955e6f0f600c2a972ae2fb4(parent600b44baeb044221d555a96686d82f1421a363b4).One push, no merge, no deploy. Non-test diff: 97 lines (under the 150-line cap).
Finding-by-finding resolution from the three pre-reviews:
_sweep_finishnow callssettledfrom afinallyfor every walked row, includingProjectionBlocked/BatchPrivacyBlockedand generic errors. A failed row read passesstate=None;defer_finishthen stamps only a row still inpersisted/ready, so a completed or pending row is untouched. A deferral failure is logged asoutcome=defer_errorand does not break the sweep. TheResultLogdouble now excludes a missing clock from a range filter, matching Firestore. New test:test_a_blocked_survey_row_is_stamped_so_the_filtered_page_can_see_it.readywithout the clockreconcile_batch_projection_ghost_holds.pynow writesprojection_finish_state_fields('ready', time.time())in the same CAS update. New test:test_apply_stamps_the_finish_clock_when_the_lever_is_on.BATCH_PROJECTION_FINISH_BACKOFF_ENABLEDadded to thedefault_onexclusion set. New test:test_default_off_switches_stay_off_in_serve_modecovers every default-off switch underCAPTURE_COVERAGE_MODE=serve.surveyednever resets, so OFF→ON strands rows written while offFinishBackoff.pageclearssurveyedon every lever-off tick, so the next enable surveys again. New test:test_reenable_after_rollback_surveys_rows_written_while_off.omi_batch_projection_finish_reads_totalandomi_batch_projection_finish_completed_total, incremented in_sweep_finish, and aOmiBatchProjectionFinishReadsPerCompletionPrometheusRule (ratio > 1200 for 15m; baseline ~579). The oldest-age/over-SLA guards are documented as saturated and unable to see a sub-900 s delay inbatch-pipeline-serving.mdand the rule annotation.session.pywritespendingwithout clearing the clockpendingwrite now includesprojection_finish_state_fields('pending', now), which deletes both fields when the lever is on.acknowledgecompletion and asserts both fields arefirestore.DELETE_FIELDin the transaction patch.due_beforeand forwards it unchanged.due_beforecoverage in the discovery testtest_due_before_mode_resets_the_cursor_and_seeds_on_the_clockexercises the realProjectionDiscoverymode switch, clock seed and legacy-cursor reset.Fresh local validation at
a9c89fac5105, GCP credentials unset, throughbin/omi-heavy run --:test_firestore_query_shapes+test_firestore_outside_query_contract)test_batch_projection_finish_backoff,test_batch_pipeline_owner_chain_projection,test_batch_pipeline_sweep_owner_chain,test_batch_pipeline_quarantine,test_jobstore_protocol_parity,test_lifecycle_state_table_writers)backend/scripts/typecheck.shMerge-main (2026-11-12)
Earlier head:
aaa3cc23a96ef9144d2cde54445aeec0b42a3401(merge oforigin/main245f8174b1793ecfc1c121d1c66f7375df9b3909intoa9c89fac5105321db955e6f0f600c2a972ae2fb4).Branch:
lane/jobstate-cut.Merge-main resolution under lead2
1c606e: one content conflict inbackend/testing/pipeline_sim/postgres_store.py, where both sides added imports. Both are kept — this PR'sPROJECTION_DISCOVERY_STATESand main'ssqlhelper — and the rest of the file auto-merged. No change to the reviewed behavior: the patch againstorigin/mainis unchanged at 33 files, +1114 / -70, and no.github/workflow, UI, credential/IAM, prod data/config or model-name change is included.Fresh local validation at
aaa3cc23a96ef, GCP credentials unset, throughbin/omi-heavy run --:test_firestore_query_shapes+test_firestore_outside_query_contract)test_batch_projection_finish_backoff,test_batch_pipeline_owner_chain_projection,test_batch_pipeline_sweep_owner_chain,test_batch_pipeline_quarantine,test_jobstore_protocol_parity,test_lifecycle_state_table_writers)backend/scripts/typecheck.shStop after this merge-main for delta-only review; no merge, no deploy.
Fix 3 (2026-11-12)
Earlier head:
948505243f61eb4598893aac807a826d43d51fc0(parentaaa3cc23a96ef9144d2cde54445aeec0b42a3401).Branch:
lane/jobstate-cut. One push, no merge, no deploy. Non-test diff: 27 added / 3 removed lines.Delta finding from Luna
a25211(1111-29a26e-review.md):projection_finish_backoff.py:34marked the surveycomplete on a short page before those rows were processed. If stamping a legacy row failed,
_sweep_finishloggedthe deferral error and continued; the row then carried no
projection_finish_due_at, and Firestore omits rowswhere a ranged field is missing, so that obligation could vanish from finish discovery until restart.
Resolution: the survey no longer closes inside
page(). A short survey page only records that the legacy walkended (
survey_short); the sweep closes the survey fromsurvey_done()after the page's rows are processed, andsettled()marksstamp_failedwhendefer_finishraises before re-raising to the existingdefer_errorlog.A failed stamp therefore leaves the survey open, the next tick stays on the unfiltered legacy page, and the row is
re-discovered. The lever-off path clears both flags exactly as it already cleared
surveyed.New test:
test_a_stamp_failure_keeps_the_survey_open_for_the_next_tick— one row's stamp raises, the surveystays open, that row carries no clock, and the next tick's unfiltered page walks and stamps it.
Fresh local validation at
948505243f61, GCP credentials unset, throughbin/omi-heavy run --:test_firestore_query_shapes+test_firestore_outside_query_contract)test_batch_projection_finish_backoff,test_batch_pipeline_owner_chain_projection,test_batch_pipeline_sweep_owner_chain,test_batch_pipeline_quarantine,test_jobstore_protocol_parity,test_lifecycle_state_table_writers)backend/scripts/typecheck.shNormal full pre-push (the
pre-pushhook run against the same head, GCP credentials unset): 46 shared checkspassed, backend typecheck 0 errors, pinned formatter clean, and the selected changed-file unit suite green
(17 + 21 + 73 + 15 + 39 + 37 + 190 passed). CI remains the full test authority.
Stop after this fix for delta-only review; no merge, no deploy.
Fix 4 (2026-11-12)
Head:
fe48e389dcbb828d7560b512cc19f8e40bca3e43(parent948505243f61eb4598893aac807a826d43d51fc0).Branch:
lane/jobstate-cut. One push, no merge, no deploy. Non-test diff: 20 added / 9 removed lines.Delta finding from Luna
0e012d(1111-f7eb48-review.md):projection_finish_backoff.py:46-51read the stampfailure only for the page that reported it and cleared it after every page. A failure on a full survey page
had already advanced discovery past that row, so a later short page closed the survey and the clock-filtered page
then could not see the still-unstamped row (Firestore omits a row whose ranged field is missing) until restart.
Resolution: the failure is now tracked per row (
unstamped) for the whole survey instead of a per-page flag, anda short page that ends the walk with an unstamped row does not close the survey: it restarts the unfiltered walk
from the front (
finish_discovery.after = None,seeded = False) so the row is rediscovered and stamped. A rowthat is re-stamped, or that moves on before its stamp, leaves the set. The lever-off path clears the set exactly
as it already cleared
surveyed.New test:
test_a_stamp_failure_on_a_full_page_restarts_the_whole_survey— pagination on, three rows, page sizetwo, one row's stamp raises on the first page. The short page that follows is asserted not to close the
survey, and the next tick is asserted to walk that row again and stamp it. The test fails on
948505243f61andpasses here.
Fresh local validation at
fe48e389dcb, GCP credentials unset, throughbin/omi-heavy run --:test_batch_projection_finish_backoff,test_batch_pipeline_owner_chain_projection,test_batch_pipeline_sweep_owner_chain,test_batch_pipeline_quarantine,test_jobstore_protocol_parity,test_lifecycle_state_table_writers)test_batch_projection_finish_backoff)backend/scripts/typecheck.shscripts/backend-python-format --check)CI remains the full test authority. Stop after this fix for delta-only review; no merge, no deploy.