Repository navigation
Launch the vendor runtime lazily: handshake with no runtime, launch at the first call (board #105) - #106
Merged
Conversation
Codex Review SummaryThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
cua serve answers initialize and tools/list from the runtime's recorded handshake (state/handshake/<release>), launches the runtime on the first js/js_reset and keeps it for the connection. A record miss launches at the handshake as before and records the answers. The MAWS hello wait moves from serve start to the launch; sandbox checks stay at the open on the planned launch. A close abandons a launch that has not spawned yet.
…s, clean unlaunched close A counting prepareLaunch proves no launch for the handshake, tools/list, ping, secrets_list, devices_list, a no-op end_task and profiles_list's registry part; one at the first js and none at the second. Real cua serve processes with a recorded handshake exit 0 on EOF, SIGTERM, SIGINT and SIGHUP with nothing launched or left. The MAWS hello wait now gates the launch, not the handshake.
README: the first call carries the launch, a Process footprint note, the MAWS hello wait at the launch, agent sessions and state/handshake in CUA_HOME. Spec Decision Log: board #105 with the live scratch-home check.
…med per connection A plain session records; a MAWS session with its own host notes replays the same record with no launch and gets its own instructions and the MAWS rule in profiles_list. The record carries none of cua's tools, host notes or js rules.
SSFSKIM
force-pushed
the
feat/lazy-runtime
branch
from
October 10, 2026 10:04
e2e8132 to
ac2504e
Compare
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.
Board #105. Every Claude Code session starts its plugin MCP servers at launch, and
cua serveused to launch the vendor runtime (cua_node, node_repl, sandbox) inopenConnection, before any call: one idle stack per open session. Now the runtime launches lazily.What changes
src/mcp/lazy-runtime.mjs(new). It is an upstream forcreateServerwith the same send/onMessage/onExit/terminate shape asspawnUpstream, with the launch behind it.initializeandtools/listare answered from a record of the runtime's own answers, kept under$CUA_HOME/state/handshake/<release>/<surfaces>@<protocolVersion>.json. The record is written atomically on the first live handshake. A record miss (the first connection after an install, or a new client protocol version) launches at the handshake as before and records the answers.tools/callthat reaches the runtime (js,js_reset, or theturn_endedof a task such a call opened). The runtime is opened with the client's owninitializeparams, and cua sendsnotifications/initializeditself, so the client's is never forwarded. Calls arriving during the launch are held in order.pingis answered locally, other requests get-32601, and notifications are dropped.cua: the runtime could not be started (<code>): …), then fails the connection.connection_closing, and their task completes with nothing to tell a runtime.terminateof a connection that never launched confirms{confirmed: true, steps: []}.openConnection. It still resolves the runtime, claims the run entry, resolves secrets and runs the sandbox checks (assertSandboxFits,assertSandboxConfines) at open, against the planned launch. A misconfiguration therefore still fails before the handshake.buildLaunch→prepareLaunch→ mkdir →spawnUpstreammoved into the lazystart;prepareLaunchis called once per launch.servestill dials the backends at start. ThewaitForHellosmoved fromserveinto the launch, so the launch keeps preferring the first backend's instance. The wait is abandoned at close.createServerchanged by one line:upstream.closing?.()at the start of close. The HTTP agent goes throughopenConnectiontoo, so its sessions are lazy as well (README updated).state/handshakein theCUA_HOMErow. Spec Decision Log: board cua serve launches the vendor runtime lazily, on the first call that needs it #105.--disable-sigusr1shim args.Why a record rather than a rebuilt tool list
The vendor launcher builds the
js/js_resetdescriptions from its instruction files. The input schemas and theinitializeresult, though, come from thenode_replbinary. A rebuilt answer could drift from what the runtime would say; a record of the runtime's own answers is exact by construction. The cost is one launch at the handshake per release, surface set and protocol version.Verification
New
test/serve-lazy.test.mjsuses a countingprepareLaunchwith in-processserveand a scratchCUA_HOMErunning the fake upstream. It proves:initialize,tools/list,ping,secrets_list,devices_list, a no-opend_taskandprofiles_list's registry part.js, whose answer is unchanged; none at the secondjs.initialize(the client's params), thennotifications/initializedonce, then the call.cua serveprocesses with a recorded handshake exit 0 on EOF, SIGTERM, SIGINT and SIGHUP, with no launch, no stderr and an emptyrun/.Live check: a scratch
CUA_HOME(an APFS clone of the installed 26.928.40906 release) with a scratchHOME, browser surface, realbin/cua.mjs serve:[email protected].initializeandtools/listwere identical to the cold ones.jslaunched the runtime and returned the API document (19,776 chars); the second returned4;end_taskreturnedended; exit 0;run/empty.The handshake record holds only the runtime's raw
initialize/tools/listanswers (lazy-runtime.mjs:record = {initialize: pendingRecord.initialize, tools: msg.result}, taken from the runtime's reply before createServer rewrites it). cua's per-connection transforms (withHostNotes, server.mjs:250;modelTools(..., {surfaces, platform, devices, inAppBrowser}), server.mjs:252) are applied to every reply, recorded or live. This is pinned by the test 'the record is the runtime's raw answers; a MAWS session and a plain one replaying it each get their own descriptions'.Gates on the rebased head (
HOME=<scratch>):(The validate warning was already on main.)
Review
An independent review (doperpowers reviewer-medium) found three issues, all fixed in 6c95622:
jsheld forever. A handshake that cannot be sent now fails the launch withruntime_exited.profiles_listnow waits for the MAWS hellos, which the handshake no longer does. Before this, aprofiles_listarriving before the first hello could reportmaws_unreachablewhile MAWS was up.Out of scope
cua install/cua runtime use, so that even the first connection of a release launches nothing.scripts/accept-native.mjs) was not run: it drives the owner's GUI with the real home. The live check above covered the browser surface with scratch homes.