agentscope-ai / agentscope-ai/agentscope-java

[Bug]:LocalFilesystem.glob 使用 **/*.md 无法匹配目录直接子文件,导致 MemoryConsolidator consolidation 失效

未关闭
#1,458 4 条评论 0 个 reaction 已指派 1 人 已被 @guslegend0510 认领 在 GitHub 查看
area/harness bug
主要语言
Java
星标
5.6k
派生
1.3k
平均合并
4 天 12 小时
30 天内合并 PR
77

描述

**问题描述:**

`LocalFilesystem.glob()` 在 `walkFileTree` 的 `visitFile` 回调中,将 `pattern`(如 `*.md`)转换为 `**/*.md` 后,用 `PathMatcher` 匹配 `searchPath.relativize(file)` 的结果。

当被搜索目录(如 `memory/`)下直接存放文件(如 `2026-05-20.md`)时,`relativize` 结果只有文件名,没有任何目录前缀,`**/*.md` 要求至少有一层 `/`,导致**匹配失败**,返回空列表。

**复现路径:**

1. `MemoryMaintenanceHook.onEvent(PostCallEvent)` 触发
2. 调用 `MemoryConsolidator.consolidate()`
3. 调用 `readDailyEntries(watermark)`
4. 调用 `fs.glob(DEFAULT_FS_RUNTIME, "*.md", "memory")`
5. `glob` 内部 `walkFileTree` 遍历 `memory/` 目录,找到 `2026-05-20.md`
6. `rel = "2026-05-20.md"`,用 `**/*.md` 匹配 → **失败**
7. 返回空列表 → `dailyEntries` 为空 → 跳过 consolidation → `MEMORY.md` 永远不更新

**根本原因:**

```java
// LocalFilesystem.java
String globExpr = effectivePattern.startsWith("**") ? effectivePattern : "**/" + effectivePattern;
PathMatcher matcher = fs.getPathMatcher("glob:" + globExpr);
// ↑ "*.md" 被转成 "**/*.md",但直接子文件的相对路径只有文件名,匹配失败

// visitFile 里只有:
if (matcher.matches(rel)) { ... }
// ↑ 缺少对 directMatcher("*.md") 的检查
```

**修复方案:**

在 `visitFile` 里同时检查 `directMatcher`:

```java
PathMatcher directMatcher = fs.getPathMatcher("glob:" + effectivePattern);

// visitFile 里改为:
if (matcher.matches(rel) || directMatcher.matches(rel)) {
// ...
}
```

**影响范围:**

所有调用 `fs.glob(pattern, path)` 且目标文件直接位于 `path` 根目录下的场景,包括但不限于:
- `MemoryConsolidator.readDailyEntries()` — `memory/*.md`
- `MemoryMaintenanceHook.expireDailyFiles()` — `memory/*.md`
- `MemoryMaintenanceHook.pruneOldSessions()` — `agents/*.log.jsonl`

贡献指南

打开贡献指南

评估

这个 Issue 还没有评估数据。

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。