agentscope-ai / agentscope-ai/agentscope-java

[sandbox-e2b] exec timeout is unreliable: readTimeout preempts callTimeout, no server-side kill, cancellation misreported

未关闭
#2,974 1 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看
主要语言
Java
星标
5.6k
派生
1.3k
平均合并
4 天 12 小时
30 天内合并 PR
77

描述

## Problem

`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:

1. **Premature false timeout.** The per-call client only sets `callTimeout(timeoutSeconds)` and inherits the base `readTimeout`:

```java
http.newBuilder().callTimeout(timeoutSeconds, TimeUnit.SECONDS).build()
```

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.

2. **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.

3. **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.

贡献指南

打开贡献指南

评估

这个 Issue 还没有评估数据。

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。