Repository navigation
fix(harness): anchor memory reads to the caller's namespace - #4053
Merged
juruoO-o merged 1 commit intoNov 11, 2026
Merged
Conversation
ningmao-hlyz
force-pushed
the
fix/memory-namespace-read
branch
5 times, most recently
from
November 8, 2026 13:28
beebe14 to
5aca279
Compare
Preview approval requiredThis pull request comes from a fork, so Mintlify won't build a preview until someone with write access approves commit |
ningmao-hlyz
force-pushed
the
fix/memory-namespace-read
branch
2 times, most recently
from
November 8, 2026 20:03
85a05ca to
616ddbc
Compare
ningmao-hlyz
force-pushed
the
fix/memory-namespace-read
branch
5 times, most recently
from
November 10, 2026 22:26
94b40a8 to
f0962d5
Compare
## Description
`WorkspaceManager.readWithOverride` falls back to
`workspace.resolve(relativePath)` when the filesystem layer returns no
content, which drops the per-identity namespace that layer applies. For
memory files this makes two reads cross the boundary:
- `memory_get("alice/MEMORY.md")` as bob resolves to `bob/alice/MEMORY.md`
in the filesystem layer (miss), then falls back to the un-namespaced
`workspace/alice/MEMORY.md` and returns alice's content - the `./`
spelling reaches the same file once normalized.
- A root-level `MEMORY.md` left over from a pre-namespace workspace is
served to every identified caller, while `memory_search` cannot list
it - the read and search surfaces disagree.
### What changed
- Reads of namespaced writable data (memory files, task records) use a
namespace-anchored fallback: filesystem first, then the local disk inside
the caller's namespace. This is the read half of a rule the write path
already follows - the fallback must land where the write did. Contexts
with no namespace at all, or without a configured filesystem, keep the
historical root read (the write path does not namespace either then). The
namespace is resolved once per read and shared with `resolveRuntimeDataPath`.
- Task records (`agents/<agentId>/tasks/<sessionId>.json`) take the same
anchored fallback. Their write path already namespaces them, so the read
path was the odd one out: a root-level leftover record was served to any
identity that named the file.
- `memory_get` rejects `..` up front through the workspace manager's own
rule (`WorkspaceManager.requireSafeRelativePath`, promoted from private so
the tool reuses it instead of mirroring the normalization - leading
whitespace and slashes cannot smuggle the segment past the check) and
validates containment against the resolved, namespaced path. A rejected
path is a tool error instead of a failed turn, and errors from the read
itself are not translated.
- Its tool description said the path was relative to the workspace. It now
says the caller's memory namespace, which is where the path resolves -
the model reads that string when deciding what to pass.
- A root-level leftover is reported once per path per manager, so an
operator upgrading an existing workspace knows to move it; it is no
longer served.
- `docs/v2/{zh,en}/docs/harness/workspace.md` state the two-layer rule as one
table - the fallback lands where the write did - so per-identity data is a
row rather than a memory-only special case, keep the upgrade note, and drop
the namespace annotations repeated on every layout tree;
`docs/v2/{zh,en}/docs/harness/filesystem.md` points at that rule.
### Compatibility
An identified caller no longer reads the workspace-root `MEMORY.md`. That
file belongs to no identity, so serving it was the leak. Two scopes are
unaffected: single-tenant setups without `userId`/`sessionId` - or without
a configured filesystem - keep the root read, and a `<project>/MEMORY.md`
served through the project layer of
an overlay stays shared - that layer is the deliberately shared project
tier (same level as `AGENTS.md` and `knowledge/`), not a per-identity
fallback. Task records follow the same rule: a record left at the
workspace root is no longer served to an identified caller.
### Tests
- New: a sibling-namespace read is rejected through both the workspace
manager and `memory_get`, in the plain, the `./` and the
leading-whitespace `..` spelling - the last failing the whole turn on
the previous code. Each `memory_get` case asserts the `ERROR` state and
that the tool output never contains the sibling's content.
- New: a root-level `MEMORY.md` is not served to identified callers, while
an identity-less read still returns it.
- New: a task record is read from the caller's namespace, and a root-level
leftover copy of the same record is not served to another identity. Both
fail on the previous code.
- `HarnessAgentIntegrationExampleTest` materializes `MEMORY.md` under the
call's namespace, matching where the file is resolved.
- `mvn -pl agentscope-harness test`: 1625 tests, 0 failures.
Fixes agentscope-ai#4052
ningmao-hlyz
force-pushed
the
fix/memory-namespace-read
branch
from
November 10, 2026 22:27
f0962d5 to
9c62673
Compare
juruoO-o
approved these changes
Nov 11, 2026
juruoO-o
left a comment
Collaborator
There was a problem hiding this comment.
已核对 memory 与 task record 的 filesystem 读取及本地兜底调用链。将身份数据的兜底限定在 caller namespace 是必要的隔离修复,共用规则的范围合理。根级遗留数据不再自动可见属于有意的安全收紧,中英文文档已说明迁移要求。未发现阻塞问题;本轮为代码复核,未重跑全仓测试。
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
fix(harness): anchor memory reads to the caller's namespace
Description
WorkspaceManager.readWithOverridefalls back toworkspace.resolve(relativePath)when the filesystem layer returns nocontent, which drops the per-identity namespace that layer applies. For
memory files this makes two reads cross the boundary:
memory_get("alice/MEMORY.md")as bob resolves tobob/alice/MEMORY.mdin the filesystem layer (miss), then falls back to the un-namespaced
workspace/alice/MEMORY.mdand returns alice's content - the./spelling reaches the same file once normalized.
MEMORY.mdleft over from a pre-namespace workspace isserved to every identified caller, while
memory_searchcannot listit - the read and search surfaces disagree.
What changed
namespace-anchored fallback: filesystem first, then the local disk inside
the caller's namespace. The filesystem layer already resolves per caller,
so a user-level copy overrides the shared one; what changes here is the
fallback, which no longer reads the workspace root. Contexts with no
namespace at all, or without a configured filesystem, keep the historical
root read (the write path does not namespace either then). The namespace
is resolved once per read and shared with
resolveRuntimeDataPath.agents/<agentId>/tasks/<sessionId>.json) take the sameanchored fallback. Their write path already namespaces them, so the read
path was the odd one out: a root-level leftover record was served to any
identity that named the file.
memory_getrejects..up front through the workspace manager's ownrule (
WorkspaceManager.requireSafeRelativePath, promoted from private sothe tool reuses it instead of mirroring the normalization - leading
whitespace and slashes cannot smuggle the segment past the check) and
validates containment against the resolved, namespaced path. A rejected
path is a tool error instead of a failed turn, and errors from the read
itself are not translated.
says the caller's memory namespace, which is where the path resolves -
the model reads that string when deciding what to pass.
operator upgrading an existing workspace knows to move it; it is no
longer served.
docs/v2/{zh,en}/docs/harness/workspace.mdstate the two-layer rule as onetable - the filesystem layer resolves per caller, and the fallback differs
by who owns the data - so per-identity data is a row rather than a
memory-only special case, keep the upgrade note, and drop the namespace
annotations repeated on every layout tree;
docs/v2/{zh,en}/docs/harness/filesystem.mdpoints at that rule.Compatibility
An identified caller no longer reads the workspace-root
MEMORY.md. Thatfile belongs to no identity, so serving it was the leak. Two scopes are
unaffected: single-tenant setups without
userId/sessionId- or withouta configured filesystem - keep the root read, and a
<project>/MEMORY.mdserved through the project layer of
an overlay stays shared - that layer is the deliberately shared project
tier (same level as
AGENTS.mdandknowledge/), not a per-identityfallback. Task records follow the same rule: a record left at the
workspace root is no longer served to an identified caller.
Tests
manager and
memory_get, in the plain, the./and theleading-whitespace
..spelling - the last failing the whole turn onthe previous code. Each
memory_getcase asserts theERRORstate andthat the tool output never contains the sibling's content.
MEMORY.mdis not served to identified callers, whilean identity-less read still returns it.
leftover copy of the same record is not served to another identity. Both
fail on the previous code.
HarnessAgentIntegrationExampleTestmaterializesMEMORY.mdunder thecall's namespace, matching where the file is resolved.
mvn -pl agentscope-harness test: 1625 tests, 0 failures.Fixes #4052