Repository navigation
feat: Retry event delivery and flush on close - #158
Conversation
Its entry in Flagsmith/sdk-spec's compatibility matrix at v0.9.0: `core events local-evaluation`.
|
Important Review skippedBot user detected. To trigger a single review, invoke the
|
Implement Flagsmith SDK spec v0.9.0. - Retry transient failures of the events API (connection errors, timeouts, 408, 429, 5xx) up to 3 attempts, backing off from 1 second with full jitter, and time out each request after 3 seconds. - Keep a batch that keeps failing for the next flush, ahead of newer events, unless its last attempt got a 500. Drop a rejected batch, and stop tracking events on 401 or 403. - Drop the oldest event when the buffer is full, instead of flushing. - Add `Flagsmith::close()`, which flushes within a timeout and stops tracking events. - Evaluate experiments locally: carry the experiment in the environment document's feature state metadata, and the variant key, into identity flags, so `getExperimentFlag` records exposures under local evaluation. - Wire the new spec steps, and the client with both local evaluation and events. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
Implemented spec v0.9.0 in 7a3c366. CI failed because the SDK lacked the new steps ( Event delivery (
Local evaluation of experiments
Tests
A limitation of the PHP steps: the single-event track steps still flush right after tracking, as before. The harness's process never ends a PHP request, so without that flush the older scenarios that track an event and then check Flagsmith would never see it. This means that in the close scenarios the events are already sent before |
Building an `Experiment` from every identity flag's metadata slowed down `getIdentityFlags` under local evaluation by about 10%. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
The spec check passed on 7a3c366, but CodSpeed flagged a 10–14% regression in four |
Zaimwa9
left a comment
There was a problem hiding this comment.
Requesting changes. Spec passes, but the full retry loop now runs in __destruct, so during an events API outage every request that tracked an event is delayed by seconds. The 3 s timeout also only applies with Guzzle.
- Make a single attempt when the processor is destroyed, the flush interval has elapsed, or the buffer is full, so that an events API outage holds up an application's request by at most one request timeout. `flush()` and `close()` still retry. - Flush a full buffer when an event is tracked into it, as before, unless it holds a batch that failed to send: only then drop its oldest event. - Time out requests through Symfony's `Psr18Client` (6.2 and later) too, not only through Guzzle. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Thanks. All three points are addressed in d61010c, with details on each inline thread:
Lint is clean and the 359 unit tests pass on PHP 8.4 and 8.1. CI runs the spec on this push. |
|
@themis-blindfold review |
⚖️ Themis review: 🟠 Fix before mergeEvent delivery gains retries and an explicit shutdown path, but the retry policy handles server responses outside the specified set and the shutdown deadline is not enforced for all supported HTTP clients. The captured CI checks passed, including the SDK specification and PHP-version test jobs.
🟠 Majors
📝 Walkthrough
🧪 How to verify
Product take: Reliable event delivery and bounded shutdown matter for experiment data and application latency; this is a substantial SDK improvement once those guarantees hold across clients. 🧭 Assumptions & unverified claimsNo unverified assumptions or claims. PHP was unavailable in the review environment, so the tests were not rerun locally. May the events arrive before closing time · reviewed at d61010c |
Retry 408, 429, 500, 502, 503 and 504, and drop a batch on any other status at once, such as 501 or 505, instead of retrying every 5xx and keeping the batch. Document that `close()` cannot cut short a request already sent through an HTTP client it cannot give a timeout. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Themis raised two majors. Both are answered on their threads, and aff1621 has the changes:
Fixed for 501, 505 and other unlisted statuses: only 408, 429, 500, 502, 503 and 504 are retried now, and any other status drops the batch on the first attempt. 500 is still retried, because spec v0.9.0 changed sdk-spec#23's original "drop on 500" rule (Flagsmith/sdk-spec#24), and its
PSR-18 cannot pass a timeout, so a request already sent through a client other than Guzzle or Symfony 6.2+ can outlast the deadline. No retry or backoff starts after it, and a new test checks that with a plain PSR-18 client. The Lint is clean and the 364 unit tests pass on PHP 8.4 and 8.1. |
🤖 I have created a release *beep* *boop* --- ## [5.4.0](v5.3.0...v5.4.0) (2026-11-13) ### Features * Retry event delivery and flush on close ([#158](#158)) ([989290a](989290a)) --- This PR was generated with [Release Please](https://github.com/googleapis/release-please). See [documentation](https://github.com/googleapis/release-please#release-please). <!-- This is an auto-generated description by cubic. --> --- ## Summary by cubic Releases v5.4.0 of the `flagsmith/flagsmith-php-client` package. Includes retry logic for event delivery and flushing events on close. <sup>Written for commit b4d0c10. Summary will update on new commits.</sup> <a href="https://cubic.dev/pr/Flagsmith/flagsmith-php-client/pull/159?utm_source=github" target="_blank" rel="noopener noreferrer" data-no-image-dialog="true"><picture><source media="(prefers-color-scheme: dark)" srcset="https://www.cubic.dev/buttons/review-in-cubic-dark.svg"><source media="(prefers-color-scheme: light)" srcset="https://www.cubic.dev/buttons/review-in-cubic-light.svg"><img alt="View guided diff" src="https://www.cubic.dev/buttons/review-in-cubic-light.svg"></picture></a> <a href="https://www.cubic.dev/action/auto-fix/pr/Flagsmith/flagsmith-php-client/159?returnTo=https%3A%2F%2Fgithub.com%2FFlagsmith%2Fflagsmith-php-client%2Fpull%2F159&source=description" target="_blank" rel="noopener noreferrer" data-no-image-dialog="true"><picture><source media="(prefers-color-scheme: dark)" srcset="https://www.cubic.dev/buttons/turn-on-auto-fix-dark.svg"><source media="(prefers-color-scheme: light)" srcset="https://www.cubic.dev/buttons/turn-on-auto-fix-light.svg"><img alt="Turn on auto-fix" src="https://www.cubic.dev/buttons/turn-on-auto-fix-light.svg"></picture></a> <!-- End of auto-generated description by cubic. -->
Contributes to Flagsmith/sdk-spec#23