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 摘要。