Skip to content

fix(deletion): close the review findings on the batched purge - #10095

Open
TheSentinel454 wants to merge 7 commits into
mainfrom
elrond/deletion-purge-review-fixes
Open

TheSentinel454 wants to merge 7 commits into
mainfrom
elrond/deletion-purge-review-fixes

Conversation

@TheSentinel454

@TheSentinel454 TheSentinel454 commented Dec 1, 2026 •

Copy link
Copy Markdown
Contributor

Stacked on #10094 (the duplicate tracing-subscriber key that breaks main). Its commit drops out of this PR when it merges.

Why

Community deletion purges PostgreSQL in bounded batches since #10081. Reviews of #10081 and #10074 found four gaps that merged with the stack:

  • search_backfill race. The search indexer's reset runs DELETE FROM search_backfill for all communities, without community admission. A purge batch that picked those rows without a lock could count rows the reset had already deleted.
  • Retry streak. Each batch that changed rows reset retry_count to zero. A later failure in the same attempt then counted 1, so an attempt that made progress still counted toward the block.
  • No batch timings by default. The purge logs every committed batch at info under buzz_db::store::deletion. buzz-admin's default filter kept buzz_db at warn, so a drain without RUST_LOG printed no timings.
  • Table added mid-purge. If a migration adds an unlisted community_id table after the attempt's first catalog check, the batch failed with a DeletionSafety error. The executor treats that error as permanent, so the request blocked until an operator ran deletions unblock.

What

  • Purge batches on search_backfill lock the rows they pick (FOR UPDATE), and wait for a concurrent reset.
  • A batch that changed rows still clears the streak, and now also records its lease generation in the checkpoint. A failure in the same stage and attempt records zero. The block comes after eight attempts with no progress.
  • buzz-admin logs buzz_db::store::deletion at info by default. The operator runbook says so.
  • An unlisted table that appears mid-purge returns a retryable error. The next attempt's first catalog check skips and logs it. A missing listed table still fails closed.

How

  • The progress marker is detail.progress_generation on the existing checkpoint row. record_retry checks it with one EXISTS query that also matches the failing stage, so a later stage under the same lease still counts its first failure.
  • The batch keeps its own streak reset. That reset commits with the batch, so it holds when the attempt ends without record_retry (a lost lease or a shutdown).
  • is_permanent_error does not change. The mid-purge drift error is now DbError::InvalidData, which it already treats as retryable.

Risk

Low to medium. The change touches the live deletion path in buzz-db. Community deletion is suspended in production until the operator re-enables it, so no request runs this code before then.

Testing

On a Linux workstation with PostgreSQL 16, at the PR head:

  • cargo fmt, clippy -D warnings, and nextest --lib --tests for buzz-db, buzz-deletion, buzz-admin.
  • The PostgreSQL lanes for store::deletion:: and buzz-deletion.
  • Five mutants, each caught by its new test (each mutant compiles and the named test fails): no search_backfill lock, ignore the progress marker, a permanent error for mid-purge drift, no batch streak reset, and progress matched in any stage.
  • A real buzz-admin deletions drain with RUST_LOG unset: stdout held one JSON result, and stderr held JSON batch records with table, rows, and elapsed_ms.

Bigger picture

This closes the review findings on #10081 and #10074. The remaining step before deletion is re-enabled is a supervised staging run.

🤖 Generated with Claude Code

TheSentinel454 and others added 6 commits December 1, 2026 18:01
Two merges each added tracing-subscriber to buzz-db's dev-dependencies.
Cargo refuses a manifest with a duplicate key, so main does not build.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Signed-off-by: Luke Tornquist <tornquist@squareup.com>
…e retries

The search indexer's reset deletes every search_backfill row without
community admission, so purge batches lock the search_backfill rows they
pick. A batch that changed rows now records its lease generation in the
checkpoint detail. record_retry starts the streak at zero for an attempt
that made progress, so the block comes after eight attempts with none.
This replaces the per-batch retry_count reset, which a later failure in
the same attempt undid.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Signed-off-by: Luke Tornquist <tornquist@squareup.com>
The purge logs each committed batch at info under
buzz_db::store::deletion, but the default filter kept buzz_db at warn,
so a drain without RUST_LOG printed no batch timings. Keep that target
at info and say so in the operator runbook.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Signed-off-by: Luke Tornquist <tornquist@squareup.com>
A purge batch fails when a migration adds an unlisted tenant table
after the attempt's first catalog check. That failure was a
DeletionSafety error, which the executor treats as permanent, so the
request blocked until an operator ran deletions unblock. Return a
retryable error instead; the next attempt's first check skips and logs
the table. A missing listed table still fails closed.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Signed-off-by: Luke Tornquist <tornquist@squareup.com>
#10074 added the skipped-tables argument to purge_in_batches after this
test was written.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Signed-off-by: Luke Tornquist <tornquist@squareup.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Signed-off-by: Luke Tornquist <tornquist@squareup.com>
@github-actions github-actions Bot added the codex-security-review-current The posted Codex security review matches its recorded range. label Dec 1, 2026
@github-actions

github-actions Bot commented Dec 1, 2026 •

Copy link
Copy Markdown

🔐 Codex Security Review

Note: This is an automated, security-focused review generated by Codex.
Use it as a supplement to human review; false positives are possible.

Scope

  • Exact PR diff: 8c2530f1f7ade7b0c957622c01e800c82687e74d...11eeb33e1a669bdabf43f14da4368d5f7f702a51
  • Model: gpt-6.1-sol

💡 Click "edited" above to see earlier reviews for this PR.


Review Summary

Overall Risk: NONE

No concrete security, correctness, or reliability regressions found in the authorized pull request range.

Findings

No concrete security, correctness, or reliability findings were identified.

Notes

  • No additional limitations were reported.

Generated by Codex Security Review |
Requested by: @TheSentinel454 |
Workflow run

A purge batch that changed rows clears the retry streak again, in its own
transaction, so the reset holds when the attempt ends without
record_retry. record_retry treats a failure as progress only when the
progress checkpoint is in the failing stage, so a later stage under the
same lease still counts its first failure.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Signed-off-by: Luke Tornquist <tornquist@squareup.com>
@github-actions github-actions Bot added codex-security-review-current The posted Codex security review matches its recorded range. and removed codex-security-review-current The posted Codex security review matches its recorded range. labels Dec 1, 2026

This branch was successfully deployed

1 active deployment
codex-review — 11eeb33e Deployed Dec 1, 2026 by TheSentinel454 via Run Codex Security Review #19114
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

codex-security-review-current The posted Codex security review matches its recorded range.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants