Skip to content

Add community-scoped user and agent profile cleanup - #9580

Merged
ravarora2 merged 9 commits into
mainfrom
rarora/profile-cleanup
Nov 17, 2026
Merged

ravarora2 merged 9 commits into
mainfrom
rarora/profile-cleanup

Conversation

@ravarora2

@ravarora2 ravarora2 commented Nov 16, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Content, account and media cleanup leave profile records behind. Add buzz-admin user-deletions profile-batches to preview or delete those records in one community. Preview is the default; explicit --delete applies 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-by references 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 --lib coverage 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 rebuilt buzz-admin against signed archive/unarchive events stored in disposable PostgreSQL:

  • For kinds 9035 and 8002, test a historical replaced-by reference to the human and then to their owned agent after unarchive.
  • Run profile-batches --pubkey <human> --community <A> --relay-pubkey <relay> in preview and --delete modes. Both refuse the unresolved reference; full table dumps remain unchanged.
  • Keep that history only in community B. Cleanup in A succeeds, preserves B, and selects zero work on retry.
  • Delete the archive subject in B. Its history is removed while the replacement identities remain intact.

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-p tag during signing. Commit ff6689386 preserves 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. At ff6689386, the production code matched the CLI-tested revision; the repository-retention correction above is newer.

Previous ownership validation follows:

At 090d2a1cf, exercised the rebuilt buzz-admin binary against a disposable PostgreSQL fixture:

  • Run user-deletions profile-batches --pubkey <human> --community <A>: preview left table exports unchanged and selected four profile/identity mutations.
  • Repeat with --delete --batch-size 2: all four mutations committed; retry selected zero work.
  • Use the same human and agent keys in another community, with the agent owned by someone else: only the human was selected, and the agent remained intact.

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 at fdf8a8363 (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.
  • Full PostgreSQL lane for those three packages: 814/818 passed, including all five new profile tests. Four unchanged infrastructure tests failed: reader-pool startup, a postgres://-only test given a postgresql:// 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.
  • Actual buzz-admin command against a separate disposable SQL fixture: default preview, --print-only, and --read-only left all table exports unchanged; --delete removed four selected rows; survivor/second-community data remained; retry selected zero rows. This is database/CLI evidence, not live relay acceptance.
  • Workspace Rust clippy and desktop static checks passed. just ci initially 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.
  • Isolated live relay at 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 2 removed 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.
  • Eight refusal cases left every table unchanged. A real process kill after a committed batch, followed by retry with saved agent keys, produced the exact expected result. Separate signed SQL fixtures covered kind 30382, verified heads and historical kind 30179; these do not claim live issuer-backed admission.
  • Independent restart checks passed: target profiles stayed absent from events, search and NIP-05; the other community was preserved; the surviving user could publish and read a profile update. A separate replay clone confirmed the boundary: replaying the original target profile recreated its user row, and a fresh profile was accepted too. Permanent erasure requires external admission/write fencing.
  • Native Desktop experiment: relay/admin fdf8a8363, buzz-app 859c9953a with isolated app storage and a local TLS configuration. Seed a survivor-owned conversation, open Alice and her agent's profiles, then run profile-batches --delete --batch-size 2 while 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.
  • Desktop observations: fresh signed relay reads returned no target profiles/events/NIP-05 in A; B and the survivor conversation remained readable. Bob updated his profile through the API and sent a reply through the native composer, with signed relay readback and visible receipt. Cached target details remained in the open profile panel, reopened search and after an app-page reload/reconnect. This does not erase client caches or prove safety under concurrent target writes; the stopped-writer contract remains.
  • At that earlier revision, the PR was draft pending human command verification. Agent testing does not satisfy the repository's human-testing requirement, and this command does not certify online erasure.

Generated with Codex

ravarora2 and others added 3 commits November 16, 2026 12:05
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>
@ravarora2 ravarora2 changed the title Add standalone profile cleanup preview and deletion Add community-scoped user and agent profile cleanup Nov 16, 2026
@ravarora2
ravarora2 marked this pull request as ready for review November 16, 2026 22:59
@ravarora2
ravarora2 requested a review from a team as a code owner November 16, 2026 22:59

@kazemek21 kazemek21 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

ravarora2 and others added 3 commits November 17, 2026 10:24
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 TheSentinel454 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🤖 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)"),

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🤖 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() {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🤖 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] = &[

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🤖 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"));

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🤖 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 TheSentinel454 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🤖 Approved at 0255779. Both earlier blockers are fixed: repository events no longer block cleanup, and the CLI test now runs in the unit lane.

@ravarora2
ravarora2 enabled auto-merge (squash) November 17, 2026 21:38
@ravarora2
ravarora2 merged commit 8b6bc9b into main Nov 17, 2026
90 checks passed
@ravarora2
ravarora2 deleted the rarora/profile-cleanup branch November 17, 2026 21:47
wpfleger96 added a commit that referenced this pull request Nov 18, 2026
…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>
wpfleger96 added a commit that referenced this pull request Nov 18, 2026
…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>
ravarora2 added a commit that referenced this pull request Nov 19, 2026
…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>

This branch was previously deployed

1 inactive deployment
codex-review — 02557799 Deployed Nov 17, 2026 by ravarora2 via Run Codex Security Review #15822
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.

Add standalone profile cleanup batches

3 participants