Repository navigation
Store versioned daily catalog streams and atomic collection claims - #93
Conversation
|
Important
This repository does not receive automatic reviews because it has fewer than 10 stars. ⚙️ Run configuration
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
|
Updates to Preview Branch (codex/luminate-streams) ↗︎
Tasks are run on every commit but only new migration files are pushed.
View logs for this Workflow Run ↗︎. |
There was a problem hiding this comment.
4 issues found across 3 files
Prompt for AI agents (unresolved issues)
Check if these issues are valid — if so, understand the root cause of each and fix them. When an issue isn't valid or won't be fixed in this PR, reply in its thread with the reason and then resolve the thread. If appropriate, use sub-agents to investigate and fix each issue separately.
<file name="supabase/migrations/20261009193000_catalog_daily_stream_tracking.sql">
<violation number="1" location="supabase/migrations/20261009193000_catalog_daily_stream_tracking.sql:1">
P3: Custom agent: **Enforce Clear Code Style and Maintainability Practices**
This new migration is 104 lines, exceeding the repository rule's under-100-line limit. Split the migration into cohesive ordered migrations or otherwise reduce it below 100 lines before merging.</violation>
<violation number="2" location="supabase/migrations/20261009193000_catalog_daily_stream_tracking.sql:61">
P2: `FOR UPDATE` makes per-ISRC commits for this catalog wait through the prior observation insert, although they write disjoint keys. Use `FOR SHARE` here so tracking updates still fence commits while independent tracks insert concurrently.</violation>
<violation number="3" location="supabase/migrations/20261009193000_catalog_daily_stream_tracking.sql:63">
P1: `account_catalogs` and `catalog_songs` are only checked with `EXISTS`, so concurrent access or song removal can commit after the check while this write still succeeds. Lock both matching rows through the transaction so removals wait or the commit is rejected.</violation>
<violation number="4" location="supabase/migrations/20261009193000_catalog_daily_stream_tracking.sql:72">
P2: Custom agent: **Flag AI Slop and Fabricated Changes**
The PR summary says unchanged days are copied into later runs with fresh receipts, but this guard skips those rows when their provider ID and stream value are unchanged. Update the summary to describe historical reuse, or change the implementation to insert the claimed copies.</violation>
</file>
Reply with feedback, questions, or to request a fix.
View guided diff | Turn on auto-fix | Re-trigger cubic
| if not found then return false; end if; | ||
| select * into t from public.catalog_stream_tracking where catalog_id=r.catalog_id for update; | ||
| if not t.enabled or t.revision <> r.revision or r.status not in ('queued','running') or | ||
| not exists (select 1 from public.account_catalogs where catalog=r.catalog_id and account=t.owner_id) or |
There was a problem hiding this comment.
P1: account_catalogs and catalog_songs are only checked with EXISTS, so concurrent access or song removal can commit after the check while this write still succeeds. Lock both matching rows through the transaction so removals wait or the commit is rejected.
Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. When an issue isn't valid or won't be fixed in this PR, reply in its thread with the reason and then resolve the thread. At supabase/migrations/20261009193000_catalog_daily_stream_tracking.sql, line 63:
<comment>`account_catalogs` and `catalog_songs` are only checked with `EXISTS`, so concurrent access or song removal can commit after the check while this write still succeeds. Lock both matching rows through the transaction so removals wait or the commit is rejected.</comment>
<file context>
@@ -0,0 +1,104 @@
+ if not found then return false; end if;
+ select * into t from public.catalog_stream_tracking where catalog_id=r.catalog_id for update;
+ if not t.enabled or t.revision <> r.revision or r.status not in ('queued','running') or
+ not exists (select 1 from public.account_catalogs where catalog=r.catalog_id and account=t.owner_id) or
+ not exists (select 1 from public.catalog_songs where catalog=r.catalog_id and song=p_isrc) then return false; end if;
+ if p_result->>'state' in ('complete','partial') then
</file context>
| (select (v->>'streams')::bigint from jsonb_array_elements(p_result->'days') v where v->>'date'=d::date::text), | ||
| p_result->>'provider_recording_id',p_result->>'source_hash',(p_result->>'retrieved_at')::timestamptz | ||
| from generate_series(r.since::timestamp,r.until::timestamp,interval '1 day') d | ||
| where not exists ( |
There was a problem hiding this comment.
P2: Custom agent: Flag AI Slop and Fabricated Changes
The PR summary says unchanged days are copied into later runs with fresh receipts, but this guard skips those rows when their provider ID and stream value are unchanged. Update the summary to describe historical reuse, or change the implementation to insert the claimed copies.
Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. When an issue isn't valid or won't be fixed in this PR, reply in its thread with the reason and then resolve the thread. At supabase/migrations/20261009193000_catalog_daily_stream_tracking.sql, line 72:
<comment>The PR summary says unchanged days are copied into later runs with fresh receipts, but this guard skips those rows when their provider ID and stream value are unchanged. Update the summary to describe historical reuse, or change the implementation to insert the claimed copies.</comment>
<file context>
@@ -0,0 +1,104 @@
+ (select (v->>'streams')::bigint from jsonb_array_elements(p_result->'days') v where v->>'date'=d::date::text),
+ p_result->>'provider_recording_id',p_result->>'source_hash',(p_result->>'retrieved_at')::timestamptz
+ from generate_series(r.since::timestamp,r.until::timestamp,interval '1 day') d
+ where not exists (
+ select 1 from (
+ select streams,provider_recording_id from public.catalog_stream_observations
</file context>
| begin | ||
| select * into r from public.catalog_stream_runs where id=p_run_id; | ||
| if not found then return false; end if; | ||
| select * into t from public.catalog_stream_tracking where catalog_id=r.catalog_id for update; |
There was a problem hiding this comment.
P2: FOR UPDATE makes per-ISRC commits for this catalog wait through the prior observation insert, although they write disjoint keys. Use FOR SHARE here so tracking updates still fence commits while independent tracks insert concurrently.
Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. When an issue isn't valid or won't be fixed in this PR, reply in its thread with the reason and then resolve the thread. At supabase/migrations/20261009193000_catalog_daily_stream_tracking.sql, line 61:
<comment>`FOR UPDATE` makes per-ISRC commits for this catalog wait through the prior observation insert, although they write disjoint keys. Use `FOR SHARE` here so tracking updates still fence commits while independent tracks insert concurrently.</comment>
<file context>
@@ -0,0 +1,104 @@
+begin
+ select * into r from public.catalog_stream_runs where id=p_run_id;
+ if not found then return false; end if;
+ select * into t from public.catalog_stream_tracking where catalog_id=r.catalog_id for update;
+ if not t.enabled or t.revision <> r.revision or r.status not in ('queued','running') or
+ not exists (select 1 from public.account_catalogs where catalog=r.catalog_id and account=t.owner_id) or
</file context>
| @@ -0,0 +1,104 @@ | |||
| -- Private calendar-day series, separate from public cumulative song_measurements. | |||
There was a problem hiding this comment.
P3: Custom agent: Enforce Clear Code Style and Maintainability Practices
This new migration is 104 lines, exceeding the repository rule's under-100-line limit. Split the migration into cohesive ordered migrations or otherwise reduce it below 100 lines before merging.
Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. When an issue isn't valid or won't be fixed in this PR, reply in its thread with the reason and then resolve the thread. At supabase/migrations/20261009193000_catalog_daily_stream_tracking.sql, line 1:
<comment>This new migration is 104 lines, exceeding the repository rule's under-100-line limit. Split the migration into cohesive ordered migrations or otherwise reduce it below 100 lines before merging.</comment>
<file context>
@@ -0,0 +1,104 @@
+-- Private calendar-day series, separate from public cumulative song_measurements.
+create table public.catalog_stream_tracking (
+ catalog_id uuid primary key references public.catalogs(id) on delete cascade,
</file context>
There was a problem hiding this comment.
1 issue found across 3 files (changes from recent commits).
Prompt for AI agents (unresolved issues)
Check if these issues are valid — if so, understand the root cause of each and fix them. When an issue isn't valid or won't be fixed in this PR, reply in its thread with the reason and then resolve the thread. If appropriate, use sub-agents to investigate and fix each issue separately.
<file name="supabase/migrations/20261010035000_catalog_stream_membership_locks.sql">
<violation number="1" location="supabase/migrations/20261010035000_catalog_stream_membership_locks.sql:10">
P2: Deleting the owning account can deadlock with this function: its FK cascades lock `account_catalogs` before `catalog_stream_tracking`, while this function locks them in reverse order. Align the cascade and commit lock order to avoid aborting either transaction.</violation>
</file>
Reply with feedback, questions, or to request a fix.
View guided diff | Turn on auto-fix | Re-trigger cubic
| if not found then return false; end if; | ||
| select * into t from public.catalog_stream_tracking where catalog_id=r.catalog_id for update; | ||
| -- Keep membership removals outside the successful commit's transaction boundary. | ||
| perform 1 from public.account_catalogs where catalog=r.catalog_id and account=t.owner_id for share; |
There was a problem hiding this comment.
P2: Deleting the owning account can deadlock with this function: its FK cascades lock account_catalogs before catalog_stream_tracking, while this function locks them in reverse order. Align the cascade and commit lock order to avoid aborting either transaction.
Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. When an issue isn't valid or won't be fixed in this PR, reply in its thread with the reason and then resolve the thread. At supabase/migrations/20261010035000_catalog_stream_membership_locks.sql, line 10:
<comment>Deleting the owning account can deadlock with this function: its FK cascades lock `account_catalogs` before `catalog_stream_tracking`, while this function locks them in reverse order. Align the cascade and commit lock order to avoid aborting either transaction.</comment>
<file context>
@@ -0,0 +1,40 @@
+ if not found then return false; end if;
+ select * into t from public.catalog_stream_tracking where catalog_id=r.catalog_id for update;
+ -- Keep membership removals outside the successful commit's transaction boundary.
+ perform 1 from public.account_catalogs where catalog=r.catalog_id and account=t.owner_id for share;
+ if not found then return false; end if;
+ perform 1 from public.catalog_songs where catalog=r.catalog_id and song=p_isrc for share;
</file context>
Daily Luminate tracking needs a private calendar-day series with atomic daily claims and retained correction history. These migrations add subscriptions, run receipts, versioned observations and service-only claim/commit/read functions; unchanged values are reused with fresh per-run receipts.
Stream commits lock tracking plus current owner and song membership rows, fencing concurrent removal. Tracking stays exclusively locked because the commit also merges shared run coverage; switching to a shared lock can deadlock on lock upgrades. The original migration is preserved after application; the locking fix is a separate migration.
Validation: disposable PostgreSQL 17 service-role checks passed, including real concurrent owner/song deletion blocking and parent-cascade completion without deadlock, daily claim and write idempotency, explicit zero vs missing, retained corrections, pause/revision/ownership/membership fences, account deletion cascade and denied browser privileges. Production ledger and RLS/access controls verified for all three migrations. The runner accepts PG_BINDIR or discovers a PostgreSQL installation.
API dependency: recoupable/api#984