|
@@ -748,7 +748,14 @@ class QtCleanService:
|
|
|
tail = await self.bench.read_event_queue(0, sid, 1)
|
|
tail = await self.bench.read_event_queue(0, sid, 1)
|
|
|
record = {"state": "starting", "started_unix_ms": 0, "boot_id": "", "error_cursor": tail["latest_sequence"]}
|
|
record = {"state": "starting", "started_unix_ms": 0, "boot_id": "", "error_cursor": tail["latest_sequence"]}
|
|
|
self.records[sid] = record
|
|
self.records[sid] = record
|
|
|
- self.stage_intents[sid] = default_stage_intents()
|
|
|
|
|
|
|
+ prior_intents = self.stage_intents.get(sid, {})
|
|
|
|
|
+ fresh_intents = default_stage_intents()
|
|
|
|
|
+ for key, slot in prior_intents.items():
|
|
|
|
|
+ if slot.get("pending") and not slot.get("consumed"):
|
|
|
|
|
+ preserved = copy.deepcopy(slot)
|
|
|
|
|
+ preserved.pop("wait_for_boot_after", None)
|
|
|
|
|
+ fresh_intents[key] = preserved
|
|
|
|
|
+ self.stage_intents[sid] = fresh_intents
|
|
|
self.auto_dispatched = {k for k in self.auto_dispatched if k[0] != sid}
|
|
self.auto_dispatched = {k for k in self.auto_dispatched if k[0] != sid}
|
|
|
rt.diagnostic_operation = True
|
|
rt.diagnostic_operation = True
|
|
|
try:
|
|
try:
|
|
@@ -785,6 +792,8 @@ class QtCleanService:
|
|
|
if (fw["boot_id"] and fw["boot_id"] != old_boot and not fw["boot_pending"] and
|
|
if (fw["boot_id"] and fw["boot_id"] != old_boot and not fw["boot_pending"] and
|
|
|
fw["boot_started_unix_ms"] >= requested_at and interactive):
|
|
fw["boot_started_unix_ms"] >= requested_at and interactive):
|
|
|
record.update(state="running", boot_id=fw["boot_id"], started_unix_ms=fw["boot_started_unix_ms"])
|
|
record.update(state="running", boot_id=fw["boot_id"], started_unix_ms=fw["boot_started_unix_ms"])
|
|
|
|
|
+ if any(slot.get("pending") for slot in self.stage_intents.get(sid, {}).values()):
|
|
|
|
|
+ self._ensure_intent_watcher(sid)
|
|
|
await self._note(rt, "新的 BIOS 已进入可交互阶段;开始按 Qt 本地计划处理阶段输入。")
|
|
await self._note(rt, "新的 BIOS 已进入可交互阶段;开始按 Qt 本地计划处理阶段输入。")
|
|
|
return {"power_action": action, "previous_power": previous, "previous_boot_id": old_boot,
|
|
return {"power_action": action, "previous_power": previous, "previous_boot_id": old_boot,
|
|
|
"boot_id": fw["boot_id"], "boot_observed": True,
|
|
"boot_id": fw["boot_id"], "boot_observed": True,
|
|
@@ -893,6 +902,9 @@ class QtCleanService:
|
|
|
rt = self._runtime(sid)
|
|
rt = self._runtime(sid)
|
|
|
if rt.diagnostic_operation or self.bench.closing:
|
|
if rt.diagnostic_operation or self.bench.closing:
|
|
|
return
|
|
return
|
|
|
|
|
+ rec_state = self.records.get(sid, {}).get("state", "idle")
|
|
|
|
|
+ if rec_state in ("starting", "failed", "completed"):
|
|
|
|
|
+ return
|
|
|
if sid in self.last_commands:
|
|
if sid in self.last_commands:
|
|
|
last_item = await self.bench.get_queue_item(self.last_commands[sid])
|
|
last_item = await self.bench.get_queue_item(self.last_commands[sid])
|
|
|
if last_item["state"] not in ("succeeded", "failed", "interrupted"):
|
|
if last_item["state"] not in ("succeeded", "failed", "interrupted"):
|
|
@@ -902,6 +914,11 @@ class QtCleanService:
|
|
|
if not point["ready"]:
|
|
if not point["ready"]:
|
|
|
return
|
|
return
|
|
|
intents = self.stage_intents.setdefault(sid, default_stage_intents())
|
|
intents = self.stage_intents.setdefault(sid, default_stage_intents())
|
|
|
|
|
+ cur_boot = fw.get("boot_id", "")
|
|
|
|
|
+ for slot in intents.values():
|
|
|
|
|
+ wait_boot = slot.get("wait_for_boot_after")
|
|
|
|
|
+ if wait_boot and (wait_boot == "__pre_start__" or cur_boot == wait_boot):
|
|
|
|
|
+ return
|
|
|
stage = point["stage"]
|
|
stage = point["stage"]
|
|
|
if stage != "uip1" and intents["uip1"]["pending"] and STAGE_ORDER.get(stage, 0) > 1:
|
|
if stage != "uip1" and intents["uip1"]["pending"] and STAGE_ORDER.get(stage, 0) > 1:
|
|
|
intents["uip1"]["pending"] = False
|
|
intents["uip1"]["pending"] = False
|
|
@@ -938,7 +955,7 @@ class QtCleanService:
|
|
|
"arguments": {"input_id": point["id"], "action": act, "amt": amt_cfg, "run_amt": slot["run_amt"]},
|
|
"arguments": {"input_id": point["id"], "action": act, "amt": amt_cfg, "run_amt": slot["run_amt"]},
|
|
|
})
|
|
})
|
|
|
self.last_commands[sid] = cmd_id
|
|
self.last_commands[sid] = cmd_id
|
|
|
- elif stage == "uip2" and (intents["amt"]["consumed"] or intents["mt"]["pending"]):
|
|
|
|
|
|
|
+ elif stage == "uip2" and (intents["amt"]["consumed"] or intents["mt"]["pending"] or intents["uip1"]["consumed"]):
|
|
|
key = (sid, point["id"], "continue_uip", 0)
|
|
key = (sid, point["id"], "continue_uip", 0)
|
|
|
if key not in self.auto_dispatched:
|
|
if key not in self.auto_dispatched:
|
|
|
self.auto_dispatched.add(key)
|
|
self.auto_dispatched.add(key)
|
|
@@ -972,6 +989,8 @@ class QtCleanService:
|
|
|
input_id = request.get("input_id", "")
|
|
input_id = request.get("input_id", "")
|
|
|
intents = self.stage_intents.setdefault(sid, default_stage_intents())
|
|
intents = self.stage_intents.setdefault(sid, default_stage_intents())
|
|
|
target_key = stage_target_for_action(action)
|
|
target_key = stage_target_for_action(action)
|
|
|
|
|
+ record = self.records.get(sid, {})
|
|
|
|
|
+ rec_state = record.get("state", "idle")
|
|
|
if point["stage"] == "amt" and request.get("run_amt") is False and action == "start_amt":
|
|
if point["stage"] == "amt" and request.get("run_amt") is False and action == "start_amt":
|
|
|
action = "skip_amt"
|
|
action = "skip_amt"
|
|
|
valid_token = (
|
|
valid_token = (
|
|
@@ -980,20 +999,31 @@ class QtCleanService:
|
|
|
or (point["stage"] == "uefi" and input_id in self.uefi_tokens.get(node, set()))
|
|
or (point["stage"] == "uefi" and input_id in self.uefi_tokens.get(node, set()))
|
|
|
)
|
|
)
|
|
|
at_prompt = bool(point["ready"] and valid_token and action in point["actions"])
|
|
at_prompt = bool(point["ready"] and valid_token and action in point["actions"])
|
|
|
|
|
+ if not input_id and rec_state in ("completed", "failed"):
|
|
|
|
|
+ at_prompt = False
|
|
|
if not at_prompt and target_key in ("uip1", "amt", "mt"):
|
|
if not at_prompt and target_key in ("uip1", "amt", "mt"):
|
|
|
- record = self.records.get(sid, {})
|
|
|
|
|
- boot_id = record.get("boot_id") or fw.get("boot_id", "")
|
|
|
|
|
stale_boot_token = bool(input_id and input_id != point.get("id", ""))
|
|
stale_boot_token = bool(input_id and input_id != point.get("id", ""))
|
|
|
- cur_stage = point["stage"] if point["ready"] else (
|
|
|
|
|
- "starting" if record.get("state") == "starting" else fw.get("observed_phase", "boot"))
|
|
|
|
|
- cur_order = STAGE_ORDER.get(cur_stage, 0)
|
|
|
|
|
|
|
+ observed_stage = point["stage"] if point["ready"] else fw.get("observed_phase", "boot")
|
|
|
|
|
+ observed_order = STAGE_ORDER.get(observed_stage, 0)
|
|
|
target_order = {"uip1": 1, "amt": 3, "mt": 5}[target_key]
|
|
target_order = {"uip1": 1, "amt": 3, "mt": 5}[target_key]
|
|
|
|
|
+ pre_start = rec_state in ("idle", "completed", "failed")
|
|
|
|
|
+ cur_order = 0 if pre_start else (0 if rec_state == "starting" else observed_order)
|
|
|
|
|
+ if pre_start and intents[target_key]["consumed"]:
|
|
|
|
|
+ intents[target_key]["consumed"] = False
|
|
|
if not stale_boot_token and cur_order < target_order and not intents[target_key]["consumed"]:
|
|
if not stale_boot_token and cur_order < target_order and not intents[target_key]["consumed"]:
|
|
|
slot = apply_stage_intent_overwrite(intents, target_key, request)
|
|
slot = apply_stage_intent_overwrite(intents, target_key, request)
|
|
|
|
|
+ if pre_start and (rec_state in ("completed", "failed") or observed_order >= target_order):
|
|
|
|
|
+ slot["wait_for_boot_after"] = fw.get("boot_id", "") or "__pre_start__"
|
|
|
if target_key != "amt" and request.get("run_amt") is not None and cur_order < 3:
|
|
if target_key != "amt" and request.get("run_amt") is not None and cur_order < 3:
|
|
|
- apply_stage_intent_overwrite(intents, "amt", {**request, "action": "start_amt" if request["run_amt"] else "skip_amt"})
|
|
|
|
|
|
|
+ intents["amt"]["consumed"] = False if pre_start else intents["amt"]["consumed"]
|
|
|
|
|
+ amt_slot = apply_stage_intent_overwrite(intents, "amt", {**request, "action": "start_amt" if request["run_amt"] else "skip_amt"})
|
|
|
|
|
+ if pre_start and (rec_state in ("completed", "failed") or observed_order >= 3):
|
|
|
|
|
+ amt_slot["wait_for_boot_after"] = fw.get("boot_id", "") or "__pre_start__"
|
|
|
if target_key != "mt" and request.get("run_mt") is not None and cur_order < 5:
|
|
if target_key != "mt" and request.get("run_mt") is not None and cur_order < 5:
|
|
|
- apply_stage_intent_overwrite(intents, "mt", {**request, "action": "start_mt" if request["run_mt"] else "skip_mt"})
|
|
|
|
|
|
|
+ intents["mt"]["consumed"] = False if pre_start else intents["mt"]["consumed"]
|
|
|
|
|
+ mt_slot = apply_stage_intent_overwrite(intents, "mt", {**request, "action": "start_mt" if request["run_mt"] else "skip_mt"})
|
|
|
|
|
+ if pre_start and (rec_state in ("completed", "failed") or observed_order >= 5):
|
|
|
|
|
+ mt_slot["wait_for_boot_after"] = fw.get("boot_id", "") or "__pre_start__"
|
|
|
self._ensure_intent_watcher(sid)
|
|
self._ensure_intent_watcher(sid)
|
|
|
enabled_val = slot.get("run_amt" if target_key == "amt" else "run_mt" if target_key == "mt" else "run_rmt")
|
|
enabled_val = slot.get("run_amt" if target_key == "amt" else "run_mt" if target_key == "mt" else "run_rmt")
|
|
|
await self._note(rt, f"阶段 {target_key} 意图已预置/覆盖(revision={slot['revision']}),到达阶段后自动执行。")
|
|
await self._note(rt, f"阶段 {target_key} 意图已预置/覆盖(revision={slot['revision']}),到达阶段后自动执行。")
|