Skip to content

perf(privacy): add WQ26-fenced negative lookup cache - #24751

Merged
Git-on-my-level merged 5 commits into
mainfrom
lane/pipeline-negcache
Nov 6, 2026
Merged

Git-on-my-level merged 5 commits into
mainfrom
lane/pipeline-negcache

Conversation

@Git-on-my-level

@Git-on-my-level Git-on-my-level commented Nov 6, 2026 •

Copy link
Copy Markdown
Member

Problem

The recorded 2026-11-06 ~04:50Z Phase 1a measurement found ~2,073 NOT_FOUND reads/s out of 3,834 privacy reads/s: conversation tombstones 829/s, account deletion markers 695/s, missing conversations 549/s. Source: firestore-phase1-1a-0450Z.md in the prescribed omi-workspace/data/run-2026-11-05-omi-pipeline/ run record. These are dated recorded measurements, not a fresh production measurement or a forecast of savings. The prescribed scout report records the 2026-11-04 Redis-bypass seeding regression (54k to 530k reads/10 min), which ruled out reviving that path.

Change and invariant

A cached NOT_FOUND must never hide a tombstone, account deletion, legal hold, or newly existing conversation. The process-local 50,000-entry LRU stores only real NOT_FOUND reads, keyed by client/plane, uid and exact document path, with the owner's WQ26 memo token and server revision including nanoseconds. Each reuse requires that same decision to have re-read the token inside the same transaction and compared it identically. The owner token remains in Firestore's conflict set; TTL is a second 60-second bound, measured before the live absence read. No Redis, speculative seeding, positive rows or authorization decisions enter this cache. Missing/malformed tokens, full-row exports and nontransactional calls stay live.

The existing Commit fence already rotates tokens atomically for all writer families, including metadata-only conversation CREATE and merge-upsert. Added regression coverage for those create shapes and extended the actual-writer emulator matrix to run with negative lookup caching as well as generation memoization. Legal holds retain their existing external-fence policy; their writes invalidate the lookup hints.

Net-zero flags (lead2 ruling 258db3 (03)): the sole new lever is privacy_negative_lookup_cache (0 off, positive percent selects the candidate cohort). Existing privacy_checks_shadow selects shadow mode within that cohort; shadow takes precedence and always reads live, bypassing generation-memo hits to gather evidence. With the new lever 0, existing decision-shadow behavior stays unchanged. No privacy_negative_lookup_shadow lever remains.

The retired batch_privacy_memoize slot pays for the new lever: remove BatchPrivacyMemo, its store/projection caller plumbing, snapshot-only replay instrumentation/assertions, and all runtime/worker chart literals (including the worker's former 100% value). The live authority walk and the WQ26 generation memo remain. Tests retain retired-key/off-path, ordering, retry and denial-parity guards. The flag registry records the replacement; the shared FIRESTORE_READ_LEVERS env budget slot has no separate per-sublever budget entries. Known lever inventory: exactly one added and one retired.

Identifier-free hit/miss/mismatch counters are on both Cloud Run GMP keep-lists and survive isolated sync-worker exits/SIGKILL. The GPU worker registers the counter on its private registry, and a real pod-parent endpoint test verifies each child's series is retained once. No negative-cache cohort is enabled; runtime config changes only remove the retired lever.

Validation

CI follow-up: removed the obsolete WQ12-only monkeypatch from test_direct_transaction_reads_are_named; production code is unchanged. Grep plus an AST scan found no other retired store patch targets. test_batch_pipeline_contention_errors.py and test_batch_pipeline_pump.py both pass in the file-isolated test.sh runner. Merged current origin/main (PR #24752) and included its owner-drain tests in the same selection.

  • BACKEND_UNIT_TEST_FILE_LIST=... BACKEND_PYTEST_WORKERS=3 bash backend/test.sh, through omi-heavy: 1046 passed across 26 files, one slow test deselected by the standard runner. Covers privacy/cache/fence/memo, WQ12 retirement, store/projection ordering and retries, read/write budgets, flag/stage ratchets, config/chart rendering, replay unit contracts, GMP retention and real GPU-worker/pod metrics endpoints.
  • Loopback-only Firestore emulator: tests/integration/test_bpp_generation_fence_emulator.py -m integration -q: 78 passed on the net-zero revision, through omi-heavy.
  • Separate loopback replay emulator process: tests/integration/test_replay_harness_privacy_firestore.py -m integration -q: 21 passed, including the retired-snapshot/generation-memo baseline and runtime-config cases. Together the emulator files passed 99 tests. Files run in separate pytest processes; an exploratory combined-file run was discarded after exposing shared-process contamination.
  • Final mandatory push guards passed: 53 repository checks, runtime-env validation, format/source closure, bounded unit selection, and type checking with 0 errors. PR metadata names INV-MEM-4. The standard type checker still reports existing warnings; no production access was used.

Invariant: INV-MEM-4 remains unchanged. Runtime manifest edits remove only the retired read-dedupe lever; canonical promotion authority and its routing are untouched.

Risk, rollout and rollback

Privacy-critical read suppression depends on complete WQ26 writer coverage. Standalone/external writers bypassing the fence remain a rollout blocker. Shadow moves the token read ahead of the lookup families and intentionally gives up generation-memo savings for sampled owners; measure absolute reads by plane. Production savings and all-plane coverage have not been verified in this code-only lane. No GCP credential tier was used; no production access, merge or deploy.

Owner: lead2. After verifying writer artifacts on every plane: hours 0–2 set privacy_negative_lookup_cache:100 and existing privacy_checks_shadow:100 (shadow only); gate = zero mismatches on >=10,000 shadow hits (actual compared lookups), all serving planes represented and no scrape gaps. Hours 2–4 enforce 10%, hours 4–6 enforce 50%, hour 6 onward enforce 100%, each advancement owned by lead2 after a clean preceding two-hour window. Set existing privacy_checks_shadow:10 during enforcement; it wins overlapping cohorts. Insufficient samples extend the window. Any mismatch stops the ramp and requires writer investigation and shadow requalification.

Rollback: privacy_negative_lookup_cache: 0 immediately restores live lookup enforcement; also set privacy_checks_shadow: 0 to restore the exact previous read path. No data migration or Redis invalidation. The existing default/percentage semantics are used as requested; this PR does not enable enforcement before shadow qualification.

Failure-Class: none

This is a read-reduction feature with a new correctness guard; no previously shipped authorization policy is changed.

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 6, 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 ✅ Completed 2026-11-06T06:18:31.720825Z d00d89b 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.

@cubic-dev-ai cubic-dev-ai Bot left a comment •

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

1 issue found across 14 files

Confidence score: 3/5

  • backend/docs/runbooks/privacy-check-shadow.md relies on a denominator that the GKE worker endpoint does not expose, so the all-plane shadow-hit metrics will be incomplete. Register the privacy collectors in the worker’s custom registry.
Prompt for AI agents (unresolved issues)

Check if these issues are valid — if so, understand the root cause of each and fix them. When an issue isn't valid or won't be fixed in this PR, reply in its thread with the reason and then resolve the thread. If appropriate, use sub-agents to investigate and fix each issue separately.


<file name="backend/docs/runbooks/privacy-check-shadow.md">

<violation number="1" location="backend/docs/runbooks/privacy-check-shadow.md:110">
P1: The GKE worker endpoint does not expose `privacy_negative_lookup_total`, so PodMonitoring cannot provide the all-plane shadow-hit denominator claimed here. Register the privacy collectors in the worker’s custom registry (and verify the parent aggregation) before treating worker coverage as qualification evidence.</violation>
</file>

Reply with feedback, questions, or to request a fix.

View guided diff | Turn on auto-fix | Re-trigger cubic

candidate NOT_FOUND; a live document is always a mismatch, even within TTL.
The denominator for qualification is shadow **hits**, not cold misses. Both
Cloud Run keep-lists retain it; GKE PodMonitoring retains application counters
without a name keep-list, and isolated workers fold the counter across exits.

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1: The GKE worker endpoint does not expose privacy_negative_lookup_total, so PodMonitoring cannot provide the all-plane shadow-hit denominator claimed here. Register the privacy collectors in the worker’s custom registry (and verify the parent aggregation) before treating worker coverage as qualification evidence.

Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. When an issue isn't valid or won't be fixed in this PR, reply in its thread with the reason and then resolve the thread. At backend/docs/runbooks/privacy-check-shadow.md, line 110:

<comment>The GKE worker endpoint does not expose `privacy_negative_lookup_total`, so PodMonitoring cannot provide the all-plane shadow-hit denominator claimed here. Register the privacy collectors in the worker’s custom registry (and verify the parent aggregation) before treating worker coverage as qualification evidence.</comment>

<file context>
@@ -80,6 +80,48 @@ overrides can only shorten that ceiling. Rollouts use the declared reader levers
+candidate NOT_FOUND; a live document is always a mismatch, even within TTL.
+The denominator for qualification is shadow **hits**, not cold misses. Both
+Cloud Run keep-lists retain it; GKE PodMonitoring retains application counters
+without a name keep-list, and isolated workers fold the counter across exits.
+
+Proposed ramp after the lead verifies writer-fence coverage on every plane:
</file context>

@Git-on-my-level
Git-on-my-level merged commit db1af51 into main Nov 6, 2026
63 checks passed
@Git-on-my-level
Git-on-my-level deleted the lane/pipeline-negcache branch November 6, 2026 06:27
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