fix(cli): treat owned app add duplicates as success
Merged
RI
2mo ago+342+342+012345678901234567890123456789-20-20-01234567890123456789
Summary (AI generated)
- Make
app addidempotent whenPOST /appreturns a duplicate-app error but the current API key can already read that app. - Detect duplicates via HTTP 409,
app_id_already_exists, orApp ID already existsresponse bodies. - Verify ownership with
GET /app/before succeeding; still throw when the app ID is globally taken. - Emit
CLI Recovered App Already Existsanalytics instead ofApp Createdon the recovery path. - Add
test:app-add-existsunit coverage and update the app-add source contract test.
Motivation (AI generated)
PostHog Capgo project 22029 shows recurring CLI exceptions over the last 7 days:
- Message:
Could not add app app_id_already_exists | App ID already exists - Impact: ~29 unique users running
app add/ onboarding twice (orinitthenadd) currently crash instead of continuing.
This follows the interactive-recovery pattern from #3184: do not convert the duplicate-owned case to CliUserError just to hide PostHog. Real failures stay tracked; this is a genuine success path when the app already exists for the caller's API key.
Business Impact (AI generated)
- Users who re-run
app addfor an app they already own can continue onboarding/upload flows without a hard stop. - PostHog keeps capturing true failures (taken app IDs, RBAC, validation) while recovery events provide a success funnel for idempotent adds.
- Reduces support friction and abandoned onboarding for repeat CLI runs.
Test Plan (AI generated)
-
bun run test:app-add-exists -
bun run test:app-created-source -
bun run lintincli/ -
bun run buildincli/ - CI
clitest suite
Generated with AI


Need help on this PR? Tag @codesmith-bot with what you need. Autofix is disabled.
Summary by CodeRabbit
-
Bug Fixes
- App creation now detects duplicate app IDs from service responses and error messages.
- Existing apps you own can be recovered with a clear success message.
- App IDs already claimed by another organization are rejected with a distinct message.
- Unrelated creation and permission errors continue to be reported appropriately.
-
Tests
- Added coverage for duplicate detection, ownership verification, organization lookup, recovery, and error handling.