refactor: 近一周 PR 技术债清扫(行为保持) - #8
Conversation
清偿项(全部行为保持,裁决语义/退出码/错误通道零变化): - kernel.adjudicate:删除防重放段无操作的 try/except InfraError: raise 纯透传 包装(异常本就由函数级 infra 通道统一上报);防重放语义(seen ref + 台账) 与 CasConflict→noop/replay-detected 路径逐字节不变 - kernel.EXIT_CODE:改由 EXIT_ALLOW/EXIT_DENY/EXIT_INFRA 常量组装, 消除字面量双写(原三常量从未被引用,属死代码) - backend.LocalGitBackend:4 处重复的 subprocess.run(git -C …) 样板收敛为 _exec_git 单一入口;各调用方的异常包装与报错文案逐字保留 ("git 子进程失败"/"git rev-parse 失败"两通道不合并) - 魔法常量具名化:timeout=30×4 → GIT_TIMEOUT_SECONDS;重试 3 次/0.15s → LOCK_RETRY_MAX_ATTEMPTS / LOCK_RETRY_SLEEP_SECONDS - 函数内 import(time / urllib.request|error|parse)上提至模块顶部 (backend.py 是静态扫描白名单中的唯一网络模块,tests/test_no_llm.py 不受限) 不动项:#2 空树 SHA 链路与 _quote_ref_path refs/ 剥离逻辑零触碰; capabilities.yaml / AGENTS.md / ci.yml / README / tests 断言数量不减。 验证:python -m py_compile arbiter/*.py ✓; python -m unittest discover -s tests → 73 tests OK ×2 连跑; python -m arbiter.policy capabilities.yaml → POLICY-OK default-deny=verified。
PR Summary by QodoRefactor kernel and local Git backend without behavior changes
AI Description
Diagram
High-Level Assessment
Files changed (2)
|
|
Caution Review failedThe pull request is closed. ℹ️ Recent review info⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Pro Plus Run ID: 📒 Files selected for processing (2)
📝 WalkthroughWalkthrough本次变更统一本地Git子进程执行、超时和锁重试配置,并调整引用及提交检查路径。防重放台账现统一处理 ChangesGit执行与防重放
Suggested labels: ✨ Finishing Touches🧪 Generate unit tests (beta)
Comment |
Code Review by Qodo
1. Independent refactors bundled together
|
| def _exec_git(self, args, ident: bool = False, stdin: str | None = None): | ||
| """构造并执行 git 子进程,返回 CompletedProcess(不判 rc、不包装异常)。 | ||
|
|
||
| ident=True 时注入兜底 user.name/email。异常是否包成 InfraError 由各 | ||
| 调用方决定(只读探测与裁决路径的错误通道语义不同,故不在此统一)。 |
There was a problem hiding this comment.
1. Independent refactors bundled together 📘 Rule violation ⚙ Maintainability
The PR combines a LocalGitBackend subprocess abstraction with separate adjudication exception restructuring and exit-code mapping cleanup in kernel.py. These changes are not mechanically dependent and therefore exceed a single functional concern.
Agent Prompt
## Issue description
This PR bundles multiple independent refactoring concerns: Git subprocess consolidation in `backend.py`, plus adjudication exception-scope and exit-code mapping changes in `kernel.py`.
## Issue Context
PR Compliance ID 2908442 requires each PR to contain one functional concern. These edits can be reviewed and reverted independently and have no implementation dependency.
## Fix Focus Areas
- arbiter/backend.py[180-193]
- arbiter/kernel.py[28-30]
- arbiter/kernel.py[97-110]
ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools
| except InfraError: | ||
| raise | ||
| backend.create_ref(seen, marker) | ||
| except CasConflict: |
There was a problem hiding this comment.
2. Commit conflicts become replays 🐞 Bug ≡ Correctness
The flattened except CasConflict now also catches backend.create_commit(), so a commit-creation conflict is reported as replay-detected even though no seen ref was created. This silently drops the delivery instead of surfacing a backend failure for retry.
Agent Prompt
## Issue description
The replay handler now catches `CasConflict` from both commit creation and seen-ref creation, misclassifying commit failures as successful replay detection.
## Issue Context
Only a conflict while creating `refs/seen/...` proves that the delivery was previously processed. Restore the nested scope so `backend.create_commit()` remains outside the `CasConflict` handler, while `InfraError` continues to flow to the function-level infra channel.
## Fix Focus Areas
- arbiter/kernel.py[103-110]
ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools
近一周 PR 全量复读结论(#1–#7,全部已合并)
_quote_ref_path剥前缀逻辑与其 e2e 实证注释逐字保留清偿清单(行为保持)
kernel.adjudicate防重放段删除无操作的外层except InfraError: raise纯透传——异常本就由函数级 infra 通道上报;CasConflict→noop/replay-detected 判定不变kernel.EXIT_CODE改由EXIT_ALLOW/EXIT_DENY/EXIT_INFRA组装(三常量原本定义后从未被引用=死代码;现消除与映射表的双写)LocalGitBackend4 处重复的subprocess.run(["git","-C",…])样板收敛为_exec_git();各调用点异常包装与报错文案逐字保留("git 子进程失败"/"git rev-parse 失败"两通道不合并)timeout=30×4 →GIT_TIMEOUT_SECONDS;锁重试3次 /0.15s→LOCK_RETRY_MAX_ATTEMPTS/LOCK_RETRY_SLEEP_SECONDStime/urllib.*)上提模块顶部——backend.py 是 test_no_llm 白名单中唯一网络模块,静态断言不受影响明确不做
验证证据
python -m py_compile arbiter/*.py✓python -m unittest discover -s tests→ 73 tests OK ×2 连跑(含并发用例,无 flake)python -m arbiter.policy capabilities.yaml→ POLICY-OK commands=['/claim','/release','/retry','/trust-status'] default-deny=verifiedgit diff --stat→ 仅 arbiter/kernel.py + arbiter/backend.py 两文件,无 CRLF/格式噪音Summary by CodeRabbit