Skip to content

fix(general): 配置拷贝四处补齐源存在性判断 - #616

Open
qiyinxi wants to merge 1 commit into
AUTO-MAS-Project:devfrom
qiyinxi:fix/sentry-general-20260908
Open

fix(general): 配置拷贝四处补齐源存在性判断#616
qiyinxi wants to merge 1 commit into
AUTO-MAS-Project:devfrom
qiyinxi:fix/sentry-general-20260908

Conversation

@qiyinxi

@qiyinxi qiyinxi commented Sep 8, 2026

Copy link
Copy Markdown
Contributor

Closes #533

问题

通用脚本里「按 ConfigPathMode 在 MAS 数据目录与脚本自身配置路径之间拷贝」这套逻辑写了 4 份,只有 ScriptConfig.set_general 一份做了存在性判断(e457f397 加的),另外三处没同步,源不存在就直接抛 FileNotFoundError,任务被判成「异常」。

Sentry 上三条:AUTO-MAS-BACKEND-4Q(4 条)、4Y(9 条)、4W(8 条),合计 21 条、至少 2 名用户。

改动

位置 方向 改法
AutoProxy.set_general data → 脚本 补齐存在性判断;源不存在时沿用脚本自身配置,与 ScriptConfig.set_general 行为对齐
AutoProxy.update_config 脚本 → data 源不存在时跳过并给出可读提示;File 分支补 mkdir(parents=True, exist_ok=True)
ScriptConfig.final_task 脚本 → data 源不存在时跳过并给出可读提示

两处回写的早退都放在 shutil.rmtree(用户配置目录) 之前——原来的顺序是先删备份再拷贝,源不存在时会先把用户已有的备份删掉、然后抛异常,用户看起来就是「配置丢了」。现在源不存在时备份原样保留。

两处早退都不会跳过别的收尾:ScriptConfig.final_task 的回写本就是函数最后一段,AutoProxy.update_config 是自包含函数,调用方(AutoProxy.py:499 / :522)后续流程不受影响。

顺带把重复出现四次的 Path.cwd() / f"data/{script_id}/{uid}/ConfigFile" 收进局部变量,只在本次改到的两个函数里做,没有扩散到别处。

本地验证

.venv/Scripts/python.exe -m pytest tests -q
682 passed, 3 skipped, 151 subtests passed in 7.68s

.venv/Scripts/python.exe -m ruff check app/task/general    # All checks passed

没有加自动化测试:按仓库 tests/AGENTS.md,bug 边界测试只在本地验证、不提交。

没有做真机手测:触发这三条路径需要装一个通用脚本并造出「用户还没跑过脚本设置」「ConfigPath 指向不存在的文件」两种状态,本地没有环境。改动是纯粹的前置判断,不改任何拷贝语义,但建议合并前由熟悉这块的人确认一下「源不存在时沿用脚本自身配置」这个取舍符合预期——这是我按 ScriptConfig.set_general 的既有行为推定的,issue 里也是这么判的。

请审阅

@DLmaster361 这块是你写的。确认后请你自行合并,我不代合。

Sourcery 总结

在通用脚本配置同步路径中安全处理缺失的配置源。

错误修复:

  • 防止在通用脚本配置导入和导出过程中因缺少配置源而引发错误;当没有可用源时,保留现有的用户配置。

功能增强:

  • 改进配置复制处理,为基于文件的配置更新提供清晰易懂的警告,并可靠地创建目标目录。
Original summary in English

Summary by Sourcery

Handle missing configuration sources safely across general-script configuration synchronization paths.

Bug Fixes:

  • Prevent missing configuration sources from raising errors during general-script configuration import and export, preserving existing user configuration when no source is available.

Enhancements:

  • Improve configuration copy handling with readable warnings and reliable destination directory creation for file-based configuration updates.

同一套「按 ConfigPathMode 在两个目录间拷贝」的逻辑在通用脚本里写了 4 份,
只有 ScriptConfig.set_general 一份做了存在性判断(e457f397 加的),另外三处
没有同步,源不存在就直接抛 FileNotFoundError 并把任务判成异常。

- AutoProxy.set_general: 补齐判断,源不存在时沿用脚本自身配置,与
  ScriptConfig.set_general 行为一致
- AutoProxy.update_config / ScriptConfig.final_task: 回写方向源不存在时跳过
  并给出可读提示,且提前返回以免把已有备份先删掉
- AutoProxy.update_config 的 File 分支补 mkdir(parents=True),Folder 分支靠
  copytree 自建目录本就不受影响

Closes AUTO-MAS-Project#533

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
@qiyinxi qiyinxi added bug Something isn't working Sentry daily Sentry daily issues labels Sep 8, 2026
@qiyinxi
qiyinxi requested a review from DLmaster361 September 8, 2026 08:28
@qiyinxi qiyinxi added the Sentry daily Sentry daily issues label Sep 8, 2026

@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 4 days and 3 hours by commenting @sourcery-ai review. Upgrade to get a review now.

@sourcery-ai

sourcery-ai Bot commented Sep 8, 2026

Copy link
Copy Markdown

审查者指南

该 PR 为所有剩余的通用脚本配置复制路径添加了缺失的源存在性检查。现在,如果用户配置缺失,则回退到脚本配置;如果脚本配置缺失,则跳过写回操作,同时不会删除现有的用户备份;此外,文件模式的目标路径也会在复制前创建。

带源存在性检查的通用脚本配置同步时序图

sequenceDiagram
    participant Script as ScriptConfig
    participant Proxy as AutoProxy
    participant UserConfig as UserConfigDir
    participant ScriptPath as ScriptConfigPath

    Script->>UserConfig: set_general()
    alt user config exists
        UserConfig-->>Script: exists
        Script->>ScriptPath: shutil.copy or shutil.copytree
    else user config missing
        UserConfig-->>Script: missing
        Script-->>Script: preserve script configuration
    end

    Proxy->>ScriptPath: update_config() / final_task()
    alt script config missing
        ScriptPath-->>Proxy: missing
        Proxy-->>Proxy: log warning and return
    else script config exists
        Proxy->>UserConfig: remove or create destination
        Proxy->>UserConfig: shutil.copy or shutil.copytree
    end
Loading

文件级变更

变更 详细信息 文件
防止源路径缺失时配置复制操作失败,或删除现有的用户备份。
  • 当脚本配置不存在时,跳过脚本到用户的写回操作并记录警告。
  • 在删除用户配置目录之前执行源检查,以保留现有备份。
  • 在复制之前,为文件模式的写回操作创建目标目录。
app/task/general/AutoProxy.py
app/task/general/ScriptConfig.py
提高用户到脚本的配置加载对用户配置缺失情况的容错能力。
  • 在复制之前,分别检查文件夹和文件源。
  • 当不存在用户专属源时,保留脚本自身的配置并发出警告。
app/task/general/AutoProxy.py
应用与此修复相关的版本元数据更新。
  • 更新记录的应用版本。
res/version.json

可能关联的问题


提示和命令

与 Sourcery 交互

  • 触发新的审查: 在拉取请求中评论 @sourcery-ai review
  • 继续讨论: 直接回复 Sourcery 的审查评论。
  • 从审查评论生成 GitHub issue: 回复审查评论,请 Sourcery 根据该评论创建 issue。你也可以使用 @sourcery-ai issue 回复审查评论,以根据该评论创建 issue。
  • 生成拉取请求标题: 在拉取请求标题的任意位置写入 @sourcery-ai,即可随时生成标题。你也可以在拉取请求中评论 @sourcery-ai title,以随时生成或重新生成标题。
  • 生成拉取请求摘要: 在拉取请求正文中任意位置写入 @sourcery-ai summary,即可在指定位置随时生成 PR 摘要。你也可以在拉取请求中评论 @sourcery-ai summary,以随时生成或重新生成摘要。
  • 生成审查者指南: 在拉取请求中评论 @sourcery-ai guide,即可随时生成或重新生成审查者指南。
  • 解决所有 Sourcery 评论: 在拉取请求中评论 @sourcery-ai resolve,即可解决所有 Sourcery 评论。如果你已经处理完所有评论且不想再看到它们,此功能会很有用。
  • 忽略所有 Sourcery 审查: 在拉取请求中评论 @sourcery-ai dismiss,即可忽略所有现有的 Sourcery 审查。如果你希望使用新的审查重新开始,这一功能尤其有用——别忘了评论 @sourcery-ai review 来触发新的审查!

自定义你的使用体验

访问你的控制面板以:

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

获取帮助

Original review guide in English

Reviewer's Guide

The PR adds missing source-existence guards to all remaining general-script configuration copy paths. Missing user configuration now falls back to the script’s configuration, while missing script configuration skips write-back without removing existing user backups; file-mode destinations are also created before copying.

Sequence diagram for guarded general-script configuration synchronization

sequenceDiagram
    participant Script as ScriptConfig
    participant Proxy as AutoProxy
    participant UserConfig as UserConfigDir
    participant ScriptPath as ScriptConfigPath

    Script->>UserConfig: set_general()
    alt user config exists
        UserConfig-->>Script: exists
        Script->>ScriptPath: shutil.copy or shutil.copytree
    else user config missing
        UserConfig-->>Script: missing
        Script-->>Script: preserve script configuration
    end

    Proxy->>ScriptPath: update_config() / final_task()
    alt script config missing
        ScriptPath-->>Proxy: missing
        Proxy-->>Proxy: log warning and return
    else script config exists
        Proxy->>UserConfig: remove or create destination
        Proxy->>UserConfig: shutil.copy or shutil.copytree
    end
Loading

File-Level Changes

Change Details Files
Prevent configuration copy operations from failing or deleting existing user backups when the source path is missing.
  • Skip script-to-user write-back with a warning when the script configuration does not exist.
  • Perform the source check before removing the user configuration directory, preserving existing backups.
  • Create the destination directory for file-mode write-back before copying.
app/task/general/AutoProxy.py
app/task/general/ScriptConfig.py
Make user-to-script configuration loading resilient to missing per-user configuration.
  • Check folder and file sources independently before copying.
  • Retain the script’s own configuration and emit a warning when no user-specific source exists.
app/task/general/AutoProxy.py
Apply a version metadata update associated with the fix.
  • Update the recorded application version.
res/version.json

Possibly linked issues


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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working Sentry daily Sentry daily issues

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant