fix(lifecycle): apply explicit resume and connect timeouts - #1352
Conversation
Review — PR #1352: fix(lifecycle): apply explicit resume and connect timeoutsAI-generated review. This review is automated and does not constitute human approval. VerdictThe PR correctly identifies and fixes a real defect: explicit idle timeouts on Resume/Connect were silently dropped at the CubeAPI→CubeMaster boundary ( Findings1. Connect still silently drops an explicit timeout for statuses other than 2. A timeout-refresh failure now fails the whole Connect on a running sandbox (low, Non-blocking observations
Scope / coverage notes
|
Preserve the optional timeout across the CubeAPI-to-CubeMaster Resume request boundary and refresh lifecycle metadata only after Resume succeeds. Apply Connect timeouts through the Resume path for paused sandboxes, and use the existing set-timeout path when Connect targets an already-running sandbox. Keep omitted-timeout behavior unchanged, preserve the existing -1/0/positive timeout semantics, and reject values below -1 at both API layers. Add the E2B-compatible optional timeout argument to Python Sandbox.connect and cover Resume, paused Connect, and running Connect with focused and runtime validation. Signed-off-by: zhengyilei <zheng_yilei@qq.com>
9e0c43d to
5a15f26
Compare
| )?; | ||
|
|
||
| d = self.fetch_sandbox_detail(sandbox_id).await?; | ||
| } else if d.status == SandboxStatus::Running { |
There was a problem hiding this comment.
The else if only handles Paused and Running. Any other status — most notably SandboxStatus::Unknown (CubeMaster status 0 = CONTAINER_CREATED, which is what a freshly created sandbox reports until it reaches running) as well as Pausing/Stopping/Error — falls through with no timeout applied, silently dropping the explicit value. That is the exact class of silent-drop this PR is meant to fix. Concretely, Sandbox.connect(id, timeout=300) issued immediately after create races the status transition and can return success while the sandbox keeps its old lifecycle policy. Consider applying the timeout for any status that is not Paused (the resume-with-timeout path), or at minimum rejecting/warning when the requested timeout cannot be applied.
| if let Some(timeout) = timeout { | ||
| self.set_timeout(sandbox_id, timeout).await?; |
There was a problem hiding this comment.
self.set_timeout(...).await? propagates any failure and fails the entire Connect request, even though the sandbox is running and the connection info could still be returned. The timeout is an optional side effect here, so a transient error (e.g. NotFound while CubeMaster's localcache is cold after a restart, or a backend error) turns a previously-always-successful "connect to running sandbox" into a hard failure. Consider treating the timeout refresh as best-effort (log and continue) to match the E2B semantics the PR claims, or at least document that Connect now fails when the timeout cannot be applied.
Motivation
Resume and Connect both accept an optional idle timeout, but explicit values do not currently become the sandbox's effective lifecycle timeout in all supported paths.
There are two gaps:
As a result, callers can successfully send
timeoutwhile the sandbox continues using its previous lifecycle policy. This also diverges from E2B-compatible Connect behavior, where an explicit timeout resets the sandbox timeout.What Changed
-1,0, and positive timeout semantics, and reject values below-1at both API layers.timeoutargument to PythonSandbox.connect.Validation
Scope
This PR only makes explicit Resume and Connect timeout values effective and adds the corresponding Python SDK compatibility surface.