Files
dxdesigner-part-replacement/docs/superpowers/plans/2026-11-05-nonblocking-execution.md
T
阿白叔 5d461ffc6c
Core regression / Python core and release configuration (push) Failing after 27s
Core regression / JavaScript syntax (push) Successful in 3s
Core regression / Python core and release configuration (pull_request) Failing after 26s
Core regression / JavaScript syntax (pull_request) Successful in 3s
test: record software smoke and cover scoped retries in CI
2026-11-06 15:00:56 +08:00

208 lines
16 KiB
Markdown
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
# 非阻塞替换与问题轮次 Implementation Plan
> **For agentic workers:** REQUIRED SUB-SKILL: Use `superpowers:executing-plans` to implement one task at a time. All boxes are pending; do not infer implementation from this plan.
**Goal:** 细化现有执行账本,单项问题不拖住其他独立项/工程;首轮结束后按 Git 规则自动重试一次,剩余问题集中处理。
**Architecture:** ExecutionJournal 继续作为真实替换回执的唯一权威;新增记录仅表达问题分类、持久重试额度和调度阶段。每工程独立 CAD 会话、正常项复用、异常后重建;不确定项不重放,同工程后继项能否继续由强制工程健康证明决定。
**Tech Stack:** Python 3.12、SQLite、现有 COM/VBScript、PrivateDesktop/Job、PySide6/DSH;经验规则使用标准库 JSON,不新增 YAML 依赖。
**Spec:** [无人值守流水线设计](../specs/2026-11-04-radical-optimization-design.md);独立校验复用[校验设计](../specs/2026-11-05-independent-netlist-verification-design.md),但可选校验不得成为强制写入准入的替代品。
## Global Constraints
- 替换项仍是工程 × 图页 × 单条换料规则;身份复用 task_id/round_id/operation_key。
- 已 verified/no_match 的终态不可因重建队列、清理历史或校验失败降级为 pending。
- 重试额度按原 task_id/round_id/operation_key 持久保存,不能按新 attempt/generation 重置。
- 只有首轮可运行项全部处理完且未暂停,才消费可重试问题。
- 无规则、冲突规则、未知错误、不确定写入状态均不自动重放。
- 正常项复用该工程会话,切换工程不共享 CAD 会话;异常后只重建当前工程会话。
- 每项失败分类、每个资源释放和每次重试均留证;DSH 解释不构成授权。
## 依赖与交付
`E01 → E02 → E03`;`E01 → E04`;`E02/E04 → E05`;`E03/E05 → E06 → E07 → E08`。E04/E05 在同工程继续策略启用前共同验收。独立校验可先交付,不是 E01~E06 的上线前置。
新文件职责:`execution_problems.py` 保存分类/额度;`execution_problem_contract.py` 定义逻辑身份/分类;`experience_rules.py` 读取固定版本策略;`project_session_health.py` 核对现有强制证明;`problem_pass.py` 处理第二轮次。只新增这些现有模块没有承担的职责。
## E01:问题分类和依赖范围
**Files:** Create `src/dx_productivity/trial_task_center/execution_problem_contract.py`;Test `tests/v1_1/test_execution_problem_contract.py`。
**Interfaces:** `problem_key(attempt: JournalAttempt) -> tuple[str, str, str]` 返回 task/round/operation;`classify_problem(*, mutation_possible: bool, readback_verified: bool, retry_rule: dict | None) -> str` 返回 retryable/manual/uncertain。pending 后继项另有 hold_reason;失败和未执行不能混为一类。
- [ ] 写不同 attempt/generation 同逻辑项仍共用额度键、跨轮次不同键、不确定风险不能被规则降为 retryable 的失败测试。
```python
def test_new_attempt_does_not_create_new_retry_budget():
from dx_productivity.trial_task_center.execution_journal import JournalAttempt
from dx_productivity.trial_task_center.execution_problem_contract import problem_key
first = JournalAttempt('task', 'round', 'operation', 'a' * 32, 1)
later = JournalAttempt('task', 'round', 'operation', 'b' * 32, 2)
assert problem_key(first) == problem_key(later)
```
- [ ] Run `python -m pytest tests/v1_1/test_execution_problem_contract.py -q`,确认缺失模块失败。
- [ ] 实现逻辑键/分类与项目/项依赖引用格式;禁止把“进程已退出”当作“没有写入”。未声明独立且当前基线无法证明时,后继项保持 project_recovery。
- [ ] 验证手动失败、未派发、用户暂停、状态不确定分别投影,不能把暂缓显示为成功。
- [ ] Commit `feat: define logical execution problem identity`。
## E02:问题记录和一次重试额度事务
**Files:** Create `execution_problems.py`;Modify `execution_journal.py` 的 schema 创建入口;Test `tests/v1_1/test_execution_problems.py`。
**Interfaces:** `ExecutionProblems(store).record(attempt, classification, evidence_ref) -> dict`、`reserve_retry(attempt, *, rule_id, rule_commit, input_fingerprint) -> bool`、`list_problems(task_id, round_id) -> tuple[dict, ...]`。额度唯一键使用 E01 的逻辑键;逐次决策另存 append-only 记录,绑定原 attempt。
- [ ] 用真实临时 SQLite 的 fixture 写以下测试,并覆盖两个连接竞争、先扣额度后崩溃、用户清空历史和旧回调。
```python
def test_retry_reservation_survives_new_attempt(problems, first_attempt, later_attempt):
options = dict(rule_id='DX-SESSION-001', rule_commit='c' * 40,
input_fingerprint='d' * 64)
assert problems.reserve_retry(first_attempt, **options) is True
assert problems.reserve_retry(later_attempt, **options) is False
```
`problems` fixture 在本任务测试文件构建真实 TaskStore;first/later 使用 E01 示例的同操作不同尝试,先提交合法失败,再申请额度。
- [ ] Run `python -m pytest tests/v1_1/test_execution_problems.py -q`,确认失败。
- [ ] 建表、唯一约束、事务内核对任务/轮次/原尝试,先持久扣减再允许派发;重启不补回已消耗额度。旧 DSH 已消耗预算迁移时保守继承,不通过更换键恢复重试权。
- [ ] 回归 `test_execution_journal.py`、`test_history_facade_concurrency.py` 和旧库升级,检查无竞争的第二份成功账本。
- [ ] Commit `feat: persist problem history and retry allowance`。
## E03:JSON 经验规则、版本锁定和校验 CLI
**Files:** Create `experience/schema.json`、`experience/rules/DX-SESSION-001.json`、`experience_rules.py`、`tools/validate_experience_rules.py`;Modify `dsh/failure_policy.py`、`packaging/Build-DxPartReplace.ps1`;Test `tests/v1_1/test_experience_rules.py`。构建时生成包内 `experience/manifest.json`,不把引用自身 Git commit 的 manifest 提交回源仓库。
**Interfaces:** `load_registry(root: Path) -> dict`、`classify_failure_context(context: dict, registry: dict) -> dict`;context 固定 error_code/stage/cad_version/mutation_possible/evidence_state/environment_fingerprint;输出 classification/rule_id/rule_commit/input_fingerprint/action。首条动作仅 reset_project_session_and_retry_item。构建 CLI `python tools/validate_experience_rules.py --root experience --emit-manifest <构建暂存目录>/manifest.json` 在构建机读取已提交规则版本并输出每文件摘要,运行客户端只校验包内 manifest。
- [ ] 写无匹配、重叠匹配、未知字段、任意命令动作、规则被修改、同输入重复判定的测试。
```python
def test_unmatched_error_is_manual():
from dx_productivity.trial_task_center.experience_rules import classify_failure_context
context = dict(error_code='unknown', stage='open_project', cad_version='7.9.5',
mutation_possible=False, evidence_state='prepared', environment_fingerprint='e' * 64)
assert classify_failure_context(context, {'rules': [], 'commit': 'c' * 40})['classification'] == 'manual'
```
- [ ] Run `python -m pytest tests/v1_1/test_experience_rules.py -q`,确认失败。
- [ ] 实现标准库严格 JSON 校验,默认 max_auto_retries=1;manifest 锁定 Git commit 与每文件摘要,批次执行中不热更新。客户端不调用 Git;脏/缺失规则拒绝自动重试但保留主轮次替换能力。
- [ ] Run `python tools/validate_experience_rules.py --root experience` 与 DSH failure_policy 组;验证 unknown、interrupted、pause 均不能被规则放宽。
- [ ] Commit `feat: version deterministic JSON experience rules`。
## E04:每工程 CAD 会话和强制恢复证明
**Files:** Create `project_session_health.py`;Modify `batch_runtime.py`、`project_session.py`、`batch_resources.py`;Test `tests/v1_1/test_project_session_health.py`、`test_batch_runtime.py`。
**Interfaces:** `evaluate_project_health(*, project_key, session_id, generation, release_proof, baseline_proof) -> dict` 返回 ready/blockers;release_proof 来自现有资源归属记录,baseline_proof 来自原有原生回读/expected_baselines。可选网表校验结果不是输入。
- [ ] 写工程间不复用 CAD、正常项复用、异常只重建该工程的计数测试;再写旧 generation 和仅 PID 消失不得准入。
```python
def test_process_exit_alone_does_not_prove_project_clean():
from dx_productivity.trial_task_center.project_session_health import evaluate_project_health
health = evaluate_project_health(project_key='A', session_id='s', generation=2,
release_proof={'process_exited': True}, baseline_proof=None)
assert health['ready'] is False
```
- [ ] Run `python -m pytest tests/v1_1/test_project_session_health.py -q`,确认失败。
- [ ] 按工程获得/释放 CAD 租约,保留已核验合法修改的最近基线;异常后的独立原生核验与资源释放必须同时满足才能允许当前工程继续。禁止用最初文件 hash 否定工具自身合法改动。
- [ ] 回归普通暂停/显式强制结束、自有进程清理、外部工程保护;unknown 会话仍被隔离,不靠重复启动覆盖证据。
- [ ] Commit `feat: prove project session health after failures`。
## E05:同工程失败后处理独立余项
**Files:** Modify `execution_journal.py`、`batch.py`、`service.py`;Test `tests/v1_1/test_item_failure_isolation.py`、`test_safe_cbb_continue.py`。
**Interfaces:** 保留 `ExecutionJournal.claim/finish` 签名;在领取新 pending 项前使用 E04 健康证明和原始目标范围进行准入。失败项留在 E02,后继项不因解除任务级失败门禁自动变为成功或被加入重试范围。
- [ ] 写 A1 安全失败/A2 独立/A3 依赖 A1/B1 独立的调用测试;A2/B1 执行,A3 dependency_blocked,A1 不立刻重试。
```python
def test_safe_failure_does_not_hold_independent_item(isolation_case):
isolation_case.run(outcomes={'A1': 'safe_failure'}, healthy_projects={'A'})
assert isolation_case.calls == ['A1', 'A2', 'B1']
assert isolation_case.state('A3') == 'dependency_blocked'
```
`isolation_case` 在本任务测试文件构造真实 ExecutionJournal 和 four-item frozen plan,注入的只是原生执行返回;必须实际走 claim/finish。
- [ ] Run `python -m pytest tests/v1_1/test_item_failure_isolation.py -q`,复现当前同工程余项暂缓。
- [ ] 将“任意 failed 就拒绝全部 claim”替换为当前项终态、范围/依赖、会话健康共同判定;无法证明的当前工程余项留 project_recovery。其他工程不受该逻辑错误阻塞。
- [ ] 验证 uncertain 从不自动重放;若有任何未解决写入风险,不能仅凭重启会话执行 A2。通过 E04/E05 后才启用此策略,旧服务接口保持兼容。
- [ ] Commit `feat: continue independent items after safe failures`。
## E06:持久首轮/问题轮次与问题项定向重放
**Files:** Create `problem_pass.py`;Modify `task_queue.py`、`retry_preparation.py`、`recovery_commit.py`;Test `tests/v1_1/test_deferred_problem_pass.py`、`test_retry_recovery_transactions.py`。
**Interfaces:** `run_problem_pass(service, queue_id: str, *, stop_event) -> dict`;`resume_problem_items(service, queue_id: str, problem_keys: tuple, *, stop_event) -> dict`。检查点 schema 增加 phase=primary/problems/finished、原轮次关联和确定的 operation_key 序列;保留 queue_id/checkpoint_id/expected_plan_hashes。
- [ ] 写 A1 失败/A2与B1成功的双轮次测试,要求首轮最后项先于首次 retry;暂停落在首轮最后一项时也不启动第二轮。
```python
def test_primary_pass_finishes_before_any_retry(two_pass_case):
two_pass_case.run(first_failure='A1')
assert two_pass_case.calls == ['A1', 'A2', 'B1', 'A1:retry']
assert two_pass_case.retry_reservations == 1
```
`two_pass_case` 在本任务用真实队列检查点、E02 SQLite 额度和 E03 最小规则构建,调用计数来自受控原生执行入口。
- [ ] Run `python -m pytest tests/v1_1/test_deferred_problem_pass.py -q`,确认失败。
- [ ] 首轮失败只记录问题并继续;首轮收尾后冻结可重试清单,逐项先扣额度、经原子重试准备再派发。重试成功不覆盖原失败证据;不确定/人工/成功项不进入自动清单。
- [ ] 注入 phase 发布/扣额度/重试准备目录切换/回执提交的中断,验证重启不回主轮次重做。人工重放只受理确认的原问题集合,拒绝外来/成功/过期轮次键。
- [ ] Commit `feat: persist primary and deferred problem passes`。
## E07:统一 DSH 重试路径、问题列表和双状态
**Files:** Modify `dsh/incidents.py`、`dsh/run_journal.py`、`dsh/task_lifecycle.py`、`ui/dsh_operations.py`、`ui/dsh_task_lifecycle.py`;Test `tests/dsh/test_work_item_incidents.py`、`tests/ui/test_dsh_operations.py`。
**Interfaces:** 事件绑定 task_id/round_id/operation_key/attempt_id;所有自动换料重试统一经过 E02/E06。`problem_projection(receipts: tuple, problems: tuple) -> dict` 在 `execution_problems.py` 定义,提供替换汇总、问题项和可继续范围;如独立校验已接入,引用其 verification_projection,不重建状态。
- [ ] 写同事件从 IncidentCoordinator 和问题轮次同时进入只派发一次、切任务不串事件、校验失败不能调用换料重试的测试。
```python
def test_dsh_and_problem_pass_share_one_allowance(shared_retry_case):
shared_retry_case.request_from_dsh()
shared_retry_case.run_problem_pass()
assert shared_retry_case.native_retry_dispatches == 1
```
`shared_retry_case` 在本任务绑定同一真实 E02/E06 记录,不能给两入口各自造一个计数器来模拟幂等。
- [ ] Run `python -m pytest tests/dsh/test_work_item_incidents.py -q`,确认失败。
- [ ] 解释/聚类仅来自持久证据,本地 ExperienceStore 不产生授权;UI 展示完成有问题、失败/暂缓/不确定、原生确认后仅重放问题项。旧事件预算迁移不能获得新额度。
- [ ] 回归现有 DSH 运行恢复/对话取消/原生确认与 Qt 页面,确保主轮次不中途弹诊断阻塞执行。
- [ ] Commit `feat: unify DSH problem handling and retry authority`。
## E08:混合批次、崩溃矩阵和真实会话验收
**Files:** Create `tests/v1_1/test_unattended_batch_acceptance.py`、`tools/verify_work_item_pipeline.py`、`docs/testing/2026-11-05-radical-pipeline-acceptance.md`;Modify `packaging/DxPartReplace.spec`、`docs/user/unattended-batch-and-problem-queue.md`(不存在时创建)。
**Interfaces:** `python tools/verify_work_item_pipeline.py --output <新目录>` 使用受控执行器跑真实账本/调度器,不启动 CAD;真实 CAD 单独记录,不与 mock 报告混计。
- [ ] 100 项中放入 5 个明确失败、2 个不确定项,93 个其余项独立或有合法恢复证明;断言其完成且每个成功项只派发一次。另设不确定工程有余项的场景,明确哪些余项暂缓。
```python
def test_uncertain_items_are_never_replayed(batch_100_case):
result = batch_100_case.run()
assert result['completed_safe_items'] == 93
assert result['status'] == 'completed_with_issues'
assert batch_100_case.uncertain_retry_dispatches == 0
```
`batch_100_case` 在本任务生成确定输入并真实经过 E01~E07;两项 uncertain 不与其余 93 项共享未恢复写入风险。
- [ ] Run `python -m pytest tests/v1_1/test_unattended_batch_acceptance.py -q`,确认失败,再实现 CLI 汇总和故障注入驱动。
- [ ] 在领取、原生修改、保存、回读、终态提交、phase切换、额度扣减、强制暂停、资源退出九个边界注入中断;必须核对实际派发次数而非只核对进度数字。
- [ ] 独立工程副本实测工程会话切换、异常后恢复、其他工程继续和问题轮次;若独立校验已交付,再验证“替换失败问题”和“校验差异问题”不会互相触发错误重试。
- [ ] 跑默认 suite、DSH/打包组和 CLI;发布包携带 JSON 规则及版本摘要,不要求用户 Git,不携带工程/模型凭据;记录实测范围后 Commit `test: verify nonblocking replacement and deferred retries`。
## 验收出口
E01~E04 为基础能力,E05 是同工程非阻塞策略,E06 是首轮/问题轮次闭环,E07 是真实 DSH 接入,E08 才是对外承诺门禁。现有 main 已有回执/恢复测试继续保留,不能以新测试代替原有防重复写入保护。