Skip to content

fix: evaluation_timestamp is never assigned, stale cleanup SQL always evaluates to NULL #378

@Grizouforever

Description

@Grizouforever

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:

AND created_at <= %s

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.pyMinerEvaluation.evaluation_timestamp field (line ~312)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions