Skip to content

fix: cache serde failures in DurableFuture instead of returning nil on re-await - #23

Open
pcbeingused333 wants to merge 2 commits into
restatedev:mainfrom
pcbeingused333:fix/c3780-serde-reraise
Open

pcbeingused333 wants to merge 2 commits into
restatedev:mainfrom
pcbeingused333:fix/c3780-serde-reraise

Conversation

@pcbeingused333

Copy link
Copy Markdown

DurableFuture#await and DurableCallFuture#await mark the future as resolved in an ensure block. If deserialization raises something other than TerminalError (for example a serde failure), the first await raises, but the future is already marked resolved with no value and no cached error, so a second await silently returns nil.

Both futures now share a settle helper that records the outcome: results and TerminalError are cached as before, and any other StandardError is cached and re-raised, so every later await raises 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.rb covers a failing serde on DurableFuture and DurableCallFuture (two awaits each must raise) and the existing TerminalError caching. 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.

@igalshilman

Copy link
Copy Markdown
Contributor

@pullfrog review

@pullfrog pullfrog Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

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.

  • settle helper: resolve! and resolve_call! now go through settle, which caches any StandardError in @error and re-raises it, so every await after a failure raises the same error.
  • Spec: spec/durable_future_serde_spec.rb awaits twice after a serde failure on both future types, and checks that a TerminalError is cached without calling resolve_handle again.

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.

Pullfrog  | Fix all ➔ | Fix 👍s ➔ | View workflow run | Using claude-opus-5-5 | 𝕏

Comment thread lib/restate/durable_future.rb Outdated
# 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

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

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.
@pcbeingused333

Copy link
Copy Markdown
Author

Thanks for the review. Pushed a follow-up commit that addresses both points from the pullfrog review:

  • settle is now declared in sig/restate.rbs (it lives in a small Settleable module included by DurableFuture and CombinedFuture), which should clear the steep check errors.
  • CombinedFuture#resolve_combined! goes through the same settle, so a second await after a non-terminal child failure re-raises instead of returning nil. Added a spec awaiting a combined future twice over a child with a failing serde.

The two red checks fail at the actions lockfile step (the dtolnay/rust-toolchain@stable pin moved), before any Ruby runs, so they are unrelated to this change.

This follow-up was prepared with Claude Code (AI) and submitted by the account owner; the spec file passes locally (the new CombinedFuture example fails on 0dd1e77 and passes here) and RuboCop is clean on the touched files; steep check could not be run locally, so CI is its first run.

This branch has not been deployed

No deployments
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