Bug Description
MinerEvaluation.evaluation_timestamp is declared in gittensor/classes.py as:
evaluation_timestamp: Optional[datetime] = None
It is never assigned anywhere in the codebase. However, in gittensor/validator/storage/repository.py, cleanup_stale_miner_data() uses evaluation.evaluation_timestamp directly as a SQL parameter:
eval_params = params + (evaluation.evaluation_timestamp,)
# ...
self.execute_command(CLEANUP_STALE_MINER_EVALUATIONS, eval_params)
The SQL queries (CLEANUP_STALE_MINER_EVALUATIONS and CLEANUP_STALE_MINER_EVALUATIONS_BY_HOTKEY) both contain the clause:
In SQL, ANY_VALUE <= NULL evaluates to NULL (not TRUE), so the entire WHERE predicate is never satisfied. The DELETE statements silently delete zero rows on every call.
Impact
Stale miner_evaluations records — those belonging to a miner that has re-registered under a new uid/hotkey or re-linked to a new github_id — are never cleaned up. These records accumulate indefinitely, causing:
- Incorrect historical score data associated with the wrong miner identity
- Unbounded growth of the
miner_evaluations table
Fix
Assign datetime.now(timezone.utc) to evaluation.evaluation_timestamp at the start of cleanup_stale_miner_data(), before it is used to build the SQL parameters.
def cleanup_stale_miner_data(self, evaluation: MinerEvaluation) -> None:
if not evaluation.github_id or evaluation.github_id == '0':
return
evaluation.evaluation_timestamp = datetime.now(timezone.utc) # <-- assign here
params = (evaluation.github_id, evaluation.uid, evaluation.hotkey)
eval_params = params + (evaluation.evaluation_timestamp,)
...
Files Affected
gittensor/validator/storage/repository.py — fix location
gittensor/classes.py — MinerEvaluation.evaluation_timestamp field (line ~312)
Bug Description
MinerEvaluation.evaluation_timestampis declared ingittensor/classes.pyas:It is never assigned anywhere in the codebase. However, in
gittensor/validator/storage/repository.py,cleanup_stale_miner_data()usesevaluation.evaluation_timestampdirectly as a SQL parameter:The SQL queries (
CLEANUP_STALE_MINER_EVALUATIONSandCLEANUP_STALE_MINER_EVALUATIONS_BY_HOTKEY) both contain the clause:In SQL,
ANY_VALUE <= NULLevaluates toNULL(notTRUE), so the entireWHEREpredicate is never satisfied. TheDELETEstatements silently delete zero rows on every call.Impact
Stale
miner_evaluationsrecords — those belonging to a miner that has re-registered under a newuid/hotkeyor re-linked to a newgithub_id— are never cleaned up. These records accumulate indefinitely, causing:miner_evaluationstableFix
Assign
datetime.now(timezone.utc)toevaluation.evaluation_timestampat the start ofcleanup_stale_miner_data(), before it is used to build the SQL parameters.Files Affected
gittensor/validator/storage/repository.py— fix locationgittensor/classes.py—MinerEvaluation.evaluation_timestampfield (line ~312)