Repository navigation
fix(conversations-v3): the live read skips open rows idle past the window cap - #25719
Merged
Merged
Conversation
…dle past the window cap GET /v1/conversations/live served the newest non-recording in_progress row. A capture that never closed keeps that status for days, so the v3 Home hid its capture card behind a stale row and filed it under its start date. The read now scans a bounded page and serves the first open row active inside the two-hour window cap.
…the router does not grow
Git-on-my-level
added a commit
that referenced
this pull request
Nov 18, 2026
) Failure-Class: FC-raw-page-limit-before-visibility-filter Co-Authored-By: Claude Opus 5.5 <[email protected]>
Git-on-my-level
added a commit
that referenced
this pull request
Nov 19, 2026
… v3 window; day view hides what Home hides (#25721) ## Summary A v3 smell audit (2026-11-18, prod at 9c88e7f, read-only, counts only) found that Home stops early for **48 of 648 v3-active owners (7.4%)**, leaving **37,540 visible rows** unreachable. It also found a stale legacy row showing as a live tile, and a day view that shows rows Home hides. This PR fixes all three on the server, for the TestFlight builds already shipped, without an app release. ### F1: Home stops at a run of hidden rows - **Cause, server side:** the indexed Home query (`discarded == False`) still matches `home_hidden` v3 windows and recordings, and readers drop them. Each page read at most 50 + `_RULE_DISCARD_PAGE_SKIP_CAP` = 64 rows. The cap counted every refill read, not only hidden rows. So a run of 64 or more hidden rows returned a short page. - **Cause, app side:** the app treats a page with fewer than 50 rows as the end (`conversation_provider.dart:986/1379`). The longest measured hidden run per owner is p99 93 and max 158. The product owner's run is 73 rows, so Home stopped after 16 rows. - **Released apps already read a storage cursor.** Since #24541 (2026-11-04), the app adds `X-Omi-Conversation-Page-Size` to its offset, and uses `>= 50` on that value for `hasMore` (`conversation_provider.dart:985-986`, `1378-1379`; `conversations.dart:199`; `conversation_home_list.dart:52`). The server only sent that header while it suppressed episode members. **Fix** - **One shared page fill** (`_PageFill`) for the offset and cursor paths: - Only hidden rows count against the cap. Visible rows never do. - Under a request budget (the Home route) the cap is now `_HIDDEN_ROW_PAGE_SKIP_CAP = 512`, so the longest measured run (158) fits about 3 times over. Readers without a budget (full-document internal callers of `get_conversations`) keep 64, so their worst case does not grow. - Refills start at the number of missing slots, then double. A long hidden run therefore costs a few RPCs, not one RPC per row. - The worst case is page + 512 rows, read with the list projection (no transcript blobs). That is far inside the existing 25,000-document request budget, which still charges every row. - **`/v1/conversations` now always sends `X-Omi-Conversation-Page-Size`**, set to the number of storage rows the page consumed. This is the amount the next `offset` must advance by. Released apps then: - **page past a hidden run:** the value is at least 50 even when the body is short; - **stop re-serving rows:** the next offset lands exactly after the last row read. - **Offset semantics are unchanged.** The offset still counts storage rows on the indexed path, so desktop and older clients that send their visible count behave as before: some rows are re-served (deduped by id), and none are skipped. Re-interpreting the offset as a visible count would need a scan of every hidden row before a deep offset, and would change desktop pagination, so I did not do it. The header carries the exact advance instead. `include_discarded=true` keeps its visible-row offset, and its header equals the page length. - **New `X-Omi-Has-More: true|false`.** It is `false` only when the scan reached the end of the query. A short page caused by the cap, or a page cut by the budget, says `true`. - **New optional `cursor` query parameter**, reusing the `conversation_list_cursor` lever code (100% on prod). With the lever on, the response carries `X-Omi-Next-Cursor`, and a cursor that decodes replaces the offset. A malformed cursor falls back to offset, as before. **The body is still a plain list.** OpenAPI and the generated TS and Swift clients are regenerated (one optional parameter added). ### F3: `/v1/conversations/live` showed a stale legacy row It returned the newest non-recording in-progress row. It did not require `v3_derived`. #25719 (merged while this PR was open) added a 2-hour idle cap in `utils/conversations/v3/live.py`. **Fix:** the route no longer scans the general list. It reads v3 windows through the existing `conversations_v3_derived_window` index (`v3_derived ASC, finished_at ASC, started_at ASC`), in the new `database/conversations_v3_live.recent_windows`: - Filters: `v3_derived == True`, `finished_at >= now - MAX_IDLE` (2 hours) and `started_at <= now + 5 min`. This is the same query shape `conversations_v3.py:284-288` already serves. - `.select()` reads only the fields the route returns plus the visibility flags. No transcript blobs are downloaded. - The index is ascending by `finished_at`, so the newest window comes last, and a read cannot stop early once it finds the open one. Reading newest-first would need a new descending index, which this PR does not add. The tile is polled every 15 seconds, so the read works in two bands instead: - **Recent band (last 10 minutes) first.** An open window's `finished_at` is its latest speech, so a speaking window is almost always here, and this band holds only a few rows. - **The rest of the 2-hour window only if the recent band has no live window**, for example an open window that has been quiet for a while. The two bands do not overlap (`finished_at < now - 10 min` on the wider one), so no row is read twice. - **One 200-row cap for each call, shared by both bands.** Reaching it is logged. - `v3_live.active` then returns the newest row that is `in_progress` with `tile_state == 'live'` and is not recording, `home_hidden`, deleted or discarded. A legacy in-progress row can never match, however new it is, and newer legacy rows can no longer push the open window out of a fixed-size scan. ### F2: the day view showed rows Home hides A date range turned off `hide_home`. **Decision: apply `hide_home` to a date-only filter**, rather than add a Home drill-in flag: - The day view is Home's own drill-in, so it should hide the same rows. - A new flag would need an app release and would not help the shipped builds. - Explicit reveal filters still show hidden rows: `include_discarded`, `sources`, `folder_id`, `starred` and non-default `statuses`. - `/v1/conversations/count` is unchanged. Its hidden-row subtraction with `hide_home` and a date range would need a new composite index, and the day page does not call it. ### Not in this PR (owned elsewhere) - The v3 `commit_projection`/reconcile size fix. - The sync intake `mark_new` fix. - F4, the live-tile clock: an app change, in #25725. ### Why the day-view change has no lever Hiding the same rows in the day view that Home hides ships on, with no read lever. This repo's rule is to ship on by default and to add a flag only for real risk to users, data or cost: - The change can only hide rows that Home already hides. - Every explicit reveal filter still shows them. - The response headers are additive. - If it proved wrong, the rollback is a one-line revert of `hide_home=not reveal`. ### Follow-up (deferred from review-20261119t003449-3d72) - Tell a deadline exhaustion (a retry can succeed) apart from a document exhaustion in `has_more`. - Guard `recent_windows` against a zero page size. It is unreachable today. - Document the client rule: `X-Omi-Has-More: true` with no cursor means fall back to offset paging. - Pass `max_idle` into `active()`. - A hidden-row run that ends exactly at the cap costs one extra empty request. ### Known limits (intended) - **A full page always says `X-Omi-Has-More: true`.** It does not probe for a next row. When the query ends exactly on a page boundary, the client makes one extra request and gets an empty page. A probe would charge every full page one more read to avoid that rare, harmless request. - **The budget can run out before any row is read**: on the offset charge, on the first read, or in the `include_discarded` scan. That page returns empty with `X-Omi-Has-More: false`, because there is no position to resume from and an identical retry would stop at the same place. - **Clients that ignore the headers still end on a short page.** A page cut at the 512 hidden-row cap is short but not final. Flutter Home reads the headers (#24541, #25725). The Flutter day view (`day_conversations_page.dart:133,159`) and web (`data.length === limit`) do not, so a date range holding more than 512 consecutive hidden rows still stops early there. The longest measured run is 158, and the follow-up is to have those views read `X-Omi-Has-More`. - **The app's incremental refresh** (`_fetchNewConversations`) still advanced by body length in the shipped build. #25725 makes it use the storage count. - **`/v1/conversations/count` with a date range** still counts hidden rows. Subtracting them needs a composite index that does not exist (see F2). For the record: macOS `ConversationRepository.swift:121-145` pairs a date-filtered list with a date-filtered count. A day view there can therefore show a count above the rows listed, until that index is added. ## App release needed? No. F1, F2 and F3 take effect for released and TestFlight builds as soon as this backend deploys. The cursor and `X-Omi-Has-More` headers are additive. Using them in Flutter is optional follow-up work. ## Test plan - New `backend/tests/unit/test_home_hidden_run_pagination.py`, synthetic rows only. It mirrors the app's paging loop (`offset += header`, `hasMore = header >= 50`): - 30 visible, then 150 hidden (`home_hidden` or recording), then 100 visible. Every visible row is reached exactly once, in order, and each page reads at most page + cap rows. - The first page is full and reports `storage_rows=200`. The next page starts exactly after it, with no re-served rows. - An app that ignores the header still reaches every row. - A run longer than the cap (cap patched to 64) returns a short page that still says `has_more` and keeps paging to the end. - End of the collection reports `has_more=false`. A budget cut keeps its prefix and says `has_more=true`. - A cursor walk across the run reaches every row. - Route: the headers are set, the cursor round-trips, and the body stays a list. - Day view: `hide_home` stays on for a date range alone and turns off for each reveal filter. - `test_conversations_v3_contract.py`, live route (#25719's cases kept, with v3 rows): - only an open, visible v3 window is returned; hidden, deleted, discarded, processing and recording rows are not; - a v3 window idle past the cap is not live; - when several qualify, the newest wins; - the read uses the v3 index filters and projection; - a speaking window among 100 recent finished ones is found with one recent-band read; - a window quiet for 30 minutes is found by widening to the full window; - the wider band excludes the recent one; - with nothing open, the cap is shared across both bands, and reaching it is logged with the bound that applied. - Updated: `test_fsr_wq4_cursor.py` (the cap counts hidden rows only) and `test_pending_bridge_read_budget.py`: - without a budget, the bound is page + 64; - with a budget, the bound is page + 512, reached in at most 5 RPCs with growing batches. - An offset charge that exhausts the budget returns `has_more: false` with no reads. - Firestore guard set passes locally (`test_firestore_query_shapes`, caller and runtime witnesses, index rules, query contract): - the driver registry covers `_PageFill._run`; - the cursor collector's entry and digest pin are removed, since it no longer streams a query itself; - the live route's old list caller witness and profile are removed, and `recent_windows` is a registered driver covered by the existing v3 window index. UI-Evidence: none -- only regenerated API client types change (one optional query parameter on the conversation list); no screen changes Line-Count-Exception: backend/database/conversations.py | 5257 -> 5292 | one shared hidden-row page fill replaces the two refill loops; its docstring states the storage-advance contract Line-Count-Exception: backend/routers/conversations.py | 2909 -> 2919 | optional cursor query parameter and page-header wiring; the helpers live in utils/conversations/list_page_headers.py and utils/conversations/v3/live.py and the live query in database/conversations_v3_live.py Failure-Class: FC-raw-page-limit-before-visibility-filter 🤖 Generated with [Claude Code](https://claude.com/claude-code)
This was referenced Nov 19, 2026
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.
Problem
On the v3 Home, an owner who is recording can see nothing in progress: no capture card and no live row.
GET /v1/conversations/liveserved the newest non-recordingin_progressrow as "the conversation in progress". A capture that never closed keeps that status for days. The app then:conversations_page.dart,deferStreamingToEpisode: episodeLive || v3Live != null);localHomeDay(v3Live.startedAt ?? v3Live.createdAt)), so it is not under Today.Reported by an owner on iOS 1.0.593 (1583) on 2026-11-18: the live read returned a row opened on 2026-11-14 while a pendant capture was running.
Prod, read-only, 2026-11-18 19:55Z:
in_progress.Change
get_live_conversation(rule inutils/conversations/v3/live.py) reads up to 10 open rows instead of 1 and serves the first non-recording row whose last activity (finished_at, elsestarted_at, elsecreated_at) is inside two hours, the v3 window cap. A stale open row is skipped. With no active row the response is{"v3": true, "conversation": null}and the client keeps its capture card.No flag: the old answer was wrong for every owner with a stale open row. No app change is needed.
Cost
One Firestore query per call as before; the page grows from 1 to at most 10 rows only for owners who have open rows.
Validation
tests/unit/test_conversations_v3_contract.py: 80 passed. Newtest_live_skips_a_capture_that_never_closedcovers a stale-only owner, a fresh open row behind a stale one and a recording, naive stored times, and a row with no time. It fails on main (the stale row is served).Not in this PR
Product invariants affected
none
Failure class (fixes)
Failure-Class: new
Failure-Class-Id: FC-nonterminal-status-read-as-live-activity