Skip to content

fix: keep tracking app lifecycle after reset() - #1068

Merged
ioannisj merged 1 commit into
mainfrom
fix/1065-reset-stops-the-session-manager-s
Nov 14, 2026
Merged

ioannisj merged 1 commit into
mainfrom
fix/1065-reset-stops-the-session-manager-s

Conversation

@ioannisj

Copy link
Copy Markdown
Contributor

💡 Motivation and Context

Fixes #1065

PostHogSessionManager.reset() nilled the didBecomeActive, didEnterBackground and application-event tokens, and only setup() creates them, so after reset() the manager stopped hearing lifecycle and UI events for the rest of the process. The background flag froze at whatever it was when reset() ran. A reset in the foreground meant background sessions never cleared, and a reset in the background meant no session was created again once the current one timed out, so events and replay lost $session_id until the app restarted.

The teardown came in with #388 (the singleton-to-instance refactor of the session manager) and was never intended. posthog-js only rotates the session id on reset() and keeps its listeners (packages/browser/src/posthog-core.ts:3979); listener teardown there lives in destroy().

Drops the three lines so reset() only rotates the session, matching js.

💚 How did you test it?

Two regression tests in PostHogTests/PostHogSessionManagerTest.swift, one per direction from the issue: a reset in the foreground followed by 31 idle minutes in the background clears the session, and a reset in the background followed by 31 idle minutes in the foreground rotates it. I ran both against main (they fail with the exact symptoms from the issue) and against this branch (they pass). make lint, make test and make buildSdk are green.

📝 Checklist

  • All commits are signed (see Commit signing)
  • 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

🤖 Agent context

DRI: @ioannisj
Autonomy: Human-driven (agent-assisted)

@ioannisj ioannisj self-assigned this Nov 13, 2026
@github-actions

Copy link
Copy Markdown
Contributor

posthog-ios Compliance Report

Date: 2026-11-13T19:06:19.494081+00:00
Duration: 226752ms

⚠️ Some Tests Failed

46/47 tests passed, 1 failed


Capture Tests

⚠️ 29/30 tests passed, 1 failed

View Details
Test Status Duration
Format Validation.Event Has Required Fields ✅ 3058ms
Format Validation.Event Has Uuid ✅ 2892ms
Format Validation.Event Has Lib Properties ✅ 2933ms
Format Validation.Distinct Id Is String ✅ 2922ms
Format Validation.Token Is Present ✅ 2931ms
Format Validation.Custom Properties Preserved ✅ 442ms
Format Validation.Event Has Timestamp ✅ 484ms
Format Validation.Non Utc Event Timestamp Is Converted To Utc ✅ 516ms
Retry Behavior.Retries On 503 ✅ 11769ms
Retry Behavior.Does Not Retry On 400 ✅ 4902ms
Retry Behavior.Does Not Retry On 401 ✅ 4830ms
Retry Behavior.Respects Retry After Header ✅ 5473ms
Retry Behavior.Implements Backoff ✅ 21743ms
Retry Behavior.Retries On 500 ✅ 9297ms
Retry Behavior.Retries On 502 ✅ 9394ms
Retry Behavior.Retries On 504 ✅ 9408ms
Retry Behavior.Max Retries Respected ❌ 21329ms
Deduplication.Generates Unique Uuids ✅ 3093ms
Deduplication.Preserves Uuid On Retry ✅ 9271ms
Deduplication.Preserves Uuid And Timestamp On Retry ✅ 10498ms
Deduplication.Preserves Uuid And Timestamp On Batch Retry ✅ 7890ms
Deduplication.No Duplicate Events In Batch ✅ 3010ms
Deduplication.Different Events Have Different Uuids ✅ 2890ms
Compression.Sends Gzip When Enabled ✅ 2829ms
Batch Format.Uses Proper Batch Structure ✅ 2869ms
Batch Format.Flush With No Events Sends Nothing ✅ 337ms
Batch Format.Multiple Events Batched Together ✅ 3064ms
Error Handling.Does Not Retry On 403 ✅ 4900ms
Error Handling.Does Not Retry On 413 ✅ 4922ms
Error Handling.Retries On 408 ✅ 5518ms

Failures

retry_behavior.max_retries_respected

Expected 4 requests, got 6

Feature_Flags Tests

✅ 17/17 tests passed

View Details
Test Status Duration
Request Payload.Request With Person Properties Device Id ✅ 2824ms
Request Payload.Flags Request Uses V2 Query Param ✅ 2744ms
Request Payload.Flags Request Hits Flags Path Not Decide ✅ 2837ms
Request Payload.Flags Request Omits Authorization Header ✅ 3211ms
Request Payload.Token In Flags Body Matches Init ✅ 2900ms
Request Payload.Groups Round Trip ✅ 2910ms
Request Payload.Groups Default To Empty Object ✅ 2960ms
Request Payload.Disable Geoip False Propagates As Geoip Disable False ✅ 2999ms
Request Payload.Disable Geoip Omitted Defaults To False ✅ 2751ms
Request Payload.Flag Keys To Evaluate Contains Only Requested Key ✅ 2959ms
Request Lifecycle.No Flags Request On Init Alone ✅ 119ms
Request Lifecycle.No Flags Request On Normal Capture ✅ 545ms
Request Lifecycle.Two Flag Calls Produce Two Remote Requests ✅ 5645ms
Request Lifecycle.Mock Response Value Is Returned To Caller ✅ 2915ms
Retry Behavior.Retries Flags On 502 ✅ 3142ms
Retry Behavior.Retries Flags On 504 ✅ 3043ms
Side Effect Events.Get Feature Flag Captures Feature Flag Called Event ✅ 3197ms

@posthog

posthog Bot commented Nov 13, 2026 •

Copy link
Copy Markdown
Contributor

PostHog Review · Deep · reviewed 3d5e46b

Nothing to post.

Step Status Result
Prepare the diff done 3 files, 1 chunk
Pick perspectives done 2 perspectives
Run review passes done 0 issues
Merge overlapping findings done 0 → 0
Validate findings done
Publish done Nothing to post

Four people posing together

@ioannisj
ioannisj marked this pull request as ready for review November 13, 2026 19:25
@ioannisj
ioannisj requested a review from a team as a code owner November 13, 2026 19:25
@veria-ai

veria-ai Bot commented Nov 13, 2026 •

Copy link
Copy Markdown

PR overview

No security issues were found in this pull request.

Reviews

@turnipdabeets turnipdabeets mentioned this pull request Nov 13, 2026
6 of 18 tasks
@ioannisj
ioannisj merged commit 7dd82ef into main Nov 14, 2026
65 of 67 checks passed
@ioannisj
ioannisj deleted the fix/1065-reset-stops-the-session-manager-s branch November 14, 2026 08:05
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.

reset() stops the session manager's foreground and background tracking for the rest of the process

2 participants