fix(cli): guard miner score _drain_logs against Warning-state crash#1374
Merged
anderdc merged 2 commits intoMay 29, 2026
Merged
Conversation
anderdc
requested changes
May 29, 2026
Collaborator
anderdc
left a comment
There was a problem hiding this comment.
The guard in gittensor/cli/miner_commands/score.py is the fix and it's correct. The 50+ lines added to tests/cli/test_miner_score.py — the parametrized test class, the idempotency and lands-in-Disabled cases, and the process-wide restore_bt_logging_state singleton fixture — are disproportionate for a two-line guard. Keep: the score.py guard. Drop: the additions to tests/cli/test_miner_score.py.
b70809c to
cd9aa85
Compare
bittensor's LoggingMachine defines `disable_logging` transitions from Trace/Debug/Default/Disabled/Info but NOT from Warning (only `disable_warning = Warning.to(Default)`), so `gitt miner score --log-level warning` crashed at shutdown when `_drain_logs` invoked `bt.logging.off()`. Step Warning down to Default first to preserve the helper's "logging off on return" contract while clearing the crash.
cd9aa85 to
799f061
Compare
Contributor
Author
|
Hi, @anderdc, I've removed. Thanks for the review. |
anderdc
approved these changes
May 29, 2026
Contributor
Author
|
Thanks @anderdc |
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
gitt miner score --log-level warningcrashed at shutdown withstatemachine.exceptions.TransitionNotAllowed: Can't disable_logging when in Warning.This guards the
_drain_logscleanup path so every value Click already accepts in--log-levelcompletes cleanly.Closes #1373
Root cause
bittensor's
LoggingMachinedefinesdisable_loggingtransitions fromTrace/Debug/Default/Disabled/Infobut not fromWarning— the onlyshutdown transition out of
Warningisdisable_warning = Warning.to(Default)(
bittensor/utils/btlogging/loggingmachine.py:127-137). Any caller that lands inWarningand then invokesbt.logging.off()raisesTransitionNotAllowed.gitt miner scoreexposeswarningviaclick.Choice([...]), calls_apply_log_level('warning')→bt.logging.set_warning(), then unconditionallycalls
bt.logging.off()in_drain_logs(). Deterministic crash, not flaky.Fix
Single guarded transition in
_drain_logs(): if the LoggingMachine is inWarning, step down toDefaultviaset_warning(on=False)first, then calloff()(which is defined fromDefault). This preserves the helper's existingcontract —
before_disable_loggingsets all stdlib loggers toCRITICAL— thata naked skip-when-Warning would silently break.
State check follows bittensor's own internal idiom
(
set_debug/set_trace/set_info/set_warningall comparecurrent_state_valuebefore transitioning) and avoids using exceptions forcontrol flow.
A/B reproduction
Before:
info exit=0
debug exit=0
trace exit=0
warning exit=1 ← TransitionNotAllowed in _drain_logs
After:
info exit=0
debug exit=0
trace exit=0
warning exit=0
Tests
New
TestDrainLogsAcrossAdvertisedLevelsintests/cli/test_miner_score.py:warning/info/debug/trace) — pins the regression and prevents drift if Click's--log-levelchoices ever expand.
Disabled.to(Disabled)idempotency — a second drain after a successfuldrain must not raise.
Warning → Disabledcontract — proves the fix doesn't just sidestep thecrash; the machine actually ends in
Disabledso logging is genuinely off.A
restore_bt_logging_statefixture snapshotscurrent_state_valuebefore eachtest and restores it on teardown — the
LoggingMachineis a process-widesingleton and would otherwise leak into the 867 other tests.
Test plan
uv run --extra dev pytest tests/cli/test_miner_score.py -v→ 21 passed(6 new + 15 existing)
uv run --extra dev pytest tests/ -x -q→ 873 passeduv run ruff check ./uv run ruff format --check .→ cleanuv run --extra dev pyright gittensor tests→ 0 errorsuv run --extra dev vulture→ no findings--log-levelvalues, all exit 0