feat: safe swap for every container update, and old image cleanup #5323
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
Model 2 · Review Depth (DistilBERT)
Depth Score: 0.02 · 1 substantive comment(s)
Model 3 · Review Timing & Attention
Session adequacy: 100% · Reviewer familiarity: 35%
Bedrock Claude 3 · Risk Narration
(disconnected)
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
claude[bot]
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,waitStableandwaitGone, plusReplacementSpecandImageRef, moved frominternal/selfupdateto a newinternal/container/swappackage. selfupdate imports it and its tests still pass.swap/swaptestis a fake engine other packages' tests can drive an update with.docker.Service.UpdateContainerswaps undercontext.WithoutCancel. Network dependents rejoin after the swap commits, and also after a rollback, since the old container was stopped either way.dev.dozzle.previous-image=<old image id>anddev.dozzle.previous-ref=<repo@sha256:...>(picked for the repository the tag names; cleared for images built locally).errorDetailmid-stream is now an error. Before, it fell through and the update said "up to date".verifyingandrolled-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.WithoutCancelone, 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, alsoautoUpdateCleanupindozzle.yml(flag or env wins, the file is read at each update). Off by default.dev.dozzle.previous-imagelabel, so the image just replaced stays as the rollback target. The first update after this ships removes nothing.ImageRemoveby 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=falseopts a container out.bool cleanup = 2onUpdateContainerRequestinprotos/rpc.proto, so they need no flag of their own. An older agent ignores the field and just doesn't clean up.container.ClientService.UpdateContainerandContainerService.Updatenow take acontainer.UpdateOptions.Not in this PR
-dozzle-old-names from the sidebar while a swap runs. The renamed container shows up for up to ~10s (longer with a healthcheck).Container, and update events. That's phase 2.Testing
go test ./...passes.internal/container/swaptests cover the ported selfupdate fake-docker cases: success, rollback on create, start, exit and unhealthy,--rmcontainers, slow removal, and label stamping.UpdateContainertests ininternal/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, pullerrorDetail.cleanupand 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 showingverifyingand the label.bun run test,bun run typecheck,bun run lint,bun run buildandbun docs/scripts/check-translations.mjsall pass.SELFUPDATE_DOCKER_IT=1orDOCKER_IT=1against a real daemon here.Docs:
actions.mdcovers the swap and rollback and adds a "Cleaning up old images" section. The flag is insupported-env-vars.mdand the key in thesetup-wizard.mddozzle.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