Skip to content

fix(sandbox): serialize only sandboxId to prevent Jackson circular dependency#108

Open
itxaiohanglover wants to merge 1 commit into
agentscope-ai:mainfrom
itxaiohanglover:fix/jackson-circular-dep
Open

fix(sandbox): serialize only sandboxId to prevent Jackson circular dependency#108
itxaiohanglover wants to merge 1 commit into
agentscope-ai:mainfrom
itxaiohanglover:fix/jackson-circular-dep

Conversation

@itxaiohanglover

Copy link
Copy Markdown

Fixes #105

Problem

SandboxService remote mode methods call mapper.writeValueAsString(sandbox), which triggers Jackson to traverse all getters including getDesktopUrl(). In remote mode, getDesktopUrl() calls managerApi.getInfo(sandbox), which calls writeValueAsString(sandbox) again — creating an infinite recursion that results in StackOverflowError.

What changed

Replaced all 5 writeValueAsString(sandbox) calls with writeValueAsString(Map.of("sandboxId", sandbox.getSandboxId())):

  • createContainer(Sandbox) — line 153
  • getInfo(Sandbox) — line 539
  • listTools(Sandbox, ...) — line 602
  • callTool(Sandbox, ...) — line 633
  • addMcpServers(Sandbox, ...) — line 663

The remote API only needs the sandbox ID for container lookups — same as local mode (sandboxMap.getSandbox(sandbox.getSandboxId())).

Validation

  • No behavior change in local mode (remoteHttpClient is null)
  • Remote mode no longer serializes the full Sandbox object, breaking the circular dependency
  • @JsonIgnore on getInfo() was already correct — the issue was getDesktopUrl() lacking it
  • This fix is more robust than adding @JsonIgnore to getDesktopUrl() because it prevents any future getter from causing similar issues

…pendency

writeValueAsString(sandbox) triggers getDesktopUrl() which calls
managerApi.getInfo(sandbox) in remote mode, causing infinite
recursion and StackOverflowError.

Fix: serialize only sandboxId (same as local mode) instead of the
full Sandbox object. The remote API only needs the sandbox ID for
container lookups.

Fixes agentscope-ai#105
@CLAassistant

Copy link
Copy Markdown

CLA assistant check
Thank you for your submission! We really appreciate it. Like many open source projects, we ask that you sign our Contributor License Agreement before we can accept your contribution.
You have signed the CLA already but the status is still pending? Let us recheck it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

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

2 participants