Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 30 additions & 1 deletion tasks/GameUi/navigator.py
Original file line number Diff line number Diff line change
Expand Up @@ -476,9 +476,12 @@ def _refresh_current_page(self, destination: Page, skip_first_screenshot: bool)
context="goto_page",
)

def _wait_for_destination(self, destination: Page, timeout: float = 4.0) -> bool:
def _wait_for_destination(self, destination: Page, timeout: float = 15.0) -> bool:
"""等待下一页面稳定出现。

过图加载期间任何已知页面都识别不到,此时继续等而不是直接判失败;
只有确认落到了别的已知页才提前返回失败,避免加载慢被误判成跳转失败。

Args:
destination: 目标页面。
timeout: 等待超时时间。
Expand All @@ -488,10 +491,20 @@ def _wait_for_destination(self, destination: Page, timeout: float = 4.0) -> bool
"""

timer = Timer(timeout).start()
last_probe = 0.0
while not timer.reached():
if self.confirm_page(destination, skip_first_screenshot=False):
self.navigator.current_page = destination
return True
now = time.time()
if now - last_probe >= 3.0:
last_probe = now
landed = self._detect_current_page(
skip_first_screenshot=True,
categories=self._navigation_detect_categories(destination),
)
if landed is not None and landed.key != destination.key:
Comment on lines +494 to +506

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟠 高 · 成功的页面转换受到惩罚

执行转换操作后、目标页面出现前,如果源页面仍可识别,_wait_for_destination 会将源页面视为一次失败的探测并返回 False。因此,目标页面还没来得及出现,_execute_transition 就会记录一次失败的转换并施加惩罚。

如果检测到的页面仍是转换源页面,请继续轮询;只有目标页面等待超时后才判定失败。

给 AI 智能体的提示
在 `tasks/GameUi/navigator.py` 第 494–506 行:

**成功的页面转换受到惩罚**

执行转换操作后、目标页面出现前,如果源页面仍可识别,`_wait_for_destination` 会将源页面视为一次失败的探测并返回 `False`。因此,目标页面还没来得及出现,`_execute_transition` 就会记录一次失败的转换并施加惩罚。

如果检测到的页面仍是转换源页面,请继续轮询;只有目标页面等待超时后才判定失败。
Original comment in English

🟠 High · Successful transitions get penalized

When the source page remains recognizable after the transition action but before the destination appears, _wait_for_destination treats the source page as a failed probe and returns False, so _execute_transition records a failed transition and adds a penalty before the destination has time to appear.

Keep polling when the detected page is still the transition source, and only fail after the destination wait expires.

Prompt for AI agents
In `tasks/GameUi/navigator.py` at lines 494-506:

**Successful transitions get penalized**

When the source page remains recognizable after the transition action but before the destination appears, `_wait_for_destination` treats the source page as a failed probe and returns `False`, so `_execute_transition` records a failed transition and adds a penalty before the destination has time to appear.

Keep polling when the detected page is still the transition source, and only fail after the destination wait expires.

return False
return False

def _execute_transition(self, transition: Transition) -> bool:
Expand Down Expand Up @@ -700,6 +713,19 @@ def detect_page_in(self, *targets: str | Page, include_global: bool = True) -> P

return GameUi._detect_pages(self, pages, skip_first_screenshot=True)

def _wait_for_any_page(self, timeout: float = 15.0) -> bool:
"""未知页(多半是过图加载)时静等可识别页面出现,期间不点任何关闭按钮。"""

timer = Timer(timeout).start()
while not timer.reached():
page = self._detect_current_page(
skip_first_screenshot=False,
categories=self._default_detect_categories(),

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 中 · 已识别的目标页面被关闭

在恢复等待期间,如果出现的可识别页面不属于全局类别或当前任务类别,_wait_for_any_page 只会搜索全局类别和当前任务类别,因此无法发现该页面;随后 close_unknown_pages 会在导航重新识别该页面之前,对它运行关闭器。

运行未知页面关闭器之前,请搜索所有已注册的页面类别,包括目标类别。

另见 tasks/GameUi/navigator.py:724。

给 AI 智能体的提示
在 `tasks/GameUi/navigator.py` 第 723 行:

**已识别的目标页面被关闭**

在恢复等待期间,如果出现的可识别页面不属于全局类别或当前任务类别,`_wait_for_any_page` 只会搜索全局类别和当前任务类别,因此无法发现该页面;随后 `close_unknown_pages` 会在导航重新识别该页面之前,对它运行关闭器。

运行未知页面关闭器之前,请搜索所有已注册的页面类别,包括目标类别。

另见 `tasks/GameUi/navigator.py:724`。
Original comment in English

🟡 Medium · Recognized destinations get dismissed

When a recognizable page appears outside the global and current-task categories during the recovery wait, _wait_for_any_page searches only the global and current-task categories, so it misses the page and close_unknown_pages runs a closer against it before navigation can re-detect it.

Search all registered page categories, including the destination category, before running unknown-page closers.

Also at tasks/GameUi/navigator.py:724.

Prompt for AI agents
In `tasks/GameUi/navigator.py` at line 723:

**Recognized destinations get dismissed**

When a recognizable page appears outside the global and current-task categories during the recovery wait, `_wait_for_any_page` searches only the global and current-task categories, so it misses the page and `close_unknown_pages` runs a closer against it before navigation can re-detect it.

Search all registered page categories, including the destination category, before running unknown-page closers.

Also at `tasks/GameUi/navigator.py:724`.

)
if page is not None:
return True
return False

def close_unknown_pages(self, skip_first_screenshot: bool = True) -> bool:
"""尝试关闭未知页面。

Expand All @@ -712,6 +738,9 @@ def close_unknown_pages(self, skip_first_screenshot: bool = True) -> bool:

self.maybe_screenshot(skip_first_screenshot)
logger.warning("Try switch to a supported page")
if self._wait_for_any_page(timeout=15.0):
# 等待期间出现了可识别页面,无需关闭动作,交给外层重识别。
return False
for action in [*self.navigator.local_unknown_closers, *self.DEFAULT_UNKNOWN_CLOSERS]:
action_name = self._action_name(action)
# 若最后3次执行的都是该动作,则跳过该动作尝试其他动作
Expand Down
Loading