Skip to content

fix: drop only unserializable events instead of the whole batch - #514

Closed
pcbeingused33 wants to merge 1 commit into
launchdarkly:mainfrom
pcbeingused33:fix/unserializable-event-batch
Closed

pcbeingused33 wants to merge 1 commit into
launchdarkly:mainfrom
pcbeingused33:fix/unserializable-event-batch

Conversation

@pcbeingused33

@pcbeingused33 pcbeingused33 commented Nov 30, 2026 •

Copy link
Copy Markdown
Contributor

Requirements

  • I have added test coverage for new or changed functionality
  • I have followed the repository's pull request submission guidelines
  • I have validated my changes against all supported platform versions (specs run on Ruby 4.0 and 3.4; Ruby 3.2 and JRuby not run locally)

Related issues

No issue in this repository. Follow-up to #498, which covered a non-finite metric_value; the same failure remains for event data.

Describe the solution you've provided

One event with unserializable content (for example track data containing a nested Float::NAN, or a string that is not valid UTF-8) discards the whole analytics batch. events_out.to_json raises inside the flush worker after trigger_flush has already cleared the outbox, so the other events and the summary are lost.

When serializing the batch fails, the flush worker now drops only the events that cannot be serialized, logs a warning for each, and sends the rest. Batches that serialize normally take the same path as before, so data is not inspected on every track call.

Two specs in spec/events_spec.rb (nested NaN and invalid UTF-8 in data) record a healthy event next to a bad one and check that only the healthy one is delivered. Both fail without the change and pass with it; RuboCop reports no offenses on the two changed files.

Reproduction:

bundle exec rspec spec/events_spec.rb -e "without losing other events"

Describe alternatives you've considered

Additional context

AI assistance was used to prepare the patch and regression tests.


Note

Overview
Fixes analytics batch loss when one custom event has unserializable data. Previously, a failed events_out.to_json in the flush worker could drop the entire batch after the outbox was already cleared—even though other events were valid.

On batch serialization failure, the flush path now runs drop_unserializable_events, which keeps only events that serialize individually, logs a warning per dropped event, and sends the remaining payload. The happy path is unchanged (no per-track validation).

Tests add coverage for bad custom data (nested Float::NAN and invalid UTF-8) alongside a healthy event, asserting only the good event is delivered—complementing the existing non-finite metric_value handling at record time.

Reviewed by Cursor Bugbot for commit 18f4bf2. Bugbot is set up for automated code reviews on this repo. Configure here.

@pcbeingused33
pcbeingused33 requested a review from a team as a code owner November 30, 2026 17:02
@keelerm84

Copy link
Copy Markdown
Member

Thanks for the detailed write-up and the regression specs. The repro made this easy to evaluate.

We discussed this as a team and have decided not to take this change. We do want to drop only the bad events instead of the whole payload. Doing that well needs a broader change to how the flush path builds the payload, and we would rather design that properly than add a second encoding pass. Re-encoding also has its own failure modes. For example, an event can pass the per-event check and still fail when the batch is encoded again, and then the whole batch is lost anyway.

For now, we plan to keep the current behavior along with the metric_value check from #498. We also don't want to validate data on every track call, because walking nested values on the caller's thread costs too much for a rare case.

We'll close this for now. Thanks again for raising it.

@keelerm84 keelerm84 closed this Dec 1, 2026
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