Skip to content

fix(events): report a loss to the next flush when the caller stopped waiting - #448

Open
abelonogov-ld wants to merge 1 commit into
mainfrom
andrey/loss-claimed-when-heard
Open

abelonogov-ld wants to merge 1 commit into
mainfrom
andrey/loss-claimed-when-heard

Conversation

@abelonogov-ld

@abelonogov-ld abelonogov-ld commented Nov 25, 2026 •

Copy link
Copy Markdown
Contributor

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 answered true after events were lost for good. Example: flushAndWait times out and returns false, the delivery then drops a batch (two payload refusals in a row), and the next flushAndWait returns true. 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's get times 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.
  • Claiming still happens as each pass ends, in delivery order, so a loss still goes to the flush whose delivery passed it. The only new case where two callers hear the same loss is when two callers joined one delivery and one gave up. Reporting twice is the safe direction.

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 reports false, and the one after reports true. It fails without the fix.

All 1277 unit tests pass locally (25 skipped).


Note

Overview
Fixes a durability bug where a flushAndWait (or timed get) could time out before a delivery finished, the delivery then dropped events for good, and the next flush still answered true because the loss had been claimed with no listener left to hear it.

EventDeliveryScheduler.RequestedAnswer replaces the plain flush future: on timeout or interrupt, it registers a listener so when the answer eventually reports a loss, that loss is forwarded (via lossUnheard) instead of being silently consumed.

DirectEventProcessor adds lossOwed and wires deliveries that claim a loss to set lossUnheard on the answer future. claimEventsLost now 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.

…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>
@abelonogov-ld
abelonogov-ld requested a review from a team as a code owner November 25, 2026 01:35

@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 c9022ad. Configure here.

unheard.run();
}
});
}

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

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)
Fix in Cursor Fix in Web

Reviewed by Cursor Bugbot for commit c9022ad. Configure here.

@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.

Risk: medium. Not approved: Cursor Bugbot found 1 unresolved potential issue, and Rule 2 (allowed PR authors) also blocks approval. Human review is needed and no reviewers were assigned.

Open in Web View Automation 

Sent by Cursor Approval Agent: SDK - Pull Request Router and Approver

This branch has not been deployed

No deployments
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.

1 participant