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

Function cli_activation_guard

src/cli/cli.c:689–745  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

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

Callers 3

cbm_cmd_installFunction · 0.85
cbm_cmd_uninstallFunction · 0.85

Tested by

no test coverage detected