You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@pekko.apache.org by "He-Pin (via GitHub)" <gi...@apache.org> on 2026/10/24 10:27:42 UTC

[PR] Add thenRun to staged reply effects [pekko]

He-Pin opened a new pull request, #3684:
URL: https://github.com/apache/pekko/pull/3684

   ### Motivation
   
   A command handler can select between persisting and replying, replying without persistence, or explicitly not replying. After that decision, a caller cannot append a common callback through the staged reply-effect API introduced in #3682. Recording a metric or sending a notification requires duplicating the callback in each branch or moving it before the reply.
   
   Add `thenRun` to that stage, while making `thenStop` end callback composition:
   
   ```scala
   handleCommand(state, command)
     .thenRun(updatedState => recordMetric(updatedState))
     .thenStop()
   ```
   
   The helper returns `ReplyEffectWithStop`. `thenStop().thenRun(...)` must not compile.
   
   ### Modification
   
   - Declare `thenRun` on `ReplyEffectOps`, returning its recursive `Self` type: Scala's state callback and Java's state and no-argument overloads, for both event-sourced and durable-state persistence. Mark all new methods `@since 2.0.0`.
   - Change `ReplyEffectWithStop.thenStop()` to return the base `ReplyEffect`. This rejects callbacks after stopping, including through `thenUnstashAll`, while `thenRun(...).thenUnstashAll().thenStop()` retains the expected stage. `stash()` continues to expose only the base type.
   - Keep traits abstract and implement the Java overloads in `EffectImpl`. Make the existing Java `EffectBuilder.thenRun` methods overridable while retaining their bodies and descriptors. The existing subtype callback adaptation is reused; no effect downcasts or runtime stage checks are introduced.
   - Add matching Scala and Java tests for persistence/reply/callback ordering, common callbacks after accepted and rejected branches, both no-reply entry points, generic `Self` helpers, and stopping after callbacks. Add compile-time rejection coverage for stopped, stashed, and widened effects.
   - Update both persistence guides with the use case, type restrictions, and existing at-most-once side-effect guarantees. Sending a reply does not wait for the recipient to receive or process it.
   
   ### Result
   
   Callers can append callbacks after choosing a reply without losing the ability to unstash or stop. Stopping the reply-effect chain removes callback capabilities. This adds no new trait and changes no runtime side-effect ordering; existing `EffectBuilder` chaining remains outside this reply-stage restriction.
   
   **Stacked on #3682 at `c00fbb3376d47b8ec28abe151673207ec5f4e71e`.** The base branch `stack/3682-reply-effect-then-stop` mirrors that exact commit so this PR shows only the incremental change and runs upstream CI. Keep this PR in draft until the parent merges; then rebase and retarget to `main` before merging. Do not merge into the temporary stack base.
   
   ### Tests
   
   - Isolated Scala 2.13 compilation of the eight effect API/implementation sources and all four new test files: passed.
   - Scala and `javac` client probes: valid generic/fluent chains compile; 10 Scala and 20 Java invalid chains are rejected. Restoring the old `thenStop` return type makes the stopped-chain probes compile, demonstrating the regression check. Positive `thenRun` probes fail against the parent API as expected.
   - Direct MiMa 1.2.1 probe against compiled `origin/main` sources: the same 22 findings covered by the parent's exact filters; no additional filter added. Published-baseline cross-version MiMa remains for CI.
   - `scalafmt --mode diff-ref=c00fbb3376d47b8ec28abe151673207ec5f4e71e` and `--list`: passed.
   - `sbt headerCreateAll javafmtAll` (JDK 17), followed by `sbt +headerCheckAll javafmtCheckAll checkCodeStyle`: passed.
   - `sbt sortImports`: environment/tool linkage failure in `stream-tests` and `multi-node-testkit` (`scala.meta.package$.Input()`); unrelated generated edits removed. Subsequent code-style checks passed.
   - `git diff --check`: passed. Auditable Qoder stdout review: no must-fix findings.
   - Full runtime tests, Scala 3/next, `validatePullRequest`, published-baseline MiMa, and Paradox: delegated to remote CI; pending. No local full-suite runtime result claimed.
   
   ### References
   
   Refs #3682, Refs #3683
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@pekko.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@pekko.apache.org
For additional commands, e-mail: notifications-help@pekko.apache.org


Re: [PR] Add thenRun to staged reply effects [pekko]

Posted by "He-Pin (via GitHub)" <gi...@apache.org>.
He-Pin commented on PR #3684:
URL: https://github.com/apache/pekko/pull/3684#issuecomment-6386827083

   Will rebase on the main later


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@pekko.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@pekko.apache.org
For additional commands, e-mail: notifications-help@pekko.apache.org


Re: [PR] Add thenRun to staged reply effects [pekko]

Posted by "He-Pin (via GitHub)" <gi...@apache.org>.
He-Pin commented on PR #3684:
URL: https://github.com/apache/pekko/pull/3684#issuecomment-6387116849

   @pjfanning Can you please take care of this one and I think this is the last one I want to be included in the 2.0.0 release. 


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@pekko.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@pekko.apache.org
For additional commands, e-mail: notifications-help@pekko.apache.org


Re: [PR] Add thenRun to staged reply effects [pekko]

Posted by "He-Pin (via GitHub)" <gi...@apache.org>.
He-Pin closed pull request #3684: Add thenRun to staged reply effects
URL: https://github.com/apache/pekko/pull/3684


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@pekko.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@pekko.apache.org
For additional commands, e-mail: notifications-help@pekko.apache.org


Re: [PR] Add thenRun to staged reply effects [pekko]

Posted by "He-Pin (via GitHub)" <gi...@apache.org>.
He-Pin closed pull request #3684: Add thenRun to staged reply effects
URL: https://github.com/apache/pekko/pull/3684


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@pekko.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@pekko.apache.org
For additional commands, e-mail: notifications-help@pekko.apache.org