Skip to content

fix: retry event uploads on HTTP 408 (Request Timeout)#539

Merged
turnipdabeets merged 2 commits into
mainfrom
fix/retry-events-on-408
May 28, 2026
Merged

fix: retry event uploads on HTTP 408 (Request Timeout)#539
turnipdabeets merged 2 commits into
mainfrom
fix/retry-events-on-408

Conversation

@turnipdabeets

Copy link
Copy Markdown
Contributor

💡 Motivation and Context

HTTP 408 (Request Timeout) is transient and retryable, and the logs endpoint already retries it — but the events retry set omitted it (a copy-paste guard from when the broader logs policy landed). The SDK compliance contract now requires retrying 408 on events, so this adds it.

Closes #538. (posthog-ios counterpart: PostHog/posthog-ios#623.)

💚 How did you test it?

Added retries on 408 to PostHogQueueTest (mirrors the existing 503/500/502/504 cases). Removed the obsolete "events spec retry policy stays narrower than logs" test, which asserted 408 was excluded — events stays curated (still no 501/505), it just gains 408.

📝 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 events retry set omitted 408 — a copy-paste guard from when the broader
logs retry policy landed. But 408 is transient and retryable, the logs
endpoint already retries it, and the SDK compliance contract now requires it.
Add 408 to the events set and drop the now-obsolete asymmetry test.

Closes #538
@turnipdabeets turnipdabeets requested a review from a team as a code owner May 27, 2026 21:05
@greptile-apps

greptile-apps Bot commented May 27, 2026

Copy link
Copy Markdown

Comments Outside Diff (1)

  1. posthog/src/test/java/com/posthog/internal/PostHogQueueTest.kt, line 504-556 (link)

    P2 Six identical-structure retry tests now exist (retries on 408/429/500/502/503/504), each differing only in the status code. Per the team's preference for parameterised tests, these should be collapsed into a single @ParameterizedTest — it removes the duplication and makes it trivial to add or drop a code in the future.

    Context Used: Do not attempt to comment on incorrect alphabetica... (source)

    Prompt To Fix With AI
    This is a comment left during a code review.
    Path: posthog/src/test/java/com/posthog/internal/PostHogQueueTest.kt
    Line: 504-556
    
    Comment:
    Six identical-structure retry tests now exist (`retries on 408/429/500/502/503/504`), each differing only in the status code. Per the team's preference for parameterised tests, these should be collapsed into a single `@ParameterizedTest` — it removes the duplication and makes it trivial to add or drop a code in the future.
    
    
    
    **Context Used:** Do not attempt to comment on incorrect alphabetica... ([source](https://app.greptile.com/review/custom-context?memory=instruction-0))
    
    How can I resolve this? If you propose a fix, please make it concise.

    Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time!

Prompt To Fix All With AI
Fix the following 2 code review issues. Work through them one at a time, proposing concise fixes.

---

### Issue 1 of 2
posthog/src/test/java/com/posthog/internal/PostHogQueueTest.kt:504-556
Six identical-structure retry tests now exist (`retries on 408/429/500/502/503/504`), each differing only in the status code. Per the team's preference for parameterised tests, these should be collapsed into a single `@ParameterizedTest` — it removes the duplication and makes it trivial to add or drop a code in the future.

```suggestion
    @ParameterizedTest
    @ValueSource(ints = [408, 429, 500, 502, 503, 504])
    fun `retries on retriable status code`(statusCode: Int) {
        val e = PostHogApiError(statusCode, "", null)
        val config = PostHogConfig(API_KEY)
        val limits = initialBatchLimits(config)

        assertFalse(deleteFilesIfAPIError(e, limits, actualBatchSize = limits.cap, logger = config.logger))
    }
```

### Issue 2 of 2
posthog/src/test/java/com/posthog/internal/EndpointSpecTest.kt:317
The removed test also served as a guard for the *negative* cases — it asserted that `501`, `505`, and `599` are not retried by the events path. Now that it's gone, no test verifies that those codes still fall outside the retry set. If the policy were accidentally widened (e.g. a future copy-paste of the logs predicate), it would go unnoticed. Consider adding a complementary parameterised test for non-retriable codes alongside the new positive one.

Reviews (1): Last reviewed commit: "fix: retry event uploads on HTTP 408 (Re..." | Re-trigger Greptile

@@ -317,22 +317,6 @@ internal class EndpointSpecTest {
http.shutdown()

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 The removed test also served as a guard for the negative cases — it asserted that 501, 505, and 599 are not retried by the events path. Now that it's gone, no test verifies that those codes still fall outside the retry set. If the policy were accidentally widened (e.g. a future copy-paste of the logs predicate), it would go unnoticed. Consider adding a complementary parameterised test for non-retriable codes alongside the new positive one.

Prompt To Fix With AI
This is a comment left during a code review.
Path: posthog/src/test/java/com/posthog/internal/EndpointSpecTest.kt
Line: 317

Comment:
The removed test also served as a guard for the *negative* cases — it asserted that `501`, `505`, and `599` are not retried by the events path. Now that it's gone, no test verifies that those codes still fall outside the retry set. If the policy were accidentally widened (e.g. a future copy-paste of the logs predicate), it would go unnoticed. Consider adding a complementary parameterised test for non-retriable codes alongside the new positive one.

How can I resolve this? If you propose a fix, please make it concise.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Good catch — restored the negative-case coverage in a focused events spec does not retry non-retriable status codes test (401/413/501/505/599 stay out of the events set), without re-introducing the 408-excluded assertion. Kept it as plain multi-assert @Test since the repo doesn't use parameterized runners.

@github-actions

github-actions Bot commented May 27, 2026

Copy link
Copy Markdown
Contributor

posthog-android Compliance Report

Date: 2026-05-27 21:16:45 UTC
Duration: 2844ms

⚠️ Some Tests Failed

0/16 tests passed, 16 failed


Feature_Flags Tests

⚠️ 0/16 tests passed, 16 failed

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

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'

@turnipdabeets turnipdabeets merged commit 8fa1bfc into main May 28, 2026
14 checks passed
@turnipdabeets turnipdabeets deleted the fix/retry-events-on-408 branch May 28, 2026 13:36
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.

Events endpoint should retry on HTTP 408 (Request Timeout)

2 participants