Skip to content

fix: soft-delete instance from DB when instance manager returns 404#183

Merged
PierreLeGuen merged 2 commits intomainfrom
fix/soft-delete-on-404
Feb 22, 2026
Merged

fix: soft-delete instance from DB when instance manager returns 404#183
PierreLeGuen merged 2 commits intomainfrom
fix/soft-delete-on-404

Conversation

@PierreLeGuen
Copy link
Contributor

Summary

  • When deleting an instance, if compose-api returns 404 (instance already removed via another channel), proceed with the DB soft-delete instead of failing
  • Other non-2xx errors (400, 500) still fail as before
  • Prevents users from getting stuck with undeletable instances

Test plan

  • Delete an instance that exists on both compose-api and DB — should work as before (204)
  • Delete an instance that was already removed from compose-api but still in DB — should now succeed with a warning log
  • Delete with compose-api returning 500 — should still fail with error

Instance may have been removed through another channel (e.g. direct
compose-api call). Previously a 404 from the instance manager blocked
the DB soft-delete, leaving the user stuck with an undeletable instance.
@gemini-code-assist
Copy link

Summary of Changes

Hello @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 refines the instance deletion workflow by introducing more robust error handling for external API calls. It specifically addresses a scenario where an instance might have already been removed from the instance manager, ensuring that the local database record can still be soft-deleted without error. This enhancement improves the reliability and user experience of instance management by preventing orphaned database entries.

Highlights

  • Improved Instance Deletion Logic: Modified the instance deletion process to gracefully handle cases where the external instance manager (compose-api) returns a 404 (Not Found) status. Instead of failing, the system will now proceed with a soft-delete of the instance from the database.
  • Enhanced Error Handling: Introduced specific handling for 404 responses from the instance manager, logging a warning but allowing the database soft-delete to complete. Other non-2xx errors (e.g., 400, 500) will still cause the deletion operation to fail as before.
  • Prevents Stuck Instances: This change prevents users from encountering 'undeletable' instances that might have been removed from the external system but remained in the local database.
Changelog
  • crates/services/src/agent/service.rs
    • Modified the delete_instance method to check for a 404 (Not Found) status code from the Agent API. If a 404 is received, a warning is logged, and the database soft-delete proceeds.
    • Ensured that other non-success HTTP status codes (e.g., 400, 500) still result in an error, maintaining existing failure behavior for unexpected issues.
Activity
  • Test plan outlined to verify deletion of existing instances (204), instances already removed from compose-api (succeed with warning), and instances with compose-api returning 500 (still fail).
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.

@claude
Copy link

claude bot commented Feb 21, 2026

Code Review

Change summary: When compose-api returns 404 on instance deletion, soft-delete from DB instead of surfacing an error to the user.

No critical issues found.

  • Logic is correct: 404 means the remote instance is already gone, cleaning up the DB record is the right behavior.
  • Logging complies with privacy requirements — only instance_id is emitted, no PII or content.
  • Non-404 failures still propagate errors as expected.
  • The removed comment accurately reflects the intentional behavior change.

✅ Approved

Copy link

@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 correctly handles the case where an instance is already deleted from the instance manager (returning a 404) by proceeding with the soft-delete in the database. This prevents instances from getting stuck in an undeletable state. The change is logically sound. The suggestion to improve the code structure for better readability and future maintenance has been retained.

Comment on lines +1187 to 1200
if status == reqwest::StatusCode::NOT_FOUND {
tracing::warn!(
"Instance not found on instance manager (already removed?), proceeding with DB soft-delete: instance_id={}",
instance_id
);
} else {
return Err(anyhow!(
"Agent API delete failed with status {}: instance_id={}",
status,
instance_id
));
}
}

Choose a reason for hiding this comment

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

medium

For better readability and to make it easier to handle other status codes in the future, you could use a match statement here to handle the non-success status codes.

Suggested change
if status == reqwest::StatusCode::NOT_FOUND {
tracing::warn!(
"Instance not found on instance manager (already removed?), proceeding with DB soft-delete: instance_id={}",
instance_id
);
} else {
return Err(anyhow!(
"Agent API delete failed with status {}: instance_id={}",
status,
instance_id
));
}
}
if !status.is_success() {
match status {
reqwest::StatusCode::NOT_FOUND => {
tracing::warn!(
"Instance not found on instance manager (already removed?), proceeding with DB soft-delete: instance_id={}",
instance_id
);
}
_ => {
return Err(anyhow!(
"Agent API delete failed with status {}: instance_id={}",
status,
instance_id
));
}
}
}

@PierreLeGuen PierreLeGuen merged commit 8c97495 into main Feb 22, 2026
2 checks passed
@PierreLeGuen PierreLeGuen deleted the fix/soft-delete-on-404 branch February 22, 2026 00:04
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.

2 participants