Skip to content

fix(android): drop inflated app start for background-spawned processes - #6526

Closed
alwx wants to merge 3 commits into
mainfrom
alwx/fix/6382
Closed

fix(android): drop inflated app start for background-spawned processes#6526
alwx wants to merge 3 commits into
mainfrom
alwx/fix/6382

Conversation

@alwx

@alwx alwx commented Jul 27, 2026

Copy link
Copy Markdown
Contributor

📢 Type of change

  • Bugfix

📜 Description

On API 35+ use the process start reason (ApplicationStartInfo#getReason()) to detect background-spawned processes (e.g. FCM push) and drop the app start, avoiding inflated app_start_cold/app_start_warm.

💡 Motivation and Context

When Android spawns the process in the background and the user opens the app later, the native SDK keeps the app start anchored at background process creation, inflating cold/warm start by the whole idle gap. Similar to how the Cocoa SDK drops pre-warmed starts.

Fixes #6382

💚 How did you test it?

Added Android unit tests (RNSentryAppStartTest); ./gradlew :RNSentry:testDebugUnitTest passing.

📝 Checklist

  • I added tests to verify changes.
  • No new PII added or SDK only sends newly added PII if sendDefaultPII is enabled.
  • All tests passing.
  • No breaking changes.

🔮 Next steps

On API < 35 getAppStartReason() returns null; fully fixing those needs an upstream sentry-java change.

On API 35+ use the process start reason (ApplicationStartInfo#getReason())
to detect background-spawned processes (e.g. FCM push) and drop the app
start, avoiding inflated app_start_cold/warm.

Fixes #6382
@github-actions

github-actions Bot commented Jul 27, 2026

Copy link
Copy Markdown
Contributor

Semver Impact of This PR

None (no version bump detected)

📋 Changelog Preview

This is how your changes will appear in the changelog.
Entries from this PR are highlighted with a left border (blockquote style).


  • fix(android): drop inflated app start for background-spawned processes by alwx in #6526
  • feat(core): Export instrumentStateGraph and deprecate instrumentLangGraph by antonis in #6520
  • chore(deps): bump the codeql-action group across 1 directory with 3 updates by dependabot in #6517
  • chore(deps): bump ruby/setup-ruby from 1.319.0 to 1.321.0 by dependabot in #6518
  • chore(deps): bump actions/checkout from 7.0.0 to 7.0.1 by dependabot in #6519
  • chore(deps): update JavaScript SDK to v10.68.0 by github-actions in #6516
  • chore(deps): bump tar from 7.5.20 to 7.5.21 by dependabot in #6515
  • chore(deps): bump lerna to ^9.0.7 to resolve remaining dev-tooling advisories by antonis in #6499
  • chore(deps): Migrate to @sentry/bundler-plugins by antonis in #6501
  • chore: update changelog warning with fix version by antonis in #6509
  • chore(deps): bump actions/setup-node from 6.4.0 to 7.0.0 by dependabot in #6463
  • chore(deps): bump json from 2.17.1.2 to 2.19.9 in /performance-tests by dependabot in #6512
  • chore(deps): update CLI to v3.6.2 by github-actions in #6511
  • chore(deps): update Sentry Android Gradle Plugin to v6.16.0 by github-actions in #6508
  • chore(deps): update Android SDK to v8.50.1 by github-actions in #6503

🤖 This preview updates automatically when you update the PR.

@alwx
alwx marked this pull request as ready for review July 27, 2026 12:47
Comment on lines +414 to +418
+ appStartReason
+ ").");
promise.resolve(null);
return;
}

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Bug: The code assumes metrics.getAppStartReason() returns a lowercase string, but the actual format from the external library is unverified and may differ, causing the feature to fail silently.
Severity: MEDIUM

Suggested Fix

Add an integration test to verify the actual return value and format of metrics.getAppStartReason() from the sentry-android dependency. Adjust the isBackgroundAppStartReason() method to handle the actual output format, whether it's an integer, an uppercase string, or something else.

Prompt for AI Agent
Review the code at the location below. A potential bug has been identified by an AI
agent. Verify if this is a real issue. If it is, propose a fix; if not, explain why it's
not valid.

Location:
packages/core/android/src/main/java/io/sentry/react/RNSentryModuleImpl.java#L414-L418

Potential issue: The code assumes that the `getAppStartReason()` method from the
external `sentry-android` library returns a lowercase string (e.g., `"push"`,
`"alarm"`). However, the actual return format is unverified. The underlying Android API
returns integer constants, and it's unknown how the Sentry library transforms them. If
the return value is an integer, an uppercase string, or another format, the
`isBackgroundAppStartReason()` check will always fail. This would cause the feature to
silently not work, meaning background-triggered app starts would not be filtered out,
leading to inflated app start metrics.

Did we get this right? 👍 / 👎 to inform future reviews.

@github-actions

Copy link
Copy Markdown
Contributor
Fails
🚫 Pull request is not ready for merge, please add the "ready-to-merge" label to the pull request

Generated by 🚫 dangerJS against 0925ea0

Comment on lines +410 to +412
if (isBackgroundAppStartReason(appStartReason)) {
logger.log(
SentryLevel.WARNING,

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Bug: The new logic to filter background app starts in fetchNativeAppStart() lacks integration test coverage. A regression could go undetected, reintroducing inflated app start metrics.
Severity: LOW

Suggested Fix

Add an integration test for fetchNativeAppStart(). This test should mock an AppStartMetrics object where getAppStartReason() returns a background reason (e.g., "push") and isAppLaunchedInForeground() is true. Verify that the promise is resolved with null, confirming the app start metric is correctly dropped.

Prompt for AI Agent
Review the code at the location below. A potential bug has been identified by an AI
agent. Verify if this is a real issue. If it is, propose a fix; if not, explain why it's
not valid.

Location:
packages/core/android/src/main/java/io/sentry/react/RNSentryModuleImpl.java#L410-L412

Potential issue: The new logic in `fetchNativeAppStart` filters out app start metrics
from background processes to prevent metric inflation. However, this critical filtering
path is not covered by any integration tests. While a unit test validates the
`isBackgroundAppStartReason()` helper method, there is no test that simulates a scenario
where `isAppLaunchedInForeground()` is `true` but `getAppStartReason()` returns a
background reason like `"push"`. This means a future regression in the interaction
between these checks within `fetchNativeAppStart()` would go undetected, potentially
reintroducing the metric inflation issue this change aims to solve.

Also affects:

  • packages/core/android/src/test/java/io/sentry/react/RNSentryAppStartTest.java:1~45

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

Cursor Bugbot has reviewed your changes and found 1 potential issue.

Fix All in Cursor

❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.

Want reviews to match your repository better? Bugbot Learning can learn team-specific rules from PR activity. A team admin can enable Learning in the Cursor dashboard.

Reviewed by Cursor Bugbot for commit 0925ea0. Configure here.

+ ").");
promise.resolve(null);
return;
}

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Warm starts wrongly dropped

Medium Severity

isBackgroundAppStartReason keys off the process start reason, which stays fixed for the process lifetime. After a background spawn (e.g. push), the first inflated open is correctly dropped, but later warm starts in the same process still report that reason and are dropped too, even though those spans are re-anchored at activity creation and are not inflated.

Fix in Cursor Fix in Web

Triggered by project rule: PR Review Guidelines for Cursor Bot

Reviewed by Cursor Bugbot for commit 0925ea0. Configure here.

@alwx

alwx commented Jul 28, 2026

Copy link
Copy Markdown
Contributor Author

Closing it in favor of getsentry/sentry-java#5841

@alwx alwx closed this Jul 28, 2026
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.

Android: app_start_cold is inflated when the process is background-spawned (FCM) before the user opens the app

1 participant