Skip to content

feat(selfupdate): let operators opt out of pre-update snapshot per-update - #149

Merged
frahlg merged 1 commit into
masterfrom
149-update-skip-snapshot-checkbox
Apr 20, 2026
Merged

frahlg merged 1 commit into
masterfrom
149-update-skip-snapshot-checkbox

Conversation

@frahlg

@frahlg frahlg commented Apr 20, 2026

Copy link
Copy Markdown
Member

Small follow-up to #141.

Summary

  • Adds a checkbox under the snapshot hint in the update modal: "Skip backup for this update". Default unchecked.
  • When ticked the UI POSTs `{"skip_snapshot": true}` to `/api/version/update`; the handler bypasses the snapshot step and returns `snapshot_skipped: true` in the response.
  • Default flow (checkbox left unchecked / no body / pre-checkbox UI) is unchanged — snapshot is created as before.

Why

Per-update opt-out for two real cases:

  1. The 5 retained snapshots already cover the likely rollback window.
  2. Tight disk on a small SD card — ~200 MB per snapshot adds up.

Deploy-time opt-out (empty `SnapshotDir`) continues to work exactly the same.

Test plan

  • `TestVersionUpdate_SkipSnapshotOptOut` — post with the flag, verify the snapshots directory stays empty.
  • Existing 8 version-update / snapshot tests green (default path untouched).
  • `make test` + `make e2e` green.
  • Smoke on Pi when this ships: open modal → see checkbox under the 🛟 hint. Tick → click Update → verify `/api/version/snapshots` count doesn't grow on this run. Untick → click Update → count grows by 1.

🤖 Generated with Claude Code

…date

Follow-up to #141. Snapshot-before-update is the right default — every
operator should keep a rollback point most of the time — but there are
two cases where the behaviour is friction:

1. The retained set of 5 recent snapshots already covers the operator
   for the kind of rollback they'd need.
2. Disk is tight (small SD card, couple hundred MB per snapshot adds up).

Added a small unobtrusive checkbox under the snapshot hint:
*"Skip backup for this update"*. Default unchecked (safety first). When
ticked the UI sends \`{"skip_snapshot": true}\` in the POST body and the
handler bypasses \`createPreUpdateSnapshot\` entirely, returning
\`snapshot_skipped: true\` in the 202 response so client/log can tell
the paths apart.

Snapshot is still created by default for every Update click. And the
deploy-time opt-out (empty SnapshotDir) keeps working exactly the same
— the new body flag and the deploy flag are both honoured.

Restart flow untouched (never snapshotted anyway) — no body sent there.

Test: TestVersionUpdate_SkipSnapshotOptOut exercises the new path —
post \`{"skip_snapshot":true}\`, verify the snapshots directory stays
empty even as the handler proceeds to trigger (sidecar absence is a
red herring for this assertion; we care that the snapshot step was
bypassed regardless of downstream outcome).

Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
@frahlg
frahlg merged commit 6161bcd into master Apr 20, 2026
1 check passed
@frahlg
frahlg deleted the 149-update-skip-snapshot-checkbox branch April 20, 2026 08:54

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 7f657cabf7

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread web/update-badge.js
Comment on lines +353 to +357
case "toggle-skip-snapshot":
// Don't re-render — the <input> element already reflects
// its own state and a full render would reset focus.
this._skipSnapshot = !!e.currentTarget.checked;
break;

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P1 Badge Reset skip-snapshot flag after each update attempt

The checkbox handler stores skip_snapshot on component state and never clears it, so a one-time opt-out persists across later modal opens and updates. In practice, if an operator checks it once (or cancels after checking), a subsequent update can silently run without a backup even though the UI text says “for this update,” which weakens rollback safety unexpectedly.

Useful? React with 👍 / 👎.

Comment on lines +98 to +102
if r.ContentLength > 0 {
if err := readJSON(r, &body); err != nil {
writeJSON(w, 400, map[string]string{"error": "bad json: " + err.Error()})
return
}

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Parse JSON body even when Content-Length is unknown

Conditioning JSON decoding on r.ContentLength > 0 drops valid request bodies when the length is unknown (e.g., chunked transfer where Go exposes ContentLength == -1). In those cases {"skip_snapshot": true} is ignored and the handler takes a snapshot anyway, so behavior depends on transport/proxy details instead of request payload.

Useful? React with 👍 / 👎.

frahlg added a commit that referenced this pull request Oct 1, 2026
#1474 pinned d74ace6, a commit on the #149 branch. #149 has now
landed on device-drivers main as 424f1e5c. Moving the pin there keeps the
bundle on main and brings esphome_dsmr 1.0.7 (srcfl/device-drivers#152),
the only bundled driver that differs.

Signed-off-by: Fredrik Ahlgren <[email protected]>
Co-authored-by: Claude Opus 5.5 <[email protected]>
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.

1 participant