Skip to content

Commit ecc6324

Browse files
cortex-qasisyphus-dev-ai
andcommitted
style: rustfmt after miner digest pin and validator import order
Keep CI fmt gate green on base/dev and gbase. Ultraworked with [Sisyphus](https://github.com/code-yeongyu/oh-my-openagent) Co-authored-by: Sisyphus <clio-agent@sisyphuslabs.ai>
1 parent d23b65a commit ecc6324

48 files changed

Lines changed: 536 additions & 434 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

bins/agent-runner/src/main.rs

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,8 @@ use std::time::Duration;
1717

1818
use agent_runner::{
1919
app, clamp_concurrency, load_or_generate, load_required, receipt_sk_path_from_env,
20-
AgentEgressPosture, DEFAULT_AGENT_EGRESS_POSTURE, DockerExecConfig, ExecutionBackend,
21-
RunnerConfig, RunnerState, DEFAULT_DISPATCH_NONCE_TTL, DEFAULT_RECEIPT_SK_PATH,
20+
AgentEgressPosture, DockerExecConfig, ExecutionBackend, RunnerConfig, RunnerState,
21+
DEFAULT_AGENT_EGRESS_POSTURE, DEFAULT_DISPATCH_NONCE_TTL, DEFAULT_RECEIPT_SK_PATH,
2222
RECEIPT_SK_FILE_ENV,
2323
};
2424
use clap::Parser;
@@ -60,7 +60,11 @@ struct Cli {
6060
#[arg(long, env = "GBASE_PACK_ROOT")]
6161
pack_root: Option<PathBuf>,
6262
/// Staging root for agent binds.
63-
#[arg(long, env = "GBASE_AGENT_WORK_ROOT", default_value = "/tmp/gbase-agent-work")]
63+
#[arg(
64+
long,
65+
env = "GBASE_AGENT_WORK_ROOT",
66+
default_value = "/tmp/gbase-agent-work"
67+
)]
6468
work_root: PathBuf,
6569
/// Miner-supplied model API key file (mounted into agent; never logged).
6670
#[arg(long, env = "GBASE_MODEL_KEY_FILE")]

bins/gateway/src/main.rs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -46,10 +46,11 @@ async fn main() -> ExitCode {
4646
}
4747
_ => {
4848
// fake_owner (default): owner hotkey == configured gateway hotkey.
49-
let hotkeys = gateway::parse_fake_metagraph_hotkeys(&config.hotkey).unwrap_or_else(|e| {
50-
tracing::warn!(error = %e, "bad GBASE_FAKE_METAGRAPH_HOTKEYS; owner-only");
51-
vec![config.hotkey.to_vec()]
52-
});
49+
let hotkeys =
50+
gateway::parse_fake_metagraph_hotkeys(&config.hotkey).unwrap_or_else(|e| {
51+
tracing::warn!(error = %e, "bad GBASE_FAKE_METAGRAPH_HOTKEYS; owner-only");
52+
vec![config.hotkey.to_vec()]
53+
});
5354
let fc = FakeChainConfig {
5455
netuid: config.netuid,
5556
owner_hotkey: config.hotkey.to_vec(),

bins/validator/src/main.rs

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -182,14 +182,7 @@ fn trust_root_dir() -> PathBuf {
182182
fn build_runtime_trust(
183183
netuid: u16,
184184
rotation_epochs: u32,
185-
) -> Result<
186-
(
187-
AttestState,
188-
LocalTrustRoot,
189-
Arc<SyncChain<FakeChain>>,
190-
),
191-
String,
192-
> {
185+
) -> Result<(AttestState, LocalTrustRoot, Arc<SyncChain<FakeChain>>), String> {
193186
let dir = trust_root_dir();
194187
if !dir.is_dir() {
195188
return Err(format!(

crates/agent-challenge/src/challenge.rs

Lines changed: 29 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -171,7 +171,8 @@ impl AgentV1Challenge {
171171
}
172172

173173
fn entry(body: &ChallengesBody) -> Result<&ChallengeEntry, ChallengeError> {
174-
body.get(CHALLENGE_ID_BYTES).ok_or_else(|| ChallengeError::UnknownChallenge(CHALLENGE_ID.into()))
174+
body.get(CHALLENGE_ID_BYTES)
175+
.ok_or_else(|| ChallengeError::UnknownChallenge(CHALLENGE_ID.into()))
175176
}
176177
fn policy(body: &ChallengesBody) -> Result<&ParticipantPolicy, ChallengeError> {
177178
Ok(&Self::entry(body)?.policy)
@@ -231,14 +232,17 @@ impl Challenge for AgentV1Challenge {
231232
attest: &dyn AttestationLookup,
232233
) -> Result<BTreeMap<Hotkey, ScoreOrAbsence>, ChallengeError> {
233234
let expected = self.expected_set(ctx)?;
234-
Ok(expected.iter().map(|h| {
235-
let call = calls.get(h).cloned().unwrap_or(MinerCallOutcome::Observed {
236-
duration_ms: 0,
237-
outcome: CallOutcome::ChallengeInternal,
238-
expected_model_patch: Vec::new(),
239-
});
240-
(*h, self.score_one(ctx, *h, &call, attest))
241-
}).collect())
235+
Ok(expected
236+
.iter()
237+
.map(|h| {
238+
let call = calls.get(h).cloned().unwrap_or(MinerCallOutcome::Observed {
239+
duration_ms: 0,
240+
outcome: CallOutcome::ChallengeInternal,
241+
expected_model_patch: Vec::new(),
242+
});
243+
(*h, self.score_one(ctx, *h, &call, attest))
244+
})
245+
.collect())
242246
}
243247

244248
fn sign_leaf(
@@ -293,7 +297,9 @@ pub fn correct_http200_fixture(netuid: u16, epoch: u64, miner: &Hotkey) -> CallO
293297
/// Helper: `NoScore` reason for missing call coverage (D24).
294298
#[must_use]
295299
pub fn silence_is_bug_leaf() -> ScoreOrAbsence {
296-
ScoreOrAbsence::NoScore { reason: NoScoreReasonCode::ChallengeInternal }
300+
ScoreOrAbsence::NoScore {
301+
reason: NoScoreReasonCode::ChallengeInternal,
302+
}
297303
}
298304

299305
/// Sign exactly one leaf per `h ∈ expected`. Refuses subset/superset (D24).
@@ -318,10 +324,14 @@ pub fn emit_signed_leaf_set(
318324
if !extra.is_empty() {
319325
return Err(LeafEmitError::UnknownHotkeys(extra.join(",")));
320326
}
321-
scores.iter().map(|(h, s)| {
322-
make_signed_leaf(secret, CHALLENGE_ID_BYTES, *h, epoch, s.clone())
323-
.map(|l| (*h, l)).map_err(|e| LeafEmitError::Sign(e.to_string()))
324-
}).collect()
327+
scores
328+
.iter()
329+
.map(|(h, s)| {
330+
make_signed_leaf(secret, CHALLENGE_ID_BYTES, *h, epoch, s.clone())
331+
.map(|l| (*h, l))
332+
.map_err(|e| LeafEmitError::Sign(e.to_string()))
333+
})
334+
.collect()
325335
}
326336

327337
/// Cover `E` from operator-side verify results (Harbor grade).
@@ -335,7 +345,10 @@ pub fn score_epoch_from_verify(
335345
ctx: &EpochCtx,
336346
results: &BTreeMap<Hotkey, Result<Reward, VerifyError>>,
337347
) -> Result<BTreeMap<Hotkey, ScoreOrAbsence>, ChallengeError> {
338-
Ok(cover_expected_verify_leaves(&challenge.expected_set(ctx)?, results))
348+
Ok(cover_expected_verify_leaves(
349+
&challenge.expected_set(ctx)?,
350+
results,
351+
))
339352
}
340353

341354
/// Map one verify grade into a leaf (no retries).
@@ -490,9 +503,7 @@ mod tests {
490503
}),
491504
"hotkey must not be silent"
492505
);
493-
let leaf = ch
494-
.sign_leaf(&sk, h, 7, scores[&h].clone())
495-
.expect("sign");
506+
let leaf = ch.sign_leaf(&sk, h, 7, scores[&h].clone()).expect("sign");
496507
assert!(matches!(
497508
leaf.score_or_absence,
498509
ScoreOrAbsence::NoScore {

crates/agent-challenge/src/epoch_loop.rs

Lines changed: 25 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,10 @@ pub struct RunnerCapacity {
3131
#[derive(Debug, Clone, PartialEq, Eq)]
3232
pub enum MinerEpochOutcome {
3333
/// Done before deadline.
34-
Completed { pack_id: String, result: TaskResultV1 },
34+
Completed {
35+
pack_id: String,
36+
result: TaskResultV1,
37+
},
3538
/// Deadline hit.
3639
TimedOut { pack_id: String },
3740
/// Failed early.
@@ -120,21 +123,31 @@ impl ActiveSignerRegistry {
120123
epoch: u64,
121124
) -> Result<SignerGuard, EpochLoopError> {
122125
let key = (challenge_id.to_owned(), epoch);
123-
let mut g = self.held.lock().unwrap_or_else(std::sync::PoisonError::into_inner);
126+
let mut g = self
127+
.held
128+
.lock()
129+
.unwrap_or_else(std::sync::PoisonError::into_inner);
124130
if g.contains_key(&key) {
125131
return Err(EpochLoopError::SignerAlreadyActive {
126132
challenge_id: challenge_id.to_owned(),
127133
epoch,
128134
});
129135
}
130136
g.insert(key.clone(), ());
131-
Ok(SignerGuard { reg: Arc::clone(self), key })
137+
Ok(SignerGuard {
138+
reg: Arc::clone(self),
139+
key,
140+
})
132141
}
133142
}
134143

135144
impl Drop for SignerGuard {
136145
fn drop(&mut self) {
137-
self.reg.held.lock().unwrap_or_else(std::sync::PoisonError::into_inner).remove(&self.key);
146+
self.reg
147+
.held
148+
.lock()
149+
.unwrap_or_else(std::sync::PoisonError::into_inner)
150+
.remove(&self.key);
138151
}
139152
}
140153

@@ -153,11 +166,14 @@ pub fn score_map_covering_expected(
153166
expected
154167
.iter()
155168
.map(|h| {
156-
let soa = graded.get(h).cloned().unwrap_or_else(|| match outcomes.get(h) {
157-
Some(MinerEpochOutcome::TimedOut { .. }) => ns(R::Timeout),
158-
Some(MinerEpochOutcome::Failed { .. }) => ns(R::MinerError),
159-
_ => ns(R::ChallengeInternal),
160-
});
169+
let soa = graded
170+
.get(h)
171+
.cloned()
172+
.unwrap_or_else(|| match outcomes.get(h) {
173+
Some(MinerEpochOutcome::TimedOut { .. }) => ns(R::Timeout),
174+
Some(MinerEpochOutcome::Failed { .. }) => ns(R::MinerError),
175+
_ => ns(R::ChallengeInternal),
176+
});
161177
(*h, soa)
162178
})
163179
.collect()

crates/agent-challenge/src/expected_set.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -294,8 +294,7 @@ mod tests {
294294
"{tip_err}"
295295
);
296296

297-
let none_err =
298-
expected_set_from_optional_pin(&policy, None, &chain).expect_err("none pin");
297+
let none_err = expected_set_from_optional_pin(&policy, None, &chain).expect_err("none pin");
299298
assert_eq!(none_err, ExpectedSetError::BlockNotPinned);
300299

301300
// Prove we did not fall through to tip: FakeChain tip metagraph would succeed if called.

crates/agent-challenge/src/leaf_map.rs

Lines changed: 30 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -44,8 +44,11 @@ pub const MAX_VERIFY_ATTEMPTS: u32 = 1 + MAX_VERIFY_RETRIES;
4444
pub fn is_operator_fault(err: &VerifyError) -> bool {
4545
matches!(
4646
err,
47-
VerifyError::Timeout { .. } | VerifyError::Docker(_) | VerifyError::MalformedOutput { .. }
48-
| VerifyError::Staging { .. } | VerifyError::MissingHeldOut { .. }
47+
VerifyError::Timeout { .. }
48+
| VerifyError::Docker(_)
49+
| VerifyError::MalformedOutput { .. }
50+
| VerifyError::Staging { .. }
51+
| VerifyError::MissingHeldOut { .. }
4952
)
5053
}
5154

@@ -77,10 +80,13 @@ pub fn map_verify_error(err: &VerifyError) -> ScoreOrAbsence {
7780
VerifyError::ApplyFailed { .. } | VerifyError::RewardZero { .. } => {
7881
ScoreOrAbsence::Score { value: 0 }
7982
}
80-
VerifyError::Timeout { .. } | VerifyError::Docker(_) | VerifyError::MalformedOutput { .. }
81-
| VerifyError::Staging { .. } | VerifyError::MissingHeldOut { .. } => {
82-
ScoreOrAbsence::NoScore { reason: NoScoreReasonCode::ChallengeInternal }
83-
}
83+
VerifyError::Timeout { .. }
84+
| VerifyError::Docker(_)
85+
| VerifyError::MalformedOutput { .. }
86+
| VerifyError::Staging { .. }
87+
| VerifyError::MissingHeldOut { .. } => ScoreOrAbsence::NoScore {
88+
reason: NoScoreReasonCode::ChallengeInternal,
89+
},
8490
}
8591
}
8692

@@ -120,13 +126,18 @@ pub fn cover_expected_verify_leaves(
120126
expected: &BTreeSet<Hotkey>,
121127
results: &BTreeMap<Hotkey, Result<Reward, VerifyError>>,
122128
) -> BTreeMap<Hotkey, ScoreOrAbsence> {
123-
expected.iter().map(|h| {
124-
let soa = results.get(h).map_or_else(
125-
|| ScoreOrAbsence::NoScore { reason: NoScoreReasonCode::ChallengeInternal },
126-
score_from_verify_result,
127-
);
128-
(*h, soa)
129-
}).collect()
129+
expected
130+
.iter()
131+
.map(|h| {
132+
let soa = results.get(h).map_or_else(
133+
|| ScoreOrAbsence::NoScore {
134+
reason: NoScoreReasonCode::ChallengeInternal,
135+
},
136+
score_from_verify_result,
137+
);
138+
(*h, soa)
139+
})
140+
.collect()
130141
}
131142

132143
/// Cap attempts by remaining seal budget so retries cannot outrun the deadline.
@@ -178,12 +189,16 @@ fn grade_loop(
178189
Err(e) => {
179190
let retry = is_retryable_operator_fault(&e) && attempts < allowed;
180191
last_operator = Some(e);
181-
if !retry { break; }
192+
if !retry {
193+
break;
194+
}
182195
}
183196
}
184197
}
185198
last_operator.as_ref().map_or_else(
186-
|| ScoreOrAbsence::NoScore { reason: NoScoreReasonCode::ChallengeInternal },
199+
|| ScoreOrAbsence::NoScore {
200+
reason: NoScoreReasonCode::ChallengeInternal,
201+
},
187202
map_verify_error,
188203
)
189204
}

crates/agent-challenge/src/lib.rs

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -8,31 +8,31 @@
88
#![forbid(unsafe_code)]
99

1010
mod challenge;
11+
mod epoch_loop;
12+
mod expected_set;
13+
mod intake;
1114
mod keys;
15+
mod leaf_map;
1216
mod score;
1317
mod submit;
1418
mod task_gen;
15-
mod leaf_map;
1619
mod verify;
17-
mod expected_set;
18-
mod epoch_loop;
19-
mod intake;
2020

2121
pub use challenge::{
2222
correct_http200, correct_http200_fixture, emit_signed_leaf_set, leaf_from_verify_result,
2323
score_epoch_from_verify, silence_is_bug_leaf, AgentV1Challenge, AttestationLookup, Challenge,
2424
ChallengeError, EpochCtx, Hotkey, LeafEmitError, MapAttestationLookup, MinerCallOutcome,
2525
};
26-
pub use expected_set::{
27-
expected_set_at, expected_set_at_chain, expected_set_from_optional_pin,
28-
expected_set_from_pinned_metagraph, hex32, BlockSource, ExpectedParticipant, ExpectedSet,
29-
ExpectedSetError, PinnedBlockHash,
30-
};
3126
pub use epoch_loop::{
3227
run_epoch_dispatch, score_map_covering_expected, ActiveSignerRegistry, EpochDispatchClient,
3328
EpochDispatchConfig, EpochDispatchResult, EpochLoopError, MinerEpochOutcome, RunnerCapacity,
3429
SignerGuard, R1_DEADLINE_FRACTION_DEN, R1_DEADLINE_FRACTION_NUM, TESTNET_TEMPO_BLOCKS,
3530
};
31+
pub use expected_set::{
32+
expected_set_at, expected_set_at_chain, expected_set_from_optional_pin,
33+
expected_set_from_pinned_metagraph, hex32, BlockSource, ExpectedParticipant, ExpectedSet,
34+
ExpectedSetError, PinnedBlockHash,
35+
};
3636
pub use intake::{
3737
intake_and_grade, verify_intake_receipt, ExpectedReceiptBind, IntakeOk, IntakePatch,
3838
ReceiptBindError,

crates/agent-challenge/src/score.rs

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,9 @@ pub enum CallOutcome {
8989
pub fn score_from_outcome(input: &ScoreInputs) -> ScoreOrAbsence {
9090
use NoScoreReasonCode as R;
9191
if input.attestation != AttestationStatus::Verified {
92-
return ScoreOrAbsence::NoScore { reason: R::AttestationNotVerified };
92+
return ScoreOrAbsence::NoScore {
93+
reason: R::AttestationNotVerified,
94+
};
9395
}
9496
let _ = input.duration_ms; // v2: no latency decay
9597
let ns = |r| ScoreOrAbsence::NoScore { reason: r };
@@ -100,12 +102,24 @@ pub fn score_from_outcome(input: &ScoreInputs) -> ScoreOrAbsence {
100102
CallOutcome::RateLimited => ns(R::RateLimited),
101103
CallOutcome::ChallengeInternal => ns(R::ChallengeInternal),
102104
CallOutcome::Http200 {
103-
challenge_id, epoch, task_id: tid, answer_digest: ans, agent_version,
105+
challenge_id,
106+
epoch,
107+
task_id: tid,
108+
answer_digest: ans,
109+
agent_version,
104110
} => {
105-
let exp_tid = task_id_v2(input.netuid, input.epoch, &input.miner_hotkey, &input.pack_id, SCORING_VERSION);
111+
let exp_tid = task_id_v2(
112+
input.netuid,
113+
input.epoch,
114+
&input.miner_hotkey,
115+
&input.pack_id,
116+
SCORING_VERSION,
117+
);
106118
let exp_ans = answer_digest_v2(&input.expected_model_patch);
107-
if challenge_id != CHALLENGE_ID || *epoch != input.epoch
108-
|| tid.as_slice() != exp_tid.as_slice() || agent_version != "1"
119+
if challenge_id != CHALLENGE_ID
120+
|| *epoch != input.epoch
121+
|| tid.as_slice() != exp_tid.as_slice()
122+
|| agent_version != "1"
109123
{
110124
return ns(R::InvalidResponse);
111125
}

crates/agent-challenge/src/task_gen.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -236,7 +236,10 @@ mod tests {
236236
let m = miner11();
237237
let v1 = task_id(FIX_NETUID, FIX_EPOCH, &m);
238238
let v2 = task_id_v2(FIX_NETUID, FIX_EPOCH, &m, FIX_PACK, SCORING_VERSION_V2);
239-
assert_ne!(v1, v2, "v1 golden must not equal v2 for same netuid/epoch/hotkey");
239+
assert_ne!(
240+
v1, v2,
241+
"v1 golden must not equal v2 for same netuid/epoch/hotkey"
242+
);
240243
}
241244

242245
#[test]

0 commit comments

Comments
 (0)