I read this thread very carefully and I think I managed to implement all the steps described by Daniel. Thank you so much for the detailed description.

But it looks like I'm stuck on the last step. I can't delete records from htable when an incoming call cannot reach the registered device (e.g., no more internet access, power off at the device). I try to do this from failure route but looks like i kamailio has not access to htable from it.

  if (t_check_status("408")) {
  xlog("L_WARN", "$ci|log| hello \n");
  xlog("L_WARN", "$ci|log| mid reg token - $sht(mid_reg_token=>$fU::$si::$sp) \n");

I do not see xlog message with mid reg token but i see 'hello'.
Yes, htable record exists in case i check using:
kamcmd htable.dump mid_reg_token

Also I need a way to remove registration at the registrar (Freeswitch in my case). This means I need to send api request from kamailio or just run some script that will do this. What is the best way ? module exec ?

Please advice,