Skip to content

fix(harness): preserve sandbox context during inbox checks - #3969

Open
wlmwang wants to merge 10 commits into
agentscope-ai:mainfrom
wlmwang:fix/no_active_sandbox
Open

wlmwang wants to merge 10 commits into
agentscope-ai:mainfrom
wlmwang:fix/no_active_sandbox

Conversation

@wlmwang

@wlmwang wlmwang commented Nov 4, 2026 •

Copy link
Copy Markdown
Contributor

Fixes #3968

AgentScope Java 版本

2.1.0-SNAPSHOT

问题原因

两个会话共用一个启用沙箱的 HarnessAgent 时,默认的 MessageBus 和 AsyncToolRegistry 使用空的 RuntimeContext 访问沙箱文件系统,因而会回退到 Agent 的共享沙箱引用。当短会话 B 先结束并清除该引用时,即使长会话 A 的沙箱还在运行,A 也可能在下一次收件箱检查时遇到 No active sandbox。

修复方案

  • 参考 fix(harness): keep memory flush/consolidation IO off the per-call sandbox #3113 对 memory 的处理,沙箱模式下默认将消息和异步工具记录存放在宿主工作区的 .agentscope/bus 下,使这些跨调用的数据独立于单次调用的沙箱生命周期。

  • 框架依次采用显式配置、DistributedStore 提供的组件和宿主工作区默认实现。中英文沙箱文档已更新。如果需要保留旧沙箱快照中的待处理消息和工具记录,需要单独迁移。

验证结果

  • 使用真实 E2B 沙箱跑了 3 轮补丁前后对照。两组均使用框架默认装配,并固定 B 释放后 A 才继续推理。补丁前,A 每次都在检查收件箱时遇到 No active sandbox。补丁后,A 每次都能在原沙箱中继续执行并正常结束,收件箱和过期异步工具记录也能正常处理。

  • 58 项定向回归测试全部通过,覆盖并发释放顺序、消息总线、异步工具注册表和存储配置优先级。Spotless 格式检查通过。

    mvn -T1C -pl agentscope-harness -am  -Dtest=SandboxControlStorageTest  -Dsurefire.failIfNoSpecifiedTests=false test

提交检查

  • 已在上述测试基线上通过 Spotless 格式检查。
  • 已通过整个仓库的全量测试。
  • 已按项目规范检查 Javadoc。
  • 已按需更新相关文档。
  • 已准备好提交评审。

@jujn jujn added the P1 紧急不重要 label Nov 7, 2026
@wlmwang
wlmwang force-pushed the fix/no_active_sandbox branch from db6c4ad to 41d5b2c Compare November 26, 2026 07:39
@mintlify

mintlify Bot commented Nov 26, 2026

Copy link
Copy Markdown

Preview approval required

This pull request comes from a fork, so Mintlify won't build a preview until someone with write access approves commit 41d5b2c.

Approve preview

This branch has not been deployed

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

Labels

P1 紧急不重要

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: A concurrent sandbox call can fail during inbox checks after another session finishes

2 participants