Skip to content

fix(remote-config): decode a payload the endpoint sends as a JSON string - #1351

Draft
posthog[bot] wants to merge 1 commit into
mainfrom
posthog/remote-config-payload-second-decode
Draft

posthog[bot] wants to merge 1 commit into
mainfrom
posthog/remote-config-payload-second-decode

Conversation

@posthog

@posthog posthog Bot commented Dec 6, 2026 •

Copy link
Copy Markdown
Contributor

💡 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 second JSON parse is missing. remote_config() returns response.data, which is res.json() — and since the endpoint answers with a JSON string holding the payload's JSON text, the caller gets that text rather than the decoded payload. php and the spec's own scenario table both decode twice.

The spec says:

The SDK SHALL decode the response body as JSON and return the value in the SDK's JSON value type […] When the decoded value is a string, the SDK SHALL parse that string as JSON once more and return the result if it parses. The SDK SHALL NOT parse a second time when the decoded value is not a string.

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_key and secret_key are stripped at construction, so a blank token disables the client and a blank secret key reads as None). 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, so AsyncClient behaves identically.
  • Tests over the spec's own scenario tables, run against a real local HTTP server for both the sync and async clients.

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 calling json.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?

  • New tests in posthog/test/test_remote_config_paths.py covering the spec's body → payload table ({}, {"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.py and the remote_config tests in test_client.py — all pass.
  • uvx ruff format --check / ruff check on the changed files, and check_public_api.py reports the snapshot up to date (no public symbols added).
  • Full suite: pytest posthog/test/ --ignore=posthog/test/ai — 8692 passed, 15 skipped. (posthog/test/ai needs 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

  • All commits are signed
  • 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

  • Changeset added (.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 main and 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

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
@github-actions

github-actions Bot commented Dec 6, 2026

Copy link
Copy Markdown
Contributor

SDK performance: posthog-python

Benchmarks 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
Test Measurement Before PR With PR Change Assessment
Capture and deliver events (32-byte payload, burst)
Shard: capture
Managed heap after settling — — — unavailable; base:​ unsupported; head:​ unsupported; base:​ CPython has no uninstrumented total managed-heap byte counter; tracing would distort this RSS pass.​; head:​ CPython has no uninstrumented total managed-heap byte counter; tracing would distort this RSS pass.​
Capture and deliver events (4,096-byte payload, burst)
Shard: capture
Managed heap after settling — — — unavailable; base:​ unsupported; head:​ unsupported; base:​ CPython has no uninstrumented total managed-heap byte counter; tracing would distort this RSS pass.​; head:​ CPython has no uninstrumented total managed-heap byte counter; tracing would distort this RSS pass.​
Capture and deliver events (32-byte payload, steady)
Shard: capture
Managed heap after settling — — — unavailable; base:​ unsupported; head:​ unsupported; base:​ CPython has no uninstrumented total managed-heap byte counter; tracing would distort this RSS pass.​; head:​ CPython has no uninstrumented total managed-heap byte counter; tracing would distort this RSS pass.​
Capture and deliver events (4,096-byte payload, steady)
Shard: capture
Managed heap after settling — — — unavailable; base:​ unsupported; head:​ unsupported; base:​ CPython has no uninstrumented total managed-heap byte counter; tracing would distort this RSS pass.​; head:​ CPython has no uninstrumented total managed-heap byte counter; tracing would distort this RSS pass.​
Queue an event (32-byte payload)
Shard: capture
Allocated memory per operation — — — unavailable; base:​ unsupported; head:​ unsupported; base:​ Background preparation has no public completion boundary before flush; see capture.​drain for full-pipeline allocations.​; head:​ Background preparation has no public completion boundary before flush; see capture.​drain for full-pipeline allocations.​
Queue an event (32-byte payload)
Shard: capture
Allocations per operation — — — unavailable; base:​ unsupported; head:​ unsupported; base:​ Background preparation has no public completion boundary before flush; see capture.​drain for full-pipeline allocations.​; head:​ Background preparation has no public completion boundary before flush; see capture.​drain for full-pipeline allocations.​
Queue an event (4,096-byte payload)
Shard: capture
Allocated memory per operation — — — unavailable; base:​ unsupported; head:​ unsupported; base:​ Background preparation has no public completion boundary before flush; see capture.​drain for full-pipeline allocations.​; head:​ Background preparation has no public completion boundary before flush; see capture.​drain for full-pipeline allocations.​
Queue an event (4,096-byte payload)
Shard: capture
Allocations per operation — — — unavailable; base:​ unsupported; head:​ unsupported; base:​ Background preparation has no public completion boundary before flush; see capture.​drain for full-pipeline allocations.​; head:​ Background preparation has no public completion boundary before flush; see capture.​drain for full-pipeline allocations.​
Evaluate 1,000 flags under concurrent load
Shard: flags-memory
Managed heap after settling — — — unavailable; base:​ unsupported; head:​ unsupported; base:​ CPython has no uninstrumented total managed-heap byte counter; tracing would distort this RSS pass.​; head:​ CPython has no uninstrumented total managed-heap byte counter; tracing would distort this RSS pass.​
Refresh 1,000 flag definitions
Shard: flags-memory
Managed heap after settling — — — unavailable; base:​ unsupported; head:​ unsupported; base:​ CPython has no uninstrumented total managed-heap byte counter; tracing would distort this RSS pass.​; head:​ CPython has no uninstrumented total managed-heap byte counter; tracing would distort this RSS pass.​
Capture and deliver events (32-byte payload, burst)
Shard: capture
Allocated memory per operation 75.21 KiB/op 75.21 KiB/op No observed change Not flagged
Capture and deliver events (32-byte payload, burst)
Shard: capture
Allocations per operation 775.5 count/op 775.5 count/op No observed change Not flagged
Capture and deliver events (32-byte payload, burst)
Shard: capture
Time per operation 38.59 µs/op 38.4 µs/op 0.5% less time Not flagged
Capture and deliver events (32-byte payload, burst)
Shard: capture
Idle process memory (RSS) 38.49 MiB 38.47 MiB <0.1% less memory Not flagged
Capture and deliver events (32-byte payload, burst)
Shard: capture
Observed peak process memory (RSS) 40.96 MiB 40.93 MiB <0.1% less memory Not flagged
Capture and deliver events (32-byte payload, burst)
Shard: capture
Process memory after settling (RSS) 40.96 MiB 40.93 MiB <0.1% less memory Not flagged
Capture and deliver events (32-byte payload, burst)
Shard: capture
Process CPU time per operation 39.09 µs/op 38.64 µs/op 1.1% less time Not flagged
Capture and deliver events (32-byte payload, burst)
Shard: capture
Lifetime peak process memory (RSS) 41.17 MiB 41.17 MiB <0.1% less memory Not flagged
Capture and deliver events (4,096-byte payload, burst)
Shard: capture
Allocated memory per operation 127.29 KiB/op 127.29 KiB/op <0.1% more memory Not flagged
Capture and deliver events (4,096-byte payload, burst)
Shard: capture
Allocations per operation 767.54 count/op 767.54 count/op <0.1% more Not flagged
Capture and deliver events (4,096-byte payload, burst)
Shard: capture
Time per operation 61.14 µs/op 59.92 µs/op 2% less time Not flagged
Capture and deliver events (4,096-byte payload, burst)
Shard: capture
Idle process memory (RSS) 42.19 MiB 42.26 MiB 0.1% more memory Not flagged
Capture and deliver events (4,096-byte payload, burst)
Shard: capture
Observed peak process memory (RSS) 47.99 MiB 48.05 MiB 0.1% more memory Not flagged
Capture and deliver events (4,096-byte payload, burst)
Shard: capture
Process memory after settling (RSS) 47.99 MiB 48.05 MiB 0.1% more memory Not flagged
Capture and deliver events (4,096-byte payload, burst)
Shard: capture
Process CPU time per operation 56.11 µs/op 54.86 µs/op 2.2% less time Not flagged
Capture and deliver events (4,096-byte payload, burst)
Shard: capture
Lifetime peak process memory (RSS) 52.39 MiB 52.44 MiB <0.1% more memory Not flagged
Capture and deliver events (32-byte payload, steady)
Shard: capture
Allocated memory per operation 80.28 KiB/op 80.28 KiB/op No observed change Not flagged
Capture and deliver events (32-byte payload, steady)
Shard: capture
Allocations per operation 820.45 count/op 820.45 count/op No observed change Not flagged
Capture and deliver events (32-byte payload, steady)
Shard: capture
Time per operation 47.86 µs/op 47.46 µs/op 0.8% less time Not flagged
Capture and deliver events (32-byte payload, steady)
Shard: capture
Idle process memory (RSS) 38.34 MiB 38.31 MiB <0.1% less memory Not flagged
Capture and deliver events (32-byte payload, steady)
Shard: capture
Observed peak process memory (RSS) 38.54 MiB 38.53 MiB <0.1% less memory Not flagged
Capture and deliver events (32-byte payload, steady)
Shard: capture
Process memory after settling (RSS) 38.54 MiB 38.53 MiB <0.1% less memory Not flagged
Capture and deliver events (32-byte payload, steady)
Shard: capture
Process CPU time per operation 47.36 µs/op 46.92 µs/op 0.9% less time Not flagged
Capture and deliver events (32-byte payload, steady)
Shard: capture
Lifetime peak process memory (RSS) 40.82 MiB 40.82 MiB No observed change Not flagged
Capture and deliver events (4,096-byte payload, steady)
Shard: capture
Allocated memory per operation 132.46 KiB/op 132.46 KiB/op <0.1% less memory Not flagged
Capture and deliver events (4,096-byte payload, steady)
Shard: capture
Allocations per operation 812.38 count/op 812.37 count/op <0.1% fewer Not flagged
Capture and deliver events (4,096-byte payload, steady)
Shard: capture
Time per operation 64.28 µs/op 62.07 µs/op 3.4% less time Not flagged
Capture and deliver events (4,096-byte payload, steady)
Shard: capture
Idle process memory (RSS) 41.96 MiB 42.01 MiB 0.1% more memory Not flagged
Capture and deliver events (4,096-byte payload, steady)
Shard: capture
Observed peak process memory (RSS) 42.48 MiB 42.52 MiB <0.1% more memory Not flagged
Capture and deliver events (4,096-byte payload, steady)
Shard: capture
Process memory after settling (RSS) 42.06 MiB 42.12 MiB 0.1% more memory Not flagged
Capture and deliver events (4,096-byte payload, steady)
Shard: capture
Process CPU time per operation 61.69 µs/op 59.29 µs/op 3.9% less time Not flagged
Capture and deliver events (4,096-byte payload, steady)
Shard: capture
Lifetime peak process memory (RSS) 42.37 MiB 42.38 MiB <0.1% more memory Not flagged
Queue an event (32-byte payload)
Shard: capture
Caller-thread CPU time per operation 23.72 µs/op 23.59 µs/op 0.6% less time Not flagged
Queue an event (32-byte payload)
Shard: capture
Time per operation 23.72 µs/op 24.4 µs/op 2.8% more time Not flagged
Queue an event (4,096-byte payload)
Shard: capture
Caller-thread CPU time per operation 24.16 µs/op 23.48 µs/op 2.8% less time Not flagged
Queue an event (4,096-byte payload)
Shard: capture
Time per operation 25.07 µs/op 25.88 µs/op 3.3% more time Not flagged
Evaluate all 10 flags
Shard: flags-scaling
Allocated memory per operation 246.26 KiB/op 246.26 KiB/op No observed change Not flagged
Evaluate all 10 flags
Shard: flags-scaling
Allocations per operation 2,426.44 count/op 2,426.44 count/op No observed change Not flagged
Evaluate all 10 flags
Shard: flags-scaling
Time per operation 153.5 µs/op 151.72 µs/op 1.2% less time Not flagged
Evaluate all 10 flags
Shard: flags-scaling
Process CPU time per operation 153.5 µs/op 151.7 µs/op 1.2% less time Not flagged
Evaluate all 100 flags
Shard: flags-scaling
Allocated memory per operation 2.36 MiB/op 2.36 MiB/op No observed change Not flagged
Evaluate all 100 flags
Shard: flags-scaling
Allocations per operation 23,803.25 count/op 23,803.25 count/op No observed change Not flagged
Evaluate all 100 flags
Shard: flags-scaling
Time per operation 1.42 ms/op 1.41 ms/op 0.9% less time Not flagged
Evaluate all 100 flags
Shard: flags-scaling
Process CPU time per operation 1.42 ms/op 1.41 ms/op 0.9% less time Not flagged
Evaluate all 1,000 flags
Shard: flags-scaling
Allocated memory per operation 23.56 MiB/op 23.56 MiB/op No observed change Not flagged
Evaluate all 1,000 flags
Shard: flags-scaling
Allocations per operation 237,464.81 count/op 237,464.81 count/op No observed change Not flagged
Evaluate all 1,000 flags
Shard: flags-scaling
Time per operation 13.82 ms/op 14.01 ms/op 1.3% more time Not flagged
Evaluate all 1,000 flags
Shard: flags-scaling
Process CPU time per operation 13.82 ms/op 14.01 ms/op 1.3% more time Not flagged
Evaluate 1,000 flags under concurrent load
Shard: flags-memory
Idle process memory (RSS) 44.29 MiB 43.97 MiB 0.7% less memory Not flagged
Evaluate 1,000 flags under concurrent load
Shard: flags-memory
Observed peak process memory (RSS) 44.59 MiB 44.26 MiB 0.7% less memory Not flagged
Evaluate 1,000 flags under concurrent load
Shard: flags-memory
Process memory after settling (RSS) 44.59 MiB 44.26 MiB 0.7% less memory Not flagged
Evaluate 1,000 flags under concurrent load
Shard: flags-memory
Lifetime peak process memory (RSS) 44.29 MiB 44.39 MiB 0.2% more memory Not flagged
Refresh 1,000 flag definitions
Shard: flags-memory
Idle process memory (RSS) 43.64 MiB 44.07 MiB 1% more memory Not flagged
Refresh 1,000 flag definitions
Shard: flags-memory
Observed peak process memory (RSS) 43.66 MiB 44.08 MiB 1% more memory Not flagged
Refresh 1,000 flag definitions
Shard: flags-memory
Process memory after settling (RSS) 43.66 MiB 44.05 MiB 0.9% more memory Not flagged
Refresh 1,000 flag definitions
Shard: flags-memory
Lifetime peak process memory (RSS) 44.27 MiB 44.37 MiB 0.2% more memory Not flagged
Evaluate one boolean flag
Shard: flags-single
Allocated memory per operation 17.85 KiB/op 17.85 KiB/op No observed change Not flagged
Evaluate one boolean flag
Shard: flags-single
Allocations per operation 177.77 count/op 177.77 count/op No observed change Not flagged
Evaluate one boolean flag
Shard: flags-single
Time per operation 7.48 µs/op 7.75 µs/op 3.6% more time Not flagged
Evaluate one boolean flag
Shard: flags-single
Process CPU time per operation 7.48 µs/op 7.75 µs/op 3.6% more time Not flagged
Evaluate a cohort-filtered flag
Shard: flags-single
Allocated memory per operation 28.19 KiB/op 28.19 KiB/op No observed change Not flagged
Evaluate a cohort-filtered flag
Shard: flags-single
Allocations per operation 277.78 count/op 277.78 count/op No observed change Not flagged
Evaluate a cohort-filtered flag
Shard: flags-single
Time per operation 10.18 µs/op 10.09 µs/op 0.9% less time Not flagged
Evaluate a cohort-filtered flag
Shard: flags-single
Process CPU time per operation 10.18 µs/op 10.09 µs/op 0.9% less time Not flagged
Evaluate a flag (early match)
Shard: flags-single
Allocated memory per operation 44.25 KiB/op 44.25 KiB/op No observed change Not flagged
Evaluate a flag (early match)
Shard: flags-single
Allocations per operation 426.27 count/op 426.27 count/op No observed change Not flagged
Evaluate a flag (early match)
Shard: flags-single
Time per operation 14.63 µs/op 14.63 µs/op <0.1% less time Not flagged
Evaluate a flag (early match)
Shard: flags-single
Process CPU time per operation 14.63 µs/op 14.63 µs/op <0.1% less time Not flagged
Evaluate a flag (late match)
Shard: flags-single
Allocated memory per operation 66.96 KiB/op 66.96 KiB/op No observed change Not flagged
Evaluate a flag (late match)
Shard: flags-single
Allocations per operation 639.77 count/op 639.77 count/op No observed change Not flagged
Evaluate a flag (late match)
Shard: flags-single
Time per operation 20.43 µs/op 20.35 µs/op 0.4% less time Not flagged
Evaluate a flag (late match)
Shard: flags-single
Process CPU time per operation 20.43 µs/op 20.35 µs/op 0.4% less time Not flagged
Evaluate a flag (no match)
Shard: flags-single
Allocated memory per operation 65.32 KiB/op 65.32 KiB/op No observed change Not flagged
Evaluate a flag (no match)
Shard: flags-single
Allocations per operation 620.77 count/op 620.77 count/op No observed change Not flagged
Evaluate a flag (no match)
Shard: flags-single
Time per operation 19.62 µs/op 19.62 µs/op <0.1% more time Not flagged
Evaluate a flag (no match)
Shard: flags-single
Process CPU time per operation 19.62 µs/op 19.62 µs/op <0.1% more time Not flagged
Evaluate a property-filtered flag
Shard: flags-single
Allocated memory per operation 21.53 KiB/op 21.53 KiB/op No observed change Not flagged
Evaluate a property-filtered flag
Shard: flags-single
Allocations per operation 212.77 count/op 212.77 count/op No observed change Not flagged
Evaluate a property-filtered flag
Shard: flags-single
Time per operation 8.16 µs/op 8.47 µs/op 3.8% more time Not flagged
Evaluate a property-filtered flag
Shard: flags-single
Process CPU time per operation 8.16 µs/op 8.47 µs/op 3.8% more time Not flagged
Evaluate a regex-filtered flag
Shard: flags-single
Allocated memory per operation 23.6 KiB/op 23.6 KiB/op No observed change Not flagged
Evaluate a regex-filtered flag
Shard: flags-single
Allocations per operation 221.78 count/op 221.78 count/op No observed change Not flagged
Evaluate a regex-filtered flag
Shard: flags-single
Time per operation 9.18 µs/op 9.17 µs/op 0.1% less time Not flagged
Evaluate a regex-filtered flag
Shard: flags-single
Process CPU time per operation 9.18 µs/op 9.17 µs/op 0.2% less time Not flagged
Evaluate a rollout flag
Shard: flags-single
Allocated memory per operation 16.88 KiB/op 16.88 KiB/op No observed change Not flagged
Evaluate a rollout flag
Shard: flags-single
Allocations per operation 166.27 count/op 166.27 count/op No observed change Not flagged
Evaluate a rollout flag
Shard: flags-single
Time per operation 7.29 µs/op 7.36 µs/op 0.9% more time Not flagged
Evaluate a rollout flag
Shard: flags-single
Process CPU time per operation 7.29 µs/op 7.36 µs/op 0.9% more time Not flagged
Evaluate a multivariate flag
Shard: flags-single
Allocated memory per operation 18.13 KiB/op 18.13 KiB/op No observed change Not flagged
Evaluate a multivariate flag
Shard: flags-single
Allocations per operation 182.77 count/op 182.77 count/op No observed change Not flagged
Evaluate a multivariate flag
Shard: flags-single
Time per operation 7.95 µs/op 7.85 µs/op 1.3% less time Not flagged
Evaluate a multivariate flag
Shard: flags-single
Process CPU time per operation 7.95 µs/op 7.85 µs/op 1.3% less time Not flagged

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 4d29c434d0432ddc25b8964e920d6dfa6e498960 → 567414f1afba3d546f6b10b1f1a39bd0994af2d5.

Full report and diagnostics

102 metric rows; 102 rows shown in all results. Omitted or shortened data remain in comparison.json, including per-runner environments, resource limits, measurement methods, samples and checkpoints.

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

0 participants