Skip to content

Comments

feat: add LXD emergency cleanup tool#370

Merged
josecelano merged 3 commits intomainfrom
add-lxd-emergency-cleanup-tool
Feb 18, 2026
Merged

feat: add LXD emergency cleanup tool#370
josecelano merged 3 commits intomainfrom
add-lxd-emergency-cleanup-tool

Conversation

@josecelano
Copy link
Member

Summary

Adds an emergency cleanup tool for orphaned LXD environments that remain after interrupted test workflows or deployment failures.

Changes

  • New Binary: lxd_cleanup tool for emergency cleanup of orphaned LXD resources
    • Supports dry-run mode for safe preview
    • Handles multiple environments in batch
    • Clear warnings about emergency-only usage
  • Documentation: Comprehensive guide in docs/tools/lxd-cleanup.md
    • Emphasizes normal destroy + purge workflow
    • Provides troubleshooting and verification steps
  • Agent Skill: Added clean-lxd-environments skill in .github/skills/
    • On-demand workflow activation for cleanup scenarios
    • Includes verification and troubleshooting guidance

Motivation

During E2E testing and development, LXD VMs can become orphaned when:

  • Tests are interrupted (Ctrl+C)
  • Deployment fails mid-process
  • State desynchronizes between application and LXD

The normal destroy + purge workflow requires valid state, making it unsuitable for these scenarios.

Usage

Emergency only - prefer normal workflow:

cargo run -- destroy environment-name
cargo run -- purge environment-name

When normal workflow fails:

# Preview cleanup
cargo run --bin lxd_cleanup -- --dry-run environment-name

# Perform cleanup
cargo run --bin lxd_cleanup -- environment-name

Testing

  • All linters passing (markdown, YAML, TOML, cspell, clippy, rustfmt, shellcheck)
  • Validated against 8 orphaned VMs from previous testing
  • All skill commands tested and working

References

  • Related: E2E testing cleanup patterns
  • Documentation: docs/tools/lxd-cleanup.md
  • Skill: .github/skills/clean-lxd-environments/skill.md

Add lxd_cleanup binary for emergency cleanup of LXD environments when
normal 'destroy' and 'purge' commands cannot be used.

This tool should ONLY be used when:
- Environment internal data is missing (manually deleted)
- Environment internal data is corrupted
- E2E tests left orphaned LXD resources

Features:
- Cleans build, templates, and data directories
- Destroys OpenTofu infrastructure
- Removes LXD instances and profiles
- Supports dry-run mode for safe preview
- Can clean multiple environments in one command
- Comprehensive logging and error handling

Documentation added at docs/tools/lxd-cleanup.md
Add agent skill for emergency cleanup of orphaned LXD environments with comprehensive workflow guidance, verification steps, and troubleshooting. Updated AGENTS.md skills table.
Add reference to docs/tech-stack/lxd.md in clean-lxd-environments skill's See Also section for better context on LXD provider.
@josecelano josecelano self-assigned this Feb 18, 2026
@josecelano
Copy link
Member Author

ACK 0e279c0

@josecelano josecelano merged commit ad5489d into main Feb 18, 2026
39 checks passed
@josecelano josecelano deleted the add-lxd-emergency-cleanup-tool branch February 18, 2026 18:56
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