Repository navigation
Shard projection drains by owner, push wakes, fresh first, head deadline - #24731
Closed
Git-on-my-level wants to merge 33 commits into
Closed
Git-on-my-level wants to merge 33 commits into
Git-on-my-level wants to merge 33 commits into
Conversation
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.
Requested by David · project thread
Change
Projection serving instances currently page the same result log and contend for owner claims. This PR adds owner-hash shard leases, FRESH/BACKLOG wake queues, and leader-only tail/backstop discovery. Holders feed the existing owner drains; transactional predecessor fences and owner claims still govern assignments. Redis failures, unheld shards and disabled prerequisites retain legacy local-drain/sweep paths. Both feature switches remain default off.
Discovery routes owners using their oldest commit and freshest non-future capture. Whole-log discovery aggregates within each page and re-routes only when a later page finds a fresher capture; tail discovery aggregates its bounded pages. Discovery atomically creates a missing wake or promotes an existing BACKLOG wake to FRESH when fresh work is found. Promotion advances the old backlog sequence, preserves future retry deadlines and leaves lease keys untouched. Other replays preserve scores and sequences; discovery never demotes fresh wakes. Real notifications keep their sequence bumps so settlement/deferral cannot erase concurrent commits. Fresh-first admission retains the two-slot backlog reserve; productive shard owners yield between turns, and durable future scores remain an admission deadline across holder replacement. Failing heads and eligible allowlisted blocked heads have a bounded held exit. Privacy, claim, shadow, predecessor, generation and wiring refusals retain their existing exclusions.
Deferred wakes use the later of the existing pump backoff and the remaining local owner timer. The timer is measured on its event-loop clock, then converted to a Redis wall-clock score; a 300-second privacy_unchanged hold therefore stays out of the due prefix until the owner can run. Claim-stop wakes also move to backlog at their retry deadline, allowing later due owners through the bounded fetch. This reuses the actual eligibility deadline without expanding fetches or adding scans. Existing sequence checks preserve concurrent notifications. Event-loop drain requests route through db_executor; failed Redis pushes retain local-drain intent.
Failed Redis settlements and deferrals mark the coordinator unhealthy. The pump retains each batch (including writes whose replies were lost), preserves deferral order/deadlines, releases leases and records the shared legacy-sweep fallback before admitting any more wakes. Successful lease refresh precedes replay; a continuing error disengages it again. Existing compare-sequence checks make replay safe and preserve newer notifications. A stale-sequence False stays healthy. No new durable structure, tuning knob, retry duration or capacity is introduced.
Redis write/admission audit of projection_shards.py and projection_shard_pump.py:
Contract: backend/docs/listen_pusher_pipeline.mdx#batch-projection-owner-shards.
Change note: backend/docs/listen_pusher_pipeline/changes/2026-11-05-projection-owner-shards.md.
Flag contracts
The opt-ins accept exactly true/1/on/yes after trimming and lowercasing; unset, blank, off and unknown values stay off. The membership setting defaults true with false-only opt-out. Backlog reserve defaults 2 within 0..16; head deadline defaults 86400 within 3600..604800; invalid inputs retain those defaults. No new flag, retry duration, capacity change or default change accompanies this follow-up.
Verification
Candidate 3aa674a, on reviewed head e4e8fa9. Wake promotion is implemented in f485674; 64bf146 preserves page-local routing, partial progress and the scan budget. All five authored commits, including merge 3aa674a, carry Failure-Class: none. No rebase, amend, force push or authored .github change.
The exact-head discovery runtime run on 64bf146 passed 2648 cases across 40 isolated files, completed 2026-11-10T09:30:06.151713+00:00. It includes every batch_projection file, projection/serving, owner-drain, privacy/resume, held/dead-letter, jobstore parity and Firestore guards. The shard file passed 291 cases and the real OwnerDrains file passed 20. Coverage includes mixed old/fresh captures on one page, pages in one call and successive calls; no demotion; unchanged fresh replay sequence; promotion with a shard lease held; stale backlog settlement/deferral; a future retry surviving holder replacement; completed-page progress on a later query failure; and routing time counting against the existing scan budget. Future captures cannot hide valid fresh work.
All nine initial regressions failed against the reviewed runtime, completed 2026-11-10T08:07:02.201127+00:00; the fixed selection, extended with future-capture controls, passed 12 cases at 2026-11-10T08:12:06.528187+00:00. The first broad run caught an integration fixture that reported fresh durable metadata alongside a backlog notification while expecting discovery to stay a no-op. The expanded fixture separates same-intent replay from newly discovered fresh work while a modeled claim is held, with both real-commit timings preserving work across replacement and zero modeled claim overlaps. No guard or budget was relaxed.
Main advanced and PR #24731 became DIRTY at 2026-11-10T12:05:21.626356+00:00. The publisher stopped before invoking push. The authorized merge of main c8959fd produced candidate 3aa674a. Its sole conflict combined main's quiet-check GMP allowlist with this PR's four shard-telemetry alternatives, preserving main's regex grouping. All three projection runtime modules and both regression-test files are byte-identical to tested 64bf; client and .github trees exactly inherit main. Merged-candidate shard/drain, allowlist and episode-metrics checks passed all 489 cases across six isolated files, completed 2026-11-10T12:22:51.764318+00:00. Fresh metadata validation passed all five checks, completed 2026-11-10T12:23:46.700133+00:00. The original load deadline is retained.
Query shapes passed 560 cases, one slow case deselected by standard fast markers, 526-second initial file wall under the unchanged 900-second budget. Full make preflight passed 42 checks, completed 2026-11-10T09:03:45.027592+00:00, through omi-heavy with OMI_CHECKS_JOBS=1. This long run began before the final page-local refinement; final metadata validation and the normal pre-push gate verify the published candidate. The async-blocker scan selected zero findings. scripts/pr-preflight --suggest passed, completed 2026-11-10T08:11:58.498200+00:00. Tuning is byte-preserved from intake.
Commands: bin/omi-heavy run --wait 3600 -- env BACKEND_UNIT_TEST_FILE_LIST=<targeted-files.txt or drain-files.txt> BACKEND_PYTEST_WORKERS=2 BACKEND_UNIT_FILE_BUDGET_SECONDS=900 TZ=UTC bash backend/test.sh; make preflight under the same gate with OMI_PR_BODY_FILE set. Python 3.11, file/process isolation and all existing budgets are retained. Local Lua/leases use fakeredis; owner claim overlap uses the hermetic claim model. Real Redis qualification and production behavior remain unmeasured. No GCP tier or production access. Evidence: owning workspace data/run-2026-11-08-retro-fixnow/out-n4-merge.md, Tenth review section. PR checks.
Tuning
These four knobs are new in this diff: their previous state was absent, rather than a smaller deployed capacity. The new shard and blocked-head paths remain default off; this disclosure does not enable them.
Shard continuation admission budget: new: 1 productive drain turn per shard admission (
backend/utils/batch_pipeline/projection_shard_pump.py:195,backend/utils/batch_pipeline/projection_drain.py:220). Yield retry uses the existingTICK_SECONDS = 1.0second (projection_shard_pump.py:64,:210), rather than the 120-second stuck-head delay. This gives waiting wakes a bounded admission opportunity between productive turns without expanding concurrent drains or changing the two-slot backlog reserve. This is internal policy, not a new flag.The existing global projection_page clamp remains 200, unchanged: backend/database/batch_pipeline_store.py:426. No existing production capacity or flag value is retuned by this follow-up. The persisted wake score is enforced as the admission time, using the current wall clock and existing take-page limits.
Discovery replays preserve existing scores, sequence tokens and TTLs; commit/routed notifications retain their sequence bumps. The opt-in parsers use the documented shared tokens.
The deadline alignment adds no tuning knob: deferred wakes use max(existing pump retry delay, remaining local timer delay), so existing privacy/live-target holds remain effective. Claim stops now receive the existing 15-second jittered durable retry score; no retry constant, fetch size, drain capacity, flag value or default changes. Routed Redis work uses the existing db_executor.
Landing and dark rollout
Merge waits for #24893. This PR stays dark. Preserve its blocked-head counter and terminal-stop semantics in the change note, add the composed re-drive-budget/terminal-stop test, and include omi_backlog_state_transitions_total in ramp monitoring before landing. This follow-up does not implement those three composition additions or authorize merging, enabling flags, deploying, or requesting review.
The registered shard ramp is staging backend-integration, then all production backend-integration serving instances in one config train, expanded by the two-lane lead, target 2026-11-12. The separate blocked-head ramp requires David's production approval, same expander/target. Expansion requires staged Redis Lua/lease tests and clean registered metrics: throughput at least the pre-switch hour for 60 min, claim-busy below 10%, no unheld shards after the roll, lower Firestore reads; bounded allowlisted holds and release-scan visibility for the deadline. Rollback false restores the legacy sweep on its next tick. Neither switch is enabled by this PR publication.
Line-count exception
Line-Count-Exception: backend/utils/batch_pipeline/projection.py | 1722 -> 1959 | Blocked-head deadline branch and resolver, shard router hooks, and tail/backstop discovery on Projector; new shard logic already lives in projection_shards.py and projection_shard_pump.py. Follow-up split: move Projector discovery (sweep, discover_owners, discover_tail, sweep_finish_only) into utils/batch_pipeline/projection_discovery.py, owned by omi-pipeline.
Product invariants affected
none
UI evidence
UI-Evidence: none -- backend only
Failure class (fixes)
Failure-Class: none
No registry class matches advisory discovery freshness aggregation and wake promotion. FC-shared-eligibility-gate-collapses-distinct-lanes describes distinct entry-point preconditions, rather than a metadata reduction and advisory wake transition. The ninth-review Redis custody audit is retained above. FC-settle-path-skips-sibling-fence-and-wake covers durable eligibility mutation; FC-unowned-scheduler-shard-writes covers exclusive Firestore pull ownership. Neither describes this failure. The shared unhealthy-release path and behavioral shard/drain regressions guard settlement, push, take and lease recovery.