Skip to content

Comments

fix(profile-cache): resolve race condition on fresh install#283

Open
filipexyz wants to merge 2 commits intodevfrom
fix/profile-cache-race-condition-276
Open

fix(profile-cache): resolve race condition on fresh install#283
filipexyz wants to merge 2 commits intodevfrom
fix/profile-cache-race-condition-276

Conversation

@filipexyz
Copy link
Contributor

Summary

  • Fixes race condition where agents weren't shown on fresh installations
  • Registers project in profile cache lazily when get_project_profiles is called
  • Improved error handling (returns 500 instead of 404 when profile loading fails after confirming project exists)

Root 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, the get_project_profiles endpoint failed because the project wasn't registered in the cache.

Solution

Register the project in the cache when get_project_profiles is called, after confirming the project exists in the database. This matches the pattern already used in other endpoints like create_agent_task.

Test Plan

  • Fresh DB install → create project → create task (no restart needed)
  • Existing projects still work after patch
  • Multiple projects can be loaded simultaneously

Closes #276

🤖 Generated with Claude Code

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>
@gemini-code-assist
Copy link
Contributor

Summary of Changes

Hello @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 get_project_profiles endpoint, ensuring projects are registered in the cache only when requested and after their existence is verified. Additionally, error handling for profile loading failures has been refined to provide more accurate status codes.

Highlights

  • Race Condition Resolution: Addresses a race condition occurring on fresh installations where agents were not displayed due to projects not being registered in the profile cache at startup.
  • Lazy Project Registration: Implements lazy registration of projects within the profile cache, specifically when the get_project_profiles endpoint is called, ensuring the project exists in the database first.
  • Enhanced Error Handling: Improves error handling for profile loading failures by returning a 500 Internal Server Error instead of a 404 Not Found if a project is confirmed to exist but profiles cannot be loaded.
Using Gemini Code Assist

The 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 /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

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 .gemini/ folder in the base of the repository. Detailed instructions can be found here.

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

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Copy link
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

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

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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant