Repository navigation
Don't drop commands sent while a transition runs - #10
Merged
Merged
Conversation
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>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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-2during acuetransition loggedPending transition: cue from: cued to: cuedand did nothing.Before
onCueawaitedsendCueToOutputs,onUncueawaited theuncuecommand, andonAfterTransitionawaited thestatecommand: a transition lasted as long as the slowest output (up to 15 s for a PubNub publish that fails).cuefrom the operator,uncue,end, theafter_durationcue,restart…) hit javascript-state-machine's pending transition.onPendingTransitionreturned a promise that only resolved forinit: the command was dropped, and its promise never settled.After
start,stop,end,cue,uncue,initanddestroygo throughApplication#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 andcue()'s "does this cue exist" check now run inside the queued transition, against the state at that time.cue,uncueandstatemessages are sent like the other messages already were (cues,start,stop,end,interact…): without waiting for an answer.sendToOutputsstill catches and logs failures. So a second cue sent during an unreachable PubNub runs right away instead of 15 s later.cuebefore thestatethat follows it, then the nextcue… Outputs that need delivery order on the wire queue their own requests, as@cuecue/pingpongalready does.@cuecue/pubnuband@cuecue/httpsend each message as its own request, like they already did for interactions.Hooks never wait for a transition (the session recovery in
onIdleand the cue durations callcue()/end()/uncue()without awaiting them inside a transition), so the queue can't deadlock;runTransition()documents that rule.Tests
New
Application commands during a transitiontests, which all fail ondevelop(timeouts or missing messages) and pass with the fix:cuesent while the first waits for its outputs runs, and its promise settles;cue,cue,uncue,cue,end) without errors;cue intro,state cued,cue vote,state cued,uncue,state idle, in that order;restart()during acuewaits for it.HttpOutput's "the app logs the failures" test now waits for the failure withvi.waitFor, sincecue()no longer waits for the request.Locally (Node 24): 146 passed, 6 skipped (MySQL, run by the
test-mysqljob). Lint and Prettier pass. Changeset:@cuecue/apppatch.🤖 Generated with Claude Code