Skip to content

feat(watcher): auto_watch config gate for background watch registration (default on)#849

Merged
DeusData merged 1 commit into
mainfrom
distill/625-auto-watch
Jul 4, 2026
Merged

feat(watcher): auto_watch config gate for background watch registration (default on)#849
DeusData merged 1 commit into
mainfrom
distill/625-auto-watch

Conversation

@DeusData

@DeusData DeusData commented Jul 4, 2026

Copy link
Copy Markdown
Owner

feat(watcher): auto_watch config gate for background watch registration (default on)

Adds an auto_watch config key that gates whether an MCP session registers its project with the background git watcher on connect. Default is true — existing users keep background auto-sync with zero config changes. Multi-project users who want each session contained to explicit indexing can run:

codebase-memory-mcp config set auto_watch false

What changed

  • src/cli/cli.h — new well-known key CBM_CONFIG_AUTO_WATCH (auto_watch).
  • src/cli/cli.cconfig usage and config list now show the key (default=true).
  • src/mcp/mcp.c — both session watcher-registration sites (autoindex completion, already-indexed connect path) now go through a register_watcher_if_enabled() helper. When disabled, the skip is logged once as a short structured line: watcher.register.skipped reason=auto_watch_off project=<name>.
  • README.md — documented under Auto-Index and Configuration.
  • tests/test_mcp.c — two guards driving the real connect path (initializemaybe_auto_index):
    • default (key unset) → watcher registered (guards the no-behavior-change promise),
    • auto_watch=false → nothing registered (verified RED against the ungated code, GREEN with the gate).

Provenance

Distilled from the auto_watch half of #625 (thanks @Andy11-cpu — credited via Co-authored-by). #625 will be closed referencing this PR.

Deliberate deltas from the original:

  1. Default flipped from false to true — shipping the original opt-in default would have silently disabled background auto-sync for every existing user. As a pure containment knob, opt-out preserves current behavior.
  2. The bundled project-index dedup commit (f7b112e) is excluded — it is Deduplicate project indexes by git/path identity #754's scope and should be reviewed there, not ride along on this knob.
  3. No watch registration added to the index_repository handler — on current main that handler never registered a watch; adding one (as the original PR did) would be new behavior beyond the gate.

Verification

  • make -f Makefile.cbm cbm builds -Werror clean; make -f Makefile.cbm lint-ci passes.
  • Suites mcp, cli, watcher (309 tests) and userconfig all green.
  • Red-first: with production code reverted to origin/main, the auto_watch=false test fails (count == 1, expected 0) — registration was unconditional; the default-case test passes on both, proving no behavior change.

…on (default on)

Add the auto_watch config key (default: true) and route both session
watcher-registration sites in mcp.c (autoindex completion and the
already-indexed connect path) through a register_watcher_if_enabled()
helper. When disabled, the skip is logged as a short structured line
(watcher.register.skipped reason=auto_watch_off).

Default is TRUE (opt-out): existing users keep background auto-sync
unchanged; the knob exists for multi-project users who want each
session contained to explicit indexing.

Distilled from the auto_watch half of PR #625. The PR's bundled
project-index dedup commit is excluded here — it belongs to #754's
own review. Unlike the original PR, no watch registration is added
to the index_repository handler (none exists on main; adding one
would be new behavior beyond the gate), and the default is flipped
from off to on to preserve current behavior.

Tests: default-unset registers the watcher on connect (guards the
no-behavior-change promise); auto_watch=false registers nothing —
verified RED against the ungated production code, GREEN with the gate.

Co-authored-by: Andy11-cpu <canada11@duck.com>
Signed-off-by: Martin Vogel <martin.vogel.tech@gmail.com>
@DeusData DeusData enabled auto-merge July 4, 2026 12:10
@DeusData DeusData merged commit 54efcef into main Jul 4, 2026
15 checks passed
DeusData added a commit that referenced this pull request Jul 4, 2026
…atch (keystone×#849)

The #832 supervisor keystone added a second watcher-registration site in
autoindex_thread's supervised-success branch, but wired it as a direct
cbm_watcher_watch() guarded only by `if (srv->watcher)`. srv->watcher is set
unconditionally (cbm_mcp_server_set_watcher), so that guard does NOT honour the
auto_watch config. PR #849 had routed ALL watcher registration through
register_watcher_if_enabled() (which checks auto_watch_enabled() and logs
watcher.register.skipped reason=auto_watch_off). On a supervisor-marked prod
host with a fresh (unindexed) project and `config set auto_watch false`, the
supervised path therefore registered a background watcher against the user's
explicit opt-out — defeating #849's multi-project containment. The in-process
twin ~20 lines below already used register_watcher_if_enabled() correctly.

Fix: replace the ungated block in the supervised-success branch with
register_watcher_if_enabled(srv), matching the in-process branch. Surrounding
supervised-success logging is unchanged.

Reproduce-first: mcp_auto_watch_false_skips_supervised_autoindex_issue853 drives
the real public entry initialize -> maybe_auto_index -> autoindex_thread on a
supervisor-marked host (kill switch off) with a FRESH project and
auto_watch=false, in a fork+alarm-bounded child (like the #832/#845 gate tests).
cbm_mcp_server_free() joins the autoindex thread so the registration decision has
run before the watch count is read. It asserts spawn_count advanced (so the probe
cannot pass vacuously by skipping the supervised branch) and watch_count == 0.
RED on the unfixed code (watch_count == 1, exit 61); GREEN after the fix
(register_watcher_if_enabled skips → watcher.register.skipped reason=auto_watch_off).

Signed-off-by: Martin Vogel <martin.vogel.tech@gmail.com>
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.

1 participant