Skip to content

Conversation

devin-ai-integration[bot]
Copy link
Contributor

Add universal cloud cred ref ID and orphaned instance cleanup

Summary

This PR implements a system for cleaning up orphaned cloud instances from validation testing. The changes include:

  1. Universal Cloud Credential Reference ID: Added a constant UniversalCloudCredRefID = "brev-validation-test" in the validation package that all validation tests now use
  2. Cleanup Function: Created CleanupOrphanedInstances() that identifies and terminates instances older than 1 hour with the universal credential reference ID
  3. GitHub Action Workflow: Added a disabled-by-default workflow that can run cleanup hourly (commented out schedule, manual trigger only)
  4. CLI Tool: Created cmd/cleanup/main.go with dry-run support for manual/automated cleanup operations

The implementation targets Lambda Labs initially but is designed to be extensible to other cloud providers.

Review & Testing Checklist for Human

  • Test dry-run mode: Run go run cmd/cleanup/main.go -provider=lambdalabs -dry-run=true to verify it correctly identifies orphaned instances without deleting them
  • Verify time-based filtering: Check that the 1-hour cutoff logic works correctly and handles timezones properly (instances created <1hr ago should NOT be cleaned up)
  • Test GitHub Action workflow: Manually trigger the workflow via GitHub Actions UI to ensure it runs correctly and respects the disabled-by-default configuration
  • Review credential matching logic: Ensure CloudCredRefID matching only targets instances created with the universal validation credential, not production instances
  • End-to-end CLI testing: Test both dry-run and actual cleanup modes with real Lambda Labs credentials to verify the complete flow works

Diagram

%%{ init : { "theme" : "default" }}%%
flowchart TD
    ValidationSuite["internal/validation/suite.go<br/>UniversalCloudCredRefID constant<br/>CleanupOrphanedInstances function"]:::major-edit
    ValidationTest["internal/lambdalabs/v1/validation_test.go<br/>Updated to use universal constant"]:::minor-edit
    GitHubAction[".github/workflows/cleanup-orphaned-instances.yml<br/>Disabled by default workflow"]:::major-edit
    CLITool["cmd/cleanup/main.go<br/>Command-line cleanup tool"]:::major-edit
    LambdaLabsClient["internal/lambdalabs/v1/instance.go<br/>ListInstances & TerminateInstance"]:::context
    
    ValidationSuite --> ValidationTest
    GitHubAction --> CLITool
    CLITool --> ValidationSuite
    ValidationSuite --> LambdaLabsClient
    
    subgraph Legend
        L1[Major Edit]:::major-edit
        L2[Minor Edit]:::minor-edit  
        L3[Context/No Edit]:::context
    end
    
    classDef major-edit fill:#90EE90
    classDef minor-edit fill:#87CEEB
    classDef context fill:#FFFFFF
Loading

Notes

  • The GitHub Action is intentionally disabled by default (manual trigger only) as requested - uncomment the schedule section to enable hourly runs
  • The cleanup function includes comprehensive error handling and logging for debugging
  • The CLI tool supports both Lambda Labs initially but is structured to easily add other cloud providers
  • All linting and existing tests pass successfully

Link to Devin run: https://app.devin.ai/sessions/ed3c049e29244357b8ea2587a22d7cd8
Requested by: @theFong

- Add UniversalCloudCredRefID constant in internal/validation
- Update validation tests to use universal constant
- Add CleanupOrphanedInstances function for 1hr+ old instances
- Create GitHub Action workflow (disabled by default)
- Add cleanup CLI tool for manual/automated cleanup

Co-Authored-By: Alec Fong <[email protected]>
Copy link
Contributor Author

🤖 Devin AI Engineer

I'll be helping with this pull request! Here's what you should know:

✅ I will automatically:

  • Address comments on this PR. Add '(aside)' to your comment to have me ignore it.
  • Look at CI failures and help fix them

Note: I can only respond to comments from users who have write access to this repository.

⚙️ Control Options:

  • Disable automatic comment and CI monitoring

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.

0 participants