controller (unreleased): a step of the host's clock is not a new boot (R-1395)
The boot pass decides through guestBootVerdict and prefers the agent's new guest_boot_key (kernel boot_id), which a clock step cannot move. An agent that sends no key gets the old rule. The move to the key recreates nothing. Claude-Session: https://claude.ai/code/session_0159rPz1ZhFKsS53msqPYxtS
This commit is contained in:
1 parent
df0990f3aa
commit
95ed6314cc
4 files changed
+167
-9
No files matched your search
@@ -395,6 +395,36 @@ func (s *Server) driveGateLoop() {
|
||||
}
|
||||
}
|
||||
|
||||
// guestBootVerdict decides „is this a new boot of the guest?” from the persisted record and the agent's two tokens
|
||||
// (R-1395). `oldTok` is guest_boot_id = "<host boot TIME>-<guest init start>"; the kernel computes the boot time from
|
||||
// the wall clock, so a STEP of the host's clock moved it and the controller recreated every drive-backed app (the
|
||||
// N100, 2026-11-14: +32.7 s, three apps down for seconds). `key` is guest_boot_key = "<kernel boot_id>-<guest init
|
||||
// start>", which a clock step cannot move; "" from an agent that does not send it.
|
||||
//
|
||||
// - no key (older agent): the old rule — a non-empty token that differs from the record is a new boot.
|
||||
// - key equals the record: same boot, whatever the old token says. THIS is the fix.
|
||||
// - the record still holds the OLD token and it equals the old token now: same boot — and the record moves to the
|
||||
// key (changed=false, persist=key), so the move itself recreates nothing.
|
||||
// - anything else: a new boot; the record becomes the key.
|
||||
//
|
||||
// persist is the value to write: after the recreate pass when changed, at once when only the record moves.
|
||||
// Pinned by TestGuestBootVerdict_*.
|
||||
func guestBootVerdict(last, oldTok, key string) (changed bool, persist string) {
|
||||
if key == "" {
|
||||
if oldTok == "" || oldTok == last {
|
||||
return false, ""
|
||||
}
|
||||
return true, oldTok
|
||||
}
|
||||
if key == last {
|
||||
return false, ""
|
||||
}
|
||||
if last != "" && oldTok != "" && oldTok == last {
|
||||
return false, key
|
||||
}
|
||||
return true, key
|
||||
}
|
||||
|
||||
// processGuestBootChange converges a GUEST REBOOT DETERMINISTICALLY. On a guest reboot docker auto-starts
|
||||
// the app containers (restart:unless-stopped) BEFORE the agent re-propagates the drive under the parent
|
||||
// (~18s later) — so the create-time bind of an app's volume fails (`mkdir …/userdata: permission denied`
|
||||
@@ -428,9 +458,21 @@ func (s *Server) processGuestBootChange() {
|
||||
if derr != nil {
|
||||
return
|
||||
}
|
||||
if resp.GuestBootID == "" || resp.GuestBootID == s.settings.GetLastGuestBootID() {
|
||||
return // no boot-id, or unchanged (controller-only restart) → no recreate
|
||||
last := s.settings.GetLastGuestBootID()
|
||||
changed, persist := guestBootVerdict(last, resp.GuestBootID, resp.GuestBootKey)
|
||||
if !changed {
|
||||
if persist != "" && persist != last {
|
||||
// R-1395: the first report with the clock-proof key, and the old token says „same boot” — take the key
|
||||
// as the record from now on. No app is touched.
|
||||
if serr := s.settings.SetLastGuestBootID(persist); serr != nil {
|
||||
s.logger.Printf("[WARN] [gate] persist boot key: %v", serr)
|
||||
} else {
|
||||
s.logger.Printf("[INFO] [gate] boot record moved to the kernel's boot key (same boot; no app recreated)")
|
||||
}
|
||||
}
|
||||
return // no token, or unchanged (controller-only restart) → no recreate
|
||||
}
|
||||
bootID := persist // the token of THIS boot, logged and persisted below
|
||||
|
||||
// Distinct stable drive paths that deployed drive-backed apps depend on (HDD_PATH is the drive root).
|
||||
needed := map[string]bool{}
|
||||
@@ -445,7 +487,7 @@ func (s *Server) processGuestBootChange() {
|
||||
}
|
||||
}
|
||||
if len(needed) == 0 {
|
||||
if serr := s.settings.SetLastGuestBootID(resp.GuestBootID); serr != nil {
|
||||
if serr := s.settings.SetLastGuestBootID(bootID); serr != nil {
|
||||
s.logger.Printf("[WARN] [gate] persist boot-id: %v", serr)
|
||||
}
|
||||
return
|
||||
@@ -456,7 +498,7 @@ func (s *Server) processGuestBootChange() {
|
||||
}
|
||||
|
||||
// READINESS GATE (the fix): wait for the REAL live in-guest bind, not the once-sampled agent view.
|
||||
s.logger.Printf("[INFO] [gate] boot %s: waiting (≤%s) for live drive bind(s) %v before recreating drive-backed apps", resp.GuestBootID, bootBindWait, paths)
|
||||
s.logger.Printf("[INFO] [gate] boot %s: waiting (≤%s) for live drive bind(s) %v before recreating drive-backed apps", bootID, bootBindWait, paths)
|
||||
presentStable := pollLiveBinds(paths, driveBindLive, time.Sleep, time.Now, bootBindWait, bootBindPoll)
|
||||
|
||||
var bootStacks []bootStack
|
||||
@@ -475,7 +517,7 @@ func (s *Server) processGuestBootChange() {
|
||||
})
|
||||
}
|
||||
recreate := func(bs bootStack) {
|
||||
s.logger.Printf("[INFO] [gate] boot %s: live bind confirmed — recreating drive-backed app %s (state=%s) onto %s", resp.GuestBootID, bs.name, bs.state, bs.hdd)
|
||||
s.logger.Printf("[INFO] [gate] boot %s: live bind confirmed — recreating drive-backed app %s (state=%s) onto %s", bootID, bs.name, bs.state, bs.hdd)
|
||||
// R-1251: a cut restore whose copy waited for THIS drive is poured back first — the recreate used to start
|
||||
// the app on the cut restore's data, and a later start poured the old copy over what the household wrote.
|
||||
if !s.resumePutBack(bs.name) || s.appHeld(bs.name) {
|
||||
@@ -487,19 +529,19 @@ func (s *Server) processGuestBootChange() {
|
||||
}
|
||||
}
|
||||
syncFB := func() {
|
||||
s.logger.Printf("[INFO] [gate] boot %s: re-syncing FileBrowser mounts against the live binds", resp.GuestBootID)
|
||||
s.logger.Printf("[INFO] [gate] boot %s: re-syncing FileBrowser mounts against the live binds", bootID)
|
||||
go s.SyncFileBrowserMounts()
|
||||
}
|
||||
_, skipped, leftStopped := recreateDriveBackedApps(bootStacks, presentStable, recreate, syncFB)
|
||||
if skipped > 0 {
|
||||
s.logger.Printf("[WARN] [gate] boot %s: %d drive-backed app(s) had no live bind within %s — leaving to the drive gate", resp.GuestBootID, skipped, bootBindWait)
|
||||
s.logger.Printf("[WARN] [gate] boot %s: %d drive-backed app(s) had no live bind within %s — leaving to the drive gate", bootID, skipped, bootBindWait)
|
||||
}
|
||||
if leftStopped > 0 {
|
||||
// INFO, not WARN: this is the gate working as intended (R-55). Make the honoured path
|
||||
// observable — a silent correct path is how an inert seam hides.
|
||||
s.logger.Printf("[INFO] [gate] boot %s: %d drive-backed app(s) left stopped on purpose (recorded Stop, or a legacy app.yaml at zero containers)", resp.GuestBootID, leftStopped)
|
||||
s.logger.Printf("[INFO] [gate] boot %s: %d drive-backed app(s) left stopped on purpose (recorded Stop, or a legacy app.yaml at zero containers)", bootID, leftStopped)
|
||||
}
|
||||
if serr := s.settings.SetLastGuestBootID(resp.GuestBootID); serr != nil {
|
||||
if serr := s.settings.SetLastGuestBootID(bootID); serr != nil {
|
||||
s.logger.Printf("[WARN] [gate] persist boot-id: %v", serr)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user