Skip to content

fix(harness): anchor memory reads to the caller's namespace - #4053

Merged
juruoO-o merged 1 commit into
agentscope-ai:mainfrom
ningmao-hlyz:fix/memory-namespace-read
Nov 11, 2026
Merged

juruoO-o merged 1 commit into
agentscope-ai:mainfrom
ningmao-hlyz:fix/memory-namespace-read

Conversation

@ningmao-hlyz

@ningmao-hlyz ningmao-hlyz commented Nov 7, 2026 •

Copy link
Copy Markdown
Contributor

fix(harness): anchor memory reads to the caller's namespace

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 per-identity runtime data (memory files, task records) use a
    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.
  • 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 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.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 #4052

@ningmao-hlyz
ningmao-hlyz force-pushed the fix/memory-namespace-read branch 5 times, most recently from beebe14 to 5aca279 Compare November 8, 2026 13:28
@mintlify

mintlify Bot commented Nov 8, 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 9c62673.

Approve preview

@ningmao-hlyz
ningmao-hlyz force-pushed the fix/memory-namespace-read branch 2 times, most recently from 85a05ca to 616ddbc Compare November 8, 2026 20:03
@jujn jujn added the P0 重要紧急 label Nov 10, 2026
@ningmao-hlyz
ningmao-hlyz force-pushed the fix/memory-namespace-read branch 5 times, most recently from 94b40a8 to f0962d5 Compare November 10, 2026 22:26
## 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

@juruoO-o juruoO-o 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.

已核对 memory 与 task record 的 filesystem 读取及本地兜底调用链。将身份数据的兜底限定在 caller namespace 是必要的隔离修复,共用规则的范围合理。根级遗留数据不再自动可见属于有意的安全收紧,中英文文档已说明迁移要求。未发现阻塞问题;本轮为代码复核,未重跑全仓测试。

@juruoO-o
juruoO-o merged commit e5dd389 into agentscope-ai:main Nov 11, 2026
7 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

P0 重要紧急

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: Memory reads fall back to un-namespaced workspace paths, letting one user read another's MEMORY.md

3 participants