From 286cdc580f9dfab25feb5b81bb1170ab1fcb7abf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lu=C3=ADs=20Sousa?= Date: Thu, 27 Nov 2025 21:40:16 -0300 Subject: [PATCH 1/2] fix(profile-cache): resolve race condition on fresh install MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit On fresh installs, the profile cache was empty because `load_genie_profiles_for_all_projects()` runs at startup before any projects exist. When users created their first project and tried to create a task, the `get_project_profiles` endpoint failed because the project wasn't registered in the cache. Solution: Register the project in the cache lazily when `get_project_profiles` is called, ensuring the project exists in the database first. This matches the pattern already used in other endpoints like `create_agent_task`. Also improved error handling to return INTERNAL_SERVER_ERROR instead of NOT_FOUND when profile loading fails (after confirming project exists). Fixes #276 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude --- forge-app/src/router.rs | 23 ++++++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) diff --git a/forge-app/src/router.rs b/forge-app/src/router.rs index 927b510b8..abe21a98e 100644 --- a/forge-app/src/router.rs +++ b/forge-app/src/router.rs @@ -27,6 +27,7 @@ use uuid::Uuid; use crate::services::ForgeServices; use db::models::{ image::TaskImage, + project::Project, task::{Task, TaskWithAttemptStatus}, task_attempt::{CreateTaskAttempt, TaskAttempt}, }; @@ -1763,6 +1764,26 @@ async fn get_project_profiles( Path(project_id): Path, State(services): State, ) -> Result>, StatusCode> { + // Fetch project from database to ensure it exists and get workspace path + let project = match Project::find_by_id(&services.pool, project_id).await { + Ok(Some(p)) => p, + Ok(None) => { + tracing::error!("Project {} not found", project_id); + return Err(StatusCode::NOT_FOUND); + } + Err(e) => { + tracing::error!("Database error fetching project {}: {}", project_id, e); + return Err(StatusCode::INTERNAL_SERVER_ERROR); + } + }; + + // Ensure project is registered in profile cache (fixes race condition on fresh installs) + services + .profile_cache + .register_project(project.id, project.git_repo_path.clone()) + .await; + + // Now safe to lookup profiles services .profile_cache .get_profiles_for_project(project_id) @@ -1777,7 +1798,7 @@ async fn get_project_profiles( }) .map_err(|e| { tracing::error!("Failed to load profiles for project {}: {}", project_id, e); - StatusCode::NOT_FOUND + StatusCode::INTERNAL_SERVER_ERROR }) } From 942b6ba325704e3e9b145d855d1fb30142dd2de0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lu=C3=ADs=20Sousa?= Date: Fri, 28 Nov 2025 17:40:16 -0300 Subject: [PATCH 2/2] refactor(router): use idiomatic Result