Repository navigation
computer: Give host module calls an execution id, log and defer - #247
Draft
mattzcarey wants to merge 1 commit into
Draft
mattzcarey wants to merge 1 commit into
mattzcarey wants to merge 1 commit into
Conversation
A host module that holds something for the length of a run, such as a connection to a browser, had no way to tell which run a call came from or when that run ended. It also had no way to tell the caller about something its return value can't carry, like the remote end having restarted since the last run. Every host module call's context now has the run's executionId, a log function that writes a line to the run's standard error, and a defer function that registers cleanup. Deferred functions run however the run ends, after its code has finished and its host calls have settled, and before its result is published, so the next run sees whatever they saved. They run one at a time, last registered first, each within the host call deadline. A failure is reported on standard error and the rest still run. Log lines have their own maxStdioBytes budget.
馃 Changeset detectedLatest commit: 2dbb36a The changes in this PR will be included in the next version bump. This PR includes changesets to release 4 packages
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
| expect(start.status).toBe(200); | ||
| const probe = (name: string) => | ||
| runtime({ | ||
| source: `import { ${name} } from "ws:lifecycle"; export default () => ${name}(${JSON.stringify(id)});`, |
commit: |
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.
Every host module call's context now has
executionId,log(text)anddefer(fn). A module can keep state for one run, clean it up when the run ends, and tell the caller things its return value can't carry.agents/browseris moving off@cloudflare/codemodeto become a host module (ws:browser) thatexeccode imports. Its CDP connector needs three things host modules didn't have:exec's result belongs to Computer, so the module writes those lines to standard error.Deferred functions run however the run ends. They start after the code has finished and its host calls have settled, and finish before the result is published, so the next run sees what they saved. They run one at a time, last registered first, each within the host call deadline. A failure is reported on standard error and the rest still run. Log lines have their own
maxStdioBytesbudget.docs/17_isolate_javascript.mdcovers this under host modules.npm testinpackages/computerandnpm run checkran. New workerd tests cover the id, logging, and deferred functions on success, failure, cancellation and a throwing deferred function. The deferred tests fail withrunDeferredturned off.This touches
bridge.tsand the hand-built test contexts that #238 also changes, so whichever lands second needs a small rebase. Under #238's replay, a deferred function should run once, on the attempt that settles.