R-353/R-357/R-358/R-360: the restore tells the truth (v0.226.0)
gates / gates (push) Successful in 11s

Four defects on the restore surface, all proven on demo-hp during the 2026-08-21
backup-truth drill, all still in shipped code. They share one acceptance idea: a
restore surface must state what it actually did, and must refuse what it cannot
do.

VERSION NOTE. The task specifying this targeted v0.224.0 against baseline
f8c9390. Both were consumed earlier the same day by R-330 (0.224.0) and R-331
(0.225.0). Drift re-confirmed against live Gitea before the first edit, operator
authorised proceeding, every symbol the spec named re-verified present at the
real baseline e5eee50.

R-353 -- a restore that gave back nothing still said it worked.
RestoreFromRecoveryUnit returned only error, so the surface printed
"<app> visszaallitva (<snapshot>)." -- equally true of a run that returned an
entire dataset and one that returned nothing. The count already existed and was
discarded one line deep: restoreDockerVolumesFrom always returned it, the
wrapper threw it away. Now (UnitRestoreResult, error), carrying replayed counts
AND what the manifest LISTED, because zero-replayed has two causes that are
opposite news. Three cases, three sentences, and EVERY one is a claim about the
BACKUP, never about the app -- this path has no SafetyDump discriminator, and
07-backup-architecture 6.3 records that an absent dump says nothing about the
app (R-361 destroyed canonical .sql files for four months).

R-357 -- the destructive restore had no free-space gate. offbox_reconstitute.go
contained ZERO references to offboxFree; all three existing gates guard
non-destructive paths. The gate now sits before mapOffsiteRestorePaths,
writeSafetyDump and StopStack, so a refusal costs nothing. Position IS the fix,
which is why the test asserts StopStack was never called. No headroom multiplier
(matches PlaceOffsiteRestore; the x1.1 elsewhere predicts a download). Fail
closed on either probe <= 0 -- otherwise `free < need` with need==0 is FALSE and
an unmeasurable scratch sails through: a gate present and inert.

R-358 -- a failed download was offered as a good one. The gate answered "the
directory exists and is non-empty", which is exactly what a part-way restic run
leaves. Now a completion marker written 0600 atomically AFTER restic returns
nil, with any stale one cleared BEFORE it starts; both orders pinned by an AST
test because resticStep is not a seam. Both handlers refuse server-side: the
wizard flags control a button, and a hidden button is not a guard.

SCENARIO F ANSWERED, and worse than the question assumed: a unit-only scratch IS
reachable through the real flow, by the most ordinary route. "Ellenorzo
visszaallitas" (mode=unit, advertised non-destructive) writes the SAME directory
-- offboxRestoreScratchDir ignores `full` and --include limits what restic
extracts, never where -- so a customer who ran the SAFE restore was then offered
the destructive one over a unit-only copy. Filed R-396; the marker closes it.

R-360 -- the delete refused only while a BACKUP ran. IsRunning() is FALSE for the
whole of a verification restore; the five sibling handlers all use
restoreOpBlocked(). Its doc comment claimed it already did this, which is why
nobody looked -- corrected in place.

Red-proofs, each printing the pre-fix behaviour, in CHANGELOG and REPORT. The
first R-357 red-proof exposed a hollow test OF MY OWN and it is recorded rather
than quietly fixed: the fixture refused earlier at the placement stat pre-pass,
so `stops == 0` passed against the pre-fix code. Fixture corrected, assertions
reordered so a removed gate reports the outage rather than "no error returned".

Green gate clean: 28 packages, rc 0. All 12 controller gates OK.
This commit is contained in:
2026-08-30 19:31:31 +02:00
parent e5eee501b5
commit b8af72764d
18 changed files with 1412 additions and 53 deletions
+39 -4
View File
@@ -438,6 +438,15 @@ func (s *Server) offboxReconstituteHandler(w http.ResponseWriter, r *http.Reques
offboxRedirectTo(w, r, restoreWizardPath(app), msg, true)
return
}
// R-358: the same server-side refusal as the place handler, and it matters MORE here — this is the
// destructive path. On 2026-08-21 „Teljes visszaállítás indítása" was offered over a part-copy left
// by a failed download and reported ok=true. The wizard's RestoreEnabled flag controls a button;
// this controls the operation.
if !s.backupMgr.OffboxFullScratchReady(app) {
s.logger.Printf("[WARN] [web] off-box reconstitute refused for %s: the restore scratch carries no completion marker", app)
offboxRedirectTo(w, r, restoreWizardPath(app), offsiteScratchIncompleteMsg, true)
return
}
// R-351: a SEPARATE field from `confirm`. The restore's own confirm answers "overwrite my live
// data"; this one answers "yes, into a different place than the backup recorded". One checkbox
// carrying both would be the two-decisions-one-button shape R-48 removed from this surface.
@@ -459,6 +468,12 @@ func (s *Server) offboxReconstituteHandler(w http.ResponseWriter, r *http.Reques
offboxRedirectTo(w, r, restoreWizardPath(app), "A teljes visszaállítás elindult — az állapot itt frissül.", false)
}
// offsiteScratchIncompleteMsg (R-358) is the server-side refusal shown when a place or reconstitute is
// attempted over a scratch that carries no completion marker. Named because two handlers assert it and
// two tests assert it verbatim. It names the action that works — Lane 1 is customer-owned, so a refusal
// that leaves the customer with no next step is not a refusal, it is a dead end.
const offsiteScratchIncompleteMsg = "A visszaállítási másolat nem teljes — a legutóbbi letöltés nem fejeződött be. Indítsd újra a teljes visszaállítás előkészítését."
// reconstituteOutcomeMsg builds the OUTCOME flash for a completed reconstitution. Pure, so the
// wording is unit-testable — this string is the customer's only evidence that the operation did
// what its label promised, and the zero-file and no-database cases must each read truthfully rather
@@ -509,8 +524,15 @@ func reconstituteOutcomeMsg(app string, res backup.OffsiteReconstituteResult) st
// `backups/offsite-restore` root it computed itself and refuses anything that lands outside (see
// DeleteOffsiteRestoreCopy). The template double-confirms before POSTing.
//
// It refuses while a backup/restore op is running: the copy being deleted could be the one currently
// being written.
// R-360 — THE DOC COMMENT USED TO CLAIM THIS AND THE CODE DID NOT DO IT, which is why nobody looked.
// It read "It refuses while a backup/restore op is running"; the guard was `s.backupMgr.IsRunning()`,
// which answers "is a BACKUP running" and is FALSE for the whole of a verification restore (see the
// standing note on the two running flags). Its five siblings on this surface all used
// `restoreOpBlocked()`, which consults both; this one was missed. Observed live 2026-08-21 22:35:
// `RestoreStatus().Running == true` while `IsRunning() == false`, and the delete of the copy the
// restore was writing into went through.
//
// It now refuses while ANY backup or restore op is running.
func (s *Server) offboxVerifyCopyDeleteHandler(w http.ResponseWriter, r *http.Request) {
if s.backupMgr == nil {
offboxRedirectTo(w, r, "/backups/restore", "A mentéskezelő nem érhető el.", true)
@@ -526,8 +548,13 @@ func (s *Server) offboxVerifyCopyDeleteHandler(w http.ResponseWriter, r *http.Re
offboxRedirectTo(w, r, "/backups/restore", "A törlés megerősítés nélkül nem hajtható végre.", true)
return
}
if s.backupMgr.IsRunning() {
offboxRedirectTo(w, r, "/backups/restore", "Egy mentési/visszaállítási művelet fut — a törlés most nem biztonságos.", true)
// R-360: `restoreOpBlocked()` and not `IsRunning()`. No app-name comparison is added deliberately:
// refusing during ANY restore is strictly stronger than refusing only for the restoring app, and it
// is the rule the other five handlers on this surface already follow. Uniformity is worth more than
// precision here — the defect was one handler being different.
if msg, blocked := s.restoreOpBlocked(); blocked {
s.logger.Printf("[WARN] [web] verification-copy delete refused for %s: a backup/restore op is running", stack)
offboxRedirectTo(w, r, "/backups/restore", msg, true)
return
}
if err := s.backupMgr.DeleteOffsiteRestoreCopy(stack); err != nil {
@@ -556,6 +583,14 @@ func (s *Server) offboxPlaceHandler(w http.ResponseWriter, r *http.Request) {
offboxRedirectTo(w, r, restoreWizardPath(app), msg, true)
return
}
// R-358: refuse SERVER-SIDE over an incomplete scratch. The wizard already hides the button when
// PlaceEnabled is false — and a hidden button is not a guard. This handler is reachable by a POST,
// and before v0.226.0 a POST over a failed download was accepted and reported success.
if !s.backupMgr.OffboxFullScratchReady(app) {
s.logger.Printf("[WARN] [web] off-box place refused for %s: the restore scratch carries no completion marker", app)
offboxRedirectTo(w, r, restoreWizardPath(app), offsiteScratchIncompleteMsg, true)
return
}
s.backupMgr.BeginRestoreOp("offbox-place", app)
go func() {
ctx, cancel := context.WithTimeout(context.Background(), 30*time.Minute)