Skip to content

Compress tool outputs, logs, files, and RAG chunks before they reach the LLM. 20% fewer tokens for coding agents, 60-95% fewer tokens for JSON, same answers. Library, proxy, MCP server.

fix(learn): treat an unreadable project memory dir as absent instead of crashing (#3710)

gglucassff60d5764c64
diff --git a/headroom/learn/plugins/claude.py b/headroom/learn/plugins/claude.py
index 14b6c2061..b4dd1c694 100644
--- a/headroom/learn/plugins/claude.py
+++ b/headroom/learn/plugins/claude.py
@@ -88,9 +88,12 @@ class ClaudeCodePlugin(LearnPlugin, ConversationScanner):
if _path_exists(claude_md):
context_file = claude_md
+ # `entry` itself stats fine (its parent is ours) but a project dir
+ # left behind by a root-run session is not traversable, so stat-ing
+ # anything under it raises PermissionError. Treat that as absent.
memory_dir = entry / "memory"
- memory_file = memory_dir / "MEMORY.md" if memory_dir.exists() else None
- if memory_file and not memory_file.exists():
+ memory_file = memory_dir / "MEMORY.md" if _path_exists(memory_dir) else None
+ if memory_file and not _path_exists(memory_file):
memory_file = None
jsonl_files = list(entry.glob("*.jsonl"))
diff --git a/tests/test_learn/test_plugin_permission_errors.py b/tests/test_learn/test_plugin_permission_errors.py
index 575cb07dd..b50e12f8f 100644
--- a/tests/test_learn/test_plugin_permission_errors.py
+++ b/tests/test_learn/test_plugin_permission_errors.py
@@ -121,3 +121,30 @@ def test_opencode_discover_projects_survives_permission_error(
projects = plugin.discover_projects()
assert len(projects) == 1
assert projects[0].context_file is None
+
+
+def test_claude_discover_projects_survives_unreadable_memory_dir(
+ tmp_path: Path, monkeypatch: pytest.MonkeyPatch
+) -> None:
+ from headroom.learn.plugins.claude import ClaudeCodePlugin
+
+ # A project dir left behind by a root-run session: the entry itself stats
+ # (its parent is ours) but nothing under it is traversable.
+ projects_dir = tmp_path / "projects"
+ entry = projects_dir / "-"
+ entry.mkdir(parents=True)
+ (entry / "session.jsonl").write_text("{}\n", encoding="utf-8")
+
+ real_exists = Path.exists
+
+ def _boom_under_entry(self: Path) -> bool:
+ if self.name == "memory" or self.parent.name == "memory":
+ raise PermissionError(13, "Permission denied", str(self))
+ return real_exists(self)
+
+ monkeypatch.setattr(Path, "exists", _boom_under_entry)
+
+ plugin = ClaudeCodePlugin(claude_dir=tmp_path)
+ projects = plugin.discover_projects()
+ assert [p.data_path for p in projects] == [entry]
+ assert projects[0].memory_file is None