MCPcopy Create free account
hub / github.com/DeusData/codebase-memory-mcp / autoindex_thread

Function autoindex_thread

src/mcp/mcp.c:20702–20752  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

20700extern void cbm_kind_in_set_free_cache(void);
20701
20702static void *autoindex_thread(void *arg) {
20703 cbm_mcp_server_t *srv = (cbm_mcp_server_t *)arg;
20704
20705 cbm_log_info("autoindex.start", "project", srv->session_project, "path", srv->session_root);
20706
20707 /* #832: use the supervised worker subprocess. Indexing the whole session in
20708 * this long-lived server thread ratchets RSS (mimalloc v3 does not reclaim the
20709 * pages worker threads abandon at exit); running it in a child that exits hands
20710 * 100% of that memory back to the OS every cycle. In a marked host this is a
20711 * safety boundary: preparation/start failure stops the operation. */
20712 if (cbm_index_supervisor_should_wrap()) {
20713 char *resp = index_run_supervised_path(srv, srv->session_root);
20714 if (resp) {
20715 free(resp);
20716 cbm_log_info("autoindex.done", "project", srv->session_project, "mode", "supervised");
20717 /* Register with watcher for ongoing change detection — gated on
20718 * auto_watch (#849), same as the in-process branch below. A bare
20719 * `if (srv->watcher)` would register even when the user set
20720 * `config set auto_watch false`, since srv->watcher is always set. */
20721 register_watcher_if_enabled(srv);
20722 return NULL;
20723 }
20724 cbm_log_error("autoindex.supervision_failed", "project", srv->session_project, "action",
20725 "fail_closed");
20726 return NULL;
20727 }
20728
20729 cbm_pipeline_t *p = cbm_pipeline_new(srv->session_root, NULL, CBM_MODE_FULL);
20730 if (!p) {
20731 cbm_log_warn("autoindex.err", "msg", "pipeline_create_failed");
20732 return NULL;
20733 }
20734 index_doc_candidates_apply(p, index_doc_candidates_choice(srv, NULL));
20735
20736 /* Block until any concurrent pipeline finishes */
20737 cbm_pipeline_lock();
20738 int rc = cbm_pipeline_run(p);
20739 cbm_pipeline_unlock();
20740
20741 cbm_pipeline_free(p);
20742 cbm_kind_in_set_free_cache(); /* free THIS thread's extraction bitset cache (see above) */
20743 cbm_mem_collect(); /* return mimalloc pages to OS after indexing (in-process only) */
20744
20745 if (rc == 0) {
20746 cbm_log_info("autoindex.done", "project", srv->session_project);
20747 register_watcher_if_enabled(srv);
20748 } else {
20749 cbm_log_warn("autoindex.err", "msg", "pipeline_run_failed");
20750 }
20751 return NULL;
20752}
20753
20754bool cbm_mcp_auto_index_within_file_limit(const char *root_path, int file_limit,
20755 int *file_count_out) {

Callers

nothing calls this directly

Calls 12

cbm_pipeline_newFunction · 0.85
cbm_pipeline_lockFunction · 0.85
cbm_pipeline_runFunction · 0.85
cbm_pipeline_unlockFunction · 0.85
cbm_pipeline_freeFunction · 0.85
cbm_mem_collectFunction · 0.85

Tested by

no test coverage detected