Skip to content

SCA-4102: Index visible v3 Home conversations - #26204

Merged
Git-on-my-level merged 8 commits into
mainfrom
agent/multica-worker-1-codex-sol/63eaf8521505
Nov 24, 2026
Merged

Git-on-my-level merged 8 commits into
mainfrom
agent/multica-worker-1-codex-sol/63eaf8521505

Conversation

@Git-on-my-level

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

Copy link
Copy Markdown
Member

Changes

  • Persist home_list_visible on conversation creation, replacement and visibility changes. The collection index skips raw recordings and hidden v3 windows before fetching Home documents. Row visibility checks run after querying.
  • Negotiate Home pagination mode in the mobile client. Indexed continuations use a cursor bound to the indexed candidate set. A rollback restarts paging at page one.
  • Keep the read gate off by default. The per-owner backfill tool reports its scan scope, expected reads and writes, and retry ceiling before applying a reviewed plan.

First review fixes

  • Resolve the Firestore deletion sentinel when stamping a write so archive readers can load with the existing Firestore fixture.
  • Stamp processing results when they write recording or home_hidden. Preserve exact legacy payloads for other processing results.

Field collision fix

  • Give the indexed list its own stored field, composite index, and backfill. The compact feed owns home_visible.
  • Prepare the compact feed and verify that indexed pagination still follows the normal list predicate. Verify that a list visibility update preserves the feed flag.

Verification

The regression fixture covers a 1,200-row hidden run and equal timestamps. Each of the first two indexed pages reads 50 documents and returns 50 rows in order. On multica-worker-1, 420 targeted backend tests passed after the first review fixes, including the archive fixture and legacy write goldens. The preceding verification ran 25 targeted Flutter tests.

On M1 Studio, 365 targeted backend tests, all 56 preflight checks, and the bounded pre-push gate passed for e6e962f0fa.

Production remains gated until the index is ready, writers are deployed, and a scoped dry run and post-backfill reconciliation have been recorded. Confirm the 50-row budget with the production conversation_list_read meter on an updated mobile build.

UI-Evidence: none -- The mobile changes cover paging requests and responses.

Line-Count-Exception: app/lib/backend/http/api/conversations.dart | 1635 -> 1642 | The existing typed and legacy API entry points pass the negotiated Home mode.
Line-Count-Exception: app/lib/providers/conversation_provider.dart | 2510 -> 2526 | The provider owns the active paging mode and serializes restarts with its current page load.
Line-Count-Exception: backend/database/conversations.py | 5515 -> 5527 | The existing persistence and query entry points maintain the derived bit and isolate cursor scopes.
Line-Count-Exception: backend/database/firestore_index_registry.py | 2402 -> 2408 | The registry owns the generated composite index declaration.
Line-Count-Exception: backend/routers/conversations.py | 3111 -> 3126 | The list endpoint negotiates the mode and records the candidate set in its read meter.
Line-Count-Exception: backend/database/conversations_v3.py | 1500 -> 1502 | The existing v3 projection and donor transactions stamp Home visibility with their source flags.

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 24, 2026 •

Copy link
Copy Markdown
Codex Review Summary: ❌ Failed

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

Review Status Commit Review trigger
📝 Code Review ❌ Failed 2026-11-24T13:11:03.779772Z
We couldn’t complete this review. Comment @codex review to try again.
e6e962f 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.

@chatgpt-codex-connector

Copy link
Copy Markdown

You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard.
To continue using code reviews, add credits to your account and enable them for code reviews in your settings.

@Git-on-my-level
Git-on-my-level merged commit 4ff5502 into main Nov 24, 2026
78 checks passed
@Git-on-my-level
Git-on-my-level deleted the agent/multica-worker-1-codex-sol/63eaf8521505 branch November 24, 2026 16:16
Git-on-my-level added a commit that referenced this pull request Nov 29, 2026
…no backfill (#26684)

SCA-4102: v3 Home reads about one document per row for recent history,
with no backfill.

## Why

Home's first request (`GET /v1/conversations?limit=50`) is what users
wait on when they open the app. In ro-prod sampled request logs read
2026-11-29 01:24Z, it took 1.46 s at p50, 9.8 s at p90 and 24 s at p99.
Hidden v3 rows (raw recordings and hidden windows) make the legacy scan
read many more documents than it returns. SCA-4102 records about 550
documents per 50-row page on v3 accounts. #26204 added and stamped
`home_list_visible`, but rows written before those writers have no bit.
So the reader only admitted owners whose whole collection had been
backfilled, and none were.

## What changes

**Hybrid reader
(`database.conversations.get_home_hybrid_conversations`).** This follows
the no-backfill design approved on SCA-4102.
- On first use, each admitted owner gets a **cutoff**: the newest
`created_at` across all of their conversations. One descending probe
reads it, at limit 1 with a `created_at` field mask, and it is stored
once at `users/{uid}/home_list_index/cutoff`. Every row above the cutoff
was created or moved there by a stamping writer.
- A page reads `created_at > cutoff` through the index. When that slice
runs out, the rest of the page comes from the legacy scan, which starts
at the cutoff inclusive via `start_at`, not a range filter.
- Cursors bind the branch and the cutoff into their signed scope.
- The owner stays on legacy when the newest key is in the future, is not
a timestamp, or the lookup fails.
- A stored cutoff never moves. Two pods certifying at once keep the
first create.

**Route negotiation.** No app change is needed. The app already sends
`auto` on page one and repeats the server's answered mode afterwards.
- `auto` page one is served hybrid and answers `indexed`. `indexed` with
a valid cursor continues the hybrid read.
- These cases return page one and answer `legacy`, which makes the app
re-fetch from the top: an `auto` continuation (F3), a cursorless
`indexed` continuation, and a cursor from another cutoff or an expired
or tampered one.
- Released clients that send no header are unchanged.

**Controls.**
- `OMI_HOME_VISIBILITY_INDEX_ENABLED` is the kill switch, on unless set
off.
- The served cohort is `OMI_HOME_VISIBILITY_INDEX_OWNERS` plus
`OMI_HOME_VISIBILITY_INDEX_PERCENT`, which defaults to 0.
- `OMI_HOME_VISIBILITY_INDEX_AUDIT_PERCENT` (default 0) is the
production shadow. Legacy-served pages check each visible row above the
owner's cutoff for `home_list_visible == true`. A missing or false bit
is exactly a row the index would hide. The audit reads no extra rows;
certifying the cutoff costs one read and one write per owner, once.
- Metrics:
`omi_home_index_{cutoff,pages,storage_rows,audit_rows}_total`, plus
`home_branch` on the `conversation_list_read` log line. All are
aggregate counts with no ids or content.

**Writer fixes from the R42 triage of #26204.**
- F1 (separate field) was already fixed before #26204 merged.
- F2: `update_conversation` retries a fenced visibility patch up to 3
times, re-reading and restamping, instead of raising on a concurrent
write.
- F3: covered by the route negotiation above.
- F4: a test pins that a processing result with neither flag writes no
bit.
- New, from the writer audit: a `created_at` move now restamps in
`update_conversation` and in the processing-result write, but only when
the value actually changes. Unchanged results stay write-free.

**Writer audit.** Every production path that creates a conversation,
changes `recording` or `home_hidden`, or moves `created_at` either
stamps the bit or cannot change it. That covers Python request routes,
Cloud Tasks jobs, the v3 builder and rederive, sync assignment and Go
finalization. The only unstamped creators are staging, harness and
emulator seeders and one one-off timestamp migration. Those are listed
in the SCA-4102 comment.

## Ramp plan (default-off cohort)

The design requires a shadow and Margin GO before serving, so the served
cohort ships at 0.

1. **Audit.** Pipeline sets `AUDIT_PERCENT=100` once David approves the
one-time certification writes. Clean metric:
`omi_home_index_audit_rows_total{result!="ok"}` stays at 0 for a full
day. Done by 2026-12-05.
2. **Named owners, then percentage.** Release adds named owners (David
first), then ramps `PERCENT` through 1, 10, 50 and 100, one full
lookback per stage, after Margin GO under SCA-3891. Clean metric: the
audit stays at 0, `recent` pages read about 1 document per row, and list
p95 and 5xx are no worse than the legacy arm. Done by 2026-12-12.
3. **Rollback.** Set `OMI_HOME_VISIBILITY_INDEX_ENABLED=false`. Indexed
continuations restart at page one. Keep the stamps and the stored
cutoffs.

## Data and privacy

The cutoff document holds only a timestamp, the certification time and a
version. Account erasure already enumerates and deletes every
subcollection under `users/{uid}`. The bit stays in storage; the API's
response model drops it.

## Verification

Hermetic unit tests, run through `test.sh`:
- `test_home_hidden_run_pagination.py`: full walks show the hybrid read
serves exactly the legacy rows in order, for 5 shapes with and without
tied timestamps. The recent slice reads one document per row across
1,200 hidden rows. A page crossing the cutoff keeps rows tied at the
cutoff in the tail exactly once. Restart cases, the kill switch and the
audit are covered.
- `test_home_index_cutoff.py`: certification, memoization, refusals, the
concurrent-create race, cohorts, the F2 retry, and `created_at`
restamping.
- `test_conversation_terminal_family.py`: F4, and restamping only when
`created_at` actually moves.
- Contract suites: caller witnesses, query-shape registry, reason
labels, archive filter.

No production reads or writes, deploys or config changes were made in
this PR.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

## Product invariants affected

none

Line-Count-Exception: backend/database/conversations.py | 5681 -> 5841 |
the hybrid Home reader must share the private list collector, cursor
scope and page fill it extends; a split would duplicate that path or
widen private helpers
Line-Count-Exception: backend/routers/conversations.py | 3482 -> 3523 |
the Home page-mode negotiation lives with the list route it governs
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