Skip to content
This repository was archived by the owner on Jul 12, 2026. It is now read-only.
This repository was archived by the owner on Jul 12, 2026. It is now read-only.

stake remove --all crashes with UnboundLocalError on 'wallet' (9.22.3 and 9.23.0) #1021

Description

@beyond-finance-agent

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions