Skip to content

fix: Enforce a 24-hour maximum session duration#470

Closed
marandaneto wants to merge 9 commits intomainfrom
fix/use-date-provider-in-session-manager
Closed

fix: Enforce a 24-hour maximum session duration#470
marandaneto wants to merge 9 commits intomainfrom
fix/use-date-provider-in-session-manager

Conversation

@marandaneto
Copy link
Copy Markdown
Member

@marandaneto marandaneto commented Mar 26, 2026

💡 Motivation and Context

Enforce a 24-hour maximum session duration. When a session exceeds 24 hours, it is automatically rotated to a new one. This prevents excessively long sessions from accumulating unbounded data.

Closes #220

💚 How did you test it?

  • Added unit tests for rotateSession(), getSessionStartedAt(), and sessionStartedAt lifecycle in PostHogSessionManagerTest.
  • Added integration tests in PostHogLifecycleObserverIntegrationTest verifying:
    • Session is rotated when it exceeds 24 hours.
    • Session is not rotated when under 24 hours.
    • Session rotation is skipped for React Native (RN manages its own sessions).
  • Used PostHogDateProvider for time mocking to make tests deterministic.
  • Ran make checkFormat — all formatting checks pass.

📝 Checklist

  • I reviewed the submitted code.
  • I added tests to verify the changes.
  • I updated the docs if needed.
  • No breaking change or entry added to the changelog.

If releasing new changes

  • Ran pnpm changeset to generate a changeset file
  • Added the "release" label to the PR to indicate we're publishing new versions for the affected packages

@marandaneto marandaneto requested a review from a team as a code owner March 26, 2026 16:42
@marandaneto marandaneto marked this pull request as draft March 26, 2026 16:43
@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented Mar 26, 2026

posthog-android Compliance Report

Date: 2026-03-27 15:36:37 UTC
Duration: 173ms

✅ All Tests Passed!

0/0 tests passed


@marandaneto marandaneto changed the title fix: use PostHogDateProvider in PostHogSessionManager for testability fix: Enforce a 24-hour maximum session duration Mar 26, 2026
Comment on lines +79 to +83
if (postHog?.isSessionReplayActive() == true) {
postHog?.stopSessionReplay()

// startSessionReplay will rotate the session id internally
postHog?.startSessionReplay(resumeCurrent = false)
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

i need to do this here so all the snapshots and caching are cleared up from the previous sessions and wont leak to the new one

if (PostHogSessionManager.isSessionExceedingMaxDuration(currentTimeMillis)) {
cancelTask()
postHog?.endSession()
postHog?.stopSessionReplay()
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

i have to check if i need to call postHog?.startSessionReplay during onStart now

@github-actions
Copy link
Copy Markdown
Contributor

This PR hasn't seen activity in a week! Should it be merged, closed, or further worked on? If you want to keep it open, post a comment or remove the stale label – otherwise this will be closed in another week.

@github-actions
Copy link
Copy Markdown
Contributor

This PR was closed due to lack of activity. Feel free to reopen if it's still relevant.

@github-actions github-actions Bot closed this Apr 21, 2026
@marandaneto
Copy link
Copy Markdown
Member Author

@ioannisj or @turnipdabeets this was done and just not tested, maybe needs a fix or something but should be almost there
i dont have the time/focus on this anymore since it started with a support hero ticket
can one of you take this and test/merge it?

@turnipdabeets
Copy link
Copy Markdown
Contributor

turnipdabeets commented Apr 21, 2026

can one of you take this and test/merge it?

I can take a look after I get back from lunch :)

@turnipdabeets
Copy link
Copy Markdown
Contributor

Continuing this in #494 — GitHub wouldn't allow reopening after the rebase + force-push.

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Enforce max session duration

2 participants