Skip to content

Commit d144a15

Browse files
Terraphim CITerraphim AI
andcommitted
fix(symphony): clippy + fmt fixes for convergence crates
Apply cargo fmt to terraphim_tracker, terraphim_workspace, and terraphim_orchestrator. Fix clippy::match_result_ok in pagerank.rs. All crates pass tests, clean clippy -D warnings, and clean fmt. Co-Authored-By: Terraphim AI <noreply@terraphim.io>
1 parent 2fafd34 commit d144a15

10 files changed

Lines changed: 169 additions & 106 deletions

File tree

Cargo.lock

Lines changed: 31 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

crates/terraphim_orchestrator/src/concurrency.rs

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -98,16 +98,12 @@ impl ConcurrencyController {
9898
}
9999

100100
/// Try to acquire a slot for a time-driven agent.
101-
pub async fn acquire_time_driven(
102-
&self,
103-
) -> Option<AgentPermit> {
101+
pub async fn acquire_time_driven(&self) -> Option<AgentPermit> {
104102
self.acquire(AgentMode::TimeDriven).await
105103
}
106104

107105
/// Try to acquire a slot for an issue-driven agent.
108-
pub async fn acquire_issue_driven(
109-
&self,
110-
) -> Option<AgentPermit> {
106+
pub async fn acquire_issue_driven(&self) -> Option<AgentPermit> {
111107
self.acquire(AgentMode::IssueDriven).await
112108
}
113109

crates/terraphim_orchestrator/src/dual_mode.rs

Lines changed: 54 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -117,17 +117,20 @@ impl DualModeOrchestrator {
117117
ConcurrencyController::new(
118118
workflow.concurrency.global_max,
119119
ModeQuotas {
120-
time_max: workflow.concurrency.global_max.saturating_sub(workflow.concurrency.issue_max),
120+
time_max: workflow
121+
.concurrency
122+
.global_max
123+
.saturating_sub(workflow.concurrency.issue_max),
121124
issue_max: workflow.concurrency.issue_max,
122125
},
123-
workflow.concurrency.fairness.parse().unwrap_or(FairnessPolicy::RoundRobin),
126+
workflow
127+
.concurrency
128+
.fairness
129+
.parse()
130+
.unwrap_or(FairnessPolicy::RoundRobin),
124131
)
125132
} else {
126-
ConcurrencyController::new(
127-
10,
128-
ModeQuotas::default(),
129-
FairnessPolicy::RoundRobin,
130-
)
133+
ConcurrencyController::new(10, ModeQuotas::default(), FairnessPolicy::RoundRobin)
131134
};
132135

133136
// Create shared state
@@ -143,9 +146,13 @@ impl DualModeOrchestrator {
143146

144147
// Setup time mode
145148
let time_mode = {
146-
let scheduler = TimeScheduler::new(&config.agents, Some(&config.compound_review.schedule))?;
149+
let scheduler =
150+
TimeScheduler::new(&config.agents, Some(&config.compound_review.schedule))?;
147151
let shutdown_rx = state.shutdown_tx.subscribe();
148-
Some(TimeModeComponents { scheduler, shutdown_rx })
152+
Some(TimeModeComponents {
153+
scheduler,
154+
shutdown_rx,
155+
})
149156
};
150157

151158
// Setup issue mode if configured
@@ -154,7 +161,11 @@ impl DualModeOrchestrator {
154161
match create_tracker(workflow) {
155162
Ok(tracker) => {
156163
let shutdown_rx = state.shutdown_tx.subscribe();
157-
Some(IssueModeComponents { tracker, workflow: workflow.clone(), shutdown_rx })
164+
Some(IssueModeComponents {
165+
tracker,
166+
workflow: workflow.clone(),
167+
shutdown_rx,
168+
})
158169
}
159170
Err(e) => {
160171
warn!("failed to create issue tracker: {}", e);
@@ -245,14 +256,14 @@ impl DualModeOrchestrator {
245256
/// Shutdown gracefully.
246257
async fn shutdown(&mut self) {
247258
info!("initiating graceful shutdown");
248-
259+
249260
// Stop accepting new tasks
250261
self.request_shutdown();
251262

252263
// Wait for active agents to complete
253264
let timeout = Duration::from_secs(30);
254265
let start = std::time::Instant::now();
255-
266+
256267
loop {
257268
let active_count = {
258269
let agents = self.active_agents.lock().await;
@@ -265,7 +276,10 @@ impl DualModeOrchestrator {
265276
}
266277

267278
if start.elapsed() > timeout {
268-
warn!("shutdown timeout reached with {} agents still active", active_count);
279+
warn!(
280+
"shutdown timeout reached with {} agents still active",
281+
active_count
282+
);
269283
break;
270284
}
271285

@@ -274,7 +288,7 @@ impl DualModeOrchestrator {
274288

275289
// Shutdown base orchestrator
276290
self.base.shutdown();
277-
291+
278292
info!("shutdown complete");
279293
}
280294

@@ -291,12 +305,19 @@ impl DualModeOrchestrator {
291305
}
292306

293307
/// Trigger compound review.
294-
pub async fn trigger_compound_review(&mut self) -> Result<CompoundReviewResult, crate::OrchestratorError> {
308+
pub async fn trigger_compound_review(
309+
&mut self,
310+
) -> Result<CompoundReviewResult, crate::OrchestratorError> {
295311
self.base.trigger_compound_review().await
296312
}
297313

298314
/// Handoff task between agents.
299-
pub async fn handoff(&mut self, from_agent: &str, to_agent: &str, ctx: HandoffContext) -> Result<(), crate::OrchestratorError> {
315+
pub async fn handoff(
316+
&mut self,
317+
from_agent: &str,
318+
to_agent: &str,
319+
ctx: HandoffContext,
320+
) -> Result<(), crate::OrchestratorError> {
300321
self.base.handoff(from_agent, to_agent, ctx).await
301322
}
302323
}
@@ -305,7 +326,10 @@ impl DualModeOrchestrator {
305326
async fn run_time_mode(components: TimeModeComponents, state: SharedState) {
306327
info!("starting time mode task");
307328

308-
let TimeModeComponents { mut scheduler, mut shutdown_rx } = components;
329+
let TimeModeComponents {
330+
mut scheduler,
331+
mut shutdown_rx,
332+
} = components;
309333

310334
// Get immediate agents (Safety layer)
311335
let immediate = scheduler.immediate_agents();
@@ -353,7 +377,11 @@ async fn run_time_mode(components: TimeModeComponents, state: SharedState) {
353377
async fn run_issue_mode(components: IssueModeComponents, state: SharedState) {
354378
info!("starting issue mode task");
355379

356-
let IssueModeComponents { tracker, workflow, mut shutdown_rx } = components;
380+
let IssueModeComponents {
381+
tracker,
382+
workflow,
383+
mut shutdown_rx,
384+
} = components;
357385

358386
let poll_interval = Duration::from_secs(workflow.poll_interval_secs);
359387

@@ -363,7 +391,7 @@ async fn run_issue_mode(components: IssueModeComponents, state: SharedState) {
363391
match tracker.fetch_candidate_issues().await {
364392
Ok(issues) => {
365393
info!(count = issues.len(), "fetched candidate issues");
366-
394+
367395
for issue in issues {
368396
// Skip blocked issues
369397
if !issue.all_blockers_terminal(&workflow.tracker.states.terminal) {
@@ -416,11 +444,15 @@ fn create_tracker(workflow: &WorkflowConfig) -> Result<Box<dyn IssueTracker>, St
416444
active_states: workflow.tracker.states.active.clone(),
417445
terminal_states: workflow.tracker.states.terminal.clone(),
418446
use_robot_api: workflow.tracker.use_robot_api,
419-
}).map_err(|e| format!("failed to create Gitea tracker: {}", e))?;
420-
447+
})
448+
.map_err(|e| format!("failed to create Gitea tracker: {}", e))?;
449+
421450
Ok(Box::new(tracker))
422451
}
423-
_ => Err(format!("unsupported tracker kind: {}", workflow.tracker.kind)),
452+
_ => Err(format!(
453+
"unsupported tracker kind: {}",
454+
workflow.tracker.kind
455+
)),
424456
}
425457
}
426458

crates/terraphim_orchestrator/src/lib.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,15 +10,15 @@ pub mod nightwatch;
1010
pub mod scheduler;
1111

1212
pub use compound::{CompoundReviewResult, CompoundReviewWorkflow};
13+
pub use concurrency::{ConcurrencyController, FairnessPolicy, ModeQuotas};
1314
pub use config::{
1415
AgentDefinition, AgentLayer, CompoundReviewConfig, ConcurrencyConfig, NightwatchConfig,
1516
OrchestratorConfig, TrackerConfig, TrackerStates, WorkflowConfig,
1617
};
17-
pub use error::OrchestratorError;
18-
pub use handoff::HandoffContext;
19-
pub use concurrency::{ConcurrencyController, FairnessPolicy, ModeQuotas};
2018
pub use dispatcher::{DispatchTask, Dispatcher, DispatcherStats};
2119
pub use dual_mode::DualModeOrchestrator;
20+
pub use error::OrchestratorError;
21+
pub use handoff::HandoffContext;
2222
pub use mode::{IssueMode, TimeMode};
2323
pub use nightwatch::{
2424
CorrectionAction, CorrectionLevel, DriftAlert, DriftMetrics, DriftScore, NightwatchMonitor,

crates/terraphim_orchestrator/src/mode/issue.rs

Lines changed: 16 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,7 @@
22
//!
33
//! Polls Gitea/Linear for issues and dispatches agents to work on them.
44
5-
use crate::{
6-
ConcurrencyController, DispatchTask, Dispatcher, WorkflowConfig,
7-
};
5+
use crate::{ConcurrencyController, DispatchTask, Dispatcher, WorkflowConfig};
86
use std::collections::HashMap;
97
use std::time::Duration;
108
use terraphim_tracker::{Issue, IssueTracker, PagerankClient};
@@ -79,18 +77,18 @@ impl IssueMode {
7977
}
8078

8179
/// Poll for issues and dispatch agents.
82-
async fn poll_and_dispatch(&mut self,
83-
) -> Result<(), Box<dyn std::error::Error>> {
80+
async fn poll_and_dispatch(&mut self) -> Result<(), Box<dyn std::error::Error>> {
8481
// Fetch candidate issues
8582
let mut issues = self.tracker.fetch_candidate_issues().await?;
8683

8784
// Fetch PageRank scores if enabled
8885
if let Some(ref pagerank) = self.pagerank {
89-
match pagerank.fetch_ready(&self.config.tracker.owner,&self.config.tracker.repo,
90-
).await {
86+
match pagerank
87+
.fetch_ready(&self.config.tracker.owner, &self.config.tracker.repo)
88+
.await
89+
{
9190
Ok(ready) => {
92-
PagerankClient::merge_scores(&mut issues,&ready.ready_issues,
93-
);
91+
PagerankClient::merge_scores(&mut issues, &ready.ready_issues);
9492
}
9593
Err(e) => {
9694
warn!("failed to fetch PageRank scores: {}", e);
@@ -140,7 +138,10 @@ impl IssueMode {
140138
}
141139

142140
// Check if issue state is active
143-
if !active_states.iter().any(|s| s.eq_ignore_ascii_case(&issue.state)) {
141+
if !active_states
142+
.iter()
143+
.any(|s| s.eq_ignore_ascii_case(&issue.state))
144+
{
144145
continue;
145146
}
146147

@@ -191,7 +192,10 @@ fn compute_sort_score(issue: &Issue) -> i64 {
191192
let base = issue.priority.map(|p| p as i64 * 100).unwrap_or(500);
192193

193194
// PageRank bonus (higher = more important = lower score)
194-
let pagerank_bonus = issue.pagerank_score.map(|pr| -(pr * 100.0) as i64).unwrap_or(0);
195+
let pagerank_bonus = issue
196+
.pagerank_score
197+
.map(|pr| -(pr * 100.0) as i64)
198+
.unwrap_or(0);
195199

196200
base + pagerank_bonus
197201
}
@@ -207,8 +211,7 @@ mod tests {
207211

208212
#[async_trait]
209213
impl IssueTracker for MockTracker {
210-
async fn fetch_candidate_issues(&self,
211-
) -> terraphim_tracker::Result<Vec<Issue>> {
214+
async fn fetch_candidate_issues(&self) -> terraphim_tracker::Result<Vec<Issue>> {
212215
Ok(self.issues.clone())
213216
}
214217

0 commit comments

Comments
 (0)