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

Function cli_activation_resolve_scope

src/cli/cli.c:613–671  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

611}
612
613static cli_activation_scope_t cli_activation_resolve_scope(
614 cli_activation_production_context_t *context) {
615 const char *runtime_dir = cbm_daemon_ipc_endpoint_runtime_dir(context->endpoint);
616 const char *scope = runtime_dir ? runtime_dir : "";
617 const char *action = cli_activation_action_text(context->action);
618 if (!context->quiesce_required) {
619 (void)snprintf(context->scope_detail, sizeof(context->scope_detail),
620 "nothing to quiesce: published binary and indexes unchanged; scope=%s",
621 scope);
622 cli_activation_log_guard_decision(context, "nothing_to_replace", NULL);
623 printf("No CBM session needs to stop for %s: the published binary and indexes are "
624 "unchanged.\n",
625 action);
626 (void)fflush(stdout);
627 return CLI_ACTIVATION_SCOPE_NOTHING_TO_REPLACE;
628 }
629 cbm_version_cohort_lease_t *lease = NULL;
630 cbm_daemon_conflict_t conflict;
631 memset(&conflict, 0, sizeof(conflict));
632 cbm_version_cohort_status_t status = cbm_version_cohort_acquire(
633 context->cohort_manager, &context->identity, cbm_now_ms(), &lease, &conflict);
634 cli_activation_release_cleanup_lease(context, &lease);
635 if (lease) {
636 return CLI_ACTIVATION_SCOPE_ERROR;
637 }
638 if (g_cli_activation_scope_cache_unreadable_for_test) {
639 conflict.active_cache_fingerprint[0] = '\0';
640 }
641 switch (status) {
642 case CBM_VERSION_COHORT_OK:
643 return CLI_ACTIVATION_SCOPE_ACTIVE;
644 case CBM_VERSION_COHORT_BUSY:
645 return cli_activation_scope_unconfirmed(
646 context, scope, "the session group was busy, so its cache identity could not be read");
647 case CBM_VERSION_COHORT_CONFLICT:
648 break;
649 default:
650 return CLI_ACTIVATION_SCOPE_ERROR;
651 }
652 if (!conflict.active_cache_fingerprint[0]) {
653 return cli_activation_scope_unconfirmed(context, scope,
654 "its cache identity could not be read");
655 }
656 if (strcmp(conflict.active_cache_fingerprint, context->cache_fingerprint) == 0) {
657 /* Positively confirmed: same cache namespace, another build or
658 * version. That IS the daemon this activation replaces. */
659 return CLI_ACTIVATION_SCOPE_ACTIVE;
660 }
661 (void)snprintf(context->scope_detail, sizeof(context->scope_detail),
662 "active cohort serves another cache namespace (%.12s), this %s targets "
663 "%.12s; scope=%s; nothing stopped",
664 conflict.active_cache_fingerprint, action, context->cache_fingerprint, scope);
665 cli_activation_log_guard_decision(context, "foreign_cohort", conflict.active_cache_fingerprint);
666 printf("Leaving active CBM sessions untouched: they serve another cache namespace than "
667 "this %s targets.\n",
668 action);
669 (void)fflush(stdout);
670 return CLI_ACTIVATION_SCOPE_FOREIGN_COHORT;

Callers 1

Tested by

no test coverage detected