Skip to content

fix(memory): read the file found in the agent workspace - #147675

Closed
obviyus wants to merge 7 commits into
mainfrom
bugloop/memory-get-workspace-owner
Closed

obviyus wants to merge 7 commits into
mainfrom
bugloop/memory-get-workspace-owner

Conversation

@obviyus

@obviyus obviyus commented Sep 14, 2026 •

Copy link
Copy Markdown
Collaborator

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'.
  • Candidate a016f35b265a96d4cdfd5d43dbf12d461ae417d2: 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. Six completed failure comparisons matched main; four other failures remain unclassified. The full matrix belongs to hosted CI and is not claimed green here.
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

Supersedes #147072 by @PollyBot13. Thanks to @PollyBot13 for reporting #146939 and contributing the original fix; both contributor commits retain their authorship.

@clawsweeper

clawsweeper Bot commented Sep 14, 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: M maintainer Maintainer-authored PR labels Sep 14, 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. 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. labels Sep 14, 2026
@clawsweeper

clawsweeper Bot commented Sep 14, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: blocked before merge. Reviewed September 13, 2026, 11:56 PM ET / September 14, 2026, 03:56 UTC (Revision 2).

ClawSweeper review

What this changes

Makes memory file reads use the same agent workspace as memory search by sharing legacy-data ownership resolution, while preserving explicit workspace settings and legacy reader behavior.

Merge readiness

⛔ Blocked before merge - 2 items remain

This remains a useful fix: current main and v2026.9.4 still have the divergent workspace rules. The reviewed patch has no actionable correctness findings, and the recorded Gateway proof supports the intended behavior.

Priority: P2
Reviewed head: a016f35b265a96d4cdfd5d43dbf12d461ae417d2

Review scores

Measure Result What it means
Overall readiness 🐚 platinum hermit (4/6) A focused owner-level repair with meaningful runtime proof and an explicitly documented compatibility tradeoff.
Proof confidence 🦞 diamond lobster (5/6) Sufficient (live_output): The captured candidate Gateway evidence exercises registered search/get tools through HTTP and reports matching agent-file bytes plus rejected parent traversal across four configurations; retained shipped-state proof separately covers pins and Doctor/restart compatibility.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Verification

Check Result Evidence
Real behavior Verified Sufficient (live_output): The captured candidate Gateway evidence exercises registered search/get tools through HTTP and reports matching agent-file bytes plus rejected parent traversal across four configurations; retained shipped-state proof separately covers pins and Doctor/restart compatibility.
Evidence reviewed 8 items Current main still needs the fix: The memory-host resolver grants the shared workspace to the first/default reader agent, whereas the core search workspace resolver uses legacy-data ownership. An explicit two-agent roster without workspace pins therefore selects different roots.
Latest release retains the old reader rule: Inspection of v2026.9.4 confirms first-agent/default-marker workspace inheritance remains in the released memory-host resolver.
Narrow ownership cutover: Explicit inputs use the shared legacy-data owner; non-explicit reader inputs retain their previous selection. Configured workspace pins still take precedence. Core retains both batch-scoped ownership caches and its existing exports.
Findings None None.
Security None None.

How this fits together

Memory Core searches an agent’s indexed notes and returns file paths and line ranges. The memory-host reader resolves those paths against the agent’s workspace and validates them before returning file contents.

flowchart TD
  A[Agent 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[Path containment check]
  F --> G[File contents or read error]
Loading

Before merge

  • Resolve merge risk (P1) - An unpinned explicit agent that relied on parent-only files will stop reading those files unless its workspace is explicitly pinned there. The PR records this intentional compatibility change; its prevalence in existing installations remains unknown.
  • 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 The production growth supports a shared lightweight ownership module while retaining existing cache lifetimes and legacy reader compatibility.

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 addresses the reported wrong-workspace read and explicitly adopts the earlier contributor fix.

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 documented ownership choice (recommended)
    Accept explicit-roster alignment with search, keeping workspace pins as the supported way to preserve parent-root reads.

Technical review

Best possible solution:

Keep search and reads on one workspace-ownership rule, honoring the recorded compatibility choice and preserving explicit pins and migrated data locations.

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

Yes: an explicit two-agent roster with distinct parent and agent USER.md markers exposes the divergent resolvers on current main. This review established the path from source; the PR separately reports failing-before tests and successful candidate Gateway runs.

Is this the best way to solve the issue?

Yes: sharing the existing legacy-data decision repairs the mismatch without changing runtime-default selection, moving files, or expanding the allowlist.

AGENTS.md: found and applied where relevant.

Codex review notes: model internal, reasoning medium; reviewed against 65710d3e8bac.

Labels

Label justifications:

  • P2: Repairs wrong-file memory reads in a bounded explicit multi-agent configuration.
  • merge-risk: 🚨 compatibility: Unpinned explicit agents lose implicit parent-root reads, an intentional behavior change requiring a workspace pin when that location is desired.
  • 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): The captured candidate Gateway evidence exercises registered search/get tools through HTTP and reports matching agent-file bytes plus rejected parent traversal across four configurations; retained shipped-state proof separately covers pins and Doctor/restart compatibility.
  • proof: sufficient: Contributor real behavior proof is sufficient. The captured candidate Gateway evidence exercises registered search/get tools through HTTP and reports matching agent-file bytes plus rejected parent traversal across four configurations; retained shipped-state proof separately covers pins and Doctor/restart compatibility.

Evidence

What I checked:

  • Current main still needs the fix: The memory-host resolver grants the shared workspace to the first/default reader agent, whereas the core search workspace resolver uses legacy-data ownership. An explicit two-agent roster without workspace pins therefore selects different roots. (packages/memory-host-sdk/src/host/config-utils.ts:173, 65710d3e8bac)
  • Latest release retains the old reader rule: Inspection of v2026.9.4 confirms first-agent/default-marker workspace inheritance remains in the released memory-host resolver. (packages/memory-host-sdk/src/host/config-utils.ts:173, 3a9d69db306c)
  • Narrow ownership cutover: Explicit inputs use the shared legacy-data owner; non-explicit reader inputs retain their previous selection. Configured workspace pins still take precedence. Core retains both batch-scoped ownership caches and its existing exports. (packages/memory-host-sdk/src/host/config-utils.ts:177, a016f35b265a)
  • Production read boundary: The registered memory_get tool passes the selected config and agent into readAgentMemoryFile. The reader resolves the workspace before its existing Markdown, traversal, and symlink checks; the patch does not broaden the read allowlist. (packages/memory-host-sdk/src/host/read-file.ts:195, a016f35b265a)
  • Behavior and compatibility proof: The captured PR body, sourceRevision d729e6b089fb0c3c88de6cca8e41a2c40ee76a54545e34a82f8350e57dd43318, records real Gateway POST /tools/invoke runs on this head: eight search-to-get reads return agent markers and eight parent traversals are rejected across roster orders, system-agent selection, and pins. Retained 2026.9.3-created-state evidence preserves pins, file hashes, and runtime default through Doctor/restart; it explicitly does not claim installed-updater proof. The added real-manager regression exercises the same observable contract. (extensions/memory-core/src/tools.real-manager.test.ts:36, a016f35b265a)
  • Prior compatibility decision and current disposition: fix(memory): honor profile and home paths in host lookups #140984 deliberately deferred workspace-ownership alignment. This PR explicitly records ending that exception for explicit rosters and documents workspace pins as the way to retain parent-root reads. The previous review contained no findings or published rank-up moves; its compatibility warning remains relevant context.

Likely related people:

  • unknown: The claimed source-line change could not be verified from bounded local history. (role: source history unknown; 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 (1 earlier review cycle)
  • reviewed 2026-09-14T01:44:03.783Z sha fc5dcfd :: blocked before merge. :: none

@obviyus

obviyus commented Sep 14, 2026

Copy link
Copy Markdown
Collaborator Author

Closing: this work now lives on #147072 itself (the contributor's branch accepts maintainer edits), with the same commits on top of theirs. AI-assisted.

@obviyus obviyus closed this Sep 14, 2026
@obviyus
obviyus deleted the bugloop/memory-get-workspace-owner branch September 14, 2026 04:41
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 maintainer Maintainer-authored PR 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: M 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.

2 participants