Skip to content

Attach existing and new Spotify artists to organization rosters atomically - #969

Merged
sidneyswift merged 4 commits into
mainfrom
codex/onboarding-roster
Oct 8, 2026
Merged

sidneyswift merged 4 commits into
mainfrom
codex/onboarding-roster

Conversation

@sidneyswift

@sidneyswift sidneyswift commented Oct 8, 2026 •

Copy link
Copy Markdown
Contributor

Adding an existing Spotify artist now uses the same atomic resolve-and-attach operation as adding a new one, so both return the canonical artist with the requested organization roster relationship committed. Lookup and attachment failures fail closed; ambiguous identities return 409, revoked membership returns 403, and unavailable persistence returns a retryable 503. Name-only creation uses a second transaction so attachment failures roll back the new profile. Post-commit profile-read failures return 503 without losing the committed artist identity.

Tracks recoupable/app#2166. Depends on recoupable/database#83: apply that migration before deploying this API change. The existing HTTP response shape and 200/reused versus 201/created distinction are retained. No production data patch or canonical merge is included.

Validation: the full API suite passes (5,982 tests; 12 skipped). Non-admin allow/deny tests run through the real request validators with synthetic credentials. Readback and valuation tests preserve committed identity; the name-only adapter preserves response timestamps. The database PR separately verifies 16 PostgreSQL cases with the actual normalization trigger, concurrency, and rollback. API lint passes. A final boundary check also rejects malformed RPC JSON with an exact sanitized error (four adapter cases passed). The unused legacy identity lookup was removed.

Limitations: repository-wide type checking reports 196 errors in unchanged files outside this repair. The default production build stalled without progress and was stopped. A webpack build compiled successfully, then stopped at page-data collection because this isolated checkout has no PRIVY_PROJECT_SECRET configuration. No isolated hosted configuration or test identity is available in this checkout, so authenticated UI → API → persisted membership verification remains pending. This is implemented and fixture-tested, not merged or production-verified. Automatic PR preview checks are separate from authenticated end-to-end verification.

Release evidence: recoupable/app#2166 (comment) (hosted preview checkpoint). Final production commit/deployment and verification boundaries are recorded in the latest release checkpoint on recoupable/app#2166 and #2167.

@vercel

vercel Bot commented Oct 8, 2026 •

Copy link
Copy Markdown
Contributor

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated
api Ready Ready Preview Oct 8, 2026 1:54am UTC

Request Review

@coderabbitai

coderabbitai Bot commented Oct 8, 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: Repository: recoupable/api/.coderabbit.yaml
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 37e49ffa-b4f8-46fe-a043-d1223ab82a63
  • Autopilot · 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.

@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 13 files

Confidence score: 3/5

  • resolveOrCreateArtist.ts removes the explicit SPOTIFY social write and relies on an RPC side effect that the tests don't verify, so Spotify links may no longer be persisted. Confirm the RPC writes them and add an assertion for that behavior.
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="lib/artists/resolveOrCreateArtist.ts">

<violation number="1" location="lib/artists/resolveOrCreateArtist.ts:25">
P1: Custom agent: **Flag AI Slop and Fabricated Changes**

The new branch removes the explicit SPOTIFY social write and relies on an unverified RPC side effect, but the replacement tests mock the RPC and never assert that a newly created artist retains its `SPOTIFY` relationship. Add an integration/regression assertion against the migration, or make the RPC contract explicitly persist that social relationship while preserving the intended failure behavior.</violation>
</file>
Architecture diagram
sequenceDiagram
    participant Client as HTTP Client
    participant API as createArtistPostHandler
    participant Validator as validateCreateArtistBody
    participant Auth as Auth & Permission Validators
    participant Resolver as resolveOrCreateArtist
    participant Onboard as onboardSpotifyArtist
    participant DB as PostgreSQL (RPC/Transactions)
    participant Reader as selectAccountWithSocials
    participant Creator as createArtistInDb

    Client->>API: POST /api/artists (name, spotify_artist_id?, organization_id?)
    API->>Validator: Validate request body
    Validator->>Validator: CHANGED: spotify_artist_id must match /^[A-Za-z0-9]{22}$/
    alt Invalid Spotify ID format
        Validator-->>API: 400 Bad Request
        API-->>Client: { status: "error" }
    end

    Validator-->>API: Validated body
    API->>Auth: Verify account + organization membership
    alt Revoked or non-member
        Auth-->>API: 403 Forbidden
        API-->>Client: { status: "error", error: "Access denied" }
    end

    Auth-->>API: Authorized (account_id, organization_id)

    alt Spotify artist ID provided
        API->>Resolver: resolveOrCreateArtist(name, accountId, orgId, spotifyId)
        Resolver->>Onboard: NEW: onboardSpotifyArtist() - atomic resolve + attach
        Onboard->>DB: RPC onboard_spotify_artist(p_account_id, p_org_id, p_name, p_spotify_id)
        DB-->>Onboard: { artist_id, created } or Error

        alt RPC error - fail closed (no fallback)
            alt Permission denied (42501)
                Onboard-->>Resolver: 403 ArtistOnboardingError
            else Ambiguous identity (21000)
                Onboard-->>Resolver: 409 ArtistOnboardingError
            else Persistence unavailable (PGRST202/23514)
                Onboard-->>Resolver: 503 ArtistOnboardingError
            end
            Resolver-->>API: Reject
            API-->>Client: Status preserved (403/409/503)
        end

        Onboard-->>Resolver: { artist_id: "canonical", created }
        Resolver->>Reader: selectAccountWithSocials(artist_id)
        alt Readback failed
            Reader-->>Resolver: null
            Resolver-->>API: 503 retryable error
        end
        Reader-->>Resolver: Artist record
        Resolver-->>API: { artist, created }
        alt Artist already existed
            API-->>Client: 200 OK (reused)
        else New artist created
            API-->>Client: 201 Created
        end

    else Name-only creation (no Spotify ID)
        API->>Resolver: resolveOrCreateArtist(name, accountId, orgId)
        Resolver->>Creator: createArtistInDb(name, accountId, orgId)
        Creator->>DB: Insert account + artist + org relationship
        DB-->>Creator: relationship_id or null
        alt Organization attach returned no relationship
            Creator-->>Resolver: null
            Resolver-->>API: 500 error
            API-->>Client: { status: "error" }
        end
        Creator-->>Resolver: Created artist
        Resolver-->>API: { artist, created: true }
        API-->>Client: 201 Created
    end
Loading

Reply with feedback, questions, or to request a fix.

View guided diff | Turn on auto-fix | Re-trigger cubic

created: false,
};
}
const result = await onboardSpotifyArtist({ name, accountId, organizationId, spotifyArtistId });

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: Custom agent: Flag AI Slop and Fabricated Changes

The new branch removes the explicit SPOTIFY social write and relies on an unverified RPC side effect, but the replacement tests mock the RPC and never assert that a newly created artist retains its SPOTIFY relationship. Add an integration/regression assertion against the migration, or make the RPC contract explicitly persist that social relationship while preserving the intended failure behavior.

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 lib/artists/resolveOrCreateArtist.ts, line 25:

<comment>The new branch removes the explicit SPOTIFY social write and relies on an unverified RPC side effect, but the replacement tests mock the RPC and never assert that a newly created artist retains its `SPOTIFY` relationship. Add an integration/regression assertion against the migration, or make the RPC contract explicitly persist that social relationship while preserving the intended failure behavior.</comment>

<file context>
@@ -18,47 +16,16 @@ export interface ResolveOrCreateArtistResult {
-        created: false,
-      };
-    }
+    const result = await onboardSpotifyArtist({ name, accountId, organizationId, spotifyArtistId });
+    const artist = await selectAccountWithSocials(result.artist_id);
+    if (!artist) throw new Error("Could not read artist after onboarding. Please retry.");
</file context>

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Validated by the companion database PR: the fixture now loads the actual social-normalization triggers and asserts the persisted Spotify social and artist relationship. All 15 PostgreSQL tests pass, including concurrent creation and rollback. Supabase Preview is also passing after the additive migration correction.

Comment thread lib/artists/createArtistInDb.ts Resolved
Comment thread lib/artists/resolveOrCreateArtist.ts Resolved
Comment thread lib/artists/resolveOrCreateArtist.ts Resolved

@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.

All reported issues were addressed across 13 files (changes from recent commits).

Reply with feedback, questions, or to request a fix.

View guided diff | Turn on auto-fix | Re-trigger cubic

@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.

0 issues found across 2 files (changes from recent commits).

Confidence score: 5/5

  • Automated review surfaced no issues in the provided summaries.
  • No files require special attention.

Requires human review: Auto-approval blocked by 1 unresolved issue from previous reviews.

View guided diff | Turn on auto-fix | Re-trigger cubic

This branch was successfully deployed

1 active deployment
Preview — b9484ab2 Deployed Oct 8, 2026 by vercel[bot]
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