Skip to content

chore(maafw): 按历史记录保留天数清理 MFW 原生日志备份 - #640

Merged
qiyinxi merged 1 commit into
AUTO-MAS-Project:devfrom
qiyinxi:chore/maafw-debug-log-cleanup-20260909
Sep 9, 2026
Merged

chore(maafw): 按历史记录保留天数清理 MFW 原生日志备份#640
qiyinxi merged 1 commit into
AUTO-MAS-Project:devfrom
qiyinxi:chore/maafw-debug-log-cleanup-20260909

Conversation

@qiyinxi

@qiyinxi qiyinxi commented Sep 9, 2026

Copy link
Copy Markdown
Contributor

MaaFramework 把 debug/maafw.log 写到一定大小就整体挪成 debug/maafw.bak.<时间戳>.log 再开新的,但从不回收旧的。实测一个每天跑的 MaaEnd 项目四天堆了 15 个备份、385 MB,而这些内容每次运行都已经另存进历史记录的 *.maafw.log,原地那份是纯冗余。

  • 新增 clean_maafw_native_debug_logs(),随启动清理一并执行,保留时长沿用 Function/HistoryRetentionTime,与旁边的 clean_debug_diagnostics 同一口径;设为「永久保留」时整轮弃权
  • 只删 maafw.bak.*.log,正在写的 maafw.loggo-service.logdebug/record/ 都不动;单个文件删失败只记 warning 不中断

本地验证

命令 结果
python -m pytest tests/core tests/task -q 376 passed, 68 subtests
python -m pytest tests --collect-only -q 退出码 0,737 collected
ruff check / ruff format --check(本 PR 新增的代码) All checks passed / already formatted

main.py 的 I001 与 app/core/config.py 的 format 差异在本分支基点上就已存在(拿 git show HEAD: 的原始文件复核过),且格式化涉及的最后一处在第 2948 行、本 PR 代码在 4293 行,未受影响,因此没有顺带格式化。

tests/AGENTS.md,对应的边界测试只在本地运行,未随 PR 提交。

🤖 Generated with Claude Code

Sourcery 摘要

通过在启动维护中加入基于保留策略的清理机制,防止 MaaFramework 原生调试日志备份无限累积。

改进:

  • 根据配置的历史记录保留期限清理已过期的 MaaFramework 原生日志备份,同时保留活动日志和无关的调试文件。

杂项:

  • 更新日志清理变更的变更日志和版本元数据。
Original summary in English

Summary by Sourcery

Prevent MaaFramework native debug log backups from accumulating indefinitely by including their retention-based cleanup in startup maintenance.

Enhancements:

  • Clean expired MaaFramework native log backups according to the configured history retention period while preserving active logs and unrelated debug files.

Chores:

  • Update the changelog and version metadata for the log cleanup change.

MaaFramework 把 debug/maafw.log 写到一定大小就整体挪成
debug/maafw.bak.<时间戳>.log 再开新的,但从不回收旧的,一个每天跑的项目
几天就能堆出几百 MB。每次运行的完整内容已经另存进历史记录的 *.maafw.log,
原地那些备份是纯冗余。

- 新增 clean_maafw_native_debug_logs(),随启动清理一并执行,判据沿用
  Function/HistoryRetentionTime,设为「永久」时整轮弃权
- 只删 maafw.bak.*.log,正在写的 maafw.log 与其他调试文件不动

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>

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

Sorry @qiyinxi, you've used your own review budget of 250,000 diff characters for the last 7 days.

You can request another review in 2 days and 20 hours by commenting @sourcery-ai review. Upgrade to get a review now.

@sourcery-ai

sourcery-ai Bot commented Sep 9, 2026

Copy link
Copy Markdown

审查者指南

本 PR 为 MFW 原生日志轮转备份增加了基于历史记录保留天数的启动时回收机制:按项目配置定位 debug 目录,仅删除过期备份,支持永久保留配置和逐文件失败容错,避免冗余日志无限占用磁盘。

MFW 原生日志备份启动时清理的时序图

sequenceDiagram
    participant Startup as BackgroundStartup
    participant Config as Config
    participant Project as MaaFWProject
    participant Debug as DebugDirectory
    participant Logger as Logger

    Startup->>Config: clean_maafw_native_debug_logs()
    Config->>Config: get(Function, HistoryRetentionTime)
    alt HistoryRetentionTime == 0
        Config->>Logger: info(permanent retention, skip cleanup)
    else Retention enabled
        loop Each MaaFW project
            Config->>Project: get(Info, Path)
            Config->>Debug: glob(maafw.bak.*.log)
            loop Each rotated backup
                alt Backup is expired
                    Config->>Debug: unlink(backup)
                else Delete fails
                    Config->>Logger: warning(delete failure)
                end
            end
        end
        Config->>Logger: success(deleted backup count)
    end
Loading

文件级变更

变更 详细信息 文件
新增按历史记录保留期限清理 MaaFramework 原生日志轮转备份的逻辑,并接入启动时的统一清理流程。
  • 复用 Function/HistoryRetentionTime 计算过期时间;设为永久保留时跳过整轮清理。
  • 遍历 MFW 项目 debug/,仅匹配并删除过期的 maafw.bak.*.log,保留当前日志及其他调试产物。
  • 对单文件删除失败记录 warning 并继续处理,其余清理完成后输出删除数量。
  • 在后台服务初始化阶段调用清理方法,并更新变更日志。
app/core/config.py
main.py
CHANGELOG.md

提示和命令

与 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

本 PR 为 MFW 原生日志轮转备份增加了基于历史记录保留天数的启动时回收机制:按项目配置定位 debug 目录,仅删除过期备份,支持永久保留配置和逐文件失败容错,避免冗余日志无限占用磁盘。

Sequence diagram for startup cleanup of MFW native log backups

sequenceDiagram
    participant Startup as BackgroundStartup
    participant Config as Config
    participant Project as MaaFWProject
    participant Debug as DebugDirectory
    participant Logger as Logger

    Startup->>Config: clean_maafw_native_debug_logs()
    Config->>Config: get(Function, HistoryRetentionTime)
    alt HistoryRetentionTime == 0
        Config->>Logger: info(permanent retention, skip cleanup)
    else Retention enabled
        loop Each MaaFW project
            Config->>Project: get(Info, Path)
            Config->>Debug: glob(maafw.bak.*.log)
            loop Each rotated backup
                alt Backup is expired
                    Config->>Debug: unlink(backup)
                else Delete fails
                    Config->>Logger: warning(delete failure)
                end
            end
        end
        Config->>Logger: success(deleted backup count)
    end
Loading

File-Level Changes

Change Details Files
新增按历史记录保留期限清理 MaaFramework 原生日志轮转备份的逻辑,并接入启动时的统一清理流程。
  • 复用 Function/HistoryRetentionTime 计算过期时间;设为永久保留时跳过整轮清理。
  • 遍历 MFW 项目 debug/,仅匹配并删除过期的 maafw.bak.*.log,保留当前日志及其他调试产物。
  • 对单文件删除失败记录 warning 并继续处理,其余清理完成后输出删除数量。
  • 在后台服务初始化阶段调用清理方法,并更新变更日志。
app/core/config.py
main.py
CHANGELOG.md

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

@qiyinxi
qiyinxi merged commit 9dc1e60 into AUTO-MAS-Project:dev Sep 9, 2026
3 checks 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.

1 participant