Skip to content

fix(audience): backdate session_end timestamp to when the session actually ended#815

Merged
nattb8 merged 1 commit into
mainfrom
feat/sdk-645-backdate-session-end-timestamp
Jul 8, 2026
Merged

fix(audience): backdate session_end timestamp to when the session actually ended#815
nattb8 merged 1 commit into
mainfrom
feat/sdk-645-backdate-session-end-timestamp

Conversation

@nattb8

@nattb8 nattb8 commented Jul 8, 2026

Copy link
Copy Markdown
Collaborator

Fixes SDK-645.

What

session_end now backdates its wire eventTimestamp to the moment the app actually stopped being active, instead of the moment the SDK happened to notice.

Why

session_end can only be detected once something else happens (the app wakes up, or gets shut down) — never at the actual moment the session stopped. Previously the event was always timestamped at that detection moment, so a session that ended by backgrounding could show a session_end timestamped minutes or hours later than reality.

Scenarios this fixes

Scenario Before After
App backgrounded >30s, then reopened session_end timestamped at reopen (e.g. 1hr later) Backdated to when backgrounding began
App force-quit while backgrounded session_end timestamped at quit Backdated to when backgrounding began
Normal quit while active (not backgrounded) session_end timestamped at quit Unchanged — quit time is when it ended

Caveat: duration_sec on the same event remains the only field with zero pause skew — it excludes every pause in a session, short and long. The backdated timestamp only corrects for the final pause before the session ends, so a session with an earlier short (<=30s) alt-tab will still show a small residual gap (bounded by that pause's length) between session_end.timestamp - session_start.timestamp and duration_sec. For exact engaged-time math, use duration_sec.

Test plan

  • dotnet test on Audience.Tests.csproj — full suite green
  • Unit tests cover all three scenarios above, plus: a normal (unpaused) end is not backdated, MessageBuilder.Track honors an explicit timestamp override and normalizes non-UTC input, and a characterization test locking in the short-pause caveat

@nattb8 nattb8 requested review from a team as code owners July 8, 2026 07:37
@nattb8 nattb8 force-pushed the feat/sdk-645-backdate-session-end-timestamp branch 4 times, most recently from 168b017 to e004e49 Compare July 8, 2026 08:17
@nattb8 nattb8 changed the title fix(audience): backdate session_end timestamp on extended-pause rollover fix(audience): backdate session_end timestamp to when the session actually ended Jul 8, 2026
…ually ended

session_end can only be detected once something else happens (the app
wakes up, or gets shut down), never at the actual moment the session
stopped. Backdate the wire eventTimestamp to _pausedAt whenever the
session ends while backgrounded, across every path that can end a
session (Resume rollover, Dispose, Shutdown), so it reflects when
backgrounding began instead of detection time. Matches duration_sec's
existing engagement-aware behavior.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
@nattb8 nattb8 force-pushed the feat/sdk-645-backdate-session-end-timestamp branch from e004e49 to a7a5f4f Compare July 8, 2026 08:22
@github-actions

github-actions Bot commented Jul 8, 2026

Copy link
Copy Markdown

Audience SDK — Build Size

Platform SDK Size Change
Android 0.37 / 20.00 MB +0.01 MB
Windows 0.16 / 20.00 MB +0.00 MB
iOS 8.54 / 20.00 MB +0.03 MB
macOS 0.92 / 20.00 MB +0.02 MB

SDK Size = build minus empty app. Change = vs baseline. Fails if any platform exceeds its absolute size limit.

@nattb8 nattb8 merged commit f9e7425 into main Jul 8, 2026
53 of 56 checks passed
@nattb8 nattb8 deleted the feat/sdk-645-backdate-session-end-timestamp branch July 8, 2026 23:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Development

Successfully merging this pull request may close these issues.

2 participants