Skip to content

feat(memory): WQ5 index-window + WQ6 mcp-cards + WQ7 canonical-statuses levers (all default-off) - #22856

Merged
Git-on-my-level merged 19 commits into
mainfrom
lane/firestore-reads-wq5-6-7-stack
Oct 20, 2026
Merged

Git-on-my-level merged 19 commits into
mainfrom
lane/firestore-reads-wq5-6-7-stack

Conversation

@Git-on-my-level

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

Copy link
Copy Markdown
Member

Summary

Firestore reads loop WQ6+WQ7 slices stacked on the WQ5 index-window branch, all behind default-off FIRESTORE_READ_LEVERS levers (absent key = off; no config change in this PR):

  • mcp_conversation_cards_cache (WQ6, exec-cherry-broom-lawsuit-begin-opinion-track): missing-slot refills + FSR_MCP_CARDS_MAX_READS cap in backend/database/mcp_conversation_pages.py.
  • canonical_statuses_dedupe (WQ7, exec-peanut-purity-maximum-treat-hold-december): missing-pair status lookups via <=30-ID __name__ IN queries in backend/utils/memory/memory_service.py.
  • Both KNOWN_LEVERS registrations included; serving-query driver entry for _canonical_statuses_by_query (queue order matches per-combo consumption; 31-ID split boundary covered).

Product invariants affected

  • INV-MEM-1 — memory list surface: index-window merge, cursor fallback and canonical-head emission follow the memory-tiers authority rules (canonical wins identity; historical suppression preserved; worst case equals lever-off).
  • INV-MEM-3 — memory status authority: WQ7 dedupe preserves the canonical-then-override decision table for all four callers (present item wins; override only for missing; unparseable present authority = 503).
  • INV-MEM-4 — dark code paths: every lever defaults off and off-path behavior is byte-identical to main.
  • INV-DATA-1 — reads-only changes; no writes, routing or ownership change.

Test plan

  • wq6 129 focused tests + wq7 185 focused tests (sol runs); stacked tree: 39/39 slice tests + 486/486 test_firestore_query_shapes.py on 53861a3.

Rollout

  1. Merge is dark; enablement is a later config PR at 5% after train + baseline.
  2. zcode glm-5.3 review (exec-era-iron-two-engage-between-alter) recorded in this PR body before merge.

Line-Count-Exception: backend/database/memories.py | 1873 -> 1929 | WQ5 index-window storage seam (window fetch + keyset compile); split deferred to the enable PR
Line-Count-Exception: backend/utils/memory/memory_service.py | 4535 -> 4692 | WQ5 merge seam + WQ7 _canonical_statuses_by_query + review fixes; split deferred to the enable PR

Failure-Class: new

View guided diff Turn on auto-fix

…ery dedupe (default-off levers)

WQ6 (exec-cherry-broom-lawsuit-begin-opinion-track): mcp_conversation_cards_cache —
missing-slot refills, FSR_MCP_CARDS_MAX_READS cap, 400 on oversized offsets; 129 tests.
WQ7 (exec-peanut-purity-maximum-treat-hold-december): canonical_statuses_dedupe —
missing pairs via <=30-ID __name__ IN queries over both owner collections; 185 tests.
Integrator: serving-query driver entry for _canonical_statuses_by_query (39/39 stacked
tests + query-shapes suite on this commit); KNOWN_LEVERS registrations included.
…tion

The FIFO queue is shared across both collection queries, so rows must be queued
per the combo's actual ID count (1 vs 31) and batch split (30+1); the earlier
fixed script left rows unconsumed or starved the overrides read (503). Also use
valid MemoryItemStatus values in fixture payloads. Single driver now runs 22
shapes with 0 errors.
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 20, 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-10-20T12:29:14.316114Z 1952325 PR opened
ℹ️ 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.

@chatgpt-codex-connector chatgpt-codex-connector 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.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 195232545e

ℹ️ 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".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment on lines +3104 to +3108
sort_key = (
window_sort_key
if firestore_read_levers.lever_enabled('memory_list_index_window', uid)
else self.memory_cursor_sort_key
)

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 Badge Preserve exact cursors when disabling the window lever

When memory_list_index_window is reduced or disabled while a client is paginating, a cursor minted by the enabled path is resumed using memory_cursor_sort_key and the legacy historical reader. That reader ignores index_window_cursor and reconstructs its Firestore bookmark from the outer microsecond-only keyset, so with nanosecond Firestore timestamps it can jump past unseen rows between the exact boundary and its truncated timestamp. Select the exact path based on the cursor contents, not only the current rollout decision, or reject such cursors rather than silently omitting memories.

Useful? React with 👍 / 👎.

…f the repo

The base_query submodule import breaks under the CI unit-suite stub
(ModuleNotFoundError: google.cloud.firestore_v1.base_query), which failed all
six Backend unit shards on #22856. Same symbol, same usage.
@Git-on-my-level
Git-on-my-level merged commit 45e71a7 into main Oct 20, 2026
59 checks passed
@Git-on-my-level
Git-on-my-level deleted the lane/firestore-reads-wq5-6-7-stack branch October 20, 2026 14:33
Git-on-my-level added a commit that referenced this pull request Oct 21, 2026
…versation_cards_cache, canonical_statuses_dedupe) (#23035)

## Summary

Firestore reads loop config: enable the three merged-but-dark memory
levers (#22856) at **5%** each. All other 13 keys unchanged from the
served flag-off literal (18f90e1, train K
`backend-f162bdb-39590246432-1` / listen 0bbf473 / pusher f162bdb):

- `memory_list_index_window` 0 → 5: caps per-request index-window reads
in memories list streams via caller-carried opaque cursor; invalid
cursor falls back to legacy behavior.
- `mcp_conversation_cards_cache` 0 → 5: mcp conversation cards
exact-size refills with read cap (`FSR_MCP_CARDS_MAX_READS`, default
1501).
- `canonical_statuses_dedupe` 0 → 5: canonical-status pairs read via
`<=30`-ID `__name__ IN` reference queries instead of two full-collection
status reads.

Predicted (levers.json, measured at 100% equivalents 10-20, snapshot
2026-10-21T11:00:46Z origins):
`memories:_stream_memory_list_index_window`,
`mcp_conversation_pages:get_mcp_conversation_cards`,
`memory_service:canonical_statuses` — per-caller reads to be measured by
the ramp readout; per-loop rules the 5% window is observational (guard +
expected-signal check), no savings claimed until 100% + readout.

Rationale: #22856 served yesterday inside train windows with the three
keys absent (= OFF per `firestore_read_levers.py`), so the levers are
merged-but-dark (runbook 2026-10-20 lesson: merged-but-dark is not
progress). One config change in flight per loop phase rules;
`singleton_loops` 25 → 100 stays deferred pending the lease-rework
evidence (WQ1).

Config only, generated with `avo/firestore-reads/set_levers.py`
(REPLACE-mode, complete 16-key literal at all sites): `_base.yaml` +
regenerated `runtime_env.yaml`, listen/pusher dev+prod values, flag
registry, and the two pinned contract tests (121 passed locally).

## Product invariants affected

- INV-MEM-4 — config-only rollout of default-off code-path levers; every
lever reverts at 0 with no data-path or authority change.
- INV-DATA-1 — value-only edit of the existing `FIRESTORE_READ_LEVERS`
key; no routing or ownership change.

## Test plan

- `backend/tests/unit/test_verify_pusher_config_references.py` +
`backend/tests/unit/test_render_backend_runtime_env.py`: 121 passed on
this branch.
- Post-merge watch: verify.py per-lever gates + backend/backend-sync 5xx
rates at the 5% cohort (no lever-specific guard exemption requested).

## Rollout

1. Train order **listen → pusher → Cloud Run** (FIRESTORE_READ_LEVERS
order; Cloud Run candidate check compares GKE env against main's
runtime_env).
2. Handoff to the two-lane lead via bus after merge (URGENT not required
— no guard breach); ramp clock starts at the served revision carrying
this literal.
3. Ramp rule: 5% ≥ 3h with verify PASS (no lever UNSAFE/FALSIFIED) →
config PR to 100% for SUPPORTED levers; 0 for FALSIFIED/UNSAFE.


<!-- This is an auto-generated description by cubic. -->
<a
href="https://cubic.dev/pr/BasedHardware/omi/pull/23035?utm_source=github"
target="_blank" rel="noopener noreferrer"
data-no-image-dialog="true"><picture><source
media="(prefers-color-scheme: dark)"
srcset="https://www.cubic.dev/buttons/review-in-cubic-dark.svg"><source
media="(prefers-color-scheme: light)"
srcset="https://www.cubic.dev/buttons/review-in-cubic-light.svg"><img
alt="View guided diff"
src="https://www.cubic.dev/buttons/review-in-cubic-light.svg"></picture></a>
<a
href="https://www.cubic.dev/action/auto-fix/pr/BasedHardware/omi/23035?returnTo=https%3A%2F%2Fgithub.com%2FBasedHardware%2Fomi%2Fpull%2F23035&source=description"
target="_blank" rel="noopener noreferrer"
data-no-image-dialog="true"><picture><source
media="(prefers-color-scheme: dark)"
srcset="https://www.cubic.dev/buttons/turn-on-auto-fix-dark.svg"><source
media="(prefers-color-scheme: light)"
srcset="https://www.cubic.dev/buttons/turn-on-auto-fix-light.svg"><img
alt="Turn on auto-fix"
src="https://www.cubic.dev/buttons/turn-on-auto-fix-light.svg"></picture></a>
<!-- End of auto-generated description by cubic. -->
tivince82 pushed a commit to tivince82/omi that referenced this pull request Oct 21, 2026
…versation_cards_cache, canonical_statuses_dedupe)

Firestore reads loop: BasedHardware#22856 landed with the three memory levers absent
from FIRESTORE_READ_LEVERS (= OFF per default). Turn them on at the
observational 5% cohort; all other keys unchanged from the served
flag-off literal (18f90e1). set_levers.py replace-mode, complete
16-key literal; contract tests 121 green.

Loop: firestore-reads; ramp clock starts at the served revision.
Git-on-my-level added a commit that referenced this pull request Oct 22, 2026
…imeouts) (#23310)

## Summary

Ramp `memory_list_index_window` 5 -> 25 in `FIRESTORE_READ_LEVERS`.
Complete 16-key literal, every other key unchanged; same 9-file surface
as the precedent 5% enable (7d3e0a0):
backend/deploy/runtime_env.yaml + _base.yaml, backend-listen/pusher
chart values (dev+prod), feature-flag-registry.md, and the two fixture
files.

## Why

Mobile clients load the Memories page with a 10s read budget
(`ReadRetry.callerWindow`, `app/lib/backend/http/read_retry.dart`). Prod
`GET /v3/memories` (cloud_run/backend, rev 6f411f0) measured
2026-10-21T14:00Z→10-22T14:06Z: p50 0.8s but p99 17.4s, 26 walks past
24s, plus 55 fast 503s — every hour had slow walks, so large accounts
regularly blow the client budget and the page never loads. PostHog
`Product Error` `error_kind=memories_fetch`: ~450 distinct reporters
over 7 days (build-dependent emission; older builds only log to
Crashlytics, so this is a floor).

The lever (bounded index-window reads for the legacy list, #22856) has
served at the observational 5% cohort since 7d3e0a0 with no adverse
signal, and the FSL-F1 `retry=None` deadline blocker is fixed at the
serving rev. This is one runbook step per
`backend/docs/runbooks/list-read-serving.md`: compare list latency,
504/500 counts, and truncation rate on large accounts after the roll;
rollback is the same literal at 5.

## Ramp plan (dated expansion checkpoint)

- **Now:** 25% on the next Cloud Run train (lead-owned).
- **Soak gate:** 48h clean — the runbook comparison (GET /v3/memories
list latency p95/p99, 504/500 counts, truncation rate on large accounts)
vs the pre-roll baseline, run by the hermes lane and posted to the
firestore-reads loop.
- **Expand:** if clean, a follow-up config PR (same 9-file surface)
raises the lever to 100, merged + trained by **2026-10-27**. Same
rollback (literal back to 25/5).
- **If the gate trips:** hold at 25%, post findings to the loop, no
expansion without a re-review.
- Owner of the expansion clock: hermes lane (this PR's author); the lead
owns the merge/train.

## Deploy

Config-only; needs the merged SHA on a Cloud Run `backend` train
(lead-owned). ~13% of users move into bounded window reads (per-uid
sha256 bucket); rollback = revert this PR or re-render the literal at 5.

## Product invariants affected

- INV-MEM-4
([`product/invariants/memory-promotion-authority.md`](../../product/invariants/memory-promotion-authority.md)):
Canonical promotion is the sole Long-term authority. All new canonical
intake starts in Short-term, one consolidation decision gives every
pending item exactly one terminal route, and only an atomically
receipted, graph-backed promotion may admit an item to Long-term.
Default access collapses canonical lineage, while keyword, vector,
compatibility, and shared-graph projections remain retryable derived
views.

This change is in the invariant's path globs only via
`backend/deploy/runtime_env.yaml`; it raises a read-path rollout
percentage for the bounded index-window list scan
(`memory_list_index_window` 5 -> 25). It creates no intake route, no
promotion pass, no second visibility authority, and no projection-state
treatment — the window read applies the unchanged row policy and merge
rules per `backend/docs/runbooks/list-read-serving.md`.

## Failure-Class

Failure-Class: none
kriegcloud pushed a commit to kriegcloud/omi that referenced this pull request Oct 22, 2026
…imeouts)

Mobile clients load the Memories page with a 10s read budget
(ReadRetry.callerWindow, app/lib/backend/http/read_retry.dart). Prod
GET /v3/memories runs p50 0.8s but p99 17.4s with 26 walks past 24s in
the last 24h, so large-account first pages time out client-side and the
page never loads; PostHog Product Error error_kind=memories_fetch shows
~450 distinct reporters over 7 days. The scan-reduction lever
memory_list_index_window (bounded index-window reads for the legacy
list, BasedHardware#22856) has been merged and observed at the 5% cohort since
7d3e0a0 with no adverse signal, and the list-read-serving runbook
step (compare list latency, 504/500 counts, truncation rate on large
accounts) is this ramp's evidence gate. Raise it one step to 25%; all
other 15 keys unchanged. Rollback is the same literal at 5.

set_levers.py-style replace-mode edit, complete 16-key literal;
contract tests green (test_render_backend_runtime_env,
test_verify_pusher_config_references, test_check_cloud_run_env_drift,
test_backend_runtime_env_validator: 271 passed).

Loop: firestore-reads; ramp continues to 100 after a clean soak at 25%.
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