Skip to content

Commit b38823b

Browse files
committed
fix(sync): guard empty project list in watch loop
When constrained_project names a project not in the DB, or every active project is filtered out by cloud-mode rules, _select_projects_to_watch() returns []. watchfiles.awatch() raises ValueError on an empty path list, which the outer handler catches with a 5-second sleep — producing a tight error-log loop until a project appears. Addresses review feedback on #759: sleep 30 s and retry instead, giving the project list time to populate (e.g. after the user adds a project). Logs include the constrained_project value so misconfiguration is easy to diagnose. Signed-off-by: phernandez <paul@basicmachines.co>
1 parent 5b95504 commit b38823b

1 file changed

Lines changed: 15 additions & 0 deletions

File tree

src/basic_memory/sync/watch_service.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -211,6 +211,21 @@ async def run(self): # pragma: no cover
211211

212212
projects = await self._select_projects_to_watch()
213213

214+
# Trigger: no projects selected (e.g. constrained_project names a
215+
# project not in the DB, or every project was filtered out)
216+
# Why: watchfiles.awatch() requires at least one path. Calling it
217+
# with an empty list raises ValueError, which the outer handler
218+
# catches with a 5s sleep — producing a tight error-log loop.
219+
# Outcome: sleep longer and retry, giving the project list a chance
220+
# to populate (e.g. after a project is added).
221+
if not projects:
222+
logger.warning(
223+
"No projects to watch; sleeping before retry "
224+
f"(constrained_project={self.constrained_project!r})"
225+
)
226+
await asyncio.sleep(30)
227+
continue
228+
214229
project_paths = [project.path for project in projects]
215230
logger.debug(f"Starting watch cycle for directories: {project_paths}")
216231

0 commit comments

Comments
 (0)