fix(cli): treat existing channel as success on channel add
Merged
RI
2mo ago+188+188+012345678901234567890123456789-4-4-0123456789
Summary (AI generated)
- Make
channel addidempotent whenPOST /channelreturns aunique_name_app_idduplicate error but the current API key can already read that channel. - Verify readability via PostgREST
findChannel(same path as console/preview keys) before succeeding. - Emit
CLI Recovered Channel Already Existsanalytics instead ofCreate channelon the recovery path. - Add
test:channel-add-existsunit coverage for duplicate detection and ownership verification.
Motivation (AI generated)
PostHog Capgo project 22029 shows recurring CLI exceptions for duplicate channel creation:
- Issue:
019feae0-980e-7443-b2b7-3fc76c463a6e(generic non-2xx; duplicate constraint split across fingerprints) - Symptom:
capgo initalready treatsunique_name_app_idas recoverable (isChannelAlreadyExistsError+ "use existing" incli/src/init/channel-conflict.ts), but barechannel addthrows on anycreateChannelerror, so CI re-runs and repeat CLI calls die on duplicate channels.
This follows the success-path pattern from #3186 (app add idempotency): real failures stay tracked in PostHog; this is a genuine success path when the channel already exists for the caller's API key.
Contrast with #3179: that PR only reclassifies 4xx errors as CliUserError to silence PostHog — it does not recover. Do not merge #3179 for this use case.
Business Impact (AI generated)
- Users and CI pipelines that re-run
channel addfor an existing channel can continue without a hard stop. - PostHog keeps capturing true failures (RBAC, 5xx, network, inaccessible duplicates) while recovery events provide a success funnel for idempotent adds.
- Aligns
channel addbehavior withcapgo initand upcoming app-add idempotency (#3186).
Test Plan (AI generated)
-
bun run test:channel-add-exists -
bun run test:init-app-conflict -
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
- Improved channel creation handling when a channel already exists.
- Readable duplicates are recovered successfully.
- Inaccessible duplicates now show a specific error.
- Access-check failures are reported separately.
- API error messages are formatted more clearly when details are available.
-
Tests
- Added coverage for readable, inaccessible, and non-duplicate channel creation outcomes.
- Added validation for invalid access-check results and formatted conflict errors.