Skip to content

Commit b8faecf

Browse files
ruvnetruvnet
andauthored
fix(mcp-brain-server): spawn_blocking for cognitive cycle + postgres version bump (#490)
- Wrap run_enhanced_training_cycle in tokio::task::spawn_blocking to prevent CPU-intensive cognitive cycles from starving HTTP handlers (root cause of 504 upstream timeouts, closes #305) - Derive Default for EnhancedTrainingResult so spawn_blocking JoinError can be handled cleanly - Bump ruvector-postgres version 0.3.0 → 2.0.1 to match the Docker image tag convention (closes #271) Co-authored-by: ruvnet <ruvnet@gmail.com>
1 parent 1d43f2c commit b8faecf

4 files changed

Lines changed: 19 additions & 6 deletions

File tree

crates/mcp-brain-server/src/main.rs

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,14 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
3232
// Wait 30s before first cycle (let startup finish, data load)
3333
tokio::time::sleep(std::time::Duration::from_secs(30)).await;
3434

35-
// Run an initial enhanced cycle on startup to bootstrap cognitive state (full retrain)
36-
let result = routes::run_enhanced_training_cycle(&train_state, true);
35+
// Run an initial enhanced cycle on startup to bootstrap cognitive state (full retrain).
36+
// spawn_blocking avoids starving HTTP handlers during the CPU-intensive bootstrap.
37+
let result = {
38+
let state = train_state.clone();
39+
tokio::task::spawn_blocking(move || routes::run_enhanced_training_cycle(&state, true))
40+
.await
41+
.unwrap_or_default()
42+
};
3743
tracing::info!(
3844
"Initial cognitive bootstrap: props={}, inferences={}, voice={}, curiosity={}, strange_loop={:.4}",
3945
result.propositions_extracted, result.inferences_derived,
@@ -115,7 +121,14 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
115121
// to benefit from incremental processing; the function auto-forces a full
116122
// retrain every 24h.
117123
if new_memories > 0 || new_votes > 0 || tick_count % 15 == 0 {
118-
let result = routes::run_enhanced_training_cycle(&train_state, false);
124+
let result = {
125+
let state = train_state.clone();
126+
tokio::task::spawn_blocking(move || {
127+
routes::run_enhanced_training_cycle(&state, false)
128+
})
129+
.await
130+
.unwrap_or_default()
131+
};
119132
tracing::info!(
120133
"Cognitive cycle #{} ({}): props={}, inferences={}, voice={}, auto_votes={}, \
121134
curiosity={}, sona_patterns={}, strange_loop={:.4}, lora_auto={}, processed={}/{}",

crates/mcp-brain-server/src/routes.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -474,7 +474,7 @@ pub fn run_training_cycle(state: &AppState) -> TrainingCycleResult {
474474
}
475475

476476
/// Enhanced training result (ADR-110)
477-
#[derive(Debug, Clone, serde::Serialize)]
477+
#[derive(Debug, Clone, Default, serde::Serialize)]
478478
pub struct EnhancedTrainingResult {
479479
pub sona_message: String,
480480
pub sona_patterns: usize,

crates/ruvector-postgres/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "ruvector-postgres"
3-
version = "0.3.0"
3+
version = "2.0.1"
44
edition = "2021"
55
license = "MIT"
66
description = "High-performance PostgreSQL vector database extension v2 - pgvector drop-in replacement with 230+ SQL functions, SIMD acceleration, Flash Attention, GNN layers, hybrid search, multi-tenancy, self-healing, and self-learning capabilities"

crates/ruvector-postgres/Dockerfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# Multi-stage Dockerfile for ruvector-postgres extension
22
# Builds the extension and creates a PostgreSQL image with it installed
3-
# v0.3.1: Fixes — Cypher self-reference, graph/RDF persistence, SONA dimension panic
3+
# v2.0.1: Extension version aligned with Docker image tag (fixes #271)
44

55
# Build stage
66
# Using nightly Rust to support edition2024 crates in the registry

0 commit comments

Comments
 (0)