Skip to content

[NoQA] Log the reason for every sign-out - #101882

Merged
mountiny merged 5 commits into
Expensify:mainfrom
callstack-internal:fm/exfy-2991-telemetry
Sep 24, 2026
Merged

mountiny merged 5 commits into
Expensify:mainfrom
callstack-internal:fm/exfy-2991-telemetry

Conversation

@adhorodyski

@adhorodyski adhorodyski commented Sep 22, 2026 •

Copy link
Copy Markdown
Contributor

Explanation of Change

Every sign-out used to log the same generic line whatever caused it. Now each one logs its reason, so the logs tell these apart (and all future cases too):

  • a user signing out,
  • a reauthentication network error,
  • SAML required,
  • no credentials,
  • device revoked,
  • unlinking a login,
  • a support session ending,
  • a stashed session being restored,
  • the mobile-app transition,
  • a deleted account,
  • a link from OldDot signing the previous user out (here it also says whether the link named a copilot account and whether the session was a copilot or support session)

Fixed Issues

$ #102131
PROPOSAL: N/A

Tests

This change only adds log lines, so it has no new test. The existing suites for the touched screens still pass.

  1. Run npx jest tests/ui/AuthScreensInitHandlerTest.tsx tests/ui/SessionTest.tsx.
  2. Verify that all 15 tests pass.
  • Verify that no errors appear in the JS console

    No manual UI testing was done. The change adds three log lines and changes no behavior.

Offline tests

No offline behavior changes. The new log lines sit in code that already runs offline.

QA Steps

No QA steps apply. Nothing changes on screen.

  • Verify that no errors appear in the JS console

    No build was made for this change, so nothing was checked on a device.

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
Android: mWeb Chrome
iOS: Native
iOS: mWeb Safari
MacOS: Chrome / Safari

Three gaps made a copilot sign-out incident unreadable straight from the logs.
This closes all three. No behaviour changes: no control flow, condition, order,
clear list, or guard moved.

signOutAndRedirectToSignIn puts the signOutReason it already receives into the
Log.info payload. The sentence stays word for word so existing queries keep
matching, and the reason is now what identifies which of its many callers ran.

Both sites that sign the current user out for a transition link now log one line
each, with its own prefix, carrying the session email against the link's email
and delegatorEmail plus the authTokenType. Those are the values the decision
compares, so one row answers which account the link named and how it differed
from the session. A read-only SessionUtils helper reads the two params the same
way isLoggingInAsNewUser does, so no token value and no full URL can reach a log
payload.

The missing-credentials branch of reauthenticate reports through
trackAuthenticationError, as the two branches below it already do. It only ever
logged, so a session that had lost its credentials left no Sentry event and the
407s that followed it looked unexplained. It reuses the reason string that branch
already passes to redirectToSignIn.

Sentry events also carry an auth_token_type tag, set where the user context is
set and cleared with the session, so copilot and supportal failures are findable
by that tag instead of only by role.

Tests cover the two contracts that are cheap to pin: the sign-out log payload
carries the reason, and the missing-credentials branch reports. The helper that
feeds the transition log lines is covered directly, including that it never
returns a credential.

Issue: callstack-internal/expensify-issues#2991
AuthScreensInitHandlerTest mocks SessionUtils with a hand-written factory, and
that factory did not know about getTransitionLinkEmailParams, so the new
transition log line threw a TypeError inside the mount effect and the sign-out
test failed. The mock now provides the function, with a beforeEach default that
matches the other mocked lookups. Running only the two suites I first touched
missed this, because the failure sits in a test for the file I consumed rather
than the file I edited.

That test now also asserts the payload of the new decision line, which is the
only coverage proving the transition log carries the session email against the
link's email and delegatorEmail.

The exported TransitionLinkEmailParams type had no importer, so knip counted a
new unused export. The type stays in the module as the function's return
annotation.

Oxfmt wrapped two long lines I had added, in SessionUtils and its test, so the
fmt diff check CI runs comes out clean.
The comments added with this work explained the diff to a reader rather than the
code, so they are gone. What stays is the Given/When/Then lines the repository
test guide asks for, and one JSDoc on getTransitionLinkEmailParams, which records
that URLSearchParams mangles the first query key of a full URL and that the raw
lookup is the fallback. That is a quirk of external code, not a note about this
change.

The transition-link reader lost five table rows that only restated what
URLSearchParams does, and its assertions name the fields now instead of
comparing the whole returned object.

Every kept test was checked against a mutation of the line it covers: dropping
the raw-value fallback, returning the link token next to the accounts, reading
the email from an unrelated param, dropping signOutReason from the log payload,
deleting the missing-credentials report, and deleting the transition log line.
All six went red, and the suites went green again with the lines restored.
clearStorageAndRedirect now logs the signOutReason it receives. Every
sign-out passes through it, so one line names the caller for all of them.

The two places that sign a user out because of a transition link each log
whether the link named a delegator, whether the current session is a
copilot session, and whether it is a support session. The line carries no
email, URL or token.

This replaces the earlier changes on this branch. The Sentry report, the
auth token type tag, the transition link helper and their tests are gone.
@adhorodyski adhorodyski changed the title Make the copilot sign-out path readable from the logs Log the reason for every sign-out Sep 23, 2026
The change only adds log lines, so it ships without a new test. The
existing suites for the touched screens still run.
@adhorodyski
adhorodyski marked this pull request as ready for review September 24, 2026 11:43
@adhorodyski
adhorodyski requested review from a team as code owners September 24, 2026 11:43
@melvin-bot
melvin-bot Bot requested review from dylanexpensify and parasharrajat and removed request for a team and dylanexpensify September 24, 2026 11:43
@melvin-bot

melvin-bot Bot commented Sep 24, 2026

Copy link
Copy Markdown

@parasharrajat Please copy/paste the Reviewer Checklist from here into a new comment on this PR and complete it. If you have the K2 extension, you can simply click: [this button]

@melvin-bot
melvin-bot Bot removed the request for review from a team September 24, 2026 11:43

@parasharrajat parasharrajat left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Reviewer Checklist

  • I have verified the author checklist is complete (all boxes are checked off).
  • I verified the correct issue is linked in the ### Fixed Issues section above
  • I verified testing steps are clear and they cover the changes made in this PR
    • I verified the steps for local testing are in the Tests section
    • I verified the steps for Staging and/or Production testing are in the QA steps section
    • I verified the steps cover any possible 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 checked that screenshots or videos are included for tests on all platforms
  • I included screenshots or videos for tests on all platforms
  • I verified that the composer does not automatically focus or open the keyboard on mobile unless explicitly intended. This includes checking that returning the app from the background does not unexpectedly open the keyboard.
  • I verified tests pass on all platforms & I tested again on:
    • Android: HybridApp
    • Android: mWeb Chrome
    • iOS: HybridApp
    • iOS: mWeb Safari
    • MacOS: Chrome / Safari
  • If there are any errors in the console that are unrelated to this PR, I either fixed them (preferred) or linked to where I reported them in Slack
  • I verified proper code patterns were followed (see Reviewing the code)
    • I verified that any callback methods that were added or modified are named for what the method does and never what callback they handle (i.e. toggleReport and not onIconClick).
    • 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 verified that this PR follows the guidelines as stated in the Review Guidelines
  • I verified other components that can be impacted by these changes have been tested, and I retested again (i.e. if the PR modifies a shared library or component like Avatar, I verified the components using Avatar have been tested & I retested again)
  • If a new component is created I verified that:
    • A similar component doesn't exist in the codebase
    • All props are defined accurately and each prop has a /** comment above it */
    • The file is named correctly
    • The component has a clear name that is non-ambiguous and the purpose of the component can be inferred from the name alone
    • The only data being stored in the state is data necessary for rendering and nothing else
    • For Class Components, any internal methods passed to components event handlers are bound to this properly so there are no scoping issues (i.e. for onClick={this.submit} the method this.submit should be bound to this in the constructor)
    • Any internal methods bound to this are necessary to be bound (i.e. avoid this.submit = this.submit.bind(this); if this.submit is never passed to a component event handler like onClick)
    • All JSX used for rendering exists in the render method
    • The component has the minimum amount of code necessary for its purpose, and it is broken down into smaller components in order to separate concerns and functions
  • If any new file was added I verified that:
    • The file has a description of what it does and/or why is needed at the top of the file if the code is not self explanatory
  • 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 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.
  • For any bug fix or new feature in this PR, I verified that sufficient unit tests are included to prevent regressions in this 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.
  • I have checked off every checkbox in the PR reviewer checklist, including those that don't apply to this PR.

🎀 👀 🎀 C+ reviewed

@melvin-bot
melvin-bot Bot requested a review from mountiny September 24, 2026 13:26
@mountiny mountiny changed the title Log the reason for every sign-out [NoQA] Log the reason for every sign-out Sep 24, 2026
@mountiny
mountiny merged commit 8598ff9 into Expensify:main Sep 24, 2026
47 of 49 checks passed
@github-actions

Copy link
Copy Markdown
Contributor

🚧 mountiny has triggered a test Expensify/App build. You can view the workflow run here.

@OSBotify

Copy link
Copy Markdown
Contributor

✋ This PR was not deployed to staging yet because QA is ongoing. It will be automatically deployed to staging after the next production release.

@adhorodyski
adhorodyski deleted the fm/exfy-2991-telemetry branch September 24, 2026 14:40
@OSBotify

Copy link
Copy Markdown
Contributor

🚀 Deployed to staging by https://github.com/mountiny in version: 9.4.94-0 🚀

platform result
🕸 web 🕸 success ✅
🤖 android 🤖 success ✅
🍎 iOS 🍎 success ✅

@MelvinBot

Copy link
Copy Markdown
Contributor

No help site changes are needed for this PR, so I didn't create a docs PR.

This PR only adds internal log lines that record why a sign-out happened. It doesn't change any screen, button, label, setting, or sign-out behavior. Nothing in App/docs/articles describes these logs, and no article needs to.

What changed
  • AuthScreensInitHandler.tsx and LogOutPreviousUserPage.tsx log the reason before a sign-out that happens when you switch to another user (with copilot and support-session flags).
  • SignInRedirect.ts logs signOutReason when it clears storage.
  • AuthScreensInitHandlerTest.tsx adds two mocks.

view run

@OSBotify

Copy link
Copy Markdown
Contributor

🚀 Deployed to production by https://github.com/Julesssss in version: 9.4.94-0 🚀

platform result
🕸 web 🕸 success ✅
🤖 android 🤖 success ✅
🍎 iOS 🍎 success ✅

Bundle Size Analysis (Sentry):

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.

5 participants