You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
[sandbox-e2b] exec timeout is unreliable: readTimeout preempts callTimeout, no server-side kill, cancellation misreported #2974
E2bEnvdProcessClient.runShellCapture() timeout handling (agentscope-extensions/agentscope-extensions-sandbox/agentscope-extensions-sandbox-e2b/src/main/java/io/agentscope/extensions/sandbox/e2b/E2bEnvdProcessClient.java) has three defects:
Premature false timeout. The per-call client only sets callTimeout(timeoutSeconds) and inherits the base readTimeout:
If base readTimeout < timeout (e.g. custom client readTimeout=1s, exec timeout=3s), the idle readTimeout fires first. The resulting InterruptedIOException is caught and wrapped as ExecTimeoutException("timed out after 3s"), but only ~1s elapsed.
Timed-out remote process is left running.buildEnvdRequest() sends no Connect-Timeout-Ms header, so timeout only disconnects the client HTTP stream. The sandbox process (e.g. sleep 1000) keeps running — leak / unexpected billing.
External cancellation misreported as timeout.catch (InterruptedIOException) unconditionally throws ExecTimeoutException, even when the thread was interrupted by outer cancellation. The interrupt bit is swallowed.
Repro
Base client readTimeout=1s, runShell(..., timeoutSeconds=3) against a hanging envd stream (NO_RESPONSE).
Expected: ExecTimeoutException after ~3s.
Actual: ExecTimeoutException after ~1s with message claiming 3s.
Expected
readTimeout for the call must stay above callTimeout so total-duration semantics wins.
Send Connect-Timeout-Ms when timeoutSeconds > 0 so envd kills the process server-side.
If Thread.currentThread().isInterrupted(), restore the bit and rethrow instead of wrapping as timeout.
I traced the three failure modes to separate timeout layers and agree they should be fixed together rather than by increasing the default read timeout globally.
A useful implementation boundary would be to derive a per-call client with readTimeout >= callTimeout (while preserving a caller-configured larger read timeout), then send Connect-Timeout-Ms only for positive execution timeouts. The exception mapping should distinguish an interrupted caller from an elapsed deadline: restore the interrupt flag and propagate cancellation when the thread is interrupted; wrap only an actual deadline expiry as ExecTimeoutException. Please also add tests for readTimeout < timeout, readTimeout > timeout, zero/unbounded timeout, request-header propagation, and interrupted execution. The tests should assert elapsed behavior and the exact cancellation/timeout type, since a message claiming a timeout is not sufficient evidence.
Category: bug | Status: Confirmed | Severity: medium
Verified against main @ 39cd304a. Both halves of the report reproduce in the code as written.
Root cause
E2bEnvdProcessClient.java:70-74 — the base envd client is built with connectTimeout(30s) and readTimeout(opt.getReadTimeoutSeconds()), defaulting to 120s (E2bSandboxClientOptions.java:41). No callTimeout on the base client.
E2bEnvdProcessClient.java:122-125 — each exec derives http.newBuilder().callTimeout(timeoutSeconds, …), and newBuilder() inherits the 120s readTimeout. So every exec carries both the requested call timeout and a 120s per-read gap timeout.
readTimeout fires on the gap between received frames of the Connect server-streaming response, so for any quiet command it wins regardless of the requested budget. Effective timeout is min(readTimeout, execTimeout).
E2bEnvdProcessClient.java:156-158 — the resulting SocketTimeoutException (an InterruptedIOException) is caught and reported as ExecTimeoutException(shellCommand, timeoutSeconds), i.e. it claims the requested timeout elapsed when it did not.
No server-side bound: buildStartRequest (:236-250) sends only cmd/args/cwd/stdin — no timeout field to envd — and on abort the client simply throws. The only kill path in the module is whole-sandbox platform.killSandbox in E2bSandbox.java:71-79, which is shutdown() and is never invoked on exec timeout, so the command keeps running until sandbox TTL.
In-repo exposure: workspace persist/hydrate uses TAR_TIMEOUT_SECONDS = 300 (E2bSandbox.java:44,107,141), and caller-facing timeouts reach 600s (codingagent/SessionsTool.java:66) — both above the 120s default read timeout.
Impact: any exec that stays silent for over 120s (builds, installs, sleep, a stalled tar) is cut short with a misleading "timed out after Ns" message, and the orphaned process keeps consuming CPU/memory, may keep mutating the workspace, and can hold locks while the agent retries. Default 300s/600s timeouts are unreliable out of the box.
Fix direction
In runShellCapture, derive the per-call client so the read timeout cannot preempt the requested one — readTimeout(max(opt.getReadTimeoutSeconds(), timeoutSeconds)), or readTimeout(0) and rely on callTimeout for streaming execs.
Add a server-side bound so an aborted command does not leak: prefix the command with timeout <N> (it already runs via /bin/bash -l -c), or call envd's process-kill RPC after a client-side abort.
Distinguish a read-timeout abort from genuine call-timeout expiry in the ExecTimeoutException message, so the reported number is truthful.
Point 1 is small and safe on its own; points 2 and 3 are what actually stop the leaked-process symptom. Reply /approve if you want a fix proposal generated (we would start with 1 + 3 and treat 2 as a follow-up, since a shell timeout prefix assumes timeout(1) exists in the sandbox image).
Status: 72 h feedback window expired — no automated PR will be generated, this proposal window here is closed
The evaluation above went 72 hours without an /approve, /revise or /reject, so per our workflow the window is closed and no competing PR will be generated. No action is needed from anyone.
The root cause in the evaluation still stands, and the fix is already in flight from the reporter:
That is the same seam the evaluation pointed at: per-call readTimeout preempting the requested callTimeout (E2bEnvdProcessClient.java:70-74, :122-125), the missing server-side bound on an aborted exec, and the resulting ExecTimeoutException reporting a timeout that did not actually elapse (:156-158). @CryoThrust's earlier boundary proposal on this thread — derive a per-call client with readTimeout >= callTimeout, send Connect-Timeout-Ms only for positive execution timeouts, and separate an interrupted caller from an elapsed deadline — is a useful acceptance bar for that PR; it was never turned into an /approve here, so no automated proposal was generated.
As of this check #2976 is MERGEABLE with reviewDecision=REVIEW_REQUIRED at head b64ed418e0 (check rollup SUCCESS), last updated 2026-09-04T07:40Z. What it needs next is a maintainer review, not a second implementation. #2976 stays the active path for this issue.
If maintainers would still like an independent proposal here, reply on this issue and we will re-evaluate.
Hi, I'd like to work on this. All three defects are clear: (1) set readTimeout = callTimeout on the per-call client so the idle timeout cannot preempt the call timeout; (2) send Connect-Timeout-Ms so the sandbox-side process is killed on timeout; (3) distinguish external cancellation (Thread.interrupt / call cancellation) from genuine read timeouts in the InterruptedIOException handler. Tests via a mock envd server for each case. PR coming shortly.
Hi, I'd like to work on this. All three defects are clear: (1) set readTimeout = callTimeout on the per-call client so the idle timeout cannot preempt the call timeout; (2) send Connect-Timeout-Ms so the sandbox-side process is killed on timeout; (3) distinguish external cancellation (Thread.interrupt / call cancellation) from genuine read timeouts in the InterruptedIOException handler. Tests via a mock envd server for each case. PR coming shortly.
I've already submitted my pull request; could you please review it? #2976
Following up on my claim from September — starting on this now. The three defects stand: readTimeout preempts callTimeout (fix: per-call client sets readTimeout = callTimeout), no Connect-Timeout-Ms header (sandbox process leaks on timeout), and external cancellation misreported as ExecTimeoutException. Tests via a mock envd server covering each. PR coming shortly.
Activity
fix(sandbox-e2b): reliable exec timeout with server-side kill (agents…
CryoThrust commentedon Sep 4, 2026
I traced the three failure modes to separate timeout layers and agree they should be fixed together rather than by increasing the default read timeout globally.
A useful implementation boundary would be to derive a per-call client with
readTimeout >= callTimeout(while preserving a caller-configured larger read timeout), then sendConnect-Timeout-Msonly for positive execution timeouts. The exception mapping should distinguish an interrupted caller from an elapsed deadline: restore the interrupt flag and propagate cancellation when the thread is interrupted; wrap only an actual deadline expiry asExecTimeoutException. Please also add tests forreadTimeout < timeout,readTimeout > timeout, zero/unbounded timeout, request-header propagation, and interrupted execution. The tests should assert elapsed behavior and the exact cancellation/timeout type, since a message claiming a timeout is not sufficient evidence.oss-maintainer commentedon Sep 13, 2026
Issue Evaluation
Category:
bug| Status: Confirmed | Severity: mediumVerified against
main@39cd304a. Both halves of the report reproduce in the code as written.Root cause
E2bEnvdProcessClient.java:70-74— the base envd client is built withconnectTimeout(30s)andreadTimeout(opt.getReadTimeoutSeconds()), defaulting to 120s (E2bSandboxClientOptions.java:41). NocallTimeouton the base client.E2bEnvdProcessClient.java:122-125— each exec deriveshttp.newBuilder().callTimeout(timeoutSeconds, …), andnewBuilder()inherits the 120sreadTimeout. So every exec carries both the requested call timeout and a 120s per-read gap timeout.readTimeoutfires on the gap between received frames of the Connect server-streaming response, so for any quiet command it wins regardless of the requested budget. Effective timeout ismin(readTimeout, execTimeout).E2bEnvdProcessClient.java:156-158— the resultingSocketTimeoutException(anInterruptedIOException) is caught and reported asExecTimeoutException(shellCommand, timeoutSeconds), i.e. it claims the requested timeout elapsed when it did not.buildStartRequest(:236-250) sends only cmd/args/cwd/stdin — no timeout field to envd — and on abort the client simply throws. The only kill path in the module is whole-sandboxplatform.killSandboxinE2bSandbox.java:71-79, which isshutdown()and is never invoked on exec timeout, so the command keeps running until sandbox TTL.TAR_TIMEOUT_SECONDS = 300(E2bSandbox.java:44,107,141), and caller-facing timeouts reach 600s (codingagent/SessionsTool.java:66) — both above the 120s default read timeout.Impact: any exec that stays silent for over 120s (builds, installs,
sleep, a stalledtar) is cut short with a misleading "timed out after Ns" message, and the orphaned process keeps consuming CPU/memory, may keep mutating the workspace, and can hold locks while the agent retries. Default 300s/600s timeouts are unreliable out of the box.Fix direction
runShellCapture, derive the per-call client so the read timeout cannot preempt the requested one —readTimeout(max(opt.getReadTimeoutSeconds(), timeoutSeconds)), orreadTimeout(0)and rely oncallTimeoutfor streaming execs.timeout <N>(it already runs via/bin/bash -l -c), or call envd's process-kill RPC after a client-side abort.ExecTimeoutExceptionmessage, so the reported number is truthful.Point 1 is small and safe on its own; points 2 and 3 are what actually stop the leaked-process symptom. Reply
/approveif you want a fix proposal generated (we would start with 1 + 3 and treat 2 as a follow-up, since a shelltimeoutprefix assumestimeout(1)exists in the sandbox image).Automated evaluation by github-manager-bot
oss-maintainer commentedon Sep 16, 2026
Status: 72 h feedback window expired — no automated PR will be generated, this proposal window here is closed
The evaluation above went 72 hours without an
/approve,/reviseor/reject, so per our workflow the window is closed and no competing PR will be generated. No action is needed from anyone.The root cause in the evaluation still stands, and the fix is already in flight from the reporter:
fix(sandbox-e2b): reliable exec timeout with server-side kill, by @chcodex, closes this issue.That is the same seam the evaluation pointed at: per-call
readTimeoutpreempting the requestedcallTimeout(E2bEnvdProcessClient.java:70-74,:122-125), the missing server-side bound on an aborted exec, and the resultingExecTimeoutExceptionreporting a timeout that did not actually elapse (:156-158). @CryoThrust's earlier boundary proposal on this thread — derive a per-call client withreadTimeout >= callTimeout, sendConnect-Timeout-Msonly for positive execution timeouts, and separate an interrupted caller from an elapsed deadline — is a useful acceptance bar for that PR; it was never turned into an/approvehere, so no automated proposal was generated.As of this check #2976 is
MERGEABLEwithreviewDecision=REVIEW_REQUIREDat headb64ed418e0(check rollupSUCCESS), last updated 2026-09-04T07:40Z. What it needs next is a maintainer review, not a second implementation. #2976 stays the active path for this issue.If maintainers would still like an independent proposal here, reply on this issue and we will re-evaluate.
Automated by github-manager-bot
aiyili commentedon Oct 1, 2026
Hi, I'd like to work on this. All three defects are clear: (1) set readTimeout = callTimeout on the per-call client so the idle timeout cannot preempt the call timeout; (2) send
Connect-Timeout-Msso the sandbox-side process is killed on timeout; (3) distinguish external cancellation (Thread.interrupt / call cancellation) from genuine read timeouts in the InterruptedIOException handler. Tests via a mock envd server for each case. PR coming shortly.chcodex commentedon Oct 2, 2026
I've already submitted my pull request; could you please review it?
#2976
fix(sandbox-e2b): reliable exec timeout with server-side kill (agents…
aiyili commentedon Oct 21, 2026
Following up on my claim from September — starting on this now. The three defects stand: readTimeout preempts callTimeout (fix: per-call client sets readTimeout = callTimeout), no Connect-Timeout-Ms header (sandbox process leaks on timeout), and external cancellation misreported as ExecTimeoutException. Tests via a mock envd server covering each. PR coming shortly.
fix(sandbox-e2b): reliable exec timeout with server-side kill (#2976)