Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions docs/src/content/docs/durable/overview.md
Original file line number Diff line number Diff line change
Expand Up @@ -165,8 +165,12 @@ owner holds the instance, so stop. `Recover` retries an unapplied effect, and re
## A note on serialized payloads

Events, service done-data, actor done-data, and actor messages are recorded as their
JSON form. A parent reducer that type-asserts a non-JSON Go type from `AssignCtx.Event`
observes the JSON-decoded shape of actor done-data on a replayed `onDone`. A service's
JSON form. An actor's done-data gets the same decode a service's result does, live
as on replay: when `WithEventDataDecoder` covers the parent's `onDone` event it
arrives as the decoder's type, and without one it arrives in JSON's generic form —
a struct as a map and an integer as a `float64`, which loses precision above 2^53
— so a reducer that type-asserts a non-JSON Go type from `AssignCtx.Event` sees the
same generic form both ways. A service's
result is decoded from its JSON form live as well as on replay, so a reducer gets the same
value both ways. When `WithEventDataDecoder` covers the invocation's `onDone` event, the
result arrives as the decoder's type, for example `durable.DecodeAs[User]`. Otherwise it
Expand Down
85 changes: 74 additions & 11 deletions durable/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,14 @@ and this module adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.

### Added

- **`WithResultTypeAlias`** tells the Runner that a service result type the journal
recorded under one full Go type name now goes by another, so a result settled or
parked under the old name still replays after a pure refactor moves or renames the
type: `Recover`, `StateAt` and a `RunService` that settles a recorded result accept
the decoded value when its type is the one the alias names, and every other recorded
name is held to strictly, exactly as before. A parked result the Handle itself holds
- **`WithResultTypeAlias`** tells the Runner that a service result type, or an actor
Comment thread
reka18 marked this conversation as resolved.
Resolved
done-data type, the journal recorded under one full Go type name now goes by another,
so a result settled or parked under the old name, and an actor's done-data settled
under it, still replay after a pure refactor moves or renames the type: `Recover`,
`StateAt` and a `RunService` that settles a recorded result, and the replay of a
recorded actor's done-data — from the journal, a checkpoint's tail or `StateAt` —
accept the decoded value when its type is the one the alias names, and every other
recorded name is held to strictly, exactly as before. A parked result the Handle itself holds
is still held to its own type, as live. The option takes the recorded name and a
value of the type the name now means, can be repeated for several renames, and maps
one hop, never chaining through another alias. One recorded name given for two
Expand Down Expand Up @@ -208,6 +210,49 @@ and this module adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.
settled, fails replay under one; a decoder that returns JSON's generic form for that
event settles or replays it. A parked Record or checkpoint is new to this version: an
older `durable` replays a parked Record as a settled result.
- **An actor's done-data and error reach `Assign` as the live run delivered them,**
through the same decode a service result and a `WithEventData` payload get, so a
retried effect can't differ from the first attempt. This is a behavior change for
callers that read the outcome from `AssignCtx.Event`: without a decoder, a live
onDone `Assign` now sees JSON's generic form — a struct becomes a map, an integer a
`float64` — where main handed it the actor's own Go value, and an error is
message-only, so `errors.Is` and `errors.As` in an onError `Assign` stop matching
what the actor returned. `WithEventDataDecoder` for the parent's onDone (and
onError) event is the opt-out: it hands `Assign` the decoded type, live as the
settle routes it and as replay re-fires it (#256). On main, `Assign` saw the actor's
own Go value live and JSON's generic form on replay. The journal records the JSON the live settle decoded
and the done-data's Go type, with its import path, and replay holds the decoder to the
type as the live settle did, failing `Recover` and `StateAt` with `ErrEventDataEncoding`
when the decoder returns another type; JSON's generic form, and nil, are always
accepted. An actor's error is message-only live and on replay: an error with the same
message, any invalid UTF-8 replaced, which `errors.Is` and `errors.As` no longer match.
An error whose `Error` method panics, such as a typed nil, settles with a message
saying the actor error panicked, its invalid UTF-8 replaced, rather than the panic
failing the Handle or crashing the host, live and on replay alike.
- **There is no parking for an actor outcome.** A done-data payload that won't decode,
or decodes as another type than the actor produced, aborts the settle through the new
`ActorSystem.WithSettleTransform` before it fires anything, so no `Assign` runs, and
`DeliverToActor` — and the `Fire` or `Tick` whose absorb drove the settle — fail the
Handle with `ErrHandleFailed` wrapping `ErrEventDataEncoding` and record nothing, so
a recovered Handle runs the actor from its initial state and the delivery again. A
`RunService` whose settle's absorb drove such a settle fails the Handle the same
way but records the service's own settle first — the ServiceFn ran and its result
decoded, so the journal holds it before the actor's settle is attempted — keeping
the parking design's "never runs again" promise: a recovered Handle re-settles the
service from the journal and never runs its ServiceFn again across any number of
Recover-and-retry rounds; only the actor re-runs. An actor outcome is never parked,
as a service result that won't decode is, because the service already ran but the
actor can run again. The
transform runs only when the settle routes a completion — the actor's spawn wired
the onDone an output settles through or the onError a failure does; a settle that
routes nothing consults no decoder, journals nothing, and can't fail the step. On
main such a settle fired the zero event its unset outcome leaves, which the parent
refused; an invoked actor that declared no onDone now routes nothing at all (see
`state`'s declared-outcome routing), so nothing is journaled for its settles where
main journaled a refused fire. `Start` and
`Recover` fail the same way when a settle their spawns drive aborts; no Handle
exists yet, so their error wraps `ErrEventDataEncoding` directly. A done-data
payload with no JSON form fails the Handle the same way, before any `Assign` runs.
- **A step that may not have been recorded fails the Handle.** That call and every later
one return `ErrHandleFailed`, wrapping the cause. A step that was recorded while
another goroutine failed the Handle also returns `ErrHandleFailed`, saying the step was
Expand Down Expand Up @@ -251,6 +296,22 @@ and this module adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.

### Fixed

- **A settle a respawn drops runs no transform.** The drop a host's respawn replay
makes (`AbsorbRespawn`) was decided after the settle transform ran, so a respawned
nested child whose output differed from its first spawn's — a time, a random id,
or any value with no JSON form — aborted the settle and failed `Recover`
(`Start`'s spawns the same way) for a settle that is thrown away whole: nothing
fires for it and nothing is journaled. The drop is now decided before the
transform, so a dropped settle consults no decoder and can abort nothing, and
`Recover` succeeds whatever the respawn's outcome encodes as.
- **The recorded data of an actor fire that was refused is never decoded.** A journal
an older version wrote can hold a settle whose parent Fire was refused — the
zero-event settle of an `InvokeActor` that declared no onDone — with its done-data
recorded and no recorded type. Replay sent that data through the event-data decoder
for the refused event before re-firing it, so a strict decoder failed `Recover` and
`StateAt` on histories that recovered fine on main. The data of a fire whose replay
will be refused is never read: replay now re-fires the recorded event plainly and
meets the same refusal.
- **A timer transition starts and stops services and actors.** `Tick` handed a fired
timer transition's effects only to the scheduler, so a timer that left a state left
its service in flight and its actor running, and one that entered a state started no
Expand Down Expand Up @@ -447,11 +508,13 @@ and this module adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.
already records it, and replay meets it again — so the actor counts as ended and
`Recover` leaves it alone. A spawn whose onError a context's ending refused still
retries, since the step that drove it records nothing, as does one with no onError
declared, as before. An invoked actor with no onError fires the zero event, which the
parent refuses as having no transition, and `durable` reads that refusal
(`state.ErrNoTransition`) as "none declared". So a declared onError the parent has no
transition for retries too, and a wildcard or a transition that takes the zero event
counts as caught; #250 tracks a better way to tell them apart. A host refusal worded
declared, as before: an invoked actor with no onError escalates rather than firing
(see the Changed entry on declared-outcome routing), so it needs no refusal to tell
it apart. A declared onError the parent has no
transition for still fires and is refused with `state.ErrNoTransition`, which
`durable` reads as "nothing caught the failure"; a wildcard or a transition that
takes the declared event counts as caught; #250 tracks a better way to tell a
declared-but-unroutable onError from a handled one. A host refusal worded
like the kernel's counts as handled.
- **A message an actor sends its parent as it spawns applies once.** A `Fire`,
`RunService`, `Start` or `Recover` didn't journal it, and `Recover` spawned the actor
Expand Down
20 changes: 14 additions & 6 deletions durable/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -179,10 +179,9 @@ owner holds the instance, so stop. `Recover` retries an unapplied effect, and re
## Caveat: serialized payloads

Events, service done-data, actor done-data, and actor messages are recorded as their
JSON form. A parent reducer that type-asserts a non-JSON Go type from `AssignCtx.Event`
observes the JSON-decoded shape of actor done-data on a replayed `onDone`. A service's
result is decoded from its JSON form live as well as on replay, so a reducer gets the same
value both ways. When `WithEventDataDecoder` covers the invocation's `onDone` event, the
JSON form. A service's result is decoded from its JSON form live as well as on replay,
so a reducer gets the same value both ways. When `WithEventDataDecoder` covers the
invocation's `onDone` event, the
result arrives as the decoder's type, for example `durable.DecodeAs[User]`. Otherwise it
arrives in JSON's generic form: a struct as a map and an integer as a `float64`, which
loses precision above 2^53. A decoder that fails, or that returns a type other than the
Expand All @@ -197,8 +196,17 @@ leaves the state that declares the service stops the service and discards it. A
longer matches. Register the decoder before you record results: replay decodes the journal
with the recovering Runner's decoder, so a decoder added or changed after results were
recorded changes what replay hands the reducer, and one that can't decode a settled result
fails `Recover` and `StateAt` with `ErrEventDataEncoding`; a parked one doesn't fail them. A
type moved or renamed after its results were recorded replays under its new name once
fails `Recover` and `StateAt` with `ErrEventDataEncoding`; a parked one doesn't fail them. An
actor's done-data gets the same decode, live as on replay: when the decoder covers the
parent's `onDone` event it arrives as the decoder's type, and without one in JSON's
generic form, a struct as a map and an integer as a `float64`. An actor's error is
message-only too, any invalid UTF-8 replaced, and one whose `Error` method panics
settles with a message saying so. A done-data payload that won't decode, or that decodes
as a type other than the actor produced, is never parked: the settle fires nothing,
`DeliverToActor` fails the Handle with `ErrEventDataEncoding` wrapped in
`ErrHandleFailed`, nothing is recorded, and a `Recover` runs the actor again. A
type moved or renamed after its results — or an actor's done-data — were recorded
replays under its new name once
told to the Runner with `WithResultTypeAlias`. A
`WithEventData` payload is decoded from its JSON form live as well as on replay, so a
reducer gets the same value both ways. `WithEventDataDecoder` decodes it as the type the caller passed, chosen per
Expand Down
Loading
Loading