How to truly eradicate "Namespace default is not found."

I’m perplexed by an intermittent issue with “Namespace default is not found.” and have attempted to get rid of it using the Describe function of the NameSpace client, without success.

The first code block that follows is the CLI output. The CLI is using Temporal to kick off and handle provisioning of another resource.

Seen in the next code block, the Workflow is being defined “just in time.” It is then checked with a Describe for “readiness”.

The CLI output seems impossible. Is there a different Describe that I should be using that really, TRULY reflects the readiness of Temporal Server to Execute a workflow?

Any help appreciated.

Meanwhile, I’m just going to go wrap the ExecuteWorkflow in a retry function, which, if the Describe can’t be replaced with something more definite, will indicate that the DetectRegisteredNamespace approach should be removed and Temporal Server should just be retried until it takes the job.

2023-11-09 08:44:16 Registering Namespace... InitCoreWorkflow
2023-11-09 08:44:16 DetectRegisteredNamespace Attempt InitCoreWorkflow
2023-11-09 08:44:16 DetectRegisteredNamespace Found InitCoreWorkflow &DescribeNamespaceResponse{NamespaceInfo:&v12.NamespaceInfo{Name:InitCoreWorkflow,State:Registered,Description:InitCore via x01-cli,OwnerEmail:admin@expertonium.com,Data:map[string]string{},Id:cf0404fb-0f80-4fe8-991d-88b41fb08d22,SupportsSchedules:true,},Config:&v12.NamespaceConfig{WorkflowExecutionRetentionTtl:24h0m0s,BadBinaries:&BadBinaries{Binaries:map[string]*BadBinaryInfo{},},HistoryArchivalState:Disabled,HistoryArchivalUri:,VisibilityArchivalState:Disabled,VisibilityArchivalUri:,CustomSearchAttributeAliases:map[string]string{},},ReplicationConfig:&v1.NamespaceReplicationConfig{ActiveClusterName:active,Clusters:[]*ClusterReplicationConfig{&ClusterReplicationConfig{ClusterName:active,},},State:Unspecified,},FailoverVersion:0,IsGlobalNamespace:false,FailoverHistory:[]*FailoverStatus{},}
2023-11-09 08:44:16 2023/11/09 14:44:16 ERROR Unable to execute InitCoreWorkflow err="Namespace default is not found."
func InitCore(cmd *cobra.Command) {

...

	workflowNamespace := "InitCoreWorkflow"

	_, err = utils.RegisterNamespace(
		cmd.Context(),
		temporalNamespaceClient,
		workflowNamespace,
		"InitCore via cli",
		"admin@expertonium.com",
		time.Duration(24*time.Hour))
	if err != nil {
		slog.Error("Temporal Client: RegisterNamespace Error", err)
		return
	}

	_, err = DetectRegisteredNamespace(
		cmd.Context(),
		temporalNamespaceClient,
		workflowNamespace,
		10,
		time.Duration(5*time.Second))
	if err != nil {
		slog.Error("Temporal Client: DetectRegisteredNamespaceReady Error", err)
		return
	}

	options := client.StartWorkflowOptions{
		ID:        workflowID,
		TaskQueue: "INIT_CORE_TASK_QUEUE",
	}

	coreConfig := types.coreConfig{
		Foo: "bar"
	}

	we, err := temporalClient.ExecuteWorkflow(cmd.Context(), options, workflowNamespace coreConfig)
	if err != nil {
		slog.Error("Unable to execute InitCoreWorkflow", "err", err)
		return
	}

	fmt.Println("Running InitCoreWorkflow", "WorkflowId", we.GetID())

...

}

func RegisterNamespace(
	ctx context.Context,
	temporalNamespaceClient client.NamespaceClient,
	workflowNamespace string,
	description string,
	ownerEmail string,
	retention time.Duration) (bool, error) {
	fmt.Println("Registering Namespace...", workflowNamespace)

	err := temporalNamespaceClient.Register(ctx, &workflowservice.RegisterNamespaceRequest{
		Namespace:                        workflowNamespace,
		Description:                      description,
		OwnerEmail:                       ownerEmail,
		WorkflowExecutionRetentionPeriod: &retention,
	})

	if err != nil {
		if strings.Contains(err.Error(), "already exists") {
			fmt.Println("Workflow namespace already exists, continuing...")
		} else {
			return false, err
		}
	}

	return true, nil
}

func DetectRegisteredNamespace(
	ctx context.Context,
	temporalNamespaceClient client.NamespaceClient,
	workflowNamespace string,
	attempts int,
	dur time.Duration) (bool, error) {
	fmt.Println("DetectRegisteredNamespace Attempt", workflowNamespace)
	workspaceDescription, err := temporalNamespaceClient.Describe(ctx, workflowNamespace)
	if err != nil {
		if attempts--; attempts > 0 {
			fmt.Println("DetectRegisteredNamespace NotFound", workflowNamespace, "remaining_attempts", attempts)
			time.Sleep(dur)
			return DetectRegisteredNamespace(ctx, temporalNamespaceClient, workflowNamespace, attempts, dur)
		}
		return false, err
	}
	fmt.Println("DetectRegisteredNamespace Found", workflowNamespace, workspaceDescription)
	return true, nil
}

I have altered the ExecuteWorkflow, in the first code block. The CLI output, indicating a fail followed by a success, follows.

I’m just going to call it good. Still interested in any thoughts about Describe.

	attempts := 10

	for {
		we, err := temporalClient.ExecuteWorkflow(cmd.Context(), options, workflowNamespace, coreConfig)
		if err != nil {
			if attempts--; attempts > 0 {
				fmt.Println("ExecuteWorkflow Failed", workflowNamespace, "remaining_attempts", attempts)
				time.Sleep(5 * time.Second)
				continue
			} else {
				fmt.Println("ExecuteWorkflow Attempts Exhausted", workflowNamespace)
				break
			}
		}
		fmt.Println("Running InitCoreWorkflow", "WorkflowId", we.GetID())
		break
	}
2023-11-09 09:51:47 Registering Namespace...InitCoreWorkflow
2023-11-09 09:51:47 DetectRegisteredNamespace Attempt InitCoreWorkflow
2023-11-09 09:51:47 DetectRegisteredNamespace Found InitCoreWorkflow &DescribeNamespaceResponse{NamespaceInfo:&v12.NamespaceInfo{Name:InitCoreWorkflow,State:Registered,Description:InitCore via x01-cli,OwnerEmail:admin@expertonium.com,Data:map[string]string{},Id:ae628fa8-2500-46f4-bf0c-46d9ab658898,SupportsSchedules:true,},Config:&v12.NamespaceConfig{WorkflowExecutionRetentionTtl:24h0m0s,BadBinaries:&BadBinaries{Binaries:map[string]*BadBinaryInfo{},},HistoryArchivalState:Disabled,HistoryArchivalUri:,VisibilityArchivalState:Disabled,VisibilityArchivalUri:,CustomSearchAttributeAliases:map[string]string{},},ReplicationConfig:&v1.NamespaceReplicationConfig{ActiveClusterName:active,Clusters:[]*ClusterReplicationConfig{&ClusterReplicationConfig{ClusterName:active,},},State:Unspecified,},FailoverVersion:0,IsGlobalNamespace:false,FailoverHistory:[]*FailoverStatus{},}
2023-11-09 09:51:47 ExecuteWorkflow Failed InitCoreWorkflow remaining_attempts 9
2023-11-09 09:51:52 Running InitCoreWorkflow WorkflowId init-core-expertoniumio-local