From 88b93f50a6fdaadb329bf27737d4ca6e63fe11a1 Mon Sep 17 00:00:00 2001 From: Bao Tran Date: Tue, 26 May 2026 23:58:41 -0400 Subject: [PATCH] fix: extension-bridge poller query + pending_queue_actions schema Two bugs that silently broke all extension mod actions (escalate/remove/approve): 1. Poller subreddit mismatch in extension-bridge.ts: pollPendingActions queried subreddit_id ILIKE subredditName, but the enqueue handler stores the Reddit t5_ ID in subreddit_id and the display name in subreddit_name. The query never matched so extension escalations were never picked up by the Devvit cron. Fixed by OR-ing across all three patterns: subreddit_name by display name, subreddit_id by display name (old rows), and subreddit_id by t5_ ID (new rows). 2. Schema mismatch in pending_queue_actions: The table was created with id UUID which rejects the sha256 hex strings the enqueue handler inserts, returning 500 on every action. The columns subreddit_name and verdict_hash were also missing. Added migration 20260526000001 to fix id to TEXT and add the missing columns. --- .../src/server/core/extension-bridge.ts | 11 +++++----- ...00001_fix_pending_queue_actions_schema.sql | 21 +++++++++++++++++++ 2 files changed, 27 insertions(+), 5 deletions(-) create mode 100644 supabase/migrations/20260526000001_fix_pending_queue_actions_schema.sql diff --git a/collab-guard/src/server/core/extension-bridge.ts b/collab-guard/src/server/core/extension-bridge.ts index a900933..afbc93a 100644 --- a/collab-guard/src/server/core/extension-bridge.ts +++ b/collab-guard/src/server/core/extension-bridge.ts @@ -148,14 +148,15 @@ export const pollPendingActions = async ( const client = await getSupabaseAdmin(); if (!client) return []; + // Extension sends subreddit_id = t5_xxx and subreddit_name = display name. + // Old rows (before subreddit_name column was added) stored the display name + // in subreddit_id. Match either pattern so both old and new rows are picked up. const { data, error } = await client .from('pending_queue_actions') .select('*') - // cgbaov2 schema stores the subreddit name in subreddit_id. - // Reddit/Devvit may lowercase subredditName in scheduler context while - // the extension preserves URL casing, so match this boundary - // case-insensitively. - .ilike('subreddit_id', scope.subredditName) + .or( + `subreddit_name.ilike.${scope.subredditName},subreddit_id.ilike.${scope.subredditName},subreddit_id.ilike.${scope.subredditId}` + ) .eq('status', 'pending') .order('requested_at', { ascending: true }) .limit(POLL_LIMIT); diff --git a/supabase/migrations/20260526000001_fix_pending_queue_actions_schema.sql b/supabase/migrations/20260526000001_fix_pending_queue_actions_schema.sql new file mode 100644 index 0000000..710bfa5 --- /dev/null +++ b/supabase/migrations/20260526000001_fix_pending_queue_actions_schema.sql @@ -0,0 +1,21 @@ +-- Fix pending_queue_actions schema mismatches +-- +-- The original migration created id as UUID, but the enqueue edge function +-- inserts a sha256 hex string (not a valid UUID), causing every enqueue call +-- to return 500. subreddit_name and verdict_hash were also missing columns +-- that the handler inserts, producing the same error. +-- +-- The poller in extension-bridge.ts was also querying subreddit_id ILIKE +-- subredditName, but the handler stores the t5_ Reddit ID in subreddit_id +-- and the display name in subreddit_name, so the query never matched. +-- That code fix is in collab-guard/src/server/core/extension-bridge.ts. + +-- 1. Change id from UUID to TEXT (handler inserts sha256 hex, not a UUID) +ALTER TABLE public.pending_queue_actions ALTER COLUMN id TYPE TEXT USING id::TEXT; +ALTER TABLE public.pending_queue_actions ALTER COLUMN id DROP DEFAULT; + +-- 2. Add subreddit_name (handler inserts body.subredditName here) +ALTER TABLE public.pending_queue_actions ADD COLUMN IF NOT EXISTS subreddit_name TEXT; + +-- 3. Add verdict_hash (handler inserts body.verdictHash here) +ALTER TABLE public.pending_queue_actions ADD COLUMN IF NOT EXISTS verdict_hash TEXT;