← Back to Pull requests

feat: safe swap for every container update, and old image cleanup #5323

Open
unknown opened this pull request with 579 lines diff across 7 files
View on GitHub
unknown unknown commented on Oct 04, 2026 01:06 UTC
Author

Fixes #5294

The Update action used to stop and remove the old container before the new one existed. If create or start failed, the container was just gone, and the auto-update schedule makes that a 3am problem. Updates now go through the same swap self-update already uses: rename old, create new, stop old, start new, wait for it to stay up, then remove old. If anything fails, the replacement is removed and the old container comes back.

This is phase 1 of the judged updates plan (amir20/doligence#708).

What changed

  • swap, forward, rollback, waitStable and waitGone, plus ReplacementSpec and ImageRef, moved from internal/selfupdate to a new internal/container/swap package. selfupdate imports it and its tests still pass. swap/swaptest is a fake engine other packages' tests can drive an update with.

  • docker.Service.UpdateContainer swaps under context.WithoutCancel. Network dependents rejoin after the swap commits, and also after a rollback, since the old container was stopped either way.

  • The replacement gets dev.dozzle.previous-image=<old image id> and dev.dozzle.previous-ref=<repo@sha256:...> (picked for the repository the tag names; cleared for images built locally).

  • A pull that reports errorDetail mid-stream is now an error. Before, it fell through and the update said "up to date".

  • New progress statuses verifying and rolled-back. The toast says it's checking the new container, and a rollback shows as a warning with the reason. The updates drawer has pills for both, and the summary counts a rollback as failed. All 16 locales.

  • The progress callback now watches the request context instead of the WithoutCancel one, so a closed tab can't park the update goroutine on a full channel.
  • Old image cleanup (#5294)

  • --auto-update-cleanup / DOZZLE_AUTO_UPDATE_CLEANUP, also autoUpdateCleanup in dozzle.yml (flag or env wins, the file is read at each update). Off by default.

  • Applies to scheduled, manual, bulk and cloud tool updates alike.

  • Runs only after the swap commits. Never on rollback.

  • Removes the image before the previous one, read from the outgoing container's dev.dozzle.previous-image label, so the image just replaced stays as the rollback target. The first update after this ships removes nothing.

  • ImageRemove by id, no force, no child pruning, so Docker refuses while anything uses the image or another tag points at it. Failures are logged at debug and never fail the update.

  • dev.dozzle.update-cleanup=false opts a container out.

  • Agents get the setting through a new bool cleanup = 2 on UpdateContainerRequest in protos/rpc.proto, so they need no flag of their own. An older agent ignores the field and just doesn't clean up.

  • Swarm is out of scope and documented as such.
  • container.ClientService.UpdateContainer and ContainerService.Update now take a container.UpdateOptions.

    Not in this PR

  • Hiding -dozzle-old- names from the sidebar while a swap runs. The renamed container shows up for up to ~10s (longer with a healthcheck).

  • Rollback as an action, image identity on Container, and update events. That's phase 2.
  • Testing

  • go test ./... passes.

  • New internal/container/swap tests cover the ported selfupdate fake-docker cases: success, rollback on create, start, exit and unhealthy, --rm containers, slow removal, and label stamping.

  • New UpdateContainer tests in internal/container/docker/update_test.go: rolled back on start failure, rolled back on unhealthy, dependents rejoin after commit and after rollback, cleanup removes the right image, refusal (in use) still succeeds, opt out label, nothing on first update, never the image just replaced, never on rollback, pull errorDetail.

  • The agent gRPC test checks cleanup and the new statuses round trip. There are also tests for bulk rolled-back state, the cloud tool passing options, the flag/env/file precedence, and the web update stream showing verifying and the label.

  • bun run test, bun run typecheck, bun run lint, bun run build and bun docs/scripts/check-translations.mjs all pass.

  • I didn't run SELFUPDATE_DOCKER_IT=1 or DOCKER_IT=1 against a real daemon here.
  • Docs: actions.md covers the swap and rollback and adds a "Cleaning up old images" section. The flag is in supported-env-vars.md and the key in the setup-wizard.md dozzle.yml table, with de, es, fr and zh translated and re-stamped.

    Nothing to deploy first. Dozzle Cloud needs nothing for this one.

    🤖 Generated with Claude Code

    https://claude.ai/code/session_017DwX91Gcan9WBmKUnryftY

    Diff: 579 lines (+434 / -145) across 7 files Reviewer: claude[bot] Review duration: 24m
    All Vouch review confidence checks passed
    Residual risk 0.28 = Change Risk (0.50) × (1 − Review Confidence (0.43)). Review depth and reviewer attention state are adequate.
    Model 1 · Change Risk (XGBoost)
    Score: 0.50 · 579 lines diff across 7 files
    0.50
    Model 2 · Review Depth (DistilBERT)
    Depth Score: 0.02 · 1 substantive comment(s)
    0.02
    Model 3 · Review Timing & Attention
    Session adequacy: 100% · Reviewer familiarity: 35%
    42%
    Bedrock Claude 3 · Risk Narration
    (disconnected)
    Groq
    Groq Risk Narration
    AWS Bedrock is currently disconnected. Generate high-confidence PR triage narration on-demand using Groq.
    Model 1 · Change Risk Attribution
    SHAP Weights
    Diff Size diff_size
    0.381
    Shallow Review Depth shallow_review_depth
    0.344
    Real PR Conversation Timeline
    1 comments
    "Review active on #5323"
    general weight: 0.35
    Reviewers
    Assignees
    Unassigned
    Labels
    risk: low confidence: 43.0% reviewed
    Vouch Risk Breakdown
    AI-powered review risk analysis
    Change Risk
    Change Risk · Model 1 (XGBoost)
    Predicted defect probability (0.00–1.00) based on diff churn, modified sensitive files, and author risk history.
    Score: 49.9% (MEDIUM) · Higher = larger blast radius
    49.9%
    Review Confidence
    Review Confidence · Models 2 & 3
    Scrutiny score (0.00–1.00) combining DistilBERT semantic review depth with reviewer familiarity and session dwell time.
    Score: 43.0% · Lower = rushed or shallow review
    43.0%
    Residual Risk
    Residual Risk · Core Equation
    Residual = Change × (1 − Confidence)
    Unmitigated risk surviving review. ≥ 0.65 triggers an automated re-queue to protect production.
    Score: 28.4% · Safe to merge
    28.4%
    Repository