Recover transient sandbox connections before executing tools
Verify control plane / verify (push) Canceled after 0s
Verify control plane / verify (pull_request) Canceled after 0s

This commit is contained in:
WebUp Cloud committed 2026-11-07 19:07:16 +08:00
1 parent 4f2cf2fc87
commit cb896bb0fa
4 files changed
+156 -52

No files matched your search

@@ -14,6 +14,7 @@ public class SandboxClient {
private final ObjectMapper json;
private final HttpClient client =
HttpClient.newBuilder()
.version(HttpClient.Version.HTTP_1_1)
.connectTimeout(Duration.ofSeconds(5))
.followRedirects(HttpClient.Redirect.NEVER)
.build();
@@ -209,8 +210,7 @@ public class SandboxClient {
try (var input = response.body()) {
byte[] bytes = input.readNBytes(limit + 1);
if (bytes.length > limit) throw new ApiError.Failure(502, "工具输出过大");
if (response.statusCode() != 200)
throw new ApiError.Failure(502, "隔离工具返回 HTTP " + response.statusCode());
if (response.statusCode() != 200) throw toolFailure(response.statusCode(), bytes);
return json.readTree(bytes).toString();
}
} catch (ApiError.Failure f) {
@@ -220,4 +220,33 @@ public class SandboxClient {
throw new ApiError.Failure(502, "隔离工具调用失败,执行结果可能不确定,请核对后处理");
}
}
private ApiError.Failure toolFailure(int status, byte[] bytes) {
String stage = "";
try {
stage = json.readTree(bytes).path("detail").asText("");
} catch (Exception ignored) {
// The response may come from an intermediate proxy rather than the gateway.
}
return switch (status) {
case 409 -> new ApiError.Failure(409, "工作区正在执行其他操作,请稍后刷新");
case 503 ->
new ApiError.Failure(
503,
switch (stage) {
case "WORKSPACE_PROVISIONING" -> "隔离环境暂时无法准备,请稍后重试";
case "WORKSPACE_STARTING" -> "隔离环境仍在启动,请稍后刷新";
case "WORKSPACE_TERMINATED" -> "隔离环境已退出,请联系管理员检查";
case "WORKSPACE_CONNECTION" -> "暂时无法连接项目的隔离环境,请稍后重试";
default -> "隔离执行服务暂时不可用,请稍后重试";
});
case 504 -> new ApiError.Failure(504, "隔离工具执行超时,请先核对结果再重试");
default ->
new ApiError.Failure(
502,
stage.equals("WORKSPACE_RESULT_UNKNOWN")
? "隔离工具连接中断,请先核对结果再重试"
: "隔离工具返回 HTTP " + status);
};
}
}