Fix neuron lifecycle: instance-level state, scores lock, autoupdater guards - #408
Merged
Conversation
… 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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Three small correctness fixes in the neuron lifecycle, all found by inspection. No behavior change in the normal single-instance path.
BaseNeuronshared state —exit_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 builtinexit()tosys.exit(1), sinceexit()isn't guaranteed present outside the REPL.update_scoreslock — the score-array extension, EMA update, and inactivity zeroing now run under the existing_state_lock. Previously they mutatedself.scoreswithout the lock whilesave_stateread it under the lock.Autoupdater — locate the repo root by walking up to the first
.gitdirectory instead of looping until a directory literally namedbitmind-subnet(which never terminates when the repo is cloned under a different name). Thegit pullnow runs viasubprocesswith--ff-only, and a non-zero exit aborts the update instead of proceeding as if it succeeded.Test plan
pytest tests/— passes🤖 Generated with Claude Code