feat(outbox): add OpCursor for pre-commit reads of op-buffered events - #79
Merged
Conversation
bodymindarts
force-pushed
the
feat/outbox-op-cursor
branch
from
July 21, 2026 18:56
47941e9 to
8e6efe2
Compare
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes using high effort and found 1 potential issue.
❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.
Reviewed by Cursor Bugbot for commit 88ef3b6. Configure here.
This was referenced Jul 21, 2026
Merged
For AtomicOperation::supports_hooks() (GaloyMoney/es-entity#155), used by OpCursor to detect commit-hook support. Keeps job at 0.6.30. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Publishing to an outbox within an es_entity op buffers events on a (merged) commit hook; nothing is written until op.commit(). OpCursor marks a position in that buffer so events published after it can be read back before commit, via reads on the Outbox that mirror how EventSequence is passed to listen_persisted: - Outbox::cursor(&op) -> Result<OpCursor<P, Tables>, CursorError> - Outbox::new_events(&op, &mut cursor) -> &[P] (advancing) - Outbox::map_new(&op, &mut cursor, f) -> Vec<T> (advancing, filter_map) - Outbox::peek_new(&op, &cursor) -> &[P] (non-advancing) The cursor is a passive token (index + PhantomData); reads borrow the op, so the buffer can't change while a slice is held. The type parameters pin a cursor to its outbox's payload/table types. cursor() fails loudly with CursorError::HooksUnsupported on an op that does not support commit hooks (a bare sqlx::Transaction, which persists publishes immediately with no op-local buffer) rather than returning a cursor that silently yields nothing. Support is detected via es-entity's &self AtomicOperation::supports_hooks(), so the signature stays borrow-light (&op) and the reads stay infallible. Motivating use case: atomically republish a mapped projection of one outbox's events onto another outbox in the same transaction (e.g. cala -> lana). PersistEvents exposes a crate-private pending() accessor. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
bodymindarts
force-pushed
the
feat/outbox-op-cursor
branch
from
July 22, 2026 07:28
5b012d0 to
0f43b4c
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.

What
Adds
OpCursor— a passive position token into an outbox's op-local publish buffer — plus reads onOutboxto consume events published within anes_entityop before commit:Outbox::cursor(&op) -> Result<OpCursor<P, Tables>, CursorError>Outbox::new_events(&op, &mut cursor) -> &[P]Outbox::map_new(&op, &mut cursor, f) -> Vec<T>filter_mapOutbox::peek_new(&op, &cursor) -> &[P]Also bumps es-entity → 0.11.3 and job → 0.6.29.
Why
Publishing to an outbox within an op buffers events on a (merged) commit hook — nothing is written until
op.commit().OpCursorlets you read those buffered events back before commit. The motivating use case is atomically republishing a mapped projection of one outbox's events onto another outbox in the same transaction (e.g. cala → lana), with per-use-case mapping inline at the call site.The cursor is a passive token (index +
PhantomData) passed to reads on theOutbox, exactly asEventSequenceis passed tolisten_persisted. Reads borrow the op, so the buffer can't change while a slice is held; the type parameters pin a cursor to its outbox's payload/table types.Fail loudly on hookless ops
cursor()returnsResultand errors withCursorError::HooksUnsupportedwhen the op does not support commit hooks (a baresqlx::Transaction, which persists publishes immediately with no op-local buffer) — rather than handing back a cursor that would silently yield nothing (which, in the repost use case, would persist source events while silently dropping the mapped repost).Detection uses es-entity 0.11.3's new
&selfAtomicOperation::supports_hooks()probe, socursor()stays borrow-light (&op, no&mut) and the reads stay infallible: a validOpCursorimplies hook support, andcommit_hook()==Nonestill covers the legitimate "supported but nothing published yet" case.Tests
tests/op_cursor.rs— 6 integration tests, all green:peekdoes not advancecursor()errors on an op without hook support (bare-tx)Full suite: 4 inbox + 6 op_cursor + 12 outbox + 4 handler + 1 doctest passing on es-entity 0.11.3 / job 0.6.29;
cargo fmt --checkandcargo clippy --all-features --all-targetsclean.🤖 Generated with Claude Code
Note
Medium Risk
Touches transactional outbox publish/commit-hook behavior and adds a new public API path for multi-outbox republish; mistakes could drop mapped events or change atomicity expectations, though behavior is covered by integration tests.
Overview
Adds
OpCursorandOutboxAPIs to read events buffered on a transaction’s commit hook beforecommit()—so callers can see only publishes that happen after a marked position (e.g. after a downstream ledger call on the samees_entityop).Outbox::cursor,new_events,peek_new, andmap_newexpose advancing vs non-advancing reads and afilter_maphelper for the main use case: map source outbox events and republish onto another outbox in the same transaction. Reads borrow the op so the pending slice stays stable while held.cursor()returnsCursorError::HooksUnsupportedwhen the op has no commit hooks (e.g. baresqlx::Transaction), using es-entity 0.11.3’ssupports_hooks(), instead of a cursor that would silently return nothing.PersistEvents::pending()backs these reads from the hook’s pre-commit buffer.Public re-exports
OpCursor/CursorErrorfrom the crate root;tests/op_cursor.rscovers scoping, peek vs consume, atomic commit/rollback republish, and hookless ops.Reviewed by Cursor Bugbot for commit 0f43b4c. Bugbot is set up for automated code reviews on this repo. Configure here.