Skip to content

fix: recompress request bodies on retry - #184

Merged
marandaneto merged 2 commits into
mainfrom
fix/sdk-compliance-retries
Aug 12, 2026
Merged

fix: recompress request bodies on retry#184
marandaneto merged 2 commits into
mainfrom
fix/sdk-compliance-retries

Conversation

@marandaneto

Copy link
Copy Markdown
Member

💡 Motivation and Context

Req re-encodes JSON request bodies when retrying, but retains the content-encoding: gzip header from the previous attempt. The retry body is therefore sent as plain JSON while marked as gzip. This caused retry requests to be unreadable and made six SDK compliance tests fail.

This change removes the stale content encoding before the compression step runs again. The retry is sent with a valid gzip body that preserves the original event UUID and timestamp. Compression fallback also removes the gzip header before sending an uncompressed body.

💚 How did you test it?

  • mix format --check-formatted
  • mix test - 331 passed, 18 excluded
  • mix credo --strict
  • mix test test/posthog/api/client_test.exs - 17 passed
  • docker compose up --build --abort-on-container-exit --exit-code-from test-harness in sdk_compliance_adapter - 46/46 compliance tests passed

📝 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 sampo add to generate a changeset file

🤖 Agent context

Autonomy: Human-driven (agent-assisted)

Pi was used to reproduce the compliance failures, inspect Req's retry pipeline, implement the fix, and run the project and Docker compliance suites. Autoreview checked the final committed diff and found no actionable issues. GitHub CLI was used to create this pull request.

@marandaneto marandaneto self-assigned this Aug 12, 2026
@marandaneto
marandaneto marked this pull request as ready for review August 12, 2026 07:04
@marandaneto
marandaneto requested a review from a team as a code owner August 12, 2026 07:04
@marandaneto

Copy link
Copy Markdown
Member Author

detected by compliance tests

@github-actions

github-actions Bot commented Aug 12, 2026

Copy link
Copy Markdown
Contributor

posthog-elixir Compliance Report

Date: 2026-08-12 07:19:37 UTC
Duration: 117538ms

✅ All Tests Passed!

46/46 tests passed


Capture Tests

29/29 tests passed

View Details
Test Status Duration
Format Validation.Event Has Required Fields 608ms
Format Validation.Event Has Uuid 609ms
Format Validation.Event Has Lib Properties 609ms
Format Validation.Distinct Id Is String 609ms
Format Validation.Token Is Present 610ms
Format Validation.Custom Properties Preserved 609ms
Format Validation.Event Has Timestamp 608ms
Retry Behavior.Retries On 503 5614ms
Retry Behavior.Does Not Retry On 400 2611ms
Retry Behavior.Does Not Retry On 401 2612ms
Retry Behavior.Respects Retry After Header 5614ms
Retry Behavior.Implements Backoff 15625ms
Retry Behavior.Retries On 500 5615ms
Retry Behavior.Retries On 502 5615ms
Retry Behavior.Retries On 504 5614ms
Retry Behavior.Max Retries Respected 15625ms
Deduplication.Generates Unique Uuids 620ms
Deduplication.Preserves Uuid On Retry 5613ms
Deduplication.Preserves Uuid And Timestamp On Retry 10619ms
Deduplication.Preserves Uuid And Timestamp On Batch Retry 5617ms
Deduplication.No Duplicate Events In Batch 615ms
Deduplication.Different Events Have Different Uuids 613ms
Compression.Sends Gzip When Enabled 609ms
Batch Format.Uses Proper Batch Structure 609ms
Batch Format.Flush With No Events Sends Nothing 607ms
Batch Format.Multiple Events Batched Together 613ms
Error Handling.Does Not Retry On 403 2612ms
Error Handling.Does Not Retry On 413 2612ms
Error Handling.Retries On 408 5615ms

Feature_Flags Tests

17/17 tests passed

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

@greptile-apps

greptile-apps Bot commented Aug 12, 2026

Copy link
Copy Markdown
Prompt To Fix All With AI
### Issue 1
test/posthog/api/client_test.exs:68
**Retry test stops too early**

Setting `max_retries` to 1 verifies only the initial request and first retry, leaving compression-state regressions on later retries undetected.

```suggestion
        max_retries: 2,
```

---

For each issue above, determine whether it is valid and should be fixed. If so, fix it directly.

Reviews (1): Last reviewed commit: "fix: recompress request bodies on retry" | Re-trigger Greptile

Comment thread test/posthog/api/client_test.exs Outdated
@marandaneto
marandaneto merged commit 35087c1 into main Aug 12, 2026
28 checks passed
@marandaneto
marandaneto deleted the fix/sdk-compliance-retries branch August 12, 2026 14:47
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