fix: make layout observation lifecycle thread-safe - #814
Open
marandaneto wants to merge 4 commits into
Open
Conversation
Keep this as a reproduction-only draft. The stale-count test intentionally fails, and Thread Sanitizer detects the existing hasSwizzled race. No production fix is included.
5 tasks
Contributor
posthog-ios Compliance ReportDate: 2026-09-10 09:31:32 UTC ✅ All Tests Passed!45/45 tests passed Capture Tests✅ 29/29 tests passed View Details
Feature_Flags Tests✅ 16/16 tests passed View Details
|
marandaneto
marked this pull request as ready for review
September 10, 2026 09:16
Member
Author
|
@ioannisj or @turnipdabeets can you help me testing this out? its very specific and we dont want to break anything, burnt quite some time figuring this out already |
Contributor
|
Reviews (1): Last reviewed commit: "fix: bound subscriber count notification..." | Re-trigger Greptile |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
💡 Motivation and Context
Converts this reproduction-only PR into a production lifecycle fix. The reproductions are now passing regression tests; no intentionally failing tests remain.
Related to #806, but these confirmed lifecycle defects do not establish the cause of the customer's production
NSISEnginecrash. The diagnostic warning in #815 and run-loop proposal in #813 remain separate work. This preserves synchronous UIKit forwarding on its original calling thread; it does not suppress background layout.Changes
Third-party swizzlers still need to honor their forwarding/restoration contracts. This cannot coordinate arbitrary other SDKs concurrently overwriting the same selector. The warning in #815 will need adapting to the new hook implementation before merging on top of this change.
💚 How did you test it?
Reproduction-first validation confirmed stale count delivery, a
hasSwizzledTSan race, multiple callback objects from concurrent first access, stack-overflowing forwarding after unsubscribe, and clobbering a newer swizzler before the fixes. A retained-old-hook regression also caught duplicate notifications during implementation.make testmake testOniOSSimulatormake buildmake format,make lint,git diff --checkmake buildFull build stops at
ExternalSDK-iOS: the example expects package identityposthog-ios, while the isolated checkout is namedposthog-ios-issue-806-lifecycle. Subsequent CocoaPods examples were not reached. No unrelated build configuration was changed.Autoreview command:
$HOME/.pi/agent/skills/autoreview/scripts/autoreview --mode branch --base origin/main --prompt-file autoreview-scope.md. One test-ordering finding was rejected after checking the actual code: this test uses only zero-interval trailing subscriptions, whoseinvokeTrailingdirectly enqueues on main before the continuation barrier. It does not traverse the background leading-throttle queue. The bundle-only reviewer could not see that unchanged implementation. No accepted review blockers remain.The bounded-delivery follow-up (
5826de1b0) passed isolated autoreview with no findings:$HOME/.pi/agent/skills/autoreview/scripts/autoreview --mode commit --commit HEAD --prompt-file autoreview-bounded-scope.md. Its tests first failed against the unbounded loop, then passed along with the existing lifecycle tests under Thread Sanitizer across three repetitions/relaunches.📝 Checklist
If releasing new changes
.changeset/stable-layout-lifecycle.md.🤖 Agent context
Autonomy: Human-driven (agent-assisted)
Manoel requested implementing the lifecycle fixes in this existing PR worktree and pushing to this PR. Pi used reproduction-first tests, file edits, make-based validation, Thread Sanitizer, GitHub CLI, and isolated Pi autoreview. Changes remain within layout-hook lifecycle and throttled subscriber-count delivery; no run-loop architecture or public API changes are included. Human review is required.