Title: Session Replay segment, buffer and gesture timestamps read the wall clock · Issue #6522 · getsentry/sentry-java · GitHub
Open Graph Title: Session Replay segment, buffer and gesture timestamps read the wall clock · Issue #6522 · getsentry/sentry-java
X Title: Session Replay segment, buffer and gesture timestamps read the wall clock · Issue #6522 · getsentry/sentry-java
Description: Follow-up to #5578. #6090 moved the 1h session cap and the 50ms move debounce onto the monotonic clock. Everything else #5578 listed still reads the wall clock. What still reads the wall clock Segment boundary. SessionCaptureStrategy cut...
Open Graph Description: Follow-up to #5578. #6090 moved the 1h session cap and the 50ms move debounce onto the monotonic clock. Everything else #5578 listed still reads the wall clock. What still reads the wall clock Segm...
X Description: Follow-up to #5578. #6090 moved the 1h session cap and the 50ms move debounce onto the monotonic clock. Everything else #5578 listed still reads the wall clock. What still reads the wall clock Segm...
Opengraph URL: https://github.com/getsentry/sentry-java/issues/6522
X: @github
Domain: github.com
IPv4 address: 140.82.114.4
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Session Replay segment, buffer and gesture timestamps read the wall clock","articleBody":"Follow-up to getsentry/sentry-java#5578. getsentry/sentry-java#6090 moved the 1h session cap and the 50ms move debounce onto the monotonic clock. Everything else getsentry/sentry-java#5578 listed still reads the wall clock.\n\n## What still reads the wall clock\n\n* **Segment boundary.** `SessionCaptureStrategy` cuts a segment when `frameTimestamp - segmentTimestamp` reaches 5s.\n* **Buffer trim.** `BufferCaptureStrategy` keeps the last 30s with `now - errorReplayDuration`. It computes the buffered segment's duration as `now - firstFrame`.\n* **Frame windows.** `ReplayCache.createVideoOf` and `rotate` walk epoch-millis windows. Frame files are named by epoch millis.\n* **Gesture timestamps.** `ReplayGestureConverter` stamps touch start, end, cancel and move events with the wall clock. The gesture batch timer and `timeOffset` durations are split out to getsentry/sentry-java#6523, which lands before v9.\n\n## What goes wrong\n\nA backward step mid-recording makes new frames look older than the segment they belong to. They fall outside the window, and `rotate` deletes them until the wall clock catches back up. Breadcrumbs from that stretch are dropped the same way. A forward step cuts a 5s segment of one frozen frame on every captured frame until the segment start catches up, so a 2-minute step sends about 24 frozen segments in 30s. Buffer mode fails too: a backward step makes the buffered duration negative, and a forward step rotates out the whole buffer.\n\n## Not a breaking change\n\nLands on main (decided on 2026-11-10), as a one-off exception to the project's rule that timestamps wait for v9. Today's behavior is a live bug, and the timestamps sent only change after a clock jump.\n\nChecked on `main` on 2026-11-09:\n\n* **Session counts.** Replay doesn't start, end or time release-health sessions. `LifecycleWatcher` decides, and replay follows. Crash-free rate and replay counts can't move.\n* **Public API.** Every public replay method that carries time takes epoch millis as a `Long`. An `AnchoredClock` still produces epoch millis. The `ICurrentDateProvider` constructor parameter must stay, because sentry-dart calls the four-argument `ReplayIntegration` constructor.\n* **Metrics.** On Android the ticker counts deep sleep, like the wall clock. With no clock step the output is the same. After a step it gets more accurate.\n\n## Decision: one anchor per recording that re-anchors on a clock jump\n\nDecided on 2026-11-10.\n\n* Anchor an `AnchoredClock` at `start()`, which reads the wall clock today, so no value changes there. Only a captured frame re-anchors: `resume()` reuses the current anchor, and the first frame after resume follows a jump made while paused, like any other jump. Re-anchoring at `resume()` would make every request queued behind it look like it raced a jump.\n* On every captured frame, compare a fresh wall-clock reading with the anchored time. If they differ by more than 1s, close the current segment at the old timeline's \"now\" and start the next segment on a new anchor.\n* With no jump, every value sent is the same as today, apart from rounding of up to 1ms.\n* After a jump, no frames are lost, and breadcrumbs, errors and spans stay aligned with the video to within one frame. The jump shows up once: a gap after a forward jump, an overlap after a backward one.\n\nRejected:\n\n* **One anchor, never re-anchored:** breadcrumbs, errors and spans stay offset for up to an hour.\n* **New anchor at each segment boundary:** changes values even without a jump, and the player freezes briefly every 5s.\n* **Project only breadcrumbs onto the replay clock:** errors and spans stay offset.\n* **End the replay on a jump:** splits one session into two replays.\n\nAlso decided:\n\n* After a backward jump the next segment overlaps the previous one, and the player's video lags its timeline until the user seeks. Accepted; the player fix is a separate frontend request.\n* A forward jump longer than the 1h session cap stops a session recording, as hitting the cap does. In buffer mode it drops the buffered video from before the jump and keeps recording, so a replay never spans a gap of hours or years.\n* Requests already queued when the clock re-anchors (pause, flush, configuration change, error) recompute from the new timeline, so no segment mixes two timelines.\n* The jump tolerance is 1s, just under the player's 1.1s \"Video Unavailable\" marker.\n* The jump detector stays internal to `sentry-android-replay`.\n* `ReplayIntegration`'s `ICurrentDateProvider` stays and becomes the anchor's wall clock, so no constructor changes.\n* After a jump in buffer mode, crash recovery only gets the frames from after the jump.\n\n## Done when\n\n* The four sites above take time from the re-anchoring replay clock. `ReplayGestureConverter` gets it through the `ICurrentDateProvider` it already takes, so this change doesn't touch that file and doesn't depend on getsentry/sentry-java#6523.\n* Frames on disk stay in epoch millis, so crash recovery on the next launch still works.\n* Tests cover a backward and a forward step for segments, the buffer trim and gesture timestamps, and a forward jump over 1h stops the recording.\n* The `ICurrentDateProvider` parameters stay; removing them is getsentry/sentry-java#6506.\n\n\u003cdetails>\u003csummary>Agent notes\u003c/summary>\n\nVerified on `main` at `5652060246` (2026-11-09).\n\n* Segment boundary: `SessionCaptureStrategy.kt:144`. Frame stamp: `:117`.\n* Buffer: `BufferCaptureStrategy.kt:138` (frame stamp), `:143` (rotate on frame), `:199` (`onTouchEvent` → `rotateEvents`), `:263-269` (segment start and duration).\n* `ReplayCache.kt`: `:81` (file name), `:179-189` (`createVideoOf` window loop), `:220` (`rotate(until = from + duration)`), `:260` (`rotate`), `:442` (`fromDisk` parses the filename into the timestamp).\n* `ReplayGestureConverter.kt`: `:74` (move event `timestamp`), `:105`, `:128`, `:142` (touch start, end and cancel timestamps). The batch timer and `timeOffset` (`:39`, `:63`, `:67-68`) are getsentry/sentry-java#6523.\n* Breadcrumb window filter: `CaptureStrategy.kt:209-212`. Gesture event filter: `:235-236`. `Breadcrumb()` stamps `System.currentTimeMillis()` (`Breadcrumb.java:567`). `maxBreadcrumbs` defaults to 100.\n* `TODO [v9]` markers: `BaseCaptureStrategy.kt:59`, `ReplayGestureConverter.kt:16`.\n* `AnchoredClock` (`sentry/src/main/java/io/sentry/time/AnchoredClock.java`) has `create(EpochClock, MonotonicTicker)`, `startTime()`, `now()`. No drift check.\n* Clocks: `options.monotonicTicker` (Android: `elapsedRealtimeNanos`) is already passed to both strategies (`ReplayIntegration.kt:236-247`). Epoch source: `options.epochClock`.\n* Public timestamp APIs in `sentry-android-replay.api`: `ReplayCache.addFrame(File, long, String)`, `ReplayCache.createVideoOf(long, long, …)`, `GeneratedVideo(File, int, long)`, `ReplayIntegration.onScreenshotRecorded(File, long)`.\n* Hybrid callers: sentry-dart `SentryFlutterPlugin.kt` (around line 293) calls `ReplayIntegration(ctx, dateProvider = CurrentDateProvider.getInstance(), recorderProvider, replayCacheProvider = null)`. `android_replay_recorder.dart` calls `onScreenshotRecorded(bitmap)`, with no timestamp. sentry-react-native's Android code only imports `DefaultReplayBreadcrumbConverter`. Unity and KMP were not checked (GitHub code search rate limit).\n* Gotchas from #6090: evaluate time checks when the frame is captured, not in the queued `replayExecutor` task (`SessionCaptureStrategyTest`: \"executor delay does not trigger a segment boundary\"). Gesture tests that step the clock by more than \\~500ms hit `CAPTURE_MOVE_EVENT_THRESHOLD` instead of the debounce.\n* Code plan (2026-11-10): new internal `capture/ReplayClock.kt` holding a volatile `AnchoredClock` and a generation counter, with `restart()`, `nowMillis()` and `checkForStep(): Rebase(oldNowMs, newStartMs)?`. Session strategy checks at capture (`:117`) and, on a rebase, closes `[segmentTimestamp, oldNow)` before storing the frame. Buffer strategy computes the trim cutoff at capture and ages buffered segments on a `Stopwatch`. The gesture converter gets `ICurrentDateProvider { replayClock.nowMillis() }` at `BaseCaptureStrategy.kt:72`.\n\n\u003c/details>","author":{"url":"https://github.com/runningcode","@type":"Person","name":"runningcode"},"datePublished":"2026-11-09T15:55:36Z","url":"https://github.com/getsentry/sentry-java/issues/6522"}
| react-profiling | 0 |
| react-import-map | react,react-dom,react-dom/client,react-dom/profiling,react-is,react/compiler-runtime,react/jsx-dev-runtime,react/jsx-runtime,scheduler@b8488ee2c322 |
| route-pattern | /_view_fragments/issues/show/:user_id/:repository/:id/issue_layout(.:format) |
| route-controller | voltron_issues_fragments |
| route-action | issue_layout |
| fetch-nonce | v2:899c3c73-fb61-f6f2-148b-26a0055e17f8 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | B0D2:2366B8:4F177A:69F40C:6B04A362 |
| html-safe-nonce | 8e96013f47c6ed15134ea6b3b1cef3f42f1e25de1aff36e435beb9d55d622d02 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJCMEQyOjIzNjZCODo0RjE3N0E6NjlGNDBDOjZCMDRBMzYyIiwidmlzaXRvcl9pZCI6Ijc5NzUyMjkwNTE4MDE3NDAxMzAiLCJyZWdpb25fZWRnZSI6ImlhZCIsInJlZ2lvbl9yZW5kZXIiOiJpYWQifQ== |
| visitor-hmac | 37f9356283a2bc4267e105563dfe31baf74e1136a751fa31a5eeb809339b2320 |
| hovercard-subject-tag | issue:6289555872 |
| github-keyboard-shortcuts | repository,issues,copilot |
| google-site-verification | Apib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I |
| octolytics-url | https://collector.github.com/github/collect |
| analytics-location | / |
| fb:app_id | 1401488693436528 |
| apple-itunes-app | app-id=1477376905, app-argument=https://github.com/_view_fragments/issues/show/getsentry/sentry-java/6522/issue_layout |
| twitter:image | https://opengraph.githubassets.com/0032d238eb34cbe17339d0b101c909a907ddb72418104f935a3e42b43bccd56a/getsentry/sentry-java/issues/6522 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/0032d238eb34cbe17339d0b101c909a907ddb72418104f935a3e42b43bccd56a/getsentry/sentry-java/issues/6522 |
| og:image:alt | Follow-up to #5578. #6090 moved the 1h session cap and the 50ms move debounce onto the monotonic clock. Everything else #5578 listed still reads the wall clock. What still reads the wall clock Segm... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | runningcode |
| hostname | github.com |
| expected-hostname | github.com |
| None | 9784b6f42e2d5eac4e394fa88cad134c0dc5b6662b4ff2787a1ed1ef5a96331d |
| turbo-cache-control | no-preview |
| go-import | github.com/getsentry/sentry-java git https://github.com/getsentry/sentry-java.git |
| octolytics-dimension-user_id | 1396951 |
| octolytics-dimension-user_login | getsentry |
| octolytics-dimension-repository_id | 3368190 |
| octolytics-dimension-repository_nwo | getsentry/sentry-java |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | false |
| octolytics-dimension-repository_network_root_id | 3368190 |
| octolytics-dimension-repository_network_root_nwo | getsentry/sentry-java |
| turbo-body-classes | logged-out env-production page-responsive |
| disable-turbo | false |
| browser-stats-url | https://api.github.com/_private/browser/stats |
| browser-errors-url | https://api.github.com/_private/browser/errors |
| release | 3fd14143b75b2af7b76bbd23b069867d091adfcc |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
| react-app-name | issues |
Links:
| Server | github.com |
| Content-Type | text/html; charset=utf-8 |
| Cache-Control | max-age=0, private, must-revalidate |
Viewport: width=device-width