fix(profile-cache): resolve race condition on fresh install#283
fix(profile-cache): resolve race condition on fresh install#283
Conversation
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 <noreply@anthropic.com>
Summary of ChangesHello @filipexyz, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed! This pull request resolves a critical race condition that affected fresh installations, preventing users from seeing agents after creating their first project. The core issue stemmed from the profile cache not being populated for new projects at startup. The solution introduces a lazy project registration mechanism within the Highlights
Using Gemini Code AssistThe full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips. Invoking Gemini You can request assistance from Gemini at any point by creating a comment using either
Customization To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a Limitations & Feedback Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here. You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension. Footnotes
|
There was a problem hiding this comment.
Code Review
This pull request effectively resolves a race condition that occurred on fresh installations by implementing lazy registration of projects in the profile cache. The approach of fetching the project from the database first to ensure it exists before attempting to load profiles is sound. Additionally, improving the error handling to return a 500 status code instead of a 404 upon profile loading failure for an existing project is a good refinement. The changes are well-reasoned and directly address the described issue. I have one suggestion to make the new error handling code more idiomatic.
Apply Gemini code review suggestion to refactor get_project_profiles error handling from match statement to map_err + ok_or_else chain. Changes: - Convert nested Result<Option<Project>> match to functional chain - Use map_err for database errors - Use ok_or_else for None case - Maintain identical error handling and logging behavior Benefits: - More idiomatic Rust pattern - Improved readability and conciseness - Standard pattern for handling Result<Option<T>> types
Summary
get_project_profilesis calledRoot Cause
On fresh installs,
load_genie_profiles_for_all_projects()runs at startup before any projects exist in the database. When users created their first project and tried to create a task, theget_project_profilesendpoint failed because the project wasn't registered in the cache.Solution
Register the project in the cache when
get_project_profilesis called, after confirming the project exists in the database. This matches the pattern already used in other endpoints likecreate_agent_task.Test Plan
Closes #276
🤖 Generated with Claude Code