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

Function application_index_start_async

src/daemon/application.c:2786–2840  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

2784 "without async"
2785
2786static char *application_index_start_async(cbm_daemon_application_session_t *session,
2787 const char *root_path, const char *args_json) {
2788 cbm_daemon_application_t *application = session->application;
2789 if (application_async_host_missing(session)) {
2790 return cbm_mcp_text_result(APPLICATION_ASYNC_NEEDS_HOST, true);
2791 }
2792 char *project_key = application_index_project_key(root_path, args_json);
2793 if (!project_key) {
2794 return cbm_mcp_text_result("failed to derive index project identity", true);
2795 }
2796 application_jobs_reap_completed(application);
2797 application_job_subscribe_status_t status = APPLICATION_JOB_SUBSCRIBE_UNAVAILABLE;
2798 cbm_mutex_lock(&application->mutex);
2799 /* Subscribe and claim in one critical section: the job cannot publish in
2800 * between, so the async reference is always released by its publish. */
2801 cbm_daemon_application_job_t *job =
2802 application_job_subscribe_locked(application, project_key, root_path, args_json, &status);
2803 bool joined = false;
2804 const char *state = "queued";
2805 if (job) {
2806 joined = job->async_owned || job->subscribers > 1;
2807 if (job->async_owned) {
2808 application_job_unsubscribe_locked(job); /* one async reference per job */
2809 } else {
2810 job->async_owned = true;
2811 }
2812 state = job->worker_started ? "running" : "queued";
2813 cbm_daemon_application_index_record_t *record =
2814 application_index_record_get_locked(application, project_key);
2815 if (record) {
2816 record->async = true;
2817 record->sync_cut_short = false; /* the advice was taken */
2818 }
2819 }
2820 cbm_mutex_unlock(&application->mutex);
2821 char *result = NULL;
2822 if (job) {
2823 cbm_log_info("daemon.index.async", "project", project_key, "joined",
2824 joined ? "true" : "false");
2825 result = application_index_async_response(project_key, state, joined);
2826 } else if (status == APPLICATION_JOB_SUBSCRIBE_BUSY) {
2827 result = cbm_mcp_text_result(
2828 "daemon index job limit reached; async requests do not queue. Retry async later, or "
2829 "call without async to wait for a slot",
2830 true);
2831 } else if (status == APPLICATION_JOB_SUBSCRIBE_CANCELLING) {
2832 result = cbm_mcp_text_result(
2833 "the previous index of this project is still being cancelled; retry async shortly",
2834 true);
2835 } else {
2836 result = cbm_mcp_text_result(application_index_admission_error(status), true);
2837 }
2838 safe_free(project_key);
2839 return result;
2840}
2841
2842static char *application_index_execute(void *context, const char *root_path, const char *args_json,
2843 bool async) {

Callers 1

Tested by

no test coverage detected