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
+76 -3
View File
@@ -1470,17 +1470,90 @@ func (s *Server) backupRestoreHandler(w http.ResponseWriter, r *http.Request) {
start := time.Now()
// Phase 2b: restore from the app's recovery unit (recovers secrets from the guest, fail-closed
// on an unrecoverable data-encrypting key; falls back to volume-only restore if no unit exists).
if err := s.backupMgr.RestoreFromRecoveryUnit(stackName); err != nil {
res, err := s.backupMgr.RestoreFromRecoveryUnit(stackName)
if err != nil {
s.logger.Printf("[ERROR] [web] Restore failed (async): stack=%s: %v", stackName, err)
s.backupMgr.EndRestoreOp(false, "Visszaállítás sikertelen: "+err.Error())
return
}
s.logger.Printf("[INFO] [web] Restore completed (async): stack=%s in %s", stackName, time.Since(start))
s.backupMgr.EndRestoreOp(true, stackName+" visszaállítva ("+snapshotID+").")
s.logger.Printf("[INFO] [web] Restore completed (async): stack=%s in %s (volumes %d/%d, dbs %d/%d)",
stackName, time.Since(start), res.VolumesReplayed, res.ManifestVolumes, res.DBsReplayed, res.ManifestDBs)
// R-353: this used to read `stackName+" visszaállítva ("+snapshotID+")."` — a sentence that is
// true of a run which returned an app's entire dataset AND of one that returned nothing at all.
// The customer reads it as "my data is back". The snapshot id is dropped from the sentence
// deliberately: it identified WHICH backup ran and told the customer nothing about what came out
// of it, which is the question the sentence exists to answer.
s.backupMgr.EndRestoreOp(true, unitRestoreOutcomeMsg(stackName, res))
}()
http.Redirect(w, r, "/backups/restore?flash="+url.QueryEscape("Visszaállítás elindult — az állapot itt frissül."), http.StatusFound)
}
// unitRestoreOutcomeMsg builds the OUTCOME sentence for a completed LOCAL recovery-unit restore. Pure,
// so the wording is unit-testable — this string is the customer's only evidence that the operation did
// what its label promised.
//
// R-353. Modelled on reconstituteOutcomeMsg (the off-site twin), and it is the same defect arriving on
// the Tier-1 path: on 2026-08-21 an opengist restore reported „opengist visszaállítva (<snapshot>)."
// over a unit that held manifest.json and compose/ and nothing else. Every clause below is earned by
// having done the thing, so a restore that really returned data reads exactly as confidently as before.
//
// THE THREE CASES ARE THREE DIFFERENT FACTS, and collapsing any two is the whole bug:
//
// - something came back → name what, and how much.
// - nothing came back AND the unit listed nothing → the BACKUP held only settings. This is a claim
// about the backup, and it is the only claim the manifest can support.
// - nothing came back BUT the unit listed dumps → something is wrong. The customer's live data was
// never removed (the volume replay only ever writes), so say that, and stop them retrying blind.
//
// R-355 IS THE RULE THIS OBEYS AND THE REASON THE MIDDLE CASE IS WORDED AS IT IS. „ennek az
// alkalmazásnak nincs adata" is a claim ABOUT THE APP and must never be inferred from a counter. On the
// off-site path SafetyDump is the honest discriminator for the database question; this path has none,
// so no claim about the app is available here at all. 07-backup-architecture §6.3 is why that is not
// pedantry: R-361 destroyed apps' canonical .sql dumps for four months, so an absent dump has causes
// that have nothing to do with whether the app has a database.
//
// No filesystem path appears in the message, only counts — same rule as reconstituteOutcomeMsg.
func unitRestoreOutcomeMsg(app string, res backup.UnitRestoreResult) string {
if res.VolumesReplayed > 0 || res.DBsReplayed > 0 {
var what string
if res.VolumesReplayed > 0 {
what = fmt.Sprintf("%d adatkötet", res.VolumesReplayed)
}
if res.DBsReplayed > 0 {
if what != "" {
what += " és az adatbázis"
} else {
what = "az adatbázis"
}
}
return fmt.Sprintf(unitRestoreDataMsgFmt, app, what)
}
if res.ManifestVolumes+res.ManifestDBs > 0 {
return fmt.Sprintf(unitRestoreNoneReturnedMsgFmt, app, res.ManifestVolumes, res.ManifestDBs)
}
return fmt.Sprintf(unitRestoreSettingsOnlyMsgFmt, app)
}
// R-353 customer-facing strings. Named constants, not inlined, because each is asserted verbatim by
// r353_unit_outcome_test.go — a silent edit to any of them is how an honest message drifts back into a
// comforting one, which is the exact history of the sentence they replace.
const (
// unitRestoreDataMsgFmt — data really came back. %s app, %s the "N adatkötet[ és az adatbázis]"
// clause built above.
unitRestoreDataMsgFmt = "A(z) %s: %s visszaállítva — az alkalmazás újraindult."
// unitRestoreSettingsOnlyMsgFmt — nothing came back and the unit listed nothing. The FIGYELEM
// sentence is a statement about THE BACKUP; it deliberately says nothing about whether the app has
// data of its own, because the manifest cannot answer that (R-355).
unitRestoreSettingsOnlyMsgFmt = "A(z) %s: a beállítások visszaálltak — az alkalmazás újraindult. FIGYELEM: ez a mentés csak a beállításokat tartalmazta, adatot nem. Az alkalmazás adatai NEM álltak vissza ebből a mentésből."
// unitRestoreNoneReturnedMsgFmt — the unit listed data and none of it returned. %d volumes, %d
// database dumps LISTED. It states the data is unchanged because that is true and load-bearing: the
// replay only ever writes into volumes, so a replay that did nothing removed nothing, and a customer
// who believes otherwise will do something worse than waiting.
unitRestoreNoneReturnedMsgFmt = "A(z) %s: FIGYELEM — a mentés %d adatkötetet és %d adatbázis-mentést sorol fel, de egyik sem állt vissza. Az adataid változatlanok maradtak. Kérj segítséget, mielőtt újra próbálod."
)
// C9-F1 customer-facing strings. Kept as named constants, not inlined, because both are asserted
// verbatim by tests — a silent edit to either is the way an honest message drifts back into a
// comforting one.