fix: retain events after network flush failures#173
Merged
Conversation
Prompt To Fix All With AIFix the following 2 code review issues. Work through them one at a time, proposing concise fixes.
---
### Issue 1 of 2
lib/HttpClient.php:162-171
Three consecutive `elseif`/`else` branches all resolve to a single unconditional `break`, repeating the same statement three times with no differentiation in outcome. The `$responseCode >= 400` and `$responseCode == 0` cases can be folded into a single `else` clause — the only branch that actually diverges from the default here is the 5xx/429 retry.
```suggestion
} else {
// Do not retry non-5xx/non-429 responses (e.g. 4xx, 413 Payload Too Large,
// or responseCode 0 for network errors). PHP sends synchronously in the hosting
// app's request path, so broad retries would slow down the host application.
break;
}
```
### Issue 2 of 2
test/QueueConsumerTest.php:73-117
**Tests should be parameterised**
`testLibCurlNetworkFailureKeepsBatchQueued`, `testLibCurlHttpFailureDropsBatch`, and `testLibCurlPayloadTooLargeDropsBatch` share identical structure — they differ only in `batchEndpointResponse`, `batchEndpointResponseCode`, `batchEndpointCurlErrno`, and whether the queue retains the event. Per the team's standard these should be a single `#[DataProvider]` test (or `@dataProvider` for older PHPUnit), keeping each scenario as a data row and consolidating the assertion logic once.
Reviews (1): Last reviewed commit: "fix: retain events after network flush f..." | Re-trigger Greptile |
|
Reviews (2): Last reviewed commit: "address pr review feedback" | Re-trigger Greptile |
dustinbyrne
reviewed
Jun 18, 2026
ioannisj
approved these changes
Jun 19, 2026
ioannisj
left a comment
There was a problem hiding this comment.
LG, tried to follow the logic as close as possible and seems correct
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
💡 Motivation and Context
QueueConsumer::flush()removed a batch from the in-memory queue before sending it. When the send failed due to a transient network or timeout failure, those events were lost even though retrying later could succeed.This change keeps batches queued for retryable transport failures while still dropping non-retryable failures so a permanently bad batch does not block later events.
💚 How did you test it?
vendor/bin/phpcs lib/QueueConsumer.php lib/Consumer/LibCurl.php lib/Consumer/Socket.php lib/Consumer/ForkCurl.php lib/HttpClient.php test/QueueConsumerTest.php test/QueueConsumerTestConsumer.php test/MockedHttpClient.phpvendor/bin/phpunit --no-coverage test/QueueConsumerTest.phpcomposer api:checkvendor/bin/phpunit --no-coverage📝 Checklist
If releasing new changes
pnpm changesetto generate a changeset file🤖 Agent context
Autonomy: Human-driven (agent-assisted)
The implementation was authored with pi. The chosen approach introduces internal flush failure classifications so queue consumers can keep events only for retryable network/timeout failures and continue dropping non-retryable batches such as oversized payloads, compression failures, retry exhaustion, and non-200 responses.
For PHP specifically, the batch HTTP client keeps its narrower retry policy instead of retrying every non-2xx/3xx response. PHP sends synchronously in the hosting app request path, so broad retries could slow down the host application; 413 payload-too-large is also not retried. Review feedback was addressed by simplifying the retry branch and parameterizing repeated LibCurl queue behavior tests.