agentscope-java icon indicating copy to clipboard operation
agentscope-java copied to clipboard

[bug] `AgentRunDataPlaneHttp` 响应 JSON `data` 信封未解包

Open Peng-io opened this issue 5 months ago • 1 comments

版本

  • agentscope-java: 2.0.0-RC3

问题描述

AgentRun REST API 的所有 JSON 响应都包裹在 data 信封中:

{
  "data": {
    "sandboxId": "xxx",
    "status": "READY",
    "templateType": "CodeInterpreter"
  }
}

但 AgentRunDataPlaneHttp.textStatus() 直接从 JSON 根级别查找 status/state 字段:

private static String textStatus(JsonNode s) {
    if (s == null) return null;
    JsonNode st = s.get("status");    // ← 始终为 null(status 在 data 内)
    if (st != null && st.isTextual()) return st.asText();
    JsonNode state = s.get("state");  // ← 也找不到
    if (state != null && state.isTextual()) return state.asText();
    return null;
}

影响

waitUntilReady() 轮询沙箱状态时,每次 textStatus() 都返回 null,导致轮询完整运行 300 秒(默认 START_WAIT_SECONDS = 300)后超时报错:

AgentRun sandbox did not become READY in time (last status=null): DY5FK2VCJDS8FFF6M2GYJADGFW

AgentRun API 测试代码AgentRunSandboxApiTest使用了自定义的 unwrap() 方法来提取 data,因此测试不受影响。但框架的生产代码未做此处理。

复现步骤

  1. 配置 AgentRunFilesystemSpec 连接 AgentRun 沙箱平台
  2. 触发沙箱创建流程(SandboxManager.acquire() → AgentRunSandboxClient.create())
  3. AgentRunSandbox.start() → ensureSandbox() → waitUntilReady() 轮询超时

预期行为

getJson() / postJson() 应在返回前解包 data 信封,或 textStatus() 应兼容嵌套格式。

建议修复

在 getJson() 和 postJson() 中统一解包 data 字段:

private JsonNode unwrapData(JsonNode node) {
    if (node != null && node.has("data") && !node.get("data").isNull()) {
        return node.get("data");
    }
    return node;
}

private JsonNode postJson(String url, ObjectNode body) throws IOException {
    // ... existing code ...
    return unwrapData(json.readTree(text));
}

private JsonNode getJson(String url) throws IOException {
    // ... existing code ...
    return unwrapData(json.readTree(text));
}

或者直接修改 textStatus() 等方法,在读取字段前先尝试提取 data。

相关文件

文件 路径
主要修复 agentscope-extensions/.../agentrun/AgentRunDataPlaneHttp.java

Peng-io avatar Jun 25 '26 09:06 Peng-io

I'd like to take this one.

Plan: keep getJson/postJson unchanged and make AgentRunDataPlaneHttp.textStatus fall back to a nested data object when the root has no textual status/state, so waitUntilReady works with both enveloped and plain responses. I'll add MockWebServer regression tests for both shapes.

This is narrower than the earlier #1920: it does not strip a top-level data field from other responses.

Note: I don't have AgentRun credentials, so the envelope shape is taken from this report and the API test quoted in #1889.

liulangjietou avatar Nov 27 '26 07:11 liulangjietou