Skip to content

Recover a buffered turn when the process that owns its timer dies #6

Description

@luantaraschi

The README states this limitation where somebody can find it, and it is the most
interesting open problem in the library:

with the facade, timers live in the process that received the message. If that process
dies with a turn buffered, the turn waits for the next message instead of firing on
time.

The state is safe: it is in the store, buffer and firstBufferedAt included. What is
lost is the setTimeout that was going to close it, so the answer arrives late, whenever
the person happens to say something else.

What a solution has to respect

  • The core stays pure. src/core returns schedule as data and creates no timers.
    Whatever recovers a turn belongs in the runtime or in a store, never in the reducer.
  • No runtime dependencies.
  • More than one process. Two instances must not both emit the same conversation's
    turn, so whatever recovers it takes the same per-conversation lock everything else
    takes.

Directions

  • A sweep on an interval, asking the store for conversations whose deadline has passed.
    This needs the store to answer a question it cannot answer today: Store has no way to
    list anything. That is the design decision to make first, and it is not a small one.
  • Leave it to the deployment and document the shape. examples/serverless.ts already
    delegates the tick to an external scheduler, and the answer for the facade may be to
    say so louder rather than to build a sweeper.

Comments are welcome before code. This one is worth agreeing on before anybody writes
it.

Metadata

Metadata

Assignees

No one assigned

    Labels

    help wantedExtra attention is needed

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions