Repository navigation
fix(events): report a loss to the next flush when the caller stopped waiting - #448
abelonogov-ld wants to merge 1 commit into
Conversation
…waiting A delivery claims the events lost up to the batch it closed for the callers waiting on it. Where the only such caller had already stopped waiting, as a flushAndWait that timed out has, nobody heard of the loss, and the next flush answered true after events were lost for good. A caller whose wait times out or is interrupted before the answer now leaves a loss that answer reports for the next delivery a caller waits on to report. Co-authored-by: Cursor <cursoragent@cursor.com>
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes using default effort and found 1 potential issue.
❌ 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 c9022ad. Configure here.
| unheard.run(); | ||
| } | ||
| }); | ||
| } |
There was a problem hiding this comment.
Timed-out loss missed during retry
High Severity
A timed-out flush still fails to report a claimed loss when that delivery is waiting on a retry. lossUnheard is assigned at pass end, but stoppedWaiting only runs it when the future later completes. The scheduler is free during the retry delay, so the next flushAndWait can claim nothing, miss lossOwed, and return true after events were already lost. That is the durability miss this change set out to close.
Additional Locations (1)
Reviewed by Cursor Bugbot for commit c9022ad. Configure here.




Follow-up from the iOS tier 3 review (ios-client-sdk#538 thread). The reviewer found the bug on iOS and called it merge-gating; Android has the same bug for a timed-out wait.
A delivery claims the events lost up to the batch it closed for the callers waiting on it, so its future answers
false. If the only caller had already stopped waiting, nobody heard of the loss, yet it was claimed. The next flush then answeredtrueafter events were lost for good. Example:flushAndWaittimes out and returnsfalse, the delivery then drops a batch (two payload refusals in a row), and the nextflushAndWaitreturnstrue. That breaks the durability spec's rule that a loss may be reported twice but never zero times.Changes:
EventDeliveryScheduler.RequestedAnswer: the future a requested delivery answers. If a caller'sgettimes out or is interrupted, then once the answer comes, a loss it reports is left for the next caller. Flushes that join one delivery still get the same future.DirectEventProcessor.runDelivery: where the answer reports a loss, it tells the future what leaves the loss for the next caller.DirectEventProcessor.claimEventsLost: the next delivery a caller waits on reports a loss left that way, as well as any loss of its own.Not covered: a
flushAsync()future that is never read. That caller chose not to hear the answer.Tests:
DirectEventProcessorTest.aLossClaimedForAFlushThatStoppedWaitingIsToldToTheNextFlush: the caller's wait times out, then the delivery loses an event; the next flush reportsfalse, and the one after reportstrue. It fails without the fix.All 1277 unit tests pass locally (25 skipped).
Note
Overview
Fixes a durability bug where a
flushAndWait(or timedget) could time out before a delivery finished, the delivery then dropped events for good, and the next flush still answeredtruebecause the loss had been claimed with no listener left to hear it.EventDeliveryScheduler.RequestedAnswerreplaces the plain flush future: on timeout or interrupt, it registers a listener so when the answer eventually reports a loss, that loss is forwarded (vialossUnheard) instead of being silently consumed.DirectEventProcessoraddslossOwedand wires deliveries that claim a loss to setlossUnheardon the answer future.claimEventsLostnow returns failure for the next waiting caller when an owed loss was left behind, even if this pass did not advance the loss mark—so reporting twice is possible, but reporting zero times is not.A new unit test covers timeout-then-drop-then-subsequent-flush behavior.
Reviewed by Cursor Bugbot for commit c9022ad. Bugbot is set up for automated code reviews on this repo. Configure here.