Repository navigation
Conversation
With stage_queues on, a summary's settle arms v3_memory_pending and a task on conversations-v3-memory extracts the memories. A marker whose task was gone (deliveries used on refusals, a purged queue, an instance that died before creating it) waited for the same owner's next summary; an owner who stopped recording kept the conversation without memories. The builder sweep now offers a task to every owed extraction past its due time (v3_memory_due_at: 15 minutes after the settle, moved on by every claim). One collection-group query of at most 500 rows a sweep, empty while extractions finish in time; each row read is moved on by 15 minutes, doubling up to 6 hours. The task keeps the hand-off's name, so a waiting task refuses the duplicate. New index conversations_v3_memory_due_sweep. Pipeline lab: queues can lose tasks (limits.<queue>.lose); scenario stage_queues_memory_task_lost. Failure-Class: none Co-Authored-By: Claude Fable 5.2 <[email protected]>
…n the shape guard due_memory took a caller-set limit, which the query-driver registry does not accept for a recurring cross-owner read: the page is the constant MEMORY_SWEEP_PAGE now. The builder sweep imports the memory stage inside its body, so the first shape capture of a process recorded the query with the wall clock and the export differed between two runs; the driver module loads the stage before a driver starts. Failure-Class: none Co-Authored-By: Claude Fable 5.2 <[email protected]>
… registry Failure-Class: none Co-Authored-By: Claude Fable 5.2 <[email protected]>
There was a problem hiding this comment.
9 issues found across 20 files
Confidence score: 3/5
- The sweep can silently recover nothing if
conversations_v3_memory_due_sweepis not READY first. Make the deploy prerequisite explicit inbackend/docs/listen_pusher_pipeline/changes/2026-11-30-v3-builder-stage-queues.md. - In
memory.py, a persistent_offerfailure leaves the marker due, so each sweep can read it again without respectingMEMORY_MAX_SWEEPS. Ensure the failure path advances or otherwise limits retries. backend/testing/pipeline_lab/v3/product.pytreats retired markers as pending even though they have no due time, so the driver can keep scheduling no-op sweeps. Exclude retired markers from the pending check.- Sweep observability can miss rare outcomes until their first occurrence, and memory-queue fallback is not counted in
omi_fallback_total. Initialize the outcome series and record the fallback.
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/utils/conversations/v3/metrics.py">
<violation number="1" location="backend/utils/conversations/v3/metrics.py:53">
P3: `MEMORY_SWEEPS` has a finite `outcome` set, but no series is created at import. Initialize each outcome like the other labelled counters in this module, so the first occurrence of a rare outcome such as `failed` or `retired` starts from a zero baseline.</violation>
</file>
<file name="backend/testing/pipeline_lab/v3/product.py">
<violation number="1" location="backend/testing/pipeline_lab/v3/product.py:258">
P3: This check counts retired memory markers as pending. Those markers keep `v3_memory_pending=True` but have no due time, so the sweep never serves them. The driver then keeps scheduling no-op sweeps every 5 minutes until the horizon, which adds events and Firestore reads to the replay. Filter on the due time (for example, only markers with `v3_memory_due_at` set) so `pending()` reflects work the sweep can actually do.</violation>
</file>
<file name="backend/testing/pipeline_lab/scenario/standins.py">
<violation number="1" location="backend/testing/pipeline_lab/scenario/standins.py:144">
P3: The `queue_lost_tasks` note says the lost tasks used every delivery "on refusals", but `QueueModel.lose` in `v3/tasks.py` documents this as "answers nobody scripted". "Refusals" also collides with the separate `refused` counter in `spec.py` (creates refused because the queue is missing). Align the wording with the `lose` docstring.</violation>
</file>
<file name="backend/docs/listen_pusher_pipeline/changes/2026-11-30-v3-builder-stage-queues.md">
<violation number="1" location="backend/docs/listen_pusher_pipeline/changes/2026-11-30-v3-builder-stage-queues.md:55">
P3: The sweep query runs on every five-minute pass regardless of `stage_queues`, so the "Off ... no new read" sentence in the switch section is no longer accurate. Say here that the sweep is not gated by the switch and returns nothing while the rollout is off.</violation>
<violation number="2" location="backend/docs/listen_pusher_pipeline/changes/2026-11-30-v3-builder-stage-queues.md:55">
P2: This paragraph describes the sweep but omits the deploy prerequisite: the `conversations_v3_memory_due_sweep` index must be READY first, or the sweep silently recovers nothing. Older markers without `v3_memory_due_at` are also never recovered. Add both to this note.</violation>
</file>
<file name="backend/utils/conversations/v3/memory.py">
<violation number="1" location="backend/utils/conversations/v3/memory.py:158">
P3: The memory-queue refusal falls back to the builder queue with only a log line. Count it with `record_fallback` the way `handoff.fell_back` does, so the failover appears in `omi_fallback_total`.</violation>
<violation number="2" location="backend/utils/conversations/v3/memory.py:176">
P3: The docstring promises each marker is read at most `MEMORY_MAX_SWEEPS` times, but a row whose `_offer` raises skips `defer_memory`. Its due time stays past, so a persistent builder-queue refusal re-reads it on every sweep. Either defer failed rows too, or narrow this docstring to the successful path.</violation>
</file>
<file name="backend/docs/runbooks/conversations-v3.md">
<violation number="1" location="backend/docs/runbooks/conversations-v3.md:89">
P3: `failed` also covers errors after task creation, such as a `defer_memory` failure. Define it as a per-marker processing error; the task may already exist and the marker's due state may be uncertain.</violation>
<violation number="2" location="backend/docs/runbooks/conversations-v3.md:90">
P2: A tenth visit can enqueue a task that completes successfully, so `retired` does not mean the extraction could not be done. Describe it as the marker leaving future sweep queries.</violation>
</file>
Reply with feedback, questions, or to request a fix.
View guided diff | Turn on auto-fix | Re-trigger cubic
| Metrics: `omi_conversations_v3_stage_handoffs_total{stage,mode}` and | ||
| `omi_conversations_v3_memory_extractions_total{outcome}`. | ||
| A memory marker whose task is gone does not wait for the owner's next summary: the builder sweep offers a | ||
| task to every owed extraction past its due time (`memory.sweep`, `v3_memory_due_at`; the settle and every claim |
There was a problem hiding this comment.
P2: This paragraph describes the sweep but omits the deploy prerequisite: the conversations_v3_memory_due_sweep index must be READY first, or the sweep silently recovers nothing. Older markers without v3_memory_due_at are also never recovered. Add both to this note.
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/listen_pusher_pipeline/changes/2026-11-30-v3-builder-stage-queues.md, line 55:
<comment>This paragraph describes the sweep but omits the deploy prerequisite: the `conversations_v3_memory_due_sweep` index must be READY first, or the sweep silently recovers nothing. Older markers without `v3_memory_due_at` are also never recovered. Add both to this note.</comment>
<file context>
@@ -51,8 +51,15 @@ An enqueue that fails runs the stage in the task that tried and is counted
-Metrics: `omi_conversations_v3_stage_handoffs_total{stage,mode}` and
-`omi_conversations_v3_memory_extractions_total{outcome}`.
+A memory marker whose task is gone does not wait for the owner's next summary: the builder sweep offers a
+task to every owed extraction past its due time (`memory.sweep`, `v3_memory_due_at`; the settle and every claim
+move that time 15 minutes ahead). The query is one collection-group page of at most 500 rows a sweep, empty
+while extractions finish in time; a row it returns costs one more read, one write and one task creation, and
</file context>
| outside the rollout gets the task on `conversations-v3`. | ||
| `omi_conversations_v3_memory_sweeps_total{outcome}`: `enqueued`, `waiting` (name taken), `summary_owed`, | ||
| `claimed`, `not_owned`, `failed` (no queue took the task; the marker stays due), `retired` (the tenth visit; | ||
| any rate here is extractions the sweep could not get done). A steady `enqueued` rate |
There was a problem hiding this comment.
P2: A tenth visit can enqueue a task that completes successfully, so retired does not mean the extraction could not be done. Describe it as the marker leaving future sweep queries.
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/conversations-v3.md, line 90:
<comment>A tenth visit can enqueue a task that completes successfully, so `retired` does not mean the extraction could not be done. Describe it as the marker leaving future sweep queries.</comment>
<file context>
@@ -73,10 +73,25 @@ Watch: queue depth and oldest task age of the four queues; `omi_conversations_v3
+outside the rollout gets the task on `conversations-v3`.
+`omi_conversations_v3_memory_sweeps_total{outcome}`: `enqueued`, `waiting` (name taken), `summary_owed`,
+`claimed`, `not_owned`, `failed` (no queue took the task; the marker stays due), `retired` (the tenth visit;
+any rate here is extractions the sweep could not get done). A steady `enqueued` rate
+means memory tasks are being lost: look at the memory queue's 429, 503 and 404 answers. The query needs the
+collection-group index `conversations_v3_memory_due_sweep`; without it the step logs
</file context>
| any rate here is extractions the sweep could not get done). A steady `enqueued` rate | |
| the marker is removed from future sweep queries). A steady `enqueued` rate |
| 'Memory extractions owed by a summary pass that ran as their own stage, by outcome', | ||
| ['outcome'], | ||
| ) | ||
| MEMORY_SWEEPS = Counter( |
There was a problem hiding this comment.
P3: MEMORY_SWEEPS has a finite outcome set, but no series is created at import. Initialize each outcome like the other labelled counters in this module, so the first occurrence of a rare outcome such as failed or retired starts from a zero baseline.
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/utils/conversations/v3/metrics.py, line 53:
<comment>`MEMORY_SWEEPS` has a finite `outcome` set, but no series is created at import. Initialize each outcome like the other labelled counters in this module, so the first occurrence of a rare outcome such as `failed` or `retired` starts from a zero baseline.</comment>
<file context>
@@ -50,6 +50,11 @@ def safe_metric(fn: Callable[[], None]) -> None:
'Memory extractions owed by a summary pass that ran as their own stage, by outcome',
['outcome'],
)
+MEMORY_SWEEPS = Counter(
+ 'omi_conversations_v3_memory_sweeps_total',
+ 'Owed memory extractions the periodic sweep found past their due time, by what it did with them',
</file context>
| coll = get_firestore_client().collection('users').document(uid).collection('conversations') | ||
| for name in ('v3_pending', 'v3_process_pending'): | ||
| # v3_memory_pending: an owed memory extraction is served by the sweep when its task is gone. | ||
| for name in ('v3_pending', 'v3_process_pending', 'v3_memory_pending'): |
There was a problem hiding this comment.
P3: This check counts retired memory markers as pending. Those markers keep v3_memory_pending=True but have no due time, so the sweep never serves them. The driver then keeps scheduling no-op sweeps every 5 minutes until the horizon, which adds events and Firestore reads to the replay. Filter on the due time (for example, only markers with v3_memory_due_at set) so pending() reflects work the sweep can actually do.
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/testing/pipeline_lab/v3/product.py, line 258:
<comment>This check counts retired memory markers as pending. Those markers keep `v3_memory_pending=True` but have no due time, so the sweep never serves them. The driver then keeps scheduling no-op sweeps every 5 minutes until the horizon, which adds events and Firestore reads to the replay. Filter on the due time (for example, only markers with `v3_memory_due_at` set) so `pending()` reflects work the sweep can actually do.</comment>
<file context>
@@ -254,7 +254,8 @@ def pending(self, uid: str) -> bool:
coll = get_firestore_client().collection('users').document(uid).collection('conversations')
- for name in ('v3_pending', 'v3_process_pending'):
+ # v3_memory_pending: an owed memory extraction is served by the sweep when its task is gone.
+ for name in ('v3_pending', 'v3_process_pending', 'v3_memory_pending'):
if next(iter(coll.where(filter=FieldFilter(name, '==', True)).limit(1).stream()), None) is not None:
return True
</file context>
| 'name': 'queue_lost_tasks', | ||
| 'count': lost, | ||
| 'text': "A Cloud Tasks queue accepted tasks and never delivered them (the scenario's " | ||
| 'queues.limits.<queue>.lose), standing in for tasks that used every delivery on refusals or were ' |
There was a problem hiding this comment.
P3: The queue_lost_tasks note says the lost tasks used every delivery "on refusals", but QueueModel.lose in v3/tasks.py documents this as "answers nobody scripted". "Refusals" also collides with the separate refused counter in spec.py (creates refused because the queue is missing). Align the wording with the lose docstring.
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/testing/pipeline_lab/scenario/standins.py, line 144:
<comment>The `queue_lost_tasks` note says the lost tasks used every delivery "on refusals", but `QueueModel.lose` in `v3/tasks.py` documents this as "answers nobody scripted". "Refusals" also collides with the separate `refused` counter in `spec.py` (creates refused because the queue is missing). Align the wording with the `lose` docstring.</comment>
<file context>
@@ -134,6 +134,17 @@ def stand_in_notes(result: Mapping[str, Any]) -> list[dict[str, Any]]:
+ 'name': 'queue_lost_tasks',
+ 'count': lost,
+ 'text': "A Cloud Tasks queue accepted tasks and never delivered them (the scenario's "
+ 'queues.limits.<queue>.lose), standing in for tasks that used every delivery on refusals or were '
+ 'purged; the refusals themselves were not played.',
+ }
</file context>
| 'queues.limits.<queue>.lose), standing in for tasks that used every delivery on refusals or were ' | |
| 'queues.limits.<queue>.lose), standing in for tasks that used every delivery on unscripted answers or were ' |
| Metrics: `omi_conversations_v3_stage_handoffs_total{stage,mode}` and | ||
| `omi_conversations_v3_memory_extractions_total{outcome}`. | ||
| A memory marker whose task is gone does not wait for the owner's next summary: the builder sweep offers a | ||
| task to every owed extraction past its due time (`memory.sweep`, `v3_memory_due_at`; the settle and every claim |
There was a problem hiding this comment.
P3: The sweep query runs on every five-minute pass regardless of stage_queues, so the "Off ... no new read" sentence in the switch section is no longer accurate. Say here that the sweep is not gated by the switch and returns nothing while the rollout is off.
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/listen_pusher_pipeline/changes/2026-11-30-v3-builder-stage-queues.md, line 55:
<comment>The sweep query runs on every five-minute pass regardless of `stage_queues`, so the "Off ... no new read" sentence in the switch section is no longer accurate. Say here that the sweep is not gated by the switch and returns nothing while the rollout is off.</comment>
<file context>
@@ -51,8 +51,15 @@ An enqueue that fails runs the stage in the task that tried and is counted
-Metrics: `omi_conversations_v3_stage_handoffs_total{stage,mode}` and
-`omi_conversations_v3_memory_extractions_total{outcome}`.
+A memory marker whose task is gone does not wait for the owner's next summary: the builder sweep offers a
+task to every owed extraction past its due time (`memory.sweep`, `v3_memory_due_at`; the settle and every claim
+move that time 15 minutes ahead). The query is one collection-group page of at most 500 rows a sweep, empty
+while extractions finish in time; a row it returns costs one more read, one write and one task creation, and
</file context>
| an unreadable index or queue is logged and counted, and the markers stay due. | ||
| Cost: one query of at most ``writers.MEMORY_SWEEP_PAGE`` rows a sweep (none when nothing is overdue), | ||
| and one more read, one write and one task creation for each row it returns; a marker is read at most | ||
| ``writers.MEMORY_MAX_SWEEPS`` times. |
There was a problem hiding this comment.
P3: The docstring promises each marker is read at most MEMORY_MAX_SWEEPS times, but a row whose _offer raises skips defer_memory. Its due time stays past, so a persistent builder-queue refusal re-reads it on every sweep. Either defer failed rows too, or narrow this docstring to the successful path.
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/utils/conversations/v3/memory.py, line 176:
<comment>The docstring promises each marker is read at most `MEMORY_MAX_SWEEPS` times, but a row whose `_offer` raises skips `defer_memory`. Its due time stays past, so a persistent builder-queue refusal re-reads it on every sweep. Either defer failed rows too, or narrow this docstring to the successful path.</comment>
<file context>
@@ -120,3 +126,77 @@ async def deliver(uid, lane=handoff.BACKGROUND):
+ an unreadable index or queue is logged and counted, and the markers stay due.
+ Cost: one query of at most ``writers.MEMORY_SWEEP_PAGE`` rows a sweep (none when nothing is overdue),
+ and one more read, one write and one task creation for each row it returns; a marker is read at most
+ ``writers.MEMORY_MAX_SWEEPS`` times.
+ """
+ now = datetime.now(timezone.utc)
</file context>
| try: | ||
| created = triggers.enqueue_memory(uid, cid, content_hash, attempts) | ||
| except Exception as error: | ||
| logger.warning('event=v3_memory_sweep outcome=queue_refused exception_type=%s', type(error).__name__) |
There was a problem hiding this comment.
P3: The memory-queue refusal falls back to the builder queue with only a log line. Count it with record_fallback the way handoff.fell_back does, so the failover appears in omi_fallback_total.
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/utils/conversations/v3/memory.py, line 158:
<comment>The memory-queue refusal falls back to the builder queue with only a log line. Count it with `record_fallback` the way `handoff.fell_back` does, so the failover appears in `omi_fallback_total`.</comment>
<file context>
@@ -120,3 +126,77 @@ async def deliver(uid, lane=handoff.BACKGROUND):
+ try:
+ created = triggers.enqueue_memory(uid, cid, content_hash, attempts)
+ except Exception as error:
+ logger.warning('event=v3_memory_sweep outcome=queue_refused exception_type=%s', type(error).__name__)
+ if created is None:
+ # Raises when the builder queue refuses it too: the marker keeps its due time for the next sweep.
</file context>
| logger.warning('event=v3_memory_sweep outcome=queue_refused exception_type=%s', type(error).__name__) | |
| record_fallback( | |
| component='conversations_v3', | |
| from_mode='stage_queue', | |
| to_mode='builder_queue', | |
| reason='enqueue_failed', | |
| outcome='recovered', | |
| log=logger, | |
| ) |
| stays owed and is served when the owner's next summary arms memory, as before the sweep existed. An owner | ||
| outside the rollout gets the task on `conversations-v3`. | ||
| `omi_conversations_v3_memory_sweeps_total{outcome}`: `enqueued`, `waiting` (name taken), `summary_owed`, | ||
| `claimed`, `not_owned`, `failed` (no queue took the task; the marker stays due), `retired` (the tenth visit; |
There was a problem hiding this comment.
P3: failed also covers errors after task creation, such as a defer_memory failure. Define it as a per-marker processing error; the task may already exist and the marker's due state may be uncertain.
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/conversations-v3.md, line 89:
<comment>`failed` also covers errors after task creation, such as a `defer_memory` failure. Define it as a per-marker processing error; the task may already exist and the marker's due state may be uncertain.</comment>
<file context>
@@ -73,10 +73,25 @@ Watch: queue depth and oldest task age of the four queues; `omi_conversations_v3
+stays owed and is served when the owner's next summary arms memory, as before the sweep existed. An owner
+outside the rollout gets the task on `conversations-v3`.
+`omi_conversations_v3_memory_sweeps_total{outcome}`: `enqueued`, `waiting` (name taken), `summary_owed`,
+`claimed`, `not_owned`, `failed` (no queue took the task; the marker stays due), `retired` (the tenth visit;
+any rate here is extractions the sweep could not get done). A steady `enqueued` rate
+means memory tasks are being lost: look at the memory queue's 429, 503 and 404 answers. The query needs the
</file context>
| `claimed`, `not_owned`, `failed` (no queue took the task; the marker stays due), `retired` (the tenth visit; | |
| `claimed`, `not_owned`, `failed` (per-marker processing error; task may already exist), `retired` (the tenth visit; |
…rsation due_memory returned whole conversation rows, up to 500 a sweep, transcript and notes included, while the sweep uses the marker's hash, attempts, claim and visit count, the owed-summary flag and the owner fence. The query is projected to those fields. Billed reads are the same; a full page no longer loads conversation content into the sweep request. Failure-Class: none Co-Authored-By: Claude Fable 5.2 <[email protected]>
Git-on-my-level
left a comment
There was a problem hiding this comment.
Verdict: the design here is sound and the tests are real, but this needs work before merge: the branch now conflicts with main, and main gained a second mechanism for the same problem after this head was built.
Blocking
-
Conflicts with current main in
backend/utils/conversations/v3/memory.py,backend/utils/conversations/v3/service.pyandbackend/docs/runbooks/conversations-v3.md(GitHub reports the PR as conflicting; Hygiene's synthetic merge fails on the same three files). A rebase is needed regardless of anything below. -
Overlap with
memory.redrive_pending, merged in #26849 and already called fromservice.sweep()on main: it re-enqueues everyv3_memory_pendingmarker whoseupdate_timeis older than 10 minutes, under a separate-redrivetask name. This PR addsmemory.sweep()to the same job. Running both reads the same rows twice per pass and enqueues two differently-named tasks per overdue marker; the claim fence keeps that correct, but it is double work and two metrics telling one story. Please pick one before merge. For what it is worth, this PR's design is the stronger one on cost and observability:due_memory(conversations_v3_processing.py:892) is one indexed page of overdue rows only, so steady state is an empty query, whereasredrive_pendingscans every pending marker each 5-minute pass with no backoff or visit cap; anddefer_memory(:925) fences the move by hash and visit count, with doubling waits and a 10-visit retire. What the main-side version does better: it catches markers armed beforev3_memory_due_atexisted, and its separate task name replaces a lost-without-claim task in about 10 minutes instead of waiting up to an hour for the name slot to roll (memory.py:134names that hour as the price). If you replace it, fold those two properties in.
Non-blocking
memory.py:174-197: a row whose_offerraises keeps its due time. With oldest-due-first ordering, a full page of persistently failing rows (both queues refusing, Firestore write failing) would starve newer overdue rows. Only reachable in an outage, but a failure-count defer would close it and make the docstring's "read at most MEMORY_MAX_SWEEPS times" true unconditionally.defer_memoryretires on the tenth visit even when that visit enqueued a task (memory.py:163); if that task is lost too, the marker is invisible to the sweep for good. The runbook says so; just confirming it is intended.- Cross-owner read verified:
due_memoryprojects only the sevenMEMORY_SWEEP_FIELDS(no transcript or notes), keeps onlyusers/{uid}/conversations/{cid}paths, and_offerre-checks the owner fence; the task'sclaim_memorystill gates onpolicy.memory_eligible. No new data exposure. - CI: the single unit failure (
test_flag_budget.py) is the flag-budget calendar check that expired on 2026-11-30, unrelated to this diff and fixed on main by #26862; the rebase clears it. The PR's own test files and the lab scenario pass.
Performance/cost: one billed read per 5-minute sweep when nothing is overdue; at most 500 rows, so at most 1,000 reads, 500 writes and 500 task creations per sweep, created serially inside the sweep request (a full page is on the order of a minute or two; it is the last step, so nothing before it is delayed).
Blast radius: the builder sweep for all owners, but the step swallows its own failures and record_fallback covers a missing index, so a bad deploy degrades to a counted no-op instead of failing the sweep. Deploy order: the conversations_v3_memory_due_sweep collection-group index must be READY before the revision ships.
USER IMPACT: none visible by itself; memories for a conversation whose background extraction task was lost now show up within roughly 15 minutes to 2 hours instead of waiting indefinitely for the owner's next recording.
Still want as a reviewer: a unit test for the _offer failure path (the row stays due and is re-read next sweep, not retired), and the rebase decision on redrive_pending.
Leaving for human maintainer review: whether the due-time sweep replaces redrive_pending (merged today) or the two coexist is an architecture call for the v3 lane owner, and the index deploy ordering needs sign-off.
by AI on behalf of David — if you need David’s attention urgently, please @Git-on-my-level and escalate with need human response.
…y switch off (#26875) ## What changed and why Open pull requests from the backend bottleneck work, joined into one so they take one pass through CI instead of one each. Two of the eight parts (#26862, #26851) have since merged on their own; this PR carries the same commits, so they add nothing to its diff. Six of them add a row to the same three flag files (`config/feature-flags.yaml`, the generated registry page, `backend/config/reliability_experiments.py`), so merged one at a time each merge made the next one conflict and cost it another full CI run. Each part is the head of its own PR, merged here with a merge commit, so the history of every part is intact. The original PR carries the full description, measurements and review notes of its part; they are closed in favour of this one. | Part | Original PR | Switch | What a merge changes in production | |---|---|---|---| | Flag budget renewal | #26862 (merged) | none | Already on main. | | GPU worker floor 6 to 12 | #26851 (merged) | none | Already on main. Nothing changes until the worker chart is rolled by the release owner. | | Fresh class for just-recorded phone audio | #26848 | `fresh_class_for_new_audio`, off | One more histogram label; one in-process flag evaluation per qualifying upload. | | Commit wake made dependable and measured | #26860 | `commit_wake` (existing), off | New counters and two histograms for every account; behaviour only for admitted accounts. | | Declared unsupported language stays on the vendor route | #26870 | `declared_unsupported_language_route`, off | Nothing without a rule. | | One capture transport per listen session | #26822 | `one_capture_transport`, off | Nothing without a rule, on the backend or in a new app build. | | Stored outlines of unvisited stretches are kept | #26832 | `outline_keep_stored`, off | One new metric; nothing else without a rule. | | Live builder pass with fewer database requests | #26868 | `lean_builder_pass`, `outline_context_on_demand`, `tombstone_check_written_rows`, all off | Nothing without a rule. | No flag store rule exists for any of the seven new switches, so no account's behaviour changes at deploy. ### The parts in one paragraph each - **Flag budget renewal (#26862).** Carries the three-file change of #26600 (SCA-3850) onto current main: the 26 rows of `backend/config/flag_budget.json` that passed `review_by` on 2026-11-30 move to 2026-12-06 with the reasons #26600 gives. One difference from #26600, after review: the five rows that already carried a row-specific reason (`BATCH_PIPELINE_PROTECTED_SHARE_ENABLED`, `BATCH_PIPELINE_PROTECTED_SHARE_PERCENT`, `SYNC_BACKFILL_WORKER_API_URL`, `SYNC_BACKFILL_WORKER_AUDIENCE`, `LISTEN_BATCH_RECONNECT_ENABLED`) keep that text, with the renewal sentence appended. No rollout setting or runtime value changes. - **GPU worker floor (#26851).** `replicaCount` and `autoscaling.minReplicas` of the production batch worker go from 6 to 12; `maxReplicas` stays 16. Nodes for the weekday peak cannot be obtained on the day, so the floor is the only setting that has them in place before the ramp. In a replay of nine weekdays it about halves the mean wait for a worker for 27% more worker node-hours. - **Fresh class for new audio (#26848).** A phone upload in the backfill lane whose audio is at most 10 minutes old is served with the fresh class (job row `priority` 0, `admitted_priority` 1). Metering, the enrichment queue and admission still read the admitted class. It reorders the GPU queue and adds no capacity; the ramp in the flag row stops at 25% until GPU capacity covers the weekday peak. The GPU worker image must carry this build before the first rule is created. - **Commit wake (#26860).** A wake that meets a busy account claim is retried (0.5, 1, 2, 4 s), the first walk waits 0.5 s, and serving-side commits of an admitted account ask the in-process owner drain. Counters at both ends and `commit_to_text` / `ready_to_text` histograms by path and cohort. In the local load test, commit to written fell from a median of 11.2 s to 0.52 s. - **Declared unsupported language (#26870).** For a multilingual-profile user (#26431), a declared language Parakeet cannot serve stays the declaration, so the upload takes the vendor route at admission: no language probe, no GPU unit, no refusal, no recovery wait. Supported and unknown declarations, legacy-on owners and the record lane are unchanged. - **One capture transport (#26822).** With the rule on, a batch-only session sends no pendant audio on the socket and a live session gets no phone-file grant, so the same audio is no longer transcribed twice. Admit accounts to `end_open_conversation` together with this rule: without socket audio the baseline End closes nothing. Stored text then depends on the phone's serial upload queue alone. - **Stored outlines kept (#26832).** A live builder or on-open pass keeps the stored outlines of stretches it did not visit, so a later visit with the same lines and prompt reuses the model's answer instead of paying for it again. About 11% fewer outline calls with every account on. - **Fewer database requests per builder pass (#26868).** Three experiments remove bookkeeping reads and writes of the live builder pass. On a synthetic day against the Firestore emulator: same documents and prompts, reads down 35%, writes down 19%. `tombstone_check_written_rows` touches the commit's deletion guard: please review it as such, and agree it with the owner of conversation deletion before any account is admitted. ### Where the parts meet - `_reconcile_outlines` in `backend/utils/conversations/v3/service.py` now takes both `keep_stored` (#26832) and `clock` (#26868). The two do not interfere: a stretch found by its lines key keeps its stored fingerprint, and `outline.with_unvisited` drops stored rows by that fingerprint as before. - `config/feature-flags.yaml`: the `commit_wake` row is #26860's; #26822 only adds its own row beside it. - `backend/testing/pipeline_lab/scenario/reach.json` was measured again on the combined branch. - `backend/docs/feature-flag-registry.md` was rendered again from the combined YAML. ### Changed after the automated review The review bot left 34 comments. One was not valid, three are answered without a code change, the rest are fixed in this PR. Behaviour with every switch off is unchanged by all of them. What changed in behaviour: - **`one_capture_transport`, app half.** Safety copies are left untagged per conversation window, by whether pendant audio was really kept off the socket in that window, not by the socket's mode when the conversation closes. Before, phone-microphone copies (always sent) could end marked as sent with no conversation id and no upload. The app half now does nothing unless `end_open_conversation` is also on for the account, because without socket audio the baseline End closes nothing. The flag row makes that pairing a precondition of every cohort. The flag texts now say the rule covers the grant that comes with the on-phone preview; the Standard cohort grant is unchanged and listed as a known limit. - **`declared_unsupported_language_route`.** With language inheritance switched off (`BATCH_PIPELINE_LANGUAGE_INHERITANCE_ENABLED=false`) and a conversation language that declares nothing, the kept declaration was lost and the upload went to the GPU. Serving and shadow intake now take one kept value. - **`commit_wake`.** The retry set held a busy-claim token no walk returns (it mattered only with the owner drain switched off); corrected. `ready_to_text` now times a vendor-route row without `ready_at` from its settle instant, as the ordered merge does. - **`tombstone_check_written_rows`.** The ramp now starts with a step that admits no account until the owner of conversation deletion has agreed the change to the deletion guard. - **Simulator and lab.** The pipeline simulator clears an inherited `OMI_RELIABILITY_EXPERIMENTS`; the lab's final verdict carries STT routes and queue counts; a scenario's `route` is validated when it is loaded. - **Docs.** Wording corrected where it promised more than the code does (the fresh-class pause is a bound on promotions, not a guarantee for units already fresh; `served` is the class on the job row, not who transcribed the unit; when `lines_key` is written; which rollout readouts are fleet-wide). ### CI The first run of this PR had its emulator proofs job cancelled at the 20-minute limit (the job took 18.4 to 19.5 minutes on main that day; this PR's three added proofs take about 70 s there). #26882 has since raised the limit to 25 minutes on main, so this PR changes no workflow. ### Tuning - MAX_READY_UNITS (#26848, fresh ring size at which promotion pauses), new: 600 waiting units, about 30 s of fleet work at the weekday peak's lease rate; promotion resumes under 300. - MAX_TIMED_OWNERS (#26860, receipt times kept for the wake start histogram), new: 8192 accounts per process. Past it a wake still walks, untimed. - SETTLE_SECONDS (#26860, wait before a wake's first walk): before 0 s, after 0.5 s. - BUSY_RETRY_DELAYS (#26860, retries of a wake's walk after a busy account claim): before 0 retries (the wake was dropped), after 4 retries at 0.5, 1, 2 and 4 s. - Worker floor (#26851): before 6, after 12 (`replicaCount` and `autoscaling.minReplicas`); `maxReplicas` stays 16. ### Not in this PR #26857 (the sweep that gives a lost memory extraction its task back) is left out. #26859, merged to main on 2026-12-01, recovers the same lost memory obligations with its own re-drive in the builder sweep, so the two would now run side by side. #26857 stays open for its author to rework or close. Line-Count-Exception: backend/utils/batch_pipeline/scheduler.py | 1529 -> 1534 | the enqueue takes the served class and a rejoining row returns to its admitted class; both belong to the two functions that own the ring Line-Count-Exception: backend/utils/batch_pipeline/projection.py | 1978 -> 2003 | the walk now returns its stop reason to the caller (`walk_owner`, with `project_owner` kept as a wrapper for its existing callers) and names its origin for the commit-to-text series; one observe call, two origin markers and the method's signature and docstring. Splitting the projector is outside this change. Line-Count-Exception: app/lib/services/capture/capture_controller.dart | 5265 -> 5276 | call sites of the experiment at the per-packet routing boundary, socket publish, socket close and the status handler; its state and helpers are in the new part file capture_one_transport.dart Line-Count-Exception: backend/routers/listen/receiver.py | 3066 -> 3070 | two one-line calls and their two imports; the logic is in routers/listen/local_preview.py Line-Count-Exception: backend/utils/conversations/v3/service.py | 2570 -> 2647 | the experiments' branches sit in reconcile and _reconcile_outlines beside the baseline calls they replace, so the two paths can be read side by side and deleted together when the rollouts end; the old branches and the switches go then Line-Count-Exception: backend/database/conversations_v3.py | 3075 -> 3171 | PendingPage, the pending page clear_terminal_pending returns and the batched source read share load's private helpers and the commit's tombstone decision is carved out of its write loop in place; the baseline paths they duplicate are removed when the rollout ends ## Product invariants affected - INV-CAP-1: the change of #26822 is in the capture routing boundary (`app/lib/services/capture/capture_controller.dart`, `capture_conversation_custody.dart`). No packet loses custody: one that is not sent is already in a phone file or the safety copy, and one the safety copy refused is sent as before. Tests follow each packet to exactly one place. ## How it was verified Each part was verified on its own branch; the commands and results are in its PR. On the combined branch: - Unit, after the review fixes: the test files the parts change, every `test_conversations_v3*`, `test_reliability_experiment*`, pipeline lab and simulator file, the batch intake, commit, projection, scheduler, admission and language files, the local preview and Standard batch files, the Firestore query shape guard and the flag files, plus the multipart and part-retirement files, every unit file that exercises batch intake and the unit files main changed since: 216 files, 9,661 tests, all pass (`BACKEND_UNIT_TEST_FILE_LIST=<list> bash test.sh`). - App, after the review fixes: `flutter test` on `one_capture_transport_test.dart`, `local_preview_admission_test.dart` and `reliability_experiments_test.dart`: 73 pass; `flutter analyze` on the changed files: no issues. - Firestore emulator: the integration files of #26868, #26832, #26870 and #26860 plus `test_conversations_v3_unchanged_writes_firestore.py`: 45 tests pass, also after the review fixes. After the merge of #26847 (multipart reads and part retirement, which meets `tombstone_check_written_rows` in the projection commit) the same files plus `test_conversations_v3_finish_emulator.py` and `test_v3_multipart_transcript_firestore.py`: 92 pass; after the merge of #26771 and #26873, with the locked closure cost and live catch-up files added: 104 pass. One of them, `test_naming_a_speaker_rearms_a_recording_and_nothing_stored_differs`, failed when run between 07:34 and 08:00 UTC, because the story's first recording (26 minutes, starting eight hours before the run) then crosses midnight UTC and the baseline outlines one more stretch. The test now starts that recording half an hour earlier in that case, and the file passes inside the window. - Pipeline lab, all 30 committed scenarios: 30 pass (`scenario run --trace-calls`, the run `reach.json` was measured from), 30 pass again after the review fixes, and all 31 (main added one) after the last merge of main. - Pipeline lab, old against new, run before the review fixes (`scenario compare`, four arms: `origin/main`, this branch with every switch off, with the four v3 switches on together, with all eight switches on together). With the switches off, every scenario main can run (28 of 30) has the same conversations and exactly the same reads, writes and no-op writes as main. With the switches on, no conversation differs; reads fall 10.6% and writes 9.3% over those scenarios, and the four v3 switches together give the same result as all eight. The four scenarios whose verdict changes with a switch are the ones written to show that switch (`fewer_requests_two_talks_and_late_sync`, `outline_kept_across_passes` and the two `stt_route_declared_unsupported_language_*`). - `scripts/check_feature_flag_registry.py`: OK. `scripts/pr-preflight`: 65 of 65 checks pass. Not verified on the combined branch: a running stack, a phone, production. The app half of #26822 was run on a test phone from its own branch (results in #26822), not from this one, and that run predates the changes made in review (per-window untagging, the `end_open_conversation` guard): tests are their only evidence. ## Tests Every part brings its own tests (listed below). Added or strengthened in review: the per-window untagging, the `end_open_conversation` guard, a capture-end flush and the hold counters in the app tests; the provider open and the warm-before-admission order in `test_reliability_experiment_one_capture_transport.py`; the kept declaration with inheritance off in the three language test files; the real projector walk with the claim held and the vendor-row ready time in `test_reliability_experiment_commit_wake.py`; changed lines against a stored outline in `test_conversations_v3_fewer_requests.py`; a real opened conversation in `test_reliability_experiment_outline_keep_stored.py`; the simulator's inherited override in `test_pipeline_sim_new_audio_wait.py`; the lab verdict's routes and the route names at load. - #26848: `tests/unit/test_reliability_experiment_fresh_class.py`, `tests/unit/test_pipeline_sim_new_audio_wait.py`. - #26860: `tests/unit/test_reliability_experiment_commit_wake.py`, `tests/integration/test_batch_commit_wake_firestore.py`. - #26870: `tests/unit/test_batch_multilingual_profile_routing.py`, `tests/unit/test_batch_admission_language.py`, `tests/integration/test_batch_declared_unsupported_language_route_firestore.py`, two pipeline lab scenarios. - #26822: `tests/unit/test_reliability_experiment_one_capture_transport.py`, `app/test/services/capture/one_capture_transport_test.dart`. - #26832: `tests/unit/test_reliability_experiment_outline_keep_stored.py`, `tests/integration/test_conversations_v3_outline_keep_stored_firestore.py`. - #26868: `tests/unit/test_conversations_v3_fewer_requests.py`, `tests/integration/test_conversations_v3_fewer_requests_firestore.py`, one pipeline lab scenario. - #26851: `tests/unit/test_batch_pipeline_chart.py` and the two HPA replay files follow the new floor. - #26862: `tests/unit/test_flag_budget.py` follows the new dates. ## UI evidence UI-Evidence: none -- no screen changes ## Failure class (fixes) Failure-Class: none 🤖 Generated with [Claude Code](https://claude.com/claude-code)
|
Hey @Nizarius 👋 Thank you so much for taking the time to contribute to Omi! We truly appreciate you putting in the effort to submit this pull request. After careful review, we've decided not to merge this particular PR. Please don't take this personally — we genuinely try to merge as many contributions as possible, but sometimes we have to make tough calls based on:
Before your next PR, please skim:
If this was declined for direction or taste, maintainers should cite an invariant ID or open a proposed one — ask if that citation is missing. Your contribution is still valuable to us, and we'd love to see you contribute again in the future! If you'd like feedback on how to improve this PR or want to discuss alternative approaches, please don't hesitate to reach out. Thank you for being part of the Omi community! |
What changed and why
Follow-up to #26824 (builder stages on their own queues, rollout switch
stage_queues). With the switch on, a summary's settle armsv3_memory_pendingon the conversation and a task onconversations-v3-memoryextracts the memories. Nothing re-served a marker whose task was gone: it waited until the same owner's next summary armed memory again, and an owner who stops recording kept that conversation without memories. The runbook listed this as a known limit. A task is lost when it uses its ten deliveries on refusals (429 or 503 from an overloadedbackend-sync, 404 from a revision without the route), when the queue is purged, or when the instance dies between the settle and the task's creation.The builder's periodic sweep (
POST /v1/conversations-v3/sweep, every 5 minutes) now also offers a task to every owed extraction that is past a due time:v3_memory_due_atis set 15 minutes ahead by the settle that arms the marker and moved 15 minutes on by every claim, in the writes those steps already make. A marker whose task is on its way, or whose extraction is running, is never in the sweep's range.conversations_v3_processing.due_memory: collection groupconversations,v3_memory_pending == trueandv3_memory_due_at <= now, oldest due first, at most 500 rows a sweep. The page size is a constant of the module (MEMORY_SWEEP_PAGE), not an argument a caller can raise. Each row comes back with seven small fields only (MEMORY_SWEEP_FIELDS: the marker's hash, attempts, claim and visit count, the owed-summary flag and the two owner-fence fields), so a full page never loads 500 conversations with their transcripts and notes. It needs a new collection-group index (conversations_v3_memory_due_sweepin the index registry;firestore.indexes.jsonregenerated), and the read is classified in the conversation reader registry (backend/docs/conversations-v3-readers.json).memory.sweep,memory._offer): it creates the memory task under the name the hand-off gave it, on the memory queue for an owner in the rollout and onconversations-v3otherwise (the owner left the rollout with an extraction owed) or when the memory queue refuses the task. It runs no model call itself. A row that cannot be served now (its summary is owed again, a worker holds a claim, another runtime owns the row) gets no task. Every row it read is then moved on: 15 minutes, doubling per visit up to 6 hours, fenced by the content hash and the visit count so a marker a newer summary armed keeps its own time. The tenth visit (about 32 hours after the first) removes the due time: the sweep never reads that marker again and it stays owed as it was before this change, so nothing the sweep cannot serve stays in the due index.omi_fallback_total{component="conversations_v3",from_mode="memory_sweep"},omi_conversations_v3_memory_sweeps_total{outcome="failed"}), the markers stay due, and the rest of the sweep has already run.new: capacity. One more Firestore query on the existing 5-minute sweep job; one collection-group composite index on
conversations(v3_memory_pending,v3_memory_due_at); one counter,omi_conversations_v3_memory_sweeps_total{outcome}(seven label values), added to the backend-sync sidecar's allow-list. Two more fields on a conversation row that has a memory marker (v3_memory_due_at,v3_memory_sweeps), written in the transactions that already write the marker.No switch of its own, and why. Only the summary settle of an account in the
stage_queuesrollout arms the marker, so with that switch off for every account (today: no flag rule exists) no row matches and the step creates no task and writes nothing. What runs for everyone after this merges is the empty query: one billed read per sweep, every 5 minutes. The step does not read the switch on purpose. An account taken out of the rollout with an extraction owed, which is the rollback case, is exactly when a task may have been lost with a purged queue, and the sweep must still serve it.Cost. With nothing overdue the query returns no rows: one billed read per sweep, whatever the number of accounts in the rollout, and nothing for an account outside it. Each overdue marker costs two reads (the page and the fenced move), one write and one task creation per visit, and at most 500 markers are visited per sweep, so a sweep is bounded at 1,000 reads, 500 writes and 500 task creations however many are owed. A marker is visited at most ten times. The step creates tasks one after another inside the sweep request and runs no model call: the extraction it restores is work the conversation already owed, and the memory queue's own dispatch limits pace it. It is the last step of the sweep, so a slow page cannot delay the steps before it; rows it did not reach stay due for the next sweep.
Recovery time. First visit 15 to 20 minutes after the settle or the last claim. A lost task that never claimed: within about two hours (the first two visits find its name taken).
Not covered. A marker armed by a revision before this change has no due time and is not found by the sweep; no flag rule exists yet, so none is armed. The sweep does not retry a failed model call inside memory extraction (the extraction still absorbs it, as before). The index must be READY in production before a revision with this change serves; the deploy readiness gate checks that, and the step degrades to a counted no-op without it.
Runbook:
backend/docs/runbooks/conversations-v3.md(Stage queues: "Lost memory tasks" replaces the known limit). Change note:backend/docs/listen_pusher_pipeline/changes/2026-11-30-v3-builder-stage-queues.md.Product invariants affected
extract_memoriesin the memory task; this PR only creates that task again when it was lost.How it was verified
stage_queues_memory_task_lost(real v3 code on a Firestore emulator and Redis, virtual clock, fake model gateway): the summary task settles and creates the memory task, the queue accepts it and never delivers it, the owner records nothing more. The sweep visits the marker at 19 and 34 minutes after the settle and finds the name taken (no second task), then creates the task on the first visit after the clock hour ends, and the memories are extracted once, from the stored text. Before this change the same story ends with no memories.scenario run --jobs 4 --repeat 2), run again after merging current main. No existing scenario's budget moved: a sweep that finds nothing overdue adds no counted read, and the backlog scenario (stage_queues_late_text_rewrite, memory task waiting behind filler load) still creates exactly the tasks it created before.backend/docs/firestore-query-checklist.md) passes with the new query's driver and the regenerated manifest. The guard found one defect in this change's test support, fixed here: the builder sweep imports the memory stage inside its body, so the first shape capture of a process recorded the query's due bound with the wall clock and two exports differed (test_export_is_deterministic). The driver module now loads the stage before a driver starts.make preflightagainst current main with this text as the PR body: all selected checks pass.Not verified: nothing ran against real Cloud Tasks or production Firestore, so the Cloud Tasks behaviour the design rests on (a finished or purged task's name stays taken for a while) is modelled by the lab's queue, not observed. No account is in the rollout yet, so there is no production marker to observe.
Tests
backend/tests/unit/test_conversations_v3_stage_queues.py: the settle and every claim move the due time on and a clear removes it; the wait between visits doubles up to 6 hours; the move is fenced by hash and visit count; the query is one page of 500 across owners, oldest due first, projected to the seven fields the sweep uses (the tests' stand-in answers with those fields only, so the step is proven not to need any other); a marker inside its grace is left alone; a lost extraction gets its task back under the hand-off's name and is extracted by it; a waiting task refuses the duplicate; a lost task that never claimed is replaced once its name's hour ends; an owner outside the rollout and a refused memory queue both get the task on the builder queue, never a model call inside the sweep; a marker no queue took stays due; summary owed, claimed and not-owned rows are only moved on; a marker nothing could serve leaves the sweep after its tenth visit and stays owed; one failing row does not stop the rest; an unreadable index is counted and returns nothing; the builder sweep counts the owners the memory sweep served; the new counter passes both sidecar allow-lists.backend/tests/support/firestore_conversations_v3_drivers.py: a driver entry fordue_memory, and the memory stage loaded before drivers run so its clock is frozen like every other module's.backend/tests/unit/test_pipeline_lab_stage_queues.py: the lab queue's newloselimit (the task is accepted, keeps its name, is never delivered), its parsing and its stand-in note.stage_queues_memory_task_lost.json;scenario/reach.jsonre-measured.Line-Count-Exception: backend/utils/conversations/v3/service.py | 2395 -> 2398 | the memory sweep is one call at the end of service.sweep, the function the scheduler route and the pipeline lab both run; the step itself lives in memory.py
Line-Count-Exception: backend/database/firestore_index_registry.py | 2422 -> 2429 | one index requirement for the sweep's query, declared in the registry every serving query's index must be declared in
UI evidence
UI-Evidence: none -- backend only
Failure class (fixes)
Failure-Class: none
🤖 Generated with Claude Code