Skip to content

重构看门狗逻辑,拆分配置项并新增强制定时重启功能 - #794

Merged
Beatrice-betty merged 3 commits into
wess09:devfrom
Beatrice-betty:dev
Aug 19, 2026
Merged

重构看门狗逻辑,拆分配置项并新增强制定时重启功能#794
Beatrice-betty merged 3 commits into
wess09:devfrom
Beatrice-betty:dev

Conversation

@Beatrice-betty

@Beatrice-betty Beatrice-betty commented Aug 19, 2026

Copy link
Copy Markdown
Collaborator

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:

  • Add optional forced scheduled emulator restarts for non-sensitive tasks when the configured restart interval is reached.

Bug Fixes:

  • Prevent task logic loops from running indefinitely by retaining configurable task-duration watchdog recovery.

Enhancements:

  • Replace log-heartbeat monitoring with explicit task-timeout monitoring and independent watchdog controls.
  • Make restart-operation hard timeouts optional, preserving the existing app restart behavior when disabled.

Chores:

  • Update configuration defaults and generated settings for watchdog, restart timeout, and scheduled restart controls.

@chatgpt-codex-connector

Copy link
Copy Markdown

You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard.

@github-actions

Copy link
Copy Markdown

⏳ CI 检查进行中,报告将在完成后更新。

@Beatrice-betty Beatrice-betty changed the title Dev 重构看门狗逻辑,拆分配置项并新增强制定时重启功能 Aug 19, 2026
@sourcery-ai

sourcery-ai Bot commented Aug 19, 2026

Copy link
Copy Markdown

审阅者指南

重构 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
Loading

可配置应用重启硬超时的序列图

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)
Loading

文件级变更

Change Details Files
重构 watchdog,使用配置驱动的任务超时和可选的强制定时模拟器重启替代日志心跳检测。
  • 移除基于日志的心跳处理器及相关的日志超时常量和恢复路径。
  • 更新 watchdog 启动逻辑,使其遵守 Error.WatchdogEnable 以及 EmulatorManagement.ForceScheduledRestart/ScheduledEmulatorRestart 总开关。
  • 扩展 watchdog 循环,对非敏感任务按照配置的重启间隔和最近重启时间执行强制定时模拟器重启。
  • 仅在启用 Error.WatchdogTaskEnable 时执行任务超时检查,并相应调整恢复原因和日志记录。
  • 在强制定时重启后更新模拟器重启时间戳,以避免立即再次触发。
alas.py
使应用重启硬超时保护变为可选,并由新的配置标志控制。
  • 引入辅助方法从配置中读取 Alas.Error.RestartOperationTimeoutEnable 并将其解析为布尔值。
  • 修改 app_restart:仅在启用硬超时保护时将 app_stop/app_start 包装在带截止时间的调用中,否则直接调用设备方法。
  • 改进与硬超时保护是否启用以及配置的超时值相关的日志记录。
module/handler/login.py
引入新的配置开关,用于控制 watchdog 行为、重启操作超时保护以及强制定时模拟器重启。
  • 在错误配置定义中添加 Error.WatchdogEnable 和 Error.WatchdogTaskEnable 标志,并移除 Error.WatchdogLogTimeout。
  • 在现有 RestartOperationTimeout 的基础上添加 Error.RestartOperationTimeoutEnable 标志。
  • 在模拟器管理配置中添加 EmulatorManagement.ForceScheduledRestart 标志,并在生成配置中接入默认值。
  • 更新参数 YAML/JSON 和 i18n 资源文件,以暴露新选项并移除已废弃的日志超时设置。
module/config/argument/argument.yaml
module/config/config_generated.py
config/template.json
module/config/argument/args.json
module/config/i18n/en-US.json
module/config/i18n/ja-JP.json
module/config/i18n/zh-CN.json
module/config/i18n/zh-MIAO.json
module/config/i18n/zh-TW.json

技巧与命令

与 Sourcery 交互

  • 触发新审阅: 在 Pull Request 上评论 @sourcery-ai review
  • 继续讨论: 直接回复 Sourcery 的审阅评论。
  • 从审阅评论生成 GitHub Issue: 通过回复审阅评论,要求 Sourcery 从该评论创建一个 issue。你也可以在审阅评论下回复 @sourcery-ai issue 来从该评论创建 issue。
  • 生成 Pull Request 标题: 在 Pull Request 标题中任意位置写入 @sourcery-ai,即可随时生成标题。你也可以在 Pull Request 中评论 @sourcery-ai title 来(重新)生成标题。
  • 生成 Pull Request 摘要: 在 Pull Request 描述正文的任意位置写入 @sourcery-ai summary,即可在对应位置生成 PR 摘要。你也可以在 Pull Request 中评论 @sourcery-ai summary 来(重新)生成摘要。
  • 生成审阅者指南: 在 Pull Request 中评论 @sourcery-ai guide,即可随时(重新)生成审阅者指南。
  • 解决所有 Sourcery 评论: 在 Pull Request 中评论 @sourcery-ai resolve,即可解决所有 Sourcery 评论。如果你已经处理完所有评论且不再希望看到它们,这会非常有用。
  • 取消所有 Sourcery 审阅: 在 Pull Request 中评论 @sourcery-ai dismiss,即可取消所有现有的 Sourcery 审阅。若你希望从新的审阅开始,这尤其有用——别忘了再评论 @sourcery-ai review 以触发新一轮审阅!

自定义你的体验

访问你的 控制面板 以:

  • 启用或禁用审阅功能,例如 Sourcery 生成的 Pull Request 摘要、审阅者指南等。
  • 更改审阅语言。
  • 添加、移除或编辑自定义审阅说明。
  • 调整其他审阅设置。

获取帮助

Original review guide in English

Reviewer's Guide

Refactors 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 restart

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
Loading

Sequence diagram for configurable app restart hard timeout

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)
Loading

File-Level Changes

Change Details Files
Refactor watchdog to use configuration-driven task timeout and optional force scheduled emulator restart instead of log heartbeat detection.
  • Remove logging-based heartbeat handler and associated log timeout constant and recovery path.
  • Update watchdog startup logic to respect Error.WatchdogEnable and EmulatorManagement.ForceScheduledRestart/ScheduledEmulatorRestart master switches.
  • Extend watchdog loop to perform force scheduled emulator restart for non-sensitive tasks based on configured restart interval and last restart time.
  • Limit task timeout checks to when Error.WatchdogTaskEnable is enabled and adjust recovery reasons and logging accordingly.
  • Ensure emulator restart timestamp is updated after forced scheduled restart to avoid immediate retriggers.
alas.py
Make app restart hard timeout protection optional and controlled by a new configuration flag.
  • Introduce helper to read Alas.Error.RestartOperationTimeoutEnable from configuration and interpret it as a boolean.
  • Modify app_restart to only wrap app_stop/app_start in deadline calls when hard timeout protection is enabled, otherwise call device methods directly.
  • Improve logging around whether hard timeout protection is enabled and the configured timeout value.
module/handler/login.py
Introduce new configuration switches to control watchdog behavior, restart operation timeout protection, and force scheduled emulator restarts.
  • Add Error.WatchdogEnable and Error.WatchdogTaskEnable flags and remove Error.WatchdogLogTimeout from error config definitions.
  • Add Error.RestartOperationTimeoutEnable flag alongside existing RestartOperationTimeout.
  • Add EmulatorManagement.ForceScheduledRestart flag to emulator management config and wire defaults in generated config.
  • Update argument YAML/JSON and i18n resource files to expose the new options and remove the obsolete log timeout setting.
module/config/argument/argument.yaml
module/config/config_generated.py
config/template.json
module/config/argument/args.json
module/config/i18n/en-US.json
module/config/i18n/ja-JP.json
module/config/i18n/zh-CN.json
module/config/i18n/zh-MIAO.json
module/config/i18n/zh-TW.json

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

@Beatrice-betty
Beatrice-betty merged commit d158b6e into wess09:dev Aug 19, 2026
5 checks passed

@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.

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` 漂移的风险。

Sourcery 对开源项目是免费的——如果你觉得这些评审有帮助,欢迎分享 ✨
帮我变得更有用!请对每条评论点 👍 或 👎,我会根据这些反馈改进之后的评审。
Original comment in English

Hey - I've left some high level feedback:

  • 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.
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`.

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

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.

1 participant