Repository navigation
fix(conversations-v3): load a heavy owner's closure by claims, bounded by size (v3_derived_budget) - #25753
Merged
Conversation
…d by size (v3_derived_budget) load() parked owners on v3_derived_budget for good: the closure ran a +/-20 min time query around every loaded recording, settled ones included, so it chained through the owner's contiguous day, and one pending recording can be owned by hundreds of back-to-back sub-minute windows. Both pushed the closure past LIMIT=128 on every retry. - A loaded recording's claimants are read exactly, by id from its claims. - The time query runs only for sources that can still be replanned: pending ones, ones an open window holds, and ones with speech but no claims. Settled neighbours no longer chain. - The bound is DERIVED_LIMIT=1024 rows plus DERIVED_BYTES=16 MiB of stored speech, instead of 128 rows. LIMIT stays for the round bound and the backfill partition. Failure-Class: FC-cap-bound-pins-owner-without-release-path Co-Authored-By: Claude Opus 5.5 <[email protected]>
…env levers (panel) - Refuse before reading when the claimed ids alone overflow the row budget, and read claimants in chunks of 100 so a byte overflow stops early (F1, F4). - Commit batches also split on documents written (rows + source updates + lease <= 450), under Firestore's 500-write commit cap now that a closure can hold hundreds of short windows (F2). - CONVERSATIONS_V3_DERIVED_LIMIT / CONVERSATIONS_V3_DERIVED_BYTES tune the bounds, and CONVERSATIONS_V3_CLOSURE_BY_CLAIMS=off restores the time query around every source (F3). Failure-Class: FC-cap-bound-pins-owner-without-release-path Co-Authored-By: Claude Opus 5.5 <[email protected]>
…oaded sources (panel 2) - The row and byte budget is checked as each derived row is added, and the time query is consumed lazily, so an overflowing closure stops reading and decoding at the bound (F1). - A closure holding more than SOURCE_LIMIT=400 sources raises v3_source_closure_budget: every commit batch rewrites each loaded source, so more than ~500 sources could never fit one transaction (F3). - The lever comment says what changing it costs: an env edit rolls a new revision (F4). Failure-Class: FC-cap-bound-pins-owner-without-release-path Co-Authored-By: Claude Opus 5.5 <[email protected]>
…rive deletes in the write cap (panel 3) - Source reads are bounded before they happen, and missing ids count and are not re-read each round (F3). SOURCE_LIMIT is env-tunable like the other bounds (F2). - The commit batch write cap also reserves a re-derive's deletes (F4, F9). - Replacing a loaded row adjusts the byte count instead of keeping the first size (F6). Failure-Class: FC-cap-bound-pins-owner-without-release-path Co-Authored-By: Claude Opus 5.5 <[email protected]>
This was referenced Nov 19, 2026
Git-on-my-level
added a commit
that referenced
this pull request
Nov 19, 2026
## DESIGN:
- **Reads.** Unchanged. The change is in the pure planner
(`outline.stretches`, `planner.preserve_finished_windows`). It adds no
query, document read or transaction round trip.
- **Writes.** Unchanged per pass. Each committed pass writes the same
rows and source claims it would have written. Parked owners commit
again, so their backlog drains through the existing paths.
- About 41 owners' builders resume after deploy.
- Their `v3_pending` backlog is bounded by what is there now: at most
200 pending sources per owner, read 32 per pass.
- **Cost.** No new model calls per pass. The one exception: an earlier
stretch that a backlog page's continuation held open now gets its single
outline call on this pass, the same call it would get once the
continuation clears. Earlier fragments of a split open window now finish
on the pass that splits it instead of when the stretch goes quiet. They
are the same fragments and get the same notes as before, only earlier.
The backlog the parked owners were owed was already counted. Nothing new
is admitted.
- **Production number that proves it.** `READBACK:` Builder leases
parked with `v3_blocked_reason=multiple_open_conversations` drop to
about 0 within 1 h of serving. Today's count is 41 at 17:2xZ, among the
483 owners holding `v3_pending` sources. The
`omi_conversations_v3_blocked_total{reason="multiple_open_conversations"}`
rate also stays at about 0. On b45a0c9 the log shows a median of 88
events per full hour, with 364 owners blocked at least once since
2026-11-18T21:44Z.
## Summary
`commit_projection` refuses a plan with more than one in-progress row
(`backend/database/conversations_v3.py:545-547`,
`Conflict('multiple_open_conversations')`). The reconcile parks the
owner (`service.py:46`, `BLOCKED`), backs off 5 min to 1 h, then replans
the same inputs. The plan comes out the same every time, so the park
never self-heals and the owner's Home freezes.
### Measurement (prod, read-only)
Tiers: `ro-prod` for logs, `prod-operator` for Firestore REST metadata.
In-process replay: every writer was stubbed and every Firestore write
method raised. `ENCRYPTION_SECRET` was held in memory only. Uids were
hashed in-process; no transcripts, titles or summaries were printed.
- **Logs.** 1,774 `v3 reconcile blocked
reason=multiple_open_conversations` events from 364 distinct owner tags,
all on backend-sync. The first was at 2026-11-18T21:44Z, the all-users
stage, and events occurred every hour after that. The problem predates
the 16:16Z deploy of #25764 and #25753.
- **Leases.** 41 parked owners. `v3_blocked_count` distribution: 1 (9
owners), 2 (12), 3 (1), 4 (4), 5 (4), and 16-28 (14). The 14 long-parked
owners all have more than 32 pending sources.
- **Sources.**
- Every parked owner has a single capture device and source `omi`.
- Not one source carries a rotation stamp, and only one carries
`v3_manual_end`.
- 34 of 41 owners have no stored in-progress derived row, so both open
rows are new windows in the same plan.
- **Replay of one live pass per owner on main.** It found three shapes,
each ending in two or more unfinished planned windows:
| Shape | Owners (of 41) | Example |
|---|---|---|
| **Preserve split.** One open window is cut around retained finished
rows' lines into 2 to 74 open fresh fragments | 15 | A live stretch with
interleaved capture became 74 open fragments |
| **Page continuation.** A backlog page's continuation marker holds
every stretch ending in the page's latest recording open | 5 | Two or
three stretches that ended 10 to 20 h ago, all open |
| **Future-dated speech.** Stretches ending up to 2 h in the future stay
open across recorded silence | 5 | Four open stretches, ending at -3,
+47, +93 and +131 min |
| Already at one or no open window (the plan changed since parking; it
commits on its next pass) | 16 | |
A second replay on the deployed b45a0c9 code, about 40 minutes later,
found 25 of the 41 owners still planning more than one open window.
### Root cause
1. **Preserve split.** `planner.preserve_finished_windows`
(`planner.py:482-485` on main) flushes the unmatched lines before each
retained row's line as a fresh window built from `{**window}`. Only a
manual stretch or its after-cut continuation
(`_keep_unmatched_together`, #25764) keeps them together. That path is
unchanged here. Every fragment of an open window inherits
`finished=False`, so a live stretch that contains published speech
(interleaved or late-synced capture, an on-open chapter, a backlog page
held open) plans one open window per gap.
2. **Continuation and future speech.** `outline.stretches`
(`outline.py:137-141` on main) computes `finished` per stretch from `now
- end >= SILENCE` and the continuation marker. A continuation marker on
the page's latest recording holds open every stretch whose last line is
in that recording. Speech stamped in the future is never 5 minutes old.
Both cases ignore the fact that a later stretch exists, and a later
stretch begins only after recorded silence or a manual cut
(`outline.py:121-131`).
### Fix
- `outline.stretches`: every stretch but the last is finished. Only the
last stretch can still be held open, by recency, page continuation or a
pending manual state.
- `preserve_finished_windows`: an open window splits around retained
rows exactly as a finished window does, with the same fragments, lines
and time matching. Only the last fragment keeps the window's open state;
published speech follows every earlier fragment, so none of them can be
the open edge. Those fragments are the same ones the window would
produce once its stretch goes quiet, so the end state is unchanged; they
just finish sooner.
- The first head (78b08e4) kept an open window's unmatched lines
together instead. The panel (F3) found that this widened the window's
time range across retained rows, so `service._match` could match a
deletion tombstone inside it and skip the whole open window. This head
drops that approach.
- Together these give at most one unfinished window per plan. Per group,
`planner.windows` and `_cohesive_groups` already leave only the last
part open. Retained windows are always finished.
What does not change:
- **Custody.** Fragments, their lines, ids and time matching are what
main produces; only `finished` differs. Retained rows keep their ids,
claims and audio. The open edge keeps the stored open row's id and
claims only unpublished audio. The test asserts all of this. The #25764
claim rules (no duplicate audio, earliest id kept) are untouched.
- **Healthy owners.** Finished windows are unchanged, and so is an open
window with a single fresh fragment, which is the shape that commits
today. The one behavioural change outside plans that cannot commit: a
backlog-continued stretch that was the only open one, but not the last
stretch, now finishes. A later stretch after recorded silence already
proves it ended.
No kill switch. Every changed plan except that one edge case is a plan
`commit_projection` refuses today. Rollback is a revert.
### Recovery (no manual unpark)
The parked owners recover on their own after deploy:
1. Their `v3_pending` markers are still owed, and the backoff expires
within 1 h.
2. The sweeper re-enqueues any owner whose pending sources are at least
10 minutes old.
3. The final batch of a successful commit clears `v3_blocked_count`,
`v3_blocked_reason` and `v3_backoff_until` (`conversations_v3.py:698`).
Replaying the fixed code against the same 41 owners runs the real
`commit_projection` against an in-memory copy of each closure (all
writers stubbed, reads from prod). Replay of head 3db0387
(~18:45-19:30Z), on the 41 owners parked at 17:20Z:
- 39 commit: 29 with exactly one open row and 10 with none. Planned rows
per owner were p50 22 and max 477.
- 2 raised `target_exists`, because a real pass committed for those
owners during the replay. Both leases were already cleared in prod, and
re-running the replay committed each with one open row.
Recount at 19:25Z: 57 owners parked, 22 of them from the 17:20Z set and
35 new. On the deployed code, 25 of the 35 new owners already plan at
most one open window, so they are transient parks that recover after
backoff; the other 10 are preserve splits. The same replay of the fix on
all 35 new owners: all 35 commit, 11 with one open row and 24 with none.
To unpark without waiting for the backoff, an operator deletes the three
fields on `users/{uid}/conversation_v3_leases/builder`, as the runbook
describes. That is not needed here.
### Out of scope, noted
- **Future-dated speech.** Six parked owners have segments stamped up to
about 2 h ahead of the server clock. This PR keeps them committing:
their last stretch stays open until real time passes its end. The clock
or offset source is a separate bug.
- **#25794 (v3-lock-merge).** It edits the same `finished` line, adding
`lock_delay`. With `lock_delay > silence_gap`, several unlocked
stretches would be open at once, and the commit refuses that. Whichever
PR lands second has to keep the rule that only the last stretch is open.
## Tests
- `test_published_speech_inside_an_open_stretch_leaves_one_open_window`:
a published row and a stored open row, then late capture around and
inside the published row. Red on main (three open fragments). Green
here, with these properties:
- exactly one open row, holding the latest line;
- no line lost;
- the stored open row's id is kept;
- the retained row's claims and audio are unchanged;
- the open edge claims only unpublished audio.
- `test_only_the_last_stretch_stays_open`: page continuation and
future-dated speech, plus the cohesion windows. Red on main, green here.
- All 21 v3 suite files pass, 486 tests: `test_conversations_v3_*`,
`test_listen_v3_*`, record-close and batch-projection admission.
- The changed-file selector (`bash test.sh` via `omi-heavy`) picked 152
files, the same set CI runs, and 7,038 tests passed. One file failed
only the local 1.00 s CPU guard:
`test_conversation_processing_retryable_timeout.py`, on the
`/v1/conversations` OpenAPI case at 1.14 s. That is the same known local
guard hit recorded on #25764, and this change does not touch it.
## Panel triage
Panel review-20261119t180246-a22d returned SHIP on 78b08e4 (luna,
deepseek and glm-flash all completed).
- F1, accept: the test now stores the previous pass's open row and
asserts the open edge keeps its id.
- F2, reject: only one open stretch can commit. Holding a current
stretch open next to a future-dated later one is exactly the two-open
plan that parks the owner. Finishing it risks at most one split when
future-stamped data exists, and no speech is lost. The future clock is a
separate data bug, noted above.
- F3, accept: fixed by dropping keep-together. An open window now splits
exactly like a finished one, with only the last fragment open.
- F4, accept: the test asserts the retained row's claims and recording
pieces.
Panel review-20261119t184151-fa1e returned FIX-FIRST on the final head
3db0387 (luna, deepseek and glm-flash all completed). No code
changed after it.
- F1, reject: the reviewer misread the test. Line 75-85 is the synced
recording, unowned and sitting between the owned 60-70 and 90-100, so
the plan is four windows. The test passes on this head.
- F2, accept: the replay of this head is filled in above.
- F3, reject: the after-manual-end continuation keeps its lines together
under #25764's rule. That is one fragment, so at most one open edge. The
behaviour is pre-existing and unchanged, and the wording above now names
it.
- F4, reject: deliberate. A single open fragment commits today, so it
stays as on main.
- F5, reject for this PR: the `_match` tombstone rule is the same as for
a single-fragment plan on main. It is a candidate follow-up: prefer an
in-progress prior over a tombstone.
- F6, accept: the cost line above is corrected.
## Product invariants affected
none
## Failure class (fixes)
Failure-Class: none
🤖 Generated with [Claude Code](https://claude.com/claude-code)
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.
Summary
v3 owners parked on
v3_blocked_reason=v3_derived_budgetnever recover. At 03:53Z, 69 builder leases carried that reason; the brief counted 12 at 03:51Z and 3 at 22:51Z.load()raisedConflict('v3_derived_budget')once the derived rows in the closure passedLIMIT = 128(backend/database/conversations_v3.py:278-297before this change). The owner backs off for up to an hour, retries, and fails the same way, while its history keeps growing.Root cause (measured)
I replayed
load()'s closure for all 69 parked owners using metadata-only prod reads (prod-operator tier). The reads covered timestamps, ids, claims and status, never transcripts or titles, and every owner was hashed.There are two drivers:
home_hidden(below_word_minimum78%,media16%). Every one of those rows owns lines of the pending recording, so a replan legitimately needs all of them; no row-count bound near 128 can hold this. Why the planner fragments speech this way is a separate bug, noted below and not fixed here.Fix
Claimants are loaded exactly, by id. Each loaded recording's
claimsnames the rows that own its lines, and those rows are read with oneget_all. This is whatpreserve_finished_windowskeys ownership on, so a replan still sees every owner of every line it plans.The time query runs only for sources that can still be replanned:
in_progress) window holds;A settled neighbour's lines all belong to the rows its claims name, so the closure no longer chains through it.
The bound is size-aware:
DERIVED_LIMIT = 1024rows plusDERIVED_BYTES = 16 MiBof stored transcript in the loaded rows. It replaces the 128-row count.LIMITstill bounds the rounds loop and the backfill partition (load_derive), and neither of those changes.Reads and writes stay bounded.
SOURCE_LIMIT = 400sources raisesv3_source_closure_budget. This is checked before the reads, and missing ids count toward it.Levers.
CONVERSATIONS_V3_DERIVED_LIMIT,CONVERSATIONS_V3_DERIVED_BYTESandCONVERSATIONS_V3_SOURCE_LIMITtune the bounds, andCONVERSATIONS_V3_CLOSURE_BY_CLAIMS=offrestores the time query around every source. They are unset in the runtime env manifest, so the code defaults apply.backend/deploy/runtime_env/_base.yamlentry for the reconcile services, regenerated withcompose_runtime_env.py. That is a config change, not a code change.CONVERSATIONS_V3_CLOSURE_BY_CLAIMS=offtogether withCONVERSATIONS_V3_DERIVED_LIMIT=128. The kill switch alone keeps the 1024-row bound.Replaying the patched closure on the same 69 owners (prod, counts only) gives:
All 69 owners fit under 1024 rows; the largest needs 447. Distinct sources per closure: p50 27, p90 44, max 74 (main: max 125), all under
SOURCE_LIMIT = 400. The replay did not count missing source ids. The byte budget was not measured against prod, because transcripts are not read.Recovery
No migration or manual unpark is needed. The
v3_pendingmarkers are still owed and the backoff is at most one hour. After deploy, the sweeper wakes each owner,load()fits, and the commit clearsv3_blocked_*, so parked owners should recover within about an hour plus one sweep.When could a recovered owner park again?
With this PR the closure no longer accumulates across settled recordings. It holds:
So it grows only while a single recording keeps fragmenting. At the heaviest measured rate (447 windows in about 2.5 h of one recording, roughly 180 per hour), reaching 1024 rows would take one recording of about 5.7 h. Recordings measured here were at most about 2.5 h. If an owner does re-park, raise
CONVERSATIONS_V3_DERIVED_LIMIT; the lasting fix is the fragmentation follow-up below.Not in this PR (follow-ups)
below_word_minimum, so on Home that speech is effectively not shown. A likely path is lines that land just outside a finished owner's[started_at, finished_at]inpreserve_finished_windows, so each becomes a fresh one-line window. This needs a planner investigation, and it is what makes closures grow by around 180 rows per hour for the heaviest owner.source_changed, retried in 1 min) more often than at 128 rows. The lasting fix is to fence only the rows a batch writes, or to skip unchanged retained rows; it belongs with S5.commit_projectionstill reads every loaded source and row sequentially inside each batch transaction. A closure of several hundred rows makes that transaction longer (S5).Tests
backend/tests/unit/test_conversations_v3_derived_budget.pyuses synthetic data:450 back-to-back windows owning one pending recording load.
Settled neighbours don't chain.
Every claimant of a loaded recording is loaded by id.
An open window's settled source still queries its neighbours, which preserves the old behaviour.
The row and byte bounds still raise
v3_derived_budget.The kill switch restores the old chaining.
Over-budget claim ids are refused before any read.
Claimants are read in chunks.
Commit batches stay under the write cap.
An overflowing closure stops decoding at the bound.
Sources are bounded before any read.
The write cap covers re-derive deletes.
All 416
tests/unit/test_conversations_v3_*.pytests pass locally.Panel
review-20261119t045831-3d98(luna and glm-flash finished; deepseek timed out) raised 4 findings; all 4 are accepted and fixed in 2373ca1.review-20261119t055525-3503on 2373ca1 (luna and glm-flash; deepseek timed out) raised 4 findings; all 4 are accepted and fixed in 19b5034.review-20261119t063249-cdc3on 19b5034 (all three models finished) raised 9 findings: 7 accepted, fixed in 48faaa5, and 2 rejected.SOURCE_LIMITis env-tunable and checked before reading.review-20261119t070714-e112on the final head 48faaa5 (luna and glm-flash; deepseek returned empty) raised 6 findings: 4 accepted and 2 rejected.Failure-Class: FC-cap-bound-pins-owner-without-release-path
🤖 Generated with Claude Code