Skip to content

chore: opportunistically clean up containers for completed tasks#598

Merged
ereslibre merged 5 commits intomainfrom
opportunistic-container-cleanup
Mar 24, 2026
Merged

chore: opportunistically clean up containers for completed tasks#598
ereslibre merged 5 commits intomainfrom
opportunistic-container-cleanup

Conversation

@ereslibre
Copy link
Copy Markdown
Collaborator

@ereslibre ereslibre commented Mar 23, 2026

Adds opportunistic container cleanup across the CLI so that containers for tasks in terminal states are automatically removed, freeing up resources without requiring an explicit user action.

Task output is already persisted via mounted volumes, so removing the container is safe. FAILED tasks are intentionally kept so users can still debug the container.

Changes

  • Added tryRemoveTaskContainer() helper in packages/cli/src/lib/sandbox/index.ts — a best-effort function that stops and removes a task's container and clears its container metadata
  • Added isTerminalStatus() and isActiveStatus() utilities in packages/cli/src/utils/task-status.ts to classify task states
  • list command: opportunistically removes containers when a task reaches a terminal status (COMPLETED, MERGED, PUSHED)
  • iterate command: removes the previous iteration's container before starting a new one
  • restart command: removes the previous container before starting a new one
  • cleanup command: bulk-removes containers for all non-active tasks during cleanup

Notes

The cleanup in the list command is fire-and-forget (.catch(() => {})), while iterate and restart await the removal since they need the container gone before starting a new one. The cleanup command also awaits removal but wraps each attempt in a try/catch for best-effort semantics.

@ereslibre ereslibre self-assigned this Mar 23, 2026
@ereslibre ereslibre requested a review from Angelmmiguel March 23, 2026 10:04
Copy link
Copy Markdown
Contributor

@Angelmmiguel Angelmmiguel left a comment

Choose a reason for hiding this comment

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

LGTM! Added a comment before approving.

@ereslibre ereslibre changed the title chore: opportunistically remove containers of completed tasks chore: opportunistically clean up containers for completed tasks Mar 24, 2026
@ereslibre ereslibre merged commit d4297bd into main Mar 24, 2026
6 checks passed
@ereslibre ereslibre deleted the opportunistic-container-cleanup branch March 24, 2026 07:42
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