Skip to content

refactor: 近一周 PR 技术债清扫——构建产物出库+死代码移除(行为保持,ADR-0059/0073 口径不变) - #393

Merged
randypanding merged 1 commit into
mainfrom
refactor/tech-debt-2026-08-26
Aug 26, 2026
Merged

refactor: 近一周 PR 技术债清扫——构建产物出库+死代码移除(行为保持,ADR-0059/0073 口径不变)#393
randypanding merged 1 commit into
mainfrom
refactor/tech-debt-2026-08-26

Conversation

@randypanding

@randypanding randypanding commented Aug 26, 2026

Copy link
Copy Markdown
Contributor

Card: #392
ADR: ADR-0059(SLI 口径零改动)、ADR-0073(metrics/dashboard 纯函数契约零改动)、ADR-0055(入口协议 C1 面惯例)

改了什么(近一周 PR 技债清扫——行为保持)

来源:2026-08-19 起 #176..#390 约 100 个 PR 全量复查后的机械技术债(每处均机械可证):

  1. 误提交构建产物出库(行为无影响):4 个 .pyc 出库 + .gitignore__pycache__/*.pyc)防复发

  2. governance/metrics.pyfeat(dashboard): 指标采集器——逃逸双窗/台账/签署/误放行(W5-C4 .github#227,ADR-0073) #253 落位,ADR-0073 计算库):删除恒未读局部 val = {"current": cur, "previous": prev}——AST 扫描确认无引用,纯计算路径零变化

  3. governance/dashboard-update.pyfeat(dashboard): 北极星对置顶组装+成本快照+human-brief 呈现(W5-C4 .github#227,ADR-0073) #254/W5-C4: 度量 dashboard 完整版(北极星对同屏 + 四类指标 + 板字段) #227 体系):删除 TemporaryDirectory with 块内恒真防御 if not os.path.isdir(td): return None——上下文管理器保证目录存在,属死代码

  4. scripts/sli-report.shfeat: 自动合并 SLI 周报 + 每周抽样审计(P3-4,.github #98,ADR-0059) #184/fix: SLI 周报标签兜底(.github #98,ADR-0059) #197/fix: SLI 去标签依赖(.github #98,ADR-0059) #198/feat: SLI escape_rate 排除演练数据(.github #98,ADR-0059) #203/pm(P1-C4): IR-0005 验收报告 + 断链修复 + cnb-bridge bootstrap 豁免(ADR-0085) #357 落位,ADR-0059 口径):

    • seed = int(...) if False else hash(...) → 死条件臂移除(表达式语义逐字等价)
    • || die "周报 issue 创建失败" \n || gh issue create ... 残串清理:\n 是字面转义'n'实参、尾段在 die 无条件 exit 2 下不可达——成功/失败出口均不变

明确不碰

gate/conductor/drift 语义、workflow YAML、REPOS.yaml 与治理数据文件、pinned SHA、断言数量、.trae-html-share-packages 备份产物(ADR-0094 登记)。diff 共 8 文件 / +5 −5(另 4 个二进制 .pyc 删除),无重排格式 churn。

怎么验证

  • python -m compileall 触达文件全过(唯一失败=既有缺陷,见下"另行申报")
  • bash -n scripts/sli-report.sh 及 gate.yml 同款九脚本清单全绿
  • governance/tests/test-*.sh 10 套自测全过(board-fields 17 项 / cost-llm-channel 6/6 / drill 5 套 / ir0002 5/5 / w1c5 / metrics-groups 9/9 / metrics-northstar 10/10 / metrics-policy / metrics-wiring 20 项 / navigation 35 项)
  • bash scripts/sli-report.sh --self-test PASS=8 FAIL=0
  • yaml 解析 OK;远端 tree SHA 6336b276… 与本地已验 commit 的 tree 逐字节一致(Git Data API 发布,blob SHA 本地 hash-object 校验一致)

另行申报(发现但不动——非行为保持范畴)

  1. scripts/escalate-test-issue.py 存在 Python SyntaxError:L81 起 f-string 含未转义 ASCII 双引号("发现错误"),整文件不可解析,create/resolve 两子命令任何调用即启动崩溃(feat(ISSUE-263): W4-C1 conductor T5/T6 路由 (#282) #306/feat(ISSUE-263): W2-C4 holdout 注册/校验与上报回路 + W4-C1 T5/T6 路由 (#276) #307 引入路径)。修复属于行为变更,须单独卡评审。
  2. scripts/g060-escalation.py L164 与前者 L191 的 dead-man 评论首字符为字面 @$<owner>(f-string 内多余 $),提醒不会 @ 生效。
  3. sli-report.sh 抽样 seed 用加盐 hash()(进程级随机),与注释"seed=ISO 周(可复现)"不符——换稳定 seed 会改变抽样结果,属行为变更。

风险 / 回滚

回滚 = revert 单 squash commit。无 schema/口径/workflow 变更。

Copilot AI lite review requested due to automatic review settings August 26, 2026 19:23

Copilot AI 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.

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

@coderabbitai

coderabbitai Bot commented Aug 26, 2026

Copy link
Copy Markdown

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro Plus

Run ID: 8557b6d5-09ac-4eaf-a64f-e858c168bede

📥 Commits

Reviewing files that changed from the base of the PR and between 390828a and 85de256.

⛔ Files ignored due to path filters (4)
  • scripts/__pycache__/adr_index_map.cpython-311.pyc is excluded by !**/*.pyc
  • specs/IR-0004/suite/__pycache__/test_spec_ir0004.cpython-311-pytest-9.1.1.pyc is excluded by !**/*.pyc
  • specs/IR-0004/suite/__pycache__/test_spec_ir0004.cpython-311.pyc is excluded by !**/*.pyc
  • specs/ISSUE-263/suite/__pycache__/test_ir263_artifacts.cpython-311.pyc is excluded by !**/*.pyc
📒 Files selected for processing (4)
  • .gitignore
  • governance/dashboard-update.py
  • governance/metrics.py
  • scripts/sli-report.sh
💤 Files with no reviewable changes (2)
  • governance/metrics.py
  • governance/dashboard-update.py

Included review availability: Your plan provides up to 10 included reviews per hour; 2 remain after this review.


📝 Walkthrough

Walkthrough

本次变更新增 Python 编译产物忽略规则,移除治理脚本中的冗余逻辑,并修正 SLI 周报脚本的抽样种子和 issue 创建失败处理。

Changes

维护性清理

Layer / File(s) Summary
Python 构建产物忽略规则
.gitignore
新增 __pycache__/ 目录和 *.pyc 文件的忽略规则。
治理脚本冗余逻辑清理
governance/dashboard-update.py, governance/metrics.py
移除 metering 账本目录的提前返回检查,并删除 _guard_status 中未使用的 val 局部变量。
SLI 报告脚本流程修正
scripts/sli-report.sh
移除抽样种子生成中的无效条件表达式。周报 issue 创建失败时直接执行 die,并删除重复命令和异常续行。

Suggested labels: tech-debt

🚥 Pre-merge checks | ✅ 1 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Title check ⚠️ Warning 标题使用了合规的 refactor: 前缀,且内容与技术债清理变更相关。但标题长度为 61 个字符,超过 50 个字符限制。 将标题缩短至 50 个字符以内,同时保留 refactor: 前缀和主要变更信息。
✅ Passed checks (1 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
  • Fix all pre-merge checks with AI
✨ Finishing Touches 💡 1
🛠️ Fix failing CI checks 💡
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch refactor/tech-debt-2026-08-26

Comment @coderabbitai help to get the list of available commands.

@qodo-code-review

Copy link
Copy Markdown

PR Summary by Qodo

清理构建产物与治理脚本死代码

✨ Enhancement ⚙️ Configuration changes 🕐 10-20 Minutes

Grey Divider

AI Description

• 移除误提交的 Python 编译缓存,并阻止其再次入库。
• 删除指标、仪表盘和 SLI 报告中的不可达或未使用代码。
• 保持 ADR-0059/0073 指标口径和运行行为不变。
Diagram

graph TD
  Repo["Repository"] --> Ignore["Ignore rules"] --> Cache["Python caches"]
  Repo --> Metrics["Metrics library"] --> Contract["Unchanged contracts"]
  Repo --> Dashboard["Dashboard updater"] --> Contract
  Repo --> SLI["SLI reporter"] --> Contract
Loading
High-Level Assessment

当前按点清理是最佳方案:每处删除都可由语言或上下文管理器语义直接证明等价,同时避免把稳定随机种子、既有语法错误等行为变更混入本次重构。更大范围的格式化或静态检查器接入会扩大审查面,不适合此行为保持 PR。

Files changed (4) +5 / -5

Refactor (3) +2 / -5
dashboard-update.py移除临时目录恒真检查 +0/-2

移除临时目录恒真检查

• 删除 'TemporaryDirectory' 上下文内不可能失败的目录存在性分支。账本下载、聚合和错误处理路径保持不变。

governance/dashboard-update.py

metrics.py删除未使用的护栏局部变量 +0/-1

删除未使用的护栏局部变量

• 移除逃逸率护栏中从未读取的 'val' 字典。当前窗和上一窗的判定与消息格式保持不变。

governance/metrics.py

sli-report.sh清理 SLI 周报死分支与不可达命令 +2/-2

清理 SLI 周报死分支与不可达命令

• 将恒假条件表达式简化为原有哈希种子路径,并明确记录其进程级加盐特性。移除 'die' 退出后的不可达 issue 创建残串,保持成功和失败出口不变。

scripts/sli-report.sh

Other (1) +3 / -0
.gitignore忽略 Python 编译缓存 +3/-0

忽略 Python 编译缓存

• 新增 '__pycache__/' 与 '*.pyc' 规则,防止本地编译和测试生成的缓存再次提交。

.gitignore

@qodo-code-review

Copy link
Copy Markdown

Code Review by Qodo

🐞 Bugs (0) 📘 Rule violations (1) 📜 Skill insights (0)

Grey Divider


Informational

1. ADR-0082 sign-off missing 📘 Rule violation § Compliance
Description
The PR deletes files under specs/*/suite/** but its description contains no explicit completed
red-team audit sign-off for ADR-0082. Even though the deleted files are build artifacts, the
checklist applies to deleted files under spec or test-design paths.
Code

specs/IR-0004/suite/pycache/test_spec_ir0004.cpython-311-pytest-9.1.1.pyc[1]

-
Relevance

● Weak

Recent exact precedents reject this sign-off finding for the same deleted IR-0004/ISSUE-263 .pyc
artifacts.

PR-#338
PR-#336

ⓘ Recommendations generated based on similar findings in past PRs

Evidence
Compliance rule 2855405 requires explicit ADR-0082 red-team audit confirmation whenever a PR
modifies, adds, or deletes files under spec or test-design paths. The diff deletes bytecode files
under specs/*/suite/**, the repository documents these suite paths as red-team guarded, and the
supplied PR description has no completed ADR-0082 audit sign-off.

Rule 2855405: Require ADR-0082 red team audit sign-off for spec and test design changes
AGENTS.md[47-47]

Agent prompt
The issue below was found during a code review. Follow the provided context and guidance below and implement a solution

## Issue description
The PR changes files under `specs/*/suite/**` without an explicit completed ADR-0082 red-team audit sign-off in the PR metadata.

## Issue Context
The changes delete generated Python bytecode rather than alter test behavior, but compliance rule 2855405 explicitly includes deleted files under spec or test-design paths. Add a completed red-team audit statement to the PR description or obtain an equivalent documented red-team approval.

## Fix Focus Areas
- specs/IR-0004/suite/__pycache__/test_spec_ir0004.cpython-311-pytest-9.1.1.pyc[1-1]

ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools


Grey Divider

Context sources
✅ Compliance rules (platform): 22 rules
Review mode: ⚖️ Balanced: Although the diff is small and mostly cleanup, it modifies runtime Python and a reporting shell script on governance/metrics paths, with multiple independent edits and explicitly noted behavior-sensitive seed and error-path semantics; a careful single-pass review is warranted.

Grey Divider

Tip of the day
💡 Did you know, you can start a comment with 'qodo' or '@qodo' to chat about any finding

More tips ↗ | Customize Qodo ↗ | Qodo docs ↗

Grey Divider

Qodo Logo

adversary-gate(ADR-0067/0082)对 specs/** 任意变更(含缓存删除)
fail-closed 要求 survived 审计。本卡为技术债清扫而非 spec 套件变更,
按保守原则不触发该审计面:specs/*/suite/__pycache__/*.pyc 暂留库,
作为已申报债务记录于 issue #392 与 PR 描述。

Card: #392

refactor: 构建产物出库 + 死代码移除(行为保持;近一周 PR 技债清扫)

来源 PR 复查发现物(#176..#390 全量复查):
- 误提交 .pyc 出库:scripts/__pycache__(#230 引入)、
  specs/IR-0004/suite/__pycache__(#338)、specs/ISSUE-263/suite/__pycache__(#336);
  附 .gitignore(__pycache__/、*.pyc)防复发
- governance/metrics.py:移除恒未读局部 val(#253 引入,ADR-0073 计算库)
- governance/dashboard-update.py:TemporaryDirectory with 块内 isdir 恒真检查删除
- scripts/sli-report.sh:X if False else 死分支简化 + die 后不可达 OR 链残串清理
  (#184/#197-203/#357 落位文件,ADR-0059 口径零改动)

不改动:gate/verdict/drift 语义、workflow YAML、REPOS.yaml/治理数据、pinned SHA。

验证:python -m compileall(除既有 escalate-test-issue.py 语法错,
见 issue 392 另报);bash -n 全绿;governance/tests/test-*.sh 10 套全过;
sli-report --self-test PASS=8 FAIL=0;yaml 解析 OK。

Card: #392
ADR: ADR-0059(SLI 口径保持)、ADR-0073(metrics/dashboard 纯函数契约保持)


(注:specs/*/suite/__pycache__/*.pyc 经重估移出本 PR——adversary-gate 对 specs/** 变更类 fail-closed 要求 survived 审计;作为已申报债务留档 issue #392 与 PR 描述。)
@randypanding
randypanding force-pushed the refactor/tech-debt-2026-08-26 branch from 85de256 to 0002321 Compare August 26, 2026 19:29
@randypanding

Copy link
Copy Markdown
Contributor Author

重估记录:首版包含 specs/*/suite/pycache 的 .pyc 出库,触发 adversary-gate(ADR-0067/0082)对 specs/** 变更类的 fail-closed 阻断。按保守原则将 specs/** 路径移出本卡(分支已重写为 0002321,tree 7f0228f);该批缓存文件保留在库并作为债务留档于 #392

@randypanding
randypanding merged commit f526751 into main Aug 26, 2026
18 checks passed
@randypanding
randypanding deleted the refactor/tech-debt-2026-08-26 branch August 26, 2026 19:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants