Skip to content

feat(prune): fix image pruning, add usage summary, progress, stopped containers and prune-all - #83

Merged
alexneo2003 merged 1 commit into
mainfrom
claude/prune-improvements
Oct 17, 2026
Merged

alexneo2003 merged 1 commit into
mainfrom
claude/prune-improvements

Conversation

@alexneo2003

Copy link
Copy Markdown
Contributor

Summary

The per-agent "Prune Images" feature had correctness gaps and gave the user no feedback. This PR fixes the pruning logic and adds a usage summary, progress, an opt-in for stopped containers, and a "Prune all agents" run.

Bugs fixed

  • Wrong versions kept: candidates relied on Docker's list order, which is not guaranteed. They are now sorted by creation time per repository, so the newest N unused versions are kept.
  • Multi-tag images were counted/removed twice (dry run double-counted; real run hit "no such image"). Now handled once, removed tag by tag.
  • Rollback targets could be pruned. Images and containers that saved rollback snapshots depend on are now always kept.
  • Inflated "space reclaimed" counted layers shared with remaining images. Now excludes shared layers (still an estimate).
  • Results never reached the UI: PRUNE_COMPLETE was broadcast but not typed or handled; dry run said "check agent logs". Now the UI gets progress and the result, and the agent replies on every path (invalid payload, concurrent run) with a requestId.
  • Empty "keep previous" field silently meant 0 (Number('') === 0). The UI now blocks invalid input and the controller validates keepPrevious (integer 0–10) and the flags (400 otherwise).
  • No guard against concurrent prunes (now 409) or a hung agent (timeout / disconnect reported as a failed outcome).

New

  • Usage summary next to the prune controls: total image size/count, reclaimable space and image count, stopped-container count. New agent command PRUNE_PREVIEW + GET /api/agents/:id/prune/preview.
  • Dry Run now lists exactly what would be removed (from the preview) instead of pointing at agent logs.
  • Progress + result: progress bar (containers/images, n/total, current item) and a toast such as "Pruned web-1: removed 3 images, 1 container, freed ~1.2 GB" (errors reported separately).
  • Stopped containers are an opt-in checkbox (off by default). Volumes are kept; temporary -ww-old/-ww-new containers and snapshot-protected ones are never removed.
  • Prune all agents (Agents page): POST /api/prune runs agents sequentially, skips offline ones, continues past failures, and shows a per-agent summary with totals (GET /api/prune/current restores state after a reload).

Notes / deviations from the plan

  • No new DB table: results are not persisted beyond the audit log hook that already records the POST requests.
  • Image removal now untags by reference rather than by ID.
  • Agents older than this change still work for pruning (the controller falls back to matching the reply to the in-flight request) but ignore includeStopped and cannot serve the preview.

Testing

  • Agent: new pruner_test.go (12 tests: ordering, keep 0, multi-tag, rollback protection, shared-layer size, stopped-container opt-in, dry run, error handling, preview). go vet clean. The only failures in go test ./... are the 4 TestRecoverOrphans_* tests that already fail on main.
  • Controller: new prune-service.test.ts and prune.test.ts (validation, 404/409/504, concurrency, partial/failed outcomes, sequential prune-all with offline/failed agents). tsc clean. These two files were run without the Postgres test container (no container runtime in my sandbox); the Postgres-backed suites (including the hub.ts changes) rely on CI.
  • UI: new tests for PruneCard, prune helpers and the store events; npm run build, lint and all 112 tests pass.
  • Not verified against a real Docker daemon (none available here). Suggested manual check: /pr-beta, then on an agent with some old image versions and a stopped container, try Dry Run, Prune with/without the checkbox, and "Prune all".

Generated by Claude Code

…containers and prune-all

Agent
- Select prune candidates per image ID, sorted by creation time (Docker does not
  guarantee list order, so the wrong versions could be kept). Multi-tag images are
  counted/removed once, tag by tag; images shared with an in-use repo are kept.
- Never remove images or containers that rollback snapshots depend on.
- Report space freed excluding layers shared with remaining images.
- Optional removal of stopped containers (never -ww-old/-ww-new or snapshot ones).
- New PRUNE_PREVIEW (disk usage + candidates), PRUNE_PROGRESS, and a PRUNE_RESULT
  that is sent on every path (invalid payload, concurrent run) with a requestId.

Controller
- PruneService: validated options (keepPrevious 0-10, booleans), one prune per
  agent (409), timeouts/disconnects reported as failures, preview endpoint, and a
  sequential prune-all run that skips offline agents and returns a summary.
- Routes: POST /api/agents/:id/prune, GET .../prune/preview, POST /api/prune,
  GET /api/prune/current. PRUNE_COMPLETE/PROGRESS/RUN_* are now broadcast to the UI
  (PRUNE_COMPLETE was previously sent but never handled).

UI
- Prune card shows total image size, reclaimable space and stopped-container
  count, an opt-in "also remove stopped containers" checkbox, a dry-run list,
  a progress bar, and a result toast ("removed 3 images, freed ~1.2 GB").
- Empty/invalid "keep previous" no longer silently means 0.
- "Prune all" on the Agents page with live progress and a per-agent summary.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01EeNrf1VXC34bbCKDsfL4TS
@github-actions

Copy link
Copy Markdown
Contributor

🧪 Test Results — ✅ All tests passed

Component Status Passed Failed
Controller (TypeScript) ✅ 294 0
Agent (Go) ✅ 165 0
UI (React) ✅ 112 0
Total ✅ 571 0

Commit: 69c49d2 | Run: #105

@alexneo2003
alexneo2003 merged commit 1aa9e64 into main Oct 17, 2026
10 checks passed
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