Skip to content

Don't drop commands sent while a transition runs - #10

Merged
phatshambler merged 2 commits into
developfrom
fix/queue-commands-during-transition
Nov 17, 2026
Merged

phatshambler merged 2 commits into
developfrom
fix/queue-commands-during-transition

Conversation

@phatshambler

Copy link
Copy Markdown
Member

Commands sent to the app while a state transition runs are no longer lost, and a slow output no longer holds the show.

Found while testing lni-votes on 0.0.45 with unreachable PubNub keys: POST /api/cues/vote-2 during a cue transition logged Pending transition: cue from: cued to: cued and did nothing.

Before

  • onCue awaited sendCueToOutputs, onUncue awaited the uncue command, and onAfterTransition awaited the state command: a transition lasted as long as the slowest output (up to 15 s for a PubNub publish that fails).
  • A command that came meanwhile (a second cue from the operator, uncue, end, the after_duration cue, restart…) hit javascript-state-machine's pending transition. onPendingTransition returned a promise that only resolved for init: the command was dropped, and its promise never settled.
  • Even without a slow output, the window existed while the store saved (MySQL).

After

  • Transitions run one after the other. start, stop, end, cue, uncue, init and destroy go through Application#runTransition(), a promise chain: each one starts once the previous one has ended, in the order they came. A failed transition doesn't block the next ones; its caller still gets the failure. start()'s "init first" check and cue()'s "does this cue exist" check now run inside the queued transition, against the state at that time.
  • Transitions don't wait for the outputs. The cue, uncue and state messages are sent like the other messages already were (cues, start, stop, end, interact…): without waiting for an answer. sendToOutputs still catches and logs failures. So a second cue sent during an unreachable PubNub runs right away instead of 15 s later.
  • Order per output is kept. Transitions are serialized and each one calls the outputs synchronously in order, so an output is still called with cue before the state that follows it, then the next cue… Outputs that need delivery order on the wire queue their own requests, as @cuecue/pingpong already does. @cuecue/pubnub and @cuecue/http send each message as its own request, like they already did for interactions.

Hooks never wait for a transition (the session recovery in onIdle and the cue durations call cue()/end()/uncue() without awaiting them inside a transition), so the queue can't deadlock; runTransition() documents that rule.

Tests

New Application commands during a transition tests, which all fail on develop (timeouts or missing messages) and pass with the fix:

  • a transition settles while an output never answers;
  • a second cue sent while the first waits for its outputs runs, and its promise settles;
  • five commands from an input sent at once, with a store that takes time to save, all run in order (cue, cue, uncue, cue, end) without errors;
  • an output gets cue intro, state cued, cue vote, state cued, uncue, state idle, in that order;
  • restart() during a cue waits for it.

HttpOutput's "the app logs the failures" test now waits for the failure with vi.waitFor, since cue() no longer waits for the request.

Locally (Node 24): 146 passed, 6 skipped (MySQL, run by the test-mysql job). Lint and Prettier pass. Changeset: @cuecue/app patch.

🤖 Generated with Claude Code

phatshambler and others added 2 commits November 17, 2026 11:30
A command sent while a transition ran (a second cue, an uncue, an end)
hit the state machine's pending transition and was dropped, with a
promise that never settled. Transitions lasted as long as the slowest
output, up to PubNub's 15 s timeout.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@phatshambler
phatshambler merged commit 56c79ea into develop Nov 17, 2026
4 checks passed
@phatshambler
phatshambler deleted the fix/queue-commands-during-transition branch November 17, 2026 18:45
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.

1 participant