agentscope-ai / agentscope-ai/agentscope-runtime-java

fix: StackOverflowError caused by Jackson serialization circular dependency in remote mode

未关闭
#105 0 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看
主要语言
Java
星标
184
派生
38
PR 合并指标
30 天内没有已合并 PR

描述

## Bug Description

When using sandbox in **remote mode** (via `RemoteHttpClient`), calling `SandboxService.getInfo(sandbox)` or any other `@RemoteWrapper` method results in a `StackOverflowError` due to Jackson
serialization triggering an infinite recursive loop.

## Root Cause Analysis

The call chain:

SandboxService.getInfo(sandbox) # line 539
→ mapper.writeValueAsString(sandbox) # serializes entire Sandbox
→ Jackson traverses getters, finds getDesktopUrl()
→ FilesystemSandbox.getDesktopUrl() # line 84
→ BrowserSandbox.getDesktopUrl() # line 83
→ GuiSandbox.getDesktopUrl() # line 88
→ GuiMixin.getDesktopUrl(managerApi, ...) # line 47
→ managerApi.getInfo(sandbox) # calls back to getInfo()
→ mapper.writeValueAsString(sandbox) # infinite loop → StackOverflowError

### Key Observations

1. `Sandbox.getInfo()` (line 153) has `@JsonIgnore` and is correctly excluded from serialization
2. `getDesktopUrl()` in `FilesystemSandbox`, `BrowserSandbox`, and `GuiSandbox` has **no** `@JsonIgnore`, so Jackson invokes it during serialization
3. `getDesktopUrl()` → `GuiMixin.getDesktopUrl()` calls `managerApi.getInfo(sandbox)`, which in remote mode calls `writeValueAsString(sandbox)` again — closing the loop
4. `SandboxService.getInfo()` in remote mode serializes the entire `Sandbox` object, when it only needs `sandboxId` (same as local mode: `sandboxMap.getSandbox(sandbox.getSandboxId())`)

### Affected Methods in `SandboxService.java`

All `@RemoteWrapper` methods that call `mapper.writeValueAsString(sandbox)`:

| Method | Line |
|--------|------|
| `createContainer(Sandbox)` | ~153 |
| `getInfo(Sandbox)` | ~539 |
| `listTools(Sandbox, ...)` | ~602 |
| `callTool(Sandbox, ...)` | ~633 |
| `addMcpServers(Sandbox, ...)` | ~663 |

### Affected Files

- `sandbox-core/.../box/FilesystemSandbox.java` — line 84
- `sandbox-core/.../box/BrowserSandbox.java` — line 83
- `sandbox-core/.../box/GuiSandbox.java` — line 88
- `sandbox-core/.../box/GuiMixin.java` — line 47
- `sandbox-core/.../manager/SandboxService.java` — lines 153, 539, 602, 633, 663

## Suggested Fix

In `SandboxService` remote mode methods, only serialize `sandboxId` instead of the entire `Sandbox` object. The remote API likely only needs the sandbox ID for container lookups, same as
local mode (`sandboxMap.getSandbox(sandbox.getSandboxId())`).

For example, in `getInfo()`:

```java
// Before (line 539):
String sandboxJson = mapper.writeValueAsString(sandbox);

// After:
String sandboxJson = mapper.writeValueAsString(Map.of("sandboxId", sandbox.getSandboxId()));

Steps to Reproduce

1. Configure sandbox to run in remote mode (with RemoteHttpClient)
2. Call any sandbox method that internally triggers getDesktopUrl() (e.g., sandbox.getInfo())
3. Observe StackOverflowError

贡献指南

打开贡献指南

评估

这个 Issue 还没有评估数据。

把新 issue 发到你的邮箱

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