fix(cli): retry 2FA preflight then warn-and-continue on network errors - #3194
Conversation
Retry the reject_access_due_to_2fa RPC up to three times on transient transport failures, then warn and continue so bundle upload and channel add are not blocked by a flaky preflight probe. Real 2FA enforcement (shouldReject) and non-network RPC failures still abort the command. Remaining preflight network failures are still reported to PostHog. Co-authored-by: Martin DONADIEU <martindonadieu@gmail.com>
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Organization UI Review profile: ASSERTIVE Plan: Pro Run ID: 📒 Files selected for processing (2)
🔗 Linked repositories identifiedCodeRabbit considers these linked repositories for cross-repo context during reviews:
Included review availability: 0 reviews are currently available. Your included PR review attempts over the past 7 days set your current allowance at 2 reviews per hour. 📝 WalkthroughWalkthrough2FA compliance RPC checks now retry transient network failures up to three attempts. Persistent network failures emit warnings and telemetry without throwing. Non-transient errors retain existing logging and rejection behavior. Tests cover app and organization flows. Changes2FA compliance network resilience
Estimated code review effort: 3 (Moderate) | ~20 minutes Merge Risk: ⚪ Minimal · up to The retry and warning behavior is localized and preserves the intended enforcement and telemetry paths; no actionable merge-blocking risk remains after normal checks and review. Sequence Diagram(s)sequenceDiagram
participant check2FAComplianceForApp
participant callTwoFactorComplianceRpcWithRetry
participant SupabaseRPC
participant warnAndContinueTwoFactorPreflightNetworkFailure
check2FAComplianceForApp->>callTwoFactorComplianceRpcWithRetry: invoke 2FA compliance RPC
callTwoFactorComplianceRpcWithRetry->>SupabaseRPC: attempt request
SupabaseRPC-->>callTwoFactorComplianceRpcWithRetry: transient network failure
callTwoFactorComplianceRpcWithRetry->>SupabaseRPC: retry up to three attempts
SupabaseRPC-->>callTwoFactorComplianceRpcWithRetry: result or persistent failure
callTwoFactorComplianceRpcWithRetry-->>check2FAComplianceForApp: return RPC result
check2FAComplianceForApp->>warnAndContinueTwoFactorPreflightNetworkFailure: warn and capture persistent network failure
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
Full details: Description checkExplanation The description explains the motivation, behavior, business impact, and test plan. It covers the required summary and testing information. The repository checklist and screenshots section are not included, but these omissions are non-critical because the description is otherwise complete and relevant. ✨ Finishing Touches 💡 1📝 Generate docstrings 💡
Comment |
Merging this PR will not alter performance
Comparing Footnotes
|
Co-authored-by: Martin DONADIEU <martindonadieu@gmail.com>
|
@coderabbitai review |
There was a problem hiding this comment.
Pull request overview
This PR adjusts the Capgo CLI’s 2FA compliance preflight (RPCs reject_access_due_to_2fa_for_app / reject_access_due_to_2fa_for_org) to be more resilient to transient network failures by retrying and then warn-and-continue (fail-open) when the probe remains unreachable, while still enforcing 2FA when the probe succeeds and indicates rejection.
Changes:
- Added a shared retry helper for the 2FA preflight RPC and a warn+telemetry “continue” path after retries are exhausted.
- Updated the app/org 2FA preflight call sites to use the retry helper and to fail-open only on transient network errors.
- Updated the 2FA network tests to match the new behavior (retry + continue instead of throwing on network failures).
Reviewed changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
cli/src/shared/two-factor-compliance.ts |
Introduces retry wrapper + warn-and-continue path and telemetry capture for preflight network failures. |
cli/src/api/app.ts |
Routes app-scoped 2FA preflight through the retry helper and fail-open handler for transient network errors. |
cli/src/utils.ts |
Routes org-scoped 2FA preflight through the retry helper and fail-open handler for transient network errors. |
cli/test/test-2fa-compliance-network.mjs |
Updates tests to assert retry counts and warn-and-continue behavior on persistent network errors. |
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
Co-authored-by: Martin DONADIEU <martindonadieu@gmail.com>
|
@coderabbitai full review |
Send status 0 for handled preflight network captures so PostHog fingerprints match non-fatal telemetry, and disable PostHog in the 2FA compliance network test to avoid real network calls. Co-authored-by: Martin DONADIEU <martindonadieu@gmail.com>
|



Summary (AI generated)
reject_access_due_to_2fa_for_app/reject_access_due_to_2fa_for_orgpreflight RPC up to three times on transient network errors.shouldReject === true(real 2FA enforcement).TwoFactorComplianceNetworkErrorwithout wrapping them inCliUserError.Motivation (AI generated)
check2FAComplianceForAppis a UX preflight on success-path commands likebundle uploadandchannel add. When the probe hits a transientfetch failed, the CLI aborts even though the backend still enforces 2FA on the actual mutation. That blocks valid uploads on flaky connectivity.PR #3180 only reclassified the failure as
TwoFactorComplianceNetworkErrorwhile staying fail-closed — the command still stopped. This change keeps telemetry visibility but lets the success path continue after retries.Business Impact (AI generated)
Test Plan (AI generated)
bun run test:2fa-compliance-network— persistent network errors warn-and-continue after 3 attempts; retry succeeds on 2nd attempt;shouldRejectstill throws; non-network RPC errors still throw.bun run test:posthog-exception—TwoFactorComplianceNetworkErrorremains PostHog-eligible.bun run lint(CLI)bun run build(CLI)Generated with AI
Need help on this PR? Tag
@codesmith-botwith what you need. Autofix is disabled.Summary by CodeRabbit