Thanks to visit codestin.com
Credit goes to github.com

Skip to content

feat: persist conversations#1525

Merged
tusharmath merged 75 commits into
mainfrom
feat/persist-conversations
Sep 12, 2025
Merged

feat: persist conversations#1525
tusharmath merged 75 commits into
mainfrom
feat/persist-conversations

Conversation

@laststylebender14

Copy link
Copy Markdown
Contributor

No description provided.

@github-actions github-actions Bot added the type: feature Brand new functionality, features, pages, workflows, endpoints, etc. label Sep 11, 2025
Comment thread crates/forge_domain/src/conversation.rs Outdated
Comment thread crates/forge_domain/src/conversation.rs Outdated
Comment thread crates/forge_infra/src/database/repository/conversation.rs Outdated
Comment thread crates/forge_infra/src/database/repository/conversation.rs Outdated
Comment on lines +110 to +133
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?))
}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

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.

Suggested change
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

Fix in Graphite


Is this helpful? React 👍 or 👎 to let us know.

@openhands-ai

openhands-ai Bot commented Sep 12, 2025

Copy link
Copy Markdown

Looks like there are a few issues preventing this PR from being merged!

  • GitHub Actions are failing:
    • ci

If you'd like me to help, just leave a comment, like

@OpenHands please fix the failing actions on PR #1525 at branch `feat/persist-conversations`

Feel free to include any additional details that might help me get this PR into a better state.

You can manage your notification settings

.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());

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

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.

Suggested change
let updated_at = context.as_ref().map(|_| Utc::now().naive_utc());
let updated_at = context.as_ref().map(|_| None);

Spotted by Diamond

Fix in Graphite


Is this helpful? React 👍 or 👎 to let us know.

Comment on lines +100 to +103
let pool = builder.build(manager).map_err(|e| {
warn!(error = %e, "Failed to create connection pool");
anyhow::anyhow!("Failed to create connection pool: {}", e)
})?;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

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

Fix in Graphite


Is this helpful? React 👍 or 👎 to let us know.

@tusharmath tusharmath merged commit 8857459 into main Sep 12, 2025
8 checks passed
@tusharmath tusharmath deleted the feat/persist-conversations branch September 12, 2025 11:05
@dariuszkowalski-com

Copy link
Copy Markdown
Contributor

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

type: feature Brand new functionality, features, pages, workflows, endpoints, etc.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants