Skip to content

Commit 4a7ef30

Browse files
committed
chore: fmt
1 parent 43b77a0 commit 4a7ef30

6 files changed

Lines changed: 111 additions & 69 deletions

File tree

rain-engine-core/src/engine.rs

Lines changed: 32 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -304,7 +304,7 @@ impl AgentEngine {
304304
wake_request: None,
305305
});
306306
}
307-
}
307+
},
308308
};
309309
counter!("rain_engine.triggers_total").increment(1);
310310

@@ -1663,22 +1663,26 @@ impl AgentEngine {
16631663
warn!(session_id = %context.session_id, "failed to record outcome: {}", err.message);
16641664
}
16651665

1666-
context.records.push(SessionRecord::Outcome(outcome.clone()));
1666+
context
1667+
.records
1668+
.push(SessionRecord::Outcome(outcome.clone()));
16671669

16681670
let outcome_clone = outcome.clone();
1669-
self.run_self_improvement(context, outcome_clone)
1670-
.await?;
1671+
self.run_self_improvement(context, outcome_clone).await?;
16711672

16721673
// Update the state projection cache AFTER self improvement
1673-
let _ = self.state_cache.set_projection(
1674-
&context.session_id,
1675-
SessionSnapshot {
1676-
session_id: context.session_id.clone(),
1677-
records: context.records.clone(),
1678-
last_sequence_no: None,
1679-
latest_outcome: Some(outcome.clone()),
1680-
}
1681-
).await;
1674+
let _ = self
1675+
.state_cache
1676+
.set_projection(
1677+
&context.session_id,
1678+
SessionSnapshot {
1679+
session_id: context.session_id.clone(),
1680+
records: context.records.clone(),
1681+
last_sequence_no: None,
1682+
latest_outcome: Some(outcome.clone()),
1683+
},
1684+
)
1685+
.await;
16821686

16831687
Ok(EngineOutcome {
16841688
trigger_id: outcome.trigger_id,
@@ -1734,7 +1738,9 @@ impl AgentEngine {
17341738
self.memory
17351739
.append_tool_performance(&session_id, performance.clone())
17361740
.await?;
1737-
context.records.push(SessionRecord::ToolPerformance(performance.clone()));
1741+
context
1742+
.records
1743+
.push(SessionRecord::ToolPerformance(performance.clone()));
17381744

17391745
if performance.calls > 0 {
17401746
counter!(
@@ -1759,7 +1765,9 @@ impl AgentEngine {
17591765
self.memory
17601766
.append_strategy_preference(&session_id, preference.clone())
17611767
.await?;
1762-
context.records.push(SessionRecord::StrategyPreference(preference));
1768+
context
1769+
.records
1770+
.push(SessionRecord::StrategyPreference(preference));
17631771
}
17641772
}
17651773

@@ -1804,7 +1812,9 @@ impl AgentEngine {
18041812
self.memory
18051813
.append_profile_patch(&session_id, profile_patch.clone())
18061814
.await?;
1807-
context.records.push(SessionRecord::ProfilePatch(profile_patch));
1815+
context
1816+
.records
1817+
.push(SessionRecord::ProfilePatch(profile_patch));
18081818

18091819
Ok(())
18101820
}
@@ -2045,9 +2055,7 @@ fn maybe_rollback_regression(
20452055
// is progress, not a failure of the policy overlay itself.
20462056
if !matches!(
20472057
outcome.stop_reason,
2048-
StopReason::ProviderFailure
2049-
| StopReason::DeadlineExceeded
2050-
| StopReason::PolicyAborted
2058+
StopReason::ProviderFailure | StopReason::DeadlineExceeded | StopReason::PolicyAborted
20512059
) {
20522060
return None;
20532061
}
@@ -2108,7 +2116,10 @@ fn propose_policy_tuning(
21082116
// We use the terminal observation count as a multiplier
21092117
let multiplier = terminal_observation_count(&snapshot.history).max(1) as f64;
21102118
let aggressive_delta = (delta * multiplier).min(200.0); // Cap at 200% increase per try
2111-
patch.max_steps = Some(increase_usize_by_percent(snapshot.policy.max_steps, aggressive_delta));
2119+
patch.max_steps = Some(increase_usize_by_percent(
2120+
snapshot.policy.max_steps,
2121+
aggressive_delta,
2122+
));
21122123
reason = Some(
21132124
"Session hit max steps; increasing future step budget within guardrails."
21142125
.to_string(),
@@ -2167,7 +2178,7 @@ fn propose_policy_tuning(
21672178
SelfImprovementMode::Shadow => {
21682179
overlay.status = PolicyOverlayStatus::Proposed; // Start as proposed in shadow mode
21692180
PolicyTuningAction::Proposed
2170-
},
2181+
}
21712182
SelfImprovementMode::AutoWithGuardrails => PolicyTuningAction::Applied,
21722183
}
21732184
};

rain-engine-core/src/state_cache.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -71,8 +71,8 @@ impl StateProjectionCache for ValkeyStateCache {
7171

7272
match val {
7373
Some(bytes) => {
74-
let snapshot =
75-
serde_json::from_slice(&bytes).map_err(|e| format!("De-serialize error: {}", e))?;
74+
let snapshot = serde_json::from_slice(&bytes)
75+
.map_err(|e| format!("De-serialize error: {}", e))?;
7676
Ok(Some(snapshot))
7777
}
7878
None => Ok(None),

rain-engine-core/src/traits.rs

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,14 @@ pub trait SkillStore: Send + Sync {
3838

3939
#[async_trait]
4040
pub trait StateProjectionCache: Send + Sync {
41-
async fn get_projection(&self, session_id: &str) -> Result<Option<crate::SessionSnapshot>, String>;
42-
async fn set_projection(&self, session_id: &str, snapshot: crate::SessionSnapshot) -> Result<(), String>;
41+
async fn get_projection(
42+
&self,
43+
session_id: &str,
44+
) -> Result<Option<crate::SessionSnapshot>, String>;
45+
async fn set_projection(
46+
&self,
47+
session_id: &str,
48+
snapshot: crate::SessionSnapshot,
49+
) -> Result<(), String>;
4350
async fn invalidate(&self, session_id: &str) -> Result<(), String>;
4451
}

rain-engine-gateway/src/main.rs

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -146,17 +146,15 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
146146
// ---------------------------------------------------------------------------
147147
// Build the HTTP router with CORS
148148
// ---------------------------------------------------------------------------
149-
let cors_base = CorsLayer::new()
150-
.allow_methods(Any)
151-
.allow_headers(Any);
152-
149+
let cors_base = CorsLayer::new().allow_methods(Any).allow_headers(Any);
150+
153151
let cors = if let Ok(origins) = env::var("RAIN_CORS_ALLOWED_ORIGINS") {
154152
if origins == "*" {
155153
cors_base.allow_origin(Any)
156154
} else {
157-
// To simplify for the gateway, if a specific list is provided,
158-
// we'll just use the first one exactly, or require a more complex CORS layer
159-
// for multiple. For now, since tower-http's AllowOrigin::list takes an array
155+
// To simplify for the gateway, if a specific list is provided,
156+
// we'll just use the first one exactly, or require a more complex CORS layer
157+
// for multiple. For now, since tower-http's AllowOrigin::list takes an array
160158
// and is hard to build dynamically, we'll allow Any if they set origins dynamically
161159
// but log a warning. A proper production setup would use a custom origin closure.
162160
// Let's implement it the simplest secure way: if it's set to a specific single domain, use that.

rain-engine-runtime/src/lib.rs

Lines changed: 62 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -200,7 +200,10 @@ impl NativeSkill for SkillInstallerSkill {
200200
let file_path = invocation.args.get("file_path").and_then(|v| v.as_str());
201201

202202
if wasm_url.is_none() && wasm_base64.is_none() && file_path.is_none() {
203-
return Err(SkillExecutionError::new(SkillFailureKind::InvalidArguments, "missing wasm_url, wasm_base64, or file_path"));
203+
return Err(SkillExecutionError::new(
204+
SkillFailureKind::InvalidArguments,
205+
"missing wasm_url, wasm_base64, or file_path",
206+
));
204207
}
205208

206209
let input_schema = invocation
@@ -252,14 +255,23 @@ impl NativeSkill for SkillInstallerSkill {
252255
} else if let Some(b64) = wasm_base64 {
253256
use base64::{Engine as _, engine::general_purpose};
254257
general_purpose::STANDARD.decode(b64).map_err(|err| {
255-
SkillExecutionError::new(SkillFailureKind::InvalidArguments, format!("Base64 decode failed: {}", err))
258+
SkillExecutionError::new(
259+
SkillFailureKind::InvalidArguments,
260+
format!("Base64 decode failed: {}", err),
261+
)
256262
})?
257263
} else if let Some(path) = file_path {
258264
tokio::fs::read(path).await.map_err(|err| {
259-
SkillExecutionError::new(SkillFailureKind::InvalidArguments, format!("File read failed: {}", err))
265+
SkillExecutionError::new(
266+
SkillFailureKind::InvalidArguments,
267+
format!("File read failed: {}", err),
268+
)
260269
})?
261270
} else {
262-
return Err(SkillExecutionError::new(SkillFailureKind::InvalidArguments, "missing wasm_url, wasm_base64, or file_path"));
271+
return Err(SkillExecutionError::new(
272+
SkillFailureKind::InvalidArguments,
273+
"missing wasm_url, wasm_base64, or file_path",
274+
));
263275
};
264276

265277
let config = rain_engine_wasm::WasmSkillConfig {
@@ -736,11 +748,13 @@ pub async fn build_runtime_state(
736748
};
737749

738750
let mut engine = AgentEngine::new(llm.clone(), memory.clone());
739-
751+
740752
if let Some(cache_config) = &config.cache {
741753
if let Some(valkey_url) = &cache_config.valkey_url {
742754
let valkey_cache = rain_engine_core::ValkeyStateCache::new(valkey_url, "rain")
743-
.map_err(|err| RuntimeConfigError::Invalid(format!("Valkey cache error: {}", err)))?;
755+
.map_err(|err| {
756+
RuntimeConfigError::Invalid(format!("Valkey cache error: {}", err))
757+
})?;
744758
engine = engine.with_state_cache(Arc::new(valkey_cache));
745759
tracing::info!("Configured Valkey state projection cache");
746760
}
@@ -1331,47 +1345,50 @@ async fn handle_get_session(
13311345
State(state): State<RuntimeState>,
13321346
Path(session_id): Path<String>,
13331347
) -> Result<Json<Value>, (StatusCode, String)> {
1334-
let snapshot = if let Ok(Some(cached)) = state.engine.state_cache().get_projection(&session_id).await {
1335-
cached
1336-
} else {
1337-
state
1338-
.memory
1339-
.load_session(&session_id)
1340-
.await
1341-
.map_err(|err| (StatusCode::INTERNAL_SERVER_ERROR, err.message))?
1342-
};
1348+
let snapshot =
1349+
if let Ok(Some(cached)) = state.engine.state_cache().get_projection(&session_id).await {
1350+
cached
1351+
} else {
1352+
state
1353+
.memory
1354+
.load_session(&session_id)
1355+
.await
1356+
.map_err(|err| (StatusCode::INTERNAL_SERVER_ERROR, err.message))?
1357+
};
13431358
Ok(Json(serde_json::to_value(snapshot).unwrap_or_default()))
13441359
}
13451360

13461361
async fn handle_get_session_view(
13471362
State(state): State<RuntimeState>,
13481363
Path(session_id): Path<String>,
13491364
) -> Result<Json<SessionView>, (StatusCode, String)> {
1350-
let snapshot = if let Ok(Some(cached)) = state.engine.state_cache().get_projection(&session_id).await {
1351-
cached
1352-
} else {
1353-
state
1354-
.memory
1355-
.load_session(&session_id)
1356-
.await
1357-
.map_err(|err| (StatusCode::INTERNAL_SERVER_ERROR, err.message))?
1358-
};
1365+
let snapshot =
1366+
if let Ok(Some(cached)) = state.engine.state_cache().get_projection(&session_id).await {
1367+
cached
1368+
} else {
1369+
state
1370+
.memory
1371+
.load_session(&session_id)
1372+
.await
1373+
.map_err(|err| (StatusCode::INTERNAL_SERVER_ERROR, err.message))?
1374+
};
13591375
Ok(Json(build_session_view(snapshot)))
13601376
}
13611377

13621378
async fn handle_get_execution_graph(
13631379
State(state): State<RuntimeState>,
13641380
Path(session_id): Path<String>,
13651381
) -> Result<Json<ExecutionGraphView>, (StatusCode, String)> {
1366-
let snapshot = if let Ok(Some(cached)) = state.engine.state_cache().get_projection(&session_id).await {
1367-
cached
1368-
} else {
1369-
state
1370-
.memory
1371-
.load_session(&session_id)
1372-
.await
1373-
.map_err(|err| (StatusCode::INTERNAL_SERVER_ERROR, err.message))?
1374-
};
1382+
let snapshot =
1383+
if let Ok(Some(cached)) = state.engine.state_cache().get_projection(&session_id).await {
1384+
cached
1385+
} else {
1386+
state
1387+
.memory
1388+
.load_session(&session_id)
1389+
.await
1390+
.map_err(|err| (StatusCode::INTERNAL_SERVER_ERROR, err.message))?
1391+
};
13751392
Ok(Json(build_execution_graph_view(&snapshot)))
13761393
}
13771394

@@ -1408,14 +1425,23 @@ async fn handle_install_skill(
14081425
} else if let Some(b64) = &request.wasm_base64 {
14091426
use base64::{Engine as _, engine::general_purpose};
14101427
general_purpose::STANDARD.decode(b64).map_err(|err| {
1411-
(StatusCode::BAD_REQUEST, format!("Base64 decode failed: {}", err))
1428+
(
1429+
StatusCode::BAD_REQUEST,
1430+
format!("Base64 decode failed: {}", err),
1431+
)
14121432
})?
14131433
} else if let Some(path) = &request.file_path {
14141434
tokio::fs::read(path).await.map_err(|err| {
1415-
(StatusCode::BAD_REQUEST, format!("File read failed: {}", err))
1435+
(
1436+
StatusCode::BAD_REQUEST,
1437+
format!("File read failed: {}", err),
1438+
)
14161439
})?
14171440
} else {
1418-
return Err((StatusCode::BAD_REQUEST, "Must provide wasm_url, wasm_base64, or file_path".to_string()));
1441+
return Err((
1442+
StatusCode::BAD_REQUEST,
1443+
"Must provide wasm_url, wasm_base64, or file_path".to_string(),
1444+
));
14191445
};
14201446

14211447
let config = rain_engine_wasm::WasmSkillConfig {

src/server.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ impl Default for ServerBuilder {
2828
},
2929
store: StoreBootstrapConfig::InMemory, // Portable by default
3030
cache: None,
31-
blob: BlobBackendConfig::InMemory, // Portable by default
31+
blob: BlobBackendConfig::InMemory, // Portable by default
3232
provider: ProviderBootstrapConfig::Mock {
3333
response: "Mock Response".to_string(),
3434
},

0 commit comments

Comments
 (0)