Files
buzz/crates/buzz-db
ravarora2 69ea27343c Fix media deletion’s community ownership and share agent discovery (#9670)
## Summary

Deleting a human must preserve an agent's uploads in communities where
someone else owns that agent or its profile is missing. Media cleanup
now carries community/key pairs through database and storage discovery,
shared-file decisions, and uploader-row deletion.

Media, content, account and profile cleanup share one direct-agent
discovery utility. Each caller retains its previous limits and
transaction behavior. Media discovers ownership once per invocation,
including retries, and uses a hash set for storage matching. The report
shape stays unchanged. The operator guide explains that community/agent
pairs have no separate cap and sit outside the inventory budget. The
discovery helper documents that global, identity-grouped discovery
requires `lock: false` because PostgreSQL cannot combine `GROUP BY` with
`FOR SHARE`.

Run a read-only preview first, then keep writers stopped throughout
deletion. Reverting the binary restores the old cross-community
selection bug; it cannot restore deleted objects.

### Related issue

Follow-up to the merged media handler in #9365 and the
content/account/profile handlers in #9363, #9364 and #9580. No duplicate
of this ownership correction was identified.

### Testing

Exercised the rebuilt `buzz-admin user-deletions media-batches --pubkey
<fixture-human> --read-only`, then `--delete`, against isolated
PostgreSQL and versioned MinIO. Preview changed neither rows nor
storage. Exclusive versions and in-scope uploader rows were deleted;
shared originals, thumbnails and historical versions survived. All four
handler commands agreed before and after a between-invocation ownership
change. Failure followed by retry used fresh ownership, and repeat
deletion removed zero versions.

Compared the production candidate SQL with the pre-PR query on about
50,000 local upload/audit rows. With 9,999 agents, execution took
120–185 ms per 500-row page versus 38–83 ms before community matching.
Three runs per query; this excludes planning, Rust preparation and
storage operations. The added per-version ownership queries are removed
entirely.

Full database/deletion/admin package runs passed (339 tests). The
PostgreSQL database/deletion run passed 904 tests; after strengthening
the retry fixture, the full deletion PostgreSQL package passed all 45
tests. The retry case retains ownership in another community, and media
tests assert exactly one ownership lookup per invocation.

Local `just test` completed with one failure in the unchanged relay
logging test `composition_log_does_not_leak_issuer_url` (expected
warning not captured); all other test groups passed. Two pre-push
attempts failed in unchanged ACP tests: first a launch timeout, then
credential tests using Git 2.40 where 2.46+ is required. All four
credential integration tests passed with Git 2.54; the full pre-push
retry was stopped at the author’s request to skip local checks and push.
Local `just ci` was also stopped before completion. Neither interrupted
run is a full pass; local hooks were skipped for publication.

The follow-up for the optional review comments changes documentation
only. Its statements were checked against the query and all five
production callers; `git diff --check` passed. Runtime suites were not
repeated for this follow-up.

Human local acceptance remains pending.

Generated with Codex

---------

Signed-off-by: Ravneet Arora <rarora@squareup.com>
Signed-off-by: dessert <7d616e7e143e5d408159614dccff1371350a1c1bd36c8de838a45ece5aca0aca@buzz.block.builderlab.xyz>
Co-authored-by: dessert <7d616e7e143e5d408159614dccff1371350a1c1bd36c8de838a45ece5aca0aca@buzz.block.builderlab.xyz>
2026-11-19 18:23:24 -05:00
..