重构看门狗逻辑,拆分配置项并新增强制定时重启功能 - #794
Merged
Merged
Conversation
|
You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard. |
|
⏳ CI 检查进行中,报告将在完成后更新。 |
审阅者指南重构 watchdog,移除基于日志心跳的死锁检测,改为使用可配置的任务超时和可选的强制定时模拟器重启逻辑,并通过新的 Error 和 EmulatorManagement 配置开关,让应用重启的硬超时可配置/可禁用。 更新后的 watchdog 任务超时与强制定时重启的序列图sequenceDiagram
participant AlasMain as AlasMainTask
participant Watchdog as WatchdogThread
participant Config as GeneratedConfig
participant Emulator as EmulatorProcess
AlasMain->>Watchdog: _start_watchdog()
Watchdog->>Config: read Error_WatchdogEnable
Watchdog->>Config: read EmulatorManagement_ScheduledEmulatorRestart
Watchdog->>Config: read EmulatorManagement_ForceScheduledRestart
alt master_enable or force_restart
Watchdog->>Watchdog: start _watchdog_loop
else no_detection_enabled
Watchdog-->>AlasMain: return (watchdog not started)
end
loop every WATCHDOG_CHECK_INTERVAL
Watchdog->>Watchdog: check _watchdog_active
opt _watchdog_active
Watchdog->>Config: read EmulatorManagement_ScheduledEmulatorRestart
Watchdog->>Config: read EmulatorManagement_ForceScheduledRestart
alt scheduled and force and not Sensitive
Watchdog->>Config: read EmulatorManagement_RestartIntervalHours
Watchdog->>Watchdog: compute elapsed_hours since last_emulator_restart_time
alt elapsed_hours >= interval
Watchdog->>Watchdog: _watchdog_recover(reason=force_scheduled_restart)
Watchdog->>Emulator: emulator_stop() via _emulator_op_with_timeout
end
end
Watchdog->>Config: read Error_WatchdogTaskEnable
alt task_enable and _watchdog_task_start > 0
Watchdog->>Config: read Error_WatchdogTaskTimeout
Watchdog->>Watchdog: compute elapsed_task
alt elapsed_task > timeout_min
Watchdog->>Watchdog: _watchdog_recover(reason=task_timeout)
Watchdog->>Emulator: emulator_stop() via _emulator_op_with_timeout
end
end
end
end
可配置应用重启硬超时的序列图sequenceDiagram
participant Login as LoginHandler
participant Config as GeneratedConfig
participant Device as Device
Login->>Login: app_restart()
Login->>Config: deep_get Alas.Error.RestartOperationTimeoutEnable
alt RestartOperationTimeoutEnable is True
Login->>Login: _restart_operation_timeout()
Login->>Login: set op_timeout
Login->>Device: _call_with_restart_deadline(device.app_stop, timeout=op_timeout)
else RestartOperationTimeoutEnable is False
Login->>Device: device.app_stop()
end
opt Restart_ClearCache
Login->>Device: device.app_clear()
end
Login->>Device: device.sleep(3)
alt RestartOperationTimeoutEnable is True
Login->>Device: _call_with_restart_deadline(device.app_start, timeout=op_timeout)
else RestartOperationTimeoutEnable is False
Login->>Device: device.app_start()
end
Login->>Device: device.sleep(wait_seconds)
文件级变更
技巧与命令与 Sourcery 交互
自定义你的体验访问你的 控制面板 以:
获取帮助Original review guide in EnglishReviewer's GuideRefactors the watchdog to remove log-heartbeat based deadlock detection, adds configurable task-timeout and optional force scheduled emulator restart logic, and makes app restart hard timeouts configurable/disableable via new Error and EmulatorManagement config switches. Sequence diagram for updated watchdog task timeout and force scheduled restartsequenceDiagram
participant AlasMain as AlasMainTask
participant Watchdog as WatchdogThread
participant Config as GeneratedConfig
participant Emulator as EmulatorProcess
AlasMain->>Watchdog: _start_watchdog()
Watchdog->>Config: read Error_WatchdogEnable
Watchdog->>Config: read EmulatorManagement_ScheduledEmulatorRestart
Watchdog->>Config: read EmulatorManagement_ForceScheduledRestart
alt master_enable or force_restart
Watchdog->>Watchdog: start _watchdog_loop
else no_detection_enabled
Watchdog-->>AlasMain: return (watchdog not started)
end
loop every WATCHDOG_CHECK_INTERVAL
Watchdog->>Watchdog: check _watchdog_active
opt _watchdog_active
Watchdog->>Config: read EmulatorManagement_ScheduledEmulatorRestart
Watchdog->>Config: read EmulatorManagement_ForceScheduledRestart
alt scheduled and force and not Sensitive
Watchdog->>Config: read EmulatorManagement_RestartIntervalHours
Watchdog->>Watchdog: compute elapsed_hours since last_emulator_restart_time
alt elapsed_hours >= interval
Watchdog->>Watchdog: _watchdog_recover(reason=force_scheduled_restart)
Watchdog->>Emulator: emulator_stop() via _emulator_op_with_timeout
end
end
Watchdog->>Config: read Error_WatchdogTaskEnable
alt task_enable and _watchdog_task_start > 0
Watchdog->>Config: read Error_WatchdogTaskTimeout
Watchdog->>Watchdog: compute elapsed_task
alt elapsed_task > timeout_min
Watchdog->>Watchdog: _watchdog_recover(reason=task_timeout)
Watchdog->>Emulator: emulator_stop() via _emulator_op_with_timeout
end
end
end
end
Sequence diagram for configurable app restart hard timeoutsequenceDiagram
participant Login as LoginHandler
participant Config as GeneratedConfig
participant Device as Device
Login->>Login: app_restart()
Login->>Config: deep_get Alas.Error.RestartOperationTimeoutEnable
alt RestartOperationTimeoutEnable is True
Login->>Login: _restart_operation_timeout()
Login->>Login: set op_timeout
Login->>Device: _call_with_restart_deadline(device.app_stop, timeout=op_timeout)
else RestartOperationTimeoutEnable is False
Login->>Device: device.app_stop()
end
opt Restart_ClearCache
Login->>Device: device.app_clear()
end
Login->>Device: device.sleep(3)
alt RestartOperationTimeoutEnable is True
Login->>Device: _call_with_restart_deadline(device.app_start, timeout=op_timeout)
else RestartOperationTimeoutEnable is False
Login->>Device: device.app_start()
end
Login->>Device: device.sleep(wait_seconds)
File-Level Changes
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
There was a problem hiding this comment.
Hey - 我在这里给出一些整体性反馈:
_watchdog_recover的文档字符串和reason的处理逻辑现在与实现不同步(文档里写只支持'task_timeout',但你新增了'force_scheduled_restart'以及一个通用分支);建议收紧这部分逻辑,要么明确写出所有支持的 reason,要么使用受约束的枚举/常量集来避免静默回退。- 有几个配置回退值是直接硬编码在 watchdog 循环里的(例如
RestartIntervalHours使用interval = 4),而不是依赖生成的配置默认值或共享常量;如果能把这些默认值集中管理,可以减少重复代码,并降低与argument.yaml漂移的风险。
给 AI Agents 的提示
Please address the comments from this code review:
## Overall Comments
- `_watchdog_recover` 的文档字符串和 `reason` 的处理逻辑现在与实现不同步(文档里写只支持 `'task_timeout'`,但你新增了 `'force_scheduled_restart'` 以及一个通用分支);建议收紧这部分逻辑,要么明确写出所有支持的 reason,要么使用受约束的枚举/常量集来避免静默回退。
- 有几个配置回退值是直接硬编码在 watchdog 循环里的(例如 `RestartIntervalHours` 使用 `interval = 4`),而不是依赖生成的配置默认值或共享常量;如果能把这些默认值集中管理,可以减少重复代码,并降低与 `argument.yaml` 漂移的风险。帮我变得更有用!请对每条评论点 👍 或 👎,我会根据这些反馈改进之后的评审。
Original comment in English
Hey - I've left some high level feedback:
- The
_watchdog_recoverdocstring andreasonhandling are now out of sync with the implementation (it says only'task_timeout'is supported but you added'force_scheduled_restart'and a generic branch); consider tightening this by explicitly documenting all supported reasons or using a constrained enum/constant set to avoid silent fallbacks. - Several configuration fallbacks are hardcoded inside the watchdog loop (e.g.,
interval = 4forRestartIntervalHours) rather than relying on the generated config defaults or shared constants; centralizing these defaults would reduce duplication and the risk of drift fromargument.yaml.
Prompt for AI Agents
Please address the comments from this code review:
## Overall Comments
- The `_watchdog_recover` docstring and `reason` handling are now out of sync with the implementation (it says only `'task_timeout'` is supported but you added `'force_scheduled_restart'` and a generic branch); consider tightening this by explicitly documenting all supported reasons or using a constrained enum/constant set to avoid silent fallbacks.
- Several configuration fallbacks are hardcoded inside the watchdog loop (e.g., `interval = 4` for `RestartIntervalHours`) rather than relying on the generated config defaults or shared constants; centralizing these defaults would reduce duplication and the risk of drift from `argument.yaml`.Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary by Sourcery
通过可配置的看门狗行为、强制计划重启以及可选的重启操作超时,改进任务恢复和模拟器生命周期管理。
New Features:
Bug Fixes:
Enhancements:
Chores:
Original summary in English
Summary by Sourcery
Improve task recovery and emulator lifecycle management with configurable watchdog behavior, forced scheduled restarts, and optional restart-operation timeouts.
New Features:
Bug Fixes:
Enhancements:
Chores: