Repository navigation
Start invoked work in the sender's turn - #250
Merged
Merged
Conversation
An invocation's work was hosted by a process whose worker was scheduled for a later turn, so even the synchronous first step of an invoked Effect ran after send returned. A browser call that needs user activation, such as window.open or clipboard.writeText, therefore ran outside the click. The hosting worker now starts immediately and runs until it first suspends, and the outcome is delivered to the machine one turn later. The entered state is always published before onDone or onFailure leaves it, and an outcome for a state exited in between is still discarded. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Contributor
Type performanceMeasured with TypeScript 6.0.3 and
Marginal instantiations are measured against the matching setup without that API call:
Check times (informational)
Type instantiations are the comparison metric. Check time varies with runner load and is informational only. |
Contributor
Runtime performanceMedian of 5 independent benchmark processes on Pull request baseline
Process runtime reference points
Effect Machine change from base
Process runtime reference change from base
Regression guardNo large, noise-adjusted throughput or heap regressions detected. Versions and interpretation
Higher throughput is better; lower heap is better. Variability is the median absolute deviation across independent processes, relative to their median. Small differences on shared GitHub-hosted hardware remain informational; the required guard rejects only large changes beyond the measured noise allowance. |
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.
Summary
sendreturned. A browser call that requires user activation (window.open,navigator.clipboard.writeText,HTMLMediaElement.play) therefore ran outside the click that sent the event; Chrome tolerates that through its activation window, stricter browsers block it.onDone/onFailureleaves it, a synchronous defect still fails the machine aftersendreturns, and a loop of instantly completing invocations still yields between steps. The outcome of a state exited in between is still discarded.runtimeGenericforks the hosted worker withstartImmediately(which also makes its trailingyieldNowunnecessary), andinvocation.tsdelivers outcomes behind oneyieldNow.Stream.callbackregisters in its own fiber.test/machine/InvocationTurn.test.tscovers both runtime strategies: invoked work and an invoked child's initial work start beforesendreturns (fail onmain), and the entered state is published first, outcomes of exited states are discarded, synchronous defects fail later, and instant-completion loops do not run insidesend(pass onmainand here).MachineRefJSDoc, the agent guide ("Let states own running work") and the Effect Atom guide ("Send without subscribing").Changeset
Minor: the timing of invoked work is observable (it now runs on the sender until it first suspends).
Validation
pnpm checkAlso checked against the consuming apps on a patched 0.45.1 build: creator-self-serve 357/357 tests, and in Chrome the Google sign-in popup opens within the click task (
falseon 0.45.1,truewith this change).🤖 Generated with Claude Code