Files
buzz/schema/functions/revoke_restricted_agent_invites.sql
Brad Seiler d2c2a74943 fix(relay): revoke invitations durably and fence restricted claims
Keep v1 natural drain with an optional UTC cutoff. Serialize claim and mint policy reads with restriction and owner writes. Share historical revocation repair across migration and desired-state upgrades while retaining deletion fences.

Co-authored-by: Codex <codex@openai.com>
Signed-off-by: Brad Seiler <seiler@squareup.com>
Signed-off-by: Local Builder <1c476cb1127ea270cb900bdc3891060140bdd1173f91498030ee9b4db01c2f20@buzz.block.builderlab.xyz>
2026-10-17 17:20:50 +00:00

17 lines
678 B
PL/PgSQL

-- Learning a verified owner must not revive invites issued by its restricted agent.
CREATE FUNCTION revoke_restricted_agent_invites() RETURNS TRIGGER
LANGUAGE plpgsql AS $$
BEGIN
IF NEW.agent_owner_pubkey IS NOT NULL AND EXISTS (
SELECT 1 FROM community_bans WHERE community_id = NEW.community_id
AND pubkey = NEW.agent_owner_pubkey AND banned
AND (ban_expires_at IS NULL OR ban_expires_at > clock_timestamp())
) THEN
UPDATE relay_invites SET revoked_at = clock_timestamp()
WHERE community_id = NEW.community_id AND created_by = encode(NEW.pubkey, 'hex')
AND revoked_at IS NULL;
END IF;
RETURN NEW;
END
$$;