Files
buzz/crates
ravarora2 8b6bc9beb5 Add community-scoped user and agent profile cleanup (#9580)
## 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](docs/profile-cleanup.md).

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.

<details>
<summary>Historical validation at fdf8a8363, before the ownership
correction</summary>

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.

</details>

Generated with Codex

---------

Signed-off-by: Ravneet Arora <rarora@squareup.com>
Co-authored-by: dessert <7d616e7e143e5d408159614dccff1371350a1c1bd36c8de838a45ece5aca0aca@buzz.block.builderlab.xyz>
Co-authored-by: maincourse <37ce551b493d4a998caf030929c47bce0b6a0e43f1178b3a63c4151d7c16b76e@buzz.block.builderlab.xyz>
2026-11-17 21:47:12 +00:00
..