From f7c5bcb6cc3a0f03ca7ca640a59762b9d061f665 Mon Sep 17 00:00:00 2001 From: beyond-finance-agent Date: Fri, 26 Jun 2026 01:05:34 +0200 Subject: [PATCH] Fix UnboundLocalError when --all is combined with --include-hotkeys In the stake_remove handler's unstake_all branch, the include_hotkeys sub-branch resolved hotkey_ss58_address but never called self.wallet_ask(...) to bind 'wallet'. The sibling branches (all_hotkeys, the bare-hotkey fallback, the 'all' alias) all do. When the call site at line ~5729 then tried to use 'wallet=wallet' inside remove_stake.unstake_all(...), Python raised UnboundLocalError: cannot access local variable 'wallet'. Adds the same wallet_ask call already used by the adjacent all_hotkeys branch, with ask_for=[WO.NAME, WO.PATH] since the hotkey is supplied via --include-hotkeys. Fixes #1021 Repro before fix: btcli stake remove --wallet.name --netuid 1 --safe \\ --tolerance 0.05 --no-partial --include-hotkeys \\ --subtensor.network finney --no-prompt --all -> UnboundLocalError on cli.py line ~5730 Verified after fix on mainnet (finney): extrinsic 8487314-15, SN4 fully unstaked from delegate hotkey, +0.244 TAO recovered. --- bittensor_cli/cli.py | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/bittensor_cli/cli.py b/bittensor_cli/cli.py index 5a81b224b..ea1b6d04d 100755 --- a/bittensor_cli/cli.py +++ b/bittensor_cli/cli.py @@ -5670,6 +5670,12 @@ def stake_remove( else: print_error("Invalid hotkey ss58 address.") return False + wallet = self.wallet_ask( + wallet_name, + wallet_path, + wallet_hotkey, + ask_for=[WO.NAME, WO.PATH], + ) elif all_hotkeys: wallet = self.wallet_ask( wallet_name,