دسکتاپ، Worker و محاسبات محلی · فصل ۵ — Reconciliation، Rollout و Watchdog · 191
Backup/Restore Smoke and Independent Watchdog
Design a recovery evidence pack that binds backups to source/version/digest metadata, performs an isolated restore smoke with integrity and application-level checks, and combines it with an independent watchdog contract whose missed heartbeat, restart budget and escalation path remain auditable. Treat backup creation, restore proof and watchdog recovery as separate claims. میتواند «Backup/Restore Smoke و Independent Watchdog» را برای یک node محلی با identity، state، privilege و recovery boundary مناسب طراحی کند.
Lesson summary
Design a recovery evidence pack that binds backups to source/version/digest metadata, performs an isolated restore smoke with integrity and application-level checks, and combines it with an independent watchdog contract whose missed heartbeat, restart budget and escalation path remain auditable. Treat backup creation, restore proof and watchdog recovery as separate claims.
میتواند «Backup/Restore Smoke و Independent Watchdog» را برای یک node محلی با identity، state، privilege و recovery boundary مناسب طراحی کند.
This lesson produces
میتواند «Backup/Restore Smoke و Independent Watchdog» را برای یک node محلی با identity، state، privilege و recovery boundary مناسب طراحی کند.
Who it is for
Foundation
Use a guided lesson-specific evidence matrix and one worked negative case.
Repair
Re-run only the failed owned dimension with a smaller deterministic synthetic fixture.
Experienced
Start from mixed authority/policy/evidence records; require explicit trade-offs and provenance.
Prerequisites
1. A backup file is not recovery readiness
A backup artifact proves only that something was stored. Recovery readiness requires a backup bound to a known source generation and digest, an isolated restore, structural and application-level checks, and auditable outcomes. Liveness also needs supervision outside the workload being supervised.
2. LOC-018 ownership boundary
This lesson owns only the Backup/Restore Smoke and Independent Watchdog evidence contract. Routine drift reconciliation belongs to LOC-016 and progressive rollout belongs to LOC-017. A valid restore does not prove watchdog detection, and a restart does not prove restored-data correctness.
3. Bind the backup to source content
Record at least backup_id, source_generation, source_digest, backup_created_at, and backup_digest. A filename or file-existence check is not enough. Without source generation or digest, the backup cannot be tied confidently to a particular source state.
4. What SQLite Online Backup proves
The SQLite Online Backup API copies database content into another database and can operate incrementally so the source need not remain locked for the entire copy. That mechanism can create a useful snapshot, but API completion alone does not prove application-level restore correctness.
5. Restore smoke must be isolated
Restore into a separate target so the recovery exercise does not overwrite live state. Record restore_target, start/completion timestamps, and isolation_confirmed. Restoring into the live path turns a smoke test into a destructive operation and weakens the evidence boundary.
6. Integrity check is one proof layer
PRAGMA integrity_check performs low-level SQLite consistency checks and returns ok when it finds no errors. Foreign-key errors require the separate foreign_key_check. Even an ok result does not prove business invariants or application behavior.
7. Run an application smoke after structural checks
After restore, evaluate at least one observable invariant such as required schema, a bounded record count, or a known state marker. Record application_smoke_result and expected_invariant. If the invariant fails, the outcome is RESTORE_FAILED even when integrity_check returned ok.
8. Re-bind restored content with digests
Connect source, backup, and restored artifacts with content evidence. source_digest, backup_digest, and optionally restored_digest expose corruption or artifact mix-ups. A file can keep the same filename after corruption; the name is not proof.
9. The watchdog decision must live outside the workload
A heartbeat generated and interpreted only by the workload is not independent supervision. watchdog_owner must represent an external supervisor, such as a service manager. The workload must not both fail and control the evidence that declares itself healthy.
10. WatchdogSec and the heartbeat deadline
With systemd, WatchdogSec defines the watchdog deadline and the service sends WATCHDOG=1 keep-alives. Missing the deadline must produce an auditable event. Process existence or a responsive UI is insufficient because an event loop can be wedged while the process still exists.
11. Restart budget must be finite
Automatic restart without a bound can create an endless failure loop. Record restart_count and restart_budget. A restart may be allowed while budget remains; after exhaustion, the state must become WATCHDOG_EXHAUSTED or escalate rather than retry forever.
12. Post-restart readiness is an independent gate
Process restart is not recovery success. Run readiness or an application probe again. If post_restart_readiness=false, do not emit RECOVERED; escalate or halt explicitly.
13. Worked example: valid backup, missed heartbeat
A node has a content-bound backup and the isolated restore passes every check. Later, the worker misses its heartbeat; an independent supervisor restarts it while budget remains, and post-restart readiness passes. The evidence pack now has two separate claims: RESTORE_PROVEN for data and RECOVERED for the watchdog path.
14. Deterministic failure probes
Test four mutations: corrupt one restored page while keeping the same filename; return integrity_check ok while the application invariant fails; keep the process alive while heartbeat exceeds the deadline; exhaust restart budget while readiness remains false. Every mutation must produce a typed state and auditable reason.
15. Transfer: Windows instead of systemd
In transfer, change the data directory and replace systemd with Windows service failure actions. Preserve the contract: content-bound backup, isolated restore, structural and application checks, independent supervisor, deadline, restart budget, post-restart readiness, and escalation. Platform mechanism changes; evidence requirements do not.
Assessment
There is no answer key in this lesson pack; answer it yourself and mark honestly. "Needs review" sends the lesson to your review queue.
F1 retrieval
F2 diagnosis
S1 application
S2 diagnosis
S3 decision
S4 transfer
Assessment rubric
| Dimension | Sufficient evidence | Blocking failure |
|---|---|---|
| Backup binding | source generation and digest link the backup to a source state | filename/existence is treated as proof |
| Restore proof | isolated restore + integrity + FK + application invariant are visible | structural check substitutes for application smoke |
| Watchdog independence | supervisor is outside workload and heartbeat deadline is explicit | workload self-reports and self-judges health |
| Finite recovery | restart budget, readiness and escalation are explicit | infinite retry or restart=success |
| Transfer | Windows mechanism changes while evidence contract is recomputed | Linux-specific result is copied as an oracle |
References & freshness
Case studies
Lesson visuals
Lab files
Use only the supplied synthetic records. Implement evaluate(case) in starter.py. Keep backup/restore evidence separate from watchdog evidence, fail closed on missing decisive evidence, require an independent supervisor, enforce a finite restart budget, and never equate process restart with readiness.
Run python run_checks.py. The learner checker validates output shape and safety boundaries only; expected decision labels and reference logic are kept outside learner-publishable paths.