Skip to content

feat(events): summarize and buffer events on the recording thread (tier 1) - #397

Merged
abelonogov-ld merged 46 commits into
mainfrom
andrey/event-durability-tier1-buffer
Nov 21, 2026
Merged

abelonogov-ld merged 46 commits into
mainfrom
andrey/event-durability-tier1-buffer

Conversation

@abelonogov-ld

@abelonogov-ld abelonogov-ld commented Sep 18, 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

Related issues

Fixes #281. DefaultEventProcessor.close() waited with no limit for its final flush, which on a slow network blocked the calling thread long enough to trigger an ANR. DirectEventProcessor.close() waits at most two seconds for that delivery and then lets it finish in the background.

Tier 1 of the Event Durability spec, "Tier 1 — the buffer". Tier 2 is stacked on this branch as #403; tier 3 will follow.

Describe the solution you've provided

DirectEventProcessor takes over from java-sdk-internal's DefaultEventProcessor in ComponentsImpl, and OutboundEventBuffer replaces the bounded queue that used to sit between the calling thread and the summarizer.

That queue is the problem this tier removes. An evaluation handed its event to an ArrayBlockingQueue and a dispatcher thread summarized it on the far side, so a burst of evaluations of untracked flags could fill the queue and displace the track and identify events an application actually asked to send. Summarizing on the recording thread means an evaluation of an untracked flag costs a counter increment and can never displace anything, because it never occupies a slot in the first place.

OutboundEventBuffer holds in full only the events that have to be sent one by one. It reuses java-sdk-internal's EventOutputFormatter and summarizer implementations rather than reimplementing them, so there stays exactly one definition of what an event looks like on the wire.

Two smaller changes ride along, both prerequisites rather than additions:

  • java-sdk-internal moves to 1.12.0, which makes the summarizer and formatter types public so the buffer can use them from its own package.
  • Diagnostic events are no longer sent while the SDK is offline or the application is backgrounded.

Describe alternatives you've considered

Reuse DefaultEventProcessor and raise its queue capacity. This moves the threshold without removing it. The displacement is a property of having a bounded handoff between the caller and the summarizer at all, and a render loop re-evaluating a tracked flag will reach any capacity you pick.

Keep the buffer inside java-sdk-internal's package to reach its package-private types. This worked, but it relied on a split package, which breaks Java modules and needed a Javadoc exclusion to build at all. Making the types public upstream was the durable fix, and is why the dependency bump is here.

Additional context

Naming. DirectEventProcessor and OutboundEventBuffer rather than an Android prefix: that prefix in this package is reserved for adapters over Android OS APIs, such as AndroidPlatformState and AndroidTaskExecutor, and neither of these classes touches one. "Direct" names the contrast with DefaultEventProcessor — nothing sits between the caller and the summarizer. DefaultEventProcessor was unavailable as a name because java-sdk-internal already exports it and this package imports from it.

Tests. DirectEventProcessorTest, EventProcessorBufferingTest and EventProcessorPrivacyTest share an EventProcessorTestBase, adding 22 tests across buffering, capacity, private-attribute redaction and diagnostics. The full unit suite is 752 tests, all passing locally.

Platform validation. The requirements box above is left unchecked deliberately. Behaviour is covered by the unit suite, but performance was measured on one physical device rather than across the supported API range.

Example app. Gains an "Eval+track+kill" button that evaluates a flag, tracks an event, flushes, and then kills the process five seconds later. That is the reproduction for the loss this work addresses, and it still loses the events on this tier — tier 3 is what makes them survive. Its LDClient.init call also moves off the deprecated three-argument overload.


Note

Overview
Replaces the SDK’s java-sdk-internal DefaultEventProcessor wrapper with DirectEventProcessor and OutboundEventBuffer, so flag evaluations are summarized on the calling thread and event-buffer capacity applies only to full-fidelity events (track/identify/custom/feature), avoiding bursts of untracked evaluations crowding out events an app asked to send.

DirectEventProcessor handles flush scheduling, offline/background behavior (including no diagnostic posts while offline or backgrounded), atomic record/flush handoff, bounded close() (2s wait then background finish), and a dedicated diagnostics posting thread separate from analytics delivery. OutboundEventBuffer reuses internal summarizers/formatters for wire-compatible payloads and bounds per-context summary cardinality.

Config/docs tweaks: capacity below 1 is clamped to 1, diagnostics report the effective capacity, and EventProcessor.close() is documented as discarding buffered events when offline. LDClient.init(..., timeout) replaces Future-based waiting in the sample MainActivity; dexcount moves off example to a new :test-app QA harness (including Eval+track+kill for event-loss reproduction).

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

abelonogov-ld and others added 8 commits September 9, 2026 11:58
…er 1)

Tier 1 of the event durability spec: the buffer.

AndroidEventBuffer folds an evaluation into summary counters as it is recorded
and holds in full only the events that have to be sent one by one, so a burst of
evaluations of untracked flags cannot displace anything. AndroidEventProcessor
takes over from java-sdk-internal's DefaultEventProcessor in ComponentsImpl,
removing the bounded queue that used to sit between the calling thread and the
summarizer.

Spec: Event Durability, "Tier 1 — the buffer".
Co-authored-by: Cursor <[email protected]>
The next commit drops the split-package hack in favor of declarations that
launchdarkly/java-core#214 makes public. That is not in a release yet, so this
points the build at a working copy until one carries it.

Skipped when the directory is absent, so a clean checkout still resolves the
published artifact rather than failing. Revert together with a version bump once
the release is out.

Co-authored-by: Cursor <[email protected]>
…package

AndroidEventBuffer was declared in com.launchdarkly.sdk.internal.events so it
could reach the summarizers and the output formatter, which were package-private
there. That made a package split across two artifacts, forced the class to be
public for the rest of the SDK to use it, and needed a javadoc exclusion plus a
classpath workaround to keep it out of the published docs.

launchdarkly/java-core#214 makes those declarations public, so the class moves to
com.launchdarkly.sdk.android where it belongs. It is package-private now, along
with its members and Payload, because everything using it is in that package, so
it is out of the published docs by virtue of its visibility rather than by being
excluded from javadoc. The build.gradle javadoc block goes back to what it was
before tier 1.

No behavior change: same summarization, same wire format, same tests.

Co-authored-by: Cursor <[email protected]>
Diagnostics are meant to be off in both states, and updateScheduledTasks cancels
the periodic task accordingly, but two paths could still reach the sender after
the state had changed. Cancelling does not stop a run that has already begun, and
the init event is submitted to the executor while still online, so going offline
or backgrounding between submission and execution left it to send anyway.

Both paths now re-check on the way out, via a predicate that mirrors the
scheduling condition so the two cannot drift. The check in sendDiagnosticStats
sits ahead of createEventAndReset, which clears the counters it returns, so a
suspended period defers its statistics rather than discarding them.

Analytics delivery is unchanged: deliverPayload already skips while offline, and
it deliberately keeps running in the background so events recorded before the app
was backgrounded still get out.

Co-authored-by: Cursor <[email protected]>
The Android prefix in this package is reserved for adapters over Android OS APIs
- AndroidPlatformState, AndroidTaskExecutor, AndroidEnvironmentReporter. Neither
of these touches an Android API, so the prefix put them in the wrong category
while also repeating what the repository and package already say.

  AndroidEventProcessor -> DirectEventProcessor
  AndroidEventBuffer    -> OutboundEventBuffer

DirectEventProcessor names what sets it apart from java-sdk-internal's
DefaultEventProcessor: nothing sits between the caller and the summarizer.
OutboundEventBuffer says which direction the events are going, which matters
once tier 3 adds a store to read them back from.

DefaultEventProcessor was avoided as a name because java-sdk-internal already
exports that simple name and this package imports from it.

Rename only, including the test class. No behavior change.

Co-authored-by: Cursor <[email protected]>
- drop OutboundEventBuffer.isEmpty, which nothing calls
- StandardCharsets.UTF_8 in place of Charset.forName("UTF-8")
- scheduleWithFixedDelay, so a cached process does not come back owing every missed run
- split an over-long Javadoc sentence

Co-authored-by: Cursor <[email protected]>
(cherry picked from commit 123cb81)
@abelonogov-ld
abelonogov-ld requested a review from a team as a code owner September 18, 2026 17:23
@abelonogov-ld abelonogov-ld mentioned this pull request Sep 18, 2026
1 of 3 tasks
abelonogov-ld added a commit that referenced this pull request Sep 18, 2026
**Requirements**

- [ ] I have added test coverage for new or changed functionality —
workflow-only change
- [x] I have followed the repository's pull request submission
guidelines
- [ ] I have validated my changes against all supported platform
versions — CI will validate the configured API level

**Related issues**

Unblocks
[#397](#397). Its
CI fails during Android SDK setup.

**Describe the solution you've provided**

Upgrade `android-actions/setup-android` from v3 to v4. Licenses are
already accepted successfully; the failure happens afterward because v3
invokes `sdkmanager tools`, and Google no longer publishes that obsolete
package. Version 4 removes `tools` from its default package list while
continuing to install command-line/platform tools and accept SDK
licenses.

**Describe alternatives you've considered**

Retrying cannot fix a package removed from Google's repository. Adding a
separate license-acceptance step would duplicate behavior and would not
address the failing `sdkmanager tools` invocation inside v3.

**Additional context**

Observed error: `Warning: Failed to find package 'tools'`. The upstream
v4 change explicitly fixes this failure.

<!-- CURSOR_SUMMARY -->
---

> [!NOTE]
> **Overview**
> **Fixes CI Android SDK setup** by upgrading the shared composite CI
action from `android-actions/setup-android@v3` to **v4.0.4** (pinned to
commit `be39fa834029ff78f1a44aa3bb0819b8fc2bd8fd`).
> 
> v3 fails after license acceptance because it still runs `sdkmanager
tools`, a package Google removed from the repository (`Failed to find
package 'tools'`). v4 stops requesting that obsolete package while still
installing the command-line/platform tooling needed for `./gradlew`
builds and the rest of the workflow.
> 
> <sup>Reviewed by [Cursor Bugbot](https://cursor.com/bugbot) for commit
d6a3b7e. Bugbot is set up for automated
code reviews on this repo. Configure
[here](https://www.cursor.com/dashboard/bugbot).</sup>
<!-- /CURSOR_SUMMARY -->

@cursor cursor Bot left a comment •

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Stale Bugbot comment from a previous run.

abelonogov-ld and others added 3 commits September 18, 2026 15:55
Bugbot flagged that diagnosticInitSent is set without consulting the
Result. That is deliberate: DefaultEventProcessor does the same, and a
failed post returns an unsuccessful Result rather than throwing, so the
flag flips either way. Note it at the assignment so the next reader does
not read it as an oversight.

Co-authored-by: Cursor <[email protected]>
Going offline cancels the periodic flush, so coming back online started a
fresh interval and left whatever the outage buffered waiting for it. Each
drop re-anchored that interval, so repeated brief losses could defer
delivery well past a single one.

Co-authored-by: Cursor <[email protected]>
java-sdk-internal's DefaultEventProcessor, which this path replaced,
skipped the summary counter for an event marked excludeFromSummaries.
OutboundEventBuffer.summarize counted unconditionally, so that flag was
the one thing the replacement did not carry over; addFullEvent already
honoured the sampling ratio, which is the sibling flag on the same
object.

Nothing observable changes today. DirectEventProcessor builds its
feature events through the constructor overload that fixes both
samplingRatio at 1 and excludeFromSummaries at false, so neither guard
can fire through the SDK's own recording path. The point is that the two
are defaulted by the same overload and would go live together: anything
that moves to the fourteen-argument constructor, which adopting sampling
requires, arms both at once. The failure mode is silent and arrives as
wrong analytics rather than as an error, since an event carries its
sampling ratio on the wire for the receiver to scale by.

The guard goes in the buffer rather than in the processor because the
buffer is where an event arrives from outside. A check in the processor
would sit three lines below the constructor call that hardcodes the
value, could never fire, and would read as dead. In the buffer it is
reachable, and OutboundEventBufferFlagsTest now covers both flags --
including sampling, which had no coverage at all.

Co-authored-by: Cursor <[email protected]>

@tanderson-ld tanderson-ld left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

This went through a multi-perspective review (general / security / adversarial), with the java-sdk-internal 1.12.0 sources as the comparison baseline. The design fundamentals held up well under adversarial scrutiny — summarizer locking, capacity enforcement under concurrency, deadlock-freedom, diagnostics state transitions, and wire-format/privacy parity were all attacked and survived — but two proven error-path regressions versus DefaultEventProcessor need fixing before this merges, and a third cluster ties into an open field issue. Inline comments mark the specific spots; summary of the findings below.

Blocking

  1. A single unserializable event permanently wedges all analytics delivery. OutboundEventBuffer.drain() restores the summarizer and never clears events when serialization fails, so a deterministic failure re-fails every subsequent flush — periodic, manual, and close()'s final delivery — while the buffer saturates and silently drops all new identify/track events and the restored summaries grow without bound. Reachable from the public API today: trackMetric(..., Double.NaN) (no finiteness check on the path; Gson's strict writer rejects it) and boolVariation(null, ...) from Java (null key poisons the summarizer itself). DefaultEventProcessor cleared the outbox before serializing: it lost one batch and recovered on the next flush. Every failure this catch block can see is deterministic (a BAOS-backed writer can't fail transiently), so the restore can only ever produce a permanent wedge — suggest discard-with-loud-log on serialization failure, or per-event quarantine. A failing regression test is available (ProofPoisonedBufferRecoveryTest).

  2. An Error during a scheduled run silently and permanently stops all flushing. guarded() catches Exception, not Throwable; an Error escaping a periodic run (realistic: StackOverflowError from deeply nested LDValue data, OutOfMemoryError growing the payload stream) makes the executor cancel the task with nothing logged, and enableOrDisableTask returns the dead-but-non-null future forever, so no state transition revives it. DefaultEventProcessor installed an uncaught-exception handler that logged loudly and shut down in an orderly way; there's no counterpart here. Suggest catch (Throwable) in guarded() plus replacing a future whose isDone() is true. Failing regression test available (ProofFlushTaskSurvivesErrorTest).

  3. close() blocking and teardown — this is #281's failure mode, inherited and extended. delivery.get() is unbounded, and because all sends now share the single scheduler thread, close's delivery can wait FIFO behind an in-flight send and a queued diagnostic POST: ~3 failed sends ≈ 2 minutes at default timeouts, versus ~82 s for the old close (which never waited on diagnostics). Issue #281 is exactly this ANR shape on the current release line (main thread parked in postMessageAndWait under LDClient.close()). Separately, scheduler.shutdown() → eventSender.close() doesn't quiesce the executor: shutdown() lets queued tasks run, so a delivery enqueued by a racing setOffline(false) (its submit doesn't re-check closed), or a still-running delivery abandoned by an interrupted wait, executes against the closed sender. Suggested as one change: bounded get(timeout) with a logged give-up, shutdownNow() + bounded awaitTermination() before eventSender.close(), and a closed re-check before the setOffline catch-up submit. (Note: timed get everywhere — untimed get on a task discarded by shutdownNow() hangs forever.) With tier 3 durability this wait stops being load-bearing entirely; bounding it now would let this work close out #281 rather than carry it forward.

Strongly recommended

  1. Serialization runs inside the monitor every evaluation contends on. drain() holds the buffer lock across the full JSON encode (logger.warn on the drop path is under it too), so recording threads — often the main thread — block behind a flush's encoding: measured ~22 ms cold for 100 events, and the work scales with accumulated summary contexts, not capacity. Fix carefully: the wide lock is what makes the failure path atomic today (restoreTo replaces rather than merges), so snapshot-under-lock/encode-outside needs a merging restore upstream first.

  2. capacity no longer bounds event-subsystem memory. The per-context summarizer is unbounded (one entry per distinct context, full attributes retained) and grows from construction while initiallyOffline. Pre-existing in degree, but the inbox backpressure that used to shed bursts is gone, and finding 1 turns "bounded by outage duration" into "bounded by process lifetime." Cap it (counting overflow into droppedEventCount) or state explicitly that a later tier owns it.

  3. An evaluation's summary/full/debug writes are three separate lock acquisitions. A flush can interleave between them (summary in payload N, feature event in N+1), and a close() interleaving can deliver the summary while silently stranding the feature event. One buffer.record(event, requireFullEvent, debugEvent) call restores the atomicity the old single-dispatcher design had, and cuts hot-path lock traffic 3×.

  4. A diagnostics period can be destroyed in exactly the way the comment says it can't. sendDiagnosticStats checks suspension, then destructively reads (getAndClearDroppedCount, createEventAndReset), then sendDiagnosticEvent re-checks suspension and can drop the built event — an offline/background transition in that window discards the period's stats and skews dataSinceDate. Drop the inner re-check for the stats path or re-inject on suppression.

  5. capacity(0) now silently drops every full-fidelity event. The >= 0 ? capacity : 1 normalization is copied from EventsConfiguration (whose javadoc says zero-or-negative → 1), but on main new ArrayBlockingQueue<>(0) crashed init loudly, masking the off-by-one; that mask is gone with the inbox. Use > 0, and consider a builder-level floor.

  6. Test gaps sit in precisely the new risk areas. diagnosticInitEventIsSentWhenComingOnline's only-one-init assertion never exercises the guard (the fixture makes setInBackground(false) a no-op transition); diagnosticInitEventIsNotSentWhileOffline waits for the init to be delivered before going offline; no test flushes concurrently with recording (the one race this design introduces, and the regression test a future lock-narrowing needs); and the injectable constructor is never used, leaving 401/mustShutDown, dropped-count-to-diagnostics accounting, and periodic stats uncovered. The two Proof* tests above are written as regression tests (they pass once 1 and 2 are fixed) and are available to include.

Worth stating what's good here too: privacy redaction is byte-for-byte parity with genuinely thorough new tests; capacity accounting, sampling, debug-event TTL, and wire ordering all verified equivalent; close() fixes a scheduler-thread leak the old wiring had on every init/close cycle; and blockingFlush() now actually matches its documented semantics.

abelonogov-ld and others added 12 commits September 21, 2026 14:47
…/sdk/android/DirectEventProcessor.java

Co-authored-by: Todd Anderson <[email protected]>
Recording an event and encoding a batch of them were sharing one monitor.
Encoding is the dominant cost on the path and runs on the events executor;
recording runs on whichever thread evaluated a flag, which on Android is
usually the main one. An evaluation could therefore wait out a whole batch
encode before it was allowed to add a counter.

The list of full events, the capacity counted against it and the drop count
move to DirectEventProcessor. A delivery takes the run under pendingLock and
encodes it after releasing, so a recording thread waits only for another
thread's memory operation. OutboundEventBuffer keeps the counters and the wire
format, and takes the summaries under its own lock for the same reason.

A run that cannot be serialized is now discarded rather than put back. Nothing
the encoder can fail on is transient -- it writes to a byte array -- so a
restored run would have failed again on every later flush and no events would
ever have been delivered again.

EventProcessorTestBase now waits out the delivery that coming online schedules.
It was previously free to land in the middle of a test's recording loop and
take a batch the test had not asked to send, which at capacity reads as the
limit having been exceeded.

Co-authored-by: Cursor <[email protected]>
Nothing in it logs any more. The capacity warning went to the processor with
the capacity check, and a failed encode is thrown to the caller rather than
reported here.

Co-authored-by: Cursor <[email protected]>
* main:
  test(fdv2): stop requiring a changeset to be the first result
abelonogov-ld and others added 3 commits September 22, 2026 15:44
…ing the server

describeConfiguration was sending the raw capacity, so a client configured with
nought told the service nought while running at one. It now shares the one
normalization with the buffer and the processor.

The race test was flaking about one run in six. Not the processor: the test
server records a request body with a single unlooped read, so a body past one
socket read's worth comes back truncated, at a point that moves between runs.
Thirty events instead of a hundred and fifty stays clear of it, and the test
still fails on every un-fixed run.

Co-authored-by: Cursor <[email protected]>
Three components bound themselves by this number and each was normalizing it,
or not. Clamping in the setter makes the field valid by construction, which is
what the sibling setter for the diagnostic interval already does, and leaves
every consumer -- the buffer, the processor, the diagnostic description -- to
just use it.

Co-authored-by: Cursor <[email protected]>
The two init tests asserted nothing. One asked a foreground processor to go to
the foreground, which setInBackground returns from before reaching any decision;
the other waited for the init event before going offline, so the only thing
stopping a second one was that the first had already gone. Each was held up by
the guard the other claimed to cover, and both passed with every guard deleted.

Coming to the foreground now goes through the background first, and waits for
the diagnostics thread to come free -- while the first init is still posting,
the claim is taken and the transition is turned away before it decides anything.
The offline one builds a processor that never comes online, then brings it
online to show the silence was the offline state and not a dead fixture.

Two new ones. A must-shut-down response has to stop recording and delivery for
good, which nothing exercised. And a flush running against four recorders has to
keep each evaluation in one payload: close() delivers once, so it can catch an
evaluation being stranded but never one being split across two deliveries.
Eight trials, because a single one catches a split lock about two times in three.

Co-authored-by: Cursor <[email protected]>

@cursor cursor Bot left a comment •

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Stale Bugbot comment from a previous run.

abelonogov-ld and others added 4 commits September 22, 2026 17:24
The MalformedJsonException in aContextAlreadyBeingCountedKeepsCountingOnceTheLimitIsReached
is not a serialization race: recording is sequential on the test thread and the payload is a
deterministic ~28 KB. The test-helpers HTTP server reads request bodies with a single unlooped
read, so larger bodies can be truncated depending on the machine. Fill the summarizer to a
limit of 10 contexts instead of 100 so each flush stays well under that size.

Co-authored-by: Cursor <[email protected]>
Offline means the application told the SDK to stay off the network, and closing does not revoke
that, so the final delivery in close() is skipped and held events are dropped. DefaultEventProcessor
behaved the same way (its FLUSH is a no-op while offline); the comments and the EventProcessor
javadoc promised more than either implementation did. Add a test pinning the behavior.

Co-authored-by: Cursor <[email protected]>
…n reconnect

The SDK builds the event processor offline and turns it on once initialization is done. Coming online
used to deliver immediately, meant for the end of an outage, but it also fired on that first transition
at startup and sent the initial identify alone before anything else was recorded. DefaultEventProcessor
never did that, and the contract tests expect the first payload to wait for a flush.

The immediate delivery existed only because cancelling the periodic flush for an outage restarted its
interval on every reconnect. The flush task now stays scheduled regardless of the offline state (a run
while offline does nothing), so the interval is never restarted and what an outage buffered goes out at
the first run after it ends. No transition needs special handling.

Co-authored-by: Cursor <[email protected]>
updateScheduledTasks no longer returns early once the processor is
closed. The closed flag now gates only starting work, so cancelling
always happens, and close() cancels its tasks by calling
updateScheduledTasks under stateLock instead of repeating the cancel
calls itself.

Co-authored-by: Cursor <[email protected]>
abelonogov-ld and others added 2 commits September 22, 2026 22:39
- Wrap recordEvaluationEvent, recordIdentifyEvent, recordCustomEvent, and
  record in try/catch to ensure unexpected telemetry failures never crash
  user application calls.
- Reset summaryContextsExceeded when taking summaries during a flush run so
  subsequent runs that exceed the context limit log the warning.
- Add unit tests confirming both behaviors.

Co-authored-by: Cursor <[email protected]>
- Catch RuntimeException rather than Throwable on the recording path.
  It runs on the application's thread, so an Error such as
  OutOfMemoryError now propagates to the application's crash reporting
  instead of being logged and swallowed.
- Drop the outer try in recordIdentifyEvent and recordCustomEvent;
  record() already handles its own failures.
- Claim the context-limit warning under recordLock, the lock the
  delivery resets it under. Claimed outside it, a delivery landing in
  between let one run's overflow suppress the next run's warning.
- Add a test that an Error while recording reaches the caller.

Co-authored-by: Cursor <[email protected]>
abelonogov-ld and others added 3 commits September 28, 2026 11:34
1.12.1 no longer calls Map.computeIfAbsent in PerContextEventSummarizer, which
threw NoClassDefFoundError on Android below API 24.

Co-authored-by: Cursor <[email protected]>

@tanderson-ld tanderson-ld left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

A tier-1 pass against the event-durability spec's §4–7 (done while reviewing #403) turned up one behavioral gap and two doc drifts — inline below — plus test gaps worth closing while this is fresh:

  • Nothing pins serialize-at-the-drain. No test fails today if a change moves an encode onto the recording path, and none asserts that an event refused for capacity is never encoded. Those are the two claims this tier is built around. A test-only entry counter / thread capture on the encoder makes both one-line assertions.
  • The in-flight-run reservation (inline comment on the drain) will want a test once it lands: block the encoder mid-drain, fill the buffer, record one more event, assert it is dropped and counted.

Cross-SDK note: the iOS tier-1 branch shares the in-flight-run gap, and it has no summarizer-entry bound at all — this branch is ahead on both counts, so whatever lands here is worth mirroring there.

@cursor cursor Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Cursor Bugbot has reviewed your changes using default effort and found 1 potential issue.

Fix All in Cursor

❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, have a team admin enable autofix in the Cursor dashboard.

Reviewed by Cursor Bugbot for commit 1f5631c. Configure here.

…te names as references (#415)

**Requirements**

- [x] I have added test coverage for new or changed functionality
- [x] I have followed the repository's [pull request submission
guidelines](../blob/main/CONTRIBUTING.md#submitting-pull-requests)
- [ ] I have validated my changes against all supported platform
versions

**Related issues**

Stacked on `andrey/event-durability-tier1-buffer`, which moved
java-sdk-internal to 1.12.1.

Picks up
[java-core#228](launchdarkly/java-core#228),
released in java-sdk-internal 1.12.2. The iOS counterpart is
[ios-client-sdk#544](launchdarkly/ios-client-sdk#544).

**Describe the solution you've provided**

`_meta.redactedAttributes` is a list of attribute references. When every
attribute is private (`allAttributesPrivate`, or an anonymous context in
a feature event), java-sdk-internal 1.12.1 listed each attribute's raw
name. A name that starts with a slash, such as `/ssn`, reads back as the
path to an attribute named `ssn`, so the list named an attribute other
than the one that was removed. 1.12.2 lists
`AttributeRef.fromLiteral(name).toString()` instead: `/~1ssn` for that
name, and the name itself for any name without a leading slash. The Go
and JavaScript SDKs write the same form.

1.12.2 contains only that fix. Both `launchdarkly-android-client-sdk`
and `shared-test-code` move to it.


`EventProcessorPrivacyTest.allAttributesPrivateReportsEachNameAsTheReferenceThatNamesIt`
checks the posted payload for attributes named `/ssn`, `/a~b` and `c/d`.
It expects `/~1ssn`, `/~1a~0b` and `c/d`, and fails on 1.12.1 with
`[/a~b, /ssn, c/d]`.

**Describe alternatives you've considered**

None. The redaction is java-sdk-internal's, which the event processor
reuses through `OutboundEventBuffer`.

**Additional context**

Event output only, and only for attribute names that start with a slash.

<!-- CURSOR_SUMMARY -->
---

> [!NOTE]
> **Overview**
> Bumps **`launchdarkly-java-sdk-internal`** from **1.12.1** to
**1.12.2** in `launchdarkly-android-client-sdk` and `shared-test-code`,
picking up the fix where **`_meta.redactedAttributes`** uses proper
**attribute references** when every attribute is private
(`allAttributesPrivate`).
> 
> With **1.12.1**, literal names starting with `/` (e.g. `/ssn`) were
listed as raw strings, which could be misread as paths to different
attributes; **1.12.2** reports the encoded refs (e.g. `/~1ssn`,
`/~1a~0b`) while ordinary names like `c/d` stay unchanged.
> 
> Adds
**`EventProcessorPrivacyTest.allAttributesPrivateReportsEachNameAsTheReferenceThatNamesIt`**
to assert the posted identify payload matches that behavior on the wire.
> 
> <sup>Reviewed by [Cursor Bugbot](https://cursor.com/bugbot) for commit
1737441. Bugbot is set up for automated
code reviews on this repo. Configure
[here](https://www.cursor.com/dashboard/bugbot).</sup>
<!-- /CURSOR_SUMMARY -->

Co-authored-by: Cursor <[email protected]>
@abelonogov-ld
abelonogov-ld added this pull request to stack #441 November 21, 2026 00:12
@abelonogov-ld
abelonogov-ld removed this pull request from stack #441 November 21, 2026 00:14
…ty-tier1-buffer

Co-authored-by: Cursor <[email protected]>

# Conflicts:
#	launchdarkly-android-client-sdk/build.gradle
#	launchdarkly-android-client-sdk/src/main/java/com/launchdarkly/sdk/android/ComponentsImpl.java
#	shared-test-code/build.gradle
@abelonogov-ld
abelonogov-ld added this pull request to stack #443 November 21, 2026 01:01
@abelonogov-ld
abelonogov-ld merged commit 5611468 into main Nov 21, 2026
7 of 8 checks passed
@abelonogov-ld
abelonogov-ld deleted the andrey/event-durability-tier1-buffer branch November 21, 2026 01:50
abelonogov-ld added a commit that referenced this pull request Nov 21, 2026
**Requirements**

- [x] I have added test coverage for new or changed functionality
- [x] I have followed the repository's [pull request submission
guidelines](../blob/main/CONTRIBUTING.md#submitting-pull-requests)
- [ ] I have validated my changes against all supported platform
versions

**Related issues**

Tier 2 of the Event Durability spec, "Tier 2 — recoverable failure"
(§10). Stacked on #397 (tier 1), and targets that branch so this diff
shows only tier 2. It is small and self-contained, so it can be reviewed
in parallel with #397. It will be retargeted to `main` once #397 merges.

**Describe the solution you've provided**

A new public method, `LDClientInterface.flushAndWait(long timeout,
TimeUnit unit)`. It sends what has been recorded and returns whether the
events were delivered within the timeout.

`flush()` is fire-and-forget, so an application that knows it is about
to lose the chance to send (an uncaught exception handler, a move to the
background) had no way to give its events that chance and find out
whether it worked. `flushAndWait` gives it both, with a bound the caller
chooses.

- `EventProcessor` gains `blockingFlush(long, TimeUnit)` as a default
method, so custom implementations written before it still compile. The
default falls back to the unbounded `blockingFlush()` and returns true.
- `DirectEventProcessor` implements it. Delivery now reports its
outcome: true if the events were accepted or there was nothing to send,
false if offline, closed, or the send failed. If the timeout expires,
the delivery is left running rather than cancelled, because the buffer
has already been drained into the payload and interrupting it would only
make the loss certain.
- With more than one environment configured, `LDClient.flushAndWait`
shares one budget across them rather than giving each a fresh copy, so
the timeout is the most the call can take.

**Describe alternatives you've considered**

*Make `flush()` return a `Future`.* That changes the signature of an
existing public method, and a `Future` still leaves the caller to pick a
timeout and interpret the exceptions. A boolean with the timeout in the
call is the shape a crash handler actually needs.

*Cancel the delivery on timeout.* It frees the thread sooner but
guarantees the events are lost, since they are no longer in the buffer.
Letting it finish in the background gives them the best chance at no
cost to the caller, who has already stopped waiting.

**Additional context**

*Tests.* Four new tests in `DirectEventProcessorTest` cover delivered
events, nothing to send, offline, and the timeout expiring first. The
full unit suite and the instrumented suite (126 tests on an emulator)
pass locally.

*Test app.* Gains two controls that show what this tier can and cannot
do:
- **Eval+Crash now** records a flag evaluation and a custom event, then
throws. `FlushOnCrashHandler` calls `flushAndWait` with a two-second
budget before handing the crash on, so the events are delivered.
- **Eval+Kill now** records the same pair and sends `SIGKILL`. Nothing
can run, so the events are lost. That is the gap tier 3 (on-disk
persistence) closes.

*Version.* The new methods are marked `@since 5.17.0`; adjust if the
release lands under a different version.

<!-- CURSOR_SUMMARY -->
---

> [!NOTE]
> **Overview**
> Adds **`LDClientInterface.flushAndWait(timeout, unit)`**, which
flushes pending analytics events and returns whether delivery completed
within the caller’s budget—aimed at last-chance sends (crash handlers,
shutdown, background transitions).
> 
> **`DirectEventProcessor`** now exposes **`flushAsync()`** with
delivery coalescing (concurrent flushes share one in-flight post),
outcome reporting (offline, HTTP failure, partial serialization drops,
events lost by an earlier undelivered run), and leaves timed-out
deliveries running rather than canceling them.
**`OutboundEventBuffer.Payload`** gains **`isComplete()`** so a
successful HTTP response still counts as failure when events were
dropped on encode.
> 
> **`LDClient.flushAndWait`** starts async flushes for all configured
environments in parallel and waits on a single shared deadline.
**`LDCrashHandler`** (experimental) wraps the default uncaught-exception
handler and calls **`flushAndWait`** before delegating to the prior
handler. **`EventProcessor.flushAsync()`** is added with a default that
bridges legacy **`blockingFlush`** via **`LDFutures.fromBlockingCall`**.
> 
> Unit, instrumentation, and test-app controls (**Eval+Crash now** vs
**Eval+Kill now**) cover success, timeout, multi-env, closed client, and
crash-path delivery.
> 
> <sup>Reviewed by [Cursor Bugbot](https://cursor.com/bugbot) for commit
1d976b5. Bugbot is set up for automated
code reviews on this repo. Configure
[here](https://www.cursor.com/dashboard/bugbot).</sup>
<!-- /CURSOR_SUMMARY -->

---------

Co-authored-by: Cursor <[email protected]>
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.

jdk.internal.misc.Unsafe.park

2 participants