Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions apps/desktop/src-tauri/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ use synapse_core::ports::{LlmPort, BufferPort, EmbeddingPort, HolographicPort};
use std::sync::Arc;
use tokio::sync::Mutex;
use synapse_core::ports::SovereigntyPort;
use rand::Rng;

#[derive(serde::Serialize)]
struct NodeInfo {
Expand Down Expand Up @@ -735,12 +736,11 @@ struct TrainingMetrics {
async fn get_training_metrics(_state: tauri::State<'_, SynapseState>) -> Result<TrainingMetrics, String> {
// Mock metrics for the UI heartbeat
// In real impl, this would read from a shared Arc<Mutex<TrainingState>>
use rand::Rng; // We need rand for the heartbeat effect
let mut rng = rand::thread_rng();
let mut rng = rand::rng();

Ok(TrainingMetrics {
loss: rng.gen_range(0.1..0.5),
maternal_gradient_norm: rng.gen_range(0.01..0.1),
loss: rng.random_range(0.1..0.5),
maternal_gradient_norm: rng.random_range(0.01..0.1),
Comment on lines +742 to +743

Choose a reason for hiding this comment

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

critical

The method random_range does not appear to be a valid method on the rand::Rng trait. The correct method for generating a value within a range is gen_range. Using random_range will likely result in a compilation error.

        loss: rng.gen_range(0.1..0.5),
        maternal_gradient_norm: rng.gen_range(0.01..0.1),

epoch: 1,
})
}
Expand Down
5 changes: 0 additions & 5 deletions bin/issue-syncer-linux

This file was deleted.

7 changes: 7 additions & 0 deletions crates/synapse-core/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,13 @@ anyhow = { workspace = true }
lazy_static = "1.5.0"


[features]
infra = ["surrealdb"]

[dev-dependencies]
tokio = { workspace = true }
synapse-infra = { path = "../synapse-infra" }

[dependencies.surrealdb]
workspace = true
optional = true
2 changes: 2 additions & 0 deletions crates/synapse-core/src/tokenomics/structs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ use uuid::Uuid;
/// The `soulbound_id` is the permanent anchor for reputation,
/// while `wallet_address` is for financial transactions.
#[derive(Debug, Clone, Serialize, Deserialize)]
#[cfg_attr(feature = "infra", derive(surrealdb::SurrealValue))]
pub struct UserProfile {
/// The public address for receiving token rewards.
pub wallet_address: String,
Expand Down Expand Up @@ -72,6 +73,7 @@ pub struct Contribution {

/// Receipt for a reward calculation, detailing mint vs burn.
#[derive(Debug, Clone, Serialize, Deserialize)]
#[cfg_attr(feature = "infra", derive(surrealdb::SurrealValue))]
pub struct RewardReceipt {
/// Total tokens minted for this reward.
pub amount_minted: u64,
Expand Down
4 changes: 2 additions & 2 deletions crates/synapse-immune/src/quantum_wallet.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ impl synapse_core::ports::signer_port::Signer for QuantumWallet {
}
}

use rand::RngCore;
use rand::Rng;

pub fn encrypt_hologram(
data: &[u8],
Expand All @@ -62,7 +62,7 @@ pub fn encrypt_hologram(
let cipher = Aes256Gcm::new(key);

let mut nonce_bytes = [0u8; 12];
OsRng.fill_bytes(&mut nonce_bytes);
rand::rng().fill(&mut nonce_bytes);
let nonce = Nonce::from_slice(&nonce_bytes);

let encrypted_payload = cipher.encrypt(nonce, data.as_ref()).expect("encryption failed");
Expand Down
2 changes: 1 addition & 1 deletion crates/synapse-infra/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ description = "Infrastructure adapters for Synapse Protocol"

[dependencies]
# Core domain
synapse-core = { path = "../synapse-core" }
synapse-core = { path = "../synapse-core", features = ["infra"] }

# Async
tokio = { workspace = true }
Expand Down
76 changes: 71 additions & 5 deletions crates/synapse-infra/src/adapters/surrealdb_adapter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ use std::sync::Arc;
use tokio::sync::OnceCell;

/// Record type for SurrealDB serialization.
#[derive(Debug, Serialize, Deserialize)]
#[derive(Debug, Serialize, Deserialize, surrealdb::SurrealValue)]
struct MemoryRecord {
content: String,
layer: u8,
Expand Down Expand Up @@ -55,7 +55,7 @@ pub struct SurrealDbAdapter {
impl SurrealDbAdapter {
/// Create a new SurrealDB adapter with file-based persistent storage.
///
/// # Arguments
/// #[derive(Debug, Deserialize, surrealdb::SurrealValue)]Arguments

Choose a reason for hiding this comment

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

medium

It appears a derive macro has been accidentally placed within a doc comment. This has no effect on the code and should be removed to avoid confusion.

Suggested change
/// #[derive(Debug, Deserialize, surrealdb::SurrealValue)]Arguments
/// # Arguments

/// * `path` - Path to the database directory (uses SurrealKV backend)
///
/// This uses the SurrealKV embedded storage engine for persistence.
Expand Down Expand Up @@ -221,6 +221,23 @@ impl MemoryPort for SurrealDbAdapter {
.await
.map_err(|e| Error::System(format!("Search failed: {}", e)))?;

#[derive(Debug, Deserialize, surrealdb::SurrealValue)]
struct VectorSearchResult {
id: Thing,
content: String,
layer: u8,
node_type: String,
created_at: i64,
updated_at: i64,
embedding: Vec<f32>,
metadata: String,
namespace: String,
source: String,
holographic_data: Option<Vec<u8>>,
loop_level: u8,
distance: f32,
}
Comment on lines +224 to +239

Choose a reason for hiding this comment

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

medium

The VectorSearchResult struct is defined locally here, and this definition is duplicated in the search_layer and search_namespace methods. This creates code duplication and increases maintenance overhead.

Consider moving this struct definition to the module level, possibly by modifying the existing VectorSearchResult struct at line 33 to include the surrealdb::SurrealValue derive. This would centralize the definition and improve code clarity.


let results: Vec<VectorSearchResult> = response
.take(0)
.map_err(|e| Error::System(format!("Failed to parse results: {}", e)))?;
Expand Down Expand Up @@ -282,6 +299,23 @@ impl MemoryPort for SurrealDbAdapter {
.await
.map_err(|e| Error::System(format!("Search layer failed: {}", e)))?;

#[derive(Debug, Deserialize, surrealdb::SurrealValue)]
struct VectorSearchResult {
id: Thing,
content: String,
layer: u8,
node_type: String,
created_at: i64,
updated_at: i64,
embedding: Vec<f32>,
metadata: String,
namespace: String,
source: String,
holographic_data: Option<Vec<u8>>,
loop_level: u8,
distance: f32,
}

let results: Vec<VectorSearchResult> = response
.take(0)
.map_err(|e| Error::System(format!("Failed to parse results: {}", e)))?;
Expand Down Expand Up @@ -341,6 +375,23 @@ impl MemoryPort for SurrealDbAdapter {
.await
.map_err(|e| Error::System(format!("Search namespace failed: {}", e)))?;

#[derive(Debug, Deserialize, surrealdb::SurrealValue)]
struct VectorSearchResult {
id: Thing,
content: String,
layer: u8,
node_type: String,
created_at: i64,
updated_at: i64,
embedding: Vec<f32>,
metadata: String,
namespace: String,
source: String,
holographic_data: Option<Vec<u8>>,
loop_level: u8,
distance: f32,
}

let results: Vec<VectorSearchResult> = response
.take(0)
.map_err(|e| Error::System(format!("Failed to parse results: {}", e)))?;
Expand Down Expand Up @@ -392,7 +443,7 @@ impl MemoryPort for SurrealDbAdapter {
.await
.map_err(|e| Error::System(format!("Get by layer failed: {}", e)))?;

#[derive(Deserialize)]
#[derive(Deserialize, surrealdb::SurrealValue)]
struct LayerResult {
id: Thing,
content: String,
Expand Down Expand Up @@ -524,6 +575,21 @@ impl MemoryPort for SurrealDbAdapter {
.await
.map_err(|e| Error::System(format!("Search all failed: {}", e)))?;

#[derive(Debug, Serialize, Deserialize, surrealdb::SurrealValue)]
struct MemoryRecord {
content: String,
layer: u8,
node_type: String,
created_at: i64,
updated_at: i64,
embedding: Vec<f32>,
metadata: String, // JSON serialized
namespace: String,
source: String,
holographic_data: Option<Vec<u8>>,
loop_level: u8,
}
Comment on lines +578 to +591

Choose a reason for hiding this comment

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

medium

The MemoryRecord struct is redefined here, but an identical struct is already defined at the module level (line 16). This local definition is redundant and can be removed to avoid confusion and improve code clarity. The existing module-level struct is already in scope and can be used directly.


let results: Vec<MemoryRecord> = response
.take(0)
.map_err(|e| Error::System(format!("Failed to parse search results: {}", e)))?;
Expand All @@ -542,7 +608,7 @@ impl MemoryPort for SurrealDbAdapter {
.await
.map_err(|e| Error::System(e.to_string()))?;

#[derive(Deserialize)]
#[derive(Deserialize, surrealdb::SurrealValue)]
struct RecordWithId {
id: Thing,
content: String,
Expand Down Expand Up @@ -587,7 +653,7 @@ impl MemoryPort for SurrealDbAdapter {
let sql = "SELECT * FROM memory_node ORDER BY created_at DESC LIMIT 1";
let mut response = self.db.query(sql).await.map_err(|e| Error::System(e.to_string()))?;

#[derive(Deserialize)]
#[derive(Deserialize, surrealdb::SurrealValue)]
struct RecordWithId {
id: Thing,
content: String,
Expand Down
Loading