feat(governance): patrol 政策文件(W3-C2 .github#219,ADR-0065) - #241
Conversation
patrol.yaml——patrol 巡逻服务阈值唯一真源(ADR-0065 决策 3): 频控(每仓每小时/每日开单上限)/observation 两次独立升级/yield 降频阈值 (SNR<0.05 收敛 1 单/日+needs-human)/三源参数(LLM 走 metering wrapper, 无凭据诚实降级)/issue_mode=draft shadow 起步/权限声明(allowed 只含 read-run+open-issue;forbidden 显式列 push/pr-write/label-write—— patrol.py 加载时断言,缺声明 fail-closed 拒跑)。 执行面:CI-Workflows pipeline/patrol/patrol.py(.github/workflows/patrol.yml 每日 02:43 UTC 拉取本文件后巡逻,拉取失败 fail-closed)。阈值改动=C1 变更 须引用 ADR。 Card: #219
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Pro Plus Run ID: 📒 Files selected for processing (1)
Included review availability: Your plan provides up to 10 included reviews per hour; 1 remains after this review. 📝 WalkthroughWalkthroughChanges巡逻政策
Suggested labels: Merge Risk: 🔵 Low · up to This PR adds a localized centralized patrol policy file, but merge should wait for the required C1 owner-only approval, valid ADR-0065 reference, and passing governance check; no broader implementation risk is indicated. 🚥 Pre-merge checks | ✅ 1 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (1 passed)
✨ Finishing Touches🧪 Generate unit tests (beta)
Comment |
PR Summary by QodoAdd versioned patrol policy file for rate limiting, yield, and permissions
AI Description
Diagram
High-Level Assessment
Files changed (1)
|
There was a problem hiding this comment.
Pull request overview
Adds a new, centralized governance policy file for the “patrol” service so rate limiting, yield/downshift thresholds, observation escalation, and permission declarations are versioned and adjustable via C1 policy changes (per ADR-0065 / .github#219), instead of code changes.
Changes:
- Introduces
governance/policy/patrol.yamlas the single source of truth for patrol thresholds and operational limits. - Declares patrol’s allowed/forbidden permission set in policy (intended for fail-closed validation by the patrol loader).
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
| # 开单形态:draft=shadow 起步(bug issue 草稿落 artifact,零线上噪音——W3-C2 | ||
| # 演习即此形态);切 gh(真开单+bug 标签)= C1 政策变更,由 owner 按演习 yield | ||
| # 数据拍板。开单必附 trace+指纹(AC-1),复现判定走 ADR-0064 三值协议。 |
Code Review by Qodo
1. Policy invariants unvalidated
|
| observation: | ||
| # 宪法 §3 钉死:LLM"看着不对"只进 observation 桶,两次独立出现才升级开单; | ||
| # 独立=不同 run 且不同 seed(防同 run 重复采样灌水)。值固定 2——放宽须先修 ADR | ||
| escalate_after_independent: 2 | ||
|
|
There was a problem hiding this comment.
1. Policy invariants unvalidated 🐞 Bug ☼ Reliability
该 PR 引入新的阈值真源 patrol.yaml,但本仓 gate 只做 yaml.safe_load 的语法解析,不校验必须字段/类型/不变量,导致未来任何结构性误改都可能在本仓 CI 放行、到下游 patrol 执行时才 fail-closed 停巡。尤其是文件内声明了硬约束(如 observation.escalate_after_independent 固定为 2、permissions.forbidden 必须存在),但当前没有机器执行的本仓侧断言。
Agent Prompt
## Issue description
`governance/policy/patrol.yaml` 作为阈值唯一真源引入后,本仓 CI 目前仅验证“YAML 可解析”,没有任何结构/类型/不变量校验。这样未来 PR 可能把关键字段拼错、删段、改类型(例如把数字写成字符串、漏掉 permissions.forbidden)而在本仓 gate 放行,直到下游 patrol 引擎运行时才 fail-closed(等价于“静默停巡直到有人注意到”)。
## Issue Context
- gate.yml 的“YAML 全量解析”仅调用 `yaml.safe_load` 并打印 OK,不做结构断言。
- patrol.yaml 自身注释声明了必须满足的硬约束(如 observation 固定值、permissions 必须带 forbidden),但注释不是机器可执行约束。
## Fix Focus Areas
- .github/workflows/gate.yml[52-65]
- governance/policy/patrol.yaml[29-33]
- governance/policy/patrol.yaml[59-65]
## Implementation sketch
1. 新增一个轻量校验脚本(例如 `scripts/validate_patrol_policy.py`),读取 `governance/policy/patrol.yaml` 并做至少以下断言(fail-closed 非 0 退出):
- 顶层必须是 dict;`schema`/`version` 存在且为期望值(如果 `schema` 是合同的一部分)。
- 必须字段存在:`targets`(list)、`rate_limit`、`observation`、`yield`、`sources`、`issue_mode`、`permissions`。
- 类型断言:数值字段为 int/float、`permissions.allowed/forbidden` 为 list[str]。
- 不变量断言:`observation.escalate_after_independent == 2`;`permissions.forbidden` 必须非空;可选地断言 `issue_mode` ∈ {draft, gh}。
2. 在 gate.yml 的 YAML 解析步骤后追加一步运行该脚本,确保 policy 结构性错误在本仓 PR 阶段被拦下。
3.(可选)将校验范围扩展为未来可能新增的 `governance/policy/*.yaml` 的结构校验,但本 PR 至少要把新引入的 patrol policy 纳入。
ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools
动机
ADR-0065 决策 3:patrol 频控/降频/开单上限/权限声明版本化集中此文件(阈值唯一真源)——频控过松刷屏/过紧漏报的调参走 C1,不走代码。本 PR 是 W3-C2 的政策半件(执行引擎在 CI-Workflows
pipeline/patrol/,PR #57)。变更清单
governance/policy/patrol.yaml(仅 append 新文件,不动既有政策文件)AC 映射(.github#219)
rate_limit.max_issues_per_repo_per_hour: 2/per_day: 6——指纹去重之外的第二道闸(突发缺陷潮按仓限速,deferred 下一窗口再攻击)。CI-Workflows 测试test_throttle_downshift.py断言本配置被消费(非硬编码)。yield.snr_threshold: 0.05/snr_window_issues: 20/downshift_daily_issue_cap: 1——信噪比(真 bug/开单数)低于阈值自动降频(收敛而非停巡)+ needs-human。observation.escalate_after_independent: 2——宪法 §3 钉死两次独立(不同 run 且不同 seed);patrol.py 加载时断言此值为 2,放宽须先修 ADR。permissions.allowed: [read-run, open-issue];forbidden: [push, pr-write, label-write, code-write]——声明性复核(执行面在 CI-Workflows patrol.yml job 级 permissions),patrol.py 缺 forbidden 声明即 fail-closed 拒跑。关键决策记录(详见文件内注释)
issue_mode: draft(shadow 起步):bug issue 落草稿 artifact,零线上噪音;切gh真开单 = C1 政策变更,由 owner 按演习 yield 数据拍板。targets当前只挂 CI-Workflows demo 靶场(blastRadius 可控);新仓接入 = targets 追加条目(C1)。sources.llm。测试方法
patrol.py run --policy governance/policy/patrol.yaml …→llm=skipped-no-creds opened=2 deferred=5(频控 2/小时 + LLM 诚实降级实证;详见 CI-Workflows PR#57 body)风险与回滚
targets置空或 CI-Workflows 摘除 patrol.yml schedule 即停(ADR-0065 回滚条款:cron 停即静默,台账留存无害)Card: #219
Summary by CodeRabbit