Skip to content

computer: Tell host module calls which execution they belong to - #290

Open
ben-reitz wants to merge 1 commit into
browser/response-valuesfrom
browser/execution-context
Open

ben-reitz wants to merge 1 commit into
browser/response-valuesfrom
browser/execution-context

Conversation

@ben-reitz

@ben-reitz ben-reitz commented Nov 2, 2026 •

Copy link
Copy Markdown
Contributor

A host module can't tell which run a call came from. A module that keeps per-run state, such as one browser session per run, has nothing to key it on: callId changes on every call.

Every host module call now gets context.execution, a frozen { id }. Every call of one run gets the same value, and a replayable run keeps it when it resumes after a restart or an answer. A module's functions belong to one backend connection, so the id alone tells its runs apart.

modules: {
  "codemode:session": {
    open: (_args, { execution }) => sessions.open(execution.id),
  },
}

The bridge now takes the execution rather than a bare call id prefix and still builds callId from its id, so call ids don't change. A bridge test checks that every call of a run gets the same frozen value, and a workerd test restarts the object mid-run and checks that calls before and after the restart see the same execution. The host module context table in docs/17_isolate_javascript.md lists the new field.

@github-actions github-actions Bot closed this Nov 2, 2026
@changeset-bot

changeset-bot Bot commented Nov 2, 2026 •

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: 77b68d2

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 4 packages
Name Type
@cloudflare/computer Minor
@cloudflare/dofs Minor
@cloudflare/computer-rpc Minor
@cloudflare/computerd Minor

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

@ben-reitz ben-reitz added the allow-pr Allow a PR to remain open. label Nov 2, 2026
@ben-reitz ben-reitz reopened this Nov 2, 2026
@ben-reitz
ben-reitz added this pull request to stack #294 November 2, 2026 17:27
@pkg-pr-new

pkg-pr-new Bot commented Nov 2, 2026 •

Copy link
Copy Markdown

Open in StackBlitz

npm i https://pkg.pr.new/@cloudflare/computer@290

commit: 77b68d2

@ben-reitz
ben-reitz force-pushed the browser/execution-context branch from 38a32b2 to 9431033 Compare November 3, 2026 10:00
@ben-reitz
ben-reitz marked this pull request as ready for review November 3, 2026 10:02
devin-ai-integration[bot]

This comment was marked as resolved.

@ben-reitz
ben-reitz force-pushed the browser/execution-context branch 2 times, most recently from 2661e4e to a8a565a Compare November 3, 2026 11:31
devin-ai-integration[bot]

This comment was marked as resolved.

@cloudflare cloudflare deleted a comment from github-actions Bot Nov 3, 2026
@ben-reitz
ben-reitz force-pushed the browser/execution-context branch from a8a565a to aad50d5 Compare November 3, 2026 11:50
@aron-cf
aron-cf force-pushed the browser/execution-context branch from aad50d5 to 04b2aec Compare November 3, 2026 14:17
@ben-reitz
ben-reitz removed this pull request from stack #294 November 4, 2026 10:44
@ben-reitz
ben-reitz added this pull request to stack #304 November 4, 2026 10:50
A host module that keeps state per run, such as a connection it opens
on a run's first call and closes when the run ends, needs to know
which run a call came from. The execution id was only reachable as
the undocumented prefix of `callId`.

Every host module call now gets `context.execution`, a frozen `{ id }`
that is the same for every call of one run. Ids are unique within one
backend, and a module's functions are per backend connection, so the
id alone tells the module's runs apart. The bridge takes the execution
in place of the bare call id prefix and still builds `callId` from its
id. A replayable run keeps its execution id when it resumes, so the
value stays the same across an interruption or an answer.
@ben-reitz
ben-reitz force-pushed the browser/execution-context branch from 04b2aec to 77b68d2 Compare November 4, 2026 10:55
@ben-reitz
ben-reitz removed this pull request from stack #304 November 4, 2026 13:38
@ben-reitz
ben-reitz added this pull request to stack #306 November 4, 2026 13:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

allow-pr Allow a PR to remain open.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant