mirror of
https://github.com/block/buzz.git
synced 2026-11-26 19:21:50 +00:00
Merge remote-tracking branch 'origin/main' into codex/agent-owned-workflow-management
* origin/main: (27 commits) chore(deps): pin earshot below 1.2.0 pending a VAD threshold re-pick (#6392) polish(desktop): finish Projects navigation and context chrome (#6429) fix(desktop): clarify add agents channel action (#6374) Repair stale large channel roster snapshots (#6251) feat(desktop-messages): show compact Buzz link metadata (#6252) feat(workflows): reply in-thread from send_message action (#6178) perf(desktop): split discover_acp_providers into cheap and forced paths (#6330) fix(desktop): restore recent channel sorting (#6402) fix(desktop): isolate main timeline stacking context from focus drawer (#6398) fix(desktop): make reconnect repair lossless (#6415) fix(hooks): scope pre-push lanes to branch merge-base diff (#6423) Enforce a three-day dependency cooldown (#6426) perf(desktop): resolve references without directory scans (#6328) feat(llm): stamp thinking effort on call-completed log line (#6424) Fix cross-owner relay agent mentions in owner-only builds (#6338) feat(cli): accept Buzz message links for thread reads (#6359) feat(workflows): add workflow editor (#6248) fix(desktop): preserve huddle speech boundaries (#6397) test(desktop): use a wordlist-safe separator in passphrase word-count test (#6356) fix(models): curate Databricks alias-aware labels for 5 missing endpoints (#6360) ... Signed-off-by: Luke Tornquist <tornquist@squareup.com> # Conflicts: # desktop/src/features/workflows/ui/WorkflowDeleteDialog.tsx # desktop/src/features/workflows/ui/WorkflowsView.tsx
This commit is contained in:
@@ -993,6 +993,85 @@ AFTER INSERT ON events
|
||||
DEFERRABLE INITIALLY DEFERRED
|
||||
FOR EACH ROW EXECUTE FUNCTION refresh_channel_ttl_after_event_insert();
|
||||
|
||||
-- Channel roster snapshot fence (keep in sync with migrations/0032).
|
||||
-- Prevent mixed-version relay pods from publishing a stale NIP-29 member
|
||||
-- snapshot after a newer canonical roster has been committed.
|
||||
--
|
||||
-- Old binaries already serialize kind 39002 replacement on the replacement
|
||||
-- advisory key. This trigger adds the channel-membership key at INSERT time,
|
||||
-- after that canonical key, and validates every p tag against the current
|
||||
-- active membership set and roles. New binaries take both keys in the same
|
||||
-- order before capture and replacement. Thus old and new writers remain
|
||||
-- compatible during a rolling deploy.
|
||||
CREATE OR REPLACE FUNCTION guard_channel_roster_snapshot()
|
||||
RETURNS TRIGGER AS $$
|
||||
DECLARE
|
||||
canonical_members TEXT[];
|
||||
snapshot_members TEXT[];
|
||||
BEGIN
|
||||
IF NEW.kind <> 39002 OR NEW.channel_id IS NULL THEN
|
||||
RETURN NEW;
|
||||
END IF;
|
||||
|
||||
PERFORM pg_advisory_xact_lock(hashtextextended(
|
||||
'buzz_channel_membership:' || NEW.community_id::text || ':' || NEW.channel_id::text,
|
||||
0
|
||||
));
|
||||
|
||||
SELECT COALESCE(
|
||||
array_agg(encode(cm.pubkey, 'hex') || ':' || cm.role::text ORDER BY cm.pubkey),
|
||||
ARRAY[]::TEXT[]
|
||||
)
|
||||
INTO canonical_members
|
||||
FROM channel_members cm
|
||||
WHERE cm.community_id = NEW.community_id
|
||||
AND cm.channel_id = NEW.channel_id
|
||||
AND cm.removed_at IS NULL;
|
||||
|
||||
-- A roster is canonical only when every p tag uses the emitted four-field
|
||||
-- shape, contains a 32-byte hex pubkey and valid authoritative role, has no
|
||||
-- duplicate members, and exactly matches the active membership rows.
|
||||
IF EXISTS (
|
||||
SELECT 1
|
||||
FROM jsonb_array_elements(NEW.tags) AS roster_tag(tag_json)
|
||||
WHERE roster_tag.tag_json->>0 = 'p'
|
||||
AND (
|
||||
jsonb_array_length(roster_tag.tag_json) <> 4
|
||||
OR COALESCE(roster_tag.tag_json->>1, '') !~ '^[0-9a-fA-F]{64}$'
|
||||
OR roster_tag.tag_json->>2 <> ''
|
||||
OR COALESCE(roster_tag.tag_json->>3, '') NOT IN ('owner', 'admin', 'bot', 'member', 'guest')
|
||||
)
|
||||
) THEN
|
||||
RAISE EXCEPTION 'kind 39002 roster contains an invalid p tag'
|
||||
USING ERRCODE = '23514';
|
||||
END IF;
|
||||
|
||||
SELECT COALESCE(
|
||||
array_agg(
|
||||
lower((roster_tag.tag_json->>1)) || ':' || (roster_tag.tag_json->>3)
|
||||
ORDER BY decode((roster_tag.tag_json->>1), 'hex')
|
||||
),
|
||||
ARRAY[]::TEXT[]
|
||||
)
|
||||
INTO snapshot_members
|
||||
FROM jsonb_array_elements(NEW.tags) AS roster_tag(tag_json)
|
||||
WHERE roster_tag.tag_json->>0 = 'p';
|
||||
|
||||
IF snapshot_members IS DISTINCT FROM canonical_members THEN
|
||||
RAISE EXCEPTION 'kind 39002 roster does not match canonical channel membership'
|
||||
USING ERRCODE = '23514';
|
||||
END IF;
|
||||
|
||||
RETURN NEW;
|
||||
END;
|
||||
$$ LANGUAGE plpgsql;
|
||||
|
||||
DROP TRIGGER IF EXISTS trg_events_guard_channel_roster_snapshot ON events;
|
||||
CREATE TRIGGER trg_events_guard_channel_roster_snapshot
|
||||
BEFORE INSERT ON events
|
||||
FOR EACH ROW EXECUTE FUNCTION guard_channel_roster_snapshot();
|
||||
|
||||
|
||||
-- Replica-fence floor guard (keep in sync with migrations/0021). A deferred
|
||||
-- constraint trigger re-checks, inside COMMIT processing, that channel-bearing
|
||||
-- event rows are no older than `buzz.created_at_floor` seconds before commit
|
||||
|
||||
Reference in New Issue
Block a user