Repository navigation
Add community-scoped user and agent profile cleanup - #9580
Conversation
Preview and delete scoped identity data for a user and owned agents. Keep shared archive snapshots signed and preserve other communities. Leave workflow integration and online fencing separate. Co-authored-by: dessert <7d616e7e143e5d408159614dccff1371350a1c1bd36c8de838a45ece5aca0aca@buzz.block.builderlab.xyz> Signed-off-by: Ravneet Arora <rarora@squareup.com>
Discover direct agents within the selected community on each run and retry. Keep profile cleanup ahead of identity removal and retain original keys only for final inspection. Co-authored-by: maincourse <37ce551b493d4a998caf030929c47bce0b6a0e43f1178b3a63c4151d7c16b76e@buzz.block.builderlab.xyz> Signed-off-by: Ravneet Arora <rarora@squareup.com>
Preserve both direct media and profile cleanup commands. Co-authored-by: maincourse <37ce551b493d4a998caf030929c47bce0b6a0e43f1178b3a63c4151d7c16b76e@buzz.block.builderlab.xyz> Signed-off-by: Ravneet Arora <rarora@squareup.com>
kazemek21
left a comment
There was a problem hiding this comment.
Kyle reviewed this PR and the Nexus review-tracker notes and approved with no comments.
Posted by Codex (gpt-6.1-sol) on behalf of kylez
Preserve content, media and profile command dispatch. Co-authored-by: maincourse <37ce551b493d4a998caf030929c47bce0b6a0e43f1178b3a63c4151d7c16b76e@buzz.block.builderlab.xyz> Signed-off-by: Ravneet Arora <rarora@squareup.com>
Select archive replacement references even after unarchive. Refuse historical requests concerning surviving identities before any mutation. Co-authored-by: maincourse <37ce551b493d4a998caf030929c47bce0b6a0e43f1178b3a63c4151d7c16b76e@buzz.block.builderlab.xyz> Signed-off-by: Ravneet Arora <rarora@squareup.com>
The event builder drops self p tags by default. Keep the NIP-IA subject and print unexpected errors in the regression assertion. Co-authored-by: maincourse <37ce551b493d4a998caf030929c47bce0b6a0e43f1178b3a63c4151d7c16b76e@buzz.block.builderlab.xyz> Signed-off-by: Ravneet Arora <rarora@squareup.com>
TheSentinel454
left a comment
There was a problem hiding this comment.
🤖 Reviewed at ff6689386. The approach is sound: preview by default, bounded batches, fingerprint rechecks, and ownership scoped to one community. I found no path that deletes the wrong data. Two recommended blockers and two optional notes are inline.
| ("subscriptions","owner_pubkey=ANY($2::bytea[])"), | ||
| ("channel_members","pubkey=ANY($2::bytea[])"), | ||
| ("relay_members","pubkey=ANY(SELECT encode(k,'hex') FROM unnest($2::bytea[]) k)"), | ||
| ("events","pubkey=ANY($2::bytea[]) AND kind NOT IN (0,10100,30177,30179,9035,9036)"), |
There was a problem hiding this comment.
🤖 Recommended blocker (P1): repo owners can never finish profile cleanup.
This check blocks on every authored event that is not a profile kind. Content cleanup keeps repository events on purpose (content_batches/mod.rs KINDS leaves out 30617/30618; see the comment above 30175). Issue #9576 and docs/profile-cleanup.md both say repositories are kept.
Failure: a human (or owned agent) who authored a kind:30617 repo announcement in this community runs content cleanup, then this command. Content cleanup leaves the 30617 event. This query then reports events: content/account cleanup or shared-reference disposition required on every run. No handler removes it, so identity cleanup can never complete.
Fix: exclude the kinds that are meant to be kept from this check. Or remove "repositories" from retained and document that repos need their own disposition step first.
| } | ||
|
|
||
| #[test] | ||
| fn preview_is_default_and_delete_is_explicit() { |
There was a problem hiding this comment.
🤖 Recommended blocker (P1): this test runs in no CI lane.
The CI unit lane does not run buzz-deletion tests. The PostgreSQL lane runs only its postgres_tests. I checked the job logs at ff6689386: all ten profile_batches::postgres_tests ran and passed, but preview_is_default_and_delete_is_explicit appears nowhere. This test guards the main safety default: preview unless --delete is passed. Removing that guard would not fail CI.
Fix: add cargo nextest run -p buzz-deletion --lib to the unit lane. The gap is older than this PR, but this PR adds the first safety-critical test that depends on it.
| selector: "t.pubkey=ANY($2::bytea[])", | ||
| }; | ||
|
|
||
| pub(super) const CHILDREN: &[Table] = &[ |
There was a problem hiding this comment.
🤖 Optional: a second hand-kept list of event projection tables.
content_batches/rows.rs (event_rows) and execute.rs already list the event-dependent projections (event_mentions, push_match_queue, push_wake_outbox, operator_listener_outbox, reactions, delivery_log). This list duplicates it with different key encodings. A new event-keyed projection table would have to be added to both lists, and it is easy to miss one. One shared const used by both handlers would prevent that drift.
| 9035 | 9036 => { | ||
| let target = subject(&tags, "p")?; | ||
| if !scope.targets.contains(&target) { | ||
| return Err(invalid("archive request concerns a surviving identity; shared-history disposition required")); |
There was a problem hiding this comment.
🤖 Optional: the doc and the code disagree on how this case is reported.
docs/profile-cleanup.md says human-signed requests about another identity and archive references on surviving identities are reported as blockers. Here they return a hard error from select(). The command exits before it prints profile_batches_start, so the operator sees one error and no plan or blocker list. The 8002/8003 branch below works the same way. Either push these into plan.blockers, or update the doc to say the command stops with an error.
Allow retained repository announcements and state through profile prerequisites, with a content-to-profile cleanup regression. Run deletion safety-default unit tests in CI and its fallback, and clarify archive planning errors. Co-authored-by: maincourse <37ce551b493d4a998caf030929c47bce0b6a0e43f1178b3a63c4151d7c16b76e@buzz.block.builderlab.xyz> Signed-off-by: Ravneet Arora <rarora@squareup.com>
Preserve account and profile command dispatch. Keep the deletion unit-test lane already added by main, without a duplicate run. Co-authored-by: maincourse <37ce551b493d4a998caf030929c47bce0b6a0e43f1178b3a63c4151d7c16b76e@buzz.block.builderlab.xyz> Signed-off-by: Ravneet Arora <rarora@squareup.com>
Include the upstream correction from #9615 so content-to-profile cleanup works after SQL function retirement. Preserve the profile cleanup changes. Co-authored-by: maincourse <37ce551b493d4a998caf030929c47bce0b6a0e43f1178b3a63c4151d7c16b76e@buzz.block.builderlab.xyz> Signed-off-by: Ravneet Arora <rarora@squareup.com>
TheSentinel454
left a comment
There was a problem hiding this comment.
🤖 Approved at 0255779. Both earlier blockers are fixed: repository events no longer block cleanup, and the CLI test now runs in the unit lane.
…c-spec-mobile * origin/main: (37 commits) buzz-db: drop the five single-table guard triggers (BUZZ-318 phase 2) (#9398) push-gateway: lock expired installations before reaping (#9627) Retire the 0032 roster trigger in migration 0095 (#8696) fix(db): hard-delete superseded relay-signed lists (#9586) Add community-scoped user and agent profile cleanup (#9580) fix(sdk): timestamp channel messages with millisecond offsets (#9548) Check product_feedback's community in the writing transaction (#9608) buzz-db: stop calling the dropped lock-key function in SQL (#9615) Clean up account records and refresh member lists (#9364) perf(mobile): save own thread interest once per unread catch-up (#9614) buzz-db: fix main (renumber the function drop to 0094, update_channel test call) (#9616) feat(relay): name the agent whose add policy refuses a DM (#9601) buzz-db: drop the community_deletion_lock_key and profile_name_fields functions (contract) (#9598) fix(deps): clear chrono, humantime and zip advisories from the dependency policy (#9609) docs: define mobile diagnostic reporting (#9600) build(mobile): link iOS plugins through Swift Package Manager (#9597) feat(push-gateway): enroll Android installations and send FCM wakes (#9560) perf(mobile): cache and animate custom emoji in the iOS picker (#9479) fix(ios): end each bold or strikethrough run at its first closing marker (#9559) Apply the private-to-open rule in update_channel too (#9581) ... Signed-off-by: Will Pfleger <wpfleger@block.xyz>
…e-recovery * origin/main: feat(cli)!: consistent channels list/get/search output (type, visibility, labels, real created_at) (#9617) ci(docker): publish the push gateway only when its inputs change (#9658) feat(mobile): reply to a message from its iOS notification (#9439) fix(mobile): stop reporting saved images as failed on iOS (#9599) perf(db): stop per-id planning of wide #e reads (#9591) [buzz] fix(ci): link relay image indexes to their source (#9637) feat(push-gateway): verify Android Key Attestation (#9562) fix(relay): remove an owner's agents with the owner (#9575) relay: refuse a reaction or deletion whose h names another channel (#9006) buzz-db: drop the five single-table guard triggers (BUZZ-318 phase 2) (#9398) push-gateway: lock expired installations before reaping (#9627) Retire the 0032 roster trigger in migration 0095 (#8696) fix(db): hard-delete superseded relay-signed lists (#9586) Add community-scoped user and agent profile cleanup (#9580) fix(sdk): timestamp channel messages with millisecond offsets (#9548) Check product_feedback's community in the writing transaction (#9608) buzz-db: stop calling the dropped lock-key function in SQL (#9615) Signed-off-by: Will Pfleger <wpfleger@block.xyz>
…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>
Summary
Content, account and media cleanup leave profile records behind. Add
buzz-admin user-deletions profile-batchesto preview or delete those records in one community. Preview is the default; explicit--deleteapplies bounded, retryable transactions.Every run and retry discovers the human’s current direct agents in that community. Ownership elsewhere cannot authorize deletion here. If Alice owns an agent in A but Bob owns it in B, deleting Alice in B preserves that agent. Each write batch locks and rechecks ownership. All profile data is removed before identity rows, so an interrupted run resumes without saved agent keys. The command no longer accepts
--agent-pubkey.The handler removes profile/configuration events and projections, rebuilds shared archive snapshots with valid signatures, and finally removes identity rows. Repository announcements/state (30617/30618) and name mappings remain intact without blocking identity removal; other authored content still requires prior cleanup. Unresolved dependencies, changed sources, untrusted signers or excessive plans stop deletion. This includes historical
replaced-byreferences in archive requests and deltas, even after unarchive removes the current archive row. See operator instructions and verification steps.Writers must be stopped. Coordinator integration, online admission fencing, media objects, client caches and final account-erasure verification remain separate. The command always reports
account_erasure_complete: false.Related issue
Fixes #9576. Continues the standalone handler pattern from #9363 (content) and #9364 (account). This is an independent PR against main.
Testing
The latest correction adds a PostgreSQL regression that runs content cleanup followed by profile preview/delete/retry for human and agent repository owners. It checks unchanged repository events, mentions, name mappings and other-community data, and verifies ordinary content still blocks profile deletion. The merge of main brings in
buzz-deletion --libcoverage in the CI unit lane and its fallback, covering the preview-default parser test without duplicate runs. Account, content, media and profile command dispatch are all preserved. The archive-history documentation also now distinguishes planning errors from printed blockers.The latest main merge includes the shared dependency-policy correction from #9609 and the content cleanup lock fix from #9615. On
54bd50299, PostgreSQL CI passed 1647 tests and failed 18 because content cleanup still called the retired SQL lock-key function; this also blocked the new content→profile regression. The merged upstream fix uses the existing Rust-built key for both the cleanup lock and the test blocker. Local test suites and hooks remain skipped at the owner’s request. CI and review of the updated head are pending. The results below apply to earlier revisions.At
92aa9c216, exercised the rebuiltbuzz-adminagainst signed archive/unarchive events stored in disposable PostgreSQL:replaced-byreference to the human and then to their owned agent after unarchive.profile-batches --pubkey <human> --community <A> --relay-pubkey <relay>in preview and--deletemodes. Both refuse the unresolved reference; full table dumps remain unchanged.All four scenarios passed. These are signed database fixtures exercised through the real CLI; they do not claim live relay admission. The correction also merges main and preserves content, media and profile command dispatch.
The initial full database run passed 880/881 tests: the new request fixture lost its required self-
ptag during signing. Commitff6689386preserves that tag; all ten profile regressions now pass. Further local checks and pre-push hooks were skipped at the owner’s explicit request. The full corrected database suite has not been rerun; GitHub CI will validate the new head. Atff6689386, the production code matched the CLI-tested revision; the repository-retention correction above is newer.Previous ownership validation follows:
At
090d2a1cf, exercised the rebuiltbuzz-adminbinary against a disposable PostgreSQL fixture:user-deletions profile-batches --pubkey <human> --community <A>: preview left table exports unchanged and selected four profile/identity mutations.--delete --batch-size 2: all four mutations committed; retry selected zero work.This fixture uses placeholder profile signatures and validates database/CLI behavior. It does not claim live signed-event admission. The earlier live relay and Desktop results below cover the previous revision.
Independent agent review covered the previous ownership correction. A later review found the historical replacement-reference bug; the historical-reference correction addresses that finding. Fresh review of this revision is still required. Human command verification has not been recorded; it is not claimed by the agent-run checks. Follow the local verification steps in
docs/profile-cleanup.md; preview must leave data unchanged, deletion must preserve other-community records, and retry must select zero work.Historical validation at fdf8a83, before the ownership correction
These records are retained from the earlier PR description. They do not validate the current revision. The saved-agent-key retry below describes the old interface, which this update removes.
cargo test -p buzz-db -p buzz-deletion -p buzz-admin: passed atfdf8a8363(298 tests, with PostgreSQL tests in the separate lane).cargo clippy -p buzz-db -p buzz-deletion -p buzz-admin --all-targets -- -D warnings: passed.postgres://-only test given apostgresql://URL, a one-second partition-lock timing assertion (1.55 seconds), and size-one matcher pool startup. The URL spelling has been corrected for future runs; the full lane has not yet been rerun. The run experienced heavy host contention.buzz-admincommand against a separate disposable SQL fixture: default preview,--print-only, and--read-onlyleft all table exports unchanged;--deleteremoved four selected rows; survivor/second-community data remained; retry selected zero rows. This is database/CLI evidence, not live relay acceptance.just ciinitially stopped at mobile formatting because the fresh worktree lacked Flutter package configuration; dependencies were installed and the retry remains incomplete. The long-running local pre-push run was stopped to publish the draft at the author’s request; incomplete gates are not claimed as passing.fdf8a8363: 22 signed client events accepted across two communities; WebSocket authentication established four agent-owner links. All three preview forms left all 67 public tables unchanged.--delete --batch-size 2removed eight selected source events, four mention rows, one archive row and two identity rows, and inserted one independently verified survivor-only archive snapshot. All other rows matched exactly; retry selected zero work.fdf8a8363,buzz-app859c9953awith isolated app storage and a local TLS configuration. Seed a survivor-owned conversation, open Alice and her agent's profiles, then runprofile-batches --delete --batch-size 2while app and relay remain running. Preview selected 17 mutations across nine batches without changing any of 67 tables. Deletion removed ten source events, four associated mention rows and two users, then inserted one validly signed survivor-only archive snapshot. Every other row, including eight survivor events and community B, matched exactly. Retry did zero work.Generated with Codex