Skip to content

Apply the sign-in response on arrival - #97690

Draft
adhorodyski wants to merge 1 commit into
Expensify:mainfrom
callstack-internal:fix/apply-signin-response-on-arrival
Draft

Apply the sign-in response on arrival#97690
adhorodyski wants to merge 1 commit into
Expensify:mainfrom
callstack-internal:fix/apply-signin-response-on-arrival

Conversation

@adhorodyski

Copy link
Copy Markdown
Contributor

Explanation of Change

One scenario. A user signs in with SAML and the client is behind on Onyx updates.

Real numbers from the reported session: the client had applied update 14868706738. The sign-in response came back with previousUpdateID: 14886370217. That is a gap of about 17 million updates.

Before the change, SaveResponseInOnyx saw the gap and parked the whole sign-in response in ONYX_UPDATES_FROM_SERVER. The parked payload held the finallyData that clears isAuthenticatingWithShortLivedToken and account.isLoading. The app then ran a gap fill to catch up. That gap fill failed and later aborted. The two flags stayed set. reauthenticate() checks those flags and gives up, so every write returned 407 for the next 8 hours. The user saw approvals and renames succeed on screen. The server got none of them.

After the change, the two sign-in commands sit in requestsToIgnoreLastUpdateID, so the response applies the moment it arrives. The flags clear. The next 407 renews the token as normal.

The gap is not ignored. The client watermark stays where it was, so the next response that carries a previousUpdateID finds the same gap and fetches it, this time with a live token.

Fixed Issues

$ #97480
PROPOSAL: n/a

Tests

  1. Run npx jest tests/unit/MiddlewareTest.ts.
  2. Verify all 14 tests pass, including the two new cases: a sign-in response applies on arrival when the client watermark is behind the response, and when the client has no watermark yet. Both cases fail without the change.
  3. Sign in on web.
  4. Set ONYX_UPDATES_LAST_UPDATE_ID_APPLIED_TO_CLIENT in Onyx far below the current server update ID, for example to 1.
  5. Open /transition with a fresh short-lived auth token.
  6. Read the console. Verify the line Applying update type: https ... command: 'SignInWithShortLivedAuthToken' appears and no Re-authentication aborted line follows.
  7. Approve a report. Verify the approval reaches the server.
  • Verify that no errors appear in the JS console

Offline tests

  1. Go offline and make a write, for example rename a report.
  2. Come back online with an expired token. Verify the queued write reaches the server after the token renews. The sign-in exemption does not change the offline path.

QA Steps

// TODO: These must be filled out, or the issue title must include "[No QA]."

  1. On staging, sign in with a SAML-required account, for example Okta.
  2. Set ONYX_UPDATES_LAST_UPDATE_ID_APPLIED_TO_CLIENT in Onyx to 1 so the client looks behind on updates.
  3. Open /transition with a fresh short-lived auth token.
  4. Approve a report, rename a report, and edit a report field.
  5. Verify each change reaches the server. Verify the app does not need a page refresh.
  • Verify that no errors appear in the JS console

PR Author Checklist

  • I linked the correct issue in the ### Fixed Issues section above
  • I wrote clear testing steps that cover the changes made in this PR
    • I added steps for local testing in the Tests section
    • I added steps for the expected offline behavior in the Offline steps section
    • I added steps for Staging and/or Production testing in the QA steps section
    • I added steps to cover failure scenarios (i.e. verify an input displays the correct error message if the entered data is not correct)
    • I turned off my network connection and tested it while offline to ensure it matches the expected behavior (i.e. verify the default avatar icon is displayed if app is offline)
    • I tested this PR with a High Traffic account against the staging or production API to ensure there are no regressions (e.g. long loading states that impact usability).
  • I included screenshots or videos for tests on all platforms
  • I ran the tests on all platforms & verified they passed on:
    • Android: Native
    • Android: mWeb Chrome
    • iOS: Native
    • iOS: mWeb Safari
    • MacOS: Chrome / Safari
  • I verified there are no console errors (if there's a console error not related to the PR, report it or open an issue for it to be fixed)
  • I followed proper code patterns (see Reviewing the code)
    • I verified that comments were added to code that is not self explanatory
    • I verified that any new or modified comments were clear, correct English, and explained "why" the code was doing something instead of only explaining "what" the code was doing.
    • I verified any copy / text that was added to the app is grammatically correct in English. It adheres to proper capitalization guidelines (note: only the first word of header/labels should be capitalized), and is either coming verbatim from figma or has been approved by marketing (in order to get marketing approval, ask the Bug Zero team member to add the Waiting for copy label to the issue)
  • If a new code pattern is added I verified it was agreed to be used by multiple Expensify engineers
  • I followed the guidelines as stated in the Review Guidelines
  • I tested other components that can be impacted by my changes (i.e. if the PR modifies a shared library or component like Avatar, I verified the components using Avatar are working as expected)
  • If a new CSS style is added I verified that:
    • A similar style doesn't already exist
    • The style can't be created with an existing StyleUtils function (i.e. StyleUtils.getBackgroundAndBorderStyle(theme.componentBG))
  • If new assets were added or existing ones were modified, I verified that:
    • The assets are optimized and compressed (for SVG files, run npm run compress-svg)
    • The assets load correctly across all supported platforms.
  • If the PR modifies code that runs when editing or sending messages, I tested and verified there is no unexpected behavior for all supported markdown - URLs, single line code, code blocks, quotes, headings, bold, strikethrough, and italic.
  • If the PR modifies a generic component, I tested and verified that those changes do not break usages of that component in the rest of the App (i.e. if a shared library or component like Avatar is modified, I verified that Avatar is working as expected in all cases)
  • If the PR modifies a component related to any of the existing Storybook stories, I tested and verified all stories for that component are still working as expected.
  • If the PR modifies a component or page that can be accessed by a direct deeplink, I verified that the code functions as expected when the deeplink is used - from a logged in and logged out account.
  • If the PR modifies the UI (e.g. new buttons, new UI components, changing the padding/spacing/sizing, moving components, etc) or modifies the form input styles:
    • I verified that all the inputs inside a form are aligned with each other.
    • I added Design label and/or tagged @Expensify/design so the design team can review the changes.
  • I added unit tests for any new feature or bug fix in this PR to help automatically prevent regressions in this user flow.
  • If the main branch was merged into this PR after a review, I tested again and verified the outcome was still expected according to the Test steps.

Screenshots/Videos

Android: Native

N/A

Android: mWeb Chrome

N/A

iOS: Native

N/A

iOS: mWeb Safari

N/A

MacOS: Chrome / Safari

N/A

A SAML sign-in returns jsonCode 200 with a new session. When the client is behind
on Onyx updates, SaveResponseInOnyx parks the whole response in
ONYX_UPDATES_FROM_SERVER behind a gap fill. That payload holds the finallyData
that clears isAuthenticatingWithShortLivedToken and account.isLoading. A gap fill
that fails or aborts leaves both flags set, reauthenticate() gives up on every
407, and every write returns 407 for the rest of the session.

Add both sign-in commands to the exemption list so the response applies when the
response arrives. The client watermark stays where the client left it, so the next
response that carries a previousUpdateID finds the same gap and fetches it with a
live auth token.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
@adhorodyski

Copy link
Copy Markdown
Contributor Author

@codex review

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: c653c1da3d

ℹ️ About Codex in GitHub

Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

Comment on lines +24 to +25
READ_COMMANDS.SIGN_IN_WITH_SHORT_LIVED_AUTH_TOKEN,
READ_COMMANDS.SIGN_IN_WITH_SUPPORT_AUTH_TOKEN,

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge Do not advance the watermark for skipped sign-in gaps

When a short-lived/support sign-in response arrives with previousUpdateID ahead of the client's watermark, adding it to requestsToIgnoreLastUpdateID bypasses the gap-fill path and calls OnyxUpdates.apply; that helper advances ONYX_UPDATES_LAST_UPDATE_ID_APPLIED_TO_CLIENT to the response lastUpdateID after applying only the sign-in payload/finallyData. In the behind-client scenario from the new test, the client now records the missing range as already applied, so later responses with previousUpdateID within that range will not refetch those server updates and the app can remain stale instead of catching up.

Useful? React with 👍 / 👎.

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.

1 participant