Skip to content

Store versioned daily catalog streams and atomic collection claims - #93

Merged
sidneyswift merged 6 commits into
mainfrom
codex/luminate-streams
Oct 10, 2026
Merged

sidneyswift merged 6 commits into
mainfrom
codex/luminate-streams

Conversation

@sidneyswift

@sidneyswift sidneyswift commented Oct 9, 2026 •

Copy link
Copy Markdown
Contributor

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

@coderabbitai

coderabbitai Bot commented Oct 9, 2026 •

Copy link
Copy Markdown

Important

  • 🔍 Trigger review

This repository does not receive automatic reviews because it has fewer than 10 stars.

⚙️ Run configuration
  • Configuration used: defaults
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: f700a3a4-7439-45c7-b93d-8a720aa584cb

  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@supabase

supabase Bot commented Oct 9, 2026 •

Copy link
Copy Markdown

Updates to Preview Branch (codex/luminate-streams) ↗︎

Deployments Status Updated
Database ✅ Sat, 10 Oct 2026 03:52:35 UTC
Services ✅ Sat, 10 Oct 2026 03:52:35 UTC
APIs ✅ Sat, 10 Oct 2026 03:52:35 UTC

Tasks are run on every commit but only new migration files are pushed.
Close and reopen this PR if you want to apply changes from existing seed or migration files.

Tasks Status Updated
Configurations ✅ Sat, 10 Oct 2026 03:52:36 UTC
Migrations ✅ Sat, 10 Oct 2026 03:52:36 UTC
Seeding ✅ Sat, 10 Oct 2026 03:52:36 UTC
Edge Functions ✅ Sat, 10 Oct 2026 03:52:36 UTC

View logs for this Workflow Run ↗︎.
Learn more about Supabase for Git ↗︎.

@sidneyswift
sidneyswift marked this pull request as ready for review October 10, 2026 03:31

@cubic-dev-ai cubic-dev-ai Bot left a comment •

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 (

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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;

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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>

Comment thread tests/run_catalog_stream_tracking.sh Resolved
@@ -0,0 +1,104 @@
-- Private calendar-day series, separate from public cumulative song_measurements.

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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>

@cubic-dev-ai cubic-dev-ai Bot left a comment •

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

Comment thread tests/run_catalog_stream_tracking.sh Resolved
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;

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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>

@sidneyswift
sidneyswift merged commit 5d46616 into main Oct 10, 2026
9 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant