Skip to content

perf(backend): prevent maintenance scan storms on lever rollback - #23801

Merged
Git-on-my-level merged 3 commits into
mainfrom
lane/fsown
Oct 27, 2026
Merged

Git-on-my-level merged 3 commits into
mainfrom
lane/fsown

Conversation

@Git-on-my-level

@Git-on-my-level Git-on-my-level commented Oct 27, 2026 •

Copy link
Copy Markdown
Member

Summary

During the 10-22/25 Firestore surges, maintenance scans multiplied across replicas; the 10-25 spike followed a lever rollback. The 10-22 exact revision trigger remains unproven. Day-aligned counters attribute 576M and 510M extra reads to the queue sampler and three finalization sweeps, rather than sync-job redrive processing. Keep the existing maintenance admission lease on by default in production independently of the singleton_loops cohort, with FSR_MAINTENANCE_COORDINATION_ENABLED=false as the explicit coordination kill switch.

Redis keys/Lua, scan cadence, takeover bounds, local recovery on Redis failure, transactional job claims and designated queue publisher are unchanged. Non-production, including stage-prod staging, retains legacy cohort qualification unless explicitly overridden. Other Firestore levers retain their current behavior. No runtime-env/config literal, index, workflow, account-data or retention changes.

This is a recurrence guard: current singleton100 already coordinates production, so steady-state new realized savings are $0. Comparable observed scanner regrowth is about $219–271 per incident at $0.43–0.47/M; recurrence frequency and monthly avoided spend are unknown. WQ21 privacy memo and WQ24 funded aggregate shortcuts are excluded because their correctness gates did not pass; WQ22 is already in #23686. No partial authorization/quota cache ships.

Validation

  • BACKEND_UNIT_TEST_FILE_LIST=/Volumes/Ephemeral/scratch/fsown/scan-tests.txt BACKEND_PYTEST_WORKERS=4 nice -n 10 bash backend/test.sh, through workspace bin/omi-heavy: 68 passed across the scan-storm guard, existing singleton/recovery and Redis Lua suites.
  • Real queue sampler with five replicas and ten ticks: 1000 document reads with coordination explicitly off, 200 with it on, with the same empty legacy lever literal. Fixed-loop tick, fail-open, publisher eligibility and takeover tests pass.
  • Feature flag registry check passed; Full make preflight: 36 checks passed (366.85s). Exact-head CI is verified separately before MERGE READY.
  • Independent Luna full-diff review through agentctl found staging uses stage prod; corrected production detection and added staging/preview regression profiles. Existing-session Luna delta SHIP, no new actionable findings (exec-yard-device-motion-guard-episode-voyage, continuation key fsown-luna-delta-1027a).

Ship and rollback (lead only)

No merge/deploy/apply by this lane. No apply request during the batch entry/soak through ~11:30Z. Lead deploys source in its allowed train, first verifying healthy designated FSR_QUEUE_AGE_PUBLISHER=1 and fresh queue-age samples. Compare lease outcomes, finalization recovery/queue freshness, errors and live p95 before/after; verify the runtime-reported release SHA for each serving artifact. Setting FSR_MAINTENANCE_COORDINATION_ENABLED=false via the regular lead-owned runtime procedure restores prior per-replica execution and can raise spend. See backend/docs/runbooks/firestore-spend-guard.md.

#23797 remains owned by the lead and untouched. Finjob5→100 requires a separate complete-literal lead config change after soak; READY index metadata alone is not a production apply.

Product invariants affected

none

Failure class

Failure-Class: none

CR train #2 integration (2026-10-27)

Merged origin/main at 8da0ca9e1b7867cb9719a33225c3d9371713356a into lane/fsown with merge commit eb963fcfca4106bdc8c718f7c308624116c3034a; no rebase or force-push. The two conflicts were documentation/registry additions: retain fleet coordination and main's server-batch documentation, new batch flags and newer default-off Soniox idle-reselect declaration; regenerate the registry. No production-code conflict. #23797's scoped literals and #23803's metrics collector remain identical to main.

Affected tests through backend/test.sh, explicit nine-file BACKEND_UNIT_TEST_FILE_LIST, BACKEND_PYTEST_WORKERS=4, under nice / omi-heavy: 458 passed, one slow test deselected by the standard harness. Final exact-head CI and mergeable,mergeStateStatus,headRefOid are recorded in reports/fsown-owner-1027.md. Lead retains merge/deploy/apply authority.

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 27, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review 🔄 Running since 2026-10-27T16:57:09.830763Z eb963fc New commits
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

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
Git-on-my-level merged commit 8d696ed into main Oct 27, 2026
57 checks passed
@Git-on-my-level
Git-on-my-level deleted the lane/fsown branch October 27, 2026 17:12
Git-on-my-level added a commit that referenced this pull request Oct 27, 2026
## Summary

Retain two unsuperseded structural Firestore query optimizations from
orphan #23442; merge current main into the existing lane history. The
public-catalog and request-cohort cache changes are removed. No query
policy, transcription, speaker labels, Free benefits, legacy price,
raw-audio custody or authority checks change.

- **Smart merge:** use the declared device composite only for
explicit-device, unbounded discarded-barrier lookups. Keep the global
finite six-row predecessor window, missing/empty-device behavior,
deleted barriers, transaction snapshot and unrelated-error propagation.
Missing-index errors fall back to the original query. Device or citation
IDs exceeding 1,500 UTF-8 bytes keep their original scans because
Firestore truncates indexed field values; no new identifier input
restriction is introduced.
- **KG pruning:** query native `memory_ids` reverse citations for at
most **30 distinct IDs** before mutations. Larger retractions keep one
original full scan so overlapping chunks cannot amplify billed reads.
Retain the full surviving-node and orphan-edge cleanup, including
unrelated dangling edges. No side collection, backfill or new
application writes.
- Independent switches default on; `FSR_SMART_MERGE_PARTITION=off` and
`FSR_KG_CITATION_INDEX=off` restore their original paths.
- Main's new donor rebasing, open-loop/retirement behavior, #23797's
scoped literals, #23801's maintenance guard and #23803's collector
changes are preserved.

## Four-part decision / economics

10-26 fleet caller data already captured in the fsown report; $0.43–0.47
per million reads × 30 days. These are **opportunity ceilings, not
forecasts or booked savings**.

| Original part | Observed caller reads/day | Monthly evidence | Result
|
| --- | ---: | --- | --- |
| Smart-merge device barrier | 16,749,388 | Entire pool $216.07–236.17;
upside capped at $236.17, eligible barrier fraction/off-device
selectivity unknown | KEEP; main still scans broadly then filters device
in Python |
| KG reverse citations | 8,915,616 | Entire pool $115.01–125.71;
first-scan-only upside capped at $62.86. Fixture-equivalent $55.83–61.02
only if its graph shape holds fleet-wide | KEEP; main still performs the
first full node scan; bulk traffic remains legacy |
| Public catalog single-flight | 1,538,759 | Entire pool only
$19.85–21.70; incremental miss coalescing unmeasured; $0 assigned |
DROP; main already has 30s list single-flight and 600s Redis backing;
limited upside does not justify extending shared-cache dependency |
| Request cohort snapshot | 2,616,546 (old + renamed callers) | Entire
pool $33.75–36.89; $0 additional assigned | DROP; main already shares
observations and clamps their original 60s deadline, while this request
memo did not recheck expiry |

Retained gross upside cap **$299.03/month**, not a point forecast.
Composite storage, empty-query floors, fallback overhead and the actual
request/graph mix remain unmeasured; net savings may be zero or
negative. **New verified/realized savings: $0**, until lead serving plus
D+1 net billing against the 10-24/25 baseline.

Track old and new callers together:
`smart_merge:find_preceding_conversations` → `smart_merge:collect`
(including unchanged finite reads);
`knowledge_graph:prune_memory_citations_from_kg` plus
`knowledge_graph:_citation_nodes`. New origins are
`task:smart_merge_partition_lookup` and `task:kg_citation_prune`. Caller
renaming is not saving.

## Integration and validation

- Merge commit `f923e4862f1240b52c429f5705f091558f2a90f3` parents:
existing PR head `789db126e73be7c01465af90e4f7f5277c3fce56` and main
`5f2caea10a67fcd2dbc52347aff08c9f0ac5fdab`. Follow-up
`f240ea8dbe01b2f061fbbb9aa5ce56be6f75070c` caps bulk KG reads. Final
source `4174839ab5f0c0bc06eda0a4e81b96b66931980a` preserves scans for
identifiers beyond index bounds, with ASCII and multibyte boundary
tests. No rebase/force-push/stash. Original divergent local lane work is
preserved.
- **1,019 passed**, one standard slow deselection, across an explicit
14-file list through `backend/test.sh`, `BACKEND_UNIT_TEST_FILE_LIST`,
`BACKEND_PYTEST_WORKERS=4`, `nice -n10` and `omi-heavy`. Includes all
seven Firestore guards, offline SDK query serialization,
global-window/deleted-barrier/transaction fallback, finalizer/donor
integration, identical KG cleanup, and bulk read non-amplification.
- Synthetic mechanisms: indexed barrier 121→1 returned rows with the
same relevant barrier; KG 206→106 reads with identical final graph; bulk
KG remains 4→4 reads. None establishes fleet savings.
- Own Luna review: SHIP on f240; final index-bound delta review and
normal pre-push/CI receipts are tracked at the top of
`reports/fsown-owner-1027.md` before MERGE READY.

## Lead-owned index / ship gate

A ro-prod **metadata-only** check found 221 composites and **no matching
device index**. The lead must clear the standard additive index prebuild
auth/environment approvals and verify
`conversations_smart_merge_device_preceding` READY before serving this
source. Production prebuild approval is a lead gate, not lane authority.
Do not ship through the missing-index fallback to bypass the readiness
gate. Native KG array-index availability also retains the standard
guard/fallback contract.

Once readiness and source CI are clean, the lead merges and ships
through its normal source train, watches missing-index/fallback/query
latency, smart-merge barrier equivalence, KG cleanup, 5xx and live p95,
and rolls either switch off on a regression. Compare matched caller
windows and D+1 total reads/writes/storage before booking dollars. This
lane performs no deploy/apply, prod write, approval or access change,
and does not close the PR.

## Product invariants affected

- INV-MEM-4 — graph pruning remains derived cleanup; privacy/deletion
authority and authoritative promotion/funding checks retain their
existing paths.

Line-Count-Exception: backend/database/firestore_index_registry.py |
2247 -> 2266 | Declare the partition query beside the original query in
the single index authority; preserve generated manifest ownership.

Failure-Class: FC-merge-across-discarded-rows
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant