Skip to content

fix(GeneralBattle): retry prepare click after battle_before timeout - #1801

Merged
runhey merged 1 commit into
runhey:devfrom
m123711:fix/general-battle-before
Sep 10, 2026
Merged

runhey merged 1 commit into
runhey:devfrom
m123711:fix/general-battle-before

Conversation

@m123711

@m123711 m123711 commented Sep 9, 2026 •

Copy link
Copy Markdown
Contributor

Problem

In RealmRaid (and other battles using run_general_battle), the start-battle click (GB_PREPARE_HIGHLIGHT) can be intercepted by the closing preset-panel animation right after switching preset team, so the battle never starts. battle_before() returns False after its 5s timeout, but the return value was ignored and run_general_battle still entered battle_wait()'s infinite loop waiting for a result screen that never appears - the script looks stuck with no action until the user manually clicks start.

Reproduced in real logs: 14:23:15.236 start click missed, battle_before returned False at 14:23:15.8, then the script waited in battle_wait until the user manually started the battle (won at 14:23:33).

Fix

Keep the original logic untouched. After battle_before() times out, re-check the screen for up to 3s (retry_prepare_click):

  • still on the prepare screen -> click start battle once more and wait for the battle to begin
  • already in real battle -> continue normally
  • neither (abnormal state) -> log a warning and return False so callers (e.g. RealmRaid, which uses last_battle to decide refresh/exit) handle it as a failed battle instead of waiting forever

Verification

  • py_compile and module import passed.
  • Logic simulation: prepare->re-click->in battle returns True; stuck on prepare returns False; already in battle returns True. All PASS.

Sourcery 摘要

在战斗开始前超时后重试启动普通战斗;当无法确认战斗状态时安全地中止。

Bug 修复:

  • 当初始点击未被注册时,在战斗开始前超时后重试启动战斗操作。
  • 当屏幕未进入有效的准备状态或战斗中状态时,干净地结束战斗,避免无限等待结果画面。
Original summary in English

Sourcery 总结

让普通战斗能够从未成功点击开始按钮的情况中恢复,并在无法确认战斗状态时安全退出。

错误修复:

  • 在战斗前阶段超时后重试开始普通战斗,以处理过渡 UI 动画导致的开始按钮点击未生效问题。
  • 当屏幕未进入有效的准备状态或战斗中状态时,干净地中止战斗,避免无限等待结果画面。
Original summary in English

Summary by Sourcery

Make general battles recover from missed start clicks and fail safely when the battle state cannot be confirmed.

Bug Fixes:

  • Retry starting a general battle after the pre-battle phase times out, handling missed start clicks caused by transitional UI animations.
  • Abort the battle cleanly when the screen does not reach a valid preparation or in-battle state, preventing indefinite waits for a result screen.

@sourcery-ai sourcery-ai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

嗨——我已经审阅了你的更改,看起来很棒!

Sourcery 评估

已批准。


Sourcery 对开源项目免费——如果你喜欢我们的审阅结果,请考虑分享它们 ✨
Original comment in English

Hey - I've reviewed your changes and they look great!

Sourcery assessment

Approved.


Sourcery is free for open source - if you like our reviews please consider sharing them ✨

@github-actions

github-actions Bot commented Sep 9, 2026

Copy link
Copy Markdown
Contributor

Findings

  • C3 [风险]
    位置:tasks/Component/GeneralBattle/general_battle.py:retry_prepare_click
    原因:准备界面持续被识别时,循环会在 3 秒窗口内反复调用 appear_then_click;这超出“超时后再点击一次”的意图,可能在界面切换或点击延迟期间重复触发开始战斗。
    修改:增加一次性重试标记,首次确认仍在准备界面后只点击一次;之后仅轮询 is_in_real_battle,直到超时或确认进入战斗。

Warning

Firewall blocked 1 domain

The following domain was blocked by the firewall during workflow execution:

  • ab.chatgpt.com

To allow these domains, add them to the network.allowed list in your workflow frontmatter:

network:
  allowed:
    - defaults
    - "ab.chatgpt.com"

See Network Configuration for more information.

Generated by PR Review Checklist for #1801 · codex · gpt56 · 13.9 AIC · ⌖ 2.44 AIC · ⊞ 12.8K · ◷

@github-actions

github-actions Bot commented Sep 9, 2026

Copy link
Copy Markdown
Contributor

Change Summary

  • run_general_battle 现在消费 battle_before() 的返回值。
  • 战前超时后新增最多 3 秒的补偿流程:识别已进入实战,或在仍处于准备页时再次点击开始战斗。
  • 3 秒内无法确认实战时返回 False,避免直接进入原本等待战斗结果的流程。

Reconstructed Intent

点击此处展开
  • 这次改动最可能是为了处理预设阵容关闭动画拦截首次开始战斗点击的场景,并把“未确认进入战斗”的状态向上层传递,避免 battle_wait() 无限等待结果页。

Observed Constraints

点击此处展开
  • 补偿流程依赖 is_in_real_battle(False) 与 is_in_prepare(False) 能互斥且覆盖超时后的有效页面状态。
  • False 必须被所有重要调用者消费;否则只是把无限等待从 battle_wait() 推迟到调用者后续流程。
  • retry_prepare_click 的 3 秒窗口假定重新点击后能在窗口内被识别为实战。

Intent Alignment

  • 核心实现与推断 intent 基本一致:新增路径确实会重试准备页点击,并在无法确认状态时提前返回。
  • 但上层链路只部分覆盖了该 intent:tasks/RealmRaid/script_task.py 在 run_general_battle() 返回后无条件调用无超时的 wait_until_appear(self.I_BACK_RED),然后才根据 last_battle 决定刷新或退出。若失败时仍停留在准备页,该调用仍可能无限等待,无法到达失败处理分支。

Release Risk

  • 风险等级:中
  • RealmRaid 是 PR 描述明确涉及的调用场景,但失败返回后的无超时等待可能保留原有“卡住”症状,只是等待位置发生变化。
  • 其他调用者多数忽略 run_general_battle() 返回值;新增失败返回会改变流程状态,但未见统一的失败/回退约定,可能导致任务继续执行后续页面操作。
  • 识别逻辑和 3 秒固定窗口涉及设备速度、动画时序,误判未知页面或窗口过短时仍可能丢失有效战斗。

Validation Gaps

点击此处展开
  • PR 中提到的编译、导入和逻辑模拟不足以验证真实页面链路;未看到针对 RealmRaid “返回 False 且仍在准备页”场景的集成验证。
  • 应验证:首次点击被动画拦截后重试成功;超时后已进入实战;始终停留准备页时调用链最终退出/刷新而非无限等待;未知页面时各调用者的行为。
  • 当前 PR 状态中的检查仍在运行,尚未看到完成的项目级测试结果。

Warning

Firewall blocked 1 domain

The following domain was blocked by the firewall during workflow execution:

  • ab.chatgpt.com

To allow these domains, add them to the network.allowed list in your workflow frontmatter:

network:
  allowed:
    - defaults
    - "ab.chatgpt.com"

See Network Configuration for more information.

Generated by PR Review Intent for #1801 · codex · gpt56 · 23.2 AIC · ⌖ 2.66 AIC · ⊞ 12.4K · ◷

@m123711

m123711 commented Sep 9, 2026

Copy link
Copy Markdown
Contributor Author

感谢分析。针对 Intent Alignment 与 Release Risk 中的两点,补充核实结果:

1. 关于 execute_round 中无超时的 wait_until_appear(I_BACK_RED)
已核实:execute_round 在整个项目中没有任何调用者(仅定义未使用,属于废弃路径)。实际运行时走的是 run_2 的 while 循环:run_general_battle() 返回后直接检查 last_battle,根据 when_attack_fail 配置进入刷新(REFRESH)或退出(EXIT)分支,失败状态会被正确消费,不会进入无限等待。因此该担忧在现有代码的实际执行路径上不成立;若未来启用 execute_round,再为其补充超时即可。

2. 关于"其他调用者多数忽略返回值"
run_general_battle 在改动前就可能返回 False(战斗失败时 battle_wait 返回 False),各调用者忽略该返回值本就是既有行为,并已长期运行。本次改动仅将"battle_before 超时未进入战斗"纳入这一既有的失败返回路径(行为与战斗失败一致),并未引入新的返回值语义,也没有改变任何调用方的行为模式。

3. 关于 3 秒窗口与动画时序
窗口长度依据真实日志根因设定(开始按钮点击被预设面板关闭动画拦截,超时返回后画面已稳定)。本 PR base 为 dev 分支,计划在 dev 长期运行测试;若窗口过短或出现时序问题,会在合并 master 前暴露并调整。

When the start-battle click (GB_PREPARE_HIGHLIGHT) is intercepted by the
closing preset-panel animation, the battle never starts and battle_before
returns False after its 5s timeout. run_general_battle then entered
battle_wait's infinite loop waiting for a result screen that never
appears - the script looks stuck until the user clicks start manually.

Fix: after battle_before times out, re-check the screen for up to 3s:
- still on the prepare screen -> click start battle once and wait for
  the battle to begin (click only once, then just poll - avoid repeated
  clicks during UI transition)
- already in real battle -> continue normally
- neither (abnormal state) -> log a warning and return False so callers
  handle it as a failed battle instead of waiting forever
@m123711
m123711 force-pushed the fix/general-battle-before branch from 57b825d to 65a6b73 Compare September 9, 2026 07:49
@m123711

m123711 commented Sep 9, 2026

Copy link
Copy Markdown
Contributor Author

已按建议修改完成:retry_prepare_click 现在确认仍在准备界面时只补点一次「开始战斗」,之后仅轮询 is_in_real_battle 直到确认进入战斗或超时,不再在 3 秒窗口内重复点击(commit 65a6b73)。已用三场景模拟验证:补点后进入战斗(1 次点击/返回 True)、始终点不到(1 次尝试/超时返回 False)、已在战斗(0 次点击/返回 True)。

@runhey
runhey merged commit 81ef494 into runhey:dev Sep 10, 2026
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants