feat: persist conversations#1525
Conversation
| async fn get_all_conversations( | ||
| &self, | ||
| limit: Option<usize>, | ||
| ) -> anyhow::Result<Option<Vec<Conversation>>> { | ||
| let mut connection = self.pool.get_connection()?; | ||
|
|
||
| let mut query = conversations::table | ||
| .order(conversations::created_at.desc()) | ||
| .into_boxed(); | ||
|
|
||
| if let Some(limit_value) = limit { | ||
| query = query.limit(limit_value as i64); | ||
| } | ||
|
|
||
| let records: Vec<ConversationRecord> = query.load(&mut connection)?; | ||
|
|
||
| if records.is_empty() { | ||
| return Ok(None); | ||
| } | ||
|
|
||
| let conversations: Result<Vec<Conversation>, _> = | ||
| records.into_iter().map(Conversation::try_from).collect(); | ||
| Ok(Some(conversations?)) | ||
| } |
There was a problem hiding this comment.
The query in get_all_conversations is missing a filter for the current workspace ID. This could result in retrieving conversations from all workspaces rather than just the active one. Consider adding a filter condition:
let mut query = conversations::table
.filter(conversations::workspace_id.eq(self.wid.to_string()))
.order(conversations::created_at.desc())
.into_boxed();This ensures users only see conversations from their current workspace.
| async fn get_all_conversations( | |
| &self, | |
| limit: Option<usize>, | |
| ) -> anyhow::Result<Option<Vec<Conversation>>> { | |
| let mut connection = self.pool.get_connection()?; | |
| let mut query = conversations::table | |
| .order(conversations::created_at.desc()) | |
| .into_boxed(); | |
| if let Some(limit_value) = limit { | |
| query = query.limit(limit_value as i64); | |
| } | |
| let records: Vec<ConversationRecord> = query.load(&mut connection)?; | |
| if records.is_empty() { | |
| return Ok(None); | |
| } | |
| let conversations: Result<Vec<Conversation>, _> = | |
| records.into_iter().map(Conversation::try_from).collect(); | |
| Ok(Some(conversations?)) | |
| } | |
| async fn get_all_conversations( | |
| &self, | |
| limit: Option<usize>, | |
| ) -> anyhow::Result<Option<Vec<Conversation>>> { | |
| let mut connection = self.pool.get_connection()?; | |
| let mut query = conversations::table | |
| .filter(conversations::workspace_id.eq(self.wid.to_string())) | |
| .order(conversations::created_at.desc()) | |
| .into_boxed(); | |
| if let Some(limit_value) = limit { | |
| query = query.limit(limit_value as i64); | |
| } | |
| let records: Vec<ConversationRecord> = query.load(&mut connection)?; | |
| if records.is_empty() { | |
| return Ok(None); | |
| } | |
| let conversations: Result<Vec<Conversation>, _> = | |
| records.into_iter().map(Conversation::try_from).collect(); | |
| Ok(Some(conversations?)) | |
| } | |
Spotted by Diamond
Is this helpful? React 👍 or 👎 to let us know.
|
Looks like there are a few issues preventing this PR from being merged!
If you'd like me to help, just leave a comment, like Feel free to include any additional details that might help me get this PR into a better state. You can manage your notification settings |
…buffer transformation
| .as_ref() | ||
| .filter(|ctx| !ctx.messages.is_empty()) | ||
| .and_then(|ctx| serde_json::to_string(ctx).ok()); | ||
| let updated_at = context.as_ref().map(|_| Utc::now().naive_utc()); |
There was a problem hiding this comment.
Race condition in updated_at timestamp calculation. The updated_at field is set to Utc::now() at record creation time, but this timestamp may not match the actual database update time, especially under concurrent operations. This could lead to inconsistent ordering in get_last_conversation queries. Consider using database-level timestamps or ensuring atomic operations.
| let updated_at = context.as_ref().map(|_| Utc::now().naive_utc()); | |
| let updated_at = context.as_ref().map(|_| None); |
Spotted by Diamond
Is this helpful? React 👍 or 👎 to let us know.
| let pool = builder.build(manager).map_err(|e| { | ||
| warn!(error = %e, "Failed to create connection pool"); | ||
| anyhow::anyhow!("Failed to create connection pool: {}", e) | ||
| })?; |
There was a problem hiding this comment.
Error handling masks underlying database connection issues. The error mapping in the pool builder converts specific database errors into generic anyhow errors, potentially hiding critical database configuration problems like file permissions, disk space, or SQLite version incompatibilities. This could make debugging database issues difficult in production.
Spotted by Diamond
Is this helpful? React 👍 or 👎 to let us know.
|
To be consistent with #1548 - where We able to configure location of history file, we should also be able to choose a location of forge.db file. User will be able to run many independent agents without mix of prompts, and it will be more useful. BTW. Great feature! I Like it very much :D |
No description provided.