fix(queue): 413 no config mutation#512
Conversation
|
posthog-android Compliance ReportDate: 2026-05-05 18:29:48 UTC
|
| Test | Status | Duration |
|---|---|---|
| Request Payload.Request With Person Properties Device Id | ❌ | 280ms |
| Request Payload.Flags Request Uses V2 Query Param | ❌ | 35ms |
| Request Payload.Flags Request Hits Flags Path Not Decide | ❌ | 43ms |
| Request Payload.Flags Request Omits Authorization Header | ❌ | 26ms |
| Request Payload.Token In Flags Body Matches Init | ❌ | 28ms |
| Request Payload.Groups Round Trip | ❌ | 24ms |
| Request Payload.Groups Default To Empty Object | ❌ | 23ms |
| Request Payload.Person Properties Distinct Id Auto Populated When Caller Omits It | ❌ | 21ms |
| Request Payload.Disable Geoip False Propagates As Geoip Disable False | ❌ | 18ms |
| Request Payload.Disable Geoip Omitted Defaults To False | ❌ | 20ms |
| Request Payload.Flag Keys To Evaluate Contains Only Requested Key | ❌ | 16ms |
| Request Lifecycle.No Flags Request On Init Alone | ❌ | 13ms |
| Request Lifecycle.No Flags Request On Normal Capture | ❌ | 2051ms |
| Request Lifecycle.Two Flag Calls Produce Two Remote Requests | ❌ | 15ms |
| Request Lifecycle.Mock Response Value Is Returned To Caller | ❌ | 17ms |
| Side Effect Events.Get Feature Flag Captures Feature Flag Called Event | ❌ | 16ms |
Failures
request_payload.request_with_person_properties_device_id
404, message='Not Found', url='http://sdk-adapter:8080/get_feature_flag'
request_payload.flags_request_uses_v2_query_param
404, message='Not Found', url='http://sdk-adapter:8080/get_feature_flag'
request_payload.flags_request_hits_flags_path_not_decide
404, message='Not Found', url='http://sdk-adapter:8080/get_feature_flag'
request_payload.flags_request_omits_authorization_header
404, message='Not Found', url='http://sdk-adapter:8080/get_feature_flag'
request_payload.token_in_flags_body_matches_init
404, message='Not Found', url='http://sdk-adapter:8080/get_feature_flag'
request_payload.groups_round_trip
404, message='Not Found', url='http://sdk-adapter:8080/get_feature_flag'
request_payload.groups_default_to_empty_object
404, message='Not Found', url='http://sdk-adapter:8080/get_feature_flag'
request_payload.person_properties_distinct_id_auto_populated_when_caller_omits_it
404, message='Not Found', url='http://sdk-adapter:8080/get_feature_flag'
request_payload.disable_geoip_false_propagates_as_geoip_disable_false
404, message='Not Found', url='http://sdk-adapter:8080/get_feature_flag'
request_payload.disable_geoip_omitted_defaults_to_false
404, message='Not Found', url='http://sdk-adapter:8080/get_feature_flag'
request_payload.flag_keys_to_evaluate_contains_only_requested_key
404, message='Not Found', url='http://sdk-adapter:8080/get_feature_flag'
request_lifecycle.no_flags_request_on_init_alone
Expected 0 /flags requests, got 1
request_lifecycle.no_flags_request_on_normal_capture
Expected 0 /flags requests, got 1
request_lifecycle.two_flag_calls_produce_two_remote_requests
404, message='Not Found', url='http://sdk-adapter:8080/get_feature_flag'
request_lifecycle.mock_response_value_is_returned_to_caller
404, message='Not Found', url='http://sdk-adapter:8080/get_feature_flag'
side_effect_events.get_feature_flag_captures_feature_flag_called_event
404, message='Not Found', url='http://sdk-adapter:8080/get_feature_flag'
The 413 adaptive batch sizing currently mutates the user-provided PostHogConfig, halving config.maxBatchSize and config.flushAt directly. That makes the user's configured values silently change at runtime — surprising for callers that read those fields back, and it leaks internal queue state across SDK boundaries. It also halves from the *configured* cap rather than the *actual* batch size that triggered the 413. If a 413 fires on a batch of 10 with maxBatchSize=50, we halve from 50 → 25 → 12 → ... wasting halvings on sizes the server already proved (or is about to prove) too large. Move the cap and flushAt into a private BatchLimits class owned by PostHogQueue, initialized from config once at construction. Halve from min(cap, actualBatchSize) so a partial batch's 413 doesn't waste cycles on larger caps the server hasn't accepted, and clamp flushAt to cap on each halve so we never buffer more events than a single batch can drain (e.g. cap=1 + flushAt=10 would otherwise pile 10 events to send 1 at a time). config.maxBatchSize and config.flushAt are now read-only as far as the queue is concerned. Matches the equivalent iOS fix in posthog-ios PR #585 and posthog-js-lite. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
The unit tests for `deleteFilesIfAPIError` exercise the halving logic against a `BatchLimits` instance directly. They don't catch the case where `takeFiles()` (or any other call site) regresses to reading `config.maxBatchSize` instead of `batchLimits.cap` — the queue would keep sending full-size batches even after the cap had been halved. Add an integration test that drives `flush()` against a mock returning 413 and asserts that `currentBatchCapForTesting` and `currentFlushAtForTesting` halve across successive flushes. Adds the two test accessors mirroring iOS's `currentBatchCapForTesting` / `currentFlushAtForTesting`.
db44f1d to
ad7734d
Compare
Replace nested max(min(...), 1) with .div(2).coerceAtLeast(1) chaining, move BatchLimits.initial(...) to a top-level initialBatchLimits(...) factory using .coerceAtLeast(1).
The 413 adaptive batch sizing currently mutates the user-provided PostHogConfig, halving config.maxBatchSize and config.flushAt directly. That makes the user's configured values silently change at runtime — surprising for callers that read those fields back, and it leaks internal queue state across SDK boundaries.
It also halves from the configured cap rather than the actual batch size that triggered the 413. If a 413 fires on a batch of 10 with maxBatchSize=50, we halve from 50 → 25 → 12 → ... wasting halvings on sizes the server already proved (or is about to prove) too large.
Move the cap and flushAt into a private BatchLimits class owned by PostHogQueue, initialized from config once at construction. Halve from min(cap, actualBatchSize) so a partial batch's 413 doesn't waste cycles on larger caps the server hasn't accepted, and clamp flushAt to cap on each halve so we never buffer more events than a single batch can drain (e.g. cap=1 + flushAt=10 would otherwise pile 10 events to send 1 at a time). config.maxBatchSize and config.flushAt are now read-only as far as the queue is concerned.
Matches the equivalent iOS fix in posthog-ios PR #585
💡 Motivation and Context
💚 How did you test it?
📝 Checklist
If releasing new changes
pnpm changesetto generate a changeset file