mirror of
https://github.com/block/buzz.git
synced 2026-11-16 06:11:34 +00:00
`bot` has the same permissions as `member`; it only labels a key with a recorded agent owner. Instead of storing that label and converting rows when an owner is recorded, store `member` for both ordinary roles and compute the label wherever a role is read: rosters, member lists, role reads, DM participants and the bot list. An agent owner is recorded once and never changes, so a key's label changes at most once. - Writers store `member` for an ordinary role; reads show `bot` exactly when users.agent_owner_pubkey is set for the key in that community. - The app-side roster fence treats `member` and `bot` as one role, so an owner recorded between roster capture and insert does not refuse the publication. - After recording an owner, a background task lists the agent's active ordinary channels and republishes their rosters. - BUZZ_RECONCILE_BOT_ROSTERS runs a one-shot startup repair of rosters that show a stale label (for example, ones older relays published). Nothing scans at every startup. - Migration 0074 drops the 0032 roster trigger, which compared roster labels with the stored role exactly. Every relay must run #8611 first. Co-authored-by: Larry <627498bd4bd1f281a16431e3c6cce3b5c25b6692798c78672298aefbf2f8f8b5@buzz.block.builderlab.xyz> Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Signed-off-by: Logan Johnson <loganj@squareup.com>
13 lines
699 B
SQL
13 lines
699 B
SQL
-- INSERT OR UPDATE OF: an UPDATE can move a previously exempt row into the
|
|
-- guarded set (channel_id NULL -> NOT NULL) or move a channel row's
|
|
-- created_at below the fence, so both mutation paths re-run the guard on the
|
|
-- NEW row. A created_at rewrite that crosses partition bounds runs as
|
|
-- DELETE + INSERT and hits the cloned AFTER INSERT guard on the destination
|
|
-- partition; an in-partition rewrite fires the UPDATE OF arm.
|
|
CREATE CONSTRAINT TRIGGER events_created_at_floor
|
|
AFTER INSERT OR UPDATE OF created_at, channel_id ON events
|
|
DEFERRABLE INITIALLY DEFERRED
|
|
FOR EACH ROW
|
|
EXECUTE FUNCTION events_created_at_floor_guard();
|
|
SELECT attach_community_write_fence('events');
|