agentscope-ai / agentscope-ai/agentscope-runtime-java
fix: StackOverflowError caused by Jackson serialization circular dependency in remote mode
- Lingua principale
- Java
- Stelle
- 184
- Fork
- 38
- Metriche di merge delle PR
- Nessuna PR unita negli ultimi 30g
Descrizione
## 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
Guida per i contributori
Apri la guida per i contributori
Valutazione
Questa issue non è ancora stata valutata.