fix(cli): unblock app add RLS failures with pending onboarding apps - #2737
Conversation
Route CLI app create through the authorized /app API (same path as web), make icon upload best-effort, fix images storage INSERT/UPDATE RLS for app-icon create, and allow org.create_app keys to complete pending onboarding apps. Co-authored-by: Martin DONADIEU <martindonadieu@gmail.com>
Merging this PR will not alter performance
Comparing Footnotes
|
|
Note Reviews pausedIt looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the Use the following commands to manage reviews:
Use the checkboxes below for quick actions:
📝 WalkthroughWalkthroughThe CLI now creates apps and completes onboarding through Capgo app APIs. Backend endpoints support restricted onboarding completion, storage RLS policies cover pending apps, and tests validate the updated flows. A queue cleanup migration now tolerates missing metadata tables. ChangesApp onboarding flow
Queue migration compatibility
Estimated code review effort: 4 (Complex) | ~60 minutes Sequence Diagram(s)sequenceDiagram
participant CLI
participant AppAPI
participant Postgres
CLI->>AppAPI: POST /app with app metadata
AppAPI->>Postgres: Insert app
Postgres-->>AppAPI: Return app_id
AppAPI-->>CLI: Return creation response
CLI->>AppAPI: PUT /app/{appId} with need_onboarding=false
AppAPI->>Postgres: Authorize and update pending app
Postgres-->>AppAPI: Return completion state
AppAPI-->>CLI: Return updated app
Suggested labels: Suggested reviewers: 🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
Comment |
Narrow the images INSERT policy pgTAP assertion, skip Cloudflare for the pending-onboarding edge path, and guard pgmq.meta cleanup when the table is absent in Tinbase/PGlite. Co-authored-by: Martin DONADIEU <martindonadieu@gmail.com>
Avoid false negatives from Postgres policy formatting and false positives from matching unrelated apps.* columns next to foldername(name). Co-authored-by: Martin DONADIEU <martindonadieu@gmail.com>
Co-authored-by: Martin DONADIEU <martindonadieu@gmail.com>
Co-authored-by: Martin DONADIEU <martindonadieu@gmail.com>
Inside EXISTS subqueries over public.apps, bare name bound to apps.name so foldername(name) compared the app display name instead of the storage object path. Use objects.name explicitly. Co-authored-by: Martin DONADIEU <martindonadieu@gmail.com>
Co-authored-by: Martin DONADIEU <martindonadieu@gmail.com>
Bugbot couldn't run - usage limit reachedBugbot is counted against Cursor usage for this user or team, and this run hit a usage or spend limit. A user or team admin can review and increase usage limits in the Cursor dashboard. (requestId: serverGenReqId_5edb83d6-925c-4cb6-bef0-b95c20b216c7) |
There was a problem hiding this comment.
Stale comment
Risk: medium. Cursor Bugbot skipped (usage limit reached), so there is no clean automated review signal for this PR. Human review is needed for the RLS migration and app create/update path changes; assigned WcaleNieWolny and Dalanir.
Sent by Cursor Approval Agent: Pull Request Approver External
There was a problem hiding this comment.
Actionable comments posted: 2
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@cli/src/api/app.ts`:
- Around line 114-116: Update the onboarding failure handling in the app API
flow to reuse the existing formatAppCreateError logic from app/add.ts,
extracting server-side details from FunctionsHttpError.context instead of
relying only on error.message. Preserve the appId context in the thrown error
while ensuring backend codes such as cannot_access_app are surfaced.
In `@supabase/migrations/20260723120547_fix_app_create_storage_rls.sql`:
- Around line 22-52: Update the INSERT policy permission logic to allow
org.create_app when the referenced app exists in a pending-onboarding state, not
only when no app row exists. Preserve app.update_settings for existing
non-pending apps, and apply the same pending-app condition to the existing-app
lookup in the policy.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: ASSERTIVE
Plan: Pro
Run ID: d1c7a6e6-0b38-46ac-90b4-fe82df8582c3
📒 Files selected for processing (8)
cli/src/api/app.tscli/src/app/add.tssupabase/functions/_backend/public/app/post.tssupabase/functions/_backend/public/app/put.tssupabase/migrations/20260723113511_cleanup_queue_skip_missing_tables.sqlsupabase/migrations/20260723120547_fix_app_create_storage_rls.sqlsupabase/tests/62_test_images_storage_insert_policy.sqltests/app-create-pending-onboarding.test.ts
🔗 Linked repositories identified
CodeRabbit considers these linked repositories for cross-repo context during reviews:
Cap-go/capacitor-updater(manual)
Surface FunctionsHttpError details when completing pending onboarding, and allow org.create_app for images INSERT when the app is pending onboarding (icon upload after app row create). Co-authored-by: Martin DONADIEU <martindonadieu@gmail.com>
Bugbot couldn't run - usage limit reachedBugbot is counted against Cursor usage for this user or team, and this run hit a usage or spend limit. A user or team admin can review and increase usage limits in the Cursor dashboard. (requestId: serverGenReqId_54e342ab-4954-4bdd-bb0a-1caf918c41fb) |
There was a problem hiding this comment.
All reported issues were addressed
Reply with feedback, questions, or to request a fix.
Re-trigger cubic
Main commit 404fb50 accidentally deleted the submodule pointer while editing an unrelated script, which broke Builder onboarding TUI preview checkout (private/cli-mcp-tests missing). Restore the previous gitlink. Co-authored-by: Martin DONADIEU <martindonadieu@gmail.com>
Co-authored-by: Martin DONADIEU <martindonadieu@gmail.com>
Bugbot couldn't run - usage limit reachedBugbot is counted against Cursor usage for this user or team, and this run hit a usage or spend limit. A user or team admin can review and increase usage limits in the Cursor dashboard. (requestId: serverGenReqId_69008c55-88eb-48c7-aec0-e5cedd15d6a0) |
There was a problem hiding this comment.
Stale comment
Risk: medium. Cursor Bugbot skipped (usage limit reached), so automated review did not complete and I am not approving. Human review is still needed for the RLS migration and app onboarding changes; reviewers are already assigned.
Sent by Cursor Approval Agent: Pull Request Approver External
Co-authored-by: Martin DONADIEU <martindonadieu@gmail.com>
Co-authored-by: Martin DONADIEU <martindonadieu@gmail.com>
Bugbot couldn't run - usage limit reachedBugbot is counted against Cursor usage for this user or team, and this run hit a usage or spend limit. A user or team admin can review and increase usage limits in the Cursor dashboard. (requestId: serverGenReqId_dacdebb6-f1d9-434e-9adf-e5e8b7960fae) |
Bugbot couldn't run - usage limit reachedBugbot is counted against Cursor usage for this user or team, and this run hit a usage or spend limit. A user or team admin can review and increase usage limits in the Cursor dashboard. (requestId: serverGenReqId_92ec98a7-633b-4166-93b9-199fe7fd13e7) |
|





Summary (AI generated)
app add/ init creates apps through authorizedPOST /app(same path as the web console) instead of a direct PostgREST insert that hits RLS.apps.nameinstead of the storage object path, and alloworg.create_appfor icon upserts on missing/pending-onboarding apps.PUT /app/:idworks for API keys withorg.create_appeven withoutapp.update_settings, and the update reuses the advisory-lock Postgres session.--supa-host/--supa-anon(and local self-host config) via sharedresolveCapgoPublicApiHost.Motivation (AI generated)
New signups that leave a pending web-onboarding app could not register a real app ID through the CLI: create failed with a row-level security error (HTTP 400). The CLI was writing through PostgREST under RLS while the web path used the service-backed API, and the images storage policy also blocked icon upserts for create-only keys.
Business Impact (AI generated)
Unblocks new-customer onboarding and CLI setup for orgs that already have a pending web-onboarding app, reducing support load and failed trials.
Test Plan (AI generated)
bun test:db/ backend pgTAP includes images storage policy checksapp addwith API key after pending web onboarding--supa-host/--supa-anontargets{host}/functions/v1Generated with AI
Summary by CodeRabbit