Skip to content

fix(android): Decide session staleness on a monotonic clock (JAVA-844) - #6688

Closed
lazerg wants to merge 3 commits into
getsentry:9.x.xfrom
lazerg:fix/session-stale-monotonic
Closed

lazerg wants to merge 3 commits into
getsentry:9.x.xfrom
lazerg:fix/session-stale-monotonic

Conversation

@lazerg

@lazerg lazerg commented Nov 20, 2026

Copy link
Copy Markdown
Contributor

📜 Description

When the app comes to the foreground and no background window is pending, LifecycleWatcher decided whether the session SDK init started is stale by comparing Session.getStarted() with the wall clock. A clock step between init and the first foreground could start an extra session or keep a stale one.

A session started by Scope.startSession() now keeps a Stopwatch on the options' monotonic ticker. It's in memory only and is never serialized (the clone carries it). LifecycleWatcher checks its elapsed time against the session interval, so it no longer needs the EpochClock. A session without one is treated as stale, same as no session.

💡 Motivation and Context

Fixes #6663

  • resolves: JAVA-844

Follow-up to #6096, removes the TODO [MAJOR] in isSessionOnScopeStale().

💚 How did you test it?

Unit tests in LifecycleWatcherTest drive the session's stopwatch with TestMonotonicTicker and set its wall-clock start an hour ahead or behind. Also added a ScopeTest case for the stopwatch being set.

📝 Checklist

  • I added GH Issue ID & Linear ID
  • I added tests to verify the changes.
  • No new PII added or SDK only sends newly added PII if sendDefaultPII is enabled.
  • I updated the docs if needed.
  • I updated the wizard if needed.
  • Review from the native team if needed.
  • No breaking change or entry added to the changelog.
  • No breaking change for hybrid SDKs or communicated to hybrid SDKs.
  • Public API changes reviewed by another Mobile SDK team member or implemented according to the develop docs spec.

Session gets an @ApiStatus.Internal getter/setter for the stopwatch.

🔮 Next steps

@github-actions github-actions Bot added the risk: medium PR risk score: medium label Nov 20, 2026
@github-actions

github-actions Bot commented Nov 20, 2026 •

Copy link
Copy Markdown
Contributor

PR risk: medium

For commit 74ff135.

Main concerns: reach, public contract, host performance.

Rules that block low also fired:

  • R4: a public API record changed: sentry/api/sentry.api

This label is a hint for reviewers, not an approval.

@github-actions github-actions Bot added risk: medium PR risk score: medium and removed risk: medium PR risk score: medium labels Nov 20, 2026
@runningcode

Copy link
Copy Markdown
Contributor

Thanks. Please take a look at our CONTRIBUTING.md and make sure to discuss before opening a PR https://github.com/getsentry/sentry-java/blob/main/CONTRIBUTING.md#submitting-changes

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

risk: medium PR risk score: medium

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants