Files
buzz/docs
ravarora2 a8f55e637a Add real content cleanup for users and agents (#9363)
## Summary

Add one shared content-cleanup handler for a user and their agents in a
specified community. Preview is the default; deletion commits bounded
batches and preserves other people's replies and reactions.

Agent selection requires ownership by this user in the target community.
Ownership elsewhere is insufficient. The start record reports missing or
conflicting ownership, and every batch rechecks the selected agents
before deleting anything.

### Reply preservation and live writes

Keep erased placeholders for messages needed by surviving reply chains
or reactions. Plain links and quotes may point to a deleted message;
their signed source messages stay unchanged. Nested reply ancestry uses
the existing parent/root indexes. No new permanent index or schema
migration is added.

Replies without thread metadata use the existing tags GIN index to
search for each selected message ID in lowercase and uppercase. The
shared marker parser checks which matches are actual replies. Mixed-case
references without thread metadata may be missed; metadata-backed
replies use binary IDs and remain covered. Planning and hard-delete
rechecks each run the probes in one SQL statement with a one-second
timeout and a 10,000-match limit. A reply matching several probes counts
several times. Exceeding either bound aborts cleanup. This avoids the
broad search through unrelated replies; production-scale performance has
not been measured.

Each batch revalidates its work under the community lock.
Transaction-local timeouts apply before locking, including after
reconnect. Planned output is written before locking and receipts after
commit. A changed row, owner, or surviving reply aborts the batch; retry
replans remaining work.

Normal reply insertion retains the added indexed parent-existence check.
This changes the live write path and prevents saving a reply whose
parent disappeared while the writer waited. Erased messages appear
unavailable in moderation lookups instead of carrying an empty author
key.

### Included content

Supported authored events and owned reaction, subscription and
notification records are included. Signer-owned personas (30175), team
definitions/catalogs (30176/30178), emoji sets/entries (30030/30180),
and project groupings (30621) include shared publications and stored
revisions. Deleting a project grouping leaves member repositories, their
announcements/state and name mappings intact.

### Testing

Local runtime tests and hooks are skipped at the owner's request. Source
review, Rust formatting and diff checks were completed. The updated
revision requires CI validation; earlier test runs and index benchmarks
do not validate this replacement. Regression cases cover ownership
conflicts/transfers, missing thread records, nested ancestry, plain
links, late replies, lookup limits, reconnects, blocked output, and
unavailable moderation targets.

No new manual relay or UI test was run for this revision. Account
blocking remains unfinished; these changes do not establish complete
online account erasure.

### Scope and compatibility

**Deferred to a separate follow-up PR to keep this PR smaller:** the
following work will extend **the same content cleanup handler**
(`purge_content` / `content-batches`), rather than introduce another
handler:

- Workflow database definitions, runs, traces, approvals, schedules and
copied inputs; some source events are already covered here.
- Canvas revision events and current canvas text.
- Artifact events, revision records and current heads.
- Channel topics and purposes.
- Gift-wrapped DMs and additional huddle history that require different
attribution rules.
- Git issues, PRs, patches, comments/status and required repository
metadata, subject to preservation rules. Repositories themselves stay.
- Remaining stored workflow, delivery and projection copies outside this
PR's current coverage.

These categories remain unfinished. Deferring them is not a permanent
retention decision or a claim of complete content erasure. The follow-up
must settle shared-document and mixed-owner workflow behavior and test
surviving content.

Profiles and managed-agent identity definitions belong to profile
cleanup. Memberships, personal preferences and access belong to account
cleanup. Media cleanup was implemented separately in #9365 and is now on
main. Deletion requests, approvals, progress/history and replay
protection stay.

The workflow orders account gating, global media cleanup, then
per-community content cleanup. Real requests still stop at the
unfinished account gate; demos simulate every stage without deletion.
Other unfinished real workflow stages fail explicitly. Existing demo
requests saved with `purge_db` must be recreated for `purge_content`.

Bulk client notifications remain separate work. Open views may retain
cached content and counts until refresh. The existing missing
reply-count button after refresh and ordinary UI access when the root is
deleted are outside this PR.

Replaces the content portion of #9355 and #9332. Related prior handler:
#8698.

Generated with Codex

---------

Signed-off-by: Ravneet Arora <rarora@squareup.com>
Co-authored-by: maincourse <37ce551b493d4a998caf030929c47bce0b6a0e43f1178b3a63c4151d7c16b76e@buzz.block.builderlab.xyz>
2026-11-17 10:17:45 -05:00
..