diff --git a/agent/sandbox/v2/options.go b/agent/sandbox/v2/options.go index 2e51f55f..801a093c 100644 --- a/agent/sandbox/v2/options.go +++ b/agent/sandbox/v2/options.go @@ -64,6 +64,8 @@ func BuildCreateOptions(cfg *types.SandboxConfig, identifier, ownerID, workspace } if opts.IdleTimeout == 0 { switch opts.Policy { + case infra.OneShot: + opts.IdleTimeout = infra.DefaultOneShotIdleTimeout case infra.Session: opts.IdleTimeout = infra.DefaultSessionIdleTimeout case infra.LongRunning: diff --git a/sandbox/v2/manager.go b/sandbox/v2/manager.go index 70ce5ebd..4d60a14c 100644 --- a/sandbox/v2/manager.go +++ b/sandbox/v2/manager.go @@ -478,6 +478,8 @@ func (m *Manager) recoverBoxes(ctx context.Context, nodeID string, res *tai.Conn manager: m, } switch policy { + case OneShot: + box.idleTimeoutD = DefaultOneShotIdleTimeout case Session: box.idleTimeoutD = DefaultSessionIdleTimeout case LongRunning: diff --git a/sandbox/v2/types.go b/sandbox/v2/types.go index 312aa54b..1974e04a 100644 --- a/sandbox/v2/types.go +++ b/sandbox/v2/types.go @@ -73,6 +73,7 @@ const ( const ( DefaultStopTimeout = 2 * time.Second + DefaultOneShotIdleTimeout = 30 * time.Minute DefaultSessionIdleTimeout = 30 * time.Minute DefaultLongRunningIdleTimeout = 2 * time.Hour ) diff --git a/sandbox/v2/watcher.go b/sandbox/v2/watcher.go index 32c89af3..2862edd2 100644 --- a/sandbox/v2/watcher.go +++ b/sandbox/v2/watcher.go @@ -86,6 +86,16 @@ func (w *sandboxWatcher) Check(ctx context.Context) []monitor.Alert { } switch b.policy { + case OneShot: + alerts = append(alerts, monitor.Alert{ + Level: monitor.Warn, + Target: "box:" + b.id, + Message: fmt.Sprintf("oneshot idle expired (idle=%s, timeout=%s), removing", idle.Round(time.Second), timeout), + Action: func(ctx context.Context) { + mgr.Remove(ctx, b.id) + }, + }) + case Session: alerts = append(alerts, monitor.Alert{ Level: monitor.Warn,