Repository navigation
feat(compute): Morph microVM backend + pre-warm pool for the computer plane - #953
Merged
Merged
Conversation
… plane Adds Morph (morph.so) as a 5th compute-plane backend alongside local/modal/e2b/daytona, plus a pre-warm pool that eliminates cold-start latency. This is the legitimate latency/reliability use of Morph's instant- snapshot microVMs — it has nothing to do with bot-detection. - gym/morph_impl.MorphComputerImpl(RemoteComputerImpl): mirrors E2BComputerImpl — start an instance from a snapshot, expose its HTTP service, await /health, delegate the screenshot+xdotool wire to RemoteComputerImpl, tear down on close(). Two modes: provision (fresh) or claim (pre-booted instance+base_url from the pool, not torn down on close). All morphcloud-SDK calls isolated in injectable, getattr-guarded helpers so tests use a fake SDK. - gym/morph_prewarm_pool.MorphPrewarmPool: keeps `size` booted+health-checked instances ready; acquire() pops one instantly + refills in the background; release()/drain() stop instances (single-use — runs mutate VM state). - computer_client: backend="morph" dispatch (claim from cfg.morph_pool when set, else provision from cfg.morph_snapshot_id); new config fields threaded through resolve_for_executor; "morph" added to the ComputerPlaneBackend Literal. - pyproject: optional `morph` extra (morphcloud). Tests: test_morph_impl.py (5) + test_morph_prewarm_pool.py (5) — provision/ claim/timeout-teardown/missing-creds; pool top_up/acquire-hot/cold-miss/release/ drain. 54 compute-plane tests green; ruff clean. Activation (operational follow-up, not in this PR): build a Morph snapshot of the computer-plane image (Xvfb+Chrome+screenshot/xdotool service on :8000 with /health), set MANTIS_MORPH_SNAPSHOT + MORPH_API_KEY, construct a MorphPrewarmPool at server startup, and set backend="morph". Verify the exact morphcloud SDK method names against the installed version first. Co-Authored-By: Claude Opus 4.8 (1M context) <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.
What
Adds Morph (morph.so) as a 5th compute-plane backend (
local/modal/e2b/daytona/morph), plus a pre-warm pool that eliminates cold-startlatency. This is the legitimate latency/reliability use of Morph's instant-
snapshot microVMs — explicitly not anything to do with bot-detection.
Pieces
gym/morph_impl.MorphComputerImpl(extendsRemoteComputerImpl, mirrorsE2BComputerImpl): start an instance from a snapshot → expose HTTP service →await
/health→ delegate the screenshot+xdotool wire. Two modes:close()instance+base_urlfrom the pool (pool owns itslifecycle, not torn down by the run)
All morphcloud-SDK calls are isolated in injectable,
getattr-guarded helpers→ tests use a fake SDK, zero real API calls.
gym/morph_prewarm_pool.MorphPrewarmPool: keepssizebooted +health-checked instances ready;
acquire()pops one instantly + refills inthe background;
release()/drain()stop instances (single-use — a runmutates VM state).
refill_async=Falsefor deterministic tests.computer_client:backend="morph"dispatch (claim frommorph_poolwhen set, else provision from
morph_snapshot_id); config fields threadedthrough
resolve_for_executor.pyproject: optionalmorphextra.Tests
test_morph_impl.py(5) +test_morph_prewarm_pool.py(5): provision / claim /health-timeout-teardown / missing-creds; pool top_up / acquire-hot /
cold-miss / release / drain. 54 compute-plane tests green;
ruffclean.Activation (operational follow-up — not in this PR)
This backend is inert until selected (default stays
local/modal). To turnit on: build a Morph snapshot of the computer-plane image (Xvfb + Chrome +
screenshot/xdotool service on
:8000with/health), setMANTIS_MORPH_SNAPSHOT+MORPH_API_KEY, construct aMorphPrewarmPoolatserver startup, and set
backend="morph". Verify the exactmorphcloudSDKmethod names against the installed version first — they're isolated in the
helpers, so any drift is a one-line fix.
🤖 Generated with Claude Code