Skip to content

fix: preserve events with non-finite numeric properties - #382

Merged
marandaneto merged 7 commits into
mainfrom
fix/non-finite-event-properties-20261022
Oct 23, 2026
Merged

marandaneto merged 7 commits into
mainfrom
fix/non-finite-event-properties-20261022

Conversation

@marandaneto

@marandaneto marandaneto commented Oct 22, 2026 •

Copy link
Copy Markdown
Member

💡 Motivation and Context

Numeric NaN and infinities can discard an event before queue admission in legacy and analytics-v1 capture. Non-finite float32 values can also produce invalid JSON without an encoder error.

Normalize supported property containers once into a copied graph, then encode the event. Replace numeric non-finites with null while preserving array positions, healthy properties/events, literal strings and caller-owned values. Arbitrary structs containing a non-finite field become null as a whole property.

Preserve native custom-marshaler boundaries, including go-json context marshalers and pointer-receiver redaction. Malformed custom output stays an error and is never replaced by exported fields. By-value array elements use addressable copies to preserve native redaction without enabling pointer methods on unrelated array containers. Unrelated serialization errors still propagate.

Related source Python PR: PostHog/posthog-python#1081. This is context, not a claim that it is merged.

💚 How did you test it?

Verified RED/GREEN for numeric event loss, invalid float32 JSON, malformed context-marshaler privacy, repeated subtree encoding and pointer-receiver redaction in slices and by-value arrays. Exact main/native controls verify array-element and named-container method semantics independently.

There are 95 authored regression/control cases through real SDK preparation/capture with fake HTTP transport, healthy neighboring events, strict JSON, error identity and input ownership checks. Full root make build passes on the exact SDK source (568 top-level PASS records), including vet and race tests. After merging the authorized upstream action-pin-only update, focused race tests, API/formatting checks and exact-final-HEAD branch autoreview pass again on Go1.26.4.

The 2,000-level probe improved from 375–390ms to 1.47–1.83ms after one-pass normalization. Upfront copying costs more for finite input: representative full preparation is about 4.06µs/38 allocations versus 1.88µs/15 on main and 2.61µs/15 on the earlier PR version. These are local microbenchmarks, not end-to-end throughput claims.

Hosted checks are clear on published 103af4a. The new array correction and workflow-only merge still need hosted checks after publication. Earlier local minimum-Go runtime checks were blocked by macOS; Linux cross-compilation was compile-only. Hosted Go 1.21 and nested-adapter checks passed on 103af4a. No production shutdown/retry behavior or timing fixtures were changed.

📝 Checklist

  • 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

The patch changeset was authored directly in the documented format. No API, runtime dependency or lane version bump is added.

🤖 Agent context

Autonomy: Human-driven (agent-assisted)

Human DRI: @marandaneto. An OpenAI implementation agent used local shell/file/gh tools under human direction. Review claims were independently reproduced before narrow corrections. Struct field/tag handling remains delegated to the native encoder rather than a replacement serializer.

The array correction is signed in b406ce477cebb6ec1ea9955352fdaf8d94336d4e. Final signed merge 466a2517009811ea8f0538f67e60e8a4a963abba incorporates canonical action pins without rewriting history. Exact branch autoreview is clean against 6ffac5a198fa246c7596376f27fad0f73466ca7a. Human review is required.

@marandaneto marandaneto self-assigned this Oct 22, 2026
@marandaneto
marandaneto marked this pull request as ready for review October 22, 2026 14:38
@marandaneto
marandaneto requested a review from a team as a code owner October 22, 2026 14:38

@posthog posthog Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

PostHog Review · Standard · reviewed db9698c: 1 Must fix, 1 Should fix.

This is the only automatic review while this pull request is a draft. Comment @posthog review to review new changes sooner. Otherwise, a review of the new changes runs when you mark it ready for review.

Comment thread event_properties_json.go Outdated
Comment thread event_properties_json.go Outdated
@posthog posthog Bot removed the posthog-review label Oct 22, 2026
@github-actions

github-actions Bot commented Oct 22, 2026 •

Copy link
Copy Markdown
Contributor

posthog-go Compliance Report

Date: 2026-10-22 18:31:22 UTC
Duration: 168970ms

✅ All Tests Passed!

111/111 tests passed


Capture_V1 Tests

✅ 94/94 tests passed

View Details
Test Status Duration
Endpoint And Method.Targets V1 Endpoint ✅ 17ms
Endpoint And Method.Does Not Use Legacy Endpoints ✅ 5ms
Required Headers.Has Authorization Bearer Header ✅ 5ms
Required Headers.Has Content Type Json ✅ 5ms
Required Headers.Has Posthog Sdk Info Format ✅ 5ms
Required Headers.Has Posthog Attempt Header ✅ 5ms
Required Headers.Has Posthog Request Id ✅ 5ms
Required Headers.Has Posthog Request Timestamp ✅ 5ms
Required Headers.Has User Agent ✅ 5ms
Body Format.Body Has Created At And Batch ✅ 5ms
Body Format.No Api Key In Body ✅ 4ms
Body Format.No Sent At In Body ✅ 6ms
Event Format.Event Has Required Root Fields ✅ 4ms
Event Format.Event Uuid Is Valid ✅ 5ms
Event Format.Event Timestamp Is Rfc3339 ✅ 4ms
Event Format.Distinct Id Is String ✅ 5ms
Event Format.Distinct Id At Root Not Properties ✅ 5ms
Event Format.Custom Properties Preserved ✅ 5ms
Event Format.Set Properties Preserved ✅ 5ms
Event Format.Set Once Properties Preserved ✅ 4ms
Event Format.Groups Properties Preserved ✅ 5ms
Event Format.Sdk Generates Uuid If Not Provided ✅ 4ms
Event Format.Event Has Required Root Fields Batch ✅ 6ms
Event Format.Event Uuid Is Valid Batch ✅ 7ms
Event Format.Event Timestamp Is Rfc3339 Batch ✅ 6ms
Event Format.Distinct Id Is String Batch ✅ 7ms
Event Format.Distinct Id At Root Not Properties Batch ✅ 8ms
Event Format.Custom Properties Preserved Batch ✅ 6ms
Event Format.Set Properties Preserved Batch ✅ 7ms
Event Format.Set Once Properties Preserved Batch ✅ 8ms
Event Format.Groups Properties Preserved Batch ✅ 7ms
Event Format.Sdk Generates Uuid If Not Provided Batch ✅ 7ms
Batch Behavior.Multiple Events In Single Batch ✅ 28ms
Batch Behavior.Batch Envelope Smoke ✅ 9ms
Batch Behavior.Flush With No Events Sends Nothing ✅ 3ms
Batch Behavior.Flush At Triggers Batch ✅ 1007ms
Batch Behavior.Created At Reflects Batch Creation Time ✅ 6ms
Deduplication.Generates Unique Uuids ✅ 11ms
Deduplication.Different Events Same Content Different Uuids ✅ 7ms
Deduplication.Preserves Uuid On Retry ✅ 5133ms
Deduplication.Preserves Timestamp On Retry ✅ 5135ms
Deduplication.Preserves Uuid And Timestamp On Batch Retry ✅ 5136ms
Deduplication.No Duplicate Events In Batch ✅ 29ms
Header Behavior On Retry.Attempt Header Starts At One ✅ 6ms
Header Behavior On Retry.Attempt Header Increments On Retry ✅ 10138ms
Header Behavior On Retry.Request Id Preserved On Retry ✅ 5134ms
Header Behavior On Retry.Different Requests Have Different Request Ids ✅ 2013ms
Header Behavior On Retry.Request Timestamp Changes On Retry ✅ 5135ms
Response Format Validation.Success Response Has Uuid Keyed Results ✅ 6ms
Response Format Validation.Success Response Has Ok For Each Event ✅ 26ms
Response Format Validation.Success No Retry After When All Ok ✅ 27ms
Response Format Validation.Success Retry After Present When Retry Events ✅ 128ms
Response Format Validation.Success No Retry After When Drop Only ✅ 27ms
Response Format Validation.Response Echoes Request Id ✅ 6ms
Retry Behavior.Retries On 408 ✅ 5133ms
Retry Behavior.Retries On 500 ✅ 5133ms
Retry Behavior.Retries On 503 ✅ 5135ms
Retry Behavior.Retries On 504 ✅ 5133ms
Retry Behavior.Retryable Errors Have Retry After ✅ 2132ms
Retry Behavior.Respects Retry After On Retryable Error ✅ 8138ms
Retry Behavior.Does Not Retry On 400 ✅ 2131ms
Retry Behavior.Does Not Retry On 401 ✅ 2131ms
Retry Behavior.Does Not Retry On 402 ✅ 2131ms
Retry Behavior.Does Not Retry On 413 ✅ 2130ms
Retry Behavior.Does Not Retry On 415 ✅ 2132ms
Retry Behavior.Non Retryable Errors Have No Retry After ✅ 2132ms
Retry Behavior.Implements Backoff ✅ 15141ms
Retry Behavior.Max Retries Respected ✅ 15144ms
Partial Batch Handling.Handles 200 Full Success ✅ 2009ms
Partial Batch Handling.Handles 200 With All Ok ✅ 3030ms
Partial Batch Handling.Does Not Retry Dropped Events ✅ 3028ms
Partial Batch Handling.Does Not Retry Limited Events ✅ 3028ms
Partial Batch Handling.Prunes Ok Events On Partial Retry ✅ 5132ms
Partial Batch Handling.Prunes Dropped Events On Partial Retry ✅ 5135ms
Partial Batch Handling.Retries Only Retry Events From Partial ✅ 5133ms
Partial Batch Handling.Partial Retry Preserves Uuids ✅ 5134ms
Partial Batch Handling.Partial Retry Attempt Header Increments ✅ 5134ms
Partial Batch Handling.Partial Retry Request Id Preserved ✅ 5133ms
Partial Batch Handling.Respects Retry After On Partial ✅ 5131ms
Partial Batch Handling.Unknown Result Treated As Terminal ✅ 3029ms
Partial Batch Handling.Mixed Ok Drop Limited No Retry ✅ 3032ms
Compression.Sends Gzip Content Encoding ✅ 7ms
Compression.No Content Encoding When Disabled ✅ 4ms
Compression.Compressed Body Is Decompressible ✅ 15ms
Error Handling.Does Not Retry On Unknown 4Xx ✅ 2131ms
Event Options.Cookieless Mode Override ✅ 6ms
Event Options.Disable Skew Correction Override ✅ 4ms
Event Options.Process Person Profile Override ✅ 5ms
Event Options.Product Tour Id Override ✅ 5ms
Event Options.Unset Options Omitted ✅ 4ms
Event Options.Options Override In Batch ✅ 7ms
Geoip And Historical Migration.Geoip Disable Injected Into Properties ✅ 5ms
Geoip And Historical Migration.Historical Migration Set In Body ✅ 5ms
Geoip And Historical Migration.Historical Migration Absent By Default ✅ 4ms

Feature_Flags Tests

✅ 17/17 tests passed

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

Comment thread event_properties_json.go Outdated
@veria-ai

veria-ai Bot commented Oct 22, 2026 •

Copy link
Copy Markdown

PR overview

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

Security review

No open security issues remain on this pull request.

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

@posthog posthog Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

PostHog Review · Standard · reviewed 103af4a: 1 Must fix.

Comment thread event_properties_json.go
Comment thread event_properties_json.go
@marandaneto
marandaneto merged commit 6b734dd into main Oct 23, 2026
48 of 49 checks passed
@marandaneto
marandaneto deleted the fix/non-finite-event-properties-20261022 branch October 23, 2026 07:39
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.

2 participants