btcli version: 9.23.0 (also reproduced on 9.22.3)
Python: 3.13.5
Install: uv tool install bittensor-cli
OS: Linux
What I expected
btcli stake remove --all with --include-hotkeys <SS58> should unstake the entire alpha balance from that hotkey on the given netuid.
What actually happens
Command crashes inside cli.py:5730 with UnboundLocalError: cannot access local variable 'wallet' where it is not associated with a value before sending any extrinsic.
Reproduce
btcli stake remove \
--wallet.name <wallet> \
--netuid 1 \
--safe --tolerance 0.05 --no-partial \
--include-hotkeys <hotkey-ss58> \
--subtensor.network finney \
--no-prompt --all
(Confirming with printf 'y\ny\n' | … to bypass safe-staking prompts.)
Output
╭───────────────────── Traceback (most recent call last) ──────────────────────╮
│ /…/bittensor_cli/cli.py:5730 in stake_remove │
│ │
│ 5727 │ │ │ ) │
│ 5728 │ │ │ return self._run_command( │
│ 5729 │ │ │ │ remove_stake.unstake_all( │
│ ❱ 5730 │ │ │ │ │ wallet=wallet, │
│ 5731 │ │ │ │ │ subtensor=self.initialize_chain(network), │
│ 5732 │ │ │ │ │ hotkey_ss58_address=hotkey_ss58_address, │
│ 5733 │ │ │ │ │ unstake_all_alpha=unstake_all_alpha, │
╰──────────────────────────────────────────────────────────────────────────────╯
UnboundLocalError: cannot access local variable 'wallet' where it is not
associated with a value
wallet is referenced on the call site but never bound in the code path taken when --all is combined with --include-hotkeys and --safe. Looks like a branch where the wallet-resolution step is skipped.
Workaround
--amount <floor(held_alpha, 6dp)> works fine — same extrinsic, no crash. We confirmed by landing extrinsic 8487004-17 on mainnet (finney) immediately after hitting the --all crash, with the same flags except --amount 9.180775 instead of --all. So the alpha-resolution + extrinsic submission paths are healthy; just the --all branch is broken.
Why it matters
We hit this in an autonomous rebalancer where the orphan-close path used --all precisely to avoid 1-atomic-unit-overshoot rejections from --amount. Falling back to floor(alpha, 6dp) is safe but means we leave a few atomic units of alpha behind on every close. A working --all path would be cleaner.
Suggested fix
In cli.py around line 5700–5730 in the stake_remove handler, the --all branch with --include-hotkeys likely needs the same wallet = self.wallet_ask(...) (or equivalent) call that the --amount branch does. Happy to PR if it's a one-liner — let me know if you'd prefer that.
btcli version: 9.23.0 (also reproduced on 9.22.3)
Python: 3.13.5
Install:
uv tool install bittensor-cliOS: Linux
What I expected
btcli stake remove --allwith--include-hotkeys <SS58>should unstake the entire alpha balance from that hotkey on the given netuid.What actually happens
Command crashes inside
cli.py:5730withUnboundLocalError: cannot access local variable 'wallet' where it is not associated with a valuebefore sending any extrinsic.Reproduce
(Confirming with
printf 'y\ny\n' | …to bypass safe-staking prompts.)Output
walletis referenced on the call site but never bound in the code path taken when--allis combined with--include-hotkeysand--safe. Looks like a branch where the wallet-resolution step is skipped.Workaround
--amount <floor(held_alpha, 6dp)>works fine — same extrinsic, no crash. We confirmed by landing extrinsic8487004-17on mainnet (finney) immediately after hitting the--allcrash, with the same flags except--amount 9.180775instead of--all. So the alpha-resolution + extrinsic submission paths are healthy; just the--allbranch is broken.Why it matters
We hit this in an autonomous rebalancer where the orphan-close path used
--allprecisely to avoid 1-atomic-unit-overshoot rejections from--amount. Falling back tofloor(alpha, 6dp)is safe but means we leave a few atomic units of alpha behind on every close. A working--allpath would be cleaner.Suggested fix
In
cli.pyaround line 5700–5730 in thestake_removehandler, the--allbranch with--include-hotkeyslikely needs the samewallet = self.wallet_ask(...)(or equivalent) call that the--amountbranch does. Happy to PR if it's a one-liner — let me know if you'd prefer that.