Skip to content

refactor(subscriptions): drop the vendored finite state machine DSL - #17

Merged
yordis merged 1 commit into
mainfrom
yordis/refactor-replace-fsm-dsl
Sep 15, 2026
Merged

yordis merged 1 commit into
mainfrom
yordis/refactor-replace-fsm-dsl

Conversation

@yordis

@yordis yordis commented Sep 15, 2026

Copy link
Copy Markdown
Member
  • The fsm package the DSL came from is unmaintained (last release 2017) and its author now advises against using it, recommending plain structs with multiclause pattern matching instead.
  • Vendoring a copy in chore: support only the last three Elixir and OTP releases #16 was only a stopgap so the compiler would stay quiet on Elixir 1.19 and 1.20; carrying generator code we cannot maintain is worse than carrying the clauses it generated.
  • Removing the macro layer makes the subscription state transitions readable and greppable, which matters because this module drives catch-up and acking.

The `fsm` package this DSL came from is unmaintained and its author now
recommends plain structs with multiclause pattern matching instead. Vendoring
a copy was only a stopgap to keep the compiler quiet on newer Elixir.

Signed-off-by: Yordis Prieto <yordis.prieto@gmail.com>
@coderabbitai

coderabbitai Bot commented Sep 15, 2026

Copy link
Copy Markdown

Review Change StackReview Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Advanced

Run ID: 122dbde7-89b9-434d-b805-c0300f66ca38

📥 Commits

Reviewing files that changed from the base of the PR and between 9215862 and 390ddbd.

📒 Files selected for processing (2)
  • lib/event_store/fsm.ex
  • lib/event_store/subscriptions/subscription_fsm.ex
💤 Files with no reviewable changes (1)
  • lib/event_store/fsm.ex

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


Walkthrough

EventStore.Fsm was removed. SubscriptionFsm now uses an explicit struct and public functions for state transitions, subscription events, catch-up handling, subscriber lifecycle operations, and stream outcomes.

Changes

Subscription FSM Migration

Layer / File(s) Summary
Replace the FSM abstraction
lib/event_store/fsm.ex, lib/event_store/subscriptions/subscription_fsm.ex
The macro-based FSM module was removed. SubscriptionFsm now defines its own struct and constructor.
Implement subscription transitions
lib/event_store/subscriptions/subscription_fsm.ex
Explicit function clauses handle subscription, catch-up, acknowledgment, checkpoint, and notification transitions. Existing capacity, disconnected, and stream-read outcomes remain supported.
Implement subscriber lifecycle
lib/event_store/subscriptions/subscription_fsm.ex
Connection, disconnection, and unsubscribe functions preserve subscriber cleanup, checkpoint persistence, and final unsubscribe behavior.

Priority: ⬇️ Low

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

Change: Refactor

Merge Risk: ⚪ Minimal · up to 390dd

No concrete regression remains that should block merging.

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 24 functions across 1 files. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly and concisely describes the main change: removing the vendored finite state machine DSL from subscriptions.
Description check ✅ Passed The description explains why the FSM DSL was removed and how explicit subscription state transitions replace it. It directly matches the changeset.
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.
  • Fix all pre-merge checks with AI
✨ Finishing Touches 💡 1
📝 Generate docstrings 💡
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch yordis/refactor-replace-fsm-dsl

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 hops through states anew
With structs lined up in ordered queues
Events now follow functions clear
Catch-up paths stay close and near
Subscribers disconnect, checkpoints cheer

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

@cursor

cursor Bot commented Sep 15, 2026

Copy link
Copy Markdown

PR Summary

Medium Risk
Touches subscription catch-up, acking, and reconnection logic in a behavior-preserving refactor; regressions would affect event delivery guarantees rather than compile-time-only changes.

Overview
Removes the vendored EventStore.Fsm macro DSL and reimplements SubscriptionFsm as a plain struct with multiclause functions that pattern-match on state and data.

State transitions that used next_state / respond now return an updated %SubscriptionFsm{} or {reply, fsm} for ack errors, matching how Subscription already unwraps ack results. catch_up_from_stream is private, takes the FSM as its first argument, and returns the struct instead of going through the macro runtime. The external entry points (subscribe, catch_up, ack, checkpoint, notify_events, etc.) stay the same so the GenServer call sites are unchanged.

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

@yordis
yordis merged commit 95f1c5d into main Sep 15, 2026
6 checks passed
@yordis
yordis deleted the yordis/refactor-replace-fsm-dsl branch September 15, 2026 21:23
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