Skip to content

[Rust] Let extensions run work hooks on peer jobs - #1501

Draft
bgentry wants to merge 1 commit into
masterfrom
bg/plugin-peer-work-hooks
Draft

bgentry wants to merge 1 commit into
masterfrom
bg/plugin-peer-work-hooks

Conversation

@bgentry

@bgentry bgentry commented Oct 13, 2026 •

Copy link
Copy Markdown
Contributor

In River for Rust, when an extension claims and completes jobs itself through PeerAttempts, River never runs the client's Hook::work_begin and Hook::work_end hooks for them. Any per-job processing in those hooks is skipped for peers, including decoding arguments that were transformed when they were inserted.

This adds PeerAttempts::work_begin and PeerAttempts::work_end to the unstable extension module. They run the client's configured hooks for a given row the same way the executor does for a job it works: in registration order, with the coordinator's work context. Begin hooks can change the row and stop at the first error. End hooks pass the result from one to the next. work_begin returns the failing hook's error unchanged, so the extension can fail that one peer and keep working the others.

work_end takes and returns the boxed error type that PeerOutcome uses. When a peer's outcome is recorded, a boxed WorkError is now unwrapped instead of being wrapped again. That lets hooks and the error handler downcast a peer's error to its original type, as they already can for a worker's error.

JavaScript needs no change. PilotAttempts.claim already applies the client's argument read transforms to the peers it returns.

@bgentry
bgentry force-pushed the bg/plugin-peer-work-hooks branch 2 times, most recently from 8734927 to 88e8ce3 Compare October 13, 2026 14:47
@bgentry bgentry changed the title let extensions run work hooks on peer jobs Let extensions run work hooks on peer jobs Oct 13, 2026
@bgentry
bgentry force-pushed the bg/plugin-peer-work-hooks branch from 88e8ce3 to 72ee6e9 Compare October 13, 2026 14:49
@bgentry bgentry changed the title Let extensions run work hooks on peer jobs [Rust] Let extensions run work hooks on peer jobs Oct 13, 2026
An extension that claims and completes peers through `PeerAttempts`
works those jobs itself, so River never runs the client's
`Hook::work_begin` and `Hook::work_end` hooks for them. Per-job
processing that lives in those hooks, such as decoding arguments that
were transformed on insertion, is skipped for every peer.

Add `PeerAttempts::work_begin` and `PeerAttempts::work_end`, which run
the client's configured hooks for a given row exactly as the executor
does for a job it works: in registration order, with the coordinator's
work context, begin hooks mutating the row and stopping at the first
error, and end hooks threading the result from one to the next. The
begin helper returns the failing hook's error unchanged so the caller
can fail that one peer with a `PeerOutcome` and keep working the rest.

`PeerAttempts` is the natural home because it already resolves the
coordinator's client and running attempt, and keeps a peer's whole
lifecycle (claim, work hooks, completion) on one type.

The end helper takes and returns the boxed error type `PeerOutcome`
uses. A `WorkError` passed through a box is now unwrapped rather than
wrapped a second time when a peer's outcome is recorded, so hooks and
the error handler can downcast a peer's error to its original type, as
they can for a worker's error.

New peer-attempt scenarios on Postgres and SQLite cover hook order,
argument changes seen by later hooks and by end hooks, a begin failure
failing only its own peer, an end hook replacing a failure before the
error handler runs, and rejection outside a running attempt.
@bgentry
bgentry force-pushed the bg/plugin-peer-work-hooks branch from 72ee6e9 to 1d0186f Compare October 13, 2026 23:41
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.

2 participants