Repository navigation
feat(firestore): open historical_scan_memo_scope at the sync-task attempt boundary - #22048
Merged
Merged
Conversation
…empt boundary Batch 3 slice B3S0: the batch-2 historical_scan_memo lever (5% on prod) was inert because no production code opened the memo scope. Open one scope per executed sync/backfill task attempt in _run_sync_job_body, inside the acquired run-lock, covering both lanes. Retry/lock/admission paths stay outside; executor leaves inherit the memo via copy_context without resetting it; every memories write still fences. people_scan_dedupe stays inert (no qualifying call site under the S6 constraints). 15 new tests; 406 targeted tests green; zcode glm-5.3 review SAFE with zero required fixes.
Codex Review SummaryThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
Git-on-my-level
added a commit
that referenced
this pull request
Oct 20, 2026
…and 7 ticks) (#22629) * config(firestore): re-enable six exonerated levers at 5% (guards in band 7 ticks) usage_month_cache, singleton_loops, queue_age_sample_budget, backfill_task_reads, historical_scan_memo, ledger_purge_coalesce: 0 -> 5. backend-sync/-backfill 5xx in band 11Z-17Z 2026-10-19 with all sync levers at 0 (drain finished); singleton lease rework (#22142) and queue-age code live on served image 4f43b2d; scope opener live (#22048). people_scan_dedupe stays 0 (no qualifying call site). set_levers.py replace-mode regeneration (16 sites, 6 files) incl. contract tests. * chore(firestore): regenerate flag registry after main merge (13-key literal, six levers at 5)
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.
Summary
Firestore reads loop, batch 3 slice B3S0 (scope opener). Batch 2 (#22019) shipped three default-off levers;
historical_scan_memois registered inFIRESTORE_READ_LEVERSat 5% on prod but inert because the memoscope
historical_scan_memo_scope(uid)had no production opener. This PR opens the scope at the sync-taskattempt boundary so the lever starts saving reads when ramped:
backend/routers/sync.py::_run_sync_job_body: wrap the awaited pipeline call inwith historical_scan_memo_scope(uid):(sync.py:2278), inside the acquired per-job run-lock, afteradmission/download checks, for both
freshandbackfilllanes. Parsing, lock acquisition, early exits(locked/terminal/expired), retry handling and lock release stay outside the scope. Exactly one scope per
executed task attempt; each Cloud Tasks retry is a fresh delivery/context, so no memo state crosses attempts.
people_scan_dedupedeliberately stays inert: its only shared callers (database/users.py:989viaget_people— speaker-learning authority path — andutils/llm/known_spellings.py:147) do not qualify for atask-wide opt-in under the S6 review constraints (external people writers lack complete invalidation). No
config change in this PR; the flag can stay at 5% until a qualifying call site is audited.
ledger_purge_coalesceneeds no opener (gated internally at the purge orchestrators) — verified unchanged.Executor propagation:
run_blockingusescopy_context()+ctx.run, so executor leaves see the memo object,never reset its token, and observe
closedafter scope exit (cancelled-leaf containment is tested). NoContextVar reset runs in a foreign context (desktop-backend incident rule respected). The inline fallback spawn
(sync.py:1635) is intentionally NOT wrapped: a scope around a fire-and-forget spawn would close before the
pipeline runs; inline-dispatch jobs keep current read counts (efficacy-only, correctness unaffected).
Product invariants affected
attempt. Default off (lever at 0/unset = byte-for-byte current behavior; the CM bare-yields).
(same uid/cursor/limit) inside one attempt; every write in
database/memories.pyfences the memo; budgetaccounting stays truthful.
historical_scan_memoalready inKNOWN_LEVERSand already declared in prodFIRESTORE_READ_LEVERSat 5).Test plan
backend/tests/unit/test_fsr_scope_opener.py(15 tests): read-count proof (2 identical scans →1 physical read, both lanes, real 5%-cohort hashing), fence-through-scope (mid-attempt write re-reads then
re-memoizes), off-path equality (
unsetwith memo-allocation guard /outside_cohort/no_openerall(2,2)), scope hygiene (no opener on locked/terminal/expired exits; close on success/TimeoutError/
CancelledError with entries cleared and ContextVar None), executor propagation without ambient leakage,
retry freshness (attempt-2 reads post-write value).
BACKEND_UNIT_TEST_FILE_LISTrunner at nice 19 (lever-on and env-unsetpasses).
scope per attempt inside the run-lock, closed on all exits, no cross-attempt memo survival, zero unfenced
memories-write paths (sweep found 0;
entities.py:159KG reassignment has no production caller), andreviewer independently re-ran 50 tests green. Reviewer notes inline-fallback spawn intentionally unwrapped
(correctness-preserving) — do not "fix" by wrapping the spawn site later.
Line-count exceptions
Line-Count-Exception: backend/routers/sync.py | 2882 -> 2887 | open historical_scan_memo_scope around the sync-task pipeline attempt (lever historical_scan_memo)
Failure-Class: none
Rollout
historical_scan_memois already declared at 5% in prodFIRESTORE_READ_LEVERS; on deploy the scope opener activates the existing 5% cohort (safety soak).readout.pyabsolute caller reads vs the pinned post-B2 baseline) decides the later100% config PR; guard services backend-sync/backend-sync-backfill stay under verify.py hourly gates
(backfill exemption expires 2026-10-18T01:00Z and is re-checked before any ramp).