Merged
fix: #4066 autopilot custom_fields 写侧保留前缀校验 + 保留语义收窄 + 注入日志收敛 #2062
grape_botAdd on 2 hours ago
fix: #4066 autopilot custom_fields 写侧保留前缀校验 + 保留语义收窄 + 注入日志收敛 #2062
Merged
grape_botAdd on 2 hours ago
grape_bot
grape_botCollaborators
2 hours ago

概述

修复 Issue #4066:autopilot 定时任务 custom_fields 写侧不校验保留前缀,非法配置落库后被执行侧静默丢弃(生产 1 小时 7 条 custom env ... rejected WARNING,GRAPE_ANALYSIS_MODE/GRAPE_ORG_ID/GRAPE_MANAGED_BY 静默失效)。

改动

  • src/kernel/scene_custom_env.py:新增 _PLATFORM_MANAGED_ENV 白名单(三精确名),is_reserved_name() 由「任何 GRAPE_ 前缀」收窄为「GRAPE_ 且不在白名单」;GRAPE_SESSION_TOKEN/GRAPE_API_TOKEN/GRAPE_WORK_BRANCH 等仍保留,BOT_/USER_ 不变。
  • src/domains/mgmt/routes/autopilot.py:新增 _validate_custom_fields(),create/update 落库前复用 custom_env_error(),非法/保留名一次性 400 汇总回显(invalid_names),不落库。
  • src/domains/runtime/engine/scheduler.py:注入循环日志由逐条 WARNING 收敛为单条 info 汇总(injected/skipped/names);平台已注入的键不被 custom_fields 覆盖。
  • src/domains/runtime/pipeline/event_pipeline.py:场景 custom_fields 注入同口径平台优先(GRAPE_ORG_ID 不被覆盖)。
  • src/domains/mgmt/migrations/autopilot_custom_fields_cleanup.py + src/api/db_setup.py:注册式迁移 202611240001(kind=cleanup,幂等 + post_check)清理 autopilot_tasks.custom_fields 与 devops_pipeline_scene.advanced_options.custom_fields 的存量非法条目。
  • docs/issue-4066/{spec,plan,task}.md 与 docs/weekly-06/scene-env-naming-constraints-doc.md 同步规则说明。

测试

  • 新增 4 个测试文件(kernel 白名单 / mgmt 写侧 400 / runtime 注入日志汇总 / mgmt 迁移清理),pytest 65 passed(含既有 org_analysis、迁移守卫回归)。
  • 相邻回归:tests/runtime/test_p8_autopilot_issue_ref.py、test_issue_486_autopilot_engine_filter.py、test_issue_3800_autopilot_offline_backoff.py、tests/mgmt/test_autopilot_*、tests/api/test_issue_536_migrations.py、迁移域归属/前端 ratchet 守卫共 121 passed。
  • 已知非本次引入的基线失败(已在 origin/arch-weekly-11-ljt 同环境复现):test_issue_1011_autopilot_uid.py 3 例、test_issue_1811_*::test_global_bot_fallback... 1 例(域名库 registry)、test_autopilot_exec_agent_task_id.py::TestMigration 4 例(函数名漂移)、test_scene_env.py::test_secret_suffix_name_explicit_false_stays_plain 1 例。

自审查 / 开源前置

  • 5 轴自审查通过(正确性/可读性/架构/安全/性能)。
  • 增量敏感扫描 0 命中;无关文件拦截 0 个(仅本次需求文件)。
likedislike
Pull Request has been successfully merged by 吕军涛.
(Thank you for grape_bot's contribution.)
grape_botgrape_botCollaborators
2 hours ago Associated issue: [P3][缺陷] 定时任务 custom_fields 写侧不校验保留前缀:GRAPE_ANALYSIS_MODE/GRAPE_ORG_ID/GRAPE_MANAGED_BY 每轮被执行侧静默丢弃(7 条/小时)
grape_bot
grape_botCollaborators
2 hours ago Comments:

[QA Agent] PR #2062 审查报告

关联 Issue

  • #4066 — [P3][缺陷] 定时任务 custom_fields 写侧不校验保留前缀(A2A 触发,首次审查)

变更摘要

  • 14 个文件,+1071 / -12(基线 arch-weekly-11-ljt,head e4bb6bab,6 个提交)
  • 源码 6 处:scene_custom_env.py(白名单收窄)、routes/autopilot.py(写侧 400)、scheduler.py(日志收敛)、event_pipeline.py(平台键优先)、迁移 autopilot_custom_fields_cleanup.py + db_setup.py 注册;测试 4 个新文件;文档 4 处

代码审查

结论: ✅ 通过

已按 5 轴逐项核对,并实测复跑(非仅看 PR 描述):

  • 正确性:is_reserved_name() 17 组边界用例(白名单 3 精确名放行、GRAPE_SESSION_TOKEN/GRAPE_API_TOKEN/GRAPE_WORK_BRANCH/GRAPE_UNLISTED_FLAG 等 8 项仍保留、BOT_/USER_/显式集合不变、小写仍报「大写」错)本地脚本 0 失败;新增 4 个测试文件实跑 47 passed;相邻回归(p8/486/3800 autopilot 3 文件)26 passed;迁移守卫(track/domain/536)65 passed
  • 架构:校验单一口径复用 custom_env_error(),写侧/迁移/场景三处同源;SQL 住 mgmt 域 migrations(table_ownership 核对:autopilot_tasks/devops_pipeline_scene 均属 mgmt,跨域守卫 P0-2 合规)
  • 安全:白名单 frozenset 三精确名防前缀放水;执行侧新增 name in env_extra 跳过使平台注入键(如 GRAPE_ORG_ID)不可被任务/场景 custom_fields 覆盖(提权边界已实测:test_platform_injected_key_not_overridden 过);日志仅汇总变量名不含值
  • 性能/可读性:注入循环 O(n) 不变;迁移幂等 + post_check 不盖章重试,符合 #3648 约定
  • 已知基线失败 test_scene_env.py::test_secret_suffix_name_explicit_false_stays_plain 在基线 7cf5d53f 上同样失败(PR 未引入,PR 描述披露属实)
级别 文件 行号 问题 建议
—(无 Critical/Required) — — — —

次要观察(不阻塞,供参考):

  • routes/autopilot.py:_validate_custom_fields 对非 dict 条目静默跳过(continue),而迁移清理 is_invalid_custom_field 把非 dict 判非法剔除——写侧比迁移口径略宽;已有测试锁定该语义(脏条目不阻塞保存、迁移侧剔除),可接受
  • scheduler.py 汇总日志 skipped_names 会打印被拒变量名(不含值),如 GRAPE_API_TOKEN 等敏感名本身出现在 info 日志——名称非机密,风险低,仅提示

工作流审查(Agent Work Loop)

结论: ✅ 健康

维度 证据状态 发现
任务理解 observed docs/issue-4066/spec.md 需求/成功标准/Scope 与 Issue 验收逐条对应
受控执行 observed 6 提交粒度清晰(写侧→日志→迁移→文档→复用收敛),全部改动均在 spec In Scope 内,无越界文件
变更验证 observed 4 新测试文件 + 相邻回归 + 迁移守卫,本地全部复跑通过;基线失败已披露并独立复现
可靠交付 observed PR 描述结构完整(改动/测试/自审查/已知失败),mergeable=true
经验沉淀 observed docs/weekly-06/scene-env-naming-constraints-doc.md 同步白名单例外与新校验层行为
  • AGENTS.md/spec 顶层目录:仓库无 AGENTS.md 与 spec/(404 observed,本仓库以 docs/issue-* 承担),CI 门禁 .github/workflows(3 个 workflow 为定向冒烟,不覆盖本 PR 测试路径)→ 测试证据以本地实跑为准(已实跑)
  • 关联仓库联合审查(grape-admin):无对 #4066 的开放 PR,worktree 内无 custom_fields/GRAPE_ORG_ID 相关代码——本次改动不涉及该仓,无需联动

安全扫描

结论: ✅ 安全(敏感名仍全保留、值不进日志/评论、token 无泄漏、迁移 SQL 无外部输入注入面)

合并检查

  • ⚠️ 平台 merge_readiness:can_merge_check 未通过、必需评审人未指定(需在平台侧补齐后合入)
  • ✅ 测试已确认(本地实跑:新增 47 + 回归 91 passed,基线失败项与本 PR 无关)

结论

审查通过,无需修改项。请确认是否合入 PR #2062(合入后可安排部署验证迁移 202611240001 生效)。

likedislike
吕军涛吕军涛Collaborators
52 minutes ago Set songspace as merger
吕军涛吕军涛Collaborators
52 minutes ago Set songspace as approver
吕军涛吕军涛Collaborators
51 minutes ago Approval passed
吕军涛吕军涛Collaborators
51 minutes ago Closed associated issue
吕军涛吕军涛Collaborators
51 minutes ago Merged pull request