Skip to content

fix: make the 10-minute back-off after a failed setup actually apply [ENG-7265] - #93

Open
mattinannt wants to merge 2 commits into
mainfrom
fix/ENG-7265_error-state-backoff
Open

mattinannt wants to merge 2 commits into
mainfrom
fix/ENG-7265_error-state-backoff

Conversation

@mattinannt

Copy link
Copy Markdown
Member

Fixes ENG-7265

What & why

When the first setup fails, the SDK stores an error state that should block setup for 10 minutes. That back-off never worked, for three reasons. This PR fixes all three.

  1. The check was inverted (as the ticket says). shouldReturnEarlyForErrorState skipped setup after the error state expired and retried while it was still active. It now skips only while !isNowExpired(expiresAt).
  2. isNowExpired could not read stored dates. Config goes through JSON.stringify/JSON.parse in AsyncStorage, so expiresAt comes back as an ISO string. new Date() >= "2026-…" compares a number with NaN and is always false. With fix 1 alone, a reloaded error state would block setup forever. isNowExpired now normalises with new Date(x).getTime().
  3. The stored error state was never loaded. handleErrorOnFirstSetup stores only { status }, with no workspace. loadFromStorage read parsedConfig.workspace.expiresAt unguarded, threw a TypeError, and dropped the whole config. Setup therefore never saw the error state. It now reads workspace?.expiresAt.

Because of 3, the ticket's "never sets up again after 10 minutes" could not actually happen in a running app. What did happen was the other symptom: setup retried on every call and there was no back-off. After this PR, the back-off applies for 10 minutes, and then setup runs again.

Alternative rejected: for 2, I considered converting dates back to Date objects inside loadFromStorage. Every date field in the config would then need its own reviver. Normalising in the one helper that compares dates is smaller, and it covers every caller.

Side effect of fix 2 (same root cause, intended): syncUserStateIfExpired (setup.ts:98) also called isNowExpired on reloaded string dates, so a user state stored before an app restart was treated as fresh forever. After 30 minutes it now re-syncs, as the code intends. setup.ts:57 (workspace) is mostly covered already, because loadFromStorage rejects an expired workspace config.

Seams tested: setup() (public), RNConfig.loadFromStorage(), isNowExpired().

  • Door: two-way. The change is internal SDK logic with no public API change (pnpm api:check passes), and reverting it is clean.
  • Blast radius: RN SDK setup, only when (a) the first setup has failed, or (b) a stored user state is reloaded after its expiry. Every other command still checks isSetup before reading config.workspace, so the workspace-less error config stays in memory only while setup has not run.

Tests (red on main, green here)

Test On main
setup.test.ts › error state back-off › skips setup while not expired (Date, ISO string) ❌ setup ran
setup.test.ts › skips inside the window and continues after it (fake timers, 09:59 / 10:00) ❌
setup.test.ts › continues setup once expired (Date) ❌ skipped
utils.test.ts › isNowExpired reads an ISO string ❌ false for a past date
config.test.ts › loadFromStorage reads back the error state a failed first setup writes ❌ err

The old error-state tests mocked isNowExpired and so pinned the inverted behaviour. The new tests run the real function, and the mock is reset after the block.

Commands run

  • pnpm lint ✅ · pnpm format:check ✅ · pnpm check-types ✅
  • pnpm test ✅ 231/231 · pnpm test:coverage ✅ · pnpm test:scripts ✅
  • pnpm build ✅ · pnpm package-check ✅ · pnpm api:check ✅ (no API change)

End to end

A container has no device or emulator. The evidence is the unit tests above plus the e2e golden-journey run on this PR.

Open gaps

  • No on-device check of the 10-minute window. It is covered by the fake-timer test only.
  • The workspace-less error config stays typed as TConfig, as it was before this PR. Tightening that type is left out of this change.

Generated by Claude Code

…indow [ENG-7265]

shouldReturnEarlyForErrorState skipped setup once the error state had
expired and retried while it was still active. Invert the check, and make
isNowExpired read the ISO strings that dates become after AsyncStorage, so
the fixed check cannot skip forever on a reloaded config.

The error-state tests now run the real isNowExpired instead of a mock.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_011A96cuRpyd6PjGE9yABjux
…f applies [ENG-7265]

handleErrorOnFirstSetup stores only `{ status }`. loadFromStorage read
`workspace.expiresAt` unguarded, threw, and dropped the config, so setup never
saw the error state and retried on every call. Guard the workspace read and
add a round-trip test.

Review follow-ups: reset the isNowExpired mock after the back-off tests, give
isNowExpired its own section in utils.test.ts, and assert the result of the
continue-setup case.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_011A96cuRpyd6PjGE9yABjux
@mattinannt
mattinannt requested a review from Dhruwang November 27, 2026 00:16
@sonarqubecloud

Copy link
Copy Markdown

@coderabbitai

coderabbitai Bot commented Nov 27, 2026

Copy link
Copy Markdown

Explain Change →

No actionable comments were generated in the recent review.

Walkthrough

Expiration checks now accept Date and ISO-string values. Stored configs without a workspace load without an expiry comparison. Setup skips error states with a future expiration and continues when they expire.

Merge Risk: Minimal · up to 6db15

This change makes the 10-minute back-off after a failed setup apply, including after storage reloads. The changes are small and covered by tests, and no merge-blocking risk was found.

Pre-merge checks: Passed 4

Check name Status Explanation
Title check Passed The title names the main change: the 10-minute back-off after a failed setup is made to apply. The changeset fixes the inverted check in shouldReturnEarlyForErrorState, adds ISO-string handling in isN…
Description check Passed The description is detailed and on-topic. It explains the three root causes (inverted check in shouldReturnEarlyForErrorState, isNowExpired failing on ISO strings after JSON round-trip, and loadFromSt…
Linked Issues check Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check Passed Check skipped because no linked issues were found for this pull request.
Full details: Title check

Explanation

The title names the main change: the 10-minute back-off after a failed setup is made to apply. The changeset fixes the inverted check in shouldReturnEarlyForErrorState, adds ISO-string handling in isNowExpired, and guards the workspace expiry read in loadFromStorage, all of which serve that goal. The title is specific and uses a conventional prefix with a ticket reference.

Full details: Description check

Explanation

The description is detailed and on-topic. It explains the three root causes (inverted check in shouldReturnEarlyForErrorState, isNowExpired failing on ISO strings after JSON round-trip, and loadFromStorage dropping workspace-less error configs). It also lists the tests added, the commands run, and the open gaps, all of which match the file-level changes.

  • Autofix · 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

Recent review info

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: Organization UI
  • Review profile: ASSERTIVE
  • Plan: Advanced
  • Run ID: cd9e9274-a40b-4432-a985-625c31f66c83
Commits

Reviewing files that changed from the base of the PR and between 760c129 and 6db15a6.

Files selected for processing: 6

  • packages/react-native/src/lib/common/config.ts
  • packages/react-native/src/lib/common/setup.ts
  • packages/react-native/src/lib/common/tests/config.test.ts
  • packages/react-native/src/lib/common/tests/setup.test.ts
  • packages/react-native/src/lib/common/tests/utils.test.ts
  • packages/react-native/src/lib/common/utils.ts

Included review availability: This review used your included allowance. Your plan provides up to 1 included review per hour; 0 remain after this review.

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.

2 participants