feat: add instance upgrade endpoint#186
Conversation
Users can upgrade their instance to the latest image via
POST /v1/agents/instances/{id}/upgrade. The endpoint fetches
the current images from the owning compose-api and restarts
the instance with the latest digest for its service type.
Summary of ChangesHello @PierreLeGuen, 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 introduces a new API endpoint and underlying service logic to enable users to upgrade their agent instances. The functionality ensures that instances can be updated to the latest available image for their specific service type, enhancing maintainability and allowing for seamless deployment of new versions. It integrates with existing systems to fetch image information and performs necessary ownership checks before proceeding with the upgrade. Highlights
Changelog
Activity
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
|
PR Review: feat: add instance upgrade endpoint1. Duplicate ownership check and redundant DB queriesThe route handler (
let instance = app_state.agent_repository.get_instance(instance_uuid).await...?
.ok_or_else(|| ApiError::not_found("Instance not found"))?;
if instance.user_id != user.user_id {
return Err(ApiError::forbidden(...));
}
let instance = self.repository.get_instance(instance_id).await?.ok_or_else(...)?;
if instance.user_id != user_id { return Err(anyhow!("Access denied")); }Fix: Remove the ownership check from the route handler (trust the service layer, consistent with how 2. No timeouts on external HTTP callsBoth HTTP calls to compose-api have no timeout: self.http_client.get(&version_url).bearer_auth(&manager.token).send().await
self.http_client.post(&restart_url).bearer_auth(&manager.token).json(...).send().awaitIf compose-api is slow or unresponsive, these requests hang indefinitely, blocking the async executor and potentially exhausting connection pool resources under load. Fix: Add a timeout, e.g.: self.http_client
.get(&version_url)
.bearer_auth(&manager.token)
.timeout(std::time::Duration::from_secs(30))
.send()
.await(Check how 3. Privacy:
|
There was a problem hiding this comment.
Code Review
This pull request introduces a new endpoint to upgrade agent instances. The implementation is consistent with existing patterns for instance management. My review focuses on improving maintainability by reducing code duplication, enhancing logging for better observability, and addressing a performance issue caused by a redundant database query. I've also pointed out opportunities to centralize string representations, particularly for enum variants using the std::fmt::Display trait, and to replace other magic strings with constants.
Code reviewFound 2 issues:
chat-api/crates/services/src/agent/service.rs Lines 1458 to 1463 in 3cd8238
chat-api/crates/api/src/openapi.rs Lines 101 to 107 in 3cd8238 🤖 Generated with Claude Code - If this code review was useful, please react with 👍. Otherwise, react with 👎. |
221a685 to
0c87dee
Compare
6934398 to
6a33ac7
Compare
Summary
POST /v1/agents/instances/{id}/upgradeendpoint that upgrades an instance to the latest image for its service type/versionendpoint, mapsservice_typeto the correct image key (worker/ironclaw), and restarts with that digestTest plan
POST /v1/agents/instances/{id}/upgradereturns 200