Skip to content

fix(flags): return no payload for a failed flag record - #1177

Open
andehen wants to merge 2 commits into
mainfrom
fix/no-payload-for-failed-flag-record
Open

andehen wants to merge 2 commits into
mainfrom
fix/no-payload-for-failed-flag-record

Conversation

@andehen

@andehen andehen commented Nov 4, 2026 •

Copy link
Copy Markdown
Contributor

💡 Motivation and Context

A /flags record the server marks failed reads as disabled, but the legacy payload reads still returned the payload it carried. The readers.v1_failed case in the feature flag rules v2 contract is such a record: a producer-valid, failed, config version 1 record that still carries metadata.payload {"columns":2}. Before this change, get_feature_flag_payload() returned {"columns": 2} for a flag that reads as disabled.

The contract now makes this explicit: a failed record never yields a payload from the legacy payload accessor (PostHog/posthog-sdk-test-harness#101).

What changes for a failed record:

Read Before After
get_feature_flag_payload() the record's payload None
get_feature_flag_result().payload the record's payload None
snapshot get_flag_payload(), sync and async the record's payload None
get_all_flags_and_payloads(), get_feature_payloads() left out (only enabled flags) left out
$feature_flag_called carried $feature_flag_payload leaves it out

The fix is in the record parser, posthog/types.py: a failed record gets metadata.payload = None, so every read path follows from it. This covers /flags?v=4 records and records from older servers. Values, reasons and the rest of the metadata are unchanged.

A side effect is in the fallback cache, which stores what a read returned. After a failed record, a later read that falls back to the cache gets the disabled result without the payload, where 7.82.1 returned the payload.

💚 How did you test it?

  • test_a_failed_record_has_no_payload_on_any_read: uses the vendored readers.v1_failed case and an older-server failed record. It checks the parsed record, get_feature_flag_result(), get_feature_flag_payload() with and without events, get_all_flags_and_payloads(), get_feature_payloads() and a snapshot read. A second test checks the async client's snapshot. All three tests fail without the fix.
  • test_a_disabled_record_that_is_not_failed_keeps_its_payload is the control: a disabled record with failed false, null or absent, in both response shapes, keeps its payload on the parsed record, get_feature_flag_result(), get_feature_flag_payload() and a snapshot read, so a change that drops the payload from every disabled flag fails it.
  • test_flags_released_behaviour.py: the server-failed flag in the 7.82.1 scenarios now carries a payload. I re-recorded released_flags_7_82_1.json with posthog 7.82.1, as released_flags_scenarios.py describes. Before changing the scenario, I checked that recording reproduces the committed file byte for byte. The only new differences from 7.82.1 are this payload, and the test names them for the getters and for the good, server failed, timeout cache history. Everything else still matches 7.82.1.
  • Full suite: uv run --frozen --all-extras pytest -q -p no:cacheprovider posthog/test. 6094 passed and 3 failed. The 3 failures are fork tests in test_metrics_autocapture.py. They also fail on an unchanged checkout when the whole suite runs on macOS, and they pass when that file runs alone.
  • ruff format --check ., ruff check ., and mypy with the baseline filter all pass.

📝 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 sampo add to generate a changeset file

🤖 Agent context

Autonomy: Human-driven (agent-assisted)

  • Written with Claude Code at the maintainer's direction, following the decision now stated in the harness contract.
  • The fix is in the parser rather than in each getter, so every read path and the flag events follow from one place.
  • Older-server failed records get the same rule. 7.82.1 also returned their payload, and the recorded v2 comparison shows it.

🤖 Generated with Claude Code

A record the server marks failed reads as disabled, so it now yields no
payload, even when it still carries metadata.payload.
get_feature_flag_payload(), get_feature_flag_result().payload and a
snapshot's get_flag_payload() return None for it, and its
$feature_flag_called events leave out $feature_flag_payload.
get_all_flags_and_payloads() and get_feature_payloads() already left it
out, because they keep only enabled flags. This holds for /flags?v=4
records and for records from older servers.

The 7.82.1 comparison's failed flag now carries a payload, and the
fixture is re-recorded with posthog 7.82.1. Every other recorded result
is unchanged. The test names the payload difference for the getters and
for the server-failed cache history.
@andehen andehen self-assigned this Nov 4, 2026
@github-actions

github-actions Bot commented Nov 4, 2026 •

Copy link
Copy Markdown
Contributor

posthog-python Compliance Report

Date: 2026-11-05T17:53:39.185695+00:00
Duration: 260156ms

✅ All Tests Passed!

121/121 tests passed


Capture_V1 Tests

✅ 95/95 tests passed

View Details
Test Status Duration
Endpoint And Method.Targets V1 Endpoint ✅ 516ms
Endpoint And Method.Does Not Use Legacy Endpoints ✅ 511ms
Required Headers.Has Authorization Bearer Header ✅ 510ms
Required Headers.Has Content Type Json ✅ 511ms
Required Headers.Has Posthog Sdk Info Format ✅ 511ms
Required Headers.Has Posthog Attempt Header ✅ 510ms
Required Headers.Has Posthog Request Id ✅ 510ms
Required Headers.Has Posthog Request Timestamp ✅ 511ms
Required Headers.Has User Agent ✅ 510ms
Body Format.Body Has Created At And Batch ✅ 511ms
Body Format.No Api Key In Body ✅ 510ms
Body Format.No Sent At In Body ✅ 510ms
Event Format.Event Has Required Root Fields ✅ 511ms
Event Format.Event Uuid Is Valid ✅ 510ms
Event Format.Event Timestamp Is Rfc3339 ✅ 510ms
Event Format.Non Utc Event Timestamp Is Converted To Utc ✅ 526ms
Event Format.Distinct Id Is String ✅ 510ms
Event Format.Distinct Id At Root Not Properties ✅ 511ms
Event Format.Custom Properties Preserved ✅ 510ms
Event Format.Set Properties Preserved ✅ 511ms
Event Format.Set Once Properties Preserved ✅ 510ms
Event Format.Groups Properties Preserved ✅ 510ms
Event Format.Sdk Generates Uuid If Not Provided ✅ 510ms
Event Format.Event Has Required Root Fields Batch ✅ 514ms
Event Format.Event Uuid Is Valid Batch ✅ 513ms
Event Format.Event Timestamp Is Rfc3339 Batch ✅ 514ms
Event Format.Distinct Id Is String Batch ✅ 514ms
Event Format.Distinct Id At Root Not Properties Batch ✅ 514ms
Event Format.Custom Properties Preserved Batch ✅ 514ms
Event Format.Set Properties Preserved Batch ✅ 513ms
Event Format.Set Once Properties Preserved Batch ✅ 513ms
Event Format.Groups Properties Preserved Batch ✅ 514ms
Event Format.Sdk Generates Uuid If Not Provided Batch ✅ 514ms
Batch Behavior.Multiple Events In Single Batch ✅ 517ms
Batch Behavior.Batch Envelope Smoke ✅ 516ms
Batch Behavior.Flush With No Events Sends Nothing ✅ 506ms
Batch Behavior.Flush At Triggers Batch ✅ 1012ms
Batch Behavior.Created At Reflects Batch Creation Time ✅ 511ms
Deduplication.Generates Unique Uuids ✅ 520ms
Deduplication.Different Events Same Content Different Uuids ✅ 514ms
Deduplication.Preserves Uuid On Retry ✅ 6520ms
Deduplication.Preserves Timestamp On Retry ✅ 6520ms
Deduplication.Preserves Uuid And Timestamp On Batch Retry ✅ 6522ms
Deduplication.No Duplicate Events In Batch ✅ 518ms
Header Behavior On Retry.Attempt Header Starts At One ✅ 510ms
Header Behavior On Retry.Attempt Header Increments On Retry ✅ 13519ms
Header Behavior On Retry.Request Id Preserved On Retry ✅ 6520ms
Header Behavior On Retry.Different Requests Have Different Request Ids ✅ 3020ms
Header Behavior On Retry.Request Timestamp Changes On Retry ✅ 6519ms
Response Format Validation.Success Response Has Uuid Keyed Results ✅ 511ms
Response Format Validation.Success Response Has Ok For Each Event ✅ 514ms
Response Format Validation.Success No Retry After When All Ok ✅ 513ms
Response Format Validation.Success Retry After Present When Retry Events ✅ 1516ms
Response Format Validation.Success No Retry After When Drop Only ✅ 513ms
Response Format Validation.Response Echoes Request Id ✅ 510ms
Retry Behavior.Retries On 408 ✅ 6520ms
Retry Behavior.Retries On 500 ✅ 6517ms
Retry Behavior.Retries On 503 ✅ 8523ms
Retry Behavior.Retries On 504 ✅ 6523ms
Retry Behavior.Retryable Errors Have Retry After ✅ 3517ms
Retry Behavior.Respects Retry After On Retryable Error ✅ 11521ms
Retry Behavior.Does Not Retry On 400 ✅ 2514ms
Retry Behavior.Does Not Retry On 401 ✅ 2513ms
Retry Behavior.Does Not Retry On 402 ✅ 2513ms
Retry Behavior.Does Not Retry On 413 ✅ 2512ms
Retry Behavior.Does Not Retry On 415 ✅ 2513ms
Retry Behavior.Non Retryable Errors Have No Retry After ✅ 2514ms
Retry Behavior.Implements Backoff ✅ 22525ms
Retry Behavior.Max Retries Respected ✅ 22525ms
Partial Batch Handling.Handles 200 Full Success ✅ 2513ms
Partial Batch Handling.Handles 200 With All Ok ✅ 3518ms
Partial Batch Handling.Does Not Retry Dropped Events ✅ 3514ms
Partial Batch Handling.Does Not Retry Limited Events ✅ 3513ms
Partial Batch Handling.Prunes Ok Events On Partial Retry ✅ 6522ms
Partial Batch Handling.Prunes Dropped Events On Partial Retry ✅ 6521ms
Partial Batch Handling.Retries Only Retry Events From Partial ✅ 6524ms
Partial Batch Handling.Partial Retry Preserves Uuids ✅ 6518ms
Partial Batch Handling.Partial Retry Attempt Header Increments ✅ 6524ms
Partial Batch Handling.Partial Retry Request Id Preserved ✅ 6520ms
Partial Batch Handling.Respects Retry After On Partial ✅ 8518ms
Partial Batch Handling.Unknown Result Treated As Terminal ✅ 3516ms
Partial Batch Handling.Mixed Ok Drop Limited No Retry ✅ 3518ms
Compression.Sends Gzip Content Encoding ✅ 511ms
Compression.No Content Encoding When Disabled ✅ 510ms
Compression.Compressed Body Is Decompressible ✅ 512ms
Error Handling.Does Not Retry On Unknown 4Xx ✅ 2513ms
Event Options.Cookieless Mode Override ✅ 510ms
Event Options.Disable Skew Correction Override ✅ 510ms
Event Options.Process Person Profile Override ✅ 510ms
Event Options.Product Tour Id Override ✅ 511ms
Event Options.Unset Options Omitted ✅ 510ms
Event Options.Options Override In Batch ✅ 516ms
Geoip And Historical Migration.Geoip Disable Injected Into Properties ✅ 510ms
Geoip And Historical Migration.Historical Migration Set In Body ✅ 511ms
Geoip And Historical Migration.Historical Migration Absent By Default ✅ 510ms

Capture_Ai Tests

✅ 5/5 tests passed

View Details
Test Status Duration
Routing.Capture Ai Posts To Ai Endpoint ✅ 511ms
Routing.Capture Does Not Reroute Ai Named Events ✅ 511ms
Identity.Capture Ai Event Has Uuid ✅ 511ms
Identity.Capture Ai Keeps Supplied Uuid ✅ 512ms
Timestamp Format.Non Utc Event Timestamp Is Converted To Utc ✅ 510ms

Feature_Flags Tests

✅ 17/17 tests passed

View Details
Test Status Duration
Request Payload.Request With Person Properties Device Id ✅ 12ms
Request Payload.Flags Request Uses V4 Query Param ✅ 12ms
Request Payload.Flags Request Hits Flags Path Not Decide ✅ 11ms
Request Payload.Flags Request Omits Authorization Header ✅ 10ms
Request Payload.Token In Flags Body Matches Init ✅ 9ms
Request Payload.Groups Round Trip ✅ 11ms
Request Payload.Groups Default To Empty Object ✅ 11ms
Request Payload.Disable Geoip False Propagates As Geoip Disable False ✅ 10ms
Request Payload.Disable Geoip Omitted Defaults To False ✅ 11ms
Request Payload.Flag Keys To Evaluate Contains Only Requested Key ✅ 12ms
Request Lifecycle.No Flags Request On Init Alone ✅ 4ms
Request Lifecycle.No Flags Request On Normal Capture ✅ 511ms
Request Lifecycle.Two Flag Calls Produce Two Remote Requests ✅ 14ms
Request Lifecycle.Mock Response Value Is Returned To Caller ✅ 11ms
Retry Behavior.Retries Flags On 502 ✅ 315ms
Retry Behavior.Retries Flags On 504 ✅ 314ms
Side Effect Events.Get Feature Flag Captures Feature Flag Called Event ✅ 514ms

Feature_Flags_Local_Evaluation Tests

✅ 4/4 tests passed

View Details
Test Status Duration
Versioned Boolean Matching.Matching Version Missing ✅ 82ms
Versioned Boolean Matching.Matching Version 1 ✅ 81ms
Versioned Boolean Matching.Matching Version 2 ✅ 77ms
Versioned Boolean Matching.Version Only Reload 1 2 1 2 Missing ✅ 45ms

@andehen
andehen marked this pull request as ready for review November 6, 2026 09:05
@andehen
andehen requested a review from a team as a code owner November 6, 2026 09:05
@andehen andehen added the stamphog Request stamphog review label Nov 6, 2026

@stamphog stamphog Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Approved.

The disclosed contract and model changes have current-head independent assurance and a STRONG-familiarity author, with targeted regression coverage. No unresolved review concerns or other refusal grounds were found.

  • Author wrote 100% of the modified lines and has 5 merged PRs in these paths (familiarity STRONG).
  • PostHog Review (Standard) reviewed the current head: no findings.
Gate mechanics and policy version
Gate Result
prerequisites ✓ all clear
deny-list ✓ no deny categories matched
size ✓ 18L, 1F substantive, 186L/6F incl. docs/generated/snapshots — within ceiling
tier ✓ T1-agent / T1c-medium (186L, 6F, two-areas, fix)
stamphog 2.7.0 .stamphog/policy.yml @ 2fb783e · reviewed head 2fb783e

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

stamphog Request stamphog review

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants