Skip to content

Commit 07bbac7

Browse files
authored
Suspend and restore every deployment mode and pause E2B natively (#846)
* Suspend and restore every deployment mode and pause E2B natively * Carry suspend control in the Runtime bootstrap * Bump the node wire version for renew_compute * Fix the E2B checkpoint outcomes and helper docs * Unify renewal, gate capacity help on mode, and count running sandboxes without suspended ones * Refresh the sandbox provider translation hash * Declare checkpoint support in the execution test Providers * Exclude suspend control from the managed bootstrap projection check * Fail a stale E2B template at create * Settle an old pending E2B pause by observation * Report running sandboxes in the Web acceptance fixture * Fix the second review findings on checkpoint suspension Running compute renews its native lease under one condition, an open Runtime connection, which is the existing renewal condition. Sandbox metrics counts running sandboxes without suspended ones, and the Provider and deployment docs describe Bootstrap.SuspendControl and resources.running.
1 parent 3ad4e54 commit 07bbac7

97 files changed

Lines changed: 988 additions & 280 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

‎README.md‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ The OpenAI Agents API, open source and self-hosted. Run Codex, Claude Code or Mi
1717

1818
- **Same API as OpenAI.** Set `OPENAI_BASE_URL` and the [official OpenAI SDK](https://developers.openai.com/api/docs/libraries), or plain HTTP, works unchanged.
1919
- **Your agent, your model.** Each Session runs Codex, Claude Code or MiniMax Code natively, as it runs on your machine, with the model provider you configure. See [Harness capabilities](https://openagentcore.dev/contracts/agents-api/harness-capabilities).
20-
- **Compute that sleeps, workspaces that stay.** On microsandbox, which keeps every workspace on independent storage, idle sandboxes release compute and resume on a compatible node with their files intact. E2B, Docker and your own Linux, macOS or Windows machine also run Sessions. See [Sandbox Provider protocol](https://openagentcore.dev/docs/sandbox-provider).
20+
- **Compute that sleeps, workspaces that stay.** On microsandbox, which keeps every workspace on independent storage, idle sandboxes release compute and resume on a compatible node with their files intact. E2B pauses idle sandboxes in place. Docker and your own Linux, macOS or Windows machine also run Sessions. See [Sandbox Provider protocol](https://openagentcore.dev/docs/sandbox-provider).
2121
- **Replaceable parts.** Sandbox Providers, workspace filesystems, Harnesses and model providers plug in through [defined protocols](AGENTS.md#protocols-at-every-boundary).
2222

2323
![Deployment overview](docs/assets/console-overview-en.webp)

‎README.zh-CN.md‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717

1818
- **与 OpenAI 相同的 API。** 设置 `OPENAI_BASE_URL` 后,[官方 OpenAI SDK](https://developers.openai.com/api/docs/libraries)或直接的 HTTP 调用无需改动即可使用。
1919
- **你的 Agent,你的模型。** 每个 Session 原生运行 Codex、Claude Code 或 MiniMax Code,使用你配置的模型提供商,与在本机运行一致。详见 [Harness 能力](https://openagentcore.dev/zh/contracts/agents-api/harness-capabilities)。
20-
- **计算会休眠,工作区会保留。** 在 microsandbox 上(每个工作区都保存在独立存储中),空闲沙箱释放计算资源,并在兼容节点上带着文件恢复。E2B、Docker 以及你自己的 Linux、macOS 或 Windows 机器同样可以运行 Session。详见[沙箱提供商协议](https://openagentcore.dev/zh/docs/sandbox-provider)。
20+
- **计算会休眠,工作区会保留。** 在 microsandbox 上(每个工作区都保存在独立存储中),空闲沙箱释放计算资源,并在兼容节点上带着文件恢复。E2B 会就地暂停空闲沙箱。Docker 以及你自己的 Linux、macOS 或 Windows 机器同样可以运行 Session。详见[沙箱提供商协议](https://openagentcore.dev/zh/docs/sandbox-provider)。
2121
- **部件可替换。** 沙箱提供商、工作区文件系统、Harness 和模型提供商都通过[既定协议](AGENTS.md#protocols-at-every-boundary)接入。
2222

2323
![部署概览](docs/assets/console-overview-zh.webp)

‎apps/daemon/internal/cli/connect.go‎

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -69,11 +69,12 @@ func runConnect(ctx *runContext, args []string) error {
6969
return fmt.Errorf("connect: %w", err)
7070
}
7171
var bootstrapped *auth.Profile
72+
var suspendEnabled bool
7273
if *bootstrapFile != "" {
7374
if *remote != "" || *environment != "" || *credentialFile != "" || *workspace != "" || fs.NArg() != 0 {
7475
return errors.New("connect: bootstrap input cannot be combined with enrollment options")
7576
}
76-
bootstrapped, err = bootstrapProfile(*bootstrapFile)
77+
bootstrapped, suspendEnabled, err = bootstrapProfile(*bootstrapFile)
7778
if err != nil {
7879
return err
7980
}
@@ -118,7 +119,7 @@ func runConnect(ctx *runContext, args []string) error {
118119
}
119120
}
120121

121-
return mainLoop(ctx, *profile, prof, agentCLIs)
122+
return mainLoop(ctx, *profile, prof, agentCLIs, suspendEnabled)
122123
}
123124

124125
// spawnBackground forks the daemon into the background. Parent
@@ -189,11 +190,11 @@ func spawnBackground(ctx context.Context, rc *runContext, profile string, argv [
189190
// background process. SIGINT / SIGTERM cancels the root context, which
190191
// unblocks the read pump and any in-flight Send so the daemon exits
191192
// without orphaning agent subprocesses.
192-
func mainLoop(rc *runContext, profile string, prof auth.Profile, agentCLIs agentCLIDiscovery) error {
193-
return mainLoopRemote(context.Background(), rc, profile, prof, agentCLIs, "")
193+
func mainLoop(rc *runContext, profile string, prof auth.Profile, agentCLIs agentCLIDiscovery, suspend bool) error {
194+
return mainLoopRemote(context.Background(), rc, profile, prof, agentCLIs, "", suspend)
194195
}
195196

196-
func mainLoopRemote(parent context.Context, rc *runContext, profile string, prof auth.Profile, agentCLIs agentCLIDiscovery, remote string) error {
197+
func mainLoopRemote(parent context.Context, rc *runContext, profile string, prof auth.Profile, agentCLIs agentCLIDiscovery, remote string, suspend bool) error {
197198
// Route through obs/log so daemon log lines pick up the same
198199
// trace_id / span_id auto-injection as the server side — when the
199200
// daemon adopts an envelope's trace, every log call under that ctx
@@ -229,7 +230,7 @@ func mainLoopRemote(parent context.Context, rc *runContext, profile string, prof
229230
registry := agent.NewRegistry()
230231
registerAgentKinds(registry, agentCLIs)
231232

232-
control, err := newSuspendControl()
233+
control, err := newSuspendControl(suspend)
233234
if err != nil {
234235
return err
235236
}

‎apps/daemon/internal/cli/connect_bootstrap.go‎

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,17 +10,17 @@ import (
1010

1111
// The launch file is the sole credential source for this connection. Reopening
1212
// it on process restart never reads or overwrites an auth profile.
13-
func bootstrapProfile(path string) (*auth.Profile, error) {
13+
func bootstrapProfile(path string) (*auth.Profile, bool, error) {
1414
raw, err := runtimefs.ReadPrivatePath(path, runtimebootstrap.MaxBytes)
1515
if err != nil {
16-
return nil, errors.New("connect: Runtime bootstrap file unavailable")
16+
return nil, false, errors.New("connect: Runtime bootstrap file unavailable")
1717
}
1818
input, err := runtimebootstrap.Decode(raw)
1919
if err != nil {
20-
return nil, err
20+
return nil, false, err
2121
}
2222
if err = localworkspace.Bind(input.EnvironmentID, input.SessionID, input.Workspace, localworkspace.CapabilityDirectory); err != nil {
23-
return nil, errors.New("connect: Runtime workspace binding unavailable")
23+
return nil, false, errors.New("connect: Runtime workspace binding unavailable")
2424
}
25-
return &auth.Profile{ServerURL: input.CoreURL, RuntimeID: input.DeviceID, RunnerCredential: input.Credential}, nil
25+
return &auth.Profile{ServerURL: input.CoreURL, RuntimeID: input.DeviceID, RunnerCredential: input.Credential}, input.SuspendControl, nil
2626
}

‎apps/daemon/internal/cli/connect_bootstrap_test.go‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ func TestBootstrapConnectionDoesNotReadOrOverwritePrivateProfile(t *testing.T) {
4545
}
4646
t.Cleanup(localworkspace.Unbind)
4747
for range 2 {
48-
p, err := bootstrapProfile(path)
48+
p, _, err := bootstrapProfile(path)
4949
if err != nil || p.ServerURL != input.CoreURL || p.RuntimeID != input.DeviceID || p.RunnerCredential != input.Credential {
5050
t.Fatal("failed bootstrap/restart", err)
5151
}
@@ -60,13 +60,13 @@ func TestBootstrapConnectionDoesNotReadOrOverwritePrivateProfile(t *testing.T) {
6060
if err = os.WriteFile(path, []byte("bootstrap-secret"), 0600); err != nil {
6161
t.Fatal(err)
6262
}
63-
if _, err = bootstrapProfile(path); err == nil || strings.Contains(err.Error(), input.Credential) {
63+
if _, _, err = bootstrapProfile(path); err == nil || strings.Contains(err.Error(), input.Credential) {
6464
t.Fatal("invalid input fell back or leaked")
6565
}
6666
if err = os.Remove(path); err != nil {
6767
t.Fatal(err)
6868
}
69-
if _, err = bootstrapProfile(path); err == nil {
69+
if _, _, err = bootstrapProfile(path); err == nil {
7070
t.Fatal("missing input fell back to private auth")
7171
}
7272
}

‎apps/daemon/internal/cli/connect_environment.go‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -166,7 +166,7 @@ func runEnvironmentConnect(parent context.Context, rc *runContext, profile strin
166166
return err
167167
}
168168
prof := auth.Profile{ServerURL: base, RuntimeID: bound.DeviceID, RunnerCredential: credential}
169-
return rejected(mainLoopRemote(parent, rc, profile, prof, discovery, remote))
169+
return rejected(mainLoopRemote(parent, rc, profile, prof, discovery, remote, false))
170170
}
171171

172172
var (

‎apps/daemon/internal/cli/suspend_control.go‎

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,9 @@ import (
1414

1515
"github.com/MiniMax-AI/OpenAgentCore/apps/daemon/internal/localworkspace"
1616
"github.com/MiniMax-AI/OpenAgentCore/internal/agentdaemon/proto"
17+
"github.com/MiniMax-AI/OpenAgentCore/internal/runtimebootstrap"
1718
)
1819

19-
const suspendControlEnv = "OAC_RUNTIME_DAEMON_SUSPEND_PID_FILE"
20-
2120
type suspendIdentity struct {
2221
PID int `json:"pid"`
2322
StartTime string `json:"start_time"`
@@ -34,14 +33,16 @@ type suspendControl struct {
3433
signal chan os.Signal
3534
}
3635

37-
func newSuspendControl() (*suspendControl, error) {
38-
path := os.Getenv(suspendControlEnv)
39-
if path == "" {
36+
// newSuspendControl publishes the control at runtimebootstrap.SuspendControlFile
37+
// when the bootstrap enables it, and fails the connection when it cannot.
38+
func newSuspendControl(enabled bool) (*suspendControl, error) {
39+
if !enabled {
4040
return nil, nil
4141
}
42-
if !filepath.IsAbs(path) || filepath.Clean(path) != path {
43-
return nil, errors.New("connect: absolute suspend control file required")
44-
}
42+
return openSuspendControl(runtimebootstrap.SuspendControlFile)
43+
}
44+
45+
func openSuspendControl(path string) (*suspendControl, error) {
4546
info, err := os.Lstat(filepath.Dir(path))
4647
if err != nil || !info.IsDir() || info.Mode().Perm()&0077 != 0 {
4748
return nil, errors.New("connect: private suspend control directory required")

‎apps/daemon/internal/cli/suspend_control_linux_test.go‎

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,13 +21,12 @@ func TestResumeControlRejectsStaleIdentityAndDiscardsPreParkSignals(t *testing.T
2121
t.Fatal(err)
2222
}
2323
path := filepath.Join(dir, "control.json")
24-
t.Setenv(suspendControlEnv, path)
2524
environment := uuid.NewString()
2625
if err := localworkspace.Bind(environment, uuid.NewString(), t.TempDir(), t.TempDir()); err != nil {
2726
t.Fatal(err)
2827
}
2928
t.Cleanup(localworkspace.Unbind)
30-
control, err := newSuspendControl()
29+
control, err := openSuspendControl(path)
3130
if err != nil {
3231
t.Fatal(err)
3332
}

‎apps/daemon/internal/cli/suspend_process_other.go‎

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,6 @@ import (
99
"os"
1010
)
1111

12-
const suspendControlEnv = "OAC_RUNTIME_DAEMON_SUSPEND_PID_FILE"
13-
1412
type suspendIdentity struct {
1513
EnvironmentID string
1614
SuspendID string
@@ -21,8 +19,8 @@ type suspendControl struct {
2119
lastResumed *proto.EnvironmentSuspendPayload
2220
}
2321

24-
func newSuspendControl() (*suspendControl, error) {
25-
if os.Getenv(suspendControlEnv) != "" {
22+
func newSuspendControl(enabled bool) (*suspendControl, error) {
23+
if enabled {
2624
return nil, errors.New("hosted suspension requires Linux")
2725
}
2826
return nil, nil

‎apps/web/e2e/fixture-console.mjs‎

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -82,18 +82,18 @@ function nodeRollout(previous = 0) {
8282
}
8383

8484
function unconfiguredDeployment(generation = 0, ownerEpoch = 3) {
85-
return { installation_id: INSTALLATION_ID, provider: "", credential_configured: false, core_url: publicUrl(), reset: null, rollout: noNodeRollout(), owner_epoch: ownerEpoch, generation, mode: "", resources: { allocations: 0, pending: 0 }, suspension: null };
85+
return { installation_id: INSTALLATION_ID, provider: "", credential_configured: false, core_url: publicUrl(), reset: null, rollout: noNodeRollout(), owner_epoch: ownerEpoch, generation, mode: "", resources: { allocations: 0, running: 0, pending: 0 }, suspension: null };
8686
}
8787

8888
function configuredDeployment() {
89-
return { installation_id: INSTALLATION_ID, provider: "docker", credential_configured: false, configuration: {}, metadata: {}, core_url: publicUrl(), reset: null, rollout: nodeRollout(), owner_epoch: 3, generation: 1, mode: "nodes", resources: { allocations: 0, pending: 0 }, specification: { resources: { cpus: 2, memory_mib: 4096 } }, specification_digest: "fixture", suspension: null };
89+
return { installation_id: INSTALLATION_ID, provider: "docker", credential_configured: false, configuration: {}, metadata: {}, core_url: publicUrl(), reset: null, rollout: nodeRollout(), owner_epoch: 3, generation: 1, mode: "nodes", resources: { allocations: 0, running: 0, pending: 0 }, specification: { resources: { cpus: 2, memory_mib: 4096 } }, specification_digest: "fixture", suspension: null };
9090
}
9191
/** The E2B template build as Core read it when the selection was saved. */
9292
const templateBuild = { status: "ready", resources: { cpus: 2, memory_mib: 2048, root_disk_mib: 10240 } };
9393

9494
// E2B runs sandboxes in its cloud: no nodes, only what Core holds there.
9595
function e2bDeployment() {
96-
return { ...configuredDeployment(), provider: "e2b", mode: "direct", rollout: noNodeRollout(), resources: { allocations: 3, pending: 1 }, specification: { resources: { cpus: 2, memory_mib: 2048 } }, configuration: { template: "oac-runtime:0f1e2d3c-4b5a-6978-8a9b-0c1d2e3f4a5b", api_url: "https://api.e2b.app", domain: "e2b.app" } , credential_configured: true, metadata: { template_build: templateBuild } };
96+
return { ...configuredDeployment(), provider: "e2b", mode: "direct", rollout: noNodeRollout(), resources: { allocations: 3, running: 3, pending: 1 }, specification: { resources: { cpus: 2, memory_mib: 2048 } }, configuration: { template: "oac-runtime:0f1e2d3c-4b5a-6978-8a9b-0c1d2e3f4a5b", api_url: "https://api.e2b.app", domain: "e2b.app" } , credential_configured: true, metadata: { template_build: templateBuild } };
9797
}
9898

9999
function reset(mode = "login", fresh = false, sandbox = "configured", nodes = "demo", address = "public", installers = true, artifacts = "docker,microsandbox") {
@@ -419,7 +419,7 @@ async function sandboxRoute(request, response, path, url) {
419419
if (!initialize && !e2b) {
420420
for (const node of state.nodes) node.rollout = { state: node.online ? "preparing" : "unknown", ready_generation: node.rollout.ready_generation };
421421
}
422-
const held = initialize ? { allocations: 0, pending: 0 } : previous.resources;
422+
const held = initialize ? { allocations: 0, running: 0, pending: 0 } : previous.resources;
423423
state.deployment = {
424424
...configuredDeployment(), provider: input.provider, mode: e2b ? "direct" : "nodes",
425425
generation: previous.generation + 1, owner_epoch: previous.owner_epoch,

0 commit comments

Comments
 (0)