Repository navigation
fix(remote-config): decode a payload the endpoint sends as a JSON string - #1351
posthog[bot] wants to merge 1 commit into
Conversation
The remote config endpoint answers with a JSON string holding the payload's JSON text, so `get_remote_config_payload()` returned that text instead of the payload. Decode a string result once more, and return a string that is not JSON unchanged, on both the sync and the async client. Generated-By: PostHog Desktop Task-Id: 82bede78-1bb4-4e30-80ee-9d585c4740d3
SDK performance: posthog-pythonBenchmarks completed. No changes flagged for review. Flags require at least a 5% change in the median and all six pairs agreeing on direction. This is a noise filter, not proof of a performance change or a CI gate. View all results
Values are medians of paired measurements. Not flagged does not mean unchanged. Unavailable means a measurement could not be provided, not zero. Estimated allocation measurements retain their instrumentation uncertainty. RSS measures the whole process, not just SDK allocations; observed peaks are sampled checkpoints. Paired ranges in the diagnostics describe variability, not confidence intervals. Each shard uses its own runner; compare Before PR against With PR within a row, not across shards. Compared 102 metric rows; 102 rows shown in all results. Omitted or shortened data remain in |
💡 Motivation and Context
Brings posthog-python into compliance with the Get Remote Config Payload contract in
openspec/specs/get-remote-config-payload/spec.md, specifically its Payload decoding and String that is not JSON requirements.Why: the weekly SDK compliance matrix scores this contract 🟡 Partial for posthog-python. Its note reads:
The spec says:
The matrix note listed two other gaps for this row — the flag key interpolated unencoded into the path, and blank credentials not treated as missing. Both are already fixed on
main(_remote_config_path()percent-encodes the key and refuses""/"."/"..";api_keyandsecret_keyare stripped at construction, so a blank token disables the client and a blank secret key reads asNone). This PR closes the one remaining gap.Changes
posthog/request.py: new_decode_remote_config_payload()— parses a decoded string once more as JSON, returns a non-string unchanged, and returns a string that is not JSON as is.remote_config()uses it.posthog/_async_request.py:_process_remote_config_response()uses the same helper, soAsyncClientbehaves identically.Compatibility
This is a bug fix, not an API change: the method's signature, request, error channel and
None-on-failure behaviour are unchanged, and a body that already decodes to an object or array is returned exactly as before. It is observable to one kind of caller — someone who has been compensating by callingjson.loads()themselves on the returned string now gets the decoded value and should drop that call. The changeset calls this out.💚 How did you test it?
posthog/test/test_remote_config_paths.pycovering the spec'sbody → payloadtable ({},{"foo":[…]},"{…}","[1,2]","123",["{\"a\":1}"]) and its not-JSON table ("hello world","{broken",""), parameterized over the sync and async clients.pytest posthog/test/test_remote_config_paths.py posthog/test/test_async_request.py posthog/test/test_request.py posthog/test/test_async_feature_flags.pyand theremote_configtests intest_client.py— all pass.uvx ruff format --check/ruff checkon the changed files, andcheck_public_api.pyreports the snapshot up to date (no public symbols added).pytest posthog/test/ --ignore=posthog/test/ai— 8692 passed, 15 skipped. (posthog/test/aineeds live provider credentials and is not runnable here.)Follow-up
Not in this PR: the spec's Empty body recommendation. PostHog answers a flag with no payload with status 200 and an empty body, which
res.json()raises on, so the SDK logs an exception for what the spec treats as an ordinary "no payload" answer. The spec says an SDK that fails on an empty body still conforms, and the matrix did not score it as a gap, so it is left for a separate change.📝 Checklist
If releasing new changes
.sampo/changesets/remote-config-payload-second-decode.md)🤖 Agent context
Autonomy: Fully autonomous
Opened by a scheduled PostHog agent run that reads the compliance matrices in PostHog/sdk-specs, ranks the open 🟡/❌ cells, and implements one per run. This cell was picked as a concrete, self-contained, backwards-compatible fix on a real user-visible bug; breaking-verdict and unknown cells are left for humans.
Scoping decision worth noting for review: of the three gaps the matrix recorded for this row, two were verified as already fixed on
mainand only the decoding gap was implemented. The empty-body recommendation was deliberately left out as a separate concern (see Follow-up).Agent-authored — please review rather than rubber-stamp.
Created with PostHog