Skip to content

Local UI to run and train LLMs and diffusion models. Supports GGUF, MLX, Qwen3.8, DeepSeek-V4.1, MiniMax-H3, Gemma 4, FLUX and more.

Fix linked-folder indexing of hidden subdirectories (#12972)

Lee Jacksonc64ae58a2689
diff --git a/studio/backend/core/rag/folder_sync.py b/studio/backend/core/rag/folder_sync.py
index e9bd35e1b10..f50b0d08982 100644
--- a/studio/backend/core/rag/folder_sync.py
+++ b/studio/backend/core/rag/folder_sync.py
@@ -76,11 +76,16 @@ _LOCKFILES = frozenset(
def _is_ignored_scan_dir(name: str, path: str) -> bool:
- return name.lower() in _IGNORE_SCAN_DIRS or os.path.exists(os.path.join(path, "pyvenv.cfg"))
+ # hidden subtrees can contain application configuration and plugins such as .obsidian.
+ return (
+ name.startswith(".")
+ or name.lower() in _IGNORE_SCAN_DIRS
+ or os.path.exists(os.path.join(path, "pyvenv.cfg"))
+ )
def _is_ignored_scan_file(name: str) -> bool:
- # .env and Terraform state hold plaintext secrets that retrieval would paste into prompts; lockfiles are noise.
+ # .env and Terraform state can expose plaintext secrets in retrieval; lockfiles add noise.
lower = name.lower()
if lower == ".env" or lower.startswith(".env.") or lower.endswith(".env"):
return True
@@ -1205,7 +1210,7 @@ def _check_root_identity(root: str, expected: tuple[int, int]) -> None:
def _source_reappeared(root: str, relative_path: str) -> bool:
- """Check scanner eligibility without following a replaced path component."""
+ """check scanner eligibility without following a replaced path component."""
path = PurePosixPath(relative_path)
parts = path.parts
if (
@@ -1217,6 +1222,9 @@ def _source_reappeared(root: str, relative_path: str) -> bool:
raise _FolderChanged("Linked folder mapping has an invalid relative path")
current = root
for index, part in enumerate(parts):
+ # previously indexed dot directories are excluded even if they still exist
+ if index < len(parts) - 1 and part.startswith("."):
+ return False
current = os.path.join(current, part)
try:
current_stat = os.lstat(current)
diff --git a/studio/backend/tests/test_rag_linked_folders.py b/studio/backend/tests/test_rag_linked_folders.py
index 2621bef41cb..bf8fad6df5e 100644
--- a/studio/backend/tests/test_rag_linked_folders.py
+++ b/studio/backend/tests/test_rag_linked_folders.py
@@ -423,6 +423,50 @@ def test_reconcile_add_rename_delete_and_skip_unsupported_and_symlinks(rag_home,
)
[email protected]("relative", [".obsidian", "notes/.obsidian", ".cache"])
+def test_scan_does_not_enter_dot_directories(tmp_path, monkeypatch, relative):
+ source = tmp_path / "vault"
+ hidden = source / relative
+ (hidden / "plugins").mkdir(parents = True)
+ (hidden / "plugins" / "manifest.json").write_text("{}", encoding = "utf-8")
+ visible = source / "notes" / "v1.0"
+ visible.mkdir(parents = True, exist_ok = True)
+ (visible / "note.md").write_text("visible note", encoding = "utf-8")
+ original_scandir = os.scandir
+
+ def guarded_scandir(path):
+ assert Path(path) != hidden, "Hidden directories must not be traversed"
+ return original_scandir(path)
+
+ monkeypatch.setattr(folder_sync.os, "scandir", guarded_scandir)
+ found, _ = folder_sync._scan(str(source))
+ assert set(found) == {"notes/v1.0/note.md"}
+
+
+@requires_sqlite_vec
[email protected]("already_indexed", [False, True])
+def test_sync_removes_documents_in_a_dot_directory(rag_home, stub_embeddings, already_indexed):
+ source, folder = _folder(rag_home)
+ notes = source / "notes"
+ notes.mkdir()
+ (notes / "note.txt").write_text("hiddencontenttoken", encoding = "utf-8")
+ (source / "visible.txt").write_text("visiblecontenttoken", encoding = "utf-8")
+ assert _run(folder["id"])["discovered"] == 2
+
+ notes.rename(source / ".obsidian")
+ if already_indexed:
+ # reproduce a mapping created before dot directories were excluded.
+ folder_sync._rename_mapping(folder["id"], "notes/note.txt", ".obsidian/note.txt")
+ result = _run(folder["id"])
+ assert result["status"] == "completed"
+ assert result["discovered"] == 1
+ assert result["deleted"] == 1
+ with _connection() as conn:
+ assert not store.search_lexical(conn, folder["scope"], "hiddencontenttoken", 5)
+ assert store.search_lexical(conn, folder["scope"], "visiblecontenttoken", 5)
+ assert (source / ".obsidian" / "note.txt").is_file()
+
+
def test_scan_skips_revisited_directory_identity(rag_home, monkeypatch):
source = rag_home / "cycle"
loop = source / "loop"