Skip to content

File watcher causes infinite re-index loop when watching project root #123

@bxw91

Description

@bxw91

When --watch auto is enabled on a folder that contains the .agent-brain/ directory (i.e. the project root), the file watcher enters an infinite loop:

  1. A job completes → writes to .agent-brain/logs/server.err and .agent-brain/jobs/
  2. watchfiles detects those writes as file changes
  3. A new job is enqueued → completes as a no-op ("all files unchanged")
  4. Repeat forever — server stays permanently in INDEXING state

Root cause

AgentBrainWatchFilter in file_watcher_service.py uses a hardcoded ignore_dirs list that does not include .agent-brain/. The exclude_patterns from config.json are passed to the document loader only — they are not forwarded to watchfiles.awatch().

Expected behavior

.agent-brain/ should be excluded from the file watcher, either by adding it to AgentBrainWatchFilter.ignore_dirs or by passing config exclude_patterns dynamically to watchfiles.awatch().

Suggested fixes

  1. Add .agent-brain to the hardcoded ignore_dirs in AgentBrainWatchFilter:

ignore_dirs = {*DefaultFilter.ignore_dirs, "dist", "build", ".next", ".agent-brain"}

  1. More broadly, consider reading the project's .gitignore and applying those patterns to the file watcher as well (AND to indexer too). Projects already declare what should be ignored there, and respecting it would prevent this class of issue for any similar directories (e.g. .turbo, .parcel-cache, .svelte-kit, etc.).

Environment

  • Agent Brain version: 9.4.1

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions