Repository navigation
Bound v3 multipart transcript reads and retirement - #26847
Git-on-my-level merged 21 commits into
Conversation
|
Late panel answer from luna for review-20261201t024044-02aa at a5c4de4.
|
Codex Review Summary: ❌ FailedThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
There was a problem hiding this comment.
11 issues found across 39 files
Confidence score: 3/5
backend/database/conversations.pycan return success while silently droppingtranscript_segmentsfor conversations with transcript corrections. Make the result reflect whether the transcript write succeeded.backend/database/sync_conversation_snapshot.pyreuses the first resolve'sread_deadlinefor later redirected reads, so a later read can inherit an expired deadline. Refresh the deadline for redirected reads.backend/database/conversations.pyletsInvalidMultipartTranscriptescape for a locked multipart target, unlike the processing-persist path, which treats the case as transient. Handle the exception consistently so callers don't get an unexpected failure.backend/utils/conversations/v3/service.pydisables multipart for every row in the plan when any row is backfill-bound, potentially affecting unrelated conversations. Limit the check to the bound row.
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/docs/listen_pusher_pipeline/changes/2026-12-01-v3-multipart-retirement.md">
<violation number="1" location="backend/docs/listen_pusher_pipeline/changes/2026-12-01-v3-multipart-retirement.md:44">
P3: This note puts the v3 multipart contract details here instead of in `listen_pusher_pipeline.mdx`, which the changes README reserves for contracts. The link at the end goes to the whole mdx with no section, and that file has no v3 multipart section to point at. Move the envelope, flag, and sweep-bound contract text into a named section of the mdx, and link this note to it.</violation>
</file>
<file name="config/feature-flags.yaml">
<violation number="1" location="config/feature-flags.yaml:61">
P3: This cohort gate is described as a rollout (pilot cohort, then widening only after measured evidence), but it is registered as a permanent `config_switch` with `terminal: keep` and no `ramp`/`review_by`. Consider using `lifecycle: rollout` with `terminal: undecided`, a `ramp`, and `review_by` so the pilot-to-all decision is tracked and expires.</violation>
</file>
<file name="backend/database/transcript_multipart.py">
<violation number="1" location="backend/database/transcript_multipart.py:138">
P3: New `_open_part` imports `derive_key` inside the function. Move it to the module import block, or note the import cycle that prevents it.</violation>
</file>
<file name="backend/docs/feature-flag-registry.md">
<violation number="1" location="backend/docs/feature-flag-registry.md:817">
P3: The `CONVERSATIONS_V3_MULTIPART_RECLAIM` row omits its prerequisites. Reclamation is effective only when `CONVERSATIONS_V3_MULTIPART_WRITES` and a non-empty `CONVERSATIONS_V3_MULTIPART_WRITE_COHORT` are also set. Add that to the summary, since this flag deletes transcript parts.</violation>
</file>
<file name="backend/database/conversations.py">
<violation number="1" location="backend/database/conversations.py:1046">
P3: These new production imports are inside functions instead of the module import block. Move them to the top-level imports so the backend import policy and static dependency checks remain consistent.
(Based on your team's feedback about backend imports at module scope.) .</violation>
<violation number="2" location="backend/database/conversations.py:1693">
P2: This upsert path raises `InvalidMultipartTranscript` for a locked multipart target, but it propagates unhandled to the caller. The processing-persist path declines the same case as transient, so the two paths handle one condition differently. Catch the error here or decline the write the same way as `_persist`.</violation>
<violation number="3" location="backend/database/conversations.py:3330">
P2: For conversations with `has_transcript_corrections`, this branch silently drops the `transcript_segments` write while `update_conversation` still returns True. Callers cannot tell that their transcript update was not applied. Return an explicit refusal or raise so the caller can handle it.</violation>
</file>
<file name="backend/database/speaker_resolution_updates.py">
<violation number="1" location="backend/database/speaker_resolution_updates.py:113">
P2: This `multipart_unavailable` refusal reaches `run_only` as a plain `False`, which `final_pass_retry.run_only` reports as `deferred_revision_changed`. Either pass the reason through to the caller's outcome, or have that caller map this reason to its own outcome so retry telemetry and revision-change metrics stay accurate.</violation>
</file>
<file name="backend/utils/conversations/v3/service.py">
<violation number="1" location="backend/utils/conversations/v3/service.py:785">
P2: The new `not any(multipart_backfill_bound(...))` checks turn off multipart for every row in the plan, not only the bound row. The writer already excludes bound rows one at a time, so this switches unrelated conversations to the size-capped path. If the plan-wide fallback is intended, add a comment saying so; otherwise drop these two checks and rely on the per-row exclusion in `prepare()`.</violation>
</file>
<file name="backend/config/conversations_v3.py">
<violation number="1" location="backend/config/conversations_v3.py:85">
P2: `multipart_backfill_bound` treats any row with truthy `backfilled` as backfill-bound. Live re-derive also stamps `backfilled` alongside `v3_rederive_live_run`, and the existing rederive and backfill predicates exclude that combination. Exclude rows with `v3_rederive_live_run` unless they carry a real backfill run marker.</violation>
</file>
<file name="backend/database/sync_conversation_snapshot.py">
<violation number="1" location="backend/database/sync_conversation_snapshot.py:55">
P2: The `read_deadline` stored on the memoized snapshot comes from the first resolve in the job. A later `read_redirected` for the same conversation reuses it, and `use_read_deadline` then keeps the earlier, expired deadline. Its child reads fail with `MultipartReadExpired` even though the current attempt has fresh budget. Resolve the deadline from the current `read_redirected` attempt instead of caching it on the snapshot.</violation>
</file>
Reply with feedback, questions, or to request a fix.
View guided diff | Re-trigger cubic
| return | ||
| multipart = transcript_multipart.is_multipart(existing.get('transcript_segments')) | ||
| if multipart and existing.get('is_locked'): | ||
| raise transcript_multipart.InvalidMultipartTranscript('multipart processing target is locked') |
There was a problem hiding this comment.
P2: This upsert path raises InvalidMultipartTranscript for a locked multipart target, but it propagates unhandled to the caller. The processing-persist path declines the same case as transient, so the two paths handle one condition differently. Catch the error here or decline the write the same way as _persist.
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/database/conversations.py, line 1693:
<comment>This upsert path raises `InvalidMultipartTranscript` for a locked multipart target, but it propagates unhandled to the caller. The processing-persist path declines the same case as transient, so the two paths handle one condition differently. Catch the error here or decline the write the same way as `_persist`.</comment>
<file context>
@@ -1649,6 +1688,9 @@ def _write_processing_result(transaction):
return
+ multipart = transcript_multipart.is_multipart(existing.get('transcript_segments'))
+ if multipart and existing.get('is_locked'):
+ raise transcript_multipart.InvalidMultipartTranscript('multipart processing target is locked')
preserve_duplicate_hint(write_data, existing)
if existing.get('arrival_at'):
</file context>
| update_data.pop('manual_speaker_assignments', None) | ||
| update_data.pop('manual_speaker_assignments_compressed', None) | ||
| if current.get('has_transcript_corrections'): | ||
| update_data.pop('transcript_segments') |
There was a problem hiding this comment.
P2: For conversations with has_transcript_corrections, this branch silently drops the transcript_segments write while update_conversation still returns True. Callers cannot tell that their transcript update was not applied. Return an explicit refusal or raise so the caller can handle it.
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/database/conversations.py, line 3330:
<comment>For conversations with `has_transcript_corrections`, this branch silently drops the `transcript_segments` write while `update_conversation` still returns True. Callers cannot tell that their transcript update was not applied. Return an explicit refusal or raise so the caller can handle it.</comment>
<file context>
@@ -3147,6 +3316,28 @@ def _update_conversation_once(uid, conversation_id, doc_ref, update_data, *, rec
+ update_data.pop('manual_speaker_assignments', None)
+ update_data.pop('manual_speaker_assignments_compressed', None)
+ if current.get('has_transcript_corrections'):
+ update_data.pop('transcript_segments')
+ update_data.pop('transcript_segments_compressed', None)
+ elif current.get('manual_speaker_assignments') is not None:
</file context>
| deletion=deleting, | ||
| ) | ||
| except transcript_multipart.InvalidMultipartTranscript: | ||
| return False, 'multipart_unavailable', None |
There was a problem hiding this comment.
P2: This multipart_unavailable refusal reaches run_only as a plain False, which final_pass_retry.run_only reports as deferred_revision_changed. Either pass the reason through to the caller's outcome, or have that caller map this reason to its own outcome so retry telemetry and revision-change metrics stay accurate.
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/database/speaker_resolution_updates.py, line 113:
<comment>This `multipart_unavailable` refusal reaches `run_only` as a plain `False`, which `final_pass_retry.run_only` reports as `deferred_revision_changed`. Either pass the reason through to the caller's outcome, or have that caller map this reason to its own outcome so retry telemetry and revision-change metrics stay accurate.</comment>
<file context>
@@ -96,7 +97,23 @@ def readable(data):
+ deletion=deleting,
+ )
+ except transcript_multipart.InvalidMultipartTranscript:
+ return False, 'multipart_unavailable', None
+ if replacement is not None:
+ replacement.stage(transaction, ref)
</file context>
| The final MCP batch adds at most two document reads to a successfully hydrated multipart detail. The pilot must | ||
| report aggregate reads including retries, writes, latency, timeouts, and retirement backlog using existing probes. | ||
|
|
||
| This change concerns the v3 projection and read boundary in the [pipeline contract](../../listen_pusher_pipeline.mdx). |
There was a problem hiding this comment.
P3: This note puts the v3 multipart contract details here instead of in listen_pusher_pipeline.mdx, which the changes README reserves for contracts. The link at the end goes to the whole mdx with no section, and that file has no v3 multipart section to point at. Move the envelope, flag, and sweep-bound contract text into a named section of the mdx, and link this note to it.
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-12-01-v3-multipart-retirement.md, line 44:
<comment>This note puts the v3 multipart contract details here instead of in `listen_pusher_pipeline.mdx`, which the changes README reserves for contracts. The link at the end goes to the whole mdx with no section, and that file has no v3 multipart section to point at. Move the envelope, flag, and sweep-bound contract text into a named section of the mdx, and link this note to it.</comment>
<file context>
@@ -0,0 +1,46 @@
+The final MCP batch adds at most two document reads to a successfully hydrated multipart detail. The pilot must
+report aggregate reads including retries, writes, latency, timeouts, and retirement backlog using existing probes.
+
+This change concerns the v3 projection and read boundary in the [pipeline contract](../../listen_pusher_pipeline.mdx).
+The loopback Firestore suite exercises real builder and MCP entry points, ownership races, blocked undo eligibility,
+direct part replacement, and bounded sweep behavior.
</file context>
| - {"key": "CONVERSATIONS_V3_COMMIT_LEASE_RENEWAL", "aliases": [], "kind": "env", "lifecycle": "ops_kill", "surfaces": ["backend"], "summary": "Default on; a multi-batch v3 projection commit renews its pass lease (builder or backfill-builder) before each batch after the first.", "fail": "open", "owner": "Goal: Pipeline", "created": "2026-11-26", "terminal": "keep", "decision": "keep", "notes": "SCA-2918. Off restores the single renewal before the commit. A failed renewal raises lease_lost or FirestoreContentionExhausted after the committed prefix and keeps pending owed. Decided per commit, so one value fleet-wide is not required. See backend/docs/listen_pusher_pipeline/changes/2026-11-26-v3-locked-closure-allowance.md."} | ||
| - {"key": "CONVERSATIONS_V3_TRANSCRIPT_SIZE_CAP", "aliases": [], "kind": "env", "lifecycle": "ops_kill", "surfaces": ["backend"], "summary": "Default on; split unpublished v3 windows at a deterministic inline transcript size budget.", "fail": "open", "owner": "Goal: Pipeline", "created": "2026-11-25", "terminal": "keep", "decision": "keep", "notes": "SCA-2918. Set off on the builder and backfill runners to disable new size cuts."} | ||
| - {"key": "CONVERSATIONS_V3_MULTIPART_WRITES", "aliases": [], "kind": "env", "lifecycle": "config_switch", "surfaces": ["backend"], "summary": "Default off; publish oversized v3 transcripts in bounded Firestore parts.", "fail": "closed", "owner": "Goal: Pipeline", "created": "2026-11-29", "terminal": "keep", "decision": "keep", "notes": "SCA-5779. Keep off until Pipeline approves end-to-end custody and Firestore operation evidence."} | ||
| - {"key": "CONVERSATIONS_V3_MULTIPART_WRITE_COHORT", "aliases": [], "kind": "env", "lifecycle": "config_switch", "surfaces": ["backend"], "summary": "Unset denies v3 multipart publication. Rollout cohort for oversized transcript writes.", "fail": "closed", "owner": "Goal: Pipeline", "created": "2026-12-01", "terminal": "keep", "decision": "keep", "notes": "SCA-5779. Uses the existing cohort grammar. Release binds an isolated cohort for the pilot. Widening to all is explicit and needs measured pilot evidence."} |
There was a problem hiding this comment.
P3: This cohort gate is described as a rollout (pilot cohort, then widening only after measured evidence), but it is registered as a permanent config_switch with terminal: keep and no ramp/review_by. Consider using lifecycle: rollout with terminal: undecided, a ramp, and review_by so the pilot-to-all decision is tracked and expires.
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 config/feature-flags.yaml, line 61:
<comment>This cohort gate is described as a rollout (pilot cohort, then widening only after measured evidence), but it is registered as a permanent `config_switch` with `terminal: keep` and no `ramp`/`review_by`. Consider using `lifecycle: rollout` with `terminal: undecided`, a `ramp`, and `review_by` so the pilot-to-all decision is tracked and expires.</comment>
<file context>
@@ -58,6 +58,8 @@ flags:
- {"key": "CONVERSATIONS_V3_COMMIT_LEASE_RENEWAL", "aliases": [], "kind": "env", "lifecycle": "ops_kill", "surfaces": ["backend"], "summary": "Default on; a multi-batch v3 projection commit renews its pass lease (builder or backfill-builder) before each batch after the first.", "fail": "open", "owner": "Goal: Pipeline", "created": "2026-11-26", "terminal": "keep", "decision": "keep", "notes": "SCA-2918. Off restores the single renewal before the commit. A failed renewal raises lease_lost or FirestoreContentionExhausted after the committed prefix and keeps pending owed. Decided per commit, so one value fleet-wide is not required. See backend/docs/listen_pusher_pipeline/changes/2026-11-26-v3-locked-closure-allowance.md."}
- {"key": "CONVERSATIONS_V3_TRANSCRIPT_SIZE_CAP", "aliases": [], "kind": "env", "lifecycle": "ops_kill", "surfaces": ["backend"], "summary": "Default on; split unpublished v3 windows at a deterministic inline transcript size budget.", "fail": "open", "owner": "Goal: Pipeline", "created": "2026-11-25", "terminal": "keep", "decision": "keep", "notes": "SCA-2918. Set off on the builder and backfill runners to disable new size cuts."}
- {"key": "CONVERSATIONS_V3_MULTIPART_WRITES", "aliases": [], "kind": "env", "lifecycle": "config_switch", "surfaces": ["backend"], "summary": "Default off; publish oversized v3 transcripts in bounded Firestore parts.", "fail": "closed", "owner": "Goal: Pipeline", "created": "2026-11-29", "terminal": "keep", "decision": "keep", "notes": "SCA-5779. Keep off until Pipeline approves end-to-end custody and Firestore operation evidence."}
+ - {"key": "CONVERSATIONS_V3_MULTIPART_WRITE_COHORT", "aliases": [], "kind": "env", "lifecycle": "config_switch", "surfaces": ["backend"], "summary": "Unset denies v3 multipart publication. Rollout cohort for oversized transcript writes.", "fail": "closed", "owner": "Goal: Pipeline", "created": "2026-12-01", "terminal": "keep", "decision": "keep", "notes": "SCA-5779. Uses the existing cohort grammar. Release binds an isolated cohort for the pilot. Widening to all is explicit and needs measured pilot evidence."}
+ - {"key": "CONVERSATIONS_V3_MULTIPART_RECLAIM", "aliases": [], "kind": "env", "lifecycle": "config_switch", "surfaces": ["backend"], "summary": "Default off; allow the bounded v3 sweep to remove expired, unreferenced transcript parts.", "fail": "closed", "owner": "Goal: Pipeline", "created": "2026-12-01", "terminal": "keep", "decision": "keep", "notes": "SCA-5779. Requires multipart writes, index readiness, serving bounded readers on every role, drainage of older readers, and Release approval. Switch off to stop reclamation."}
- {"key": "CONVERSATIONS_V3_SIZE_QUARANTINE", "aliases": [], "kind": "env", "lifecycle": "ops_kill", "surfaces": ["backend"], "summary": "Default on. A one-seed v3 pass Firestore rejects for size sets the seed and the pending sources its rejected commit writes aside so the rest of the backlog drains.", "fail": "open", "owner": "Goal: Pipeline", "created": "2026-11-26", "terminal": "keep", "decision": "keep", "notes": "SCA-2918. Closures still load quarantined rows; only seeding, the pass chain and the sweep skip them, for 24 h per id. Set off on live builders to restore head-of-line retries; stored v3_size_quarantine ids are then ignored. See backend/docs/runbooks/conversations-v3.md."}
</file context>
| - {"key": "CONVERSATIONS_V3_MULTIPART_WRITE_COHORT", "aliases": [], "kind": "env", "lifecycle": "config_switch", "surfaces": ["backend"], "summary": "Unset denies v3 multipart publication. Rollout cohort for oversized transcript writes.", "fail": "closed", "owner": "Goal: Pipeline", "created": "2026-12-01", "terminal": "keep", "decision": "keep", "notes": "SCA-5779. Uses the existing cohort grammar. Release binds an isolated cohort for the pilot. Widening to all is explicit and needs measured pilot evidence."} | |
| - {"key": "CONVERSATIONS_V3_MULTIPART_WRITE_COHORT", "aliases": [], "kind": "env", "lifecycle": "rollout", "surfaces": ["backend"], "summary": "Unset denies v3 multipart publication. Rollout cohort for oversized transcript writes.", "fail": "closed", "owner": "Goal: Pipeline", "created": "2026-12-01", "terminal": "undecided", "decision": "pending", "review_by": "2026-12-15", "ramp": {"cohorts": ["isolated pilot cohort bound by Release", "widen to all only after measured pilot evidence"], "clean_metric": "multipart publication errors and reconcile latency flat versus the single-document path", "expander": "Goal: Pipeline", "done_by": "2026-12-15"}, "notes": "SCA-5779. Uses the existing cohort grammar. Release binds an isolated cohort for the pilot. Widening to all is explicit and needs measured pilot evidence."} |
|
|
||
|
|
||
| def _open_part(uid: str, cid: str, value: str | bytes) -> bytes: | ||
| from utils.encryption import derive_key |
There was a problem hiding this comment.
P3: New _open_part imports derive_key inside the function. Move it to the module import block, or note the import cycle that prevents it.
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/database/transcript_multipart.py, line 138:
<comment>New `_open_part` imports `derive_key` inside the function. Move it to the module import block, or note the import cycle that prevents it.</comment>
<file context>
@@ -44,11 +125,33 @@ def part_id(blob):
+
+
+def _open_part(uid: str, cid: str, value: str | bytes) -> bytes:
+ from utils.encryption import derive_key
+
+ if not isinstance(value, bytes) or len(value) < _MIN_ENCRYPTED_BODY_BYTES:
</file context>
| | `CONVERSATIONS_V3_FAST_FINISH_LONG_DAILY_SECONDS` | Default 7200; provider audio seconds (retries, chunk overlaps and the language probe included) of manual finishes over 20 minutes that the whole fleet may send through the chunked fast first transcript per UTC day (one shared Redis counter per day); past it, or when Redis cannot answer, a long pass is skipped as long_cap (or a chunk retry as retry_cap) and batch delivers. Invalid values read as 0. | backend | env | closed | — | — | {value: '1000000000', category: config} (cloud_run/backend-integration); {value: '7200', category: config} (cloud_run/backend-projection-pump) | — | keep | keep | — | Goal: Pipeline | | ||
| | `CONVERSATIONS_V3_FIRST_APP_BUILD` | First released v3 mobile build; missing/invalid reports unknown and cannot qualify the episode deletion gate | backend | env | closed | — | valueFrom (backend-listen (chart), pusher (chart)) | valueFrom (backend-listen (chart), pusher (chart)) | — | keep | keep | — | lane/conversations-v3 / lead2 | | ||
| | `CONVERSATIONS_V3_LOCK_SECONDS` | Default 300 seconds, bounded 120–3600; controls the v3 elapsed time before locking and queuing notes | backend | env | closed | — | — | — | — | keep | keep | — | v3-rollout coordinator | | ||
| | `CONVERSATIONS_V3_MULTIPART_RECLAIM` | Default off; allow the bounded v3 sweep to remove expired, unreferenced transcript parts. | backend | env | closed | — | — | — | — | keep | keep | — | Goal: Pipeline | |
There was a problem hiding this comment.
P3: The CONVERSATIONS_V3_MULTIPART_RECLAIM row omits its prerequisites. Reclamation is effective only when CONVERSATIONS_V3_MULTIPART_WRITES and a non-empty CONVERSATIONS_V3_MULTIPART_WRITE_COHORT are also set. Add that to the summary, since this flag deletes transcript parts.
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/feature-flag-registry.md, line 817:
<comment>The `CONVERSATIONS_V3_MULTIPART_RECLAIM` row omits its prerequisites. Reclamation is effective only when `CONVERSATIONS_V3_MULTIPART_WRITES` and a non-empty `CONVERSATIONS_V3_MULTIPART_WRITE_COHORT` are also set. Add that to the summary, since this flag deletes transcript parts.</comment>
<file context>
@@ -814,7 +814,9 @@ and an explicit empty literal renders as `''`.
| `CONVERSATIONS_V3_FAST_FINISH_LONG_DAILY_SECONDS` | Default 7200; provider audio seconds (retries, chunk overlaps and the language probe included) of manual finishes over 20 minutes that the whole fleet may send through the chunked fast first transcript per UTC day (one shared Redis counter per day); past it, or when Redis cannot answer, a long pass is skipped as long_cap (or a chunk retry as retry_cap) and batch delivers. Invalid values read as 0. | backend | env | closed | — | — | {value: '1000000000', category: config} (cloud_run/backend-integration); {value: '7200', category: config} (cloud_run/backend-projection-pump) | — | keep | keep | — | Goal: Pipeline |
| `CONVERSATIONS_V3_FIRST_APP_BUILD` | First released v3 mobile build; missing/invalid reports unknown and cannot qualify the episode deletion gate | backend | env | closed | — | valueFrom (backend-listen (chart), pusher (chart)) | valueFrom (backend-listen (chart), pusher (chart)) | — | keep | keep | — | lane/conversations-v3 / lead2 |
| `CONVERSATIONS_V3_LOCK_SECONDS` | Default 300 seconds, bounded 120–3600; controls the v3 elapsed time before locking and queuing notes | backend | env | closed | — | — | — | — | keep | keep | — | v3-rollout coordinator |
+| `CONVERSATIONS_V3_MULTIPART_RECLAIM` | Default off; allow the bounded v3 sweep to remove expired, unreferenced transcript parts. | backend | env | closed | — | — | — | — | keep | keep | — | Goal: Pipeline |
| `CONVERSATIONS_V3_MULTIPART_WRITES` | Default off; publish oversized v3 transcripts in bounded Firestore parts. | backend | env | closed | — | — | — | — | keep | keep | — | Goal: Pipeline |
+| `CONVERSATIONS_V3_MULTIPART_WRITE_COHORT` | Unset denies v3 multipart publication. Rollout cohort for oversized transcript writes. | backend | env | closed | — | — | — | — | keep | keep | — | Goal: Pipeline |
</file context>
| | `CONVERSATIONS_V3_MULTIPART_RECLAIM` | Default off; allow the bounded v3 sweep to remove expired, unreferenced transcript parts. | backend | env | closed | — | — | — | — | keep | keep | — | Goal: Pipeline | | |
| | `CONVERSATIONS_V3_MULTIPART_RECLAIM` | Default off; allow the bounded v3 sweep to remove expired, unreferenced transcript parts. Requires CONVERSATIONS_V3_MULTIPART_WRITES on and a non-empty CONVERSATIONS_V3_MULTIPART_WRITE_COHORT. | backend | env | closed | — | — | — | — | keep | keep | — | Goal: Pipeline | |
|
|
||
|
|
||
| def _plan_multipart_processing(tx, user, ref, payload, existing): | ||
| from database.recurring_voice_privacy import filter_processing_write |
There was a problem hiding this comment.
P3: These new production imports are inside functions instead of the module import block. Move them to the top-level imports so the backend import policy and static dependency checks remain consistent.
(Based on your team's feedback about backend imports at module scope.) .
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/database/conversations.py, line 1046:
<comment>These new production imports are inside functions instead of the module import block. Move them to the top-level imports so the backend import policy and static dependency checks remain consistent.
(Based on your team's feedback about backend imports at module scope.) .</comment>
<file context>
@@ -1037,6 +1042,40 @@ def _stage_notes_identity(transaction, user_ref, write_data, existing):
+def _plan_multipart_processing(tx, user, ref, payload, existing):
+ from database.recurring_voice_privacy import filter_processing_write
+
+ _, people = _stage_notes_identity(tx, user, payload, existing, defer=True)
</file context>
|
FULL ROUND: critical:data-loss: review newly changed Notes commit and bounded reader behavior |
…d-lifetime # Conflicts: # backend/docs/feature-flag-registry.md # backend/utils/conversations/v3/service.py
…multipart-read-lifetime # Conflicts: # backend/database/conversations_v3.py
Two conflicts with #26847 (bounded multipart reads and part retirement), both in the projection commit. conversations_v3.py: the planned part-retirement field is dropped in staged_row, the helper the tombstone_check_written_rows decision and the write loop share, so both see the row main's loop wrote. firestore_query_driver_registry.py: the commit's body digest is pinned again and both re-review notes kept. test_conversations_v3_fewer_requests.py follows main: the multipart switch takes the uid, and the staged manifest and the prior manifest are in the shape part retirement reads. Failure-Class: none
…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)
Changes
Carry a 30-second multipart transcript read budget through Firestore part reads, decoding, the decoded cache, and deferred v3 builder hydration and memoized sync redirects. MCP verifies the current parent and account deletion marker in one bounded batch before exposing multipart speech. Where a list or agent read already has a document budget, its child reads consume that allowance. Export refreshes only an expired multipart parent, at most once, and fails the export if that fresh read cannot finish.
Use authenticated encryption on compressed bytes for new multipart tails and bodies at both protection levels. Continue reading the prior compressed bytes and encrypted strings. Keep the current encrypted references through a protection-level change. Lifecycle processing, speaker assignment, late speaker repair, final-pass promotion, and translation materialization use a fenced transaction to publish their changed parts while retaining unchanged parts. With publication off, manual speaker assignment returns its existing HTTP 409, and segment updates and final-pass promotion return their established refusal value.
Notes-only processing preserves the existing transcript. A Notes transaction that stages People changes also increments the owner generation in the same commit. That adds one write and no reads for a transaction with People changes. Meeting evidence shares the caller's deadline through queueing, the parent read, and part hydration. An unavailable retirement sweep leaves later scheduled work eligible to run.
Speaker edits plan their multipart reads before staging effects. The final protected receipt carries the durable label evidence and learning markers from those effects in the same commit as the manifest and People updates.
Queue superseded part IDs transactionally with the updated manifest. The v3 sweep scans at most eight due markers per run and uses an encrypted shared checkpoint to advance past a full page of parked markers across instances. The checkpoint adds one read and at most one committed write per enabled sweep, and no work while off. Discovery returns up to eight marker documents, has a one-read minimum, and can add index-entry charges. Each candidate uses three document reads. An edit that supersedes sealed parts adds one marker read per transaction attempt and one marker write on commit. It can delete at most 32 documents per eligible marker, including the marker when it drains. Existing account erasure covers the marker under the same subcollection. Multipart publication excludes backfill undo candidates. Both rollout flags default off, and publication requires an explicit owner cohort.
Verification
The flags stay off through code delivery. Before pilot writes, Release must verify the codec-capable image set across the affected roles, drain older revisions, verify the same writer and cohort settings across all affected mutation roles, rehearse the all-off rollback, and confirm exact Firestore index query charges. Earlier images cannot read the compact envelope.
Line-Count-Exception: backend/database/conversations.py | 5899 -> 6157 | fence multipart edits, charge child reads, and verify owner and revision at the existing conversation boundary
Line-Count-Exception: backend/database/conversations_v3.py | 2807 -> 2867 | stage bounded retirement records in the existing transaction and preserve deferred hydration deadlines
Line-Count-Exception: backend/database/firestore_index_registry.py | 2423 -> 2427 | register the due index and marker field exemption with the manifest generator
Line-Count-Exception: backend/utils/conversations/v3/service.py | 2417 -> 2429 | isolate gated sweep errors and preserve the size path for backfill lineage
Product invariants affected