Skip to content

fix(subscriptions): stop an acknowledgement from before a disconnect covering events the subscriber has not processed - #72

Merged
yordis merged 3 commits into
mainfrom
yordis/fix-concurrent-late-ack
Oct 27, 2026
Merged

yordis merged 3 commits into
mainfrom
yordis/fix-concurrent-late-ack

Conversation

@yordis

@yordis yordis commented Oct 26, 2026 •

Copy link
Copy Markdown
Member

@yordis
yordis added this pull request to stack #73 October 26, 2026 16:00
@cursor

cursor Bot commented Oct 26, 2026 •

Copy link
Copy Markdown

PR Summary

Medium Risk
Changes subscription checkpoint/ack semantics on disconnect and redelivery—core delivery guarantees—but behavior is tightly scoped with new unit and locking tests.

Overview
Fixes a bug where a late acknowledgement from before a disconnect/reconnect could advance last_seen for events the subscriber had only received on redelivery, effectively marking work as done that was never processed on the current delivery.

Subscriber tracking now keeps a superseded queue: on reset_in_flight (e.g. lock loss), prior in-flight deliveries move there instead of being forgotten. acknowledge consumes acks against the oldest matching superseded delivery first (including across multiple resets), and only then against current in-flight events. discard_superseded lets stale acks drop the corresponding superseded slot without checkpointing.

The subscription FSM no longer ignores acks in states where they previously no-oped; it applies discard_superseded so acks that arrive while disconnected align with pre-reset deliveries without affecting redelivered events.

Integration tests cover multi-subscriber reconnect scenarios; unit tests cover multi-reset ack ordering.

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

@coderabbitai

coderabbitai Bot commented Oct 26, 2026 •

Copy link
Copy Markdown

Review in Change Stack →

No actionable comments were generated in the recent review.

Recent review info
Run configuration
  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: Organization UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 75435701-cfc8-4b9e-aa31-098dc85c09c4
Commits

Reviewing files that changed from the base of the PR and between 4fa06ef and bfd8e3f.

Files selected for processing: 2
  • lib/event_store/subscriptions/subscriber.ex
  • test/subscriptions/subscriber_test.exs
Files skipped from review as they are similar to previous changes: 1
  • lib/event_store/subscriptions/subscriber.ex

Included review availability: This review used your included allowance. Your plan provides up to 1 included review per hour; 0 remain after this review.

Walkthrough

Subscriber acknowledgements now distinguish superseded deliveries from current in-flight events. The subscription FSM discards superseded deliveries for known subscribers. Tests cover repeated resets and acknowledgements across disconnects and redelivery.

Changes

Subscription acknowledgement boundaries

Layer / File(s) Summary
Superseded delivery tracking
lib/event_store/subscriptions/subscriber.ex, test/subscriptions/subscriber_test.exs
Subscriber state retains in-flight events cleared by resets. Acknowledgements check superseded deliveries before current in-flight events. Unit tests cover repeated resets, acknowledgements, and discards.
FSM acknowledgement integration
lib/event_store/subscriptions/subscription_fsm.ex, test/subscriptions/subscription_locking_test.exs
The fallback acknowledgement clause discards superseded deliveries for known subscribers. Locking tests cover acknowledgements before and during disconnects, then after redelivery. Test helpers support subscriber setup and state checks.

Priority: Normal

Estimated code review effort: 3 (Moderate) | ~20 minutes

Change: Bug fix

Possibly related issues

Possibly related PRs

  • TrogonStack/commanded_eventstore#27: That PR changes when a subscription learns that its advisory lock is lost. This change handles acknowledgements that arrive across the resulting disconnect and redelivery.

Suggested reviewers: slashdotdash, vheathen

Merge Risk: Minimal · up to bfd8e

The PR is mergeable; no actionable regression was identified in the reviewed changes.

Pre-merge checks: Passed 4 · Failed 1

Failed Failed checks: 1 warning

Check name Status Explanation Resolution
Docstring Coverage Warning Docstring coverage is 28.57% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 7 functions across 4 files. Write docstrings for the functions missing them to satisfy the coverage threshold.
Passed Passed checks: 4 passed
Check name Status Explanation
Title check Passed The title clearly and concisely describes the main fix: preventing acknowledgements sent before a disconnect from covering unprocessed redelivered events.
Description check Passed The description directly explains the acknowledgement bug and connects it to the disconnect and redelivery behavior addressed by the changes.
Linked Issues check Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check Passed Check skipped because no linked issues were found for this pull request.
Finishing Touches: 💡 1
📝 Generate docstrings: 💡
  • Commit to this branch
  • Create a new PR
🧪 Generate unit tests (beta)
  • Commit to this branch
  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

A rabbit counts each event twice,
Old trails fade as new ones rise.
Acks find the delivery they knew,
While fresh events wait their turn too.
Hops resume when streams renew.

Comment @coderabbitai help to get the list of available commands.

@yordis yordis changed the title yordis/fix concurrent late ack fix(subscriptions): stop an acknowledgement from before a disconnect covering events the subscriber has not processed Oct 26, 2026

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

@yordis
yordis force-pushed the yordis/fix-concurrent-late-ack branch from 2b2a460 to 0a631c9 Compare October 26, 2026 16:16
@yordis
yordis removed this pull request from stack #73 October 26, 2026 16:53
@yordis
yordis force-pushed the yordis/fix-concurrent-late-ack branch from 0a631c9 to 630ac62 Compare October 26, 2026 16:54
@yordis
yordis added this pull request to stack #74 October 26, 2026 17:10
@yordis
yordis force-pushed the yordis/fix-concurrent-late-ack branch 3 times, most recently from 37a08b9 to 97f21ff Compare October 26, 2026 19:31
@yordis
yordis force-pushed the yordis/fix-concurrent-late-ack branch from 97f21ff to 8f5a1a3 Compare October 26, 2026 20:27
Base automatically changed from yordis/fix-checkpoint-retry-after-error to main October 26, 2026 22:05
… covering events redelivered after it

Signed-off-by: Yordis Prieto <yordis.prieto@gmail.com>
…covering events the subscriber has not processed

Signed-off-by: Yordis Prieto <yordis.prieto@gmail.com>
@yordis
yordis force-pushed the yordis/fix-concurrent-late-ack branch from 8f5a1a3 to 4fa06ef Compare October 26, 2026 22:06
…allow acknowledgements of events sent again

Signed-off-by: Yordis Prieto <yordis.prieto@gmail.com>
@yordis
yordis merged commit 7964d47 into main Oct 27, 2026
7 checks passed
@yordis
yordis deleted the yordis/fix-concurrent-late-ack branch October 27, 2026 00:43
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