Repository navigation
docs(before-send-hook): order calls while an async hook runs - #166
Draft
posthog[bot] wants to merge 1 commit into
Draft
posthog[bot] wants to merge 1 commit into
posthog[bot] wants to merge 1 commit into
Conversation
The spec said hooks run synchronously and never reorder events. Flutter's Dart-layer beforeSend may return a Future, and posthog-flutter 5.x now hands calls to the underlying SDK in the order the app made them so an event keeps the identity, registered properties, groups and consent it was captured under. Adds the ordering requirement, the no-deadlock rule for a hook that calls back into the SDK, and the bounded wait that releases later calls without dropping the pending event. Narrows the synchronous-execution prose to the SDKs it describes. Generated-By: PostHog Desktop Task-Id: bb18dc36-dad3-4323-9385-4fa5bacc5ed7
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.
Why
before-send-hooksays under Concurrency & ordering guarantees that hooks "run synchronously with event preparation" and that the chain "does not batch or reorder events". That holds for every SDK except posthog-flutter, whose Dart-layerbeforeSendmay return aFuture— and the spec never said what an SDK owes callers when the hook can complete asynchronously.In posthog-flutter 5.x,
capture(),screen()andcaptureException()awaited the hook before handing the call to posthog-js or the native SDK, so areset(),identify(),register(),group(),optIn()oroptOut()made right after an un-awaited capture reached the SDK first and the event went out under the next user's identity, registered properties, groups and consent.Source: PostHog/posthog-flutter#672 (merged 2026-10-30), which adds ordered hand-over and notes in its own follow-ups that this spec is the thing out of date.
What changed in the spec
before-send-hookgains one requirement, Ordered hand-over while a before-send hook can complete asynchronously:$screen) cannot deadlock.The Concurrency & ordering guarantees prose is narrowed to the SDKs synchronous execution is true of.
Proposed, applied and archived on this branch under
openspec/changes/archive/2026-11-01-order-calls-around-async-before-send/, asAGENTS.mdasks.Uncertain / for review
beforeSendfor 6, which closes the window entirely; the spec notes that as the convergent answer rather than requiring either shape.acceptance/private/before-send-hook.featureis untouched: the harness has no steps for call ordering or for an asynchronous hook, so the three scenarios live inspec.mdonly and have not been run against an adapter.Validation
openspec validate --specs --strict --no-interactive: 32 passed, 36 failed — identical tomain's totals, all pre-existing "requirement text is very long" warnings. The change itself validates with only that same length warning.Created with PostHog Desktop
🤖 Generated with Claude Code