Skip to content

fix(memory): toRelative strips workspace root for ROOTED local filesystem paths#1698

Open
McClone wants to merge 1 commit into
agentscope-ai:mainfrom
McClone:fix/toRelative-workspace-path
Open

fix(memory): toRelative strips workspace root for ROOTED local filesystem paths#1698
McClone wants to merge 1 commit into
agentscope-ai:mainfrom
McClone:fix/toRelative-workspace-path

Conversation

@McClone

@McClone McClone commented Jun 10, 2026

Copy link
Copy Markdown

No description provided.

@McClone McClone requested a review from a team June 10, 2026 09:48
@CLAassistant

CLAassistant commented Jun 10, 2026

Copy link
Copy Markdown

CLA assistant check
Thank you for your submission! We really appreciate it. Like many open source projects, we ask that you sign our Contributor License Agreement before we can accept your contribution.


McClone seems not to be a GitHub user. You need a GitHub account to be able to sign the CLA. If you have already a GitHub account, please add the email address used for this commit to your account.
You have signed the CLA already but the status is still pending? Let us recheck it.

@McClone McClone force-pushed the fix/toRelative-workspace-path branch 2 times, most recently from e65c603 to 3863742 Compare June 10, 2026 10:07
…stem paths

In LocalFsMode.ROOTED/UNRESTRICTED, glob returns absolute paths (e.g.,
/data/agent/.agents/memory/2026-06-10.md). The old toRelative() only
stripped the leading '/' which broke resolution in readManagedWorkspaceFileUtf8.

Make toRelative non-static and strip the workspace root prefix via
WorkspaceManager.getWorkspace() when the path is absolute, preserving
the '/' fallback for SANDBOXED virtual paths.
@McClone McClone force-pushed the fix/toRelative-workspace-path branch from 3863742 to 819a19e Compare June 10, 2026 10:08
@codecov

codecov Bot commented Jun 10, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 0% with 5 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
...scope/harness/agent/memory/MemoryConsolidator.java 0.00% 5 Missing ⚠️

📢 Thoughts on this report? Let us know!

McClone pushed a commit to McClone/agentscope-java that referenced this pull request Jun 10, 2026
…scope-ai#1698)

Patch coverage was 0% — the 5 new lines in toRelative() were unreachable
via the existing RemoteFilesystem-based tests.  Changed toRelative() from
private to package-private and added three test cases that exercise:
- absolute path under workspace root (the primary fix path)
- absolute path outside workspace root (falls through to old behaviour)
- null and relative paths (edge cases)
@AgentScopeJavaBot AgentScopeJavaBot added bug Something isn't working area/harness agentscope-harness (test/runtime support) labels Jun 11, 2026

@AgentScopeJavaBot AgentScopeJavaBot 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.

🤖 AI Review

This is a small, focused bugfix for MemoryConsolidator.toRelative(). The old implementation naively stripped the leading / from any path, which worked for SANDBOXED virtual paths (e.g. /memory/file.mdmemory/file.md) but produced incorrect results for ROOTED local filesystem paths (e.g. /home/user/workspace/memory/file.mdhome/user/workspace/memory/file.md). The fix correctly uses java.nio.file.Path to detect absolute paths rooted under the workspace and relativize them. The static-to-instance conversion is necessary and correct. Downstream normalizeRelativePath() already handles OS-specific separators, so no cross-platform issue. The only gap is the lack of a regression test for the exact scenario being fixed.

if (path == null) {
return "";
}
Path p = Path.of(path);

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.

[nitpick] No regression test is included for the bug being fixed. The existing MemoryConsolidatorFilesystemTest exercises the Remote/InMemoryStore path but never covers the local ROOTED (non-sandboxed, non-namespaced) case where FileInfo.path() is a real absolute filesystem path. Consider adding a unit test that creates a local WorkspaceManager with a @TempDir, seeds a memory/ directory, and asserts that consolidate() reads daily ledgers correctly — or at minimum a package-private test that directly invokes toRelative() with all three path shapes (SANDBOXED /memory/x.md, ROOTED absolute /tmp/ws/memory/x.md, namespace-relative ns/memory/x.md).

@AgentScopeJavaBot AgentScopeJavaBot 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.

🤖 AI Review

This is a small, focused bugfix for MemoryConsolidator.toRelative(). The old implementation naively stripped the leading / from any path, which worked for SANDBOXED virtual paths (e.g. /memory/file.mdmemory/file.md) but produced incorrect results for ROOTED local filesystem paths (e.g. /home/user/workspace/memory/file.mdhome/user/workspace/memory/file.md). The fix correctly uses java.nio.file.Path to detect absolute paths rooted under the workspace and relativize them. The static-to-instance conversion is necessary and correct. Downstream normalizeRelativePath() already handles OS-specific separators, so no cross-platform issue. The only gap is the lack of a regression test for the exact scenario being fixed.

if (path == null) {
return "";
}
Path p = Path.of(path);

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.

[nitpick] No regression test is included for the bug being fixed. The existing MemoryConsolidatorFilesystemTest exercises the Remote/InMemoryStore path but never covers the local ROOTED (non-sandboxed, non-namespaced) case where FileInfo.path() is a real absolute filesystem path. Consider adding a unit test that creates a local WorkspaceManager with a @TempDir, seeds a memory/ directory, and asserts that consolidate() reads daily ledgers correctly — or at minimum a package-private test that directly invokes toRelative() with all three path shapes (SANDBOXED /memory/x.md, ROOTED absolute /tmp/ws/memory/x.md, namespace-relative ns/memory/x.md).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area/harness agentscope-harness (test/runtime support) bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants