Skip to content

fix(conversations-v3): group-atomic backfill undo; drain stops on account deletion - #25703

Merged
Git-on-my-level merged 25 commits into
mainfrom
lane/v3-backfill-undo-fixes
Nov 26, 2026
Merged

Git-on-my-level merged 25 commits into
mainfrom
lane/v3-backfill-undo-fixes

Conversation

@Git-on-my-level

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

Copy link
Copy Markdown
Member

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 feat(conversations-v3): per-owner backfill and repair runs with live parity and exact undo #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

…ount deletion

Follow-up to #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]>
@chatgpt-codex-connector

Copy link
Copy Markdown
Codex Review Summary: ❌ Failed

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ❌ Failed 2026-11-18T16:01:50.399104Z
We couldn’t complete this review. Comment @codex review to try again.
cee2d90 PR opened
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@chatgpt-codex-connector

Copy link
Copy Markdown

You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard.
To continue using code reviews, add credits to your account and enable them for code reviews in your settings.

Git-on-my-level and others added 24 commits November 18, 2026 23:19
The account-deletion stop is an int flag in the drain counts instead of a
string under 'stopped', which pyright rejected for the int-valued dict.

Failure-Class: FC-irreversible-terminal-hide

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

The drain checked the deletion marker once per chunk, so a marker set after
that check let the chunk's other workers still start model calls. Each row
now rechecks right before its notes call and releases its lease when blocked.

Failure-Class: FC-irreversible-terminal-hide

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…t, drain lease safety

Answers panel review-20261118t171612-b1c4:
- Re-derived copies start a fresh v3_backfill_attempts budget.
- An undo group over 400 documents is refused whole (undo_group_too_large).
- A failed account-deletion read releases the row's summary lease.
- An account_deletion block keeps the chunk's notes counts in the ledger.
- --no-wait keeps a blocked owner's exit 1; dry-run prints undo groups and a
  lower-bound deleted-donor count; runbook wording matches.
- Behavioural tests pin capture-loss accounting for silent-backfill recovery
  (counted) and v3 backfill copies (skipped).

Failure-Class: FC-irreversible-terminal-hide

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

Answers panel review-20261118t182520-4d1e:
- The backfill drain's account-deletion checks read the marker past the 30s
  negative cache (account_deletion_blocks_user_work(fresh=True)).
- load_derive resolves the deletion marker on the data plane, not the
  conversations client it was handed.
- A Conflict inside an undo group is recorded in the ledger; the run stays
  'undoing' so a rerun continues, and the operator exits 1.

Failure-Class: FC-irreversible-terminal-hide

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

When undo keeps a group because the owner deleted a copy, only the copies
without a deletion tombstone hand their owed notes to the live marker; the
deleted copy's backfill marker is just cleared (panel review-20261118t194704-adbf).

Failure-Class: FC-irreversible-terminal-hide

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

Answers panel review-20261118t202629-29f6:
- The undo group transaction reads each copy's summary lease and refuses
  (notes_in_flight) when a notes write started after undo's first check.
- A rerun or refused undo keeps the totals of groups already undone.
- The account-deletion blocked partition records notes_remaining.
- A test pins load_derive's deletion-marker read to the data plane.

Failure-Class: FC-irreversible-terminal-hide

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…ept undo groups

Answers panel review-20261118t211606-42ac:
- An account-deletion stop still reads what notes remain owed, so the
  blocked partition's notes_remaining is accurate.
- A rerun undo carries only restored/removed totals; kept groups stay in the
  run's documents and are recounted, never double-counted.

Failure-Class: FC-irreversible-terminal-hide

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

Answers panel review-20261118t214510-6e27:
- Undo persists its totals after every group, so a crash never loses groups
  already undone.
- A delete whose tombstone lands after its group was undone (the shared delete
  path reads the copy before writing the tombstone) is counted as
  deleted_during_undo for the operator; the runbook says what to do.
- An owner skipped for an active run fails the operator's exit code.
- The fresh deletion-marker read keeps the check metrics (called/decision,
  authority_unavailable) by going through get_user_deletion_wipe_status.
- Runbook: only surviving copies' notes move to the live marker.

Failure-Class: FC-irreversible-terminal-hide

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…pies on donors

Answers panel review-20261118t220607-afa0:
- Each undo group's transaction writes the run's undo progress (restored and
  removed totals, removed copy ids), so a crash or retry never loses totals,
  and the race check covers every attempt's removals and lists their ids.
- Deleting a backfilled copy records its id on the donor even when other
  claims cover the interval, so undo always sees the deletion.
- A kept group clears the live notes marker on a deleted copy too.
- A run with kept groups or a raced delete ends undone_partial (exit 1).
- The group bound counts reads (row, tombstone, notes lease per copy).
- Only a re-derive blocks on an unclaimed converted donor; a resume keeps its
  copy. The operator reports only Conflicts and an existing run as blocked.
- Runbook: the remedy for an owner-deleted copy that blocks a re-derive.

Failure-Class: FC-irreversible-terminal-hide

Co-Authored-By: Claude Opus 5.5 <[email protected]>
deleted_during_undo_ids is a list alongside the integer totals; pyright
rejected updating an int-inferred dict with it.

Failure-Class: FC-irreversible-terminal-hide

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

Answers panel review-20261118t223845-273f: load_derive gates sending the
owner's transcript to the outline model, so it reads the account-deletion
marker past the negative cache. Runbook states the read-count undo bound.

Failure-Class: FC-irreversible-terminal-hide

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

A Conflict mid-undo now still checks the copies already removed for a delete
that raced them and records deleted_during_undo_ids in the error patch.
undo_backfill_group returns the number of converted donors it kept, and
undo_run counts that instead of every donor in the group.

Failure-Class: FC-irreversible-terminal-hide

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

A live builder pass after a run carries the run tag onto a window that also
holds recordings captured after the run. Undo deleted that copy. It now keeps
any group whose copy holds a recording outside the group (kept_live), counts
groups_kept_live/donors_kept_live and ends undone_partial.

Failure-Class: FC-irreversible-terminal-hide

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

create_run raises BackfillRunExists (a ValueError) and the operator catches
the type, not the message. Undo renews its leases inside the per-group
Conflict handling, so a lease lost on renew writes the same structured error
record as a failed group.

Failure-Class: FC-irreversible-terminal-hide

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

A copy named only by a donor's post-run deleted span or recorded deleted copy
still links the group's donors but is no longer read: that donor already keeps
the group, so such ids cannot push a group over the read bound. Undoing a run
already undone or undone_partial reports its record and changes nothing. A
test pins the kept branch clearing a deleted copy's live notes marker. The
runbook explains the dry-run lower bound and the kept reasons.

Failure-Class: FC-irreversible-terminal-hide

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Preserve historical live re-derive while keeping per-owner backfill blocking and partial undo reporting. Pin the notes source version for the deletion admission fence and keep notes-9 checkpoints reusable.

Co-authored-by: multica-agent <[email protected]>
@Git-on-my-level
Git-on-my-level merged commit d8a5714 into main Nov 26, 2026
70 checks passed
@Git-on-my-level
Git-on-my-level deleted the lane/v3-backfill-undo-fixes branch November 26, 2026 11:28
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