Skip to content

perf(validator): schedule metagraph sync and metagraph_history snapshots#296

Open
Thykof wants to merge 1 commit into
mainfrom
feat/metagraph-schedule
Open

perf(validator): schedule metagraph sync and metagraph_history snapshots#296
Thykof wants to merge 1 commit into
mainfrom
feat/metagraph-schedule

Conversation

@Thykof

@Thykof Thykof commented Jul 9, 2026

Copy link
Copy Markdown
Collaborator

Problem

metagraph_history receives a full snapshot (one row per available uid) on every low-frequency prompt cycle, because the write is coupled to the prompt cadence. At short cycle intervals that is a large volume of near-identical rows per day with no consumer that needs that granularity — downstream analytics read the table on an hourly basis.

Change

Give the metagraph work its own schedule, decoupled from prompt cadence (constants in neurons/validator.py; each cycle runs as its own process with its own timer):

  • Prompt processes (low/high): refresh the chain metagraph — miner_uids, axon addresses, and miner identity rows — at most every METAGRAPH_SYNC_INTERVAL_MINUTES = 15, writing no snapshot. The refresh runs after forward_prompt, so the chain sync never delays a minute-aligned prompt slot.
  • Scoring process: the only metagraph_history writer, at most every METAGRAPH_SNAPSHOT_INTERVAL_MINUTES = 30 (including the boot snapshot; prompt-process restarts append nothing).
  • Miner identities always upsert: insert_new_miners now runs on every refresh (the on-conflict updated_at bump is kept — it makes a re-current identity the newest row for its uid). Since miner_uids and the identity rows travel through the same call, a newly queryable uid always has its miners row before its first responses are saved.
  • Degenerate chain responses: an empty sync result is applied (the shared metagraph object was just emptied — stale uids must not outlive it, forward_prompt skips cleanly) but the timer is not stamped, so the next cycle retries instead of waiting a full interval.
  • New pure helper metagraph_refresh_due in synth/utils/helpers.py with unit tests; the save parameter is renamed to save_snapshot (identities are no longer gated by it) and made required.

Verification

  • black --check / flake8 clean; new test_metagraph_refresh_due covers the gate boundaries (never-refreshed, below/at/above interval).
  • Reviewed across multiple passes for the failure modes of the scheduling change: new/re-registered miner identity attribution, prompt-slot timing, empty-metagraph recovery, boot behavior per cycle, and caller compatibility of the signature change (single call site).

🤖 Generated with Claude Code

metagraph_history gained a full snapshot every prompt cycle because the
write was coupled to the cycle cadence. Decouple it: prompt processes
refresh the chain metagraph (miner_uids, axons, miner identities) at
most every 15 minutes with no snapshot; the scoring process is the only
snapshot writer, at most every 30 minutes, including at boot. Miner
identity rows are now upserted on every refresh so a newly queryable
uid always has its miners row before its first responses are saved. An
empty (degenerate) sync result is applied but not stamped, so the next
cycle retries; the refresh runs after forward_prompt so the chain sync
never delays a minute-aligned prompt slot.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR decouples metagraph syncing and metagraph_history snapshotting from the prompt cadence by introducing a dedicated refresh scheduler and a helper gate function, reducing unnecessary snapshot volume while keeping miner identity/address data fresh for querying.

Changes:

  • Added metagraph_refresh_due() helper (with unit tests) to gate refresh operations by interval.
  • Updated validator cycle loop(s) to refresh the metagraph on a separate schedule, writing metagraph_history snapshots only from the scoring process.
  • Adjusted miner identity upserts so miner records are refreshed independently of snapshot writes, and renamed the forward helper parameter to save_snapshot.

Reviewed changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 1 comment.

File Description
tests/test_helpers.py Adds unit coverage for the new metagraph_refresh_due() interval gate.
synth/validator/forward.py Renames save to required save_snapshot, always upserts miner identities, and gates metagraph_history writes by caller schedule.
synth/utils/helpers.py Introduces metagraph_refresh_due() helper for refresh scheduling decisions.
neurons/validator.py Implements per-cycle metagraph refresh scheduling and ensures only the scoring cycle writes snapshots.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread neurons/validator.py
Comment on lines +209 to +213
An empty result (degenerate chain response) is applied — the shared
metagraph object was just emptied by the sync, so stale uids must
not outlive it — but not stamped, so the next cycle retries.
"""
now = get_current_time()
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.

2 participants