feat(watcher): auto_watch config gate for background watch registration (default on)#849
Merged
Conversation
…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>
4 tasks
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>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
feat(watcher):
auto_watchconfig gate for background watch registration (default on)Adds an
auto_watchconfig key that gates whether an MCP session registers its project with the background git watcher on connect. Default istrue— existing users keep background auto-sync with zero config changes. Multi-project users who want each session contained to explicit indexing can run:What changed
src/cli/cli.h— new well-known keyCBM_CONFIG_AUTO_WATCH(auto_watch).src/cli/cli.c—configusage andconfig listnow show the key (default=true).src/mcp/mcp.c— both session watcher-registration sites (autoindex completion, already-indexed connect path) now go through aregister_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 (initialize→maybe_auto_index):auto_watch=false→ nothing registered (verified RED against the ungated code, GREEN with the gate).Provenance
Distilled from the
auto_watchhalf of #625 (thanks @Andy11-cpu — credited viaCo-authored-by). #625 will be closed referencing this PR.Deliberate deltas from the original:
falsetotrue— 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.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.index_repositoryhandler — on currentmainthat handler never registered a watch; adding one (as the original PR did) would be new behavior beyond the gate.Verification
make -f Makefile.cbm cbmbuilds-Werrorclean;make -f Makefile.cbm lint-cipasses.mcp,cli,watcher(309 tests) anduserconfigall green.origin/main, theauto_watch=falsetest fails (count == 1, expected 0) — registration was unconditional; the default-case test passes on both, proving no behavior change.