Skip to content

feat: replace EventSourced::Services with Jobs and wire atomic enqueue#15

Open
0xgleb wants to merge 1 commit into
feat/job-enqueuefrom
feat/jobs-eventsourced-reshape
Open

feat: replace EventSourced::Services with Jobs and wire atomic enqueue#15
0xgleb wants to merge 1 commit into
feat/job-enqueuefrom
feat/jobs-eventsourced-reshape

Conversation

@0xgleb

@0xgleb 0xgleb commented Jun 5, 2026

Copy link
Copy Markdown
Collaborator

Motivation

The crash-safety gap ADR-0001 exists to close: with type Services, handlers run
side effects before events persist, so a crash between the two orphans the
action. This change makes handlers pure and wires job enqueue into the same
transaction that commits events.

Solution

  • EventSourced: drop type Services, add type Jobs: JobList;
    initialize/transition become sync and take &mut JobQueue<Self::Jobs>; the
    trait sheds #[async_trait]. Service reads (clock, config) move into the
    Command.
  • Atomic enqueue without threading a transaction through cqrs-es:
    Store::send/send_command run the handler inside a with_pending_jobs
    task-local scope; the Lifecycle handler buffers its JobQueue via
    buffer_pending; SqliteEventRepository drains it with flush_pending_jobs
    inside the event-commit transaction.
  • Jobs buffered with no active scope are dropped with a warning rather than
    silently lost; JobList: Send so the queue threads through the Send command
    future.
  • Drops the services parameter from send_command, test_store,
    TestHarness::with, TestStore::new/with_reactor, StoreBuilder::build,
    and sqlite_snapshot_cqrs; Lifecycle::Services collapses to ().
  • Test: a command enqueues its job atomically with its events (event row +
    Pending job row written together).

Closes RAI-918.

@coderabbitai

coderabbitai Bot commented Jun 5, 2026

Copy link
Copy Markdown

Warning

Review limit reached

@0xgleb, we couldn't start this review because you've reached your PR review rate limit.

More reviews will be available in 18 minutes and 37 seconds. Learn how PR review limits work.

Your organization has run out of usage credits. Purchase more credits in the billing tab to continue.

⌛ How to resolve this issue?

After more reviews become available, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans include higher PR review limits than trial, open-source, and free plans. In all cases, reviews become available again over time. During sustained high-volume PR review activity, CodeRabbit may temporarily slow when the next review becomes available.

Please see our Fair Usage Limits Policy for further information.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: ASSERTIVE

Plan: Pro

Run ID: ad98cc83-0e59-4ccb-8316-304b76da1cc6

📥 Commits

Reviewing files that changed from the base of the PR and between d162898 and b77e4d4.

📒 Files selected for processing (17)
  • crates/event-sorcery/src/dependency.rs
  • crates/event-sorcery/src/job.rs
  • crates/event-sorcery/src/lib.rs
  • crates/event-sorcery/src/lifecycle.rs
  • crates/event-sorcery/src/projection.rs
  • crates/event-sorcery/src/schema_registry.rs
  • crates/event-sorcery/src/sqlite_event_repository.rs
  • crates/event-sorcery/src/testing.rs
  • crates/event-sorcery/src/wire.rs
  • examples/README.md
  • examples/complex/src/audit_log.rs
  • examples/complex/src/inventory.rs
  • examples/complex/src/main.rs
  • examples/complex/src/order.rs
  • examples/simple/README.md
  • examples/simple/src/main.rs
  • examples/simple/src/support_ticket.rs
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch feat/jobs-eventsourced-reshape

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

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

0xgleb commented Jun 5, 2026

Copy link
Copy Markdown
Collaborator Author

Warning

This pull request is not mergeable via GitHub because a downstack PR is open. Once all requirements are satisfied, merge this PR as a stack on Graphite.
Learn more


How to use the Graphite Merge Queue

Add the label add-to-gt-merge-queue to this PR to add it to the merge queue.

You must have a Graphite account in order to use the merge queue. Sign up using this link.

An organization admin has required the Graphite Merge Queue in this repository.

Please do not merge from GitHub as this will restart CI on PRs being processed by the merge queue.

This stack of pull requests is managed by Graphite. Learn more about stacking.

@0xgleb 0xgleb force-pushed the feat/job-enqueue branch from 2f4e282 to fd682b8 Compare June 8, 2026 22:58
@0xgleb 0xgleb force-pushed the feat/jobs-eventsourced-reshape branch from f8d5519 to fa00224 Compare June 8, 2026 22:58
@0xgleb 0xgleb force-pushed the feat/job-enqueue branch from fd682b8 to 0cf1ebc Compare June 8, 2026 23:41
@0xgleb 0xgleb force-pushed the feat/jobs-eventsourced-reshape branch 2 times, most recently from 910433d to c5c503c Compare June 9, 2026 20:39
@0xgleb 0xgleb mentioned this pull request Jun 9, 2026
@0xgleb 0xgleb force-pushed the feat/jobs-eventsourced-reshape branch from c5c503c to a755cb4 Compare June 9, 2026 21:22
@0xgleb 0xgleb force-pushed the feat/job-enqueue branch from 140bf44 to 45b05cf Compare June 9, 2026 21:22
@0xgleb 0xgleb force-pushed the feat/jobs-eventsourced-reshape branch from a755cb4 to 207ae2c Compare June 9, 2026 23:24
@0xgleb 0xgleb force-pushed the feat/job-enqueue branch from 45b05cf to 027f95b Compare June 9, 2026 23:24
@0xgleb 0xgleb force-pushed the feat/jobs-eventsourced-reshape branch from 207ae2c to 7159bba Compare June 9, 2026 23:55
@0xgleb 0xgleb force-pushed the feat/job-enqueue branch from 027f95b to 3867cc7 Compare June 9, 2026 23:55
@0xgleb 0xgleb force-pushed the feat/jobs-eventsourced-reshape branch from 7159bba to 14d1da0 Compare June 10, 2026 00:01
@0xgleb 0xgleb force-pushed the feat/job-enqueue branch from 3867cc7 to e3483da Compare June 10, 2026 01:18
@0xgleb 0xgleb force-pushed the feat/jobs-eventsourced-reshape branch from 14d1da0 to 177dc0c Compare June 10, 2026 01:18
@0xgleb 0xgleb force-pushed the feat/job-enqueue branch from e3483da to 5e6527b Compare June 10, 2026 02:50
@0xgleb 0xgleb force-pushed the feat/jobs-eventsourced-reshape branch from 177dc0c to 23d66f7 Compare June 10, 2026 02:50
@0xgleb 0xgleb marked this pull request as ready for review June 10, 2026 02:58
@0xgleb 0xgleb added the enhancement New feature or request label Jun 10, 2026 — with Graphite App
@0xgleb 0xgleb force-pushed the feat/job-enqueue branch from 5e6527b to dc53f2b Compare June 10, 2026 03:05
@0xgleb 0xgleb force-pushed the feat/jobs-eventsourced-reshape branch from 23d66f7 to a0945e0 Compare June 10, 2026 03:05
@0xgleb 0xgleb requested review from JuaniRios and findolor June 10, 2026 03:10
@0xgleb 0xgleb force-pushed the feat/jobs-eventsourced-reshape branch from a0945e0 to a2a190c Compare June 10, 2026 03:39
@0xgleb 0xgleb force-pushed the feat/job-enqueue branch from dc53f2b to 349d5ef Compare June 10, 2026 03:39
@linear-code

linear-code Bot commented Jun 10, 2026

Copy link
Copy Markdown

RAI-918

@0xgleb 0xgleb force-pushed the feat/jobs-eventsourced-reshape branch from a2a190c to e2743b6 Compare June 10, 2026 04:06
@0xgleb 0xgleb force-pushed the feat/job-enqueue branch from 349d5ef to 70c4573 Compare June 10, 2026 04:06
@0xgleb 0xgleb force-pushed the feat/jobs-eventsourced-reshape branch 3 times, most recently from 52388ad to e2743b6 Compare June 10, 2026 04:53
@0xgleb 0xgleb force-pushed the feat/job-enqueue branch from 70c4573 to eb12f80 Compare June 10, 2026 05:28
@0xgleb 0xgleb force-pushed the feat/jobs-eventsourced-reshape branch from e2743b6 to 64a435a Compare June 10, 2026 05:28

@findolor findolor left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Approved.

@0xgleb 0xgleb force-pushed the feat/job-enqueue branch from eb12f80 to f7c21f5 Compare June 10, 2026 17:39
@0xgleb 0xgleb force-pushed the feat/jobs-eventsourced-reshape branch from 64a435a to f7b49c2 Compare June 10, 2026 17:39
@graphite-app graphite-app Bot force-pushed the feat/job-enqueue branch from f7c21f5 to 1ac9ec5 Compare June 10, 2026 19:19
@graphite-app graphite-app Bot force-pushed the feat/jobs-eventsourced-reshape branch from f7b49c2 to a14c560 Compare June 10, 2026 19:19
@0xgleb 0xgleb force-pushed the feat/jobs-eventsourced-reshape branch from a14c560 to 72cd628 Compare June 12, 2026 19:45
@0xgleb 0xgleb force-pushed the feat/job-enqueue branch from 1ac9ec5 to 577f213 Compare June 12, 2026 19:45
@0xgleb 0xgleb force-pushed the feat/jobs-eventsourced-reshape branch from 72cd628 to 97bdb7d Compare June 12, 2026 21:16
@0xgleb 0xgleb force-pushed the feat/job-enqueue branch from 577f213 to 0749e4a Compare June 12, 2026 21:16
@0xgleb 0xgleb force-pushed the feat/job-enqueue branch from 0749e4a to d162898 Compare June 12, 2026 21:55
@0xgleb 0xgleb force-pushed the feat/jobs-eventsourced-reshape branch from 97bdb7d to b77e4d4 Compare June 12, 2026 21:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants