lxd: delete container only if parts is empty
Metadata
Current evaluation
Merged PR #1762 (dbce9a058), changing LXD cleanup to delete a build container only after all parts are removed, preserving it for targeted cleans and making repeated cleans safe.
Resolution: closed resolved
Reason: The approved change was merged as commit dbce9a058. It makes full cleanup remove the LXD container, while project- or part-specific cleanup preserves it and later clean commands safely handle its absence.
Evaluated by: mr-cal-bot
No scores available.
Issue body
- [x] Have you followed the [guidelines for contributing](https://github.com/snapcore/snapcraft/blob/master/CONTRIBUTING.md)?
- [x] Have you signed the [CLA](http://www.ubuntu.com/legal/contributors/)?
- [x] If this is a bugfix. Have you checked that there is a bug report open for the issue you are trying to fix on [bug reports](https://bugs.launchpad.net/snapcraft)?
- [x] If this is a new feature. Have you discussed the design on the [forum](https://forum.snapcraft.io)?
- [x] Have you successfully run `./runtests.sh static`?
- [x] Have you successfully run `./runtests.sh unit`?
-----
Steps to manually test this:
* export SNAPCRAFT_CONTAINER_BUILDS=helga
* cd snapcraft/tests/integration/snaps/go-hello/
* lxc list helga: | grep go-hello
* Observe no container exists
* snapcraft pull
* lxc list helga: | grep go-hello
* Observe container exists
* snapcraft clean -s pull go-hello
* lxc list helga: | grep go-hello
* Observe container exists
* snapcraft clean go-hello
* Observe container still exists, artifacts were cleaned
* snapcraft clean
* lxc list helga: | grep go-hello
* Observe container was deleted, message "Deleting helga:snapcraft-go-hello"
* Repeat "snapcraft clean", "snapcraft clean go-hello", "snapcraft clean -s pull go-hello"
* Observe no error occurred with already deleted container
Fixes [bug 1734145](https://bugs.launchpad.net/snapcraft/+bug/1734145)
Evaluation history
| Date | Model | Scores | Action | Summary |
|---|---|---|---|---|
| stealth/space-bunny-alpha | — | closed resolved | Merged PR #1762 (dbce9a058), changing LXD cleanup to delete a build container only after all parts are removed, preserving it for targeted cleans and making repeated cleans safe. | |
| stealth/space-bunny-alpha | — | closed resolved | Merged PR #1762 (dbce9a058) so LXD containers are deleted only when no parts remain, making clean operations safe and idempotent. | |
| qwen/qwen3.6-35b-a3b | — | — | Merged fix resolving bug 1734145 by updating LXD container cleanup logic to only delete containers when parts are empty. Approved by one reviewer, passed CI checks, and modified two files. | |
| qwen3.6-35b-a3b-mtp-q6 | — | — | Merged to fix bug 1734145. Updates LXD container cleanup to only delete containers when the parts list is empty, preventing errors during repeated clean operations. |
Update history
No update history recorded yet.
Related issues
| Issue | Project | State | Summary | Similarity |
|---|---|---|---|---|
| #1434 lxd: clean with no parts should only delete | snapcraft | merged | Merged #1434 in commit 33c7a6bc1, making argless LXD clean delete container resources without executing commands inside the container. | |
| #1587 lifecycle: clean after deleting container | snapcraft | merged | Merged PR #1587 (commit daca4618b): LXD cleanup logic moved into lxd.py's clean() so `snapcraft clean` removes leftover build containers, addressing the forum-reported container-build clean issue. | |
| #1456 clean up stale containers | snapcraft | closed | Stale LXD build-container cleanup was implemented in merged PR #1587 (commit daca4618b), moving cleanup into the LXD clean lifecycle. | |
| #1230 lxd: refactor Cleanbuilder into Containerbuild and add Project. | snapcraft | merged | Merged PR #1230 (ce66ca561) replaced Cleanbuilder with a Containerbuild base class and added Project to create and reuse project-named LXD containers. | |
| #1655 lxd: distinguish argless clean from clean -s pull | snapcraft | merged | Merged in snapcraft#1655 (ed32603c7), fixing LXD cleanup so bare clean removes build containers while clean -s pull preserves or recreates them. | |
| #1734145 snapcraft clean <part-name> destroys everything when using containers | snapcraft (launchpad) | closed | Fixed targeted container cleanup: `snapcraft clean <part>` no longer deletes the LXD container while other parts remain; merged in #1762 (dbce9a058). | |
| #1627 lxd: split container classes into different files | snapcraft | merged | Merged in snapcraft#1627 via d2118855c, splitting LXD container classes into separate modules, relocating Cleanbuilder methods and deduplicating environment setup without functional changes. | |
| #459 Remove LXD container once we've finished a build | snapcraft | closed | Closed unmerged: testing showed cleanbuild already destroyed its LXD containers; the startup failure was fixed separately by merged PR #458 (f78b1e3a3). | |
| #1403 lxd: Only remove container if one exists | snapcraft | merged | Merged PR #1403, adding an LXD existence check so failed container creation no longer triggers a second exception while stopping or removing a nonexistent container. | |
| #1644 lxd: fix the push in container builds | snapcraft | merged | Merged PR #1644 fixed LXD container-build artifact pushes; the change landed as commit d4a34e07d. |