Skip to content

fix(Harness Sandbox mode)沙箱模式多线程安全问题,以及doflush时,沙箱已经关闭的bug修复#1807

Open
zhaojinyu wants to merge 6 commits into
agentscope-ai:mainfrom
zhaojinyu:feat/fix-sandbox-bug
Open

fix(Harness Sandbox mode)沙箱模式多线程安全问题,以及doflush时,沙箱已经关闭的bug修复#1807
zhaojinyu wants to merge 6 commits into
agentscope-ai:mainfrom
zhaojinyu:feat/fix-sandbox-bug

Conversation

@zhaojinyu

Copy link
Copy Markdown
Contributor

…reading issues.The sandbox will be released before MemoryFlushMiddleWare executed.

AgentScope-Java Version

2.0.0-RC3

Description

Sandbox模式bug很多,HarnessAgent设计是可复用,在sandbox模式同时访问agent的时候,SandboxLifecycleMiddleware内部的sanbox对象没有线程安全保护,sandbox需要放入context中获取。
另外MemoryFlushMiddleware在执行doFlush的时候,因为是异步的,HarnessAgent在releaseForCall的时候可能已经停掉了sandbox, 异步的doflush已经进不去沙箱获取和上传文件了。sandbox模式比较特殊,其他模式应该没问题,主流程在HarnessAgent里编排的,要改动挺大(担心影响后面的统一设计),先临时把sandbox模式的doflush做成了同步执行,其他的继续走异步。坐等官方统一解决吧。另外还有state返序列化失败,数据库存不进去数等等问题(本pr没修)

Checklist

Please check the following items before code is ready to be reviewed.

  • Code has been formatted with mvn spotless:apply
  • All tests are passing (mvn test)
  • Javadoc comments are complete and follow project conventions
  • Related documentation has been updated (e.g. links, examples, etc.)
  • Code is ready for review

@zhaojinyu zhaojinyu requested a review from a team June 17, 2026 10:55
@CLAassistant

CLAassistant commented Jun 17, 2026

Copy link
Copy Markdown

CLA assistant check
All committers have signed the CLA.

…reading issues.The sandbox will be released before MemoryFlushMiddleWare executed.
@zhaojinyu zhaojinyu force-pushed the feat/fix-sandbox-bug branch from 65f5687 to 0a1adf7 Compare June 17, 2026 11:02
@AgentScopeJavaBot AgentScopeJavaBot added bug Something isn't working area/harness agentscope-harness (test/runtime support) labels Jun 18, 2026

@AgentScopeJavaBot AgentScopeJavaBot left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🤖 AI Review

chickenlj and others added 3 commits June 18, 2026 10:01
# Conflicts:
#	agentscope-harness/src/main/java/io/agentscope/harness/agent/middleware/MemoryFlushMiddleware.java
# Conflicts:
#	agentscope-harness/src/main/java/io/agentscope/harness/agent/middleware/MemoryFlushMiddleware.java
…fix-sandbox-bug

# Conflicts:
#	agentscope-harness/src/main/java/io/agentscope/harness/agent/middleware/MemoryFlushMiddleware.java
@zhaojinyu zhaojinyu force-pushed the feat/fix-sandbox-bug branch from 060a2c0 to 38cddca Compare June 18, 2026 04:00
@chickenlj

Copy link
Copy Markdown
Collaborator

Please fix the test failures, thanks.

Error: Errors:
Error: HarnessAgentTest.runtimeContextSandboxSpecProvidesDefaultSandboxContext:387 » SandboxConfiguration No active sandbox — sandbox filesystem used outside of a call context
Error: SandboxFilesystemIsolationScopeExampleTest.agentScope_allCallsShareOneSandbox:247 » SandboxConfiguration No active sandbox — sandbox filesystem used outside of a call context
Error: SandboxFilesystemIsolationScopeExampleTest.sessionScope_differentSession_createsFreshSandbox:150 » SandboxConfiguration No active sandbox — sandbox filesystem used outside of a call context
Error: SandboxFilesystemIsolationScopeExampleTest.sessionScope_sameSession_resumesSandbox:121 » SandboxConfiguration No active sandbox — sandbox filesystem used outside of a call context
Error: SandboxFilesystemIsolationScopeExampleTest.userScope_differentUsers_createsFreshSandbox:213 » SandboxConfiguration No active sandbox — sandbox filesystem used outside of a call context
Error: SandboxFilesystemIsolationScopeExampleTest.userScope_sameUser_differentSessions_resumesSandbox:184 » SandboxConfiguration No active sandbox — sandbox filesystem used outside of a call context

@zhaojinyu

zhaojinyu commented Jun 18, 2026

Copy link
Copy Markdown
Contributor Author

Please fix the test failures, thanks.

Error: Errors: Error: HarnessAgentTest.runtimeContextSandboxSpecProvidesDefaultSandboxContext:387 » SandboxConfiguration No active sandbox — sandbox filesystem used outside of a call context Error: SandboxFilesystemIsolationScopeExampleTest.agentScope_allCallsShareOneSandbox:247 » SandboxConfiguration No active sandbox — sandbox filesystem used outside of a call context Error: SandboxFilesystemIsolationScopeExampleTest.sessionScope_differentSession_createsFreshSandbox:150 » SandboxConfiguration No active sandbox — sandbox filesystem used outside of a call context Error: SandboxFilesystemIsolationScopeExampleTest.sessionScope_sameSession_resumesSandbox:121 » SandboxConfiguration No active sandbox — sandbox filesystem used outside of a call context Error: SandboxFilesystemIsolationScopeExampleTest.userScope_differentUsers_createsFreshSandbox:213 » SandboxConfiguration No active sandbox — sandbox filesystem used outside of a call context Error: SandboxFilesystemIsolationScopeExampleTest.userScope_sameUser_differentSessions_resumesSandbox:184 » SandboxConfiguration No active sandbox — sandbox filesystem used outside of a call context

Fix:
In HarnessAgent.Builder, when wiring the default WorkspaceMessageBus / WorkspaceAsyncToolRegistry, route their I/O through a host-side LocalFilesystem rooted at the resolved
workspace if the agent's filesystem is a SandboxBackedFilesystem; otherwise reuse the agent filesystem as before. Other AbstractSandboxFilesystem impls (OverlayFilesystem,
LocalFilesystemWithShell) are unaffected.
本次修改与昨天提交的messageBus的逻辑冲突,在sandbox模式下messagebus依赖SandboxBackedFilesystem,sandbox又在context里,所以执行bus的时候就找不到sandbox就崩了。我理解sandbox模式的bus功能是不是可以使用localfilesystem,感觉本身用SandboxBackedFilesystem管理bus的数据也不太合适?
DistributedStore已经增加了MessageBus的注入,可以增加一个redis版本的实现为sandbox使用

@zhaojinyu zhaojinyu force-pushed the feat/fix-sandbox-bug branch from 3172985 to e1d5541 Compare June 22, 2026 06:21
@zhaojinyu zhaojinyu requested a review from chickenlj June 22, 2026 06:26
@zhaojinyu zhaojinyu force-pushed the feat/fix-sandbox-bug branch from e1d5541 to 5a79ad9 Compare June 22, 2026 06:31
@zhaojinyu zhaojinyu force-pushed the feat/fix-sandbox-bug branch from 5a79ad9 to 93a0124 Compare June 22, 2026 06:34
@codecov

codecov Bot commented Jun 22, 2026

Copy link
Copy Markdown

@zhaojinyu

Copy link
Copy Markdown
Contributor Author

@chickenlj please review. thanks

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

Labels

area/harness agentscope-harness (test/runtime support) bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants