fix: defer automatic uploads while device synchronization is pending
Community checks / verify (push) Skipped
Verify Frame Flow / verify (push) Successful in 5m30s

This commit is contained in:
渡口浪人
2026-10-18 20:21:52 +08:00
parent 50bb41899d
commit a2e8a204e8
11 changed files with 202 additions and 33 deletions
+25 -5
View File
@@ -174,7 +174,7 @@ class DisplayService:
if result:
row = self.db.one("SELECT result FROM operations WHERE id=?", (id,))
previous = json.loads(row["result"]) if row and row["result"] else {}
for key in ("photo_attempts", "upload_intent"):
for key in ("photo_attempts", "upload_intent", "sync_observations"):
if key in previous:
result = {**result, key: previous[key]}
self.db.execute(
@@ -519,6 +519,23 @@ class DisplayService:
continue
payload = json.loads(op["payload"])
if op["action"] == "display":
if op["client_id"] in (
"scheduler",
"scheduler-retry",
) and self.db.one(
"SELECT id FROM operations WHERE device_id=? AND action='display' "
"AND status='SYNCING' AND write_started=1 AND updated_at>? LIMIT 1",
(
op["device_id"],
(
datetime.now(UTC)
- timedelta(seconds=self.settings.sync_timeout)
).isoformat(),
),
):
# Upload activates a new image upstream. Give the prior
# image its existing confirmation window before replacing it.
continue
priority = payload["options"]["priority"]
top = self.top(op["device_id"])
if top and priority < top["priority"]:
@@ -823,6 +840,7 @@ class DisplayService:
try:
driver = self.registry.get(op["device_id"])
device = driver.device(refresh=True)
self.recovery.observe_device(op, device=device)
if intent:
expected = self.upload_reconciliation.check(op, driver, device)
if (
@@ -850,7 +868,8 @@ class DisplayService:
if device.current_content.id == expected
else "target_mismatch",
)
except FlowError:
except FlowError as exc:
self.recovery.observe_device(op, error=exc)
self.recovery.observe(op, "read_unavailable")
except Exception:
# Bad vendor metadata for one operation must not stop the worker.
@@ -858,6 +877,7 @@ class DisplayService:
for op in self.db.all("SELECT * FROM operations WHERE status='SYNCING'"):
try:
device = self.registry.get(op["device_id"]).device()
observation = self.recovery.observe_device(op, device=device)
target = json.loads(op["result"])["image_id"]
if (
device.current_content.id == target
@@ -878,11 +898,11 @@ class DisplayService:
"code": E.WRITE_RESULT_UNKNOWN,
"message": "Frame refresh was not confirmed",
"request_id": op["request_id"],
"details": {},
"details": {"last_device_observation": observation},
},
)
except FlowError:
pass
except FlowError as exc:
self.recovery.observe_device(op, error=exc)
self.recovery.close_superseded_displays()