Skip to content

docs(on-feature-flags): record Android's runtime flag listener registration - #161

Merged
turnipdabeets merged 3 commits into
mainfrom
posthog/android-flag-listener-subscription
Nov 3, 2026
Merged

turnipdabeets merged 3 commits into
mainfrom
posthog/android-flag-listener-subscription

Conversation

@posthog

@posthog posthog Bot commented Oct 30, 2026 •

Copy link
Copy Markdown
Contributor

Why

The on-feature-flags spec records Android's only listener surfaces as the config field PostHogConfig.onFeatureFlags and the reloadFeatureFlags(...) completion, and Behavior item 5 names browser and iOS as the only SDKs that invoke a listener registered after flags are already loaded.

posthog-android#878 (merged into the 4.0 line) changes that. It adds PostHog.onFeatureFlags(PostHogFeatureFlagsCallback) — on the instance and the static facade — returning a PostHogFeatureFlagsSubscription with unsubscribe(), replays the current flags to a late subscriber, and delivers on the main thread. It matches posthog-ios 4.0's onFeatureFlags(_:) and posthog-js's onFeatureFlags, which the spec already records as method-style surfaces.

What changed in the spec

  • Surface variants: Android gains the 4.0 method-style registration and its subscription handle. 4.0 removes PostHogConfig.onFeatureFlags (recorded by docs(flags): record the mobile majors' flag API surfaces #164, merged into this branch); reloadFeatureFlags(...) stays as a one-off completion.
  • Behavior item 5: Android's onFeatureFlags(...) registration joins browser and iOS as a surface that replays current values to a late-registered listener. Android's reload completion is explicitly not in that group.
  • Concurrency: records Android 4.0's thread split: onFeatureFlags(...) listeners run on the main thread and the reload completion on the background thread, the same split posthog-ios makes.
  • Two added requirements: a runtime listener registration stays active until unsubscribe() (including across a close()/setup() cycle), and a load already in flight when reset() or close() ran reaches no listener and is not replayed to a later one.

Proposed, applied and archived on this branch under openspec/changes/archive/2026-10-30-record-android-flag-listener-subscription/, as AGENTS.md asks. openspec validate on-feature-flags --type spec --strict passes.

Conformance (checked 2026-11-03)

Requirement posthog-android 4.0 posthog-ios 4.0 posthog-js posthog_flutter 6.0
Registration survives close() / setup() Pass Pass Pass Pass
In-flight load across reset() / close() not delivered Pass Fails for reset() Pass Pass

posthog-js drops a superseded load the same way Android does: _requestGeneration in browser-common is bumped in reset() and dispose(). posthog-ios writes a /flags response that was in flight at reset() to its cache and delivers it to listeners. That bug is already on iOS main and needs an SDK fix; the requirement is right. The change record (design.md, proposal.md) now says so.

For review


Created with PostHog Desktop

🤖 Generated with Claude Code

…ration

posthog-android 4.0 adds onFeatureFlags(callback) returning an unsubscribable
subscription, replaying current values to a late-registered listener and
delivering on the main thread. The spec listed Android as config-field only and
named browser and iOS as the only replaying surfaces.

Also states the lifetime of a runtime listener registration and that a load
discarded by reset() or close() reaches no listener.

Generated-By: PostHog Desktop
Task-Id: 0f06e86a-cfe0-4675-879c-f62409de4f6c
turnipdabeets added a commit that referenced this pull request Oct 30, 2026
openspec validate --strict only reads the first line of a requirement, which is what fails on #161.
* docs(flags): record the mobile majors' flag API surfaces

* docs(on-feature-flags): keep requirement keywords on the first line

openspec validate --strict only reads the first line of a requirement, which is what fails on #161.
@turnipdabeets
turnipdabeets marked this pull request as ready for review November 3, 2026 17:38
@turnipdabeets
turnipdabeets requested a review from a team as a code owner November 3, 2026 17:38
@turnipdabeets
turnipdabeets merged commit 8d8ee30 into main Nov 3, 2026
10 checks passed
@turnipdabeets
turnipdabeets deleted the posthog/android-flag-listener-subscription branch November 3, 2026 17:43
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.

1 participant