Skip to content

fix: only attach $sdk_debug_pending_queue_size once the queue reaches flushAt - #995

Open
marandaneto wants to merge 4 commits into
mainfrom
fix/queue-size-debug-only-when-degraded
Open

marandaneto wants to merge 4 commits into
mainfrom
fix/queue-size-debug-only-when-degraded

Conversation

@marandaneto

Copy link
Copy Markdown
Member

💡 Motivation and Context

Every event carries $sdk_debug_pending_queue_size, even when the queue holds fewer events than flushAt. That is just normal batching, so the value adds bytes to every event without helping anyone find a delivery problem.

Now the key is only attached once the queue holds at least flushAt events. That means a flush is due and has not happened yet, for example while offline or backing off. The threshold is the queue's current flushAt, which already halves after a 413 response. PostHogQueueInterface gets a backedUpSize property that returns null by default. It is @PostHogInternal, so this is not a public API change, and posthog.api is updated.

The key stays SDK-owned. While the queue is healthy, a registered or caller-supplied value with the same name is removed instead of being sent. When the queue is backed up, the SDK value replaces it, as before.

Spec: PostHog/sdk-specs#238.

💚 How did you test it?

  • New PostHogQueueTest case for backedUpSize below and at flushAt.
  • New PostHogTest cases: no key below flushAt, including registered and caller values, and the depth reaching the next event while the queue is held offline. The second test fails when backedUpSize is made to return null.
  • Seven existing tests that expected the key on healthy events failed before the change and pass now. The Android event snapshot drops the key and its normalizer.
  • ./gradlew :posthog:test for PostHogTest, PostHogQueueTest and PostHogStatelessTest (376 tests) and :posthog-android:testReleaseUnitTest (1036 tests) pass. apiCheck and make checkFormat are clean.

📝 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)

@github-actions

github-actions Bot commented Nov 20, 2026 •

Copy link
Copy Markdown
Contributor

posthog-android Compliance Report

Date: 2026-11-20 09:54:00 UTC
Duration: 118654ms

✅ All Tests Passed!

46/46 tests passed


Capture Tests

✅ 29/29 tests passed

View Details
Test Status Duration
Format Validation.Event Has Required Fields ✅ 437ms
Format Validation.Event Has Uuid ✅ 34ms
Format Validation.Event Has Lib Properties ✅ 36ms
Format Validation.Distinct Id Is String ✅ 32ms
Format Validation.Token Is Present ✅ 30ms
Format Validation.Custom Properties Preserved ✅ 33ms
Format Validation.Event Has Timestamp ✅ 30ms
Retry Behavior.Retries On 503 ✅ 7038ms
Retry Behavior.Does Not Retry On 400 ✅ 4024ms
Retry Behavior.Does Not Retry On 401 ✅ 4025ms
Retry Behavior.Respects Retry After Header ✅ 7030ms
Retry Behavior.Implements Backoff ✅ 17035ms
Retry Behavior.Retries On 500 ✅ 7020ms
Retry Behavior.Retries On 502 ✅ 7021ms
Retry Behavior.Retries On 504 ✅ 7019ms
Retry Behavior.Max Retries Respected ✅ 17038ms
Deduplication.Generates Unique Uuids ✅ 44ms
Deduplication.Preserves Uuid On Retry ✅ 7018ms
Deduplication.Preserves Uuid And Timestamp On Retry ✅ 12034ms
Deduplication.Preserves Uuid And Timestamp On Batch Retry ✅ 7019ms
Deduplication.No Duplicate Events In Batch ✅ 43ms
Deduplication.Different Events Have Different Uuids ✅ 31ms
Compression.Sends Gzip When Enabled ✅ 22ms
Batch Format.Uses Proper Batch Structure ✅ 22ms
Batch Format.Flush With No Events Sends Nothing ✅ 14ms
Batch Format.Multiple Events Batched Together ✅ 38ms
Error Handling.Does Not Retry On 403 ✅ 4025ms
Error Handling.Does Not Retry On 413 ✅ 4021ms
Error Handling.Retries On 408 ✅ 5029ms

Feature_Flags Tests

✅ 17/17 tests passed

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

@marandaneto
marandaneto marked this pull request as ready for review November 20, 2026 08:56
@marandaneto
marandaneto requested a review from a team as a code owner November 20, 2026 08:56
@veria-ai

veria-ai Bot commented Nov 20, 2026 •

Copy link
Copy Markdown

PR overview

No security issues were found in this pull request.

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 4edcf1d: 1 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.

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

🤖 An AI agent wrote this on behalf of @ioannisj.

No findings from me. I looked at the backedUpSize threshold, the removal of caller and registered values in posthog/src/main/java/com/posthog/PostHog.kt, and the @Volatile read of the halved flushAt on capture threads, and it all looks right to me.

# Conflicts:
#	posthog-android/src/test/resources/json/snapshots/batch-request.json
#	posthog/api/posthog.api
#	posthog/src/main/java/com/posthog/PostHog.kt
#	posthog/src/test/java/com/posthog/PostHogTest.kt

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.

3 participants