Skip to content

Fix neuron lifecycle: instance-level state, scores lock, autoupdater guards - #408

Merged
dylanuys merged 1 commit into
mainfrom
fix/neuron-lifecycle
Jul 9, 2026
Merged

Fix neuron lifecycle: instance-level state, scores lock, autoupdater guards#408
dylanuys merged 1 commit into
mainfrom
fix/neuron-lifecycle

Conversation

@dylanuys

@dylanuys dylanuys commented Jul 9, 2026

Copy link
Copy Markdown
Contributor

Summary

Three small correctness fixes in the neuron lifecycle, all found by inspection. No behavior change in the normal single-instance path.

  • BaseNeuron shared stateexit_context, block_callbacks, and the substrate handles were declared as class attributes, so they were shared across instances: a second instantiation reused the same exit context and appended to the same callback list. They're now initialized per-instance in __init__. Also switched the not-registered path from the builtin exit() to sys.exit(1), since exit() isn't guaranteed present outside the REPL.

  • update_scores lock — the score-array extension, EMA update, and inactivity zeroing now run under the existing _state_lock. Previously they mutated self.scores without the lock while save_state read it under the lock.

  • Autoupdater — locate the repo root by walking up to the first .git directory instead of looping until a directory literally named bitmind-subnet (which never terminates when the repo is cloned under a different name). The git pull now runs via subprocess with --ff-only, and a non-zero exit aborts the update instead of proceeding as if it succeeded.

Test plan

  • pytest tests/ — passes
  • ruff (error-level) — clean
  • Testnet validator restart + autoupdate cycle before the next release

🤖 Generated with Claude Code

… guards

- BaseNeuron: exit_context/block_callbacks/substrate handles were CLASS
  attributes — a second instantiation shared the exit context and
  accumulated block callbacks. Now initialized per-instance. Library
  code raises SystemExit via sys.exit(1) instead of builtin exit().
- update_scores: score extension/EMA/liveness-zeroing now runs under
  _state_lock; previously it mutated self.scores unlocked while
  save_state read it under the lock.
- autoupdater: locate the repo root by walking to the first .git
  directory (was: loop forever unless the clone dir is literally named
  bitmind-subnet); replace unchecked os.system('git pull') with
  subprocess git pull --ff-only, checking the exit code and aborting
  the update on failure.
@dylanuys
dylanuys merged commit 7bb6948 into main Jul 9, 2026
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant