Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
import io.agentscope.harness.agent.filesystem.model.FileInfo;
import io.agentscope.harness.agent.filesystem.model.GlobResult;
import io.agentscope.harness.agent.workspace.WorkspaceManager;
import java.nio.file.Path;
import java.time.Instant;
import java.util.ArrayList;
import java.util.Comparator;
Expand Down Expand Up @@ -264,14 +265,22 @@ private static String fileName(String path) {
}

/**
* Converts an absolute filesystem path (e.g. {@code /memory/2025-01-01.md}) to a
* workspace-relative path ({@code memory/2025-01-01.md}) for use with
* {@link WorkspaceManager#readManagedWorkspaceFileUtf8}.
* Converts an absolute filesystem path to a workspace-relative path for use
* with {@link WorkspaceManager#readManagedWorkspaceFileUtf8}. Strips the
* workspace root prefix when the path is an absolute local filesystem path;
* strips only the leading {@code /} for SANDBOXED virtual paths.
*/
private static String toRelative(String path) {
private String toRelative(String path) {
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).

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).

if (p.isAbsolute()) {
Path root = workspaceManager.getWorkspace();
if (p.startsWith(root)) {
return root.relativize(p).toString();
}
}
return path.startsWith("/") ? path.substring(1) : path;
}

Expand Down
Loading