Skip to content

feat: add getRemoteConfigPayload to the server SDK - #978

Open
ioannisj wants to merge 4 commits into
mainfrom
feat/get-remote-config-payload
Open

ioannisj wants to merge 4 commits into
mainfrom
feat/get-remote-config-payload

Conversation

@ioannisj

@ioannisj ioannisj commented Nov 13, 2026 •

Copy link
Copy Markdown
Contributor

💡 Motivation and Context

Fixes #577

The Java server SDK has no way to read the payload of a remote config feature flag. Adds getRemoteConfigPayload(key) to posthog-server, with the matching flagRemoteConfigPayload request method on the core PostHogApi.

It sends GET {host}/api/projects/@current/feature_flags/{key}/remote_config?token={projectToken} with the personal API key as a bearer token. No distinct id, no evaluation, no $feature_flag_called event, and no caching. The call blocks the calling thread for the request.

The payload is parsed from JSON. A string result is parsed a second time, and stays a string when that second parse fails, same as getRemoteConfigPayload in posthog-node.

It never throws. It returns null with a warning when:

  • no personalApiKey is set (no request is sent)
  • the flag key is blank, ., or .. (no request is sent)
  • the request fails or the status isn't 2xx
  • the response body isn't valid JSON

An empty 2xx body returns null with no warning. That's how the server answers a flag that has no payload, so it isn't a failure. A disabled client returns null with no request.

Where it differs from posthog-node:

  • posthog-node throws when there's no personal API key. Here it's a warning and null, because the flag methods in this SDK don't throw into the host app.
  • The flag key is percent-encoded as one path segment. posthog-node doesn't escape it, so a key with /, ?, or # changes the request there.
  • A non-2xx status is a failure. posthog-node has no status check, so a JSON error body comes back as the payload.
  • A body that isn't JSON is a warning and null. In posthog-node the call rejects.
  • An empty 2xx body is null. posthog-node throws a SyntaxError on it today, from await response.json() at packages/node/src/client.ts:2272 (480395c4).

The response body and the request headers aren't logged, because a remote config payload can be a decrypted secret. Both parses go through a strict JsonReader, since the shared serializer's Gson is lenient and would accept a body like OK as a string.

The posthog.com docs change isn't part of this PR.

💚 How did you test it?

Unit tests with MockWebServer: 11 for the request method in PostHogApiTest and 21 in the new PostHogRemoteConfigPayloadTest. They cover the request shape and key encoding, each parse result, each null case with its warning, an empty 2xx body with no warning, a 404 with an empty body, and that no event is sent.

  • ./gradlew :posthog:test :posthog-server:test apiCheck spotlessCheck passed on the head commit.
  • make api adds the new method to posthog.api and posthog-server.api. posthog-android.api has no diff.

I didn't test against a live PostHog instance.

📝 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

github-actions Bot commented Nov 13, 2026 •

Copy link
Copy Markdown
Contributor

posthog-android Compliance Report

Date: 2026-11-13 21:01:00 UTC
Duration: 118073ms

✅ All Tests Passed!

46/46 tests passed


Capture Tests

✅ 29/29 tests passed

View Details
Test Status Duration
Format Validation.Event Has Required Fields ✅ 264ms
Format Validation.Event Has Uuid ✅ 26ms
Format Validation.Event Has Lib Properties ✅ 23ms
Format Validation.Distinct Id Is String ✅ 20ms
Format Validation.Token Is Present ✅ 23ms
Format Validation.Custom Properties Preserved ✅ 21ms
Format Validation.Event Has Timestamp ✅ 20ms
Retry Behavior.Retries On 503 ✅ 7026ms
Retry Behavior.Does Not Retry On 400 ✅ 4020ms
Retry Behavior.Does Not Retry On 401 ✅ 4021ms
Retry Behavior.Respects Retry After Header ✅ 7022ms
Retry Behavior.Implements Backoff ✅ 17031ms
Retry Behavior.Retries On 500 ✅ 7017ms
Retry Behavior.Retries On 502 ✅ 7018ms
Retry Behavior.Retries On 504 ✅ 7016ms
Retry Behavior.Max Retries Respected ✅ 17034ms
Deduplication.Generates Unique Uuids ✅ 37ms
Deduplication.Preserves Uuid On Retry ✅ 7016ms
Deduplication.Preserves Uuid And Timestamp On Retry ✅ 12036ms
Deduplication.Preserves Uuid And Timestamp On Batch Retry ✅ 7017ms
Deduplication.No Duplicate Events In Batch ✅ 26ms
Deduplication.Different Events Have Different Uuids ✅ 27ms
Compression.Sends Gzip When Enabled ✅ 22ms
Batch Format.Uses Proper Batch Structure ✅ 21ms
Batch Format.Flush With No Events Sends Nothing ✅ 17ms
Batch Format.Multiple Events Batched Together ✅ 35ms
Error Handling.Does Not Retry On 403 ✅ 4027ms
Error Handling.Does Not Retry On 413 ✅ 4028ms
Error Handling.Retries On 408 ✅ 5033ms

Feature_Flags Tests

✅ 17/17 tests passed

View Details
Test Status Duration
Request Payload.Request With Person Properties Device Id ✅ 29ms
Request Payload.Flags Request Uses V2 Query Param ✅ 21ms
Request Payload.Flags Request Hits Flags Path Not Decide ✅ 20ms
Request Payload.Flags Request Omits Authorization Header ✅ 26ms
Request Payload.Token In Flags Body Matches Init ✅ 26ms
Request Payload.Groups Round Trip ✅ 18ms
Request Payload.Groups Default To Empty Object ✅ 16ms
Request Payload.Disable Geoip False Propagates As Geoip Disable False ✅ 31ms
Request Payload.Disable Geoip Omitted Defaults To False ✅ 22ms
Request Payload.Flag Keys To Evaluate Contains Only Requested Key ✅ 18ms
Request Lifecycle.No Flags Request On Init Alone ✅ 9ms
Request Lifecycle.No Flags Request On Normal Capture ✅ 18ms
Request Lifecycle.Two Flag Calls Produce Two Remote Requests ✅ 29ms
Request Lifecycle.Mock Response Value Is Returned To Caller ✅ 20ms
Retry Behavior.Retries Flags On 502 ✅ 320ms
Retry Behavior.Retries Flags On 504 ✅ 322ms
Side Effect Events.Get Feature Flag Captures Feature Flag Called Event ✅ 28ms

@posthog posthog Bot added the self-driving label Nov 13, 2026
@posthog

posthog Bot commented Nov 13, 2026 •

Copy link
Copy Markdown
Contributor

PostHog Review · Deep · reviewed 055d5c8

Nothing to post.

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

A happy dog on a sunny path

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

veria-ai Bot commented Nov 13, 2026 •

Copy link
Copy Markdown

PR overview

All previously flagged issues have been addressed. No open security concerns remain on this pull request.

Fixed/addressed: 1 · PR risk: 0/10

Reviews

This branch has not been deployed

No deployments
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.

Feature Flags: Add Remote config to Java SDK

2 participants