I have test on vanilla using the same way. It works.
refresh_village_merchant_inventory and some other scripts which refresh the inventories of merchants. The abnormal behavior of this operation may cause the merchants have few goods to sell.troop_ensure_inventory_space has weird behavior. If it tries to remove items when there is not enough space, it seems to randomly remove items.(try_for_range, ":unused", 0, 96),
(troop_add_item,"trp_player", "itm_tutorial_spear"),
(try_end),
(troop_ensure_inventory_space, "trp_player", 1),(try_for_range, ":unused", 0, 96),
(troop_add_item,"trp_player", "itm_tutorial_spear"),
(try_end),
(troop_ensure_inventory_space, "trp_player", 1),