Skip to content

fix: store the person-properties hash only once the update is queued - #967

Merged
turnipdabeets merged 4 commits into
mainfrom
fix/person-properties-hash-after-queue
Nov 12, 2026
Merged

turnipdabeets merged 4 commits into
mainfrom
fix/person-properties-hash-after-queue

Conversation

@turnipdabeets

Copy link
Copy Markdown
Contributor

💡 Motivation and Context

Android stores the person-properties dedup hash before the event is built. So if beforeSend drops a $set, or sets $process_person_profile to false, or the SDK is opted out, the hash is stored anyway, and the next identical setPersonProperties/identify call is skipped. The server never gets that update.

This makes Android follow sdk-specs #208 (and the existing identify spec), and matches how iOS's queueEvent already works:

  • The duplicate check still runs before capture.
  • The hash is recorded only after the event is queued, based on the event as sent (after beforeSend). It's recorded when the event keeps its name and $process_person_profile is missing or true.
  • If it's queued with any other value, or renamed, the hash is cleared so a repeat gets sent.
  • If the event is dropped, the hash is left alone.
  • An accepted $identify now records the hash too, as the spec says. A follow-up identify with the same properties no longer sends an extra $set.

Two identical calls racing each other can now both be sent, which the spec allows. The old code wrote the hash in the check itself.

The v4 branch PR #965 can then be rebased onto this and shrink to the per-call process_person_profile option, which is already covered here because that option lands in $process_person_profile before the hook runs.

💚 How did you test it?

  • New tests in PostHogTest: a $set dropped by beforeSend is resent, a $set made personless by beforeSend is resent, an update made while opted out is sent after optIn(), and identify skips a $set that repeats its $identify properties. All 4 fail on main and pass with this change.
  • ./gradlew spotlessCheck :posthog:apiCheck :posthog:test :posthog-android:testDebugUnitTest: 1094 + 1033 tests, 0 failures.

📝 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

Autonomy: Human-driven (agent-assisted)

Claude Code (Opus) wrote the fix after a spec review of sdk-specs#208 found Android #965 stored the hash before beforeSend and queueing. I followed iOS's queueEvent as the reference, but kept Android's pre-capture duplicate check rather than moving the whole check under the queue lock.

The dedup hash was written before capture ran, so a $set that beforeSend
dropped or made personless, or one made while opted out, still left its
hash and the next identical update was skipped. The hash is now checked
before capture and recorded or cleared after the event is queued, from
the event as sent. An accepted $identify records it too.
@turnipdabeets
turnipdabeets requested a review from a team as a code owner November 11, 2026 00:17
@turnipdabeets turnipdabeets self-assigned this Nov 11, 2026
@veria-ai

veria-ai Bot commented Nov 11, 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

@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 b99bd17: 2 Should fix.

See this review and its findings in PostHog Review. Comment @posthog review --deep for a Deep review. A Deep review takes longer and looks deeper than a Standard review.

@github-actions

github-actions Bot commented Nov 11, 2026 •

Copy link
Copy Markdown
Contributor

posthog-android Compliance Report

Date: 2026-11-12 14:20:28 UTC
Duration: 118044ms

✅ All Tests Passed!

46/46 tests passed


Capture Tests

✅ 29/29 tests passed

View Details
Test Status Duration
Format Validation.Event Has Required Fields ✅ 300ms
Format Validation.Event Has Uuid ✅ 26ms
Format Validation.Event Has Lib Properties ✅ 25ms
Format Validation.Distinct Id Is String ✅ 23ms
Format Validation.Token Is Present ✅ 22ms
Format Validation.Custom Properties Preserved ✅ 20ms
Format Validation.Event Has Timestamp ✅ 21ms
Retry Behavior.Retries On 503 ✅ 7026ms
Retry Behavior.Does Not Retry On 400 ✅ 4021ms
Retry Behavior.Does Not Retry On 401 ✅ 4022ms
Retry Behavior.Respects Retry After Header ✅ 7022ms
Retry Behavior.Implements Backoff ✅ 17029ms
Retry Behavior.Retries On 500 ✅ 7018ms
Retry Behavior.Retries On 502 ✅ 7018ms
Retry Behavior.Retries On 504 ✅ 7018ms
Retry Behavior.Max Retries Respected ✅ 17020ms
Deduplication.Generates Unique Uuids ✅ 32ms
Deduplication.Preserves Uuid On Retry ✅ 7016ms
Deduplication.Preserves Uuid And Timestamp On Retry ✅ 12029ms
Deduplication.Preserves Uuid And Timestamp On Batch Retry ✅ 7017ms
Deduplication.No Duplicate Events In Batch ✅ 29ms
Deduplication.Different Events Have Different Uuids ✅ 22ms
Compression.Sends Gzip When Enabled ✅ 15ms
Batch Format.Uses Proper Batch Structure ✅ 14ms
Batch Format.Flush With No Events Sends Nothing ✅ 11ms
Batch Format.Multiple Events Batched Together ✅ 24ms
Error Handling.Does Not Retry On 403 ✅ 4017ms
Error Handling.Does Not Retry On 413 ✅ 4019ms
Error Handling.Retries On 408 ✅ 5024ms

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 ✅ 26ms
Request Payload.Flags Request Hits Flags Path Not Decide ✅ 20ms
Request Payload.Flags Request Omits Authorization Header ✅ 19ms
Request Payload.Token In Flags Body Matches Init ✅ 17ms
Request Payload.Groups Round Trip ✅ 18ms
Request Payload.Groups Default To Empty Object ✅ 19ms
Request Payload.Disable Geoip False Propagates As Geoip Disable False ✅ 17ms
Request Payload.Disable Geoip Omitted Defaults To False ✅ 16ms
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 ✅ 24ms
Request Lifecycle.Two Flag Calls Produce Two Remote Requests ✅ 33ms
Request Lifecycle.Mock Response Value Is Returned To Caller ✅ 16ms
Retry Behavior.Retries Flags On 502 ✅ 318ms
Retry Behavior.Retries Flags On 504 ✅ 318ms
Side Effect Events.Get Feature Flag Captures Feature Flag Called Event ✅ 17ms

turnipdabeets and others added 2 commits November 10, 2026 21:43
Gson throws on values such as Double.NaN, which made identify and setPersonProperties throw before the event was captured. Fall back to the map's string form and log instead.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
If beforeSend changed or removed $set/$set_once or the distinct id, the original hash was still cached and a later identical update was skipped. Compare the hash of the event as queued and clear it on a mismatch; an empty map now hashes like a missing one.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

@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 480834f: 1 Should fix.

@dustinbyrne dustinbyrne 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.

The earlier NaN-identification and hook-filtered-payload cases are addressed, and relevant CI passes. Two optional robustness notes remain for unhashable or pathological property inputs.

AI-assisted review.

Catch failures from the recursive sort as well as serialization, and
send an unhashable update without caching a hash, instead of falling
back to Map.toString(), which equates 1 and "1".

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@turnipdabeets
turnipdabeets enabled auto-merge (squash) November 12, 2026 14:19
@turnipdabeets
turnipdabeets merged commit 6540a3f into main Nov 12, 2026
17 checks passed
@turnipdabeets
turnipdabeets deleted the fix/person-properties-hash-after-queue branch November 12, 2026 14:33
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