Skip to content

fix(replay): Allow STARTED -> RESUMED state transition in ReplayLifecycle#5213

Closed
buenaflor wants to merge 1 commit intomainfrom
cursor/android-session-replay-restart-2809
Closed

fix(replay): Allow STARTED -> RESUMED state transition in ReplayLifecycle#5213
buenaflor wants to merge 1 commit intomainfrom
cursor/android-session-replay-restart-2809

Conversation

@buenaflor
Copy link
Contributor

📜 Description

Fix a bug in the ReplayLifecycle state machine where the STARTED -> RESUMED transition was not allowed. This caused the replay to not properly resume after the app returned to foreground following a session timeout in the background.

💡 Motivation and Context

When the app goes to background for longer than sessionIntervalMillis:

  1. The timer fires and calls replayController.stop() → state becomes STOPPED
  2. When the app returns to foreground, LifecycleWatcher.startSession() calls replayController.start() → state becomes STARTED
  3. Immediately after, it calls replayController.resume() → this failed because the state machine did not allow STARTED → RESUMED

The recording still partially worked through the root view listener path (which triggers onConfigurationChanged), but the lifecycle state was incorrect (stuck at STARTED instead of RESUMED), and captureStrategy.resume() / recorder.resume() were never called.

The fix adds RESUMED as a valid transition from the STARTED state in ReplayLifecycle.

💚 How did you test it?

  • Updated ReplayLifecycleTest to verify STARTED -> RESUMED is now allowed
  • Added a new test after stop, start and resume restarts replay in ReplayIntegrationTest that verifies the full stop → start → resume flow works correctly
  • Ran existing LifecycleWatcherTest, ReplayLifecycleTest, and ReplayIntegrationTest — all pass

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

🔮 Next steps

Open in Web Open in Cursor 

…ycle

The ReplayLifecycle state machine did not allow transitioning from STARTED
to RESUMED. This caused a bug when the app returned to foreground after
being in background longer than sessionIntervalMillis:

1. Timer fires -> stop() -> state becomes STOPPED
2. App returns to foreground -> start() -> state becomes STARTED
3. resume() fails because STARTED -> RESUMED was not allowed

The fix adds RESUMED as a valid transition from the STARTED state.

Co-authored-by: Giancarlo Buenaflor <giancarlobuenaflor97@gmail.com>
@github-actions
Copy link
Contributor

Semver Impact of This PR

🟢 Patch (bug fixes)

📋 Changelog Preview

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


Bug Fixes 🐛

  • (replay) Allow STARTED -> RESUMED state transition in ReplayLifecycle by buenaflor in #5213

🤖 This preview updates automatically when you update the PR.

@github-actions
Copy link
Contributor

Fails
🚫 Please consider adding a changelog entry for the next release.

Instructions and example for changelog

Please add an entry to CHANGELOG.md to the "Unreleased" section. Make sure the entry includes this PR's number.

Example:

## Unreleased

### Fixes

- Allow STARTED -> RESUMED state transition in ReplayLifecycle ([#5213](https://github.com/getsentry/sentry-java/pull/5213))

If none of the above apply, you can opt out of this check by adding #skip-changelog to the PR description or adding a skip-changelog label.

Generated by 🚫 dangerJS against 3ebf05f

@sentry
Copy link

sentry bot commented Mar 18, 2026

Sentry Build Distribution

App Name App ID Version Configuration Install Page
SDK Size io.sentry.tests.size 8.36.0 (1) release Install Build

@buenaflor buenaflor closed this Mar 18, 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.

2 participants