Skip to content

fix(memory): read the searched workspace for explicit agents - #147072

Merged
obviyus merged 8 commits into
openclaw:mainfrom
PollyBot13:fix/memory-explicit-workspace
Sep 14, 2026
Merged

obviyus merged 8 commits into
openclaw:mainfrom
PollyBot13:fix/memory-explicit-workspace

Conversation

@PollyBot13

@PollyBot13 PollyBot13 commented Sep 13, 2026 •

Copy link
Copy Markdown
Contributor

Closes #146939. Related: #140984.

What Problem This Solves

Fixes memory_get returning a different file from memory_search when an explicitly owned multi-agent roster relies on inherited workspace paths.

User Impact

Search results and subsequent reads agree on the agent's workspace without requiring a per-agent workspace pin. Explicit workspace overrides remain authoritative. No files move, no index reset or storage migration is required, and Markdown containment and read limits are unchanged.

For explicitly owned rosters, an unpinned first agent no longer implicitly reads the parent workspace merely because it appears first. A valid retained migration owner and sole-agent inheritance still follow canonical behavior. Raw reader inputs without explicit ownership keep their existing legacy behavior.

Why This Change Was Made

The prior path repair in #140984 deliberately deferred workspace-ownership alignment. This PR proposes only that bounded alignment: core and explicitly owned memory-host reads share the compatibility-owner decision through a pure internal helper. The existing private path bridge avoids importing the full agent runtime. The original config object is preserved for retained migration-owner lookup; optional legacy reader IDs remain accepted.

Maintainer choices — proposed, not previously approved

  1. Accept explicit-roster alignment (recommended and implemented). Search's canonical workspace ownership is authoritative for reads too. Alternatively, retain the mismatch and require explicit workspace pins; this PR does not silently change search to match the old getter.
  2. Preserve legacy reader compatibility (implemented). Inputs without ownership: "explicit" retain first-agent/default-marker inheritance. Broader normalization of those inputs is intentionally deferred, rather than changing the shipped reader contract in this fix.
  3. Keep adjacent policy out of scope (recommended). No context-limit merging changes, shared-system-agent workspace redesign, public SDK entrypoint, or broader path allowlist. Those require separate decisions.

ClawSweeper's source review supports this direction but requests a compatibility decision; it is not maintainer approval. Please review the ownership choice before merge. Rollback is reverting this change; the issue's explicit-workspace-pin mitigation remains available.

Evidence

After-fix real Gateway proof — September 13, 2026

Built candidate be5a589a0ee148b54c51f6876ef5281ee9b29cb5, Node 26.8.1/macOS. Used a loopback-only Gateway, registered Memory Core tools through HTTP POST /tools/invoke, synthetic files and real on-disk SQLite state, provider: none, and vectors disabled. No test-helper imports, provider calls, or production configuration/state changes.

Setup Actual search → get result
Fresh explicit two-agent roster, neither agent pinned; parent contains a decoy main: USER.md, status=ok, Orchid proof main; other: USER.md, status=ok, Orchid proof other
Fresh setup, parent traversal for each agent MEMORY_PATH_NOT_ALLOWED
Installed 2026.9.3, existing explicit workspace pins main/other: USER.md, status=ok, matching Orchid upgrade main / Orchid upgrade other
Same shipped-created state after candidate Doctor migration and candidate Gateway startup Both agents return those same markers with status=ok

For each agent, passed the search result's path/start line/inclusive line count into memory_get. Stopped the shipped Gateway before switching binaries. Candidate initially refused the older session-identity database; followed its supported doctor --fix --non-interactive instruction (exit 0, both agent databases v19→v20), then repeated the actual HTTP flow. Both existing workspace pins were preserved exactly, and SHA-256 checks showed all three synthetic USER.md files unchanged. Doctor did change normal config metadata/defaults; the whole config was not unchanged. All proof Gateways were stopped.

This is fresh-runtime and shipped-created-state/Doctor migration proof, not an installer, openclaw update driver, or live-user upgrade test. Retained legacy-owner shapes beyond these fixtures remain covered by focused tests, not claimed as live proof. The schema migration belongs to the candidate's existing upgrade path; this six-file patch introduces no schema or embedding-metadata changes. Maintainer acceptance of explicit-roster read-root alignment remains required.

CI at this evidence update: the model-login catalog timing case in large-26 failed, making the aggregate gate red. Its fixture disables memory and uses one pinned agent without explicit ownership; likely unrelated, but no matching base failure was verified. No CI pass is claimed.

  • Focused validation: 162 tests passed across six files (one existing skipped test), including the real-manager tool regression and package-boundary contracts.
  • Final-head node scripts/check-changed.mjs passed: core and test types, core/extension lint, formatting, dead-export scans, package/SDK boundaries, and runtime import-cycle checks. git diff --check passed.
  • Full pnpm build passed in 3m26s, including plugin SDK exports, CLI bootstrap imports, built plugin-loading checks, and Control UI build. After that build, the only patch change moved an unchanged re-export below imports for lint; the rebase added only unrelated ACP tests. The repository-wide test suite was not run.
  • Tests-first reproduction on upstream main: both roster orders returned the parent decoy through memory_get after real SQLite-backed memory_search found the agent marker.
  • The regression exercises both agents, both roster orders, returned path/line readback, and rejection of parent traversal. It uses temporary files and databases with embeddings disabled; no provider request or private installation data.
  • Compatibility coverage includes explicit workspace overrides, retained/removed migration owners, ignored legacy markers under explicit ownership, optional legacy IDs, sole/duplicate agents, and absent/empty rosters. Existing legacy path, file-reader, core ownership, and package-boundary coverage is retained.
  • Independent clean-context P0–P3 source review found no actionable findings. The repository Auto Review CLI was also attempted but could not authenticate; no successful CLI review is claimed.

AI-assisted implementation and review. Maintainer approval remains required; no merge or automatic repair authority is inferred from the issue labels.


Maintainer addendum — September 14, 2026

The ownership choices proposed above are accepted. This addendum records the final shared legacy-data owner, the preserved durable runtime default, and the refreshed proof. Earlier evidence remains tied to its stated revision.

Problem

Memory search finds an agent's file, but memory_get returns the parent's different file as success.

Fix and impact

Search and explicit memory reads now share one lightweight legacy-data owner. The two existing cached facts stay with the agent owner. Raw reader behavior, optional IDs, workspace pins, home/profile handling, and extra paths remain supported. No schema, migration, config key, protocol, or dependency changes.

Owner decision: explicit-roster reads must return the searched workspace's file, never a different parent file. This ends the explicit-roster exception retained in #140984. To retain the parent as an agent's workspace, configure that workspace explicitly. Legacy data ownership remains separate from the durable runtime default, preserving #146246.

Production growth is reduced from 46 to 38 net lines:

  • agent-roster.ts moves existing roster readers into a lightweight module and owns the shared data decision.
  • agent-scope-config.ts shrinks by 96 lines while preserving public exports and both cache lifetimes.
  • Memory-host config-utils.ts adds eight net lines to preserve raw-reader compatibility and use the shared owner for explicit inputs.
  • openclaw-runtime-paths.ts adds the one export needed by that call.

Evidence

  • Main 5576f256da61f4708ed59ada7604702a18d8e0fc: the three unpinned regression rows fail with status: ok and text: Parent decoy; the pinned control passes. Command: node scripts/run-vitest.mjs extensions/memory-core/src/tools.real-manager.test.ts -t 'reads the indexed agent file with explicit ownership'.
  • Retained HTTP proof at accepted a016f35b265a96d4cdfd5d43dbf12d461ae417d2 (the rebuilt branch has identical owner files): real Gateway POST /tools/invoke, search then get, covers both roster orders, a non-first system agent, explicit pins, and parent traversal. Eight reads return the known agent file bytes; eight traversals are rejected.
  • Fresh merge f48cf5fc4eb0e717f252fefde7929632f24d494a, parents candidate above and main f6d984fcbef0f00cdeee4737d70ababb869f5162: 297 tests pass, one existing skip, across the owner, memory, session/auth, and Doctor suites below.
  • Local production/test type checks, changed-file type-aware lint, formatting, architecture, unused-export, line-count, and assertion checks pass. The assertion allowance only shrinks.
  • Retained 2026.9.3-created state proof preserves pins, file hashes, and runtime default through Doctor/restart. This proves state compatibility, not the installed update driver.
  • Earlier local matrix replay was stopped; its historical failures remain recorded. Current exact-head CI run 34806299349 completed successfully at 1c3602c201d65ed43e45c4c1c856fe4fcc696dc8, with every executed job passing.
HTTP requests and fresh-merge test command

The isolated Gateway runs through pnpm openclaw gateway run --port <isolated-port> --bind loopback.

{"agentId":"main","tool":"memory_search","args":{"query":"AGENT_MAIN_ORCHID","corpus":"memory"}}
{"agentId":"main","tool":"memory_get","args":{"path":"USER.md","from":1,"lines":3}}
{"agentId":"main","tool":"memory_get","args":{"path":"../USER.md","from":1,"lines":2}}

The search-returned path and line range drive the read. The read returns # main\nAGENT_MAIN_ORCHID searched source; traversal returns MEMORY_PATH_NOT_ALLOWED.

node scripts/run-vitest.mjs \
  packages/memory-host-sdk/src/host/config-utils.test.ts \
  packages/memory-host-sdk/src/host/read-file.test.ts \
  packages/memory-host-sdk/src/host/read-file-manager-compat.test.ts \
  extensions/memory-core/src/tools.real-manager.test.ts \
  src/agents/agent-scope-config.test.ts \
  src/agents/legacy-inherited-auth-dir.test.ts \
  src/plugins/contracts/extension-package-project-boundaries.test.ts \
  src/config/legacy.roster.test.ts \
  src/commands/sessions.default-agent-store.test.ts \
  src/commands/doctor/shared/legacy-config-migrations.agent-rosters.test.ts \
  src/commands/doctor/shared/legacy-config-migrations.runtime.system-agent.test.ts \
  src/commands/doctor/shared/default-agent-role-materialization.test.ts \
  src/commands/doctor/shared/default-agent-role-materialization.write.test.ts \
  src/commands/doctor-config-flow.workspace-persistence.test.ts \
  src/agents/agent-scope.test.ts \
  src/agents/agent-scope.workspace-inference.test.ts

Consumers

Explicit memory reads and memory search now share one legacy-data owner (src/agents/agent-roster.ts); the moved roster types keep their index, key, and kind fields and every typed reader of them was checked. Workspace pins, the raw legacy readers, and the durable runtime default are unchanged. No public SDK entrypoint is added.

Contributor-branch refresh

The accepted content is rebuilt on the original contributor head be5a589a0ee148b54c51f6876ef5281ee9b29cb5, followed by a plain merge of main ae5a4b4a55526a32edbc6d865af66e4a4f7dd25b and the five maintainer commits in order. There were no conflicts or manual resolutions, and all five messages are unchanged.

The resulting head 1c3602c201d65ed43e45c4c1c856fe4fcc696dc8 has the same complete tree as the accepted revision merged with that main. The 16-file command above passed again on this head: 297 tests, one existing skip, exit 0.

The unchanged local preflight passed on this same head in a physical checkout with its own dependencies. It covered type-aware lint, production types, core/extension/script/root-test types, and protocol checks. The initial nested-checkout attempt failed only the declaration-input isolation guard; physical isolation resolved it without disabling any check.

@clawsweeper

clawsweeper Bot commented Sep 13, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
ClawSweeper picked this up.

Pull request received. I will update this pull request when review starts.

ClawSweeper review complete

ClawSweeper finished reviewing this revision. The review result is being finalized.

View the workflow run.

@openclaw-barnacle openclaw-barnacle Bot added extensions: memory-core Extension: memory-core agents Agent runtime and tooling size: S labels Sep 13, 2026
@clawsweeper clawsweeper Bot added P2 Normal backlog priority with limited blast radius. merge-risk: 🚨 compatibility 🚨 May break existing users, config, migrations, defaults, or upgrade paths. rating: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask. labels Sep 13, 2026
@clawsweeper

clawsweeper Bot commented Sep 13, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: blocked before merge. Reviewed September 14, 2026, 12:39 AM ET / 04:39 UTC (Revision 3).

ClawSweeper review

What this changes

Aligns Memory Core’s file reads with the workspace searched for explicitly configured agents, shares the existing ownership resolver, and adds search-to-read regression coverage.

Merge readiness

⛔ Blocked before merge - 2 items remain

This remains a useful fix: current main and the latest release still select the wrong read root for affected explicit rosters. The refreshed evidence addresses the earlier proof concern, the addendum records acceptance of the compatibility change, and no introduced correctness defect was found.

Priority: P2
Reviewed head: 1c3602c201d65ed43e45c4c1c856fe4fcc696dc8

Review scores

Measure Result What it means
Overall readiness 🐚 platinum hermit (4/6) A focused, source-consistent repair with real runtime evidence and an explicitly accepted compatibility tradeoff.
Proof confidence 🦞 diamond lobster (5/6) Sufficient (live_output): Recorded real Gateway HTTP calls exercise the changed memory-host resolver through registered search/get tools and return matching file bytes while rejecting parent traversal. Production owner blobs match the retained proof revision; fresh and shipped-created-state results cover the touched contract without claiming installed-updater proof.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Verification

Check Result Evidence
Real behavior Verified Sufficient (live_output): Recorded real Gateway HTTP calls exercise the changed memory-host resolver through registered search/get tools and return matching file bytes while rejecting parent traversal. Production owner blobs match the retained proof revision; fresh and shipped-created-state results cover the touched contract without claiming installed-updater proof.
Evidence reviewed 8 items Current main still needs the repair: The memory-host resolver still assigns the inherited workspace using its first-agent/default-marker selection. Search uses the core workspace owner, which applies legacy-data ownership independently of the runtime default.
Latest release retains the old reader behavior: The resolver in v2026.9.4 contains the same first-agent inheritance branch; this repair is not present in the supplied latest release.
Bounded ownership alignment: Explicit workspace pins retain precedence. Only explicit ownership selects the shared legacy-data owner; raw legacy reader inputs retain their existing selection. Core retains separate batch-cached runtime-default and legacy-data facts.
Findings None None.
Security None None.

How this fits together

Memory Core searches an agent’s indexed workspace and returns file paths and line ranges. The memory-host reader resolves those references into bounded Markdown excerpts for the agent.

flowchart TD
  A[Agent and configuration] --> B[Workspace ownership]
  B --> C[Memory search index]
  C --> D[File path and line range]
  B --> E[Memory file reader]
  D --> E
  E --> F[Containment checks]
  F --> G[Matching excerpt or read error]
Loading

Before merge

  • Resolve merge risk (P1) - Explicit, unpinned rosters that relied on the getter’s former parent workspace will instead read their canonical agent workspace; parent-only files may become unavailable. The addendum accepts this change and identifies an explicit workspace pin as the way to retain parent-root behavior.
  • Add data-model compatibility proof - Confirm migration or upgrade compatibility proof before merge.
Agent review details

Security

None.

PR surface

Source +38, Tests +74, Other 0. Total +112 across 6 files.

View PR surface stats
Area Files Added Removed Net
Source 4 156 118 +38
Tests 1 74 0 +74
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 1 1 1 0
Total 6 231 119 +112

Review metrics

Metric Value Why it matters
Production versus regression coverage Production +38 net lines; tests +74 net lines Production growth extracts a shared lightweight owner while preserving existing exports and cache lifetimes.

Stored data model

Persistent data-model change detected: vector/embedding metadata: packages/memory-host-sdk/src/host/config-utils.ts. Confirm migration or upgrade compatibility proof before merge.

Root-cause cluster

Relationship: fixed_by_candidate
Canonical: #146939
Summary: This PR implements the reported wrong-workspace read; the parallel draft carries the same owner repair.

Members:

Proposal only: this assessment does not dispatch repair, suppress jobs, mutate sibling items, close, or merge anything.

Merge-risk options

Maintainer options:

  1. Retain the accepted workspace alignment (recommended)
    Proceed with the documented ownership choice and preserved workspace-pin escape hatch for installations intentionally reading the parent root.

Technical review

Best possible solution:

Use the accepted shared legacy-data owner for search and reads, preserving explicit workspace pins and the demonstrated existing-state compatibility.

Do we have a high-confidence way to reproduce the issue?

Yes: two unpinned explicit agents with different parent and agent USER.md markers expose the divergent search and read roots in current source. The contributor records failing-before verification; this read-only review did not execute tests.

Is this the best way to solve the issue?

Yes: sharing the existing ownership decision repairs the mismatch without widening file access, moving data, or conflating the runtime default with legacy data ownership.

AGENTS.md: found and applied where relevant.

Codex review notes: model internal, reasoning medium; reviewed against 3de18f60bdef.

Labels

Label justifications:

  • P2: Repairs successful but incorrect memory reads in a bounded explicit multi-agent configuration.
  • merge-risk: 🚨 compatibility: The accepted change removes implicit parent-root reads for affected explicit rosters, potentially changing which existing files the getter can reach.
  • rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🦞 diamond lobster and patch quality is 🐚 platinum hermit.
  • status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR. Sufficient (live_output): Recorded real Gateway HTTP calls exercise the changed memory-host resolver through registered search/get tools and return matching file bytes while rejecting parent traversal. Production owner blobs match the retained proof revision; fresh and shipped-created-state results cover the touched contract without claiming installed-updater proof.
  • proof: sufficient: Contributor real behavior proof is sufficient. Recorded real Gateway HTTP calls exercise the changed memory-host resolver through registered search/get tools and return matching file bytes while rejecting parent traversal. Production owner blobs match the retained proof revision; fresh and shipped-created-state results cover the touched contract without claiming installed-updater proof.

Evidence

What I checked:

  • Current main still needs the repair: The memory-host resolver still assigns the inherited workspace using its first-agent/default-marker selection. Search uses the core workspace owner, which applies legacy-data ownership independently of the runtime default. (packages/memory-host-sdk/src/host/config-utils.ts:173, 3de18f60bdef)
  • Latest release retains the old reader behavior: The resolver in v2026.9.4 contains the same first-agent inheritance branch; this repair is not present in the supplied latest release. (packages/memory-host-sdk/src/host/config-utils.ts:173, 3a9d69db306c)
  • Bounded ownership alignment: Explicit workspace pins retain precedence. Only explicit ownership selects the shared legacy-data owner; raw legacy reader inputs retain their existing selection. Core retains separate batch-cached runtime-default and legacy-data facts. (packages/memory-host-sdk/src/host/config-utils.ts:178, 1c3602c201d6)
  • Actual read boundary: The registered getter passes its resolved config and agent to readAgentMemoryFile. That reader uses the changed workspace resolver while retaining Markdown restrictions, extra-path checks, symlink containment, and bounded reads. (packages/memory-host-sdk/src/host/read-file.ts:209, 1c3602c201d6)
  • Complete captured body and real runtime proof: REST retrieval recovered all 12,619 UTF-16 units and matched captured SHA-256 c6e712e202deaae5add734aebbb5055aeb005bb53c5f0c26b5fcc5cc415d14cb. The body records real Gateway POST /tools/invoke search-to-get results: eight matching agent-file reads and eight rejected parent traversals across roster orders, a non-first system agent, and workspace pins. It also records preserved pins, file hashes, and runtime default with 2026.9.3-created state through Doctor/restart. The September 14 addendum accepts explicit-roster alignment. (1c3602c201d6)
  • Retained proof matches production owner files: GitHub content blob identities at proof revision a016f35 match HEAD for all four changed production modules. The complete test file differs, so no whole-tree equivalence is inferred. The body separately reports 297 passing tests and one existing skip on the reviewed head. (src/agents/agent-roster.ts:119, a016f35b265a)

Likely related people:

  • steipete: Suggested for follow-up; no historical authorship or introduction is verified. (role: unverified routing candidate; confidence: low)

Rating scale

Score Internal tier Crab rank Meaning
6/6 S 🦀 challenger crab Exceptional readiness
5/6 A 🦞 diamond lobster Very strong readiness
4/6 B 🐚 platinum hermit Good normal PR; ordinary maintainer review
3/6 C 🦐 gold shrimp Useful, but confidence is limited
2/6 D 🦪 silver shellfish Proof or implementation needs work
1/6 F 🧂 unranked krab Not merge-ready
N/A NA 🌊 off-meta tidepool Rating does not apply

Overall follows the weaker of proof and patch quality.
Shiny media proof means a screenshot, video, or linked artifact directly shows the changed behavior. Runtime, network, CSP, and security claims still need visible diagnostics.

Workflow

  • ClawSweeper keeps one durable marker-backed review comment per issue or PR.
  • Re-runs edit this comment so the latest verdict, findings, and automation markers stay together instead of adding duplicate bot comments.
  • A fresh review can be triggered by eligible @clawsweeper re-review comments, exact-item GitHub events, scheduled/background review runs, or manual workflow dispatch.
  • PR/issue authors and users with repository write access can comment @clawsweeper re-review or @clawsweeper re-run on an open PR or issue to request a fresh review only.
  • Maintainers can also comment @clawsweeper review to request a fresh review only.
  • Fresh-review commands do not start repair, autofix, rebase, CI repair, or automerge.
  • Maintainer-only repair and merge flows require explicit commands such as @clawsweeper autofix, @clawsweeper automerge, @clawsweeper fix ci, or @clawsweeper address review.
  • Maintainers can comment @clawsweeper explain to ask for more context, or @clawsweeper stop to stop active automation.

History

Review history (2 earlier review cycles)
  • reviewed 2026-09-13T14:13:00.239Z sha be5a589 :: needs real behavior proof before merge. :: none
  • reviewed 2026-09-13T14:36:00.097Z sha be5a589 :: blocked before merge. :: none

@clawsweeper clawsweeper Bot added proof: sufficient ClawSweeper judged the real behavior proof convincing. rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR. and removed rating: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask. labels Sep 13, 2026
@obviyus

obviyus commented Sep 14, 2026

Copy link
Copy Markdown
Collaborator

landpr-approve-admin-merge
pr: 147072
head: 1c3602c
scope: owner-review

@obviyus
obviyus merged commit b5b7ca4 into openclaw:main Sep 14, 2026
231 of 232 checks passed
@obviyus

obviyus commented Sep 14, 2026

Copy link
Copy Markdown
Collaborator

Thanks @PollyBot13 for the fix and the report in #146939!

Proof: Search followed by read returns the exact agent file in both roster orders, with a non-first system agent and explicit workspace pins. Parent traversal remains rejected.

  • Bug: Search found an agent's file, but the read returned a different parent file as success.
  • Fix: Explicit memory reads use the same workspace decision as search, while configured workspace pins remain authoritative.
Before After
Search finds the agent marker; read returns the parent decoy. Read returns the searched agent file and its requested lines.

github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Sep 15, 2026
…w#147072)

Closes openclaw#146939. Related: openclaw#140984.

## What Problem This Solves

Fixes `memory_get` returning a different file from `memory_search` when an explicitly owned multi-agent roster relies on inherited workspace paths.

## User Impact

Search results and subsequent reads agree on the agent's workspace without requiring a per-agent workspace pin. Explicit workspace overrides remain authoritative. No files move, no index reset or storage migration is required, and Markdown containment and read limits are unchanged.

For explicitly owned rosters, an unpinned first agent no longer implicitly reads the parent workspace merely because it appears first. A valid retained migration owner and sole-agent inheritance still follow canonical behavior. Raw reader inputs without explicit ownership keep their existing legacy behavior.

## Why This Change Was Made

The prior path repair in openclaw#140984 deliberately deferred workspace-ownership alignment. This PR proposes only that bounded alignment: core and explicitly owned memory-host reads share the compatibility-owner decision through a pure internal helper. The existing private path bridge avoids importing the full agent runtime. The original config object is preserved for retained migration-owner lookup; optional legacy reader IDs remain accepted.

### Maintainer choices — proposed, not previously approved

1. **Accept explicit-roster alignment (recommended and implemented).** Search's canonical workspace ownership is authoritative for reads too. Alternatively, retain the mismatch and require explicit workspace pins; this PR does not silently change search to match the old getter.
2. **Preserve legacy reader compatibility (implemented).** Inputs without `ownership: "explicit"` retain first-agent/default-marker inheritance. Broader normalization of those inputs is intentionally deferred, rather than changing the shipped reader contract in this fix.
3. **Keep adjacent policy out of scope (recommended).** No context-limit merging changes, shared-system-agent workspace redesign, public SDK entrypoint, or broader path allowlist. Those require separate decisions.

ClawSweeper's source review supports this direction but requests a compatibility decision; it is not maintainer approval. Please review the ownership choice before merge. Rollback is reverting this change; the issue's explicit-workspace-pin mitigation remains available.

## Evidence

### After-fix real Gateway proof — September 13, 2026

Built candidate `be5a589a0ee148b54c51f6876ef5281ee9b29cb5`, Node 26.8.1/macOS. Used a loopback-only Gateway, registered Memory Core tools through HTTP `POST /tools/invoke`, synthetic files and real on-disk SQLite state, `provider: none`, and vectors disabled. No test-helper imports, provider calls, or production configuration/state changes.

| Setup | Actual search → get result |
| --- | --- |
| Fresh explicit two-agent roster, neither agent pinned; parent contains a decoy | main: `USER.md`, `status=ok`, `Orchid proof main`; other: `USER.md`, `status=ok`, `Orchid proof other` |
| Fresh setup, parent traversal for each agent | `MEMORY_PATH_NOT_ALLOWED` |
| Installed 2026.9.3, existing explicit workspace pins | main/other: `USER.md`, `status=ok`, matching `Orchid upgrade main` / `Orchid upgrade other` |
| Same shipped-created state after candidate Doctor migration and candidate Gateway startup | Both agents return those same markers with `status=ok` |

For each agent, passed the search result's path/start line/inclusive line count into `memory_get`. Stopped the shipped Gateway before switching binaries. Candidate initially refused the older session-identity database; followed its supported `doctor --fix --non-interactive` instruction (exit 0, both agent databases v19→v20), then repeated the actual HTTP flow. Both existing workspace pins were preserved exactly, and SHA-256 checks showed all three synthetic `USER.md` files unchanged. Doctor did change normal config metadata/defaults; the whole config was **not** unchanged. All proof Gateways were stopped.

This is fresh-runtime and shipped-created-state/Doctor migration proof, **not** an installer, `openclaw update` driver, or live-user upgrade test. Retained legacy-owner shapes beyond these fixtures remain covered by focused tests, not claimed as live proof. The schema migration belongs to the candidate's existing upgrade path; this six-file patch introduces no schema or embedding-metadata changes. Maintainer acceptance of explicit-roster read-root alignment remains required.

CI at this evidence update: the model-login catalog timing case in [large-26](https://github.com/openclaw/openclaw/actions/runs/34761804381/job/103735936253) failed, making the aggregate gate red. Its fixture disables memory and uses one pinned agent without explicit ownership; likely unrelated, but no matching base failure was verified. No CI pass is claimed.

- Focused validation: 162 tests passed across six files (one existing skipped test), including the real-manager tool regression and package-boundary contracts.
- Final-head `node scripts/check-changed.mjs` passed: core and test types, core/extension lint, formatting, dead-export scans, package/SDK boundaries, and runtime import-cycle checks. `git diff --check` passed.
- Full `pnpm build` passed in 3m26s, including plugin SDK exports, CLI bootstrap imports, built plugin-loading checks, and Control UI build. After that build, the only patch change moved an unchanged re-export below imports for lint; the rebase added only unrelated ACP tests. The repository-wide test suite was not run.
- Tests-first reproduction on upstream main: both roster orders returned the parent decoy through `memory_get` after real SQLite-backed `memory_search` found the agent marker.
- The regression exercises both agents, both roster orders, returned path/line readback, and rejection of parent traversal. It uses temporary files and databases with embeddings disabled; no provider request or private installation data.
- Compatibility coverage includes explicit workspace overrides, retained/removed migration owners, ignored legacy markers under explicit ownership, optional legacy IDs, sole/duplicate agents, and absent/empty rosters. Existing legacy path, file-reader, core ownership, and package-boundary coverage is retained.
- Independent clean-context P0–P3 source review found no actionable findings. The repository Auto Review CLI was also attempted but could not authenticate; no successful CLI review is claimed.

AI-assisted implementation and review. Maintainer approval remains required; no merge or automatic repair authority is inferred from the issue labels.


---

## Maintainer addendum — September 14, 2026

The ownership choices proposed above are accepted. This addendum records the final shared legacy-data owner, the preserved durable runtime default, and the refreshed proof. Earlier evidence remains tied to its stated revision.

### Problem

Memory search finds an agent's file, but `memory_get` returns the parent's different file as success.

### Fix and impact

Search and explicit memory reads now share one lightweight legacy-data owner. The two existing cached facts stay with the agent owner. Raw reader behavior, optional IDs, workspace pins, home/profile handling, and extra paths remain supported. No schema, migration, config key, protocol, or dependency changes.

Owner decision: explicit-roster reads must return the searched workspace's file, never a different parent file. This ends the explicit-roster exception retained in openclaw#140984. To retain the parent as an agent's workspace, configure that workspace explicitly. Legacy data ownership remains separate from the durable runtime default, preserving openclaw#146246.

Production growth is reduced from 46 to 38 net lines:

- `agent-roster.ts` moves existing roster readers into a lightweight module and owns the shared data decision.
- `agent-scope-config.ts` shrinks by 96 lines while preserving public exports and both cache lifetimes.
- Memory-host `config-utils.ts` adds eight net lines to preserve raw-reader compatibility and use the shared owner for explicit inputs.
- `openclaw-runtime-paths.ts` adds the one export needed by that call.

### Evidence

- Main `8751fab4903de6356beacef93401ad0e5f99ea02`: the three unpinned regression rows fail with `status: ok` and `text: Parent decoy`; the pinned control passes. Command: `node scripts/run-vitest.mjs extensions/memory-core/src/tools.real-manager.test.ts -t 'reads the indexed agent file with explicit ownership'`.
- Retained HTTP proof at accepted `a016f35b265a96d4cdfd5d43dbf12d461ae417d2` (the rebuilt branch has identical owner files): real Gateway `POST /tools/invoke`, search then get, covers both roster orders, a non-first system agent, explicit pins, and parent traversal. Eight reads return the known agent file bytes; eight traversals are rejected.
- Fresh merge `f48cf5fc4eb0e717f252fefde7929632f24d494a`, parents candidate above and main `51084d8c93db2a51a7a1aa9b6e1935f78bd0162d`: 297 tests pass, one existing skip, across the owner, memory, session/auth, and Doctor suites below.
- Local production/test type checks, changed-file type-aware lint, formatting, architecture, unused-export, line-count, and assertion checks pass. The assertion allowance only shrinks.
- Retained 2026.9.3-created state proof preserves pins, file hashes, and runtime default through Doctor/restart. This proves state compatibility, not the installed update driver.
- Earlier local matrix replay was stopped; its historical failures remain recorded. Current exact-head CI run [34806299349](https://github.com/openclaw/openclaw/actions/runs/34806299349) completed successfully at `1c3602c201d65ed43e45c4c1c856fe4fcc696dc8`, with every executed job passing.

<details>
<summary>HTTP requests and fresh-merge test command</summary>

The isolated Gateway runs through `pnpm openclaw gateway run --port <isolated-port> --bind loopback`.

```json
{"agentId":"main","tool":"memory_search","args":{"query":"AGENT_MAIN_ORCHID","corpus":"memory"}}
{"agentId":"main","tool":"memory_get","args":{"path":"USER.md","from":1,"lines":3}}
{"agentId":"main","tool":"memory_get","args":{"path":"../USER.md","from":1,"lines":2}}
```

The search-returned path and line range drive the read. The read returns two lines: `# main`, followed by `AGENT_MAIN_ORCHID searched source`. Traversal returns `MEMORY_PATH_NOT_ALLOWED`.

```sh
node scripts/run-vitest.mjs \
  packages/memory-host-sdk/src/host/config-utils.test.ts \
  packages/memory-host-sdk/src/host/read-file.test.ts \
  packages/memory-host-sdk/src/host/read-file-manager-compat.test.ts \
  extensions/memory-core/src/tools.real-manager.test.ts \
  src/agents/agent-scope-config.test.ts \
  src/agents/legacy-inherited-auth-dir.test.ts \
  src/plugins/contracts/extension-package-project-boundaries.test.ts \
  src/config/legacy.roster.test.ts \
  src/commands/sessions.default-agent-store.test.ts \
  src/commands/doctor/shared/legacy-config-migrations.agent-rosters.test.ts \
  src/commands/doctor/shared/legacy-config-migrations.runtime.system-agent.test.ts \
  src/commands/doctor/shared/default-agent-role-materialization.test.ts \
  src/commands/doctor/shared/default-agent-role-materialization.write.test.ts \
  src/commands/doctor-config-flow.workspace-persistence.test.ts \
  src/agents/agent-scope.test.ts \
  src/agents/agent-scope.workspace-inference.test.ts
```

</details>

## Consumers

The moved roster types retain their `index`, `key`, and `kind` fields. The following typed read sites preserve their source-location contracts; generic word matches elsewhere are not consumers of these fields.

<details>
<summary>Preserved roster-field callers</summary>

census: generic index reviewed — 19 callers listed

- `src/agents/sandbox/secret-owner.ts:53:42` — Report unresolved SSH secret references at the selected agent source path.
- `src/cli/config-model-validation.ts:117:90`, `src/cli/config-model-validation.ts:221:62` — Locate model validation issues and test whether edited paths change model ownership at the correct keyed entry or list index.
- `src/commands/doctor/shared/context-engine-host-compat.ts:113:90`, `src/commands/doctor/shared/context-engine-host-compat.ts:153:90` — Locate context-engine host compatibility warnings and repairs at the source agent path.
- `src/commands/doctor/shared/exec-safe-bins.ts:85:35` — Locate executable allowlist warnings at the source agent tools.exec path.
- `src/commands/doctor/shared/plugin-tool-allowlist-warnings.ts:91:90`, `src/commands/doctor/shared/plugin-tool-allowlist-warnings.ts:293:90` — Locate plugin tool allowlist warnings at the source agent path.
- `src/config/io.write-prepare.ts:993:71`, `src/config/io.write-prepare.ts:1000:41` — Preserve original roster representation, legacy occurrence identity, explicit writes/deletions, authored reference restoration, and source paths across config writes.
- `src/config/validation-core.ts:159:36`, `src/config/validation-core.ts:281:90`, `src/config/validation-core.ts:335:55` — Locate avatar, model-policy, and sandbox environment errors at the authored keyed entry or original list index.
- `src/config/validation.ts:715:90` — Attach heartbeat target validation issues to the correct authored agent path.
- `src/secrets/runtime-config-collectors-core.ts:536:35` — Locate agent text-to-speech secret assignments at the source agent path.
- `src/secrets/runtime-config-collectors-memory.ts:125:90` — Locate memory secret assignments at the source agent path; the separate unchanged implicit-agent producer supplies the legacy key when no roster exists.
- `src/secrets/runtime-config-collectors-sandbox.ts:75:90` — Carry the source agent path into sandbox secret collection candidates.
- `src/security/dangerous-config-flags-core.ts:50:36` — Report dangerous flags at canonical keyed paths when an ID exists; retain original list index for an ID-less legacy row.
- `src/skills/workshop/tool-policy-diagnostic.ts:49:40` — Report canonical keyed tool-policy paths when an ID exists; retain original list index for an ID-less legacy row.

census: generic key reviewed — 18 callers listed

- `src/agents/sandbox/secret-owner.ts:52:45` — Report unresolved SSH secret references at the selected agent source path.
- `src/cli/config-model-validation.ts:117:60`, `src/cli/config-model-validation.ts:221:42` — Locate model validation issues and test whether edited paths change model ownership at the correct keyed entry or list index.
- `src/commands/doctor/shared/context-engine-host-compat.ts:113:60`, `src/commands/doctor/shared/context-engine-host-compat.ts:153:60` — Locate context-engine host compatibility warnings and repairs at the source agent path.
- `src/commands/doctor/shared/exec-safe-bins.ts:84:38` — Locate executable allowlist warnings at the source agent tools.exec path.
- `src/commands/doctor/shared/plugin-tool-allowlist-warnings.ts:91:60`, `src/commands/doctor/shared/plugin-tool-allowlist-warnings.ts:293:60` — Locate plugin tool allowlist warnings at the source agent path.
- `src/config/io.write-prepare.ts:1001:44` — Preserve original roster representation, legacy occurrence identity, explicit writes/deletions, authored reference restoration, and source paths across config writes.
- `src/config/validation-core.ts:158:39`, `src/config/validation-core.ts:281:60`, `src/config/validation-core.ts:334:58` — Locate avatar, model-policy, and sandbox environment errors at the authored keyed entry or original list index.
- `src/config/validation.ts:715:60` — Attach heartbeat target validation issues to the correct authored agent path.
- `src/secrets/runtime-config-collectors-core.ts:535:38` — Locate agent text-to-speech secret assignments at the source agent path.
- `src/secrets/runtime-config-collectors-memory.ts:125:60` — Locate memory secret assignments at the source agent path; the separate unchanged implicit-agent producer supplies the legacy key when no roster exists.
- `src/secrets/runtime-config-collectors-sandbox.ts:75:60` — Carry the source agent path into sandbox secret collection candidates.
- `src/security/dangerous-config-flags-core.ts:46:44` — Report dangerous flags at canonical keyed paths when an ID exists; retain original list index for an ID-less legacy row.
- `src/skills/workshop/tool-policy-diagnostic.ts:46:41` — Report canonical keyed tool-policy paths when an ID exists; retain original list index for an ID-less legacy row.

census: generic kind reviewed — 64 callers listed

- `src/agents/agent-roster.ts:23:15`, `src/agents/agent-roster.ts:35:15` — Select the raw representation before projecting entries; preserve entries precedence and reject invalid representation values.
- `src/agents/agent-scope-config.ts:281:15`, `src/agents/agent-scope-config.ts:294:15`, `src/agents/agent-scope-config.ts:329:15`, `src/agents/agent-scope-config.ts:334:15`, `src/agents/agent-scope-config.ts:316:47` — Preserve direct and mutable roster lookup branches; source.kind in the batch index preserves keyed clone-on-read and legacy list identity.
- `src/agents/sandbox/secret-owner.ts:51:25` — Report unresolved SSH secret references at the selected agent source path.
- `src/cli/config-cli-roster.ts:17:21`, `src/cli/config-cli-roster.ts:35:55`, `src/cli/config-cli-roster.ts:53:19`, `src/cli/config-cli-roster.ts:58:17`, `src/cli/config-cli-roster.ts:90:22`, `src/cli/config-cli-roster.ts:107:38` — Preserve list order and keyed/list path translation across CLI mutations and canonicalization.
- `src/cli/config-model-validation.ts:117:14`, `src/cli/config-model-validation.ts:220:14`, `src/cli/config-model-validation.ts:221:14` — Locate model validation issues and test whether edited paths change model ownership at the correct keyed entry or list index.
- `src/commands/doctor-config-flow.ts:255:45` — Read migrated keyed entries to persist the legacy workspace and stamp explicit ownership for multiple agents.
- `src/commands/doctor/shared/context-engine-host-compat.ts:113:14`, `src/commands/doctor/shared/context-engine-host-compat.ts:153:14` — Locate context-engine host compatibility warnings and repairs at the source agent path.
- `src/commands/doctor/shared/exec-safe-bins.ts:83:16` — Locate executable allowlist warnings at the source agent tools.exec path.
- `src/commands/doctor/shared/legacy-config-core-migrate.ts:30:41`, `src/commands/doctor/shared/legacy-config-core-migrate.ts:35:25`, `src/commands/doctor/shared/legacy-config-core-migrate.ts:45:19`, `src/commands/doctor/shared/legacy-config-core-migrate.ts:46:20`, `src/commands/doctor/shared/legacy-config-core-migrate.ts:108:107` — Validate representation/value agreement, repair the selected roster in its existing shape, and name that shape in repair messages.
- `src/commands/doctor/shared/plugin-tool-allowlist-warnings.ts:91:14`, `src/commands/doctor/shared/plugin-tool-allowlist-warnings.ts:293:14` — Locate plugin tool allowlist warnings at the source agent path.
- `src/config/io.write-prepare.ts:892:14`, `src/config/io.write-prepare.ts:951:20`, `src/config/io.write-prepare.ts:1146:15`, `src/config/io.write-prepare.ts:1177:25`, `src/config/io.write-prepare.ts:1185:26`, `src/config/io.write-prepare.ts:1218:23`, `src/config/io.write-prepare.ts:1233:23`, `src/config/io.write-prepare.ts:1255:25`, `src/config/io.write-prepare.ts:1269:23`, `src/config/io.write-prepare.ts:1287:21`, `src/config/io.write-prepare.ts:1330:23`, `src/config/io.write-prepare.ts:1352:21`, `src/config/io.write-prepare.ts:1354:21`, `src/config/io.write-prepare.ts:1450:23`, `src/config/io.write-prepare.ts:1455:27`, `src/config/io.write-prepare.ts:1467:42`, `src/config/io.write-prepare.ts:1532:72`, `src/config/io.write-prepare.ts:1546:23`, `src/config/io.write-prepare.ts:1551:25`, `src/config/io.write-prepare.ts:993:25`, `src/config/io.write-prepare.ts:999:22` — Preserve original roster representation, legacy occurrence identity, explicit writes/deletions, authored reference restoration, and source paths across config writes.
- `src/config/legacy.roster.ts:106:23`, `src/config/legacy.roster.ts:117:35` — Select legacy list conversion, then consume the keyed roster after migration.
- `src/config/validation-core.ts:157:12`, `src/config/validation-core.ts:281:14`, `src/config/validation-core.ts:333:34` — Locate avatar, model-policy, and sandbox environment errors at the authored keyed entry or original list index.
- `src/config/validation.ts:715:14` — Attach heartbeat target validation issues to the correct authored agent path.
- `src/gateway/server-methods/config.ts:528:15`, `src/gateway/server-methods/config.ts:531:15` — Enumerate explicitly authored agent IDs in either representation before rejecting unapproved removals.
- `src/plugins/provider-auth-choice-helpers.ts:304:52`, `src/plugins/provider-auth-choice-helpers.ts:306:52` — Write normalized agent model references back using the original keyed or list representation.
- `src/secrets/runtime-config-collectors-core.ts:534:16` — Locate agent text-to-speech secret assignments at the source agent path.
- `src/secrets/runtime-config-collectors-memory.ts:125:14` — Locate memory secret assignments at the source agent path; the separate unchanged implicit-agent producer supplies the legacy key when no roster exists.
- `src/secrets/runtime-config-collectors-sandbox.ts:75:14` — Carry the source agent path into sandbox secret collection candidates.
- `src/security/dangerous-config-flags-core.ts:45:21` — Report dangerous flags at canonical keyed paths when an ID exists; retain original list index for an ID-less legacy row.
- `src/skills/workshop/tool-policy-diagnostic.ts:45:19` — Report canonical keyed tool-policy paths when an ID exists; retain original list index for an ID-less legacy row.

</details>

Registered memory tools use the shared data owner for explicit workspace reads. Search manager lookup, forget/reset/backfill, session/auth data locations, and Doctor materialization retain their existing owner contracts. There is no new state writer; config-identity provenance and the separate data/runtime batch facts keep their existing lifetimes.

### Contributor-branch refresh

The accepted content is rebuilt on the original contributor head `be5a589a0ee148b54c51f6876ef5281ee9b29cb5`, followed by a plain merge of main `76352103416b7c8c567c8397154af0764ce249fe` and the five maintainer commits in order. There were no conflicts or manual resolutions, and all five messages are unchanged.

The resulting head `1c3602c201d65ed43e45c4c1c856fe4fcc696dc8` has the same complete tree as the accepted revision merged with that main. The 16-file command above passed again on this head: 297 tests, one existing skip, exit 0.


The unchanged local preflight passed on this same head in a physical checkout with its own dependencies. It covered type-aware lint, production types, core/extension/script/root-test types, and protocol checks. The initial nested-checkout attempt failed only the declaration-input isolation guard; physical isolation resolved it without disabling any check.

Co-authored-by: Ayaan Zaidi <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

agents Agent runtime and tooling extensions: memory-core Extension: memory-core merge-risk: 🚨 compatibility 🚨 May break existing users, config, migrations, defaults, or upgrade paths. P2 Normal backlog priority with limited blast radius. proof: sufficient ClawSweeper judged the real behavior proof convincing. rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. size: S status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: memory_get reads a different USER.md than memory_search with explicit agent ownership

2 participants