Zend certified PHP/Magento developer

Magento 2 session variable is empty on checkout

I have a custom module that creates a session variable first on a block, then I start the session variable on a template.phtml

Then I wan’t to get this value in checkout and finally unset the session variable. But it’s doing something weird, sometimes is working, sometimes is empty.

Here is my code:
I’m using MagentoFrameworkSessionSessionManagerInterface $coreSession
Block.php

public function setSession($uniqueid){
        $this->coreSession->start();
        $this->coreSession->setUniqueid($uniqueid);
    }

    public function getSession(){
        $this->coreSession->start();
        return $this->coreSession->getUniqueid();
    }

    public function unsetSession(){
        $this->coreSession->start();
        return $this->coreSession->unsUniqueid();
    }

Then in phtml, here it’s working fine

<?php

    $params = $block->getData('params');
 
    $block->unsetSession();
   $block->setSession($params['uniqueId']);
?>

here is not working, I have an Observer listening on sales_order_place_after event

OrderSuccess.php

public function execute(MagentoFrameworkEventObserver $observer){
        //Get UNIQUE ID of guest customer
      
        $uniqueId = $this->_coreSession->getUniqueid();
        //Get Order data
        $order = $observer->getOrder();
        $orderNumber = $order->getIncrementId();
        $orderGrandTotal = $order->getGrandTotal();
        $this->_logger->info("Order Number: ".$orderNumber);
        $this->_logger->info("Order Grand Total: ".$orderGrandTotal);
        $this->_logger->info("Unique ID: ".$uniqueId);
        //set unique id to Order
        $order->setUniqueid($uniqueId);
        //Unset session
        $this->_coreSession->unsUniqueid();
    }

This variable session is because all guest customers needs to have that value.
Thanks!