Skip to content

feat(conversations-v3): per-owner backfill and repair runs with live parity and exact undo - #25686

Merged
Git-on-my-level merged 18 commits into
mainfrom
lane/v3-owner-backfill
Nov 18, 2026
Merged

Git-on-my-level merged 18 commits into
mainfrom
lane/v3-owner-backfill

Conversation

@Git-on-my-level

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

Copy link
Copy Markdown
Member

Summary

This turns the conversations v3 backfill into a per-owner repair tool. It re-derives one owner's legacy pendant and phone conversations for a configurable window (default 2 days) through the live v3 builder and notes path. The legacy rows stay intact and an exact undo is available. Requested 2026-11-18 for spot-checking v3 on a named account. Built as the reusable per-owner repair tool from the scope addition, not as a one-off script.

  • Window and scale. The operator plans one owner and one window from an owners file. Partitions are cut at five-minute silences (the live hard boundary) and hold at most 48 documents. A plan needing a forced cut inside a gap-free run reports it as forced_cuts. An overfull partition blocks with a reason. The window is never partially converted silently.
  • Run ledger. users/{uid}/conversations_v3_backfill_runs/{run_id} records operator, window, planned and served code SHA, per-partition counts and outcome. It holds no user content. It makes runs resumable and idempotent, and undo targets a run.
  • Isolation. The five-minute sweep starts a planned run only when CONVERSATIONS_V3_BACKFILL=on. Each partition then runs as one task on a new conversations-v3-backfill queue with one dispatch at a time. Derive passes use their own backfill-builder lease and notes marker (v3_backfill_process_pending), so they never make the owner's live builder busy and never ride the live queue or sweep.
  • Accuracy. Backfilled notes now take the live CAPTURE_END path. The old path used SILENT_BACKFILL, which kept every row, skipped speakers and meeting context, added recovery guards and only wrote notes above 600 words. process_conversation withholds only the derived effects for v3_derived && backfilled rows.
  • Non-destructive and reversible. Legacy structured notes and summaries are kept. The donor stores the prior value of every field the conversion touches (v3_backfill_prior). undo --run restores donors exactly, then deletes the derived rows, with no tombstones and no audio changes. Deleting a backfilled copy in the app never arms the donor's audio purge, which fixes a latent data-loss path.
  • Re-derive mode. It rebuilds rows that were already backfilled after a pipeline fix. Ids are reused through adoption, with no delete-and-recreate. Copies that no rebuilt window claims are retired in the same commit.
  • Runbook. A new "Backfill and repair (per owner)" section in backend/docs/runbooks/conversations-v3.md, plus a change note.

Scope choice: the full repair tool (owners file, ledger, resume, re-derive, runbook). Nothing from the scope addition was deferred. Re-derive does not keep edits made to backfilled copies, which is documented.

Home choice. During a spot check, Home shows the v3 rows and hides the legacy rows: donors become recording=True with backfill_superseded, and their notes are kept. There are no duplicate cards. A legacy row that is opened by id 404s like any recording until undo. Memories and tasks that point at a legacy conversation keep pointing at it.

Accuracy: each live step vs the derive path

Live v3 step Derive applies it? Gap and effect
Source eligibility (omi/phone, completed, not private, deleted, merged or locked) Yes, plus legacy-specific skips: discarded, imported, unreadable, and rows no window claims. Skipped rows stay as visible legacy conversations. The dry-run counts each class, and the ledger counts sources_unclaimed.
Capture: transcript segments (STT, VAD-gated speech) Uses the persisted legacy transcript. Legacy rows were transcribed by the legacy pipeline. Capture and STT are not re-run, so a missing transcript is not treated as silence.
Capture: duplicate-capture removal and deleted_spans Yes (outline.stretches). None.
Capture: wearer recognition (is_user on segments, speaker-evidence projection) Yes, same visibility.hydrate_recognition. Evidence is keyed by the legacy conversation id. Rows with no evidence and no is_user fall into the live "uncertain → conversation" rule, the same as live. The dry-run counts wearer-labelled sources.
Capture: language Yes (language of the first source). None.
Capture: media/noise classification (content_kind, MEDIA_NOISE_MODE) Yes, it runs in the notes path on the derived row, as live. Writes boundary signals for historical times, as live does. The 7-day boundary-store retention can make older windows classify differently.
Capture: short-clip floor (quiet_minimum, short_clip_relevance) Yes, same trigger (CAPTURE_END, ASSESS). Fixed in this PR. It previously used SILENT_BACKFILL (KEEP) and a 600-word floor.
Planner: five-minute SILENCE hard boundary, two-hour cap, resumes_previous Yes, the same planner. Partitions are cut only at gaps ≥ five minutes. A gap-free run over 48 documents is a counted forced_cut. The run-window edges (since/until) can also split a stretch.
Planner: manual end (v3_manual_end cut, manual-end visibility, full notes) Yes, mapped from the legacy relevance_decision.trigger == client_finalize. Legacy rows without that record are treated as silence-ended. Such a manual stop under 300 words would be hidden as below_word_minimum instead of shown. The dry-run counts manual_end_sources.
Outline: prompt, model (conversation_v3_outline, Luna), context block (profile, people, earlier titles) Yes. Context is read as of the backfill time, not the capture time: the current profile and people, and earlier titles of rows already derived that day.
Home visibility (media, background_wearer_recognized, below_word_minimum, wearer_recognition_uncertain, manual_end) Yes, the same visibility.project. None. A parity test covers each reason.
Notes: _process floors (media/background none, <20 words none, 20–299 task-only, ≥300 notes) Yes. Fixed in this PR (it was <600 → none).
Notes: models and prompts (conversation_v3_summary Luna/low, agentic notes ≥1500 words), require_current_generated_compute, funded-processing checks Yes. Same functions and same entitlement checks against the owner. Usage counts against the owner's usage tracker, as live does.
Notes: relevance, speaker resolution, meeting context, summary context (v3_context.summary) Yes (CAPTURE_END). Memories and profile are read as of now. They can include memories that legacy processing extracted from the same conversation.
Derived effects (memories, tasks, apps, folders, vectors, notifications, duplicate links, owner-recognition telemetry) Withheld (historical seam, terminal_no_derived_effects). Intentional: legacy processing already produced these for the same speech.
Created webhooks (v3_created_pending, created.deliver) Off. policy.created_eligible excludes backfilled. A live pass over an interrupted backfill's donors also stamps backfilled. Intentional.

Verification: test_derive_pass_matches_the_live_builder_on_the_same_inputs runs 8 synthetic scenarios through a live pass and a derive pass. It requires identical committed rows (ids, windows, kind, home_hidden/reason, segments, structured, claims) except the backfill stamps and the notes marker. test_v3_backfilled_window_takes_the_live_notes_trigger_but_no_derived_effects and test_backfilled_rows_take_the_live_trigger_and_floor cover the notes seam.

Cost estimate (one owner, 2 days)

Rates are from the gateway Luna card openai.gpt-6-luna.2026-09-22: $0.10/M in, $0.60/M out. Agentic notes are capped at $0.02 per conversation.

  • The brief gives about 762 legacy rows in 2 days (not re-measured here). Merging at five-minute silences gives roughly 250–400 stretches, so about 250–400 outline calls: about $0.05–0.15.
  • Notes: roughly 60–120 windows of 300 words or more (about $0.10–0.25 one-shot, plus up to about $0.40 for up to about 20 agentic windows). Roughly 80–150 task-only calls: about $0.02–0.05.
  • Total: about 400–700 LLM calls, about $0.5–1.5. Planning ceiling: $3.

run --dry-run prints the exact per-owner figure from the real partition loads: stretches, outline calls, notes, agentic and task-only calls, and USD. Gateway usage has the actual spend.

Operator commands (prod-operator tier; the coordinator runs these after merge, with David's go-ahead)

S=backend/scripts/conversations_v3_backfill.py; O=/path/to/owners.txt   # one uid per line, chmod 600
PYTHONPATH=backend backend/.venv/bin/python $S run --owners-file $O --days 2 --dry-run   # counts + estimate, writes nothing
PYTHONPATH=backend backend/.venv/bin/python $S run --owners-file $O --days 2             # needs CONVERSATIONS_V3_BACKFILL=on; waits
PYTHONPATH=backend backend/.venv/bin/python $S status --owners-file $O
PYTHONPATH=backend backend/.venv/bin/python $S undo --owners-file $O --run RUN_ID --dry-run
PYTHONPATH=backend backend/.venv/bin/python $S undo --owners-file $O --run RUN_ID

Before the first run, two things must be in place:

  • Queue: the conversations-v3-backfill queue from backend/deploy/ops/prod.yaml must exist. The prod config train currently fails WIF, so the coordinator creates the queue by hand from these exact values.
  • Route switch: CONVERSATIONS_V3_BACKFILL=on is now in the prod overlay for backend-sync only, added by the coordinator. It only allows operator-planned runs: the five-minute sweep starts nothing unless an operator planned a run, and with no planned run nothing happens.

Rollback for the switch: set it back to off in the overlay, or gcloud run services update backend-sync --update-env-vars CONVERSATIONS_V3_BACKFILL=off followed by update-traffic.

Product invariants affected

  • INV-MEM-4 (also runtime_env.yaml: adds CONVERSATIONS_V3_BACKFILL=on for prod backend-sync): backfilled v3 rows take no memory intake. process_conversation returns at the historical seam before extraction, the same as silent backfill. Canonical promotion is unchanged.
  • INV-TASK-2: backfilled v3 rows write no tasks or Candidates. The derived-effects return happens before any action-item path, and task-only notes store their extraction only inside the row's structured, the same as live v3 short windows.

Failure-Class: FC-irreversible-terminal-hide

Line-Count-Exception: backend/utils/conversations/process_conversation.py | 3508 -> 3513 | the historical seam must sit inside process_conversation's derived-effects return path; it reuses the existing silent-backfill branches

Review

omi-panel review-20261118t112231-b18f (luna, glm-flash; deepseek returned empty): 12 findings, all accepted and fixed in fix(conversations-v3): answer the backfill panel review. The fixes:

  • Unclaimed donors stay legacy.
  • Start markers are under users/{uid}, so account deletion purges them.
  • No new run while a blocked run exists.
  • Redelivery re-dispatches a lost successor.
  • Re-derive refuses mixed-run windows.
  • A refused undo is recorded.
  • Missing runs exit 1.
  • A stopped drain reports stopped.
  • The cost-model test is added.
  • The partition-gap caveat is documented.

Test plan

  • New tests/unit/test_conversations_v3_backfill.py (46 tests): the live-vs-derive parity matrix, partition boundaries against outline.stretches, loader classification, resume and re-derive, non-destructive conversion with exact undo on StrictFirestore, the audio-purge guard, the notes-marker settle, drain, the task chain (derive → drain → next, blocked, busy → 503, stopped run), sweep start inert while the switch is off, resume, undo ordering and in-flight refusal, and an operator dry-run that writes nothing and prints no uid.
  • test_process_conversation_free_tier_branch.py: a backfilled v3 window takes the live trigger and gets no derived effects.
  • Updated the v3 transactions, review and conflict suites, the runtime env validator, the Firestore query-shape drivers (615 pass), query contract and index rules, the collection-budget check, the reader inventory, the lifecycle write guard, the async-blocker scan, config-train and service-selection tests.
  • Not run: the Firestore emulator and production. The coordinator runs the dry-run and then the run on the named account after merge.

🤖 Generated with Claude Code

Git-on-my-level and others added 18 commits November 18, 2026 17:48
…parity and exact undo

Turn the v3 backfill into a reusable per-owner repair tool:

- Operator plans one owner + window (default 2 days) from an owners file;
  partitions cut at five-minute silences; run ledger with counts, code SHA
  and outcome; the sweep starts planned runs only when
  CONVERSATIONS_V3_BACKFILL=on; one step at a time on a dedicated
  conversations-v3-backfill queue.
- Derive passes hold their own backfill-builder lease and notes marker, so
  they never make the live builder busy or ride the live queue/sweep.
- Backfilled notes take the live CAPTURE_END path (relevance, speaker
  resolution, meeting context, live floors); process_conversation withholds
  only derived effects for v3 backfilled rows.
- Non-destructive conversion: legacy notes kept, prior field values recorded,
  undo restores donors exactly and removes derived rows; deleting a
  backfilled copy never arms the donor audio purge.
- Resume and re-derive reuse ids by adoption; legacy manual stops map to the
  v3 manual end; discarded/imported/private/unreadable rows stay legacy.

Failure-Class: FC-irreversible-terminal-hide

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…view

Count live-writer terminal failures as failed, keep a start-marker read error
from failing the live sweep, resume a run whose start marker was lost, and
rename the live backoff local that shadowed the window bound.

Failure-Class: FC-irreversible-terminal-hide

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…cker

Failure-Class: FC-irreversible-terminal-hide

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…bind historical in the hook harness

Revert the fixture change (other suites assert the stored sentinel) and compare
the restored donor as Firestore would store it.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
- A legacy row no derived window claims stays a visible legacy conversation
  (counted as sources_unclaimed) instead of being hidden with no replacement.
- Start markers move under users/{uid} so account deletion purges them; the
  sweep reads them with a bounded collection-group list.
- The operator refuses a new run while one is blocked; undo/resume exit 1
  when no listed owner has the run.
- A redelivered committed partition re-dispatches a lost successor (named
  task, so a duplicate is a no-op).
- Re-derive blocks (rederive_mixed_runs) rather than merge rows from two
  runs, keeping undo run-scoped.
- A refused undo records its reason; a drain stopped mid-way reports stopped.
- classify_window reports legacy_candidates; the cost model has a test;
  the runbook documents the row-level partition-gap caveat.

Failure-Class: FC-irreversible-terminal-hide

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…telemetry

Backfilled v3 rows skip owner-recognition telemetry and capture-loss
accounting; legacy processing already observed the same speech.

Failure-Class: FC-irreversible-terminal-hide

Co-Authored-By: Claude Opus 5.5 <[email protected]>
The run ledger's run/partition status, the re-derive reset of a prior
backfilled copy, and undo's donor restore are reviewed entries in the
lifecycle writer inventory (restore is a backfill-lease-fenced extra writer).

Failure-Class: FC-irreversible-terminal-hide

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…the test

The file-isolated runner charged the cold database.home_feed import to the
first feed-read case's call phase, which crossed the 1.00s CPU guard on CI.

Failure-Class: FC-irreversible-terminal-hide

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…ed after #25050)

Failure-Class: none

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…prod backend-sync

Failure-Class: none

Co-Authored-By: Claude Opus 5.5 <[email protected]>
#25679 bound BATCH_PIPELINE_MERGE_STALE_HEAD_UID_ALLOWLIST as a literal in the
prod backend-integration overlay. test_rollout_cohort_deploy's contract is
that the Cloud Run manifest omits private uid bindings so deploys keep the
live value (gcloud preserves undeclared env), so main's backend unit suite
went red. Remove the literal and its known-gaps exception; the uid is bound
on the service at deploy time.

Unchanged: the test, #25673's skip code, #25679's regression case, and the
GPU worker Helm value. Helm is declarative, so omitting it there would drop
the canary on the next upgrade instead of preserving it; that literal keeps
its reviewed no-uid-literals exception.

Failure-Class: none
Co-Authored-By: Claude Opus 5.5 <[email protected]>
…h both builders

- A donor whose backfilled copy the owner deleted (a post-run deleted span, or
  no claim left) is kept converted, with every copy it shares and their donors;
  the restore transaction re-checks, and a deletion that races undo is kept.
- Undo holds the backfill and live builder leases before it enumerates the
  run, so no pass commits or stamps a row while it restores and deletes.
- A converted donor that no longer reads blocks the partition
  (backfill_source_unreadable) instead of retiring its only copy.
- undo on a re-derive run id names the original run and exits 1; the dry-run
  counts donors the owner deleted; classification splits not-completed rows.

Failure-Class: FC-irreversible-terminal-hide

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@Git-on-my-level
Git-on-my-level merged commit 9c88e7f into main Nov 18, 2026
64 checks passed
@Git-on-my-level
Git-on-my-level deleted the lane/v3-owner-backfill branch November 18, 2026 15:11
Git-on-my-level added a commit that referenced this pull request Nov 19, 2026
## Summary

Generate port task drafts when a merged Python PR changes finalization
or batch behavior. The map covers all 34 finalization and 41 batch
runtime Python sources cited by the [landed
contracts](#25802), plus
imported family policy and implementation. The [scope
document](https://github.com/BasedHardware/omi/blob/9554967bf78fab4d18b1504a7ef19b31e46141af/backend-go/docs/port-map-scope.md)
records the boundaries and exclusions. The PR branch includes `main` at
contracts merge `97b4059861a7`. The batch map includes the projection
kill-switch defaults introduced upstream in #25791.

The Backend Go Checks workflow runs the Python suite when these files
change in a PR. On each main push, it walks the pushed first-parent
merge commits, looks up their merged main PRs, and checks the complete
paginated file list against GitHub's `changed_files` count before
drafting. The CLI also rejects duplicate filenames in a counted input
and uses both sides of renames. The job prints JSON and uses read-only
permissions. Tracker writes are outside this change. [Commit-to-PR
API](https://docs.github.com/en/rest/commits/commits#list-pull-requests-associated-with-a-commit)
· [PR files
API](https://docs.github.com/en/rest/pulls/pulls#list-pull-requests-files)

## Verification

- Nine focused tests exercise family matching, renames, duplicate or
truncated file lists, malformed inputs, task text, existence of every
mapped file, and coverage of the checked-in batch contract. Run `python3
-m unittest discover -s .github/scripts -p test_go_port_tasks.py -v`.
- `actionlint .github/workflows/backend-go-checks.yml` passed. Ran the
workflow's push steps locally over three real first-parent merges and
verified Go test selection on Go and Python-only ranges.
- `cd backend-go && TEST_FIRESTORE_REQUIRED=1 make check` passed with
Postgres 16 and the Firestore emulator.
- Compared both map families to every runtime Python citation in the
landed contracts. Replaying merged PR #25791 also matched the new batch
projection kill switch.
- Repository preflight and `gh pr checks 25810 --watch` passed at head
`9554967bf7`. Local preflight skipped the 90-day failure-class ratchet
because the checkout is shallow. [Backend Go
Checks](https://github.com/BasedHardware/omi/actions/runs/44627579785)

## Product invariants affected

none

## Examples from merged PRs

```bash
count=$(gh api "repos/BasedHardware/omi/pulls/$PR" --jq .changed_files)
gh api --paginate --slurp "repos/BasedHardware/omi/pulls/$PR/files?per_page=100" |
  jq 'add' | python3 .github/scripts/go_port_tasks.py --pr "$PR" --changed-files "$count"
```

### PR #25771

```json
[
  {
    "family": "finalization",
    "title": "Port Python PR #25771 to Go finalization",
    "body": "Python PR [#25771](#25771) changed `backend/database/conversations.py`, `backend/models/conversation.py`, `backend/utils/conversations/process_conversation.py`, `backend/utils/conversations/render.py`, `backend/utils/conversations/v3/policy.py`. Review the merged diff and port any behavior changes to the Go finalization family under `backend-go/`. Add or update parity coverage for the changed behavior, or record why the Go port needs no change.",
    "matched_paths": [
      "backend/database/conversations.py",
      "backend/models/conversation.py",
      "backend/utils/conversations/process_conversation.py",
      "backend/utils/conversations/render.py",
      "backend/utils/conversations/v3/policy.py"
    ]
  }
]
```

### PR #25755

```json
[
  {
    "family": "finalization",
    "title": "Port Python PR #25755 to Go finalization",
    "body": "Python PR [#25755](#25755) changed `backend/config/merge_before_processing.py`, `backend/models/conversation.py`, `backend/models/structured.py`, `backend/utils/conversations/deterministic_minimum.py`, `backend/utils/conversations/empty_structure_minimum.py`, `backend/utils/conversations/fragment_visibility.py`, `backend/utils/conversations/historical_minimum.py`, `backend/utils/conversations/home_titles.py`, `backend/utils/conversations/merge_conversations.py`, `backend/utils/conversations/process_conversation.py`, `backend/utils/conversations/processing_trigger.py`, `backend/utils/conversations/relevance_salience.py`, `backend/utils/conversations/summary_delivery.py`, `backend/utils/conversations/sync_hold_completion.py`, `backend/utils/episodes/member_notes.py`, `backend/utils/llm/notes_short_clip_policy.py`. Review the merged diff and port any behavior changes to the Go finalization family under `backend-go/`. Add or update parity coverage for the changed behavior, or record why the Go port needs no change.",
    "matched_paths": [
      "backend/config/merge_before_processing.py",
      "backend/models/conversation.py",
      "backend/models/structured.py",
      "backend/utils/conversations/deterministic_minimum.py",
      "backend/utils/conversations/empty_structure_minimum.py",
      "backend/utils/conversations/fragment_visibility.py",
      "backend/utils/conversations/historical_minimum.py",
      "backend/utils/conversations/home_titles.py",
      "backend/utils/conversations/merge_conversations.py",
      "backend/utils/conversations/process_conversation.py",
      "backend/utils/conversations/processing_trigger.py",
      "backend/utils/conversations/relevance_salience.py",
      "backend/utils/conversations/summary_delivery.py",
      "backend/utils/conversations/sync_hold_completion.py",
      "backend/utils/episodes/member_notes.py",
      "backend/utils/llm/notes_short_clip_policy.py"
    ]
  }
]
```

### PR #25686

```json
[
  {
    "family": "finalization",
    "title": "Port Python PR #25686 to Go finalization",
    "body": "Python PR [#25686](#25686) changed `backend/utils/conversations/lifecycle.py`, `backend/utils/conversations/process_conversation.py`, `backend/utils/conversations/v3/policy.py`, `backend/utils/conversations/v3/service.py`, `backend/utils/conversations/v3/triggers.py`. Review the merged diff and port any behavior changes to the Go finalization family under `backend-go/`. Add or update parity coverage for the changed behavior, or record why the Go port needs no change.",
    "matched_paths": [
      "backend/utils/conversations/lifecycle.py",
      "backend/utils/conversations/process_conversation.py",
      "backend/utils/conversations/v3/policy.py",
      "backend/utils/conversations/v3/service.py",
      "backend/utils/conversations/v3/triggers.py"
    ]
  }
]
```
Git-on-my-level added a commit that referenced this pull request Nov 26, 2026
…ount deletion (#25703)

## Summary

Follow-up to #25686. It merged at 2c5a581 while omi-panel
`review-20261118t145557-1937` was still running on that head, and that
review came back FIX-FIRST. This PR fixes its findings in the backfill
drain, undo, re-derive and the operator script. Undo has to be
verifiable before the first owner run, so these fixes gate the run.

- **Account deletion stops the backfill drain** (F1, blocking).
`drain_backfill` checks the account-deletion marker before each notes
chunk. Once deletion starts, no transcript goes to the notes model, and
the step marks the run blocked with reason `account_deletion`.
- **Undo works one connected group per transaction** (F3, F4, F10). A
group is the donors plus the copies that claim them. In one transaction,
undo reads the group's donors, copies and the copies' deletion
tombstones. It then either restores the donors exactly and deletes the
copies, or keeps the whole group as backfilled v3. It keeps the group
when the owner deleted a copy, shown by a tombstone or by a donor
deleted span added after the run.
- A delete racing undo can no longer resurface a legacy row. The
tombstone is written before the claim release and is read inside the
transaction.
  - Nothing is hidden or shown twice partway through.
- A donor with no claim and no new span is restored. Its copy never
committed (an interrupted run) or a re-derive retired it. The previous
version wrongly kept it hidden.
- A kept copy's owed backfill notes move to the live notes marker. The
owner's next live builder pass writes them, so an owner with no further
capture or app open keeps them pending until then.
- **Re-derive** (F5, F6). A donor this run already converted that no
rebuilt window claims now blocks the partition
(`backfill_donor_unclaimed`) instead of staying hidden with no copy. A
re-derived prior copy no longer inherits a stale notes marker.
- **Operator** (F7, F8). One owner's blocked plan prints `owner[N]
blocked: <reason>`, the script continues with the other owners, and it
exits 1. Blocked reasons include an overfull partition, account
deletion, an unreadable source and an existing run.
- **Partitions** (F11). A gap-free run over the cap is now cut at the
latest of equal gaps, so partitions fill up. Before, every row became
its own partition with its own outline call.
- **Telemetry scope** (F9). Only backfilled v3 copies skip capture-loss
and owner-recognition telemetry. Silent-backfill recovery keeps both, as
on main before #25686.
- **Flag notes** (F12). The `CONVERSATIONS_V3_BACKFILL` registry notes
now state the prod backend-sync value and the operator-only gating.

Later review rounds on this PR (`review-20261118t171612-b1c4` through
`review-20261118t223845-273f`) added these fixes:

- **Account-deletion checks.** The drain checks the deletion marker
before each batch and row. At model admission, a single-attempt
Firestore transaction reads the same customer-data marker that deletion
intent writes. This covers both task-only and full notes for backfilled
v3 copies. If deletion wins after the row check, the drain releases the
lease, preserves the owed notes marker, and blocks the run without
incrementing its backfill retry count. The derive loader and the drain
read the marker fresh, past the 30-second negative cache, and the fresh
read keeps the check metrics.
- **Undo, per group:**
- The group transaction refuses while any copy holds a notes lease
(`notes_in_flight`).
- It records undo progress in the run ledger in the same transaction
(totals and removed copy ids), so a crash or retry loses nothing.
- **Undo, owner deletions:**
- Deleting a backfilled copy records its id on the legacy row even when
other claims cover the interval, so undo always sees it.
  - A deleted copy never goes to the notes model.
- Copies deleted in the instant undo removed them are listed as
`deleted_during_undo_ids`.
- **Undo, read bound.** A copy a donor names only by a post-run deleted
span or a recorded deleted copy still links the group but is not read,
because that donor already keeps the group. Old deletions therefore
never push a group over the read bound. Undoing a run that is already
`undone` or `undone_partial` reports its record and changes nothing.
- **Undo, status.** A run with kept groups or a raced delete ends
`undone_partial` (exit 1). The group size bound counts reads, not
documents. An undo that fails partway still checks the copies it already
removed for a racing delete and records them in the error.
`donors_kept_deleted` counts only converted donors that stayed hidden.
- **Re-derive and operator.**
  - Re-derived copies start a fresh notes retry budget.
- Only a re-derive blocks on an unclaimed converted donor; a resume
carries on.
- The operator script reports only Conflicts and an existing run (the
typed `BackfillRunExists`) as a blocked owner, and an owner skipped for
an active run sets exit 1.
- Undo renews its leases inside the per-group error handling, so a lease
lost on renew writes the same error record as a failed group.

From the 18:30Z smell audit:

- **Undo never deletes live capture.** A live builder pass after the run
carries the run tag onto a window that also holds recordings captured
after the run. Undo now keeps any group whose copy holds a recording
outside the group (`kept_live`). It counts
`groups_kept_live`/`donors_kept_live` and ends `undone_partial`.
- **Known limit, not changed:** donors are selected by `started_at <
until`, and `--until` defaults to now. Only completed, non-recording
legacy rows qualify (`backfill_legacy_source`), so an in-progress
capture is never converted. A legacy conversation that completed just
before the run is in scope. Pass an explicit `--until` to leave recent
history alone.

Rejected on purpose, and tracked as follow-ups (the coordinator agreed
with the notes-lock reject, bus a16967):

- A shared admission guard for ordinary live v3 and legacy notes remains
a follow-up. This change scopes the guard to backfilled v3 copies,
including copies whose owed notes move to the live queue after undo.
- A lock between the shared delete path
(`conversation_tombstones.record_deletion`) and undo. Undo surfaces the
race instead, through the raced ids and `undone_partial`.

Not changed here: F2 (removal of the
`BATCH_PIPELINE_MERGE_STALE_HEAD_UID_ALLOWLIST` prod binding). It came
from #25696 (jobstore-index's #25679 repair), which was merged into
#25686. Its owner and declaration live with that change.

## Product invariants affected

- INV-MEM-4 and INV-TASK-2 are unchanged. Backfilled v3 rows still take
no memory intake, tasks or Candidates. Kept copies that move to the live
notes marker go through the same `historical` seam in
`process_conversation`.

Failure-Class: FC-irreversible-terminal-hide

Line-Count-Exception: backend/database/conversations_v3.py | 1799 ->
1862 | Keep the connected undo transaction with the projection writer
and its visibility index.
Line-Count-Exception: backend/routers/conversations.py | 3276 -> 3314 |
Pass observed row existence through the existing delete paths so undo
races return the refresh response.
Line-Count-Exception:
backend/utils/conversations/process_conversation.py | 3608 -> 3612 |
Preserve typed admission failures and scope suppressed telemetry to
backfilled copies.
Line-Count-Exception: backend/utils/conversations/v3/service.py | 1652
-> 1678 | Check deletion during the paged drain and preserve the
processing state when admission is blocked.

## Test plan

November 26 verification after merging current main

- 97 ordinary backfill tests and 6 prompt-version tests passed.
- 1,309 related backend tests passed.
- 4 Firestore emulator cases passed, each covering both admission
orders. Cases combine immediate and grace-period deletion with absent
and cancelled markers.
- Backfilled notes use an 8-second SDK request timeout and a 12-second
overall admission budget. Slow notes exhaust one backfill retry and
cannot settle as success.

`tests/unit/test_conversations_v3_backfill.py` passed all 81 tests on
the rebased PR head, including the regression that starts deletion after
the drain checks and before model admission. Existing coverage includes:

- Undo on StrictFirestore:
  - `test_undo_never_resurrects_a_donor_whose_copy_the_owner_deleted`
-
`test_a_deletion_racing_undo_keeps_the_group_and_hands_owed_notes_to_live`
  - `test_an_interrupted_conversion_with_no_claim_is_restored`
  - the exact-restore and lease tests, now on `undo_backfill_group`.
- Undo grouping and ordering:
  - `test_undo_groups_link_donors_and_copies_including_deleted_copies`
  - `test_only_a_post_run_deleted_span_counts_as_the_owners_deletion`
  - `test_undo_holds_both_builder_leases_before_it_enumerates_the_run`
-
`test_undo_works_one_group_per_call_and_refuses_while_notes_are_in_flight`
- Drain:
  - `test_the_drain_stops_once_account_deletion_starts`
- `test_a_step_blocks_the_run_when_the_drain_stops_for_account_deletion`
- Re-derive:
- `test_a_converted_donor_no_rebuilt_window_claims_blocks_the_partition`
  - the stale notes marker asserted in the loader re-derive test.
- Operator: `test_one_owners_blocked_plan_never_stops_the_others`.
- Partitions: partition sizes asserted in
`test_a_gap_free_run_over_the_cap_is_a_counted_forced_cut`.

Updated pins: `test_owner_recognition_telemetry` and the
`test_capture_loss_accounting` harness.

The local Firestore emulator verified both admission orders with absent
and cancelled markers, for immediate and grace-period deletion.
Production was outside this verification.

🤖 Generated with [Claude Code](https://claude.com/claude-code)
Git-on-my-level added a commit to Git-on-my-level/omi that referenced this pull request Nov 26, 2026
…ount deletion

Follow-up to BasedHardware#25686 for the head panel review-20261118t145557-1937:
- Undo restores donors and removes copies per connected group in one
  transaction that reads the copies' deletion tombstones, so a delete racing
  undo never resurfaces a legacy row; a group with an owner deletion stays v3
  and hands owed notes to the live marker; a donor with no claim and no new
  span (interrupted run, retired by re-derive) is restored.
- The backfill drain checks the account-deletion marker before each chunk and
  the step blocks the run (account_deletion).
- A converted donor no rebuilt window claims blocks the partition; re-derived
  prior copies drop stale notes markers.
- Operator: one owner's blocked plan prints its reason and the batch continues
  (exit 1). Gap-free forced cuts fill partitions.
- Only v3 backfill copies skip capture-loss/owner-recognition telemetry;
  silent-backfill recovery keeps it. Flag registry notes state the prod value.

Failure-Class: FC-irreversible-terminal-hide

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant