Skip to content

feat: 清理旧日志时同步清理旧 on_error#299

Open
ocsin1 wants to merge 1 commit into
MistEO:mainfrom
ocsin1:feat/session-aware-log-cleanup
Open

feat: 清理旧日志时同步清理旧 on_error#299
ocsin1 wants to merge 1 commit into
MistEO:mainfrom
ocsin1:feat/session-aware-log-cleanup

Conversation

@ocsin1

@ocsin1 ocsin1 commented Jul 26, 2026

Copy link
Copy Markdown
Contributor

close 4531

按本次 MXU 启动时间区分新旧文件,清理旧 .log 时同步清理旧 on_error,并保护正在使用的日志。手动清理仅在全部任务停止时清除本次启动产生的 on_error,运行中自动保留;同时增加任务提交互斥、分类报告和文件系统测试。

Summary by Sourcery

引入支持会话感知的日志功能以及 MaaFramework on_error 清理机制,使其与任务提交流程和运行时状态协调配合,并向前端暴露结构化的清理报告。

New Features:

  • 添加一个绑定会话的日志清理命令,根据进程启动时间和请求的清理范围,删除旧的顶层日志文件及对应的 MaaFramework on_error 产物。
  • 在前端暴露一个带类型定义的日志清理助手,用于调用后端命令,并在手动和自动日志清理时呈现详细的清理报告。
  • on_error 清理范围添加选项,允许调用方在系统空闲时只清理“上一会话”的产物,或同时包含“当前会话”的产物。

Bug Fixes:

  • 保护活动日志文件和当前的 on_error 输出,避免被误删,包括在启动时自动清理和手动清理过程中。
  • 将任务提交与 on_error 清理过程串行化,避免在任务状态检查与任务启动之间出现竞争条件,从而防止正在运行的会话文件被误删除。

Enhancements:

  • 通过将日志清理从通用的 file_ops 中移出,置入一个职责更清晰、错误报告更明确的专用模块来优化文件操作。
  • 改善与清理相关的日志记录,在后端和 UI 中针对成功和失败路径分别输出分类的 info/warn 消息。
  • 添加全面的基于文件系统的测试,用于验证日志和 on_error 清理行为,包括符号链接(symlink)、目录缺失和删除失败等边界情况。

Build:

  • 引入仅用于测试的依赖,用于支持文件系统和时间戳操作,从而支撑新的日志清理测试。

Tests:

  • 添加针对会话感知日志和 on_error 清理的单元测试,覆盖范围解析、快照行为、保护规则以及失败处理。
Original summary in English

Summary by Sourcery

Introduce session-aware log and MaaFramework on_error cleanup that coordinates with task submission and runtime state while exposing structured cleanup reporting to the frontend.

New Features:

  • Add a session-bound log cleanup command that deletes old top-level log files and corresponding MaaFramework on_error artifacts based on process start time and requested scope.
  • Expose a typed log cleanup helper in the frontend that invokes the backend command and surfaces a detailed cleanup report for manual and automatic log clearing.
  • Add options for on_error cleanup scope, allowing callers to clear only previous-session artifacts or include current-session ones when the system is idle.

Bug Fixes:

  • Protect active log files and current on_error outputs from accidental deletion, including during auto-clear on launch and manual cleanup.
  • Serialize task submission with on_error cleanup to avoid race conditions between task state checks and task start that could lead to removing files from a running session.

Enhancements:

  • Refine file operations by moving log cleanup out of generic file_ops into a dedicated module with clearer responsibilities and error reporting.
  • Improve logging around cleanup operations by emitting categorized info/warn messages for success and failure paths in both backend and UI.
  • Add comprehensive filesystem-based tests to validate log and on_error cleanup behavior, including edge cases like symlinks, missing directories, and deletion failures.

Build:

  • Introduce test-only dependencies for filesystem and timestamp manipulation to support the new log cleanup tests.

Tests:

  • Add unit tests for session-aware log and on_error cleanup covering scope resolution, snapshot behavior, protection rules, and failure handling.
Original summary in English

Summary by Sourcery

引入支持会话感知的日志功能以及 MaaFramework on_error 清理机制,使其与任务提交流程和运行时状态协调配合,并向前端暴露结构化的清理报告。

New Features:

  • 添加一个绑定会话的日志清理命令,根据进程启动时间和请求的清理范围,删除旧的顶层日志文件及对应的 MaaFramework on_error 产物。
  • 在前端暴露一个带类型定义的日志清理助手,用于调用后端命令,并在手动和自动日志清理时呈现详细的清理报告。
  • on_error 清理范围添加选项,允许调用方在系统空闲时只清理“上一会话”的产物,或同时包含“当前会话”的产物。

Bug Fixes:

  • 保护活动日志文件和当前的 on_error 输出,避免被误删,包括在启动时自动清理和手动清理过程中。
  • 将任务提交与 on_error 清理过程串行化,避免在任务状态检查与任务启动之间出现竞争条件,从而防止正在运行的会话文件被误删除。

Enhancements:

  • 通过将日志清理从通用的 file_ops 中移出,置入一个职责更清晰、错误报告更明确的专用模块来优化文件操作。
  • 改善与清理相关的日志记录,在后端和 UI 中针对成功和失败路径分别输出分类的 info/warn 消息。
  • 添加全面的基于文件系统的测试,用于验证日志和 on_error 清理行为,包括符号链接(symlink)、目录缺失和删除失败等边界情况。

Build:

  • 引入仅用于测试的依赖,用于支持文件系统和时间戳操作,从而支撑新的日志清理测试。

Tests:

  • 添加针对会话感知日志和 on_error 清理的单元测试,覆盖范围解析、快照行为、保护规则以及失败处理。
Original summary in English

Summary by Sourcery

Introduce session-aware log and MaaFramework on_error cleanup that coordinates with task submission and runtime state while exposing structured cleanup reporting to the frontend.

New Features:

  • Add a session-bound log cleanup command that deletes old top-level log files and corresponding MaaFramework on_error artifacts based on process start time and requested scope.
  • Expose a typed log cleanup helper in the frontend that invokes the backend command and surfaces a detailed cleanup report for manual and automatic log clearing.
  • Add options for on_error cleanup scope, allowing callers to clear only previous-session artifacts or include current-session ones when the system is idle.

Bug Fixes:

  • Protect active log files and current on_error outputs from accidental deletion, including during auto-clear on launch and manual cleanup.
  • Serialize task submission with on_error cleanup to avoid race conditions between task state checks and task start that could lead to removing files from a running session.

Enhancements:

  • Refine file operations by moving log cleanup out of generic file_ops into a dedicated module with clearer responsibilities and error reporting.
  • Improve logging around cleanup operations by emitting categorized info/warn messages for success and failure paths in both backend and UI.
  • Add comprehensive filesystem-based tests to validate log and on_error cleanup behavior, including edge cases like symlinks, missing directories, and deletion failures.

Build:

  • Introduce test-only dependencies for filesystem and timestamp manipulation to support the new log cleanup tests.

Tests:

  • Add unit tests for session-aware log and on_error cleanup covering scope resolution, snapshot behavior, protection rules, and failure handling.

按本次 MXU 启动时间区分新旧文件,清理旧 .log 时同步清理旧 on_error,并保护正在使用的日志。手动清理仅在全部任务停止时清除本次启动产生的 on_error,运行中自动保留;同时增加任务提交互斥、分类报告和文件系统测试。

@sourcery-ai sourcery-ai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Hey - 我已经审查了你的修改,它们看起来很棒!


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

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


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