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

Function cli_activation_guard

src/cli/cli.c:683–739  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

681}
682
683static int cli_activation_guard(cbm_daemon_runtime_activation_action_t action,
684 const char *target_version, const char *target_build,
685 cbm_cli_activation_mutation_fn mutation, void *mutation_context) {
686 if (g_cli_activation_test_ops_set) {
687 return cbm_cli_activation_guard_with_ops(&g_cli_activation_test_ops, mutation,
688 mutation_context);
689 }
690
691 cli_activation_production_context_t context;
692 if (!cli_activation_production_context_init(&context, action, target_version, target_build)) {
693 cli_activation_production_context_close(&context);
694 cli_activation_production_diagnostic(NULL, CLI_ACTIVATION_REFUSED_MESSAGE);
695 return CLI_TRUE;
696 }
697 printf("Stopping active CBM sessions and operations for %s...\n",
698 cli_activation_action_text(action));
699 (void)fflush(stdout);
700 if (!cli_activation_log_event(&context, "requested", NULL)) {
701 cli_activation_production_context_close(&context);
702 (void)fprintf(stderr, "error: activation request could not be recorded safely; "
703 "no activation was committed.\n");
704 return CLI_TRUE;
705 }
706
707 cbm_cli_activation_ops_t ops = {
708 .context = &context,
709 .reserve_for_mutation = cli_activation_production_reserve,
710 .mutation_lease_release = cli_activation_production_release,
711 .visible_diagnostic = cli_activation_production_diagnostic,
712 };
713 int rc = cbm_cli_activation_guard_with_ops(&ops, mutation, mutation_context);
714 if (rc == CLI_OK) {
715 if (!cli_activation_log_event(&context, "completed",
716 "activation mutation completed; configuration APIs do not "
717 "provide an aggregate rollback status")) {
718 (void)fprintf(stderr, "warning: activation completed, but its final log "
719 "record could not be written.\n");
720 }
721 } else {
722 (void)cli_activation_log_event(
723 &context, "failed",
724 context.mutation_authorized
725 ? (rc == CLI_ACTIVATION_PARTIAL
726 ? "published/current binary retained; agent "
727 "configuration refresh or cleanup incomplete"
728 : "activation mutation failed; filesystem writes may "
729 "have completed")
730 : "cohort drain or coordination failed");
731 }
732 cli_activation_production_context_close(&context);
733 if (!context.cleanup_ok) {
734 (void)fprintf(stderr, "error: activation coordination cleanup failed; restart "
735 "your coding-agent sessions before retrying.\n");
736 return CLI_TRUE;
737 }
738 return rc;
739}
740

Callers 3

cbm_cmd_installFunction · 0.85
cbm_cmd_uninstallFunction · 0.85

Tested by

no test coverage detected