Skip to content

[No QA] [iOS] Mirror app hang context in standalone NewDot and add the NewDot screen to native events - #106989

Merged
mountiny merged 5 commits into
Expensify:mainfrom
arekm213:arekm213/app-hang-sentry-context
Nov 19, 2026
Merged

mountiny merged 5 commits into
Expensify:mainfrom
arekm213:arekm213/app-hang-sentry-context

Conversation

@arekm213

@arekm213 arekm213 commented Nov 16, 2026 •

Copy link
Copy Markdown
Contributor

Explanation of Change

Companion to the Mobile-Expensify PR linked below, which splits APP-77W and tags app hang false positives in the HybridApp.

  • ios/SentryNativeSDKManager.m: the same app hang section as Mobile-Expensify (app_hang.main_thread, app_hang.blocked, app_hang.interrupted, app_hang.since and the idle fingerprint), so standalone NewDot reports hangs the same way. Standalone NewDot has no odot.foreground tag, so every idle hang is grouped as NewDot. The existing JS duplicate filter moved into a processEventBeforeSend function to match the Mobile-Expensify structure. Its behaviour is unchanged.
  • src/libs/Navigation/NavigationRoot.tsx: sets a NewDot Screen Sentry context (route name and time) on every navigation and on ready. JS contexts sync to the native scope, so native events such as app hangs, including fatal ones sent on the next launch, show which NewDot screen the user was on. It is a context and not a tag, so it does not change grouping or add high cardinality tags.

This section is temporary and is marked to be removed together with App Hang tracking in sentry-cocoa 10.

Fixed Issues

$ #106340
PROPOSAL:

MOBILE-EXPENSIFY: https://github.com/Expensify/Mobile-Expensify/pull/14235

Tests

  1. Build the HybridApp for iOS with Sentry enabled (ENABLE_SENTRY_ON_DEV=true), run it on a simulator and sign in.
  2. Navigate to any NewDot screen, for example Account > Profile.
  3. Trigger an app hang (see the Mobile-Expensify PR for steps) and open it in Sentry.
  4. Verify the event has a "NewDot Screen" context with the route name of the screen from step 2.
  5. Verify the app hang event has the app_hang.* tags described in the Mobile-Expensify PR.
  • Verify that no errors appear in the JS console

Offline tests

Not applicable, this only changes crash reporting metadata.

QA Steps

[No QA] No user facing change. A sanity pass is enough: run the app, sign in and navigate around.

  • 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 verified any copy / text that was added to the app 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 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 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.
  • If the PR adds or modifies the UI:
    • I asked an AI agent to review the changes for accessibility issues and addressed its findings.
    • I tested with a screen reader (VoiceOver on macOS) and verified all new/changed elements are reachable with a logical focus order.
    • I verified all new/changed elements have meaningful accessible names and roles.
    • I verified state changes are announced (e.g. checked/unchecked, expanded/collapsed, selected).
  • 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

Not applicable, no UI change.

Android: mWeb Chrome

Not applicable, no UI change.

iOS: Native

The "NewDot Screen" context on an app hang event in Sentry: event (screen Settings_Troubleshoot).

iOS: mWeb Safari

Not applicable, no UI change.

MacOS: Chrome / Safari

Not applicable, no UI change.

…n to native events

Same App Hang tags and idle fingerprint as Mobile-Expensify, plus a NewDot Screen Sentry context set on every navigation.
@arekm213

Copy link
Copy Markdown
Contributor Author

@MelvinBot review

@MelvinBot

Copy link
Copy Markdown
Contributor

Review findings

[P2] Lifecycle classification misses interruptions near the start of a hang.
In SentryNativeSDKManager.m:190–211, start is calculated from the time beforeSend executes. The code already acknowledges roughly one second of reporting delay, but compensates only for the blocked-thread calculation—not lifecycle comparisons.

For example, a 2.4-second hang processed one second later shifts start one second forward. An inactive transition early in that hang is then incorrectly tagged app_hang.interrupted=no. Preserve the hang’s timing independently of callback execution, and add a regression test covering delayed processing.

CI blocker: Spellcheck failed on odot, libsystem, and isnan; add appropriate dictionary entries or scoped exclusions.

Static review only; iOS hang capture and native context persistence were not runtime-verified.


view run

@arekm213

Copy link
Copy Markdown
Contributor Author

start is calculated from the time beforeSend executes. The code already acknowledges roughly one second of reporting delay, but compensates only for the blocked-thread calculation—not lifecycle comparisons.

Good catch, I tried this, but it ended up making the tags less accurate. The duration Sentry reports already includes the time it takes to notice that the hang has ended, so moving the start back an extra second puts it before the hang actually began. Then a hang that starts right after the app comes back to the foreground gets tagged as interrupted=background, which is exactly the resume case we want to catch. I'd rather miss an interruption in the first fraction of a second, so I kept the original calculation.

@arekm213
arekm213 marked this pull request as ready for review November 16, 2026 13:36
@arekm213
arekm213 requested review from a team as code owners November 16, 2026 13:36
@expensify-chore-bot
expensify-chore-bot Bot requested review from dylanexpensify and situchan and removed request for a team November 16, 2026 13:36
@expensify-chore-bot

Copy link
Copy Markdown

@situchan 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]

@expensify-chore-bot
expensify-chore-bot Bot removed the request for review from a team November 16, 2026 13:36
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 16, 2026 •

Copy link
Copy Markdown
Codex Review Summary: ✅ Completed

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-16T14:18:10.351475Z a9f265f Draft marked ready
ℹ️ About Codex in GitHub

Your team has set up Codex to 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" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@situchan

situchan commented Nov 16, 2026 •

Copy link
Copy Markdown
Contributor

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 any copy / text that was added to the app 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 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
    • 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
    • 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 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.
  • If the PR adds or modifies the UI:
    • I asked an AI agent to review the changes for accessibility issues and addressed its findings.
    • I tested with a screen reader (VoiceOver on macOS) and verified all new/changed elements are reachable with a logical focus order.
    • I verified all new/changed elements have meaningful accessible names and roles.
    • I verified state changes are announced (e.g. checked/unchecked, expanded/collapsed, selected).
  • 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.

Screenshots/Videos

Android: HybridApp
Android: mWeb Chrome
iOS: HybridApp
ios.mp4
iOS: mWeb Safari
MacOS: Chrome / Safari

@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: a9f265f54d

ℹ️ 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".

// Classification is on `frame.package` (the image path, e.g. ".../UIKitCore"), never on `frame.function`:
// SentryCrashReportConverter fills only instructionAddress, imageAddress, package and inApp, and symbolication
// happens server-side after beforeSend returns, so `function` is always nil.
static NSString *frameImageName(SentryFrame *_Nullable frame) {

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 Give the new native helpers verb-led names

The new helpers such as frameImageName, appHangMinimumDuration, and appHangException have noun-led names that read as values rather than operations. .claude/skills/app-coding-standards/rules/consistency-20-function-names.md, required by AGENTS.md, explicitly requires new function names to start with a verb. These are internal static functions, so no external interface dictates their names. Rename them to forms such as getFrameImageName and getAppHangException, and use verb-led names for the new predicates as well.

AGENTS.md reference: AGENTS.md:L7-L10

Useful? React with 👍 / 👎.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

This file mirrors SentryNativeSDKManager.m in Mobile-Expensify, where frameImageName and frameIsInImage already exist next to helpers like victimFrame and truncatedTagValue. I kept the new helpers in the same style so both copies stay identical and consistent with that file.

Comment thread ios/SentryNativeSDKManager.m Outdated
return @"idle";
}

// "App hanging between 2.4 and 3.2 seconds." -> 2.4, the lower bound. NAN for any other wording.

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 Replace the prose arrow in the duration comment

The -> here describes a relationship outside the quoted Sentry message; it is not part of the external string being documented. .claude/skills/app-coding-standards/rules/consistency-15-plain-comment-style.md, required by AGENTS.md, explicitly prohibits using arrows for relationships in comment prose. Reword the example as a sentence explaining that its lower bound is 2.4.

AGENTS.md reference: AGENTS.md:L7-L10

Useful? React with 👍 / 👎.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Done

Comment thread ios/SentryNativeSDKManager.m Outdated
Comment on lines +192 to +193
CFAbsoluteTime now = CFAbsoluteTimeGetCurrent();
CFAbsoluteTime start = now - minimumDuration;

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Classify lifecycle changes against the actual hang interval

If the app becomes inactive or backgrounds after a non-fatal hang ends but before beforeSend runs, using the callback time here makes that later lifecycle change count as an interruption of the hang. The acknowledged callback delay also shifts start forward and drops interruptions near the beginning: a 2.4-second hang from 100.0 to 102.4, with beforeSend at 103.4, computes start = 101.0 and ignores a resignation at 100.25. This misclassifies the new triage tags. Base the lifecycle checks on the hang's recorded interval, bounded at hang end, rather than send-processing time.

Useful? React with 👍 / 👎.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Base the lifecycle checks on the hang's recorded interval, bounded at hang end, rather than send-processing time.

Sentry's duration runs until it sees frames again, so the start lands near the real one, not a second late. And during a blocking hang the lifecycle observers can't run until it ends, so leaving mid-hang gets recorded right after the end. Bounding there would drop exactly those cases

@dylanexpensify dylanexpensify left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Product input not required for this PR.

Comment thread src/libs/Navigation/NavigationRoot.tsx Resolved
Comment thread src/libs/Navigation/NavigationRoot.tsx Resolved
Comment on lines +84 to +92
static void recordRunLoopActivity(CFRunLoopActivity activity) {
CFAbsoluteTime now = CFAbsoluteTimeGetCurrent();
os_unfair_lock_lock(&appLifecycleLock);
if (!lastRunLoopActivityWasSleep && lastRunLoopActivityTime > 0) {
addBusyTimeLocked(lastRunLoopActivityTime, now);
}
lastRunLoopActivityTime = now;
lastRunLoopActivityWasSleep = activity == kCFRunLoopBeforeWaiting;
os_unfair_lock_unlock(&appLifecycleLock);

@situchan situchan Nov 16, 2026 •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Hang windows mix wall-clock and monotonic time

Sentry measures the hang duration with CLOCK_UPTIME_RAW, but start = now - minimumDuration and the busy history use CFAbsoluteTimeGetCurrent(), which shifts when the system clock is adjusted.
A clock change near a hang moves the window and tags the hang wrongly.

if (!isFatal && !isnan(minimumDuration)) {
// Non-fatal hangs are sent when the hang ends, so the start is roughly now minus the duration.
CFAbsoluteTime now = CFAbsoluteTimeGetCurrent();
CFAbsoluteTime start = now - minimumDuration;

Use clock_gettime_nsec_np(CLOCK_UPTIME_RAW) (or CACurrentMediaTime()) here and in the Mobile-Expensify copy (iOS/Expensify/SentryNativeSDKManager.m at lines 251 and 358).

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Good catch, switched to CACurrentMediaTime() in both repos and retested the launch and resume cases on a simulator. Since uptime can be shorter than a bogus hang duration right after a reboot, the busy history lookup is now clamped at 0

@mountiny

Copy link
Copy Markdown
Contributor

@arekm213 can you address all the ai comments please? and conflicts

lastRunLoopActivityTime = CACurrentMediaTime();
lastRunLoopActivityWasSleep = NO;
os_unfair_lock_unlock(&appLifecycleLock);
CFRunLoopObserverRef runLoopObserver = CFRunLoopObserverCreateWithHandler(kCFAllocatorDefault, kCFRunLoopAllActivities, true, LONG_MAX, ^(CFRunLoopObserverRef observer, CFRunLoopActivity activity) {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

@arekm213

arekm213 commented Nov 17, 2026 •

Copy link
Copy Markdown
Contributor Author

@mountiny @situchan all the review comments and merge conflicts are addressed now and its ready for review again

@mountiny
mountiny merged commit a7bcc02 into Expensify:main Nov 19, 2026
39 of 43 checks passed
@github-actions

Copy link
Copy Markdown
Contributor

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

@github-actions

Copy link
Copy Markdown
Contributor

@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.

@OSBotify

Copy link
Copy Markdown
Contributor

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

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

@MelvinBot

Copy link
Copy Markdown
Contributor

No help site update needed — this PR only changes internal Sentry diagnostics for app hangs and screen context, without changing user-facing features, workflows, or documented behavior.


view run

@OSBotify

Copy link
Copy Markdown
Contributor

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

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

@OSBotify

Copy link
Copy Markdown
Contributor

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

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

@OSBotify

Copy link
Copy Markdown
Contributor

🚀 Deployed to production by https://github.com/marcaaron in version: 9.5.51-1 🚀

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.

6 participants