Repository navigation
Open
Labels
Description
Is your feature request related to a problem? Please describe.
Follow-up to #2654 (sessions local-first vs MEMORY.md sandbox-only) and related symptom in #3110 (async memory flush fails with no active sandbox).
In sandbox mode (e.g. E2B), control-plane files are execution-plane writes:
WorkspaceManager.appendUtf8WorkspaceRelative/writeUtf8WorkspaceRelativego throughfilesystem.uploadFileswhenever a filesystem is present (WorkspaceManager.java:370-397,711-729), soMEMORY.md/memory/*.md(viaMemorySaveTool:73-80,MemoryFlushManager:225-235) land inside the sandbox, never on host disk.- Reads are sandbox-first (
readWithOverride:818-824,listMemoryFilePaths:939-974), so once a sandbox copy exists it shadows the host copy (split-brain). - The default projection whitelist (
SandboxFilesystemSpec:42-43:AGENTS.md, skills, subagents, knowledge, .skills-cache) excludes these files, so a fresh sandbox from template loses them; durability depends on TAR/NATIVE snapshot instead. tools.jsonis correctly host-side today (build-timeToolsConfigLoader.loadviaHarnessAgent:2726, MCP registered on host atHarnessAgent:2730), andexecutein sandbox mode is E2B-bound (HarnessAgent:2690-2691) — the sandbox shell never sees host env. Memory/sessions should follow the same control-plane principle.
Describe the solution you'''d like
- Define a host-owned set:
MEMORY.md,memory/,agents/(sessions/tasks),plans/,tools.json(build-time read-only). Never add them toworkspaceProjectionRoots; lock with a test on the projection payload. WorkspaceManager: addisHostOwned(path); host-owned reads/writes bypass the filesystem and go local (namespace-aware viaresolveRuntimeDataPath; note the current local branch ignores namespace). Dedicated tools (memory_save/search/get,session_*/task_*, flush/consolidator, transcript writer) inherit host-side behavior with no per-tool changes. Generalize the existing precedenttaskRecordsRouteToLiveSandbox:441-457.- Fail closed on the generic surface in sandbox mode:
read_file/write_file/edit_file/executeon host-owned paths return an error pointing to the dedicated tool (e.g.use memory_get/memory_save), instead of silent dual-write. Transparent per-prefix routing (RoutedSandboxFilesystem) is the heavier alternative and hides the boundary — not recommended. - Tests: sandbox-mode
memory_savelands on host disk + absent in sandbox glob; projection tar contains no host-owned paths; genericread_file MEMORY.mdin sandbox returns the pointer error; memory survives sandbox recreate without snapshot.
Describe alternatives you'''ve considered
- Status quo (memory lives in sandbox snapshot): couples memory durability to sandbox lifecycle, breaks cross-replica sharing and fresh-template starts.
- Projection + write-back (add memory to projection roots, copy back on release): more code, write-conflict handling, still leaks via snapshots. Heavier than host-owning.
Additional context
- Env: 2.0.3-SNAPSHOT, Java 17, E2B sandbox (
E2bSandboxFilesystem). - Cc [Question] Inconsistent persistence semantics: sessions/*.jsonl (local-first) vs MEMORY.md (sandbox-only) in e2b scenario #2654 [Bug]:现在的记忆是异步写入,会有问题,写入的时候沙箱已经关闭,就会警告memory flush failed: no active sandbox, sandbox filesystem used outside of call context #3110.
Activity
tanzzj commentedon Sep 21, 2026
Both the memory stores designed in AS 2.0 and AS 1.0 depend on the filesystem. Once you remove the
Memory.mdin the sandbox, how does each pod get the latest memory file?But I do think that with a DistributedStore configured, storing agents/*/sessions|tasks in the sandbox is unnecessary.
That said, this may relate to the other feature request: memory storage should support different storage types like Redis/JDBC, filesystem just a default option.
oss-maintainer commentedon Sep 21, 2026
Issue Evaluation
Category:
enhancement| Status: Evaluated — valid, design questions to settle (verified againstmain@8ca0080)Claims verified against the current code. The core diagnosis holds:
appendUtf8WorkspaceRelativeuploads through the filesystem (agentscope-harness/src/main/java/io/agentscope/harness/agent/workspace/WorkspaceManager.java:370-397,uploadFilesat:392-393), andwriteUtf8WorkspaceRelativedoes the same (:711-729,:723-724). Only thefilesystem == nullbranch stays local — there is no sandbox/host predicate at all.MemorySaveTool(agent/tool/MemorySaveTool.java:48-80) andMemoryFlushManager(agent/memory/MemoryFlushManager.java:225-235, plusMemoryConsolidator.java:302for curatedMEMORY.md) write through exactly those helpers, soMEMORY.md/memory/*.mdland in the sandbox.WorkspaceManager.java:818-824), so a sandbox copy shadows the host copy — the split-brain description is accurate.AGENTS.md, skills, subagents, knowledge, .skills-cache(agent/filesystem/spec/SandboxFilesystemSpec.java:41-42, applied at:127-141andHarnessAgent.java:2459; tar built inagent/sandbox/WorkspaceProjectionApplier.java:50-134), which excludes memory paths — a fresh sandbox from template does start without them.taskRecordsRouteToLiveSandbox(WorkspaceManager.java:441-457, host-direct read:649-655, write:663-669). Line numbers inHarnessAgenthave drifted — the build-timeToolsConfigLoader.loadis at:2765, host-side MCP registration at:2769-2774, sandbox-boundexecuteat:2724-2725.agentscope-extensions-sandbox-e2b/.../E2bSandbox.java:87-150persists/restores the whole workspace via TAR (NATIVE_SNAPSHOT uses the platform snapshot API), anddocs/v2/en/docs/harness/workspace.md:285documents that as intended behaviour.Two corrections. (1) "tools.json is correctly host-side today" is only true in effect:
agent/tools/ToolsConfigLoader.java:57-78reads through the same sandbox-first two-layer path and swallows exceptions intoOptional.empty()(:66-74), so an unreachable sandbox at build time silently yields no tools config rather than a host-side guarantee. (2) The proposed step 2 has a latent trap:resolveRuntimeDataPathis namespace-prefixed (WorkspaceManager.java:239-248) while the local read fallback is not (:823, and the local write helpers at:850-872,:882-913). Making host-owned paths namespace-aware on the write side without fixing the read fallback silently loses memory instead of exposing it.On the reviewer's question (@tanzzj — how does each pod get the latest memory file if
MEMORY.mdleaves the sandbox): the code already has a distributed answer, but it is mode-specific, not sandbox-mode-specific. Shared-store/remote mode routesMEMORY.md,tools.json,sessions/andtasks/into KV namespaces (docs/v2/en/docs/harness/filesystem.md:64-70), and cross-replica sandbox pickup needs a distributedAgentStateStoreplus a non-Noop snapshot spec — configuring aDistributedStoredoes not change which filesystem mode is selected (DistributedStore.java:57-61). Today in sandbox mode the read fallback returns that pod's own host file, which is precisely the divergence being reported. Sessions are already asymmetric with memory: local-first with an async mirror into the filesystem (agent/memory/session/SessionTree.java:346,:583-598,:724-735), so host-owning memory would make the two paths consistent rather than invent a new pattern.Feasibility: feasible in the harness, but not as a single change. Fail-closed on generic tools is the risky half: the prompt already forbids
write_file/edit_fileon memory paths (agent/middleware/WorkspaceContextMiddleware.java:100-104), but reads and shell access are not restricted, and skills/scripts running inside the sandbox can currently readMEMORY.mdbecause it is written there — closing that surface is an LLM-visible behaviour change that also contradicts published docs (workspace.md:285,skill.md:393), so it needs a doc/CHANGELOG decision, not just code.Test-coverage reality check: no existing test asserts memory placement in sandbox mode (the sandbox tests in
agentscope-harness/src/test/java/io/agentscope/harness/agent/example/SandboxFilesystemIsolationScopeExampleTest.java:104-140cover lifecycle/resume only), whileMemoryConsolidatorFilesystemTest.java:94-115,HarnessAgentTest.java:1066-1090,RemoteFilesystemSpecTest.java:54-78andProjectAwareOverlayTest.java:106-118,:170-173,:325-347would break if host-owning leaked out of sandbox mode. So host-owning must be gated strictly toSandboxBackedFilesystem, and existing sandbox-residentMEMORY.mdneeds a migration path or upgrading agents silently wake up with empty memory.Suggested minimal increment (for discussion): route-based host-owning of
MEMORY.mdandmemory/in sandbox mode via the existingfilesystemRoute/RoutedSandboxFilesystemmechanism (agent/filesystem/RoutedSandboxFilesystem.java:41-74,agent/filesystem/CompositeFilesystem.java:76-137) + the namespace fix on the read fallback + projection and round-trip tests; defer the fail-closed behaviour change andagents//plans/ownership to a follow-up.No bot-generated PR here: this spans harness core plus docs, needs a migration story, and the maintainers' call on the fail-closed boundary should be settled first.
Automated evaluation by github-manager-bot