Repository navigation
fix: cache serde failures in DurableFuture instead of returning nil on re-await - #23
pcbeingused333 wants to merge 2 commits into
Conversation
|
@pullfrog review |
There was a problem hiding this comment.
Important
The fix is correct for DurableFuture and DurableCallFuture, but it fails steep check: settle is not declared in sig/restate.rbs. CombinedFuture also still returns nil on a second await after a non-terminal error.
Approach: sound. Caching the non-terminal exception is the only option, since the VM notification is single-shot. Putting the logic in one shared settle helper removes the duplicated rescue/ensure code. The CombinedFuture combinator in the same file still has the old pattern, though.
Reviewed changes
I reviewed the whole diff and ran the new spec (3/3 pass), RuboCop (clean) and steep check (3 problems, 2 of them errors) locally.
settlehelper:resolve!andresolve_call!now go throughsettle, which caches anyStandardErrorin@errorand re-raises it, so everyawaitafter a failure raises the same error.- Spec:
spec/durable_future_serde_spec.rbawaits twice after a serde failure on both future types, and checks that aTerminalErroris cached without callingresolve_handleagain.
Both failing PR checks (Build, lint, typecheck & test and verify / verify) fail during the actions lockfile check, because the dtolnay/rust-toolchain@stable pin has moved. CI never ran any Ruby code, so the type error below has not been reported there.
⚠️ CombinedFuture still returns nil on a second await after a non-terminal failure
CombinedFuture#resolve_combined! uses the same rescue TerminalError / ensure @resolved = true pattern this PR replaces. When a child raises a non-terminal error, for example a serde failure surfaced by finalize_all_completed or finalize_first_succeeded (both rescue only TerminalError), the first await raises and the second returns nil. I reproduced this on the PR head: Restate.all_settled-style (:all_completed) over a child with a failing serde gives raised ArgumentError: bad payload, then returned nil.
Technical details
# CombinedFuture still loses non-terminal failures on re-await
## Affected sites
- lib/restate/durable_future.rb:189-196 — `resolve_combined!` rescues only `TerminalError`; `ensure` marks the future resolved with `@value = nil`, `@error = nil` when anything else propagates.
## Required outcome
- A second `await` on a `CombinedFuture` whose first `await` raised a non-terminal `StandardError` raises the same error instead of returning `nil`.
- One implementation of the "record outcome" logic, shared by `DurableFuture` and `CombinedFuture` (it is not a subclass, so it cannot inherit `settle` today).
## Suggested approach
- Move `settle` into a small private mixin (or a module function) in `durable_future.rb`, include it in both classes, and rewrite `resolve_combined!` as `settle { @ctx.wait_combined(tree); finalize_value }`.
- Declare it in `sig/restate.rbs` for whichever owner it ends up on.
- Add a `CombinedFuture` example to `spec/durable_future_serde_spec.rb` (e.g. `:all_completed` over a child with a raising serde, awaited twice).
- Optional: the doc comment on `DurableCallFuture#await` (line 89, "Caches both successes and TerminalError failures") is now stale.claude-opus-5-5 | 𝕏
| # re-raised on await. Any other failure (e.g. a serde error) is cached too: | ||
| # the VM notification is single-shot, so leaving the future "resolved" with | ||
| # no value would make the next await silently return nil. | ||
| def settle |
There was a problem hiding this comment.
settle is missing from sig/restate.rbs, and durable_future.rb is in the Steep check list. So bundle exec steep check (run by make typecheck, which make verify in CI depends on) now fails with Ruby::NoMethod at lines 54 and 100, plus an UndeclaredMethodDefinition warning here. I confirmed this locally. Add the method under the private section of DurableFuture in the RBS:
def settle: () { () -> untyped } -> void…ture Addresses the review on this PR: steep failed because settle was not declared in sig/restate.rbs, and CombinedFuture still returned nil on a second await after a non-terminal failure. settle now lives in a small Settleable module included by both classes.
|
Thanks for the review. Pushed a follow-up commit that addresses both points from the pullfrog review:
The two red checks fail at the actions lockfile step (the This follow-up was prepared with Claude Code (AI) and submitted by the account owner; the spec file passes locally (the new |

DurableFuture#awaitandDurableCallFuture#awaitmark the future as resolved in anensureblock. If deserialization raises something other thanTerminalError(for example a serde failure), the firstawaitraises, but the future is already marked resolved with no value and no cached error, so a secondawaitsilently returnsnil.Both futures now share a
settlehelper that records the outcome: results andTerminalErrorare cached as before, and any otherStandardErroris cached and re-raised, so every laterawaitraises the same error. The VM notification is single-shot, so re-resolving the handle is not an option.Testing and validation
spec/durable_future_serde_spec.rbcovers a failing serde onDurableFutureandDurableCallFuture(two awaits each must raise) and the existingTerminalErrorcaching. On current main 2 of 3 examples fail (second await returns nil); with the fix all 3 pass. RuboCop is clean on the touched files. No VM or network is needed.This change was prepared with AI assistance.