agentscope-ai / agentscope-ai/agentscope-java

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

Aperta
#1,458 4 commenti 0 reazioni 1 assegnatario Rivendicata da @guslegend0510 Vedi su GitHub
area/harness bug
Lingua principale
Java
Stelle
5.6k
Fork
1.3k
Merge medio
4g 12h
PR unite (30g)
77

Descrizione

**问题描述:**

`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`

Guida per i contributori

Apri la guida per i contributori

Valutazione

Questa issue non è ancora stata valutata.

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.