Repository navigation
fix(batch): hold the provider backlog; owner wakes commit fresh provider rows only - #25204
Merged
Merged
Conversation
…der rows only Co-Authored-By: Claude Fable 5.2 <[email protected]>
…llowed values Co-Authored-By: Claude Fable 5.2 <[email protected]>
Co-Authored-By: Claude Fable 5.2 <[email protected]>
…ixes - hold applies whatever the membership switch says (rows it stamped kept committing through the head wait after it was turned off) - fresh probe behind an unready provider backlog head at depth 0 - bounded fallback when the fresh query is unavailable - no depth marker for a held backlog head at the cap - flag budget count and helper-switch list Failure-Class: new Co-Authored-By: Claude Fable 5.2 <[email protected]>
…ready held head Round-2 review: a recovered non-fresh provider row passed the hold through the recovery wake, and an unready held provider head at the depth cap still wrote a depth marker. Failure-Class: new Co-Authored-By: Claude Fable 5.2 <[email protected]>
A probe made only for the backlog hold no longer switches the depth hold off for the whole merge instance when the fresh query is unavailable. Failure-Class: new Co-Authored-By: Claude Fable 5.2 <[email protected]>
Git-on-my-level
added a commit
that referenced
this pull request
Nov 13, 2026
…owners yield (#25213) ## What Two changes so a fresh result is projected promptly while a projection backlog drains: 1. Discovery: each assignment discovery tick also reads up to half a page from the newest 120 seconds of commits, so a new result is usually seen within its first two minutes however long the backlog (an estimate, below; not a per-row guarantee). 2. Owner drain: newly requested owners get a turn before backlog owners. ## Why On 2026-11-13 about 250,000 old results were committed in three hours (the provider backlog release, stopped by #25204). Projection drains owners from one FIFO queue, 8 at a time per process, and a turn runs up to 120 seconds. Measured in production (result metadata and log counts only): - Sample of 20,000 pending results at 15:34Z: 74% captured over a day earlier; 651 owners; the top 100 hold 82%. - Of results committed 10–20 minutes earlier, 56% were unprojected (about 0.2% before the incident); 26% of those committed 60–70 minutes earlier. - Half of the waiting under-1h rows (1,290 of 2,587) belong to 198 owners with no older rows of their own. They wait only for other owners' turns. - Projection is about 1,000 rows a minute against about 575 a minute of normal inflow at that hour, so the backlog needs hours to drain. Fresh results should not be late for all of it. - Discovery pages pending results oldest first, 100 rows per 20-second tick per process, and a GPU-route commit has no other wake (the worker pump has no commit callback). With 154,000 pending rows, 35 processes pass a given row about once in 15 minutes. That matches the measured delay. - Owner-drain turn lines, 5-minute sample at about 15:45Z: turns that ran to the 120-second deadline were 51 of 1,140 turns but 58% of slot time, and advanced about 0.43 rows a second each. ## Change **Discovery** (`backend/utils/batch_pipeline/projection_discovery.py`, assignment discovery only). Each tick also reads up to half a page from the newest `BATCH_PIPELINE_PROJECTION_RECENT_DISCOVERY_SECONDS` (default 120) of commits. - No cursor (the offer memory below is the only state): the read starts at a random point in the window each tick and reads oldest first. Replicas draw their start points independently, so they can land on different rows (nothing forces them to); a restarted process behaves like any other. - A process offers a row from this read once. The entry is kept for two windows, longer than the row stays in the window. A row still pending after that is offered by the main cursor, as before. - Rows read here count against the page, so the page holds no more rows; the main cursor gets the rest (at least half). The tick makes one more Firestore query than before (two instead of one for the pending page). - A main cursor that has not reached the newest row for 30 minutes (`MAIN_PASS_SECONDS`) starts again: one time in eight at the oldest pending row, otherwise at a uniform random point between it and now. This closes a gap review found: when rows arrive as fast as a cursor reads, no cursor wraps, and rows before every process's start point are never paged. The gap exists on `main` too, at twice the arrival rate. - Same query and index as the main cursor, with a start point. A failed recent query costs only that half page; rows read before a failed main query are not recorded as offered, so they stay eligible for a later recent read (which starts at a new random point and may not reach them on the next tick). Expected coverage, from the numbers above and not measured: with about 170–330 rows committed per 20-second tick and 35 processes each reading 50 from a random point of a window holding six ticks of rows, one tick misses a given new row with probability about e^(-35×50/(6×rows per tick)), 18–41% today. Over the six ticks a row spends in the window that is about e^(-35×50/rows per tick), under 1% today and about 7% at twice today's commit rate. It assumes uniform arrivals and independent draws. **Owner drain** (`backend/utils/batch_pipeline/projection_drain.py`). Per process; no new read, no new stored state, no index. - A newly requested owner's first turn runs `BATCH_PIPELINE_OWNER_DRAIN_FIRST_TURN_SECONDS` (default 15, about one step) instead of 120. - An owner whose productive turn ends with rows left is a backlog owner. It keeps 120-second turns but waits in its own queue; newly requested owners launch first. - A backlog turn ends at its next step boundary (`stop=yield`) when a newly requested owner is waiting and no slot is free: one backlog turn per waiting owner, and never the last backlog turn running. - If no backlog owner is running, one goes ahead after four rounds of new owners, so the backlog cannot be starved. Unchanged: order inside one owner (commit order under the assignment fence and the owner claim), discovery, claim-aware admission, privacy and live-target backoff. An owner's fresh row behind that same owner's backlog still waits for it. Details: `backend/docs/listen_pusher_pipeline/changes/2026-11-13-projection-fresh-owner-turns.md`. ## Rollout Ships on. Both are scheduling changes inside one process, each with an off value: `BATCH_PIPELINE_OWNER_DRAIN_FIRST_TURN_SECONDS=0` restores the single FIFO queue and 120-second turns; `BATCH_PIPELINE_PROJECTION_RECENT_DISCOVERY_SECONDS=0` restores the single discovery cursor and removes the 30-minute restart. Deploy: `backend-integration` only (the surface that runs the projection owner drain). Must stay clean after deploy: projected rows per minute not lower than before (the backlog keeps draining); enrichment 200s per minute flat. Expected to improve: share of under-1h captures committed 10–20 minutes earlier that are unprojected. ## Known limits - The main cursor advances at as little as half its speed while recent rows fill their half of the page, so a backlog row that depends on discovery alone (not on its owner's running drain) is found later. Owners already draining are not affected. The 30-minute restart is random: one restart in eight begins at the oldest row, the others at a uniform point, so every stretch of the log has a chance of being read in each period. That is not a guarantee for any single row, and how long a row can wait has not been measured. - A row is offered by the recent read once per process run, so up to 35 times fleet-wide when fewer than 50 rows are pending in the window, plus once for each process that restarts while the row is in the window. The bound assumes the commit stamp is no more than one window ahead of the process clock (entries are kept for two windows). Offers per tick stay within the page size, as before; each offer reads the row's job and result, and repeated owners are coalesced per process and by the owner claim across processes. - It does not help an owner whose fresh row sits behind that owner's own backlog (about half of the waiting fresh rows today). - A long chain's read-ahead is per turn, so a backlog turn that yields early discards it; under constant arrival of new owners, backlog turns get shorter and the backlog drains somewhat slower. - Classification is per process and resets on restart: after a deploy every backlog owner takes one 15-second first turn before it is known as backlog. ## Tuning disclosure - BATCH_PIPELINE_OWNER_DRAIN_FIRST_TURN_SECONDS new: 15 (0 = off, max 120) - BACKLOG_OWED_TURNS new: 4 - BATCH_PIPELINE_PROJECTION_RECENT_DISCOVERY_SECONDS new: 120 (0 = off, max 3600) - MAIN_PASS_SECONDS new: 1800 - MAIN_RESTART_HEAD_SHARE new: 0.125 - offer memory new: two windows (240 s at the default) No new pipeline state and nothing new stored. New process memory only: in the owner drain, the backlog queue and two sets of owner ids; in discovery, the ids and offer times of rows the recent read offered (about 150 a minute at most; an entry stops suppressing after two windows and is removed when the map next passes 4,096 entries, so older entries can sit in memory until then) and the time the main pass began. ## Product invariants affected none ## Failure class (fixes) Failure-Class: FC-backlog-release-shares-lane-with-fresh-work Second fix in this class: the first (#25204) stopped the unmetered release; this one gives fresh work its own place in the projection stage the release filled. ## Tests ``` cd backend .venv/bin/python -m pytest tests/unit/test_batch_pipeline_projection_discovery.py tests/unit/test_batch_pipeline_owner_drain.py \ tests/unit/test_batch_pipeline_sweep_owner_chain.py tests/unit/test_pipeline_sim_projection_drain.py tests/unit/test_flag_budget.py -q ``` New in `tests/unit/test_batch_pipeline_owner_drain.py`: a light owner queued behind three heavy owners finishes before any heavy owner gets a second turn, and every chain still projects whole and in order; new owners launch before queued backlog owners and the backlog is still owed a turn; a backlog turn yields only for a waiting new owner without a free slot, one per waiting owner, never the last one; the off value; the setting's bounds. The existing FIFO fairness test now pins the off value. New in `tests/unit/test_batch_pipeline_projection_discovery.py`: a new commit is on the first page behind a 400-row backlog and the page is no larger; the main cursor visits every backlog row while a full half page of new commits arrives on every tick; a row that stays pending is offered by the recent read once in 20 minutes of ticks, and once more by a restarted process; rows already offered still count against the page (query limits 50 and 50); each tick reads from a different point; the off value keeps one cursor and no restart; a failed recent query costs only its half; rows read before a failed main query are not recorded as offered and are offered again when a later read reaches them (shown with a fixed start point, striping on and off); a main cursor that has not wrapped for 30 minutes restarts and one that wraps does not; one restart in eight begins at the oldest row; setting bounds. `tests/unit/test_batch_pipeline_sweep_owner_chain.py::test_pending_page_skips_receipts_and_follow_ups_still_run` pinned one query for the pending page; it now pins two, with limits 50 and 100. That test was already failing on the first pushed heads of this branch and neither the pre-push gate nor CI ran it. ## Review Independent review (Luna). Round 1 on `cc4a583`: FIX, one should-fix (a failed main query moved the recent cursor); the owner drain passed checks A to G. Round 2 on `1a06b86`, against the contract (SCA-1960): FIX. Blocker: with half a page, the main cursor may never wrap under sustained arrivals, so rows before every process's start point could go unread. Should-fix: a still-pending recent row could be re-offered up to 45 times per process per window. Note: one more query per tick. I also found that the round-2 design would have left every process's recent cursor at the window floor under today's load. The recent read was rewritten (no cursor, one offer per row per process run) and the 30-minute restart added. Round 3 on `4d722a7`: FIX. It confirmed the restart's gating, the page and query counts, the off value, the failed-query paths and unchanged order inside an owner. Blocker: a uniformly random restart point almost never lands on the head of the log, so the oldest rows could still go unread under unending arrivals. Should-fix: the once-per-process bound assumed aligned clocks and no restarts; several statements in this description were stale or too strong. Response: one restart in eight now begins at the oldest row; offer entries are kept for two windows; the description is corrected. The rollout owner ruled the 1-in-8 head restart acceptable as probabilistic coverage (SCA-1960); a cursor that guarantees every row is read is assigned to the metered-release PR. Narrow confirmation on `b30e6be`: the code matches the ruling (head restart, gating, two-window offer memory in filter and prune, nothing recorded on a failed main query), tests prove their names, no security, privacy, custody or data-loss risk. Its verdict was FIX for two sentences in this description: the retry after a failed main query was stated as next-tick, and the memory statement ignored that pruning only runs above 4,096 entries. Both are corrected above; no code change followed, so the head is unchanged. A description-only pass on the same head confirmed both and asked for one more wording change (replicas can, not do, land on different rows), made above. The reviewer proposed always restarting at the oldest row; that was not taken because every process would then re-read the same first rows each period and nothing past them. Not tested here: production behaviour, the coverage estimate above, and the effect on the backlog's drain rate. 🤖 Generated with [Claude Code](https://claude.com/claude-code)
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.
What
Follow-up to #25187. While a new switch is off (the default), the ordered merge does not commit provider-route catch-up rows. An owner's fresh provider rows still commit, ahead of that held backlog, whenever the fresh-row query is available (see the known limits for when it is not).
Why
#25187 reached
backend-integrationon 2026-11-13 at 11:36Z. Measured in production (job and result metadata, request logs):result_ready(170,000 at catch-up depth 4, 125,000 at depth 1).backend-integrationwas at its instance ceiling, and completed enrichment and provider-STT requests fell by about half until the ceiling was raised from 35 to 70.So the fault is the unmetered release of the backlog, not provider merge membership. This PR removes the release from the owner wake and leaves delivery of fresh units in place.
Change
BATCH_PIPELINE_PROVIDER_BACKLOG_RELEASE_ENABLED, off unlesstrue. While off, inutils/batch_pipeline/merge.py:fresh_captureabsent, or false) is not committed. It staysresult_readywithmerge_pending. This holds whateverBATCH_PIPELINE_PROVIDER_MERGE_MEMBERSHIP_ENABLEDis set to: on 2026-11-13 at 13:00Z, 78 minutes after that switch was set tofalse, 3,435 provider rows captured over a day earlier were still committed in a 2-minute window, 2,925 of them through the head wait, because rows stampedready_atwhile it was on stay eligible afterwards. Unprojected results rose from 78,204 (12:12Z) to 117,076 (12:56Z).FailedPrecondition; fresh rows behind a held row then wait for the query to work again. The probe now also runs when the catch-up depth hold is switched off (depth 0), both when the held row heads the owner and when an unready provider backlog row does (there the head wait alone would pick a held row and commit nothing).FailedPrecondition, a held owner is not probed and its backlog stays held. Before review this path recursed without bound.merge_holdsmarker and adds no owner to the in-memory re-offer set, including when the owner is at the depth cap and whether the held head is ready or not, so maintenance does not re-drain held owners every pass.Details:
backend/docs/listen_pusher_pipeline/changes/2026-11-13-provider-backlog-hold.md.What is not delivered while the switch is off
FRESH_CAPTURE_LAG_SECONDS): 13% of 1,820 provider admissions sampled on 2026-11-13. These were not being delivered before today either.Known limit: when an owner's oldest pending row is a GPU-route row that is not ready, a fresh provider row behind a held provider row waits for that head, because the fresh probe only runs behind a catch-up head. Provider owners are almost entirely single-route, and this is the behaviour GPU rows already have.
Known limit: a GPU-route catch-up row (an old upload) that sits behind a held provider row of the same owner waits with it, because the merge takes an owner's rows in capture order and cannot select past the held row. Fresh rows of either route still commit ahead of the held row through the fresh probe. The exception is while the fresh query is unavailable (
FailedPrecondition, a missing index): the probe backs off, and a fresh row behind a ready held provider row waits until the query works again. It ends with the metered release.Rollout and the default-off switch
This is a default-off gate, so here is its plan. It is not a per-user ramp; it guards one stock of rows.
backend-integrationthen turnsBATCH_PIPELINE_PROVIDER_MERGE_MEMBERSHIP_ENABLEDback on (it was set tofalseafter the measurements above).backend-integration, flat.card:drain-stuck-provider-stt-backlog-for). Date: before 2026-12-05, when the oldest staged results reach the bucket's 30-day lifecycle. The switch is removed with that job.trueis the old behaviour (release paced only by the depth hold) and should not be used without projection headroom.Rollback of this PR's effect:
BATCH_PIPELINE_PROVIDER_BACKLOG_RELEASE_ENABLED=true.BATCH_PIPELINE_PROVIDER_MERGE_MEMBERSHIP_ENABLED=falsenow stops fresh delivery too (no new row is stamped fresh, and unstamped rows are held), without releasing anything.Tuning disclosure
No value changes and no new knob. No new pipeline state: a held row keeps
state=result_ready,merge_pending=true. Its exit is a commit, when the switch is on or the release job offers it, or the existing terminal paths.Product invariants affected
none
Failure class (fixes)
Failure-Class: new
Proposed:
FC-backlog-release-shares-lane-with-fresh-work. A fix that made stuck work eligible released all of it at once into stages (projection owner queue, serving CPU) that fresh work also depends on, with no class and no rate of its own.Tests
New in
tests/unit/test_batch_provider_merge_membership.py: by default only fresh rows commit and the backlog stays ready, with no hold marker and no re-offer, however far projection advances; opting in releases it under the depth hold; fresh rows pass a held backlog with the depth hold off; a provider row stamped not-fresh is held too; a ready backlog row does not pass an unready head; GPU catch-up rows are not affected. Added after review: the membership switch off still holds the backlog; a fresh row passes an unready backlog head at depth 0; an unavailable fresh query is asked once and the backlog stays held; a held head at the depth cap writes no marker. Each of the four fails without the fix.tests/unit/test_flag_budget.pyfailed in CI onb1165bd(the new name was missing from the budget count and the helper-switch list); fixed.The two provider golden traces (
provider_stt_ja,provider_stt_unsupported) admit their uploads after the fresh lag, so their config now sets the switch on and the traces are unchanged: they keep pinning the commit and projection path.Review
Independent review (Luna), round 1 on
b1165bd: FIX, two blockers (no fresh probe at depth 0 behind an unready provider head; unbounded recursion when the fresh query is unavailable) and one should-fix (a depth marker written for a held head at the cap). All three are fixed with a test each. The reviewer found no privacy-fence bypass and confirmed the other commit routes use the guarded path.Round 2 on
bfa768a: FIX. Round-1 findings confirmed closed; no privacy-fence bypass. Two blockers and two should-fix:tests/unit/test_batch_pipeline_recovered_release.py.due('result_ready')) takes the 100 oldestresult_readyrows with no cursor, so rows that never commit pin it. That page is already pinned: on 2026-11-13 at 13:35Z its 100 rows were all 9.1 to 10.1 days old (71 GPU-route, 29 provider). This PR adds more rows that stayresult_ready, behind those. Rows that can commit are reached by their owner wake and the per-pump drains, as today. One class is not: a GPU-route catch-up row behind a held provider row of the same owner (the known limit above) is reached by its wake, commits nothing, and has no marker or page to bring it back; it waits for the release like the provider row in front of it. The fix is a cursor on that page plus the metered release.Head confirmation on
2e675fc: FIX. It confirmed 1 and 2 closed, no privacy-fence bypass, and no change for owners without provider rows. It found my account of items 3 and 4 inaccurate; both are corrected above (the GPU catch-up case is stated, item 4 is now fixed in code). It also raised custody: held results are GCS artifacts under the 30-day staging lifecycle, and this PR adds no enforcement of the release deadline. That is accurate and stays open by design: these rows have been undelivered since 2026-11-05 with or without this PR, releasing them unmetered is what delayed every user's results on 2026-11-13, and the metered release has an owner and a date (before 2026-12-05, see Rollout). If that job is late, the oldest held results become unprojectable.Narrow confirmation on
b1cbfad: item 4 confirmed closed, recursion terminates on every path, no new data-loss or privacy-fence risk, and the account of the two open items matches the code. Its verdict was FIX for one sentence in this description ("Fresh rows of either route are not affected"), which lacked the query-availability exception; the sentence is corrected under the known limits. No code change followed, so the head is unchanged.Rulings by the rollout owner session (goal-owners rollout, R14 self-drive, 2026-11-13), both accepted for this PR:
card:drain-stuck-provider-stt-backlog-forwith what is lost if it slips.Not tested here: production behaviour. The acceptance read after re-enabling is the share of fresh provider units settled 3–8 minutes earlier that are committed, and the two must-stay-clean metrics above.
🤖 Generated with Claude Code