Skip to content

feat(watch): add config option to disable linked worktree discovery - #270

Open
rusel95 wants to merge 3 commits into
yoanbernabeu:mainfrom
rusel95:feat/watch-worktree-discovery-optout
Open

feat(watch): add config option to disable linked worktree discovery#270
rusel95 wants to merge 3 commits into
yoanbernabeu:mainfrom
rusel95:feat/watch-worktree-discovery-optout

Conversation

@rusel95

@rusel95 rusel95 commented Jul 2, 2026

Copy link
Copy Markdown

Problem

Fixes #211. grepai watch in a main worktree unconditionally discovers all linked git worktrees, auto-initializes them (creates .grepai/, edits their .gitignore) and watches them alongside the main project. There is no way to opt out.

For workflows that create many short-lived worktrees — AI-agent sessions, git worktree-based review checkouts — this multiplies indexing work, embedding calls and resident memory by the worktree count. The #211 author tried five separate workarounds (ignore patterns, per-worktree configs, killing sub-watchers…) — none work, because discovery is a separate mechanism from file scanning and ignores all of them.

Change

One new key in .grepai/config.yaml, read in the main worktree:

watch:
  discover_worktrees: false   # default: true
  • Backward compatible by construction: the field is a *bool (omitempty), so existing configs — and configs rewritten by the watcher — keep the historical behavior (enabled) unless the user explicitly opts out. WorktreeDiscoveryEnabled() encapsulates the default.
  • Single choke point: the guard lives inside discoverWorktreesForWatch, which is the sole entry to discovery, so the initial scan, the TUI path and the supervisor's periodic reconcile all respect it.
  • Live toggle: the config is re-read on every discovery pass (3s reconcile), so flipping the option takes effect within seconds without restarting the watcher; already-watched worktrees are released on the next pass.
  • Fails closed: if the config can't be loaded (e.g. a torn write while the user edits it between two reconcile passes), discovery is skipped for that pass and a warning is logged — a broken config can never silently re-enable the side-effectful auto-init the user opted out of.

Tests

  • main worktree discovers + auto-inits a linked worktree (baseline, key absent)
  • discover_worktrees: false → no discovery, no auto-init side effects
  • linked worktree never discovers siblings regardless of the option
  • unreadable/torn config → fail closed, no discovery, no auto-init
  • WorktreeDiscoveryEnabled() accessor: nil/true/false table test
  • YAML round-trip: explicit false survives config load/save

Docs

configuration.md and watch-guide.md now list the key; git-worktrees.md gains a "Disabling Worktree Discovery" section and two troubleshooting rows (discovery not triggering; too many worktrees indexed).

🤖 Generated with Claude Code

ruslanpopesku-ops and others added 3 commits July 2, 2026 12:57
grepai watch auto-discovers and indexes every linked git worktree with
no way to opt out. In projects where tooling creates many short-lived
worktrees (e.g. AI coding agents), each one triggers a parallel initial
scan and its own watch session, multiplying memory usage and embedding
work for trees that are throwaway copies of the main checkout.

Add watch.discover_worktrees to config.yaml:

    watch:
      discover_worktrees: false

The option is a pointer-typed bool so existing configs without the key
keep the historical default (enabled). The check lives inside
discoverWorktreesForWatch, so it covers the initial scan, the TUI path,
and the supervisor's periodic reconcile - toggling it takes effect on
the next reconcile without restarting the watcher.

Fixes yoanbernabeu#211

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
…worktrees

Review findings on the original commit:
- a torn/invalid config during the 3s reconcile no longer silently
  re-enables discovery (which auto-inits worktrees — a side effect that
  is not free to undo); the error is now logged and the pass skipped
- test pins the fail-closed direction
- the option is documented in watch-guide, configuration and
  git-worktrees docs (incl. a 'Disabling Worktree Discovery' section)
- struct comment notes the key is only read from the main worktree

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
markpinero added a commit to hi-high/grepai that referenced this pull request Jul 29, 2026
Bring in high-value open upstream fixes for Qdrant multi-project
workspaces, monorepo watch startup, Ollama resilience, and worktree
fan-out control:

- yoanbernabeu#248 qdrant project namespace
- yoanbernabeu#263 workspace ListDocuments scope
- yoanbernabeu#207 qdrant gRPC message size
- yoanbernabeu#257 embedder timeout/retries
- yoanbernabeu#277 parallel change detection
- yoanbernabeu#270 discover_worktrees config
- yoanbernabeu#203 gitignore root guard
- yoanbernabeu#264 symbol extractor version invalidation

Keeps prior mark.1 harden (atomic GOB, corrupt recovery, 90s shutdown,
--no-worktrees).
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add config option to disable automatic git worktree discovery in grepai watch

2 participants