Repository navigation
Reuse finished Environment preparation across Sessions - #808
Merged
Merged
Conversation
Core computes a key from the Project, initial files and setup operations and calls RestorePreparation/SavePreparation on the Provider. On a hit only finalize runs. The microsandbox helper owns storage, a 24 hour TTL and an 8 GiB bound. The daemon rebinds an identical restored capability installation.
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 users see
Core may start a hosted Environment from the result of an earlier preparation in the same Project whose effective configuration, after Template composition, is identical, for up to 24 hours after that preparation. Each Session still gets its own copy. Setup commands and package installation then do not run again for this Session. Only
/environmentis reused; HOME and other compute-local changes are not. Setup must not create per-Session unique values, perform external side effects that must happen per Session, or fetch credentials that expire within 24 hours; configurations that need this must differ (for example inenvorfiles). Providers that do not declare the operations (Docker, E2B) always prepare in full. There is no setting, no/v1or OpenAPI change and no management API.Key
SHA-256 hex of: the tenant ID, then each initial file's (path, sha256 of body), then each setup operation's request (JSON) and sha256 of its data. It excludes Environment, Session, Harness and Agent. Network policy is not part of it: preparation always uses the host network and Core rejects non-enabled effective network for Sessions. Core never interprets the key beyond computing it.
Changes
RestorePreparation(ref, key) (bool, error)andSavePreparation(ref, key), declared Supported or Unsupported together in each adapter's operations file. Both address the initial compute, because compute state is empty until initialization completes. Docker and E2B declare Unsupported.restore_preparation(key->restored) andsave_preparation(key), both fields added to the strict frame decoder (generation_json.go) with a round-trip test. Protocol version unchanged; the fields are additive.runtime_preparation_cache.go,runtime_initialization.go): a hit skips the file and setup operations but still sendsfinalize; a miss prepares and then saves; a save error is logged and does not fail the Session; a restore error fails preparation.preparation.go): all storage, TTL and seeding. One tar archive ofinitialization,packagesandworkspaceunder/environment(neverruntime-state, which holds the running daemon's Codex home, Claude SDK history and completion markers) per (key, image digest, workspace mode) in a private directory under the Runtime home, valid 24 hours, pruned past the TTL and then oldest first above 8 GiB. The bound exists because the TTL alone does not limit disk on a busy node; a measured archive is tens of MiB (51 MiB real, 200 MiB synthetic), so 8 GiB holds over a hundred. Owned disk goes through guest tar and the SDK file copy; an NFS bind goes through host tar with xattrs preserved. An entry that fails to extract is deleted, so only that Session fails. The save gets at most half of the remaining preparation budget, so it never takes the time completion needs.installed.jsonidentity to the current Session when the selection hash is identical, and still rejects a different selection. One existing test that expected an identity-only mismatch to fail now uses a changed selection.Measured
Copy throughput (mx2, real Environment: 51 MiB, about 320 files, one 47 MiB binary):
End to end on mx (fresh install of e01726b, microsandbox node mx2 with NFS workspace storage, one Template with an npm package, a setup command, an initial file, a Skill and env):
Every Turn saw the package, the setup output, the initial file and the Skill. The store is 0700 with 0600 entries owned by the node user, and an entry holds only
initialization/,packages/andworkspace/. Hosted regression: codex 9/9 and claude_sdk 9/9. The first e2e run (b336d80) found the strict frame decoder rejecting the new fields; fixed in e01726b.Tests
Core: hit, miss and failed save. Daemon: finalize rebinds an identical restored installation and rejects a different selection. Helper: an expired entry is not restored. Node: preparation request and response frames survive strict decoding. Failure paths (failed extract, save budget) were not exercised on a real VM.
Need help on this PR? Tag
@codesmith-botwith what you need.