Compare commits
60
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
818fb9a695 | ||
|
|
f80127e7bd | ||
|
|
ec2591ac75 | ||
|
|
22442e03ae | ||
|
|
9d9b316634 | ||
|
|
6d45ea1fa0 | ||
|
|
d0bbc73da3 | ||
|
|
4fb715507e | ||
|
|
c114db9f31 | ||
|
|
7d4f6bde0b | ||
|
|
ad3ee4151c | ||
|
|
650dfd5491 | ||
|
|
ba69f86628 | ||
|
|
8ccc9716de | ||
|
|
3187b304c6 | ||
|
|
29b40a5370 | ||
|
|
315d2e85b3 | ||
|
|
d954b527f5 | ||
|
|
63999b7bfd | ||
|
|
46deb9cec8 | ||
|
|
488bf027cc | ||
|
|
bd80f86357 | ||
|
|
0540a1e3bb | ||
|
|
846c4b92e9 | ||
|
|
03ae2cdaa8 | ||
|
|
4a438e027b | ||
|
|
b2a84404d8 | ||
|
|
7597e98eef | ||
|
|
e63a82b695 | ||
|
|
b038951cc4 | ||
|
|
cdbc92fab8 | ||
|
|
d9bfc57900 | ||
|
|
e65bed0408 | ||
|
|
a74b810786 | ||
|
|
de16bbdfa1 | ||
|
|
eda9403d94 | ||
|
|
9ccf99bd8f | ||
|
|
d08a940afe | ||
|
|
f91b4deb5e | ||
|
|
fe8765beec | ||
|
|
a606ed9179 | ||
|
|
6175bdb254 | ||
|
|
211d139653 | ||
|
|
d9cf6a07e9 | ||
|
|
ec677a2864 | ||
|
|
b9712ed651 | ||
|
|
e6e9b6906d | ||
|
|
f25dd228fd | ||
|
|
deaf8c3ab4 | ||
|
|
de486a9c6b | ||
|
|
4da211d5d2 | ||
|
|
b3c8c9c126 | ||
|
|
76074f8d11 | ||
|
|
f5d39f6261 | ||
|
|
0406028a02 | ||
|
|
dbb264f679 | ||
|
|
b19afc6a53 | ||
|
|
6a8bf08809 | ||
|
|
6cd6520bae | ||
|
|
d0c07f4f74 |
No files matched your search
@@ -49,8 +49,9 @@ jobs:
|
|||||||
npm install --prefix /opt/ci-node --no-audit --no-fund node@24.11.1
|
npm install --prefix /opt/ci-node --no-audit --no-fund node@24.11.1
|
||||||
node --version
|
node --version
|
||||||
npm ci --prefix integration/dsh --no-audit --no-fund
|
npm ci --prefix integration/dsh --no-audit --no-fund
|
||||||
- name: Read-only model availability (real Harness, no remote model calls)
|
- name: Runtime and model availability (real Harness, no remote model calls)
|
||||||
run: |
|
run: |
|
||||||
|
node tools/verify_dsh_runtime.mjs
|
||||||
node tools/verify_dsh_model_availability.mjs
|
node tools/verify_dsh_model_availability.mjs
|
||||||
node --test tests/integration/test_dsh_standard_compat.mjs
|
node --test tests/integration/test_dsh_standard_compat.mjs
|
||||||
node tools/verify_dsh_incident_restart.mjs
|
node tools/verify_dsh_incident_restart.mjs
|
||||||
@@ -154,5 +155,6 @@ jobs:
|
|||||||
- name: Intervention panel and bounded model views (no model or network)
|
- name: Intervention panel and bounded model views (no model or network)
|
||||||
run: |
|
run: |
|
||||||
node tools/verify_dsh_incident_panel.mjs
|
node tools/verify_dsh_incident_panel.mjs
|
||||||
|
node tools/verify_dsh_dock_startup.mjs
|
||||||
node tools/verify_dsh_model_results.mjs
|
node tools/verify_dsh_model_results.mjs
|
||||||
node tools/verify_dsh_diagnosis_cancel.mjs
|
node tools/verify_dsh_diagnosis_cancel.mjs
|
||||||
@@ -0,0 +1,7 @@
|
|||||||
|
# DxPartReplace 1.3.3-beta.1 实机评分包
|
||||||
|
|
||||||
|
此 Windows x64 便携版包含 #33 的八项修复,供六套固定试卷重新评分。更新内容包括同数据目录单实例、工程路径报错、窗口恢复、搜索空状态、BOM 表头警告,以及 DxDataBook 加载、资源回收和队列续跑。
|
||||||
|
|
||||||
|
退出旧程序后将 ZIP 完整解压到新目录,双击 `启动程序.cmd`。核对窗口标题为 `DxDesigner 器件替换 · 1.3.3-beta.1`。需要复测旧任务时,使用旧 `data` 的备份副本。
|
||||||
|
|
||||||
|
优先用现场库复测 BOB、BOB_Shield 的 `4885-S033D0-M220` 和 WiFi LWB01 的 `4885-S018D0-M220`。记录能否打开工程、加载料号、保存回读及释放桌面。卷四测试 8 工程混合批次,另跑 100 工程队列。卷六记录暂停、跨进程恢复和已保存项的派发次数。原始分数为 373/600,本包成绩以实机逐题结果为准。[实机评分工单 #42](https://git.simgreek.com/Skyworth_Digital_Hardware/dxdesigner-part-replacement/issues/42)
|
||||||
@@ -0,0 +1,9 @@
|
|||||||
|
# 引脚字段读取范围
|
||||||
|
|
||||||
|
FREEFORM / FLAT BLOCKS 原生文本中的 `Pin 名称\tnum 编号\ttype 类型码` 可以与已解析图的实例、位号、物理脚号核对。适配器保留文件 SHA256 和行号,重复或无法绑定的字段不进入已证明清单。类型码按原文展示,不臆造类型语义。
|
||||||
|
|
||||||
|
自建格式夹具验证了逻辑名和电气类型码。另对已有工程的两份已保存副本执行了真实原生只读导出:前后各 57 个器件,83 个物理引脚取得了名称和类型码的原文证明。验收记录在本机 `D:/dx-vfy-native-final/acceptance.json`;原始客户工程和网表不提交 Git。
|
||||||
|
|
||||||
|
引脚级 Value 尚未在该格式中证明,保持 unknown;器件 Value 不能代替它。确切库版本内部的引脚到焊盘映射尚未支持,保持未覆盖。若检查计划要求这些未证明字段,结论必须为 INCOMPLETE(已有明确硬异常时仍为 DIFFERENT)。
|
||||||
|
|
||||||
|
探针:`python tools/probe_verification_pin_metadata.py <受管导出/netlist.json>`,只读已有输出,不调用 CAD、不修改工程。
|
||||||
@@ -0,0 +1,32 @@
|
|||||||
|
# 批量替换阻塞与状态闭环实施计划
|
||||||
|
|
||||||
|
按用户在本聊天确认的设计执行。保留此前 issue29 修复,不修改其他聊天的 independent-verification 文档。
|
||||||
|
|
||||||
|
## 用户已确定的规则
|
||||||
|
|
||||||
|
- 位号可明确定位时忽略 UID 缺失、异常、重复或变化;贯通清单、计划、执行、回读、恢复和网表。
|
||||||
|
- 同工程统一保存/关闭重开/回读一次,暂停时提前提交;提交前不得记作 saved_ok。
|
||||||
|
- Mentor 和全部自有写进程确认退出后,隔离残留桌面并放行新批次,不假报桌面已释放。
|
||||||
|
- 结果不确定的工程保留待核验并隔离,同写入源一并隔离;释放全部自有写进程后继续独立工程。人工暂停停止整批。
|
||||||
|
- 操作回执、任务、队列状态幂等收敛。已保存结果、网表验收、资源告警分别展示。
|
||||||
|
- 补齐关键调用进入/返回和等待原因及诊断包,不让清理错误覆盖原错误。
|
||||||
|
|
||||||
|
## 实施任务
|
||||||
|
|
||||||
|
1. 位号身份:原生清单与目标键使用位号身份,保留原始 UID 证据;旧计划/成功操作编号不变,执行与网表允许位号关联,合法多单元及真实歧义分别处理。
|
||||||
|
2. 工程提交/暂停:增加待保存及工程提交记录,工程结束或暂停统一保存回读,所有待提交项原子转完成;SafeStop 不包装成 Baseline,确认未写入暂停返回 pending/paused;未知保存仍 blocked。
|
||||||
|
3. 资源隔离:新增隔离终态和明确阻断字段,持久化进程退出证明;残留桌面不重复 Quit/CloseDesktop,新会话可进入;未知写进程不得隔离放行。
|
||||||
|
4. 工程与任务隔离:新增 BLOCKED,工程异常释放后继续独立工程,区分本地回收控制和用户暂停;共享工程/iCDB写入源隔离,旧回执不重放。
|
||||||
|
5. 诊断与状态:明确停止原因/等待原因,记录关键操作进入返回;诊断包含执行日志、worker进度、原生报告和提交证据,保留脱敏/体积限制;UI正确显示 blocked/failed/paused/completed。
|
||||||
|
6. 集成验收:按设计20种场景测试,回归现有队列/恢复/资源/UI/网表;本机CAD仅副本,不把fake和CLI协议验证称为真实CAD验收;记录每工程save次数及阶段计时。打包候选版但不自动发布旧Release。
|
||||||
|
|
||||||
|
## 接口约定
|
||||||
|
|
||||||
|
- 现有 @REFDES| 标识复用,不改写旧成功操作编号。
|
||||||
|
- saved_ok 仅表示保存回读已通过。新增暂存状态必须由工程提交记录覆盖后才能转 verified。
|
||||||
|
- 隔离桌面保持 desktop_released=false;写进程退出证据与桌面存在性分开。
|
||||||
|
- BLOCKED是业务待核验,不等于全局资源未释放。
|
||||||
|
|
||||||
|
## 工作区与验证
|
||||||
|
|
||||||
|
当前分支 codex/issue29-blocking-cleanup,base b19afc6。已有未提交变更已完成此前回归,用户授权本轮继续实施。每个非平凡行为先RED后GREEN。阶段回归按实际修改选择,最终检查 tracked diff、打包产物和验收覆盖。
|
||||||
@@ -0,0 +1,324 @@
|
|||||||
|
# 独立校验新增功能 Implementation Plan
|
||||||
|
|
||||||
|
> **For agentic workers:** REQUIRED SUB-SKILL: Use `superpowers:executing-plans` to implement task-by-task. N01–N12 implementation and local development-package acceptance are complete. Continuous full-suite stability remains a release gate; see the acceptance record. Do not start implementation from the UI image alone or dispatch agents without user authorization.
|
||||||
|
|
||||||
|
**Goal:** 新增可独立创建、接收成功结果、执行并让人复核的工程校验任务,交付 A 工作台及完整判断/失败处理。
|
||||||
|
|
||||||
|
**Architecture:** 在现有原生捕获、导出、图比较、回执证明之上增加校验领域包;任务、工程项、不可变输入版本、执行尝试与本次运行范围各有身份。界面只查持久事实和证据;统一输入接口不包含来源分类,批量与未来增量共用接口。
|
||||||
|
|
||||||
|
**Tech Stack:** Python 3.12、SQLite、PySide6、pytest/pytest-qt、已有 Native CLI/OwnedCliScope/ServiceWorker/LatestQuery;标准库 JSON/HTML,无新运行时依赖。
|
||||||
|
|
||||||
|
**Spec:** [业务、流程、状态、数据与失败处理](../specs/2026-11-17-independent-verification-business-design.md)。对应用户最终选择的 A 图片入口,不采用此前带来源或流水线横条的旧草案。
|
||||||
|
|
||||||
|
用户已确认业务方向,开发阶段、工作区隔离、跨任务接口和交付门槛统一从[开发与交付入口](2026-11-17-verification-development.md)读取。本文件是该入口下的逐任务清单,N01~N12 已实施并完成本地开发包验收;既有连续全量回归的时序波动保留为发布门槛,详见验收记录。
|
||||||
|
|
||||||
|
## Global Constraints
|
||||||
|
|
||||||
|
- 只开发当前没有的功能;不接手 issue29 收尾、既有任务列表或其他并行修复。
|
||||||
|
- 原始捕获、原生导出、覆盖核验与绑定实际回执的预期解析直接复用;不重写旧替换状态机。
|
||||||
|
- 独立任务始终可创建;资源忙只影响执行领取,不影响新建和输入登记。
|
||||||
|
- 无 source/type/mode 来路字段或来源筛选;没有预期清单不等于所有变化均被允许。
|
||||||
|
- 当前只在已落盘结果后批量交接;增量接口和乱序规则先做好,不修改替换侧实时刷新。
|
||||||
|
- 所有工作只读固定输入;禁止重新换料、自动换脚、修改库或把当前工程补造为旧 before。
|
||||||
|
- 位号/物理脚号/连接严格;引脚文字变化与器件 Value、网络名分开;未知字段不能冒充一致。
|
||||||
|
- “执行成功”与“工程结论”分开;必查未知不能通过,已知异常不被警告或未知覆盖。
|
||||||
|
- 同一输入版本只允许一个活动尝试;新版本不替换在跑输入,迟到结果不能覆盖当前结论。
|
||||||
|
- GUI 不进行 CAD/CLI/磁盘全图扫描;延用既有风格、980×700 最小窗口与1280×880默认窗口。
|
||||||
|
- 新增原生进程只使用现有 OwnedCliScope;退出无法确认时暂停该执行器,不触发旧 CAD 退出/恢复动作。
|
||||||
|
- 清理不能删除活动/当前引用的快照、证明和报告;Git不接收客户工程、原始网表或厂商二进制。
|
||||||
|
- 每个任务独立测试/审阅/提交;只暂存其明确文件,保护工作区并行修改。实现前按最新主线重新定位接口。
|
||||||
|
|
||||||
|
## 0. 文件划分与依赖
|
||||||
|
|
||||||
|
领域包新建于 `src/dx_productivity/trial_task_center/verification/`,以下缩写 `V/` 指该目录;`UI/` 指既有 `src/dx_productivity/trial_task_center/ui/`。测试使用完整仓库相对路径。
|
||||||
|
|
||||||
|
| 文件 | 职责 | 首次任务 |
|
||||||
|
| --- | --- | --- |
|
||||||
|
| `V/__init__.py`、`V/contracts.py` | 输入/检查/状态合同,结果汇总 | N01 |
|
||||||
|
| `V/store.py` | 校验任务、工程、版本、尝试、运行、命令去重事务 | N02 |
|
||||||
|
| `V/service.py` | 本域公开接口,接收/查询/执行薄编排 | N03 |
|
||||||
|
| `V/intake.py` | 稳定导入、版本接收、成功交接适配 | N03 |
|
||||||
|
| `V/queries.py` | 当前版本投影、分页与统计 | N04 |
|
||||||
|
| `V/runner.py` | 独立只读执行器、资源准入与发布 | N05 |
|
||||||
|
| `V/control.py`、`V/ownership.py` | 冻结运行范围、持久停止、跨窗口进程归属和恢复证明 | N10 |
|
||||||
|
| `V/rules.py` | J01~J13 分维度判断与事实差异 | N06 |
|
||||||
|
| `V/pin_metadata.py` | 已验证原生字段适配、能力与未覆盖清单 | N07 |
|
||||||
|
| `V/evidence.py` | issue 定位、端点差异与确定性图数据 | N08 |
|
||||||
|
| `UI/verification_workspace.py` | 页面、任务选择、工程表、底栏 | N09 |
|
||||||
|
| `UI/verification_controller.py` | 异步查询、选择代次和用户命令 | N09 |
|
||||||
|
| `UI/verification_inspector.py` | 逐脚对照、事实表、范围与证据入口 | N09 |
|
||||||
|
| `V/report.py` | 同一证据包的HTML/JSON和整任务导出 | N11 |
|
||||||
|
| `tools/verify_independent_verification.py` | 受控/真实只读验收CLI,明确区分两种证据 | N12 |
|
||||||
|
|
||||||
|
新增 schema 由现有 `store_schema.py` 的版本升级入口调用 `V/store.py`,原服务 `service.py` 只暴露本域服务引用,不继续堆叠校验业务。
|
||||||
|
|
||||||
|
依赖:N01→N02→N03→N04;N02/N03→N05;N01→N06;N05/N06→N07→N08;N04/N05/N08→N09;N05/N09→N10→N11→N12。
|
||||||
|
|
||||||
|
N05 可以先用已有比较器返回原始事实和明确覆盖,N06 增加分级,N07 丰富引脚元数据;能力未验证的阶段必须产生 unknown,不为界面测试假造通过。
|
||||||
|
|
||||||
|
## N01:固定输入、执行状态与结论合同
|
||||||
|
|
||||||
|
**Files:** Create `V/__init__.py`、`V/contracts.py`;Test `tests/v1_1/test_independent_verification_contracts.py`。
|
||||||
|
|
||||||
|
**Interfaces:** `validate_input(value: dict) -> dict`;`rollup_results(checks: tuple[dict, ...], *, required_checks: tuple[str, ...], optional_checks: tuple[str, ...] = ()) -> dict`。返回 verdict、coverage、warnings/errors/unknown计数及 scope。missing required check 等同 unknown;空检查不能一致,空required_checks拒绝为非法检查计划。`CheckResult` 用字典并严格校验 check_id/state/issues/evidence_refs,不新增泛型框架。
|
||||||
|
|
||||||
|
检查ID固定:inputs(J01)、coverage(J02)、components(J03)、physical_pins(J04)、connections(J05/J06)、net_names(J07)、declared_attributes(J08)、attribute_changes(J09)、pin_text(J10)、pin_semantics(J11)、footprint_mapping(J12)、export_identity(J13)。同一check有多个issue,不重复check_id;无expectation时declared_attributes不能伪装已检查,attribute_changes仍输出变化事实。
|
||||||
|
|
||||||
|
- [x] 写空结果、缺必查、错误与未知并存、警告、可选未知、无预期清单的失败测试:
|
||||||
|
|
||||||
|
```python
|
||||||
|
def test_empty_checks_do_not_prove_consistency():
|
||||||
|
from dx_productivity.trial_task_center.verification.contracts import rollup_results
|
||||||
|
result = rollup_results((), required_checks=('connections',))
|
||||||
|
assert result['verdict'] == 'INCOMPLETE'
|
||||||
|
assert result['coverage'] == 'partial'
|
||||||
|
```
|
||||||
|
|
||||||
|
- [x] Run `.venv/Scripts/python.exe -m pytest tests/v1_1/test_independent_verification_contracts.py -q`,确认新合同尚不存在而失败。
|
||||||
|
- [x] 实现严格字段、枚举、摘要、整数版本与受管引用结构校验;拒绝外部任意输出路径,UI不传来源字段。输入字段按规范4.1,check_plan明确 required/optional/excluded。
|
||||||
|
- [x] 实现纯汇总优先级,核心逻辑固定为:
|
||||||
|
|
||||||
|
```python
|
||||||
|
if any(row['state'] == 'error' for row in checks):
|
||||||
|
verdict = 'DIFFERENT'
|
||||||
|
elif any(states.get(key, 'unknown') not in {'equal', 'expected_change', 'warning'}
|
||||||
|
for key in required_checks):
|
||||||
|
verdict = 'INCOMPLETE'
|
||||||
|
elif any(row['state'] == 'warning' for row in checks):
|
||||||
|
verdict = 'WARNING'
|
||||||
|
else:
|
||||||
|
verdict = 'CONSISTENT'
|
||||||
|
```
|
||||||
|
|
||||||
|
`states` 在同函数中由唯一 check_id 建立;重复check_id拒绝,不用后值覆盖前值。必查项被标not_requested同样不能通过;空required_checks在该分支前抛出TaskCenterError。覆盖清单独立计算。
|
||||||
|
|
||||||
|
- [x] 重跑本组,补 actual属性值不能反推expected、not_requested不计已检查、没有规则时scope文字不能“换料符合”的断言。
|
||||||
|
- [x] 对照规范J01~J13与状态表自审字段;保留原始文字及证据引用,不在合同层猜测引脚功能。
|
||||||
|
- [x] Commit `feat: define independent verification contracts and verdicts`。
|
||||||
|
|
||||||
|
## N02:任务、版本、尝试与去重事务
|
||||||
|
|
||||||
|
**Files:** Create `V/store.py`;Modify `src/dx_productivity/trial_task_center/store_schema.py`;Test `tests/v1_1/test_independent_verification_store.py`。
|
||||||
|
|
||||||
|
**Interfaces:** `VerificationRepository(task_store)`:`create_task(name: str, *, request_id: str) -> dict`、`publish(task_id: str, inputs: tuple[dict, ...], *, submission_id: str) -> dict`、`create_attempt(item_id: str, version: int, *, request_id: str) -> dict`、`claim(attempt_id: str, *, owner_id: str) -> dict`、`finish(attempt_id: str, *, generation: int, result: dict) -> bool`。这些只操作已验证的领域记录;原生I/O由服务完成。
|
||||||
|
|
||||||
|
- [x] 写旧DB升级、创建去重、同版不同正文、乱序、唯一活动尝试、迟到finish与并发claim测试。测试内创建真实临时TaskStore:
|
||||||
|
|
||||||
|
```python
|
||||||
|
def test_new_task_does_not_require_replacement_task(tmp_path):
|
||||||
|
from dx_productivity.trial_task_center.store import TaskStore
|
||||||
|
from dx_productivity.trial_task_center.verification.store import VerificationRepository
|
||||||
|
with_store = TaskStore(tmp_path / 'tasks.db')
|
||||||
|
try:
|
||||||
|
repo = VerificationRepository(with_store)
|
||||||
|
first = repo.create_task('电源板核对', request_id='create-1')
|
||||||
|
again = repo.create_task('电源板核对', request_id='create-1')
|
||||||
|
assert first['task_id'] == again['task_id']
|
||||||
|
finally:
|
||||||
|
with_store.close()
|
||||||
|
```
|
||||||
|
|
||||||
|
- [x] Run `.venv/Scripts/python.exe -m pytest tests/v1_1/test_independent_verification_store.py -q`,确认失败。
|
||||||
|
- [x] 建 verification_tasks/items/input_revisions/attempts/runs/requests 表,状态只属于本域;给版本和请求去重键唯一索引。至少固定:
|
||||||
|
|
||||||
|
```sql
|
||||||
|
CREATE UNIQUE INDEX verification_input_identity
|
||||||
|
ON verification_input_revisions(item_id, input_version);
|
||||||
|
CREATE UNIQUE INDEX verification_active_attempt
|
||||||
|
ON verification_attempts(item_id, input_version)
|
||||||
|
WHERE state IN ('queued','running','publishing','stopping');
|
||||||
|
```
|
||||||
|
|
||||||
|
- [x] 实现事务内版本指针移动、逐条接收和CAS generation;批量外层错误全拒绝,逐项错误返回原因,已接收其他项不回滚。保存request摘要,拒绝同request_id异文。
|
||||||
|
- [x] 用真实临时SQLite跑本组及既有schema/store回归;核对旧execution_operations与重试额度字节/行值未被新操作改写。
|
||||||
|
- [x] 故障注入提交前/提交后;返回值在事务内准备,不能因COMMIT后的额外尾读失败误报未接收;记录同一 before 新after与新before分项的区别。
|
||||||
|
- [x] Commit `feat: persist verification tasks inputs and attempts`。
|
||||||
|
|
||||||
|
## N03:统一接收、独立导入与成功结果交接
|
||||||
|
|
||||||
|
**Files:** Create `V/service.py`、`V/intake.py`;Modify `src/dx_productivity/trial_task_center/service.py` 仅暴露 `verification` 服务;接入 `dsh/execution_runs.py` 的已持久结果通知,不修改其执行/恢复合同;Test `tests/v1_1/test_independent_verification_intake.py`。
|
||||||
|
|
||||||
|
**Interfaces:** `VerificationService(task_store, data_root: Path)`;`create_task(name, *, request_id)`;`publish_inputs(task_id, inputs, *, submission_id)`;`import_pair(task_id, before: Path, after: Path, *, request_id: str, stop_event) -> dict`;`receive_successful_results(result_ref: dict, *, submission_id: str) -> dict`;`reconcile_deliveries(*, limit: int = 100) -> dict`。两种操作最终发布同一种inputs,无来路枚举。默认自动接收容器名为“校验任务”,以持久交接关联键去重,用户可改名。
|
||||||
|
|
||||||
|
- [x] 写两份工程同文件/数据库别名、捕获时变化、成功交接缺before、未成功结果拒绝、重复交接、一次批量和分次输入等价的测试。自建文件只用于事务/捕获测试,不假称可打开CAD工程。
|
||||||
|
- [x] Run `.venv/Scripts/python.exe -m pytest tests/v1_1/test_independent_verification_intake.py -q`,确认失败。
|
||||||
|
- [x] 复用capture_project,受管目录外输入先检查稳定性;两个文件最终数据库同源也要拒绝。已冻结交接只核验引用,不打开原CAD或重新捕获旧before。
|
||||||
|
- [x] 对已落盘成功范围建规范inputs;expectation_ref来自冻结清单/有效回执,不用after反推。补有界交接对账:首次接收和重启/进入校验页重扫未确认通知都用同submission键,落库回执作为完成依据。
|
||||||
|
- [x] 重跑本组;让导入/发布期间的替换和恢复入口抛AssertionError,证明只创建校验记录。成功工程缺证据仍可见,错误输入不能将旧baseline换成当前工程。
|
||||||
|
- [x] 对照接口确认当前能批量传、未来能乱序增量传;输入接收不创建queued尝试,不强制切走用户正在看的任务。
|
||||||
|
- [x] Commit `feat: receive verification inputs and import project pairs`。
|
||||||
|
|
||||||
|
## N04:当前版本查询、任务统计与历史投影
|
||||||
|
|
||||||
|
**Files:** Create `V/queries.py`;Modify `V/service.py`;Test `tests/v1_1/test_independent_verification_queries.py`。
|
||||||
|
|
||||||
|
**Interfaces:** `list_tasks(*, query='', cursor=None, limit=50, read_control=None)`;`read_task(task_id, *, state='', query='', cursor=None, limit=100, read_control=None)`;`read_item(item_id, *, version: int | None = None, read_control=None)`;`read_issues(attempt_id, *, kind='', cursor=None, limit=100, read_control=None)`。返回task view_revision、当前input_version、attempt身份、结论、范围、动作门禁、分页cursor。`summarize_items(rows)`只统计当前版本。
|
||||||
|
|
||||||
|
- [x] 写24项计数、旧版不重复计数、重校验转排队后旧绿灯退出当前、同名不同身份、筛选与整任务操作范围分离的测试。
|
||||||
|
- [x] Run `.venv/Scripts/python.exe -m pytest tests/v1_1/test_independent_verification_queries.py -q`,确认失败。
|
||||||
|
- [x] 实现“输入→当前尝试→结论→可执行动作”的单一投影;执行succeeded且verdictDIFFERENT必须显示异常,而非通过。空任务可新建/加工程,活动任务不禁用创建其他任务。
|
||||||
|
- [x] 参数化查询实现50任务/100工程/100问题上限,搜索名称、路径及已有issue位号/料号;转义LIKE的百分号/下划线。分页cursor绑定过滤、排序和view_revision,身份不从行号推断。
|
||||||
|
- [x] 跑本组与既有任务只读查询测试,核对“24=16一致+2警告+1异常+1无法校验+4待校验,已处理20”;暂停/中断单列不当一致。
|
||||||
|
- [x] 用并发读/新版本发布验证快照计数一致;旧attempt结果只进入历史,不刷新当前绿色。
|
||||||
|
- [x] Commit `feat: query current verification results and task summaries`。
|
||||||
|
|
||||||
|
## N05:独立只读执行器与原生后端适配
|
||||||
|
|
||||||
|
**Files:** Create `V/runner.py`;Modify `netlist_verification.py` 仅暴露固定输入导出缓存适配,原调用保持;Modify `V/service.py`、`V/store.py`;Test `tests/v1_1/test_independent_verification_runner.py`;Regression `test_netlist_execution.py`、`test_pr27_netlist_pause.py`。
|
||||||
|
|
||||||
|
**Interfaces:** `run_attempt(service, attempt_id: str, *, stop_event) -> dict`;`export_inputs(before_ref: dict, after_ref: dict, *, output: Path, stop_event) -> tuple[dict, dict]`;`can_start_native_export(service) -> dict` 返回allowed/reason,不占用新建入口。N06前本适配可返回已有比较事实并显式缺少扩展检查,不能编造完整结论。
|
||||||
|
|
||||||
|
- [x] 写任意独立任务可运行、原输入不变、缺工具不启动CAD、旧缓存损坏重导出、并发领取唯一、资源忙排队的测试。runner用受控OwnedCliScope/现有graph夹具,实际持久库和文件发布链不替换为固定成功值。
|
||||||
|
- [x] Run `.venv/Scripts/python.exe -m pytest tests/v1_1/test_independent_verification_runner.py -q`,确认失败。
|
||||||
|
- [x] 依照E03~E07核验固定引用;捕获/导出只走既有native_netlist。首版独立runner一次领取一个工程对,前后导出顺序运行,避免复制旧批次pool再叠加并发。若原生资源准入不可证明可并行,则留队列等待;不以该等待禁用新建。
|
||||||
|
- [x] 组织比较调用与暂存产物;先按E10确认自有CLI退出,再按E11发布结果及CAS finish。原异步导出/旧finish行为不被替换为新全局队列,接收既有完整证据时可以只复核/复用而不额外开进程。
|
||||||
|
- [x] 跑新组及两个旧网表组;断言替换派发数、CAD启动数、execution_operations写次数均为0,旧入口的暂停与缓存合同不退化。
|
||||||
|
- [x] 注入导出失败和发布中断;确认旧结果不覆盖、迟到attempt不更新当前。记录新执行器与旧资源修复的责任边界,不用本任务修退出helper。
|
||||||
|
- [x] Commit `feat: execute independent verification on immutable inputs`。
|
||||||
|
|
||||||
|
## N06:结构、属性、警告与未知的逐项判断
|
||||||
|
|
||||||
|
**Files:** Create `V/rules.py`;Modify `V/runner.py`;Test `tests/v1_1/test_independent_verification_rules.py`。
|
||||||
|
|
||||||
|
**Interfaces:** `evaluate(before: dict, after: dict, *, expectations: dict | None, check_plan: dict, pin_metadata: dict | None = None) -> dict` 返回checks、issues和N01汇总;`match_components(before_graph, after_graph) -> dict`返回可证明对应及歧义,不改原图。没有expectations与有意声明空变化清单须区分。
|
||||||
|
|
||||||
|
- [x] 用真实最小graph夹具写J01~J13反例:断线、短接、交换物理脚、位号增删、用户网名、无清单属性、正常目标变化、非目标变化、命名警告、必查unknown。固定脚号互换测试独立于名称相似度。
|
||||||
|
- [x] Run `.venv/Scripts/python.exe -m pytest tests/v1_1/test_independent_verification_rules.py -q`,确认失败。
|
||||||
|
- [x] 复用已有完整图/物理端点语义,建立只读对应视图;延用最新实例范围+生效位号唯一绑定,UID仅保留原始证据,其缺失/重复/变化不得否定已证明的位号对应。真实位号/实例歧义仍unknown。连接按完整端点集合比较,单端网络与未连接不混用。
|
||||||
|
- [x] 按check输出事实,不直接复用旧verified作为新最终结论;对允许改名的原比较结果补warning。关键边界为:
|
||||||
|
|
||||||
|
```python
|
||||||
|
if numbers_equal is False or connections_equal is False:
|
||||||
|
pin_text_state = 'error'
|
||||||
|
elif numbers_equal is not True or connections_equal is not True or pin_text_changed is None:
|
||||||
|
pin_text_state = 'unknown'
|
||||||
|
elif pin_text_changed:
|
||||||
|
pin_text_state = 'warning'
|
||||||
|
else:
|
||||||
|
pin_text_state = 'equal'
|
||||||
|
```
|
||||||
|
|
||||||
|
该片段只在物理脚已建立对应后运行;结构或连接已证明改变仍按硬异常处理,未证明的比较结果不会被Python的假值语义误判为“已证实改变”。unknown字段不由空字符串补齐,GND/VCC语义不由模型判断。
|
||||||
|
|
||||||
|
- [x] 跑本组及现有physical pin/逻辑改名测试;证明默认旧比较器结果不被全局放宽,网名变化不会套入引脚名称规则。
|
||||||
|
- [x] 检查错误优先、未知必查、警告、范围一致四类;有已知反脚加缺失属性时仍DIFFERENT,同时保留unknown列表。
|
||||||
|
- [x] Commit `feat: classify verification checks with explicit evidence and coverage`。
|
||||||
|
|
||||||
|
## N07:引脚级字段与封装映射能力探测
|
||||||
|
|
||||||
|
**Files:** Create `V/pin_metadata.py`、`tools/probe_verification_pin_metadata.py`、`docs/research/2026-11-17-pin-metadata-capability.md`;Test `tests/v1_1/test_verification_pin_metadata.py`;Modify `V/runner.py`。
|
||||||
|
|
||||||
|
**Interfaces:** `inspect_pin_metadata(export: dict, *, evidence_root: Path) -> dict` 返回每物理脚的logical_name/pin_value/electrical_type字段、存在性、原始定位、confidence为proven/unknown;`inspect_footprint_mapping(binding: dict) -> dict` 首版只接纳真实可证适配,未支持返回unknown及原因,不用空字典代表映射相同。
|
||||||
|
|
||||||
|
- [x] 写引脚Value与器件Value不同、原字段缺失、引脚类型变化、逻辑名对齐物理号、库映射未知的测试。缺证据边界:
|
||||||
|
|
||||||
|
```python
|
||||||
|
def test_missing_mapping_is_unknown(tmp_path):
|
||||||
|
from dx_productivity.trial_task_center.verification.pin_metadata import inspect_footprint_mapping
|
||||||
|
result = inspect_footprint_mapping({'symbol': 'example', 'cell': 'example', 'evidence': None})
|
||||||
|
assert result['state'] == 'unknown'
|
||||||
|
assert result['mapping'] is None
|
||||||
|
```
|
||||||
|
|
||||||
|
- [x] Run `.venv/Scripts/python.exe -m pytest tests/v1_1/test_verification_pin_metadata.py -q`,确认失败。
|
||||||
|
- [x] 探针只在用户工程已保存副本/受管导出上读取现有原生输出,记录确切字段、版本、存在性和物理脚绑定。先确认能否读出,不能凭类型名发明COM方法或回退CAD采集;探针不直接进入生产导入链。
|
||||||
|
- [x] 只有已证明的字段进入最小解析适配;无引脚Value就保留unknown,不用逻辑名或器件Value代替。库内映射默认未覆盖,只有取得真实版本/符号/Cell/脚号证据才实现对应分支。
|
||||||
|
- [x] 运行本组及N06,使用自建可提交fixture覆盖loop/outloop、同号不同文字、同名不同脚和已证实映射交换;客户报告只本地保存,仓库仅自建摘录。
|
||||||
|
- [x] 写能力报告:已验证字段/格式、未覆盖项、真实读取或纯夹具证据;无法验证的能力不阻止A基础页交付,但必查请求该能力时必须INCOMPLETE。
|
||||||
|
- [x] Commit `feat: expose proven pin metadata and unsupported mapping coverage`。
|
||||||
|
|
||||||
|
## N08:可人工复核的证据模型与连接图
|
||||||
|
|
||||||
|
**Files:** Create `V/evidence.py`;Modify `V/runner.py`;Test `tests/v1_1/test_verification_evidence.py`。
|
||||||
|
|
||||||
|
**Interfaces:** `build_evidence(before_graph: dict, after_graph: dict, issues: tuple[dict, ...], *, binding: dict) -> dict` 返回issue稳定ID、前后物理脚位置、连接对端、差异表和raw定位。`connection_view(evidence: dict, issue_id: str) -> dict` 只生成确定性绘图数据,不调用图片/语言模型。
|
||||||
|
|
||||||
|
- [x] 写R12 1/2互换、短接多对端、纯改名不画红断线、未知映射、图页未知与证据摘要损坏测试。前后pin1的绘制顺序必须相同,不能自动互换位置使图看起来一致。
|
||||||
|
- [x] Run `.venv/Scripts/python.exe -m pytest tests/v1_1/test_verification_evidence.py -q`,确认失败。
|
||||||
|
- [x] 从N06事实产生唯一issue_id;图和表共享同一数据结构,不分别拼判断。端点按固定脚号排列,变化线给出added/removed及原网络名,保留多gate与实例身份。
|
||||||
|
- [x] 将issue绑定不可变raw文件、摘要与可定位段落/对象键;图页无法确定则明确未定位。图标注“由网表生成”,不画伪原理图截图,不用生成模型解释电气正确性。
|
||||||
|
- [x] 跑本组与N06;反例断言每条红色连线都有对应连接error/差异,纯文字warning没有虚构接线变化。
|
||||||
|
- [x] 检查独立输入无expectation时证据仍可读;原生身份列差异与有效料号显示分开,不改写raw以统一数值。
|
||||||
|
- [x] Commit `feat: build traceable pin and network comparison evidence`。
|
||||||
|
|
||||||
|
## N09:A工作台、独立新建与证据检查器
|
||||||
|
|
||||||
|
**Files:** Create `UI/verification_workspace.py`、`UI/verification_controller.py`、`UI/verification_inspector.py`;Modify `UI/main_window.py`、`UI/icons.py`,样式仅加本页控件选择器;Test `tests/ui/test_verification_workspace.py`、`test_verification_inspector.py`。
|
||||||
|
|
||||||
|
**Interfaces:** `VerificationWorkspace(service, parent=None)`;`open_task(task_id, item_id=None)`、`set_active(active)`、`shutdown()`、`busy`、`busy_changed`;`VerificationInspector.set_evidence(evidence)`。controller通过N04查询,未来增量输入仅更新结果查询,不重新设计来路入口。
|
||||||
|
|
||||||
|
- [x] 写四导航映射、始终可新建、已有任务时独立导入、无来源横条、选择保持、不同任务延迟回调、DIFFERENT不显示通过的Qt测试。沿用既有`ui` fixture,但不更改其修复逻辑。
|
||||||
|
- [x] Run `.venv/Scripts/python.exe -m pytest tests/ui/test_verification_workspace.py tests/ui/test_verification_inspector.py -q`,确认失败。
|
||||||
|
- [x] 按最终图建立任务列表/状态筛选/工程表/右证据/固定底栏;main_window按页面对象明确映射四导航,DSH懒加载不被触发。新建对话框只含名称与可选前后工程,不要求来源选择。
|
||||||
|
- [x] QPainter或Qt原生控件渲染N08确定性图,表格同源;保持8–12px圆角、白色数据面、已有亚克力外框和减少透明度设置。980宽改可展开详情,不遮住开始/停止按钮。
|
||||||
|
- [x] 跑本组、现有history/DSH导航与样式测试;无后台run时点击导航或选工程只查询,不隐式导出。
|
||||||
|
- [x] 人工看1280×880、980×700及125/150%缩放;右侧R12对照保持1/2位置,警告/未知文字可读。静态图片仅视觉参考,不算功能验收。
|
||||||
|
- [x] Commit `feat: add the independent verification workspace and evidence inspector`。
|
||||||
|
|
||||||
|
## N10:开始、停止、重校验、崩溃恢复与版本竞争
|
||||||
|
|
||||||
|
**Files:** Modify `V/service.py`、`V/store.py`、`V/runner.py`、`UI/verification_controller.py`、`UI/main_window.py` 仅校验生命周期;Test `tests/v1_1/test_verification_control.py`、`tests/ui/test_verification_control.py`。
|
||||||
|
|
||||||
|
**Interfaces:** `start(task_id, *, selection: tuple[tuple[str,int], ...] | None, request_id)`,None表示服务端冻结当前全部ready;`stop(run_id, *, request_id)`;`rerun(item_id, version, *, request_id)`;`recover() -> dict`;`begin_shutdown()`。停止/恢复均不调用替换停止/准备重试/核验恢复函数。
|
||||||
|
|
||||||
|
- [x] 写重复点击、冻结范围不吞新项、当前v2不被v1完成覆盖、取消与提交竞争、进程退出未知、重启不自动执行的测试。queued取消保留历史;整run停止前从未派发项投影回待校验,用户单项取消显示已停止。
|
||||||
|
- [x] Run `.venv/Scripts/python.exe -m pytest tests/v1_1/test_verification_control.py tests/ui/test_verification_control.py -q`,确认失败。
|
||||||
|
- [x] 实现命令幂等与持久stop_requested;领取前/后、原生导出阶段和发布CAS前检查。终态提交先发生时保留真实结果;取消先发生时旧callback不能提交当前结果。
|
||||||
|
- [x] 实现重启核实OwnedCli身份/退出、F15产物补提交和interrupted;归属核对使用原owner/token/进程创建身份,不仅凭PID,以免PID复用误杀外部进程。未知资源留stopping,禁止盲目新导出。新attempt递增generation,旧terminal不改回running。
|
||||||
|
- [x] 跑本组及旧网表暂停组;在全部校验控制测试中将既有替换动作设为抛AssertionError,证明不会触发。GUI关闭不join/wait原生进程,通知安全结束后再关闭。
|
||||||
|
- [x] 受控慢导出期间切页、建新任务和停止,验证事件循环可响应;新工程后到保持待校验,不无限扩展当前run范围。
|
||||||
|
- [x] Commit `feat: control and recover independent verification attempts`。
|
||||||
|
|
||||||
|
## N11:完整报告、历史与证据保留
|
||||||
|
|
||||||
|
**Files:** Create `V/report.py`;Modify `V/service.py`、`UI/verification_controller.py`、`retention.py` 仅保护校验引用,复用HistoryRepository;Test `tests/v1_1/test_verification_reports.py`、`tests/ui/test_verification_report_actions.py`;Create `docs/user/independent-verification.md`。
|
||||||
|
|
||||||
|
**Interfaces:** `render_item_report(result_ref: dict, destination: Path) -> Path`;`export_task(task_id, destination: Path, *, request_id)`;`open_evidence(attempt_id, artifact_id)`只接受受管artifact标识。导出冻结view_revision,可在运行中生成并明确未完成项。
|
||||||
|
|
||||||
|
- [x] 写同版本报告/图表一致、HTML转义、原证据损坏、导出重名、运行中快照、清历史不删证据、缓存不可伪装新结果的测试。
|
||||||
|
- [x] Run `.venv/Scripts/python.exe -m pytest tests/v1_1/test_verification_reports.py tests/ui/test_verification_report_actions.py -q`,确认失败。
|
||||||
|
- [x] 从N08证据包渲染HTML/JSON,字段转义,原始文件只引用或用户明确选择后打包;默认不复制整个工程。报告固定输入/策略/工具/attempt摘要与检查范围。
|
||||||
|
- [x] 暂存→完整性核验→原子发布,重名目录明确错误不混写;HistoryRepository用稳定source_key防重复记录校验事件,此source_key为事件去重而非UI来源类型。
|
||||||
|
- [x] 跑本组与retention/history回归,核对当前/活动引用不可被普通日志清空删除,失去证据时显示不可用而非缓存绿灯。
|
||||||
|
- [x] 写用户说明:新建/自动接收无需来源、开始范围、警告/异常/未知、版本更新、停止重启、对照图与证据查看;不宣称ERC/PCB已检查。
|
||||||
|
- [x] Commit `feat: export verification evidence and preserve result history`。
|
||||||
|
|
||||||
|
## N12:集成、真实只读输入、包内入口与发布门禁
|
||||||
|
|
||||||
|
**Files:** Create `tools/verify_independent_verification.py`、`tests/v1_1/test_independent_verification_acceptance.py`、`tests/ui/test_verification_acceptance.py`、`docs/testing/2026-11-17-independent-verification-acceptance.md`;Modify `packaging/DxPartReplace.spec`及打包测试只在确有静态遗漏时,保护现有本地变更。
|
||||||
|
|
||||||
|
**Interfaces:** CLI `--fixture-root ... --output ...` 与 `--native-before ... --native-after ... --output ...` 明确分开;后者只读两份合法已保存工程,不执行换料。原有真实新换料闭环由已有执行器/验收工具交接,本任务只验证新校验任务能接收和复核,不重做其他任务的修复。
|
||||||
|
|
||||||
|
- [x] 用真实临时SQLite、受控CLI和完整文件发布链建立端到端用例:两份工程创建、批量成功交接、增量乱序、24工程计数、命名警告、反脚、缺基线、停止、重启、v1/v2竞争、报告。每用例记录实际派发与原工程摘要,不用单纯固定绿灯填页面。
|
||||||
|
- [x] Run `.venv/Scripts/python.exe -m pytest tests/v1_1/test_independent_verification_acceptance.py tests/ui/test_verification_acceptance.py -q`,确认缺口;前置已全部实现时允许首跑通过,不为制造red破坏实现。
|
||||||
|
- [x] 实现验收CLI串联公开接口并非零退出失败,记录模型图片仅参考、新功能真实证据另存。真实只读副本上复核引脚字段与层级范围;未知范围保持未知,不修改源工程制造反例。
|
||||||
|
- [x] 运行全部新增组、现有网表/BOM/导航/关闭/DSH及打包回归;再按仓库默认配置运行默认suite一次。记录当前分支并行修复是否已合入,不能冒用旧108项或旧EXE结果。
|
||||||
|
- [x] 在实际包中验证四导航、缺CAD工具仍可新建/导入记录/看已有报告、正确unavailable、正常关闭;不携带厂商exe和客户fixture。若可用真实本次成功回执,验证自动交接与手工独立输入共存且零重复换料。
|
||||||
|
- [x] 输出验收矩阵每项结果、通过数量、精确构建/输入/策略摘要、失败现场和未测范围;未取得真实引脚Value/映射证明时保留未覆盖声明。
|
||||||
|
- [x] Commit `test: accept independent verification tasks and evidence workflows`,功能完成后再走集成/发布决策;本计划不授权发布。
|
||||||
|
|
||||||
|
## 1. 场景到任务的验收映射
|
||||||
|
|
||||||
|
| 场景 | 必须满足 | 任务 |
|
||||||
|
| --- | --- | --- |
|
||||||
|
| 前面已有替换任务,仍新建独立校验 | 新建不依赖或覆盖换料任务,不要求来源 | N02/N03/N09 |
|
||||||
|
| 成功结果批量与分次传入 | 当前数据相同,重复与旧版不派发 | N02/N03 |
|
||||||
|
| 校验运行时收到新版本 | 旧输入固定,旧结果历史,新版待校验 | N02/N04/N10 |
|
||||||
|
| R12 1/2连接互换 | DIFFERENT,固定脚号图与逐脚表同源 | N06/N08/N09 |
|
||||||
|
| loop→outloop且结构不变 | WARNING,不能直接无提示通过 | N06/N07 |
|
||||||
|
| 缺引脚字段或库内映射 | unknown/未覆盖,必查未知不通过 | N01/N07 |
|
||||||
|
| 只有网名变 | 拓扑与名称分别显示,不套引脚改名放行 | N06 |
|
||||||
|
| 无清单两份工程 | 可比较,不能说换料规则符合 | N01/N03/N06 |
|
||||||
|
| CLI/解析/证据失败 | 明确原因,安全收尾后继续,未知资源暂停 | N05/N10/N11 |
|
||||||
|
| 关闭/崩溃/迟到回调 | 不重做换料、不污染新尝试,重启不自运行 | N10 |
|
||||||
|
| 图、表、报告、raw | 同一输入/issue/attempt,能追溯 | N08/N11 |
|
||||||
|
| 24项及1000工程规模 | 当前版本计数正确,100行有界读取,事件循环可响应 | N04/N09/N12 |
|
||||||
|
|
||||||
|
## 2. 分段交付与未实现边界
|
||||||
|
|
||||||
|
1. N01~N04:可以创建、接收和查询独立任务,先不宣称校验完成。
|
||||||
|
2. N05~N08:可独立执行、输出分级结论与人工证据;无法读取的字段保留unknown。
|
||||||
|
3. N09~N11:最终A页面、控制、报告与历史完整可用。
|
||||||
|
4. N12:真实输入、包内入口与回归结果已留证,交付本地开发包;默认回归仍有既有时序波动,不据此发布。
|
||||||
|
|
||||||
|
共12个新增功能任务、84个复选步骤已逐项实施和执行验证;测试波动及未覆盖能力见验收记录,勾选不表示已满足发布门槛。本文不是把旧计划未完成项全部重做:原生后端、非阻塞换料和当前修复仍沿用已有成果。未来替换实时推送、自动启动开关、未知电气语义字典、库映射扩展和自动修复均不作为首版暗含承诺。
|
||||||
@@ -0,0 +1,22 @@
|
|||||||
|
# 保存后原生数据核验实施计划
|
||||||
|
|
||||||
|
用户已确认:原生数据定位 → DxDesigner 仅负责目标器件替换、属性写入和保存 → 从已保存数据库导出数据核验。此轮修正上一轮没有移除的 CAD 全页核验,不增加第二套全页保护。
|
||||||
|
|
||||||
|
## 约束与接口
|
||||||
|
|
||||||
|
- 正常执行不调用 QPCurrentSemanticState、QPVerifyUntouched、QPNativeCapture/QPNativeRead,不为核验关闭重开 CAD。工程末保存关闭一次;下一工程复用 CAD 会话。
|
||||||
|
- 写入所需的目标器件定位、原实例属性快照、属性恢复与引脚编号提升仍属于写入操作,限于目标器件;不读取非目标属性/样式/连接。禁止把全页检查改名后继续运行。
|
||||||
|
- 新目标快照使用 `X\tsaved_netlist_v1` 标记;保留原 M/C/A 格式及旧操作编号。C.connections 使用 `NETLIST` 表示连接由保存后原生导出核验,不查询 CAD 连接。旧快照/旧恢复证据按原协议处理,不删除历史保护。
|
||||||
|
- 新 CAD 工程收尾清单第一行第三列为 `project_saved`;只证明写入/保存/关闭已返回,不能当成 `project_verified`。各项保持 pending_save,原生导出核验通过后才提交 saved_ok/verified。
|
||||||
|
- 原生 helper 新快照成功阶段为 `native_replace_applied`,保留事务/库件/尝试身份;旧快照仍保留 native_replace_verified。新正常路径不做全页前后 COM 验证。
|
||||||
|
- Python 在确认工程关闭后,复用 native_netlist.capture_project/export_netlist 与原生证据校验,按工程/页/位号对齐全部暂存目标;核验料号、Value/NC、Cell 和可导出的库件属性。证据不完整、目标缺失、属性错误均不得提前完成,不回退 CAD。
|
||||||
|
- 独立前后网表比较继续单独展示;尽量复用同一份保存后导出,不再次驱动 CAD。原生格式不覆盖文字位置/字体/颜色,明确覆盖范围,不伪造图形证明。
|
||||||
|
- 新回执/重启/暂停/恢复不再要求 full_sheet_v1 或 CAD value-readback TSV;使用有保存源与原尝试绑定的原生导出证据。旧回执验证保留兼容。
|
||||||
|
- 不改原工程、中心库、Excel;真实验证仅新副本。保留用户和其他聊天文档。当前功能分支继续,本轮基点 d9cf6a0。
|
||||||
|
|
||||||
|
## 实施与验证
|
||||||
|
|
||||||
|
1. VBS/native_helper:先写真实函数测试,令任何正常路径全页扫描调用都失败;实现仅目标写入、工程保存关闭及 project_saved 协议。测试两项目标、合法多单元、暂停前缀、旧恢复兼容。
|
||||||
|
2. Python 原生核验/回执:先写缺失/错误目标、原生导出失败、无 CAD 的正例;接入工程提交回调和持久证据。不得以省略 baseline 的方式给旧回执放行。
|
||||||
|
3. 集成:同步运行时关闭检查点、journal、恢复与独立网表导出复用。先 RED 后 GREEN;真实副本两项替换比较扫描次数与计时,确认全页 CAD 采集为零、无保存后重开。
|
||||||
|
4. 针对改动回归、独立审查、记录真实限制并提交本地变更。此次先改执行链;上一轮候选程序保留,不将旧包冒充本轮源码。
|
||||||
@@ -0,0 +1,158 @@
|
|||||||
|
# 工程校验功能开发与交付计划
|
||||||
|
|
||||||
|
> **For agentic workers:** REQUIRED SUB-SKILL: Use `superpowers:executing-plans` with the linked N01~N12 detailed plan. This is the delivery entry point, not authorization to begin application changes. N01–N12 implementation and local development-package acceptance are complete; continuous full-suite stability remains a release gate.
|
||||||
|
|
||||||
|
**Goal:** 开发独立校验任务、可信判断和可人工复核的 A 工作台,复用现有能力,只增加缺失功能。
|
||||||
|
|
||||||
|
**Architecture:** 按“任务数据 → 独立校验 → 人工证据 → 页面与操作 → 验收”顺序交付。任务、工程输入版本、执行尝试分开持久化;统一接收接口适配当前批量交接和未来增量推送;判断、图、表和报告共享一份事实。
|
||||||
|
|
||||||
|
**Tech Stack:** Python 3.12、SQLite、PySide6、现有原生网表CLI与进程归属机制、pytest/pytest-qt;不新增运行时依赖。
|
||||||
|
|
||||||
|
**Spec:** [已确认业务设计及六张流程/状态图](../specs/2026-11-17-independent-verification-business-design.md)。逐文件接口、测试命令和提交步骤见 [N01~N12 开发清单](2026-11-17-independent-verification-new-features.md)。
|
||||||
|
|
||||||
|
## Global Constraints
|
||||||
|
|
||||||
|
- 只做新增功能,不接手其他任务的退出、资源回收、工程统一提交或任务徽标修复。
|
||||||
|
- 任何时候可新建校验,不展示或要求选择来源,不加换料流水线横条。
|
||||||
|
- 当前接收已提交成功结果;增量、去重和版本接口做好,但本轮不开发替换实时刷新。
|
||||||
|
- 使用固定前后副本;不自动换脚、不重新换料、不写原工程或库。
|
||||||
|
- 位号/物理脚号/连接严格;引脚文字变化单独警告;缺证据明确未知。
|
||||||
|
- 工具判断、人工接线图、事实表、报告绑定同一工程版本和同一次尝试。
|
||||||
|
- 每任务先验证失败用例、最小实现、相关回归、自审和单独提交。功能完成前不发布。
|
||||||
|
|
||||||
|
## 1. 开工前处理
|
||||||
|
|
||||||
|
现在共享工作区的公共执行模块正在由其他任务修改,包括回执、工程统一保存、身份关联、资源隔离和 UI 状态。不得复制或清理这些未提交修改,也不得在其上混入本功能实现。
|
||||||
|
|
||||||
|
实施时使用独立开发分支 `codex/independent-verification` 和独立工作目录,按 `superpowers:using-git-worktrees` 流程准备。先核对已有分支是否存在并保留工作;不重置用户分支。基础纯逻辑和新增文件可基于已提交主线开发;接线前将其他任务的已合入修复同步进来,再复核接口。
|
||||||
|
|
||||||
|
| 接口边界 | 我们需要什么 | 处理原则 |
|
||||||
|
| --- | --- | --- |
|
||||||
|
| 工程身份 | 实例范围、生效位号、物理脚号及可靠对应证据 | 延用最新位号唯一关联规则;UID 为证据,不因UID缺失/变化一律拒绝 |
|
||||||
|
| 成功交接 | 真正已保存、关闭/重开回读的工程提交证明 | 待保存或只完成内存替换的项不得交接为成功 |
|
||||||
|
| 输入副本 | 本次 before、after、范围与摘要 | 缺失就登记无法校验,不能补造历史before |
|
||||||
|
| 预期变化 | 相对同一before的累计已成功修改及固定规则 | 不只传最后一条改动,不从after实际值反推预期 |
|
||||||
|
| 自有资源 | 当前本域CLI的归属和退出证明 | 复用既有接口,不修CAD退出;隔离桌面不被错误等同未退出CLI |
|
||||||
|
| UI公共文件 | 四导航插入点、关闭协作、主服务引用 | 窄范围接线,不覆盖其他任务实时刷新或状态投影改动 |
|
||||||
|
|
||||||
|
接线不满足时仍可完成本域数据/规则测试;不得用虚构成功回执凑出可演示闭环。若同名类/方法已经被新版本增加,应先复用,不按旧文件清单重复建设。
|
||||||
|
|
||||||
|
## 2. 四个开发阶段
|
||||||
|
|
||||||
|
| 阶段 | 任务 | 完成后能做什么 | 阶段验收条件 |
|
||||||
|
| --- | --- | --- | --- |
|
||||||
|
| 第一阶段:校验任务与数据 | N01~N04 | 创建空任务、导入两份工程、接收成功项、保存版本和查询状态 | 重复/乱序不重复建项;新版本不覆盖旧输入;无来源限制;缺证据可见 |
|
||||||
|
| 第二阶段:独立校验与人工证据 | N05~N08 | 独立导出、逐项判断、警告分级,生成前后接线图所需数据 | 反脚检出;改名有警告;未知不通过;图和表能定位到原始证据 |
|
||||||
|
| 第三阶段:A 页面与完整操作 | N09~N11 | 第四页、任务选择、开始/停止/重校验、前后对照、报告和历史 | 有其他任务仍可新建;控制操作不换料;关闭重启安全;报告可独立复核 |
|
||||||
|
| 第四阶段:集成与交付验收 | N12 | 在实际应用包中完成两种输入路径和混合批次 | 相关/默认回归、真实只读输入、产物身份、正常关闭全部留证 |
|
||||||
|
|
||||||
|
前三个阶段是内部可测交付,不等同发布版本。每阶段更新同一进度记录,注明实际完成的任务、提交、测试和能力缺口,不依据图片或测试数量推断已经支持的业务范围。
|
||||||
|
|
||||||
|
## 3. 十二个任务的工作量边界
|
||||||
|
|
||||||
|
| ID | 要实现的最小完整内容 | 依赖 | 做完怎么判断 |
|
||||||
|
| --- | --- | --- | --- |
|
||||||
|
| N01 | 输入、逐项检查、执行状态、结论和覆盖合同 | 无 | 空检查/缺必查不一致,错误优先,警告与未知分别保留 |
|
||||||
|
| N02 | SQLite校验任务、工程、不可变版本、尝试、运行与去重 | N01 | 同版同文幂等,同版异文拒绝,只有一个活动尝试,旧DB正常打开 |
|
||||||
|
| N03 | 独立导入、统一发布、成功交接和有界补交 | N02 | 一次批量和分次发布结果相同;只交接提交成功范围;创建不派发 |
|
||||||
|
| N04 | 当前版本投影、计数、分页、筛选、历史 | N03 | 24项计数正确,旧结果不重复,筛选不改变批量命令范围 |
|
||||||
|
| N05 | 复用原生导出的独立只读runner | N02、N03 | 不调用替换/CAD写入,工作副本隔离,资源忙只排队 |
|
||||||
|
| N06 | 器件/物理脚/连接/属性/名称的判断分级 | N01、N05 | 断线短接反脚、错属性均定位;允许改名给警告;缺证据未知 |
|
||||||
|
| N07 | 引脚Value、逻辑名、电气类型能力验证与适配 | N05、N06 | 证明字段来源与脚号对应;拿不到就unknown,不替代字段 |
|
||||||
|
| N08 | 同源issue、接线图数据、对照表和raw定位 | N06、N07 | 1/2脚前后位置固定,红线有对应事实,文字警告不画成接错线 |
|
||||||
|
| N09 | A页面、独立新建、四导航、工程表与检查器 | N04、N05、N08 | 与整体UI一致,已有任务时仍可新建,无来源/流水线横条 |
|
||||||
|
| N10 | 开始/停止/继续/重校验、关闭重启与版本竞争 | N05、N09 | 停止未派发项保留待校验,迟到结果不串版本,零重复换料 |
|
||||||
|
| N11 | 单项/整任务HTML/JSON、证据打开、历史和引用保留 | N08、N10 | 图表报告对应同一证据包,运行中报告标未完成,清历史不删证明 |
|
||||||
|
| N12 | 服务/Qt/真实只读输入/实际包验收 | N01~N11 | 全链路证据可复查,失败现场保留,支持范围写明 |
|
||||||
|
|
||||||
|
顺序执行即可,不需要同时派多个代理。每项具体文件、接口签名、用例和7步清单在[N01~N12详细清单](2026-11-17-independent-verification-new-features.md)中;共84步,不在此重复创建另一套进度复选框。
|
||||||
|
|
||||||
|
## 4. 最早验证的两个能力点
|
||||||
|
|
||||||
|
N01~N04开发期间可以提前做N07的只读探针,尽早知道业务边界;只读探索结果不等于N07任务已完成。
|
||||||
|
|
||||||
|
| 能力点 | 成功时 | 无法取得时 |
|
||||||
|
| --- | --- | --- |
|
||||||
|
| 引脚级Value/名称/类型 | 保存准确字段、存在性、原始定位,与物理脚绑定后比较 | 明确标该字段未覆盖;用户必查时INCOMPLETE;不得用器件Value代替 |
|
||||||
|
| 库内引脚到焊盘映射 | 只有确切库版本和绑定证明才启用检查 | 首版显示未覆盖,不承诺能发现网表未体现的库内反脚 |
|
||||||
|
|
||||||
|
已确认的工程接线反脚检查不能因为扩展映射拿不到就不做;也不能因为基础网表一致而宣称库内部映射通过。GND/VCC文字变化的语义字典和自动严重性仍沿用业务稿的保留决定,不在开发时临时让模型判断。
|
||||||
|
|
||||||
|
## 5. 开发时固定的接口载荷
|
||||||
|
|
||||||
|
这里固定形状,摘要、ID和受管路径由服务生成,示例是结构说明,不是可跳过验证的真实输入。
|
||||||
|
|
||||||
|
```python
|
||||||
|
input_record = {
|
||||||
|
'item_key': 'stable-project-comparison-key',
|
||||||
|
'project_key': 'stable-project-identity',
|
||||||
|
'input_version': 1,
|
||||||
|
'before_ref': {'manifest_id': 'before-id', 'sha256': 'a' * 64},
|
||||||
|
'after_ref': {'manifest_id': 'after-id', 'sha256': 'b' * 64},
|
||||||
|
'expectation_ref': None,
|
||||||
|
'check_plan': {
|
||||||
|
'policy_version': 'verification-v1',
|
||||||
|
'required_checks': ['inputs', 'coverage', 'components', 'physical_pins', 'connections', 'net_names'],
|
||||||
|
'optional_checks': ['pin_text'],
|
||||||
|
'excluded_checks': ['footprint_mapping'],
|
||||||
|
},
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
校验task_id与submission_id为外层命令参数;没有 source 字段。expectation_ref=None仅说明未核对换料规则;若后来提供规则,要发布新版本,不能修改原检查上下文。check_plan的id与N01实际定义保持一致,类型/枚举/摘要长度在边界拒绝非法值。
|
||||||
|
|
||||||
|
结果包至少分开保存:输入版本、attempt/generation、执行state、verdict、coverage、checks、issues、artifacts、resource_state。界面不得把attempt succeeded当成verdict CONSISTENT。
|
||||||
|
|
||||||
|
## 6. 每个提交的验证流程
|
||||||
|
|
||||||
|
1. 写本任务明确反例,运行该测试确认失败原因属于本功能缺失。
|
||||||
|
2. 实现最小完整逻辑;同步所有调用方、必要fixture、序列化和导出。
|
||||||
|
3. 运行该任务测试和与公共边界相关的既有回归,失败则定位根因,不通过跳过/放宽断言凑绿。
|
||||||
|
4. 对照业务稿检查状态、图表数据、证据绑定和失败路径;确认未调用换料/恢复入口。
|
||||||
|
5. 只提交本任务文件,记录提交SHA、实际命令、通过数量和未测范围,再进入下一项。
|
||||||
|
|
||||||
|
本仓库默认测试路径在 `pyproject.toml` 中为 `tests/v1_1` 与 `tests/ui`;只运行裸pytest不能声称DSH/打包组已测。N12需显式执行相关扩展组后,再跑默认suite。
|
||||||
|
|
||||||
|
```text
|
||||||
|
.venv/Scripts/python.exe -m pytest tests/v1_1/test_native_cli_netlist.py tests/v1_1/test_netlist_execution.py tests/v1_1/test_pr27_netlist_pause.py -q
|
||||||
|
.venv/Scripts/python.exe -m pytest tests/ui tests/dsh tests/packaging -q
|
||||||
|
.venv/Scripts/python.exe -m pytest -q
|
||||||
|
```
|
||||||
|
|
||||||
|
第一条是旧原生网表边界回归;第二条涵盖UI、DSH、打包;第三条按项目默认配置验证。具体新增测试文件由N01~N12逐项命令执行,不能只跑以上旧测试声称新功能完成。进程级测试使用新的短路径basetemp,环境变量仅对测试进程设置,不改系统用户环境。
|
||||||
|
|
||||||
|
## 7. 最终交付门槛
|
||||||
|
|
||||||
|
| 验收面 | 必须提供的证据 |
|
||||||
|
| --- | --- |
|
||||||
|
| 功能路径 | 已有换料成功数据交接与用户独立两份工程均可创建、运行、查看、重校验,且可共存 |
|
||||||
|
| 业务正确性 | 反脚/断线/短接/错属性/命名警告/缺证据均给出对应事实与范围 |
|
||||||
|
| 人工说服力 | 同一R12反脚在图、逐脚表、HTML报告、raw证据四处一致,能看出为什么异常 |
|
||||||
|
| 版本与幂等 | 重复接收零重复项;v1结果不覆盖v2;同版异文拒绝;旧attempt不能覆盖新结果 |
|
||||||
|
| 非阻塞与失败 | 单项问题保留后继续其他可运行项;资源/存储不确定时暂停正确范围,不假报通过 |
|
||||||
|
| 使用体验 | 980×700、1280×880和125%/150%可读;慢查询可导航和停止;新建按钮始终可用 |
|
||||||
|
| 生命周期 | 正常关闭、崩溃恢复、停止继续、证据丢失、历史清理均不损坏输入或重复换料 |
|
||||||
|
| 包与范围 | 实际包启动/入口/关闭、工具缺失原因、精确产物与输入摘要;未覆盖能力明确列出 |
|
||||||
|
|
||||||
|
开发不设虚假的固定天数。每阶段通过验收出口后再推进;引脚字段/封装映射的探索结果影响能承诺的检查范围,不影响先交付可信基础校验和证据页面。
|
||||||
|
|
||||||
|
## 8. 交接状态
|
||||||
|
|
||||||
|
### N12 后续闭环标准(2026-11-18)
|
||||||
|
|
||||||
|
所有后续任务按[闭环标准 v1](../../testing/verification-closed-loop-standard.md)留证;不再用“导入成功”“文件已生成”或历史分组通过数量单独宣布闭环完成。批量添加见[验收记录](../../testing/2026-11-18-verification-batch-import.md)。
|
||||||
|
|
||||||
|
- [x] C01~C05:开始前冻结名单/输入/策略,核对实际运行成员、预期结论、同源图表与报告、原文和退出证明;源文件不变、新增换料操作为0。
|
||||||
|
- [x] C06:实际包正常关闭后重启,证据可回读,尝试数不增加。
|
||||||
|
- [x] C07:实际包单项重校验,新attempt及generation递增,旧结果/报告不被覆盖。
|
||||||
|
- [x] C08受控回归:反脚、命名警告、必查未知、停止/资源未知、版本竞争和单项失败后继续的服务/Qt反例。
|
||||||
|
- [x] C08实际包补充:原生导出失败项先运行,后续正常项仍完成;混合批次的报告、重启和重校验均通过,见[本轮闭环验收](../../testing/2026-11-18-verification-closed-loop.md)。
|
||||||
|
- [x] C08实际包停止与资源未知:已有各自独立现场,见[剩余闭环执行记录](2026-11-18-verification-remaining-closure.md);三工程停止/继续和自有实例异常退出后资源未知保护分别通过。
|
||||||
|
- [x] 真实已保存换料回执触发的自动交接实际包闭环:新临时副本真实换料1项,自动交接后校验、报告、重启和重校验通过,校验期间换料增量0;见同一执行记录。
|
||||||
|
- [x] 连续默认全量:两轮2276 passed,固定提交上的最终运行0失败/0错误,631个产品/测试/工具文件运行前后不变;扩展120 passed、1 skipped(缺7-Zip)。未改旧时序断言,完整结果见[最终闭环验收](../../testing/2026-11-18-verification-final-closure.md)。
|
||||||
|
|
||||||
|
单次只读验收入口为 `tools/verify_independent_verification.py --expect-verdict ...`,明确只覆盖 C01~C05;实际包入口为 `tools/accept_verification_closed_loop.py`,覆盖独立输入 C01~C07,并可用 `--fault-batch` 增加原生失败隔离反例。未测项在JSON里保留not_run。测试失败或标准不符均非零退出;已有换料历史采用执行前基线,不能要求历史总数为0。
|
||||||
|
|
||||||
|
用户授权的 N01~N12 已顺序实现、分步提交并完成本地开发包验收。11月18日后续批量导入及四项剩余闭环均已完成:独立输入和真实换料保存交接两条实际包路径通过,停止与资源未知保护通过,固定版本的默认全量2276项通过。历史波动记录保留,不宣称修复其全部根因。未合并、推送或发布,本分支没有复制另一修复任务的未提交修改。
|
||||||
|
|
||||||
|
实施进度及验证结果见 docs/testing/2026-11-17-independent-verification-acceptance.md。后续开发以本入口和[N01~N12清单](2026-11-17-independent-verification-new-features.md)共同为准,11月6日的V/U旧计划保留为历史参考,不能再并行照旧重建后端或来源界面。
|
||||||
@@ -0,0 +1,28 @@
|
|||||||
|
# 固定私有桌面跨批复用 Implementation Plan
|
||||||
|
|
||||||
|
**Goal:** 外部 Agent 保留 HDESK 引用时,正常批次和重启继续复用同一个受管理桌面,停止按批次增加桌面对象。
|
||||||
|
|
||||||
|
**Architecture:** 用现有 supervisor 领取当前用户/登录会话/窗口站唯一的命名槽位。桌面名称稳定,租用编号、Job 和执行代次每批独立;先确认写进程退出,再归还槽位,保留对象未消失的事实。原批次资源与业务回执仍沿用现有规则。
|
||||||
|
|
||||||
|
**Tech Stack:** Python 3.12、pywin32、现有原子 JSON 记录和 Windows Job;无新依赖、常驻服务或桌面池扩容。
|
||||||
|
|
||||||
|
**Spec:** `docs/testing/2026-11-18-desktop-reuse-research.md`,用户已明确批准实施,沿用当前功能分支,不涉及校验工作台。
|
||||||
|
|
||||||
|
## 约束
|
||||||
|
|
||||||
|
- 原工程、中心库和 Excel 不作为故障注入对象;真实验证使用新副本。
|
||||||
|
- 命名槽位跨 data-root/应用重启一致,跨用户/登录会话隔离。
|
||||||
|
- 空窗口列表不能证明写进程退出;实际 Job 与精确进程身份是交接依据。
|
||||||
|
- 崩溃中断的启动窗口不能假报零写入或自动重放;新槽位不能绕过旧写入者。
|
||||||
|
- 对象复用与桌面消失分别记录;旧租用不能关闭新代次的 CAD。
|
||||||
|
- 正常批次仍退出 Mentor,不关闭外部 Agent 或远程强关其句柄。
|
||||||
|
- 缓存命中和纯 CLI 不获取桌面。
|
||||||
|
|
||||||
|
## 步骤
|
||||||
|
|
||||||
|
1. [x] 新增 `desktop_slot.py` 与 `test_desktop_slot.py`。先以跨 root 顺序租用、竞争、放弃的互斥量、存活旧 writer、挂起 launch、损坏记录与重复归还建立 RED;实现稳定名称、命名互斥、持久来源、启动前 Job 记录、不可变归还证明和释放。
|
||||||
|
2. [x] 修改 `isolated_desktop.py`:显式 managed 模式;新批 Job 命名与启动阶段绑定;关闭本批进程/句柄后归还;外部残留不重复等待/关闭。同步 `batch_runtime.py`、独立 `isolated_cad.py`、`cell_catalog.py` 的实际入口,测试证明记录使用真实稳定名称、库读取严格验证进程释放且保留桌面残留。
|
||||||
|
3. [x] `batch_resources.py` 兼容旧 UUID 记录,管理新租用的历史观察;补旧/新租用隔离、进程仍活跃和归还证明损坏的测试,维持回执及源文件保护。
|
||||||
|
4. [x] 使用生产入口实测外部持有、20 次跨进程轮换、并发争用、owner 崩溃/子 Job 未退;副本工程跑两批 Mentor,核验原生数据和桌面数量。完成受影响回归、差异审查与本地提交,记录不覆盖的故障机条件。
|
||||||
|
|
||||||
|
验证临时目录使用 `D:/CodexValidation/managed-desktop-20261118/`。每个新分支先观察预期失败,完成后检查 XML/退出码;不将 Win32 探针作为业务样本。
|
||||||
@@ -0,0 +1,16 @@
|
|||||||
|
# 剩余四项闭环执行计划
|
||||||
|
|
||||||
|
用户确认顺序实施并允许在工具新建的临时副本中执行真实换料。使用 `codex/independent-verification` 工作区,不修改另一修复工作区,不合并/推送/发布。
|
||||||
|
|
||||||
|
- [x] 实际包停止、重启不重跑、继续未派发项、明确重校验已停止项。三工程现场:`D:/dx-vfy-stop-three-20261118/acceptance.json`,两项未派发均保持待校验,继续和重校验的报告绑定通过。
|
||||||
|
- [x] 本工具自有实例异常退出,按PID和创建时间证明后才中断;重启保留资源未知,不派发后续原生导出,仍能新建校验。现场:`D:/dx-vfy-owner-exit-20261118/acceptance.json`。不为闭环伪造退出证明,不终止其他进程。
|
||||||
|
- [x] 真实换料交接:临时副本 RV05 从4100-CA0000-T7替换至4100-CA0000-T0,RV11保持;真实保存回执自动登记,校验/报告/重启/重校验不新增换料。新现场 `D:/dx-vfy-real-handoff-20261118-v2/acceptance.json` 和其 `verification-loop/acceptance.json` 均通过;替换操作1条且verified,校验阶段增量0,声明属性检查为expected_change,原始样例及库LMC摘要未变。
|
||||||
|
- [x] 最终回归:两轮完整默认suite均为2276 passed;最终固定提交XML `D:/dx-vfy-fixed-default-20261118.xml`,运行前后631个产品/测试/工具文件摘要不变。执行恢复与打包扩展120 passed、1 skipped(缺官方7-Zip),最终包运行时和资源释放复核通过。没有用分组复核替代连续通过,也未放宽旧断言。
|
||||||
|
|
||||||
|
验收工具新增 `--control-scenario stop|owner-exit`、`--handoff-data`,真实换料入口为 `tools/accept_verification_saved_handoff.py`。后者只接受全新外部输出目录,先原生导出证明固定RV05/RV11前提,使用已有BOM/执行器和实际EXE运行;不通过直接修改SQLite制造回执。
|
||||||
|
|
||||||
|
交接场景的before来自不可变历史捕获,不能要求它的源文件在真实替换后仍保留旧字节;`freeze_inputs(..., historical_before=True)`要求冻结预期清单,核验历史副本完整性,以已保存after的源摘要建立校验只读基线。默认独立导入仍要求两个源与导入时摘要相同。
|
||||||
|
|
||||||
|
每项完成需:输入名单/摘要和预期在执行前固定;运行及报告身份一致;原始样例/共享库不变;测试副本仅发生一次授权替换;校验阶段新增换料为0;停止/异常状态不能被显示为一致。按[闭环标准](../../testing/verification-closed-loop-standard.md)逐项留passed/failed/not_run。
|
||||||
|
|
||||||
|
最终四项记录见[剩余闭环验收](../../testing/2026-11-18-verification-final-closure.md)。保留分支与独立工作目录;未合并、推送或发布。Value/库内部映射仍属于明确未覆盖的能力边界。
|
||||||
@@ -0,0 +1,402 @@
|
|||||||
|
# 独立工程校验:判断、执行、状态与失败处理
|
||||||
|
|
||||||
|
日期:2026-11-17。状态:业务细化稿,尚未实现新增功能。本文落实本次对话已确定的校验任务与 A 界面;未回答的引脚语义问题明确列为待人工确认,不擅自变成自动放行规则。
|
||||||
|
|
||||||
|
## 1. 用户使用方式与本轮范围
|
||||||
|
|
||||||
|
用户可以随时创建校验任务,选择修改前、修改后的工程。前面的替换成功结果也可以自动交接到校验任务;校验页不展示或要求选择来源,不把当前换料任务作为新建校验的前置条件。
|
||||||
|
|
||||||
|
当前先在已有替换执行结果落盘后一次性交接。接收接口支持批量、增量、去重和版本更新,为后续实时交接留接口;本轮不改替换任务的实时刷新机制。
|
||||||
|
|
||||||
|
用户在工程表里先看结论,再点开同一物理脚号的前后连接图、差异表和原始证据,能够独立复核。校验不修改工程,不自动换脚、不重新换料;发现的问题集中记录。
|
||||||
|
|
||||||
|
本轮新增:校验任务与输入接收、独立只读运行与恢复、判断分级、引脚元数据能力探测、可复核证据、A 工作台和报告。其他任务正在处理的退出/收尾修复、任务列表修复、既有替换状态机和性能优化不纳入本轮。
|
||||||
|
|
||||||
|
## 2. 现有能力怎样复用
|
||||||
|
|
||||||
|
检查基线:`main/v1.3.1@b19afc6`。工作区有并行进行的 issue29 修改;实施前再次核对实际主线,不能覆盖其改动。
|
||||||
|
|
||||||
|
| 已有模块 | 直接复用 | 新增边界 |
|
||||||
|
| --- | --- | --- |
|
||||||
|
| `native_netlist.py` | 固定副本、HIER/effective ASCII/Keyin 导出、层级/实例/gate 与物理连接交叉核验 | 新增领域层调用已有公开捕获/导出接口;不重写原生导出器 |
|
||||||
|
| `netlist_verification.py` | 完整导出缓存、原生库回执绑定、原计划/实际成功证据 | 提取或暴露接收固定输入的薄适配;原有队列入口保持兼容 |
|
||||||
|
| `native_cli.OwnedCliScope` | 隐藏进程、归属和退出证明 | 独立校验只拥有自己的 CLI,不接管替换 CAD |
|
||||||
|
| `batch_resources.write_record` | 原子文件发布 | 新报告先完整发布再提交数据库引用 |
|
||||||
|
| `TaskStore`、schema、事务锁 | 持久化与升级 | 只新增校验表,不写 execution_operations 终态或重试预算 |
|
||||||
|
| `LatestQuery`、`ServiceWorker` | 异步读取、旧回调隔离 | UI 不同步跑导出或遍历全工程 |
|
||||||
|
| `HistoryRepository`、现有样式 | 事件与窗口视觉 | 四导航、任务列表、工程表和证据检查器 |
|
||||||
|
|
||||||
|
现有比较器已能拒绝物理脚号/连接变化,并在已证明的目标符号替换中允许逻辑脚名变化;该变化目前没有警告。ASCII 引脚记录中的类型、引脚级 Value、库内焊盘映射不能因现有物理图通过而视为已覆盖。新增功能补充这些事实和范围,不全局放宽旧比较器。
|
||||||
|
|
||||||
|
## 3. 四种业务对象与身份
|
||||||
|
|
||||||
|
| 对象 | 是什么 | 身份与生命周期 |
|
||||||
|
| --- | --- | --- |
|
||||||
|
| 校验任务 task | 左侧一个名称,例如“电源板核对”;可以含多个工程 | 独立 task_id,随时新建;既有任务或排队不禁用新建 |
|
||||||
|
| 工程项 item | 中间表里的一行比较对象 | item_id;绑定 project_key、基线 before_id 和检查配置,不按名称猜测合并 |
|
||||||
|
| 输入版本 revision | 一对固定 before/after、预期变化及检查配置 | item_id + input_version;发布后不可修改 |
|
||||||
|
| 执行尝试 attempt | 对某个版本真正运行一次校验 | attempt_id + generation;重新校验增加尝试,不更改旧报告 |
|
||||||
|
|
||||||
|
另有批量命令 run:只冻结本次选择的 item/revision 集合、派发顺序和停止意图,不建立第二套工程结论。任务的状态与统计由当前工程版本推导,不另造会与工程行矛盾的通过标记。
|
||||||
|
|
||||||
|
同名工程不自动合并。同一个工程更换了 before 基线,建立新的工程项;不能把另一轮 before 覆盖到原项上。相同基线下的新 after 与累计预期变化才是新 input_version。
|
||||||
|
|
||||||
|
## 4. 统一输入与未来增量交接
|
||||||
|
|
||||||
|
### 4.1 统一接收合同
|
||||||
|
|
||||||
|
UI、文件导入和成功交接最终调用同一个 `publish_inputs(task_id, inputs, submission_id)`。没有 source/type/mode 等按来路分流的字段。
|
||||||
|
|
||||||
|
| 字段 | 必需 | 含义与校验 |
|
||||||
|
| --- | --- | --- |
|
||||||
|
| task_id | 是 | 已存在的校验任务;创建独立任务不要求换料任务存在 |
|
||||||
|
| submission_id | 是 | 请求去重键;相同键与不同正文冲突时拒绝 |
|
||||||
|
| item_key / project_key | 是 | 发布者持久身份;独立导入由服务生成,不使用显示名作为身份 |
|
||||||
|
| input_version | 是 | 同工程项内递增整数;较旧版本不得夺回当前版本 |
|
||||||
|
| before_ref / after_ref | 是 | 受管快照引用及 manifest 摘要;缺失证据可登记不可用工程项,不能伪造输入 |
|
||||||
|
| expectation_ref | 可空 | 已确认的预期属性变化与适用器件、证据引用;空表示未提供换料规则,不等于确认所有属性都应不变 |
|
||||||
|
| check_plan | 是 | 本次要求核对的维度、必查/可选范围和固定策略版本 |
|
||||||
|
| payload_digest | 服务生成 | 规范化内容摘要,绑定输入、预期和检查计划 |
|
||||||
|
|
||||||
|
内部证据仍保留真实执行回执、文件摘要和版本以供追溯,但它们不是 UI 的任务来源字段。不得以“没有换料任务”拒绝独立输入。
|
||||||
|
|
||||||
|
### 4.2 接收规则
|
||||||
|
|
||||||
|
1. task 不存在、外层结构不合法:整个请求拒绝,不修改任何任务。
|
||||||
|
2. 外层有效后逐条处理;一条坏输入不会撤销其他条已接收的输入。返回 accepted、duplicates、stale_ignored、rejected 以及逐条原因。
|
||||||
|
3. 相同 item_key/version/digest:幂等返回原记录,不加行、不重复排队。
|
||||||
|
4. 相同 item_key/version、不同 digest:记输入冲突,不覆盖。
|
||||||
|
5. 较旧版本:只返回旧记录或忽略,不成为当前版本。版本跳号允许,不能依据到达顺序推断修改顺序。
|
||||||
|
6. 新版本:原子发布新 revision,然后移动 current_revision 指针;旧输入、运行和结果保留。
|
||||||
|
7. 新工程/新版本默认待校验,接收本身不自动执行。正在运行的批量命令不自动吞入后来到达的项,避免未来持续流入导致命令永不结束。
|
||||||
|
8. 当前一次性交接与未来逐条交接具有相同语义;未来是否自动开始是独立运行设置,首版默认手动。
|
||||||
|
|
||||||
|
### 4.3 成功交接与独立输入
|
||||||
|
|
||||||
|
- 成功交接从已落盘、已保存回读且归属准确的回执读取成功范围,引用已冻结前后副本;失败、不确定或未执行项不冒充成功工程。工程内部分成功时只能交接有完整检查范围和可靠 after 的成功集合,明确预期范围;不能宣称整个替换计划完成。
|
||||||
|
- 若替换成功但附加校验副本缺失,仍登记该项并显示“缺少校验证据”,不撤销替换成功,也不从当前盘上补造旧 before。
|
||||||
|
- 当前已有网表报告可以作为证据导入,但只有输入、工具、解析器、检查策略和输出摘要均匹配时才复用;不能用旧 verified 字段直接点亮新任务。
|
||||||
|
- 独立新建填写任务名和前后工程;服务后台验证不同工程文件/数据库别名、源稳定性及可读性,冻结受管副本后发布同一种输入。没有预期清单时只比较结构和列出属性变化,不声称换料规则已符合。
|
||||||
|
- 交接失败不影响已保存换料结果。接收去重和已有回执扫描允许重新交接;UI 不在结束回调里等待全部捕获或导出。首版进入校验页或重启时扫描有界、尚未交接的已完成结果,且不为缺失 before 创建替代基线。
|
||||||
|
|
||||||
|
## 5. 判断规则:先证明能检查,再判断结果
|
||||||
|
|
||||||
|
每个检查返回 `check_id`、`state`、`required`、`issues`、`evidence_refs`、`coverage_reason`。state 为 equal / expected_change / warning / error / unknown / not_requested。所有异常都有明确事实;警告不能抵消异常,未知不能冒充相同。
|
||||||
|
|
||||||
|
### 5.1 输入与范围
|
||||||
|
|
||||||
|
| 编号 | 判断内容 | 具体逻辑 | 结果 |
|
||||||
|
| --- | --- | --- | --- |
|
||||||
|
| J01 | 前后输入可信 | manifest 存在、摘要匹配、数据库和配置属于声明对象,源在捕获时稳定 | 缺失/损坏则 unknown,停止依赖该输入的检查 |
|
||||||
|
| J02 | 能完整读出 | HIER 实例集合、effective 器件/脚/网络互反覆盖与 Keyin 物理端点覆盖一致 | 部分/截断/不支持配置则 unknown,不能比较两个不完整图判通过 |
|
||||||
|
| J03 | 器件身份 | 延用最新实例范围+生效位号唯一对应;UID保留为证据,缺失、重复、变化不得否定已证明的位号对应 | 缺件、多件或位号改变为 error;真实位号/实例对应歧义为 unknown,不做相似匹配 |
|
||||||
|
|
||||||
|
多 gate 使用工程实例范围+生效位号+物理脚作为对应依据,不能将同一位号的不同 gate 误报为重复器件;同一物理脚重叠仍为异常或无法完整核对。跨工程不合并身份。
|
||||||
|
|
||||||
|
### 5.2 脚号、连接和网名
|
||||||
|
|
||||||
|
| 编号 | 判断内容 | 具体逻辑 | 结果 |
|
||||||
|
| --- | --- | --- | --- |
|
||||||
|
| J04 | 物理脚号和集合 | 对应器件的物理脚号集合和占用次数必须相同,包括已知未连接脚 | 增减、重复或编号改变为 error;不能交换脚号消除差异 |
|
||||||
|
| J05 | 固定脚号的连接 | 每个端点 `(实例范围, 位号, 物理脚号)` 对应网络的完整端点集合前后相同 | 分组变化为 error;给出新增/丢失对端及网络分裂/合并 |
|
||||||
|
| J06 | 单连接端与未连接 | 有明确完整名册时区分“单端网络”“明确未连接”“导出未覆盖” | 已连接变未连接为 error,未覆盖为 unknown |
|
||||||
|
| J07 | 网名 | 连接分组相同后再比较名称 | 已识别自动生成名称变化保留说明;用户/未知网名变化保持 error,不能套用引脚文字警告 |
|
||||||
|
|
||||||
|
R12.1 原连 NET_LOOP/U1.3、R12.2 原连 GND/C5.2,修改后两者互换:J05 必须报错。器件数、脚数、网络总数相同不能抵消此错误。
|
||||||
|
|
||||||
|
比较本质是端点分组,不能因为另一个脚仍写 GND 就推断整个器件接线正确;两个网络同名也不能替代端点集合证明。
|
||||||
|
|
||||||
|
### 5.3 预期属性与引脚文字
|
||||||
|
|
||||||
|
| 编号 | 判断内容 | 具体逻辑 | 结果 |
|
||||||
|
| --- | --- | --- | --- |
|
||||||
|
| J08 | 有清单的器件属性 | 只允许固定 expectation_ref 声明的目标 UID/位号及字段按精确目标变化;其余字段保持原值 | 已声明且符合为 expected_change;漏换/错值/非目标变化为 error |
|
||||||
|
| J09 | 没有预期清单 | 仍列出全部属性变化,区分器件 Value、引脚 Value 和网络名 | 属性变更为 warning,标“未核对换料规则”;不得显示规则符合。无变化也只证明一致,不证明某个换料目标已完成 |
|
||||||
|
| J10 | 引脚 Value/名称 | 先按固定物理脚号对应;保留原始文字,单独记录变化;不能把器件 Value 充当引脚 Value | 文字相同为 equal。用户确认的 loop→outloop 且结构/连接保持时为 warning;其他名称变化为 warning 并提示功能需确认,不自动宣称功能等价 |
|
||||||
|
| J11 | 功能位置疑点 | 若 GND/VCC 等文字变化或原两脚文字对调,保留原始值和结构证据 | 输出高关注 warning“疑似功能变化,需人工确认”;是否升级 error 尚未由用户确认。若 J04/J05 或可靠库映射已证明互换,直接 error,不依赖名称猜测 |
|
||||||
|
| J12 | 库内映射 | 已有可靠方法能读取并绑定确切库版本、symbol/Cell 和引脚→焊盘映射时再核对 | 明确反脚为 error;未实现/拿不到为 unknown 或 not_requested,显式显示未覆盖 |
|
||||||
|
| J13 | 原生身份表 | Keyin Part 表与 effective Part Number 各自保留 | 旧身份列与有效料号不一致单列 warning/限制说明,不改写原始输出,不据此推导 PCB 已验证 |
|
||||||
|
|
||||||
|
J10 的“其他名称变化为 warning”只表示需要复核,不能解释为所有改名均安全。不能采用字符串相似度、模型猜测或全局 loop 替换来自动放行。引脚电气类型变更在可读取时与原值一起提示;其自动严重性字典首版不臆造。
|
||||||
|
|
||||||
|
预期值来自用户确认的清单、固定策略与可靠事务/库证据;不得从待校验 after 的实际字段倒推“预期就是这个值”。旧策略的特殊保留/NC 语义由已有函数解释并保留证据,本轮不另写一套换料策略。
|
||||||
|
|
||||||
|
### 5.4 首版检查范围
|
||||||
|
|
||||||
|
核心必查:可信输入、完整图、器件/位号、物理脚号、端点连接与名称;有 expectation_ref 时该范围内的预期属性也为必查。没有清单时属性检查为“只展示变化”,不能冒充目标检查。
|
||||||
|
|
||||||
|
引脚 Value/电气类型先做原生字段能力探测。探测未完成或字段缺失,报告明确 unknown;用户请求该项时不得算完整通过。库内部焊盘映射首版默认不请求,UI 固定披露“未覆盖:封装库内部映射”;有可靠适配器后才能启用为必查项。
|
||||||
|
|
||||||
|
检查计划记录 required_checks、optional_checks、excluded_checks 和策略摘要。未请求项不能被写成已检查;用户不能通过“一键忽略异常”改写原报告。只对当前输入和明确范围下结论。
|
||||||
|
|
||||||
|
## 6. 结论与执行状态必须分开
|
||||||
|
|
||||||
|
### 6.1 业务结论
|
||||||
|
|
||||||
|
```text
|
||||||
|
存在任何已证明 error → DIFFERENT(发现异常)
|
||||||
|
否则有必查 unknown → INCOMPLETE(无法完整校验)
|
||||||
|
否则有 warning → WARNING(检查完成,有警告)
|
||||||
|
否则全部必查 equal / expected_change → CONSISTENT(本次检查范围一致)
|
||||||
|
```
|
||||||
|
|
||||||
|
可选 unknown 使 coverage=partial 并显示未覆盖项;允许核心范围一致,但显示“核心检查一致,扩展项未覆盖”,不能笼统写全工程全部通过。必查 unknown 优先于警告,已经证明的异常优先于 unknown,两类事实都保留。
|
||||||
|
|
||||||
|
J08 未请求时,结论文字始终附“未核对换料规则”。人工作出“已查看/备注”的行为不改变机器结论;真正消除异常需要修改工程后发布新输入版本。
|
||||||
|
|
||||||
|
### 6.2 三组独立字段
|
||||||
|
|
||||||
|
| 字段 | 值 | 含义 |
|
||||||
|
| --- | --- | --- |
|
||||||
|
| input_state | receiving / ready / unavailable | 前后副本是否已可信发布 |
|
||||||
|
| attempt_state | queued / running / publishing / stopping / succeeded / failed / cancelled / interrupted | 校验程序是否完成执行;succeeded 可以对应 DIFFERENT |
|
||||||
|
| verdict | CONSISTENT / WARNING / DIFFERENT / INCOMPLETE / 空 | 工程内容结论;尚未得到结果时为空 |
|
||||||
|
|
||||||
|
另存 resource_state=not_started/owned/released/unknown 与 currentness=current/historical。资源未知只影响归属的校验执行器准入,不改写已有换料回执,也不发出全局 CAD 退出命令。
|
||||||
|
|
||||||
|
## 7. 每个工程怎样执行
|
||||||
|
|
||||||
|
| 步骤 | 动作 | 发布物 / 下一步条件 |
|
||||||
|
| --- | --- | --- |
|
||||||
|
| E01 | 接收工程或导入两份文件 | 建 item 与不可变输入版本,登记缺证据原因 |
|
||||||
|
| E02 | 固定当前点击范围 | 全部待校验或明确所选 item/revision;提交后不跟随新版本漂移 |
|
||||||
|
| E03 | 入队与领取 | 事务内去重与 CAS;同一版本只允许一个活动尝试 |
|
||||||
|
| E04 | 复核固定输入 | 校验 manifest/摘要、工具与配置支持;原文件变化不偷偷换输入 |
|
||||||
|
| E05 | 准备工作副本 | 从受管冻结输入复制;原生工具不写原工程或冻结原件 |
|
||||||
|
| E06 | 导出前/后图和属性 | 复用已有 HIER/effective/Keyin;保存命令、版本、输出摘要和清理结果 |
|
||||||
|
| E07 | 核对覆盖 | 先执行 J01/J02;某维度缺数据就记录 unknown,不以空集合相同通过 |
|
||||||
|
| E08 | 执行判断 | J03~J13 只读取本版本输入和预期;检查之间按依赖分组继续,不因一个可定位差异跳过其他可检查维度 |
|
||||||
|
| E09 | 组织人工证据 | 生成逐脚差异、网络端点增删、前后示意和原始证据定位 |
|
||||||
|
| E10 | 确认资源退出 | 自有 CLI 收尾得到证明后才能提交执行完成并继续派发;不以“报告已写完”代替资源确认 |
|
||||||
|
| E11 | 发布结果 | 暂存→摘要与资源证明核对→原子发布产物→数据库 CAS 完成;迟到尝试不可覆盖新尝试 |
|
||||||
|
| E12 | 更新当前任务 | 更新工程行/计数;下一个工程继续,最后导出本命令汇总 |
|
||||||
|
|
||||||
|
首版一个独立校验工程对处于运行中,新runner前后顺序导出,同时最多一个本域CLI;复用已有单次导出能力,不另建一个双线程批次池叠加并发。资源实际许可/系统准入继续生效,不能证明可并行时保留排队,不通过新建任务动作抢占替换资源。只增加任务和排队不占原工程写入租约;原有批次内部导出并发不由本功能改写。
|
||||||
|
|
||||||
|
发生差异不会立即弹模态框要求处理,不自动重新运行相同输入。只读工具异常首版由用户点击重校验;不借用、消耗或重置换料的一次自动重试额度。
|
||||||
|
|
||||||
|
## 8. 总流程图
|
||||||
|
|
||||||
|
```mermaid
|
||||||
|
flowchart TD
|
||||||
|
A[新建校验或接收已成功结果] --> B[统一接收接口与去重]
|
||||||
|
B --> C{固定前后输入可用}
|
||||||
|
C -->|否| D[登记无法校验及原因]
|
||||||
|
C -->|是| E[待校验]
|
||||||
|
E --> F[用户开始当前待校验或所选]
|
||||||
|
F --> G[冻结本次范围并入队]
|
||||||
|
G --> H[领取一个工程版本]
|
||||||
|
H --> I[复核输入并在工作副本导出]
|
||||||
|
I --> J{覆盖和格式可判断}
|
||||||
|
J -->|完整或部分可判断| K[逐项判断并保存未知范围]
|
||||||
|
J -->|无有效输入| L[记录执行失败或无法判断]
|
||||||
|
K --> M[生成前后对照与事实证据]
|
||||||
|
M --> O{自有资源已确认释放}
|
||||||
|
L --> O
|
||||||
|
D --> V[更新任务列表与原因]
|
||||||
|
O -->|是| N[原子发布结果并更新状态]
|
||||||
|
N --> P{本次范围还有待执行项}
|
||||||
|
P -->|有| H
|
||||||
|
P -->|无| V
|
||||||
|
O -->|否| Q[暂停该校验执行器并保留队列]
|
||||||
|
Q --> R[等待安全收尾或人工处理]
|
||||||
|
R -->|确认释放后用户继续| N
|
||||||
|
```
|
||||||
|
|
||||||
|
## 9. 状态图
|
||||||
|
|
||||||
|
### 9.1 单次执行尝试
|
||||||
|
|
||||||
|
```mermaid
|
||||||
|
stateDiagram-v2
|
||||||
|
[*] --> Queued: 用户明确提交
|
||||||
|
Queued --> Running: CAS领取且资源准入通过
|
||||||
|
Queued --> Cancelled: 派发前取消
|
||||||
|
Running --> Publishing: 证据与资源退出证明齐备
|
||||||
|
Publishing --> Succeeded: 产物与数据库引用提交成功
|
||||||
|
Running --> Failed: 工具或解析失败且资源已释放
|
||||||
|
Publishing --> Failed: 结果发布失败且可确认落盘状态
|
||||||
|
Running --> Stopping: 记录停止意图
|
||||||
|
Publishing --> Stopping: 完成提交前请求停止
|
||||||
|
Stopping --> Cancelled: 自有资源退出确认
|
||||||
|
Queued --> Interrupted: 重启后冻结原队列
|
||||||
|
Running --> Interrupted: 崩溃后核实旧进程退出
|
||||||
|
Publishing --> Interrupted: 提交结果未能证明完整
|
||||||
|
Stopping --> Interrupted: 重启后核实收尾状态
|
||||||
|
Succeeded --> [*]
|
||||||
|
Failed --> [*]
|
||||||
|
Cancelled --> [*]
|
||||||
|
Interrupted --> [*]
|
||||||
|
```
|
||||||
|
|
||||||
|
Stopping 的 resource_state=unknown 时保持等待,不直接迁移 Cancelled。Succeeded 只表示比较处理完成,仍须读取 verdict;停止与发布竞争以数据库提交先后为准,完整终态已提交就保留真实结果,不改成“取消”。恢复/重校验建立新 attempt,旧终态不原地改回 running。
|
||||||
|
|
||||||
|
整run停止时,尚未实际派发的queued尝试记录cancelled及`run_stopped_before_dispatch`原因,释放队列预留;工程行恢复“待校验”,继续时创建新queued尝试。用户明确取消单个工程或已经启动的工程显示“已停止”;不能因两种行为都留下cancelled尝试就混淆行状态。
|
||||||
|
|
||||||
|
### 9.2 任务状态由工程当前版本推导
|
||||||
|
|
||||||
|
```mermaid
|
||||||
|
stateDiagram-v2
|
||||||
|
[*] --> Empty: 创建任务
|
||||||
|
Empty --> Ready: 收到可运行输入
|
||||||
|
Empty --> Attention: 只有不可用输入
|
||||||
|
Ready --> Active: 用户开始校验
|
||||||
|
Active --> Stopping: 用户停止当前运行范围
|
||||||
|
Stopping --> Paused: 归属资源已释放
|
||||||
|
Paused --> Active: 用户继续尚未开始项
|
||||||
|
Active --> Attention: 本次完成且有异常或缺证据
|
||||||
|
Active --> Finished: 当前范围完成
|
||||||
|
Attention --> Ready: 补充合法新输入或手动重校验
|
||||||
|
Finished --> Ready: 收到新工程或新版本
|
||||||
|
Paused --> Ready: 收到新输入且无活动派发
|
||||||
|
```
|
||||||
|
|
||||||
|
队列尚未执行的行存在时,任务不得标“所有工程已完成”。任务可继续接收新输入;Finished 不是禁止接收的永久关闭状态。Attention 与 Finished 的详情仍显示准确计数,警告不导致自动重试。
|
||||||
|
|
||||||
|
## 10. 数据流向与版本更新
|
||||||
|
|
||||||
|
### 10.1 数据流图
|
||||||
|
|
||||||
|
```mermaid
|
||||||
|
flowchart LR
|
||||||
|
A[已落盘的成功结果] --> C[统一输入接收服务]
|
||||||
|
B[用户选择两份工程] --> D[稳定性检查与冻结副本]
|
||||||
|
D --> C
|
||||||
|
C --> S[(SQLite任务/工程/版本/尝试)]
|
||||||
|
C --> M[(受管快照及manifest)]
|
||||||
|
S --> Q[独立校验调度器]
|
||||||
|
Q --> M
|
||||||
|
M --> W[一次性工作副本]
|
||||||
|
W --> N[已有原生导出与覆盖核验]
|
||||||
|
N --> G[标准图与逐项判断]
|
||||||
|
E[(固定预期变化与策略版本)] --> G
|
||||||
|
G --> R[(不可变结果包和原始证据)]
|
||||||
|
R --> S
|
||||||
|
S --> U[A工作台查询投影]
|
||||||
|
R --> U
|
||||||
|
U --> H[人查看前后图/差异表/原始证据]
|
||||||
|
R --> X[导出HTML与JSON]
|
||||||
|
```
|
||||||
|
|
||||||
|
没有从校验服务回到替换执行器的写入箭头。GUI 不直接读原工程数据库,示意图与差异表来自同一个标准图和 issue 记录,不使用生图模型或语言模型生成工程判定。
|
||||||
|
|
||||||
|
### 10.2 新版本到来时
|
||||||
|
|
||||||
|
```mermaid
|
||||||
|
sequenceDiagram
|
||||||
|
participant P as 输入发布者
|
||||||
|
participant S as 校验服务
|
||||||
|
participant DB as 持久库
|
||||||
|
participant W as 校验执行器
|
||||||
|
participant UI as A工作台
|
||||||
|
P->>S: 发布工程A v1和去重键
|
||||||
|
S->>DB: 原子发布v1并设为当前
|
||||||
|
S-->>P: 返回接收回执
|
||||||
|
UI->>S: 开始工程A v1
|
||||||
|
S->>DB: 建立queued尝试
|
||||||
|
W->>DB: CAS领取v1
|
||||||
|
P->>S: 发布工程A v2
|
||||||
|
S->>DB: 新增v2并更新当前指针
|
||||||
|
S-->>UI: v2待校验,v1正在处理历史版本
|
||||||
|
W->>DB: 提交v1结果,绑定v1尝试
|
||||||
|
DB-->>UI: v1结果归档,v2仍待校验
|
||||||
|
P->>S: 重复v2或迟到v1
|
||||||
|
S-->>P: 去重或忽略旧版,不新增派发
|
||||||
|
```
|
||||||
|
|
||||||
|
同一 before 下,v2 的预期集合必须覆盖该 before 到 v2 after 的全部累计成功变化,不能只携带最后一条改动;否则其他合法变化会被误判。新一轮 before 不同则新建工程项。当前只做接收和版本管理,不在本轮实现替换侧实时推送。
|
||||||
|
|
||||||
|
## 11. 结果包:让人能够复核
|
||||||
|
|
||||||
|
每个 issue 必须有:稳定 issue_id、check_id、严重性、工程/版本、位号/实例、物理脚号、前值、后值、预期或保持规则、关联证据及定位、检查范围。没有足够定位时说明“图页未定位”,不编造图页或 CAD 截图。
|
||||||
|
|
||||||
|
| 产物 | 内容与约束 |
|
||||||
|
| --- | --- |
|
||||||
|
| `result.json` | 身份、attempt/generation、输入/工具/策略摘要、逐项结论、覆盖、问题与资源证明 |
|
||||||
|
| 标准图 | 物理脚、网络端点、有效属性、实例/多 gate、字段来源;原值不被正常化覆盖 |
|
||||||
|
| 原始导出 | HIER/effective/Keyin 和完整工具输出,保持原样 |
|
||||||
|
| 连接对照 | 前后相同脚号相同位置;只高亮变化连接,列新增/丢失对端 |
|
||||||
|
| 事实表 | 引脚/字段、替换前、替换后、判断、证据入口;与示意图共享同一 issue 数据 |
|
||||||
|
| 覆盖清单 | 已检查、未知、未请求;封装内部映射不能被工程网表结果隐含覆盖 |
|
||||||
|
| HTML/JSON报告 | 相同结果包渲染;明确任务、版本、生成时间和未完成项 |
|
||||||
|
|
||||||
|
例如 R12 反脚:左右两张图均保持 1 脚在上、2 脚在下;前后网络/对端不同处标红。明确标“连接关系示意(由网表生成)”,不伪装原理图截图。命名警告用 amber,不能用红色导线假装发生实际断接。
|
||||||
|
|
||||||
|
UI 的原始证据入口只能打开受管、摘要匹配的文本/报告,不接受工程字符串或模型输出指定任意可执行路径。所有 HTML 字段转义,客户数据和原始网表不写入 Git。
|
||||||
|
|
||||||
|
## 12. 失败处理矩阵
|
||||||
|
|
||||||
|
| 编号 | 失败或变化 | 当前工程怎样处理 | 其他工程 / 后续 |
|
||||||
|
| --- | --- | --- | --- |
|
||||||
|
| F01 | 缺 before/after | input unavailable,指出缺哪个副本 | 继续其他可运行项;补合法记录,不补造 before |
|
||||||
|
| F02 | 独立导入源正在写入或复制中变化 | 不发布可信 revision,保留导入原因 | 可重新选择/捕获;其他任务可新建 |
|
||||||
|
| F03 | 相同版本不同内容 | 输入冲突,拒绝覆盖 | 返回逐条原因,其他已接收项保留 |
|
||||||
|
| F04 | 旧版本迟到/重复通知 | 幂等或 stale_ignored | 不再导出、不改当前结果 |
|
||||||
|
| F05 | 缺工具/不支持配置 | 明确能力原因,必查为 unknown | 其他支持项继续;不回退 CAD 读取 |
|
||||||
|
| F06 | CLI 超时/异常退出 | 保存诊断,自有进程安全收尾 | 确认 released 后继续下一项;用户可单项重校验 |
|
||||||
|
| F07 | CLI 无输出/空图/截断/覆盖不足 | 无法完整检查;保留可定位事实 | 不显示通过,其他工程继续 |
|
||||||
|
| F08 | 发现反脚/漏换/非目标改动 | succeeded + DIFFERENT,保存事实与证据 | 继续后续项,不自动修改或重试 |
|
||||||
|
| F09 | 只有符合条件的文字变化 | succeeded + WARNING | 继续,留待集中查看 |
|
||||||
|
| F10 | 引脚属性/库映射读取不支持 | 对应 check unknown/not_requested | 必查未知则 INCOMPLETE;未请求项始终披露 |
|
||||||
|
| F11 | 用户停止 | 先存停止意图,停止当前自有只读导出 | 未派发项回到待校验;当前 cancelled 后用户可重校验 |
|
||||||
|
| F12 | 自有资源退出不确定 | 保持 stopping + resource unknown | 暂停该校验执行器,不盲目开启下一导出,不杀用户 CAD |
|
||||||
|
| F13 | 应用关闭或崩溃 | 正常关闭先收尾;异常重启核实旧进程和产物 | interrupted 后等用户继续,不自动重复换料或开始校验 |
|
||||||
|
| F14 | 结果文件或数据库提交失败 | 不显示完成;旧结果保持 | 优先停止受影响发布/执行范围;存储故障不能保证后续落盘,不承诺其他项仍可持久化 |
|
||||||
|
| F15 | 保存文件后DB提交前崩溃 | 扫描已发布结果包并核对输入/attempt/token | 仅有完整不可变包、released证明且无更新尝试才可补提交;否则 interrupted |
|
||||||
|
| F16 | 迟到 worker 回调 | CAS拒绝当前终态覆盖,保留诊断 | 新尝试/新版本不受污染 |
|
||||||
|
| F17 | 当前工程文件后来变化 | 已固定版本仍能比较,其结果标“对应已保存副本” | 不偷偷替换 after;要核对新状态须新输入版本 |
|
||||||
|
| F18 | 报告丢失/摘要不符 | UI显示证据不可用,保留原记录 | 可对原固定输入重校验;不能用残留绿灯代替证据 |
|
||||||
|
|
||||||
|
一般异常不弹阻塞对话框。需要用户选择路径、确认停止或操作外部文件时才交互。资源/存储归属异常属于无法安全继续的边界,不用“非阻塞”掩盖它。
|
||||||
|
|
||||||
|
```mermaid
|
||||||
|
flowchart TD
|
||||||
|
A[步骤异常或用户停止] --> B{已有完整提交的终态}
|
||||||
|
B -->|有| C[保留真实结论与证据]
|
||||||
|
B -->|无| D[记录失败或停止意图]
|
||||||
|
D --> E[收尾本次自有只读进程]
|
||||||
|
E --> F{资源退出是否有证明}
|
||||||
|
F -->|有且存储可用| G[当前项终态,其他待执行项继续]
|
||||||
|
F -->|无| H[保持停止中,暂停该执行器]
|
||||||
|
H --> I[继续收尾或人工处理资源]
|
||||||
|
I -->|确认退出后用户继续| G
|
||||||
|
D -->|持久化不可用| J[显示存储故障,暂停结果发布]
|
||||||
|
```
|
||||||
|
|
||||||
|
## 13. A 工作台与数量口径
|
||||||
|
|
||||||
|
- 四导航保持一致;上方只有“工程校验”和始终可用的“新建校验”。无来源、流水线或返回替换任务横条。
|
||||||
|
- 左侧先选择校验任务,再筛选当前任务工程;中间表与右侧证据随同一个 item/revision 切换。
|
||||||
|
- 新建任务只需名称;选择两份工程可在新建对话框完成,也可先建空任务后加工程。校验侧不要求用户先创建替换任务。
|
||||||
|
- “开始待校验”仅对当前任务所有 ready、未提交的当前版本生效,不受表格筛选暗中缩小范围;“校验所选”只对显式勾选版本生效。勾选随切任务/分页/筛选清空并提示,避免隐藏提交。
|
||||||
|
- “重新校验此工程”默认当前选中版本;历史版本只能从历史详情显式重校验并始终标历史,不能把其结果挂到当前版本。
|
||||||
|
- 表格每页100项,差异每页100项;250ms搜索防抖,后台查询代次隔离旧回调;不在GUI扫描全部网表。
|
||||||
|
- 统计只取每个 item 的 current_revision。已处理 = 一致 + 有警告 + 有异常 + 无法完整校验;排队/执行中/待校验/已停止/中断分别列出。失败且无有效业务结果计入无法校验,并保留“执行失败”原因,不计一致。
|
||||||
|
- 旧版结果和旧尝试不重复计入当前计数。重校验排队后该行显示排队中,旧结果可展开查看但不继续充当当前已处理结论。
|
||||||
|
- 没有完整证据的“处理结束”不显示绿色通过;只有 scoped 一致可使用绿色,并带检查范围。
|
||||||
|
|
||||||
|
## 14. 持久化、接口与发布顺序
|
||||||
|
|
||||||
|
新增校验 task/item/input_revision/attempt/run 与命令去重记录,复用当前 SQLite 事务和日志模式。文件内容保存在受管目录,数据库存身份、状态、摘要与引用;不在新表复制原 execution_operations 状态。运行去重/停止命令可使用校验域自己的 request 表;不复用专用于 AI 创建任务的请求语义。
|
||||||
|
|
||||||
|
```text
|
||||||
|
verification/<task_id>/<item_id>/inputs/<version>/manifest.json
|
||||||
|
verification/<task_id>/<item_id>/attempts/<attempt_id>/raw/...
|
||||||
|
verification/<task_id>/<item_id>/attempts/<attempt_id>/result.json
|
||||||
|
verification/<task_id>/<item_id>/attempts/<attempt_id>/report.html
|
||||||
|
```
|
||||||
|
|
||||||
|
输入版本、尝试、产物路径均由服务生成并验证归属,不允许外部命令在受管目录之外指定输出位置。清历史不删除校验结果;活动/当前引用的快照、原生证明和结果包不得按普通日志保留期清掉。首版不新增“一键删除证据”入口。
|
||||||
|
|
||||||
|
发布顺序固定:完整暂存文件 → 原子发布 manifest/结果包 → DB事务验证身份与generation并引用 → 通知UI。目录与DB不能跨资源真原子,使用上述顺序和 F15 恢复规则;拒绝“先更新成功状态,再尝试写报告”。
|
||||||
|
|
||||||
|
## 15. 能力门禁和未确认事项
|
||||||
|
|
||||||
|
1. 引脚级 Value 的实际字段、端点逻辑名与物理脚号对应、可读电气类型需用真实导出确认;缺失不以器件属性替代。
|
||||||
|
2. 库内脚→焊盘读取尚未证明,首版可先交付工程物理连接校验与明确未覆盖项,不宣称封装制造验证。
|
||||||
|
3. GND→VCC 或纯功能文字对调的自动严重性尚未由用户确认,首版保留高关注警告,不让模型推断电气等价或改工程。
|
||||||
|
4. 用户网名变化暂不放宽为普通命名警告;后续若要放宽,独立规则与反例确认。
|
||||||
|
5. 多层级/多 gate 当前已有读取能力;直接换料的子实例范围不是本轮新增任务。独立比较若不能唯一建立前后对应,返回 unknown,不强行比对。
|
||||||
|
6. 旧 before 缺失不会因为新增页面而变得可恢复;真实新副本验收与图像原型分开。
|
||||||
|
|
||||||
|
实施从[开发与交付入口](../plans/2026-11-17-verification-development.md)进入,逐项步骤见[独立校验新增功能计划](../plans/2026-11-17-independent-verification-new-features.md)。本文及计划不授权开始 CAD 写入、改动其他任务的修复或发布程序。
|
||||||
@@ -0,0 +1,109 @@
|
|||||||
|
# 批量执行闭环验收
|
||||||
|
|
||||||
|
本轮对应 `docs/superpowers/plans/2026-11-17-batch-execution-closure.md`。位号优先定位;工程内先暂存,工程统一保存回读后提交;不确定工程隔离,确认全部自有写进程退出后继续独立工程。工程执行、网表验收、资源告警分开记录。
|
||||||
|
|
||||||
|
```mermaid
|
||||||
|
flowchart TD
|
||||||
|
A[导入 BOM 并保存待执行计划] --> B[原生读取当前工程所需位号与网表]
|
||||||
|
B --> C{工程/页/位号能否明确定位}
|
||||||
|
C -- 否 --> D[记录明确的匹配错误]
|
||||||
|
C -- 是 --> E[逐项原生替换和内存核验]
|
||||||
|
E --> F[写 pending_save / 暂存回执]
|
||||||
|
F --> G{工程还有项且未暂停}
|
||||||
|
G -- 是 --> E
|
||||||
|
G -- 否 --> H[统一保存页 / 关闭工程 / 重开回读 / 最终关闭]
|
||||||
|
H --> I{全部前缀核验通过}
|
||||||
|
I -- 是 --> J[原子提交已保存回执和任务进度]
|
||||||
|
J --> K{人工暂停}
|
||||||
|
K -- 是 --> L[结束整批 / 保留未执行项]
|
||||||
|
K -- 否 --> M[继续下一独立工程]
|
||||||
|
E -- 未知写入或异常 --> N[保留 uncertain / 工程待核验]
|
||||||
|
I -- 否 --> N
|
||||||
|
N --> O[回收该工程自有写进程]
|
||||||
|
O --> P{写进程退出和自有句柄关闭已证实}
|
||||||
|
P -- 否 --> Q[停止整批 / 等待资源核验]
|
||||||
|
P -- 是 --> R[隔离工程及共享写入源]
|
||||||
|
R --> S{旧桌面是否仍存在}
|
||||||
|
S -- 是 --> T[保留隔离告警 / desktop_released=false]
|
||||||
|
S -- 否 --> M
|
||||||
|
T --> M
|
||||||
|
J --> U[独立原生网表验收 / 单独显示结果]
|
||||||
|
R --> V[共享源后续任务未派发即阻塞]
|
||||||
|
V --> W[原依赖恢复后显式核验重新准入]
|
||||||
|
```
|
||||||
|
|
||||||
|
## 20 类验收场景
|
||||||
|
|
||||||
|
下面是自动化验收矩阵,不代表 20 次真实 Mentor 替换。Python 测试替代 COM 边界;VBS 测试执行生产脚本函数并使用假 COM 对象。真实 Windows 桌面测试另列。
|
||||||
|
|
||||||
|
| # | 场景 | 需要确认的结果 | 自动化覆盖 |
|
||||||
|
|---|---|---|---|
|
||||||
|
| 1 | 器件 UID 缺失或格式异常 | 位号明确时可定位,原始 UID 留证 | `test_refdes_identity_closure` inventory cases |
|
||||||
|
| 2 | 不同位号共享 UID | 不误绑定,不阻断无关器件 | 同模块 duplicate UID / unselected collision cases |
|
||||||
|
| 3 | 替换或重开后 UID 变化 | 快照、回读、网表仍关联原位号,旧操作编号不变 | 同模块 snapshot/readback/netlist cases |
|
||||||
|
| 4 | 原 UID 被另一位号复用 | 不把错误位号当成替换成功 | 同模块 reused UID mismatch cases |
|
||||||
|
| 5 | 不同页或层级同位号 | 依据工程、页和层级定位,真实歧义拒绝 | 同模块 sheet/hierarchy cases |
|
||||||
|
| 6 | 同一物理器件多个合法单元 | 全单元快照及回读,物理引脚连接仍严格比较 | 同模块 multiunit cases |
|
||||||
|
| 7 | 工程中多项暂存 | 游标推进,但 saved/completed 不提前增加 | `test_project_commit_progress` |
|
||||||
|
| 8 | 工程末统一保存 | 每个已修改页保存一次,工程关闭重开回读一次 | `test_project_commit_vbs` save/reopen case |
|
||||||
|
| 9 | 暂存前缀后人工暂停 | 提交已修改前缀,未执行项不产生写入/不确定状态 | `test_project_commit_end_to_end` pause cases |
|
||||||
|
| 10 | 写入前暂停 | 保留 SafeStop 来源,当前项保持 pending | `test_project_commit_vbs` / `test_resource_isolation_prewrite_pause` |
|
||||||
|
| 11 | 回读失败或提交清单不完整 | 不提前提交任何暂存项 | `test_project_commit_journal` / `test_project_commit_proof` |
|
||||||
|
| 12 | 保存成功后程序崩溃 | 从不可变提交证据幂等恢复,不重放替换 | `test_project_commit_journal` / `test_project_commit_public_recovery` |
|
||||||
|
| 13 | 工程保存回读持续有进度且超过原等待时间 | 不因固定 60 秒误判收尾失败 | `test_project_commit_session` progressing commit case |
|
||||||
|
| 14 | 自有进程退出但旧桌面仍被外部句柄持有 | 保留 desktop_released=false,隔离告警,新批次可进入 | `test_resource_isolation`;真实 Windows 探针 |
|
||||||
|
| 15 | 仍有写进程或进程身份未知 | 不允许隔离放行 | `test_resource_isolation` active/unknown cases |
|
||||||
|
| 16 | 隔离后重启,随后外部句柄消失 | 重验退出证明;被动确认释放,不重复 Quit | 同模块 restart/passive disappearance cases |
|
||||||
|
| 17 | 工程结果未知,资源已收尾 | 保留 blocked 和 uncertain,继续独立工程,恢复队列不重放 | `test_project_isolation_queue` / `test_workspace_execution` |
|
||||||
|
| 18 | 本地回收与人工停止 | 本地回收不污染下一工程;人工暂停/强制结束仍生效 | `test_project_isolation_queue` / workspace control cases |
|
||||||
|
| 19 | 后续工程共享 iCDB 写入源 | 未派发即阻塞,原依赖核验完成后才重新准入 | `test_lifecycle_integration_fix` dependency cases |
|
||||||
|
| 20 | 任务完成、失败、恢复及资源告警 | 实时分类;已保存结果与网表/资源结果分别展示;诊断含最后成功项和未返回调用 | `test_live_task_completion` / `test_failed_native_recovery_guard` / `test_diagnostics_closure` |
|
||||||
|
|
||||||
|
## 证据位置
|
||||||
|
|
||||||
|
- 本轮回归日志:`build/batch-execution-closure/`。
|
||||||
|
- Windows 桌面实际持有、重启复核及新桌面准入:`build/batch-execution-closure/resource-isolation/run-4ace6aa7a36b4204a7bed568b5ce7505/evidence.json`。
|
||||||
|
- 工单原始日志保留在 `outputs/issues-20261117/issue29/`,不修改用户上传证据。
|
||||||
|
|
||||||
|
## 自动化验证结果
|
||||||
|
|
||||||
|
主程序/UI 全量运行 2335 项,最初 2320 项通过、15 项失败。14 项仍断言“未知结果必须整批暂停”,已按已批准的工程隔离策略更新,同时保留同工程后项不派发、不重放和独立工程可继续的断言;另一项修复测试对尚未创建完成的原生弹窗按钮的读取竞态。随后对全部失败项和本轮新增/修改的调用链定点复验。
|
||||||
|
|
||||||
|
最终 JUnit 合并记录为 **2438 个唯一用例通过,0 个未解决失败**,证据见 `build/batch-execution-closure/verified-test-summary.json`。这是全量运行加定点复验的合并结果,不是另一次全部用例在最后源码上的全量运行。定点记录为 root delta 143 项、lifecycle delta 97 项、project recovery 29 项、identity delta 47 项、deleted guard 1 项,均通过;这些记录存在重叠,不应直接相加。
|
||||||
|
|
||||||
|
独立审查已复核位号/多单元、工程暂存及暂停、资源隔离、共享源恢复及公开工程提交恢复。工程已保存但数据库回执未完成时,公开恢复入口验证原生关闭检查点、保存源、回读文件及原尝试身份后恢复回执,不启动 CAD 或重复替换;源变化、其他未知写入、证据损坏及不匹配的中断记录继续保持待核验。
|
||||||
|
|
||||||
|
## 实机边界
|
||||||
|
|
||||||
|
工程级批量保存、UID 异常和多单元替换需要使用副本进行真实 Mentor 验收。自动化协议验证、真实桌面句柄探针和真实 CAD 写入必须分别报告;不得用前两者声称已完成原 100 工程队列。原工程、中心库、Excel 和历史 uncertain 记录不作为试验修改对象。
|
||||||
|
|
||||||
|
首轮真实 Mentor 探针 `build/batch-execution-closure/mentor-live/` 在 RL02 原生替换和内存回读后失败:新暂存入口未暂时清除内存 `restored_ok`,导致生产命令读取器认定没有待处理命令。该问题已有真实读取器回归;复测使用 `mentor-live-fixed/` 全新副本。失败副本及 uncertain 保留,不重放。首轮 Mentor 正常退出、桌面释放,无强制终止;原备份 34 个文件前后哈希一致。
|
||||||
|
|
||||||
|
第二轮 `mentor-live-fixed/` 发现未选中非 PCB 图形的空位号被写成相同别名,导致后续全页原生回读重复 UID;已对空位号跳过引用别名并保留其独立原始 UID。第三轮 `mentor-live-final/` 通过该位置并写出 `pending_save`,随后全页语义采集缺少逐器件进度,触发无进度停止;补充实际完成计数后使用 `mentor-live-progress/` 新副本复测。前三轮异常资源均确认释放,备份源文件前后哈希一致;不计为工程保存成功验收。
|
||||||
|
|
||||||
|
第四轮真实 Mentor 验收通过,证据为 `build/batch-execution-closure/mentor-live-progress/closure-live-summary.json`。RL02、RL05 两项替换先暂存,最后统一提交;日志确认一个 worker、一次保存、两次打开工程(首次打开及保存后重开)。两项 SQL 操作均为 `verified/generation=1`,工程提交 `verified`,任务 `completed`。独立原生清单读取复核 13 个位号:两项目标料号正确,其余 11 项保留原料号。Mentor 和桌面确认释放,无强制终止;备份源 34 个文件哈希未变化。
|
||||||
|
|
||||||
|
### 本机计时及限制
|
||||||
|
|
||||||
|
| 实际边界 | 秒 |
|
||||||
|
|---|---:|
|
||||||
|
| 第一项开始至暂存回执 | 472.664 |
|
||||||
|
| 第二项派发至暂存回执,含前一项检查点核验 | 539.298 |
|
||||||
|
| 工程收尾,含完整状态检查、统一保存、关闭重开和回读 | 431.863 |
|
||||||
|
| 其中两次原生替换提交调用 | 0.631 / 0.424 |
|
||||||
|
| Mentor 退出 | 5.093 |
|
||||||
|
| 桌面释放 | 0.009 |
|
||||||
|
| 整个队列 | 1450.341 |
|
||||||
|
| 队列结束后的独立原生清单复核 | 1.505 |
|
||||||
|
|
||||||
|
“其中”调用嵌套于上层步骤,不能再次相加。本轮同时存在构建和回归负载,不能作为独占性能基准,也没有同条件旧版对照。全页状态反复采集仍是明显耗时项;本次证明阻塞闭环、保存次数与结果提交正确,**没有证明速度提升**。真实 CAD 仅验证一个副本工程、两次替换;多单元、UID 异常和 20 类异常场景主要依靠自动化协议/COM 边界测试,不能当成 20 个真实工程已通过。
|
||||||
|
|
||||||
|
候选包仅供本地测试,不自动覆盖旧 Release。
|
||||||
|
|
||||||
|
## 本地候选程序
|
||||||
|
|
||||||
|
入口:`D:\CodexValidation\batch-closure-20261117\candidate\dist\DxPartReplace\DxPartReplace.exe`。这是包含完整 Harness/Node/Qt 运行时的目录包,运行时文件须与程序一起保留。应用版本资源仍为 1.3.1,本轮候选代码通过冻结模块核对区分,不代表远端已经发布了新版本。
|
||||||
|
|
||||||
|
冻结包内 162 个应用模块与最终源码编译结果一致,两份 VBS 与源码逐字节一致。EXE SHA256:`4b19948b6a008912851f3ab674afa361bf4a28de4b74f20d3d04b80719200cc1`。打包程序本身已通过启动、冻结监督进程、进程身份读取、资源释放及正常退出验证。报告位于候选目录上级的 `source-verification.json` 与 `packaged-runtime-verification.json`。
|
||||||
|
|
||||||
|
实施决定:沿用已有功能分支保留先前授权修复;互不重叠的模块并行处理后统一审查;本地直接交付完整目录包。前两项若判断错误需集成返工,目录包如需转移到其他机器可另行归档。本轮未合并、推送或发布远端版本。
|
||||||
@@ -0,0 +1,94 @@
|
|||||||
|
# 独立工程校验验收记录
|
||||||
|
|
||||||
|
2026-11-18 已追加批量添加工程对,见[本轮验收](2026-11-18-verification-batch-import.md)。同一路径的本地开发包已更新;下文为11月17日历史结果,原EXE和证明保留在 `D:/dx-vfy-history-20261117/`。
|
||||||
|
|
||||||
|
开发分支:`codex/independent-verification`。独立工作目录:`.worktrees/independent-verification`。基础主线:`origin/main@b19afc6`;重新 fetch 后未出现更新提交。原工作区另一项修复仍有未提交修改,本分支没有复制它们。
|
||||||
|
|
||||||
|
## 已实现范围
|
||||||
|
|
||||||
|
| 阶段 | 结果 |
|
||||||
|
| --- | --- |
|
||||||
|
| N01~N04 | 独立任务、不可变输入版本、幂等交接、独立导入、当前版本投影、筛选/分页/计数 |
|
||||||
|
| N05~N08 | 原生只读导出、固定物理脚号判断、名称/属性警告、未知覆盖、同源接线图和逐脚事实 |
|
||||||
|
| N09~N11 | 第四导航、随时新建、开始/停止/重校验、历史版本与尝试、异步关闭、HTML/JSON报告、证据摘要与保留 |
|
||||||
|
| N12 | 混合批次、验收 CLI、真实原生导出已验证;最终默认回归、扩展回归和安装包结果见下方完成记录 |
|
||||||
|
|
||||||
|
## 验收路径
|
||||||
|
|
||||||
|
受控格式路径:`python tools/verify_independent_verification.py --fixture-root <目录> --output <新目录>`。夹具目录中 `before/after` 各含合法捕获配置 `.prj` 与数据库、`effective.txt` 和 `design.kyn`。该路径明确标记 `controlled-format-fixture`,不能冒充真实 CAD 导出。
|
||||||
|
|
||||||
|
真实只读路径:`python tools/verify_independent_verification.py --native-before <前工程.prj> --native-after <后工程.prj> --output <新目录>`。非零退出区分异常、缺覆盖和执行失败;警告结果保留给人工确认。
|
||||||
|
|
||||||
|
实际执行输出:`D:/dx-vfy-native-final/acceptance.json`。前后各 57 个器件、83 个有原文定位的引脚,结论 WARNING(器件属性变化且没有固定换料清单;原生身份表另有提示)。两个工程文件及两个数据库的 SHA256 前后不变,`replacement_operations=0`。JSON、HTML、网表原文及输入摘要保留于该本地目录,Git不收录工程和厂商二进制。
|
||||||
|
|
||||||
|
## 验证过的关键反例
|
||||||
|
|
||||||
|
- R12.1/2 互换:DIFFERENT;前后图位置不随名称交换,表和报告来自相同证据。
|
||||||
|
- loop→outloop、拓扑不变:WARNING;不伪造红色接错线。
|
||||||
|
- 断线、短接、位号变化、物理脚号/占用次数变化、用户网名变化:硬异常。
|
||||||
|
- 有固定清单时精确核对目标属性;无清单时列出变化并注明“未核对换料规则”。
|
||||||
|
- 缺必查字段/库映射:INCOMPLETE;硬异常与未知同时存在时仍为 DIFFERENT。
|
||||||
|
- 重复/乱序交接不重复创建;旧版本结果只留历史;重校验不会沿用旧绿灯。
|
||||||
|
- 持久停止先于提交时取消获胜;终态先提交时保留真实结果;未派发项回到待校验。
|
||||||
|
- 原始证据损坏取消绿色结论并拒绝有效报告;清历史不删除证据;存储失败暂停执行器。
|
||||||
|
- 慢证据核验不占住数据库事务,新建任务可继续;同一尝试仅一个领取者。
|
||||||
|
- 关闭可重复调用;重启不自动重跑;退出缺证明保留现场,不按 PID 误杀其他进程。
|
||||||
|
|
||||||
|
## 视觉检查
|
||||||
|
|
||||||
|
实际 Qt 截图而非生图:本机 `F:/dx-vfy-preview-20261117/`。1280×880、980×700,以及 1.25/1.5 缩放均已生成检查。接线图使用自建 R12 反脚夹具演示,不能冒充真实工程错误。完整事实另有逐脚表和原文定位。
|
||||||
|
|
||||||
|
## 验证环境与限制
|
||||||
|
|
||||||
|
共享 `.venv` 的基础 Python 路径异常,导致 `-E/-I` 的旧进程边界测试失败;Windows 默认 GBK 还影响旧测试中未声明编码的读取。没有修改产品旧执行器或用户环境变量。独立验证环境为 `D:/dx-vfy-python-20261117`,基于本机已安装 Python 3.12.10,复用已安装依赖;测试使用进程级 `-X utf8`。
|
||||||
|
|
||||||
|
首次默认回归:2221 passed、6 failed、6 errors;其中关闭重复调用的本功能回归已修复,环境相关项在独立环境的相关 66 项测试中通过。首次扩展回归 818 passed、4 failed、4 skipped;本功能首选问题定位已修正,GBK 相关的 28 项复核通过。不能把首轮失败记录解释为最终全绿结果。
|
||||||
|
|
||||||
|
F 盘空间不足使第一次构建未完成;仅清理了本工作目录本次生成的失败构建目录,构建和后续测试转到 D 盘。没有清理原工作区、客户工程或其他任务输出。引脚级 Value、确切库内部引脚到焊盘映射、ERC/PCB 正确性仍未覆盖。
|
||||||
|
|
||||||
|
## 最终完成记录
|
||||||
|
|
||||||
|
N01~N12 的新增功能已完成并提交到独立分支,本次交付本地开发包,不合并、不推送、不发布。原工作区另一任务的未提交修复未改动。
|
||||||
|
|
||||||
|
### 测试结果
|
||||||
|
|
||||||
|
| 范围 | 实际结果与证据 |
|
||||||
|
| --- | --- |
|
||||||
|
| 全部新增服务/Qt/验收组(16 个测试文件) | **81 passed**,`D:/dx-vfy-new-final81.xml`;包含慢读取不饿死、100行分页保持、刷新保留问题选择 |
|
||||||
|
| DSH 与打包扩展组 | **476 passed, 1 skipped**;跳过项是未配置官方 7-Zip 的自解压验证 |
|
||||||
|
| 默认范围分段及相关复核 | 当前收集 **2250** 项,均能在通过的分组记录中找到,`missing=[]`;`D:/dx-vfy-regression-coverage.json` |
|
||||||
|
| 一次连续默认全量稳定全绿 | **未取得**;不能用分组覆盖替代。此前运行及复核记录保留如下 |
|
||||||
|
|
||||||
|
新增组命令:使用 `D:/dx-vfy-python-20261117/Scripts/python.exe -X utf8 -m pytest`,逐项传入 `tests/v1_1/test_independent_verification_{contracts,store,intake,queries,runner,rules,acceptance}.py`、`tests/v1_1/test_verification_{pin_metadata,evidence,control,reports}.py`、`tests/ui/test_verification_{workspace,inspector,control,report_actions,acceptance}.py`(花括号表示文件集合,实际使用完整文件名),参数 `-q --basetemp D:/dx-vfy-tests-final81 --junitxml D:/dx-vfy-new-final81.xml`。扩展组命令为同一解释器执行 `-m pytest tests/dsh tests/packaging -q`。
|
||||||
|
|
||||||
|
默认范围证据:`D:/dx-vfy-default-complete.xml`(1496 passed、1 failed)、`D:/dx-vfy-default-tail.xml`(746 passed、1 failed、1 teardown error)。失败分别涉及既有 safe-user-stop 的真实 supervisor 启动见证超时,以及 history 搜索精确 250ms 的定时边界;相应文件未改,独立复核 `D:/dx-vfy-legacy-stop.xml` 为 **34 passed**。既有 VBS 超时组单独复核 **5 passed**。这些波动仍是发布前需要处理的事项,不在本次新增功能中改写旧逻辑或放宽断言。
|
||||||
|
|
||||||
|
覆盖审计只收集当前默认用例、与各 XML 的实际 passed 节点集合比较,不运行或跳过测试;证据集合为上述两份默认记录、新增81项及34项复核,`continuous_full_run_green=false`。审计脚本 `D:/vfy_audit_coverage.py`。
|
||||||
|
|
||||||
|
### 实际包验收
|
||||||
|
|
||||||
|
开发包:`D:/dx-vfy-release-20261117/DxPartReplace/DxPartReplace.exe`(须保留同目录完整 `_internal`)。源码提交 `f91b4de`;EXE SHA256:`9aeea5d8fb1263b1da32d5d0363a2f9cd6310d884c41a45c44debb4bf3fb8fb3`。随后只更新验收文档,不改变包内源码。
|
||||||
|
|
||||||
|
完整运行时由仓库标准 spec 构建。最终 Python 修改通过官方 PyInstaller PYZ/EXE API 重新编译并原子替换 EXE,复用该次已完成且未改变的原生/Node运行时,未修改厂商内容。可复核脚本为 `D:/verification-code-refresh.spec`;`D:/vfy_verify_archive.py` 实际逐个比较归一化路径后的 Python 代码对象,**22 个变更源码模块与最终包完全一致**,无 mismatch,证明保存在 `D:/dx-vfy-package-proof.json`。
|
||||||
|
|
||||||
|
| 实际操作 | 结果与现场 |
|
||||||
|
| --- | --- |
|
||||||
|
| 四导航、连续新建两个独立任务 | 通过,`D:/dx-vfy-package-ui-v2/acceptance.json` |
|
||||||
|
| 使用真实系统文件选择器添加前后工程并开始 | 原生导出完成、WARNING、输入四文件摘要不变、换料操作数0、正常退出,`D:/dx-vfy-package-pair-v5/acceptance.json` |
|
||||||
|
| 包内重校验 | generation 2、WARNING;PID+进程创建时间归属证明成立、换料操作数0、正常退出,`D:/dx-vfy-package-final-rerun/acceptance.json` |
|
||||||
|
| 最终包重启并查看已有结果 | 右侧真实接线图与“input · 需关注”加载完成;attempt数仍为2、不自动执行、换料操作数0、退出码0,`D:/dx-vfy-package-final-view/acceptance.json` |
|
||||||
|
| 最终包运行时/正常关闭 | frozen supervisor、win32timezone、创建时间读取及资源释放均通过;`tools/verify_packaged_runtime.py` 对新数据根 `D:/dx-vfy-package-smoke-delivery` 的实际结果 |
|
||||||
|
|
||||||
|
最终包截图:`D:/dx-vfy-package-final-view/native-result-final.png`。该图使用真实导出的工程结果,不能把较早在读取完成前抓到的待校验画面当成最终证据。反脚效果仍使用明确标注的自建 R12 夹具;没有改写客户工程制造错误。
|
||||||
|
|
||||||
|
### 操作与恢复细节
|
||||||
|
|
||||||
|
工程表每页100项,“下一页”有界读取;周期刷新保留当前页,筛选回第一页,开始全部不受分页影响。周期刷新等待当前查询完成,保留多选、问题选择和事实滚动位置,用户显式切换仍使用代际取消。切任务清空旧检查器,关闭先失效旧查询。
|
||||||
|
|
||||||
|
`verification/ownership.py` 用 PID 和创建时间证明校验窗口归属,保护另一窗口仍活跃的执行;调度仅处理本实例运行,停止请求持久化。进程已经退出但缺少原生CLI退出证明时仍保持资源未知;不猜测退出、不按PID杀进程、不自动重跑。资源失败原因随尝试保存。
|
||||||
|
|
||||||
|
成功交接与增量接口已通过受控真实SQLite/服务集成测试;本次包内真实验证走独立两份工程路径,没有为制造新回执再执行客户换料。未来替换实时推送不在本轮范围。
|
||||||
|
|
||||||
|
### 保留边界
|
||||||
|
|
||||||
|
引脚级 Value、确切封装库内部脚位到焊盘映射未得到来源证明,明确未覆盖;ERC/PCB及自动修复不属于本功能。默认连续全量时序稳定性尚未满足发布门槛。以上限制不以网表一致或执行完成掩盖。
|
||||||
@@ -0,0 +1,68 @@
|
|||||||
|
# 保存后原生数据核验
|
||||||
|
|
||||||
|
本轮修正正常执行链仍然依赖全页 CAD/COM 核验的问题。DxDesigner 负责目标器件替换、属性恢复、保存和关闭;保存后的目标数据与连接核验由 Mentor 原生命令行导出承担。
|
||||||
|
|
||||||
|
```mermaid
|
||||||
|
flowchart TD
|
||||||
|
A[原生数据发现目标:工程、页、位号] --> B[打开工程与目标页]
|
||||||
|
B --> C[仅记录目标器件原属性]
|
||||||
|
C --> D[替换目标器件,记录库件 Value 写入期望]
|
||||||
|
D --> E[恢复属性与 NC,暂存 pending_save]
|
||||||
|
E --> F{还有同工程目标?}
|
||||||
|
F -- 有 --> C
|
||||||
|
F -- 无或暂停 --> G[保存并关闭一次,发布 project_saved]
|
||||||
|
G --> H[捕获保存数据库,原生命令行导出]
|
||||||
|
H --> I{按工程、页、位号核验目标数据}
|
||||||
|
I -- 通过 --> J[原子提交本工程回执,追加完成状态]
|
||||||
|
I -- 不通过或导出失败 --> K[保留已保存待核验状态,不重放替换]
|
||||||
|
K --> H
|
||||||
|
J --> L[独立前后网表比对复用同一份保存后导出]
|
||||||
|
```
|
||||||
|
|
||||||
|
## 开发项
|
||||||
|
|
||||||
|
- [x] 正常路径不调用全页语义状态、非目标属性、连接索引与原生 CAD 宿主快照。
|
||||||
|
- [x] 新快照 `saved_netlist_v1` 仅含目标 C/A;旧快照继续使用原兼容路径。
|
||||||
|
- [x] helper 使用 `native_replace_applied`,不将写入完成冒充核验通过。
|
||||||
|
- [x] 写入前固定选定库件、Value/NC 与 Cell 期望,保留原 preserve 语义。
|
||||||
|
- [x] 工程末保存关闭一次;不为核验重开 CAD。
|
||||||
|
- [x] 原生导出按工程、页、位号匹配目标,UID 作为尝试关联证据。
|
||||||
|
- [x] `project_saved` 仅授权后续原生验证,SQL 完成提交必须具备已验证导出。
|
||||||
|
- [x] 暂停、重启与恢复沿用原尝试,已保存操作不重放。
|
||||||
|
- [x] 回执只记录本项观察与共享导出引用,完整工程证明只存一份。
|
||||||
|
- [x] 独立网表比对复用保存后导出。
|
||||||
|
- [x] 完成状态以追加方式发布,保持活动批次的增量读取位置。
|
||||||
|
- [x] 单步执行和非复用模式也按本次调用保存、原生核验、提交完成。
|
||||||
|
- [x] 多批保存恢复只对最新保存状态比较当前源;历史已完成批次核对其固化证据。
|
||||||
|
- [x] 修正真实工程端口名 `LED2/RXDLY` 被误识别为层级路径的问题。
|
||||||
|
- [x] 审查发现的可变缓存图与 mixed no-match 提交问题均有失败复现和修复测试。
|
||||||
|
|
||||||
|
## 验收记录
|
||||||
|
|
||||||
|
真实验证只使用备份的新副本,原备份 34 个文件哈希保持不变。样本选择单页 RL02/RL05,料号从 `4100-CA3300-T7` 替换为 `4100-CA3300-2200`。
|
||||||
|
|
||||||
|
第一次副本完成替换、一次保存与关闭,但原生解析因带 `/` 的端口名误判而拒绝提交。修复解析后,新 Python 进程在 6.03 秒内完成导出与原子提交,两项仍为 generation 1,没有调用 CAD 或重放替换。以原备份独立导出作前基准,与已验证保存后导出比较,结果 verified、差异为空;后导出直接复用。
|
||||||
|
|
||||||
|
第二次副本暴露完成状态发布重建文件、破坏增量读取位置的问题。追加式发布修复后,第三次全新副本完整执行通过:任务表状态 completed,两项操作 verified 且 generation 仍为 1,CAD 进程正常退出。
|
||||||
|
|
||||||
|
| 指标 | 上一轮 | 本轮第三份副本 |
|
||||||
|
| --- | ---: | ---: |
|
||||||
|
| 两项任务总耗时 | 1450.341 秒 | 226.461 秒 |
|
||||||
|
| 工程打开 | — | 1 次 |
|
||||||
|
| 工程保存 | 1 次 | 1 次 |
|
||||||
|
| 全页原生 CAD 快照 | 4 次 | 0 次 |
|
||||||
|
| 保存后为核验重开 CAD | 存在 | 0 次 |
|
||||||
|
|
||||||
|
本轮无 `post-state-*.tsv`,两个目标快照均无 U/G 记录。独立原生器件清单读取耗时 1.312 秒,13 个器件料号全部符合预期;对第三份副本的完整原生前后网表比较同样 verified、差异为空,直接复用保存后导出。原备份 34 文件哈希不变。耗时降低约 84.4%,剩余耗时主要在 CAD 启动、目标定位、替换交互和属性写入。
|
||||||
|
|
||||||
|
本次只完成两项目标的实机功能与性能探针,不能代替此前要求的 20 个业务样本验收。
|
||||||
|
|
||||||
|
第四份新副本验证非复用分支:253.389 秒,两次打开/保存,两个工程提交均 verified,任务 completed,全页 CAD 原生采集仍为 0。两个公开执行事件的 Value 回执均为 verified。随后在该副本模拟“SQL 已提交但状态发布未完成”的保护记录,复现历史源指纹错误阻塞;修复后,新 Python 进程在 0.452 秒内完成恢复,尝试编号、generation、操作状态和历史条目数量均未改变,审计记录 `native_replacement_called=false`。CAD 进程已正常退出。
|
||||||
|
|
||||||
|
全量回归先得到 2412 通过、1 失败;失败来自抽取 VBS 函数的测试夹具漏声明全局新模式变量。修正夹具后该文件 37 项通过;最后一轮涉及执行、恢复、状态、网表与身份关联的回归 430 项通过。后续多批恢复专项 51 项通过,包含三个恢复时机与五个失败证据场景。将全量与增量报告按测试名称合并、以后续复验覆盖原失败结果,**2426 个不同用例均已验证通过**;这不是一次完整重跑的数量,也不将重复执行算作额外业务样本。
|
||||||
|
|
||||||
|
证据位于 `D:/CodexValidation/saved-netlist-20261117/`,自动化报告位于 `build/saved-netlist-validation/`。
|
||||||
|
|
||||||
|
## 覆盖限制
|
||||||
|
|
||||||
|
原生 ASCII 导出不证明 Value 属性的空值/缺失差异,也不覆盖 CAD 显示位置、字体和颜色;回执保留此限制,不伪造这些图形核验结果。本轮不更新旧候选安装包。
|
||||||
@@ -0,0 +1,56 @@
|
|||||||
|
# 私有桌面累积:GitHub 参考与本地可行性验证
|
||||||
|
|
||||||
|
日期:2026-11-18。范围:工单 #20/#29 的 Win32 Desktop 生命周期;不涉及独立校验工作台。本轮为源码调研和一次性 Win32 探针,未修改产品执行逻辑,也未启动 Mentor。
|
||||||
|
|
||||||
|
## 结论
|
||||||
|
|
||||||
|
推荐采用“当前用户、当前 Windows 登录会话内的固定命名桌面,串行租用;每批独立进程 Job 与执行代次”。桌面身份与任务/批次身份解耦。默认只需一个槽位,因为现有 CAD 本身串行执行。
|
||||||
|
|
||||||
|
现有 `BatchCadRuntime._ensure_desktop()` 每次需要新运行代次就生成 `dx-<uuid>`。外部 Agent 留住旧桌面后,隔离记录允许后续任务继续,但新一代仍创建不同桌面;这处理了队列阻断,没有限制桌面对象数量。
|
||||||
|
|
||||||
|
固定对象可以在前一批自有写进程退出后重新打开,即使外部只读句柄仍存在。关闭自己的句柄、关闭 Mentor 和确认桌面对象消失是三件不同的事。复用不应把 `desktop_disappeared=false` 伪报为 true。
|
||||||
|
|
||||||
|
## GitHub 参考
|
||||||
|
|
||||||
|
| 项目 | 核对源码 | 借鉴内容及边界 |
|
||||||
|
| --- | --- | --- |
|
||||||
|
| Sandboxie Plus | [GuiServer.cpp](https://github.com/sandboxie-plus/Sandboxie/blob/f23a6cfd50f506413634e8f2906bfc2888d2b1c3/Sandboxie/core/svc/GuiServer.cpp#L1237) | `GetWindowStationAndDesktopName` 使用静态窗口站/桌面句柄和缓存名称,复用长期管理对象。这里只借鉴资源生命周期,不表示 Sandboxie 已证明解决本机 OCular 问题;它的 dummy desktop、驱动和权限模型不照搬。 |
|
||||||
|
| System Informer | [native.c](https://github.com/winsiderss/systeminformer/blob/952a0e7a4efb45b5e1acc4c733916684a7803406/phlib/native.c#L2158)、[hndlinfo.c](https://github.com/winsiderss/systeminformer/blob/952a0e7a4efb45b5e1acc4c733916684a7803406/phlib/hndlinfo.c#L2256) | 系统句柄枚举、进程句柄快照、对象类型/名称查询,适合作为按需持有者诊断参考。权限不足必须保留未知,不以推断代替持有者身份,不把远端关闭句柄作为日常回收策略。 |
|
||||||
|
| DesktopHeapDiag | [README](https://github.com/leonardomsft/DesktopHeapDiag/blob/7af5ffc3bbc499d3e0850c61326880bc95cb93a5/README.MD)、[main.cpp](https://github.com/leonardomsft/DesktopHeapDiag/blob/7af5ffc3bbc499d3e0850c61326880bc95cb93a5/main.cpp) | 说明桌面堆与 USER 对象的区别。该工具通过大量注册窗口类、逼近分配上限估算使用率,不适合嵌入产品每批自动运行;本轮只读源码,没有运行它。 |
|
||||||
|
|
||||||
|
另核对 UltraVNC 的桌面线程退出处理和 CreateDesktop 示例。普通 Windows Virtual Desktop 切换器使用另一套窗口分组接口,不能替代 Win32 HDESK 管理。未引入任何上述项目的二进制、驱动或依赖。
|
||||||
|
|
||||||
|
微软 [CreateDesktopW](https://learn.microsoft.com/en-us/windows/win32/api/winuser/nf-winuser-createdesktopw) 明确规定:同名桌面已存在时返回已有对象句柄。[CloseDesktop](https://learn.microsoft.com/en-us/windows/win32/api/winuser/nf-winuser-closedesktop) 关闭调用方句柄;调用进程线程正在使用该句柄时会失败。重复 CloseDesktop 不能替外部进程释放其引用。
|
||||||
|
|
||||||
|
## 最小落地方案
|
||||||
|
|
||||||
|
1. 同一用户、同一 Windows 登录会话、同一窗口站使用一个稳定桌面名。不能由工作区路径或批次 UUID 决定,避免更换 data-root、重启程序或多份安装包又制造新桌面。
|
||||||
|
2. 用同范围的命名互斥量串行领取桌面;桌面名称、访问权限与持久租用记录共同确认归属,不能收养任意历史 `dx-*` 对象。
|
||||||
|
3. 每批仍建立新 Job、执行代次、尝试身份与新 Mentor 进程。前批自有写进程及其子树确认退出后,才能把桌面交给下批。已保存回执、源隔离和不重放规则沿用既有逻辑。
|
||||||
|
4. 批次结束先收尾 Mentor/worker 和 Job,再关闭本批桌面句柄。对象消失则记录 released;外部句柄留住但已满足交接条件时记录可复用的空闲桌面及残留事实。不能继续依赖“名称存在=前批写入仍活跃”。
|
||||||
|
5. 异常/重启后重新核对原进程身份与租用记录,再打开相同槽位。槽位仍有实际写入者或无法安全交接时,仅等待该槽位处理,不以新 UUID 桌面绕开。
|
||||||
|
6. 历史资源记录引用租用代次,而不把名称相同误认成同一批 CAD。旧记录不能反复向新 Mentor 发 Quit,也不能因新批正在使用同名桌面而重判旧批清理失败。
|
||||||
|
|
||||||
|
首版无需常驻服务、桌面池扩容或新第三方管理器。使用现有 supervisor 持有本批租用即可。正常结束仍按用户要求退出 CAD;跨批复用的是桌面对象。
|
||||||
|
|
||||||
|
## 本地可行性探针
|
||||||
|
|
||||||
|
脚本:`build/desktop-research-20261118/probe_named_desktop_reuse.py`。结果:`build/desktop-research-20261118/named-desktop-reuse-result.json`。
|
||||||
|
|
||||||
|
- 一个明确由探针创建的独立进程持续 OpenDesktop,模拟外部 Agent 持有引用。
|
||||||
|
- 创建进程关闭自己的句柄后,桌面继续存在,确实进入外部持有场景。
|
||||||
|
- 20 个独立工作进程依次打开/创建同一个名称,每次实际启动另一个进程,在目标桌面创建并销毁 Win32 STATIC 窗口。
|
||||||
|
- 其中 4 个工作进程在自己的 GUI 子进程正常退出后直接 `os._exit(0)`,验证其桌面句柄交给系统收尾的情况;没有测试 GUI 子进程仍活着时的崩溃接管。
|
||||||
|
- 20 轮名称集合始终只比初始状态多同一个对象,新增桌面对象数为 1。
|
||||||
|
- 外部持有者关闭句柄后,该对象消失。调用线程的桌面未变化,没有切换输入桌面。
|
||||||
|
- 46.356 秒,探针 passed;所有探针子进程已结束,无 Mentor 进程启动。
|
||||||
|
|
||||||
|
该探针证明同名对象在外部引用保留下可跨进程复用,不证明真实 OCular 的持有方式完全相同,也不证明 Mentor 跨批 ROT、COM、许可、弹窗和退出兼容性。它更不代表 20 个业务样本通过。
|
||||||
|
|
||||||
|
## 产品改动范围与正式验收
|
||||||
|
|
||||||
|
预计涉及 `isolated_desktop.py` 的明确打开/创建与释放事实、`batch_runtime.py` 的槽位租用和代次、`batch_resources.py` 的历史租用解释,以及 supervisor 跨进程互斥范围。保留现有进程所有权、已保存回执和原生网表核验。
|
||||||
|
|
||||||
|
正式验收应包括外部引用持续存在下的多批真实 Mentor、正常退出/重启、owner 崩溃但 Job 子进程尚在、两份应用同时请求、证据中断、旧租用记录与新代次隔离,并检查桌面对象数不随批次数增长。至少两份工程轮换且分别核验最终原生数据。
|
||||||
|
|
||||||
|
已经存在的任意 UUID 桌面不会因采用稳定槽位自动消失。存量对象仍需外部持有方正常关句柄,或由系统在相关登录会话结束时回收;产品先控制新增对象数量。应在用户故障机上核对持有者和长期运行数据,才能宣布 #20 根治。
|
||||||
@@ -0,0 +1,83 @@
|
|||||||
|
# 固定私有桌面复用:实现与验收
|
||||||
|
|
||||||
|
日期:2026-11-18。分支:`codex/issue29-blocking-cleanup`,基础提交:`d08a940`。范围为 #20/#29 的桌面累积和租用交接;不包含独立校验工作台。
|
||||||
|
|
||||||
|
## 实现结果
|
||||||
|
|
||||||
|
同一 Windows 用户 SID、登录 SID、窗口站产生稳定的 `dx-<32hex>` 桌面名,不再按批次 UUID 创建新桌面。批次、执行代次、租用编号、Mentor 进程及每个子进程的命名 Job 仍独立。批次结束仍退出 Mentor。
|
||||||
|
|
||||||
|
默认队列运行时、独立 CAD 和需要 GUI 的 LibraryManager 入口均启用 managed 模式。原始 `PrivateDesktop` 默认接口保留,缓存命中及纯 CLI 路径不额外领取桌面。无新依赖、服务或桌面池。
|
||||||
|
|
||||||
|
租用状态存于 `%LOCALAPPDATA%/DxPartReplace/desktop-slots/<scope>/`,使用命名互斥量跨进程串行交接。目录创建后取规范路径,以适应本机 Codex MSIX 路径虚拟化。一个短生命周期线程持有和释放 Win32 mutex,允许主线程领取、监控线程收尾,避免 Windows 互斥量的线程所有权错误。
|
||||||
|
|
||||||
|
启动前先持久化命名 Job;实际 Windows 启动通过 `PROC_THREAD_ATTRIBUTE_JOB_LIST` 在 CreateProcess 内原子分配 Job,避免 owner 在“创建子进程”和“加入 Job”之间崩溃留下无归属子进程。启动记录未发布时,仅原子分配且实际 Job 已空的情况允许接管。自定义未知启动边界继续保留未确认状态。
|
||||||
|
|
||||||
|
```mermaid
|
||||||
|
flowchart TD
|
||||||
|
A[请求执行批次] --> B[领取稳定名称的互斥租用]
|
||||||
|
B --> C{前批 owner / Job 已退出?}
|
||||||
|
C -- 否或未确认 --> D[保留等待状态,不创建其他桌面]
|
||||||
|
C -- 是 --> E[创建或打开同名桌面]
|
||||||
|
E --> F[独立命名 Job 启动本批 Mentor / worker]
|
||||||
|
F --> G[执行、保存及原生数据核验]
|
||||||
|
G --> H[正常退出或失败收尾本批进程]
|
||||||
|
H --> I{本批写入者与句柄均已收尾?}
|
||||||
|
I -- 否 --> J[保留租用,继续收尾]
|
||||||
|
I -- 是 --> K[关闭本批桌面句柄,写不可变归还证明]
|
||||||
|
K --> L{桌面对象已消失?}
|
||||||
|
L -- 否 --> M[记录 reusable / isolated,允许下批复用]
|
||||||
|
L -- 是 --> N[记录 released]
|
||||||
|
```
|
||||||
|
|
||||||
|
外部句柄留住桌面时,记录 `desktop_released=false` 与 `desktop_release_state=reusable`,不把归还租用伪报成对象已消失。旧批次只校验自己的不可变归还证明;被动观察桌面消失也取得同一互斥量,不打开或关闭新批次的 Mentor。
|
||||||
|
|
||||||
|
## 验收证据
|
||||||
|
|
||||||
|
证据根目录:`D:/CodexValidation/managed-desktop-20261118/`。构建临时 XML 位于本仓库 `build/managed-desktop/`,不作为产品文件提交。
|
||||||
|
|
||||||
|
| 验证 | 结果 | 证据 |
|
||||||
|
| --- | --- | --- |
|
||||||
|
| 最终相关回归 | 133 passed,43.55 秒 | `build/managed-desktop/final-regression.xml` |
|
||||||
|
| 更早运行的桌面、runtime、catalog 回归 | 143 passed | `build/managed-desktop/regression-1.xml` |
|
||||||
|
| 更早运行的资源生命周期、恢复、保存证明回归 | 135 passed | `build/managed-desktop/fake-delta.xml` |
|
||||||
|
| 最终原生循环 | 20 轮通过,34.781 秒 | `native-probe-04/report.json` |
|
||||||
|
| 两批真实 Mentor | 均通过保存与原生数据回读 | `mentor-live-final/two-batches-result.json` |
|
||||||
|
| 原始备份保护 | 34 个文件 SHA-256 均未变化 | 对照 `mentor-live/original-hashes.json` |
|
||||||
|
|
||||||
|
上述 pytest 集合存在交集,不能累加为独立样本数。先前一次回归与真实 CAD 同时争用默认槽位导致 3 项失败,最终已在 CAD 退出后串行重跑相关模块,包含这 3 项,133 项全过。
|
||||||
|
|
||||||
|
### 原生循环的判定范围
|
||||||
|
|
||||||
|
生产 `BatchCadRuntime` 入口运行 20 个独立进程轮次,外部 helper 全程 OpenDesktop 保持句柄,各轮实际创建和销毁 Win32 窗口。验证稳定桌面名、20 个不同租用编号、竞争实例拒绝领取、owner 崩溃后存活 Job 阻止接管、Job 退出后允许复用。分别覆盖进程身份发布后崩溃,以及原子 Job 已分配但身份尚未发布时崩溃。helper 释放后检查对象消失。
|
||||||
|
|
||||||
|
桌面数量断言针对本探针自己的资源记录:整个运行仅一个受管理名称。全系统枚举同时记录,但其他应用可能并发创建对象,不能把全系统变化归因于本产品。早期 probe-01 因该全系统断言失败的报告保留;probe-03 在改成按归属统计后通过,最终版本另跑 probe-04。原生 20 轮不是 20 个 BOM 业务样本。
|
||||||
|
|
||||||
|
最终 probe-04 全部判定通过:20 个独立租用共用一个名称;并发实例和崩溃后存活 Job 均阻止接管;两种崩溃边界在 Job 退出后恢复;外部 holder 退出后桌面消失。最终检查两批真实任务的全部已记录写进程身份均已退出,受管理桌面已不存在。
|
||||||
|
|
||||||
|
### 两批真实 Mentor
|
||||||
|
|
||||||
|
使用两个独立的新工程副本,同一个外部 helper 跨两批一直持有桌面引用。每批仅替换 `RL02`:`4100-CA3300-T7` → `4100-CA3300-2200`,并从保存后的原生数据回读确认 RL02 和其他未选位号。
|
||||||
|
|
||||||
|
| 项目 | 第一批 | 第二批 |
|
||||||
|
| --- | --- | --- |
|
||||||
|
| 队列执行耗时 | 201.373 秒 | 156.222 秒 |
|
||||||
|
| saved / failed | 1 / 0 | 1 / 0 |
|
||||||
|
| 任务状态 | completed | completed |
|
||||||
|
| CAD 代次 | 1 | 1 |
|
||||||
|
| 正常退出 / 强杀 | 正常 / 无 | 正常 / 无 |
|
||||||
|
| CAD 退出收尾耗时 | 3.484 秒 | 3.156 秒 |
|
||||||
|
| 租用编号 | `2a9dfc16c34e4510bc0df4710869ea02` | `62c4f185a1ac45ccad8a387369d7b5d3` |
|
||||||
|
|
||||||
|
两批桌面均为 `dx-5f48d43089f541634f609af9e3fbdfac`。批次刚结束、helper 仍持有时,Mentor 已释放,桌面未消失,租用已归还。helper 关闭后,两批历史资源记录经被动核对均为 released,待释放集合为空。整体驱动耗时 368.837 秒。
|
||||||
|
|
||||||
|
任务 ID:第一批 `e7fbebd9-c2fa-4554-be05-26f004fd0d02`,第二批 `bfdcaaf8-59ec-467f-81b5-bf061858e799`。各批 `report.json`、`tasks.db` 和 `data/batch-resources/*/session.json` 均保留于 `mentor-live-final/`。
|
||||||
|
|
||||||
|
## 审查和保留问题
|
||||||
|
|
||||||
|
独立源码审查发现并修复两处问题,均观察 RED/GREEN:归还证明临时读取失败后,历史记录不能恢复非阻塞状态;创建 Job 失败时,没有启动进程却留下未确认 launching 记录。随后审查原子 Job 分配及跨线程 mutex 交接,未发现新的具体问题。
|
||||||
|
|
||||||
|
较早真实运行保留在 `mentor-live/`:首批选择 RL02、RL05,两处替换以及 Save/CloseProject 返回后,`bind_project_commit_source` 读取 `database/icdb.dat` 遇到 PermissionError。正常 Quit 后仍需强制结束两个本批后代。业务结果保留失败/未确认,未重放。自有写进程退出后租用成功归还。本次没有修改 `execution_proof.py`,也没有放宽保存证明;数据库锁的根因仍未解决。最终两批单目标成功不能证明该失败已修复。
|
||||||
|
|
||||||
|
已有随机 UUID 桌面不会自动消失;存量仍依赖外部持有方正常关句柄或 Windows 登录会话结束。测试 helper 模拟的是外部 OpenDesktop 引用,真实 OCular 环境的长期行为仍需用户故障机验收。稳定名称只限制本产品新增受管理对象,不保证消除其他软件内部资源泄漏。
|
||||||
|
|
||||||
|
本次未构建安装包或发布新版本,没有操作原工程、中心库、系统配置或外部 Agent。
|
||||||
@@ -0,0 +1,86 @@
|
|||||||
|
# 保存后数据库占用:修复与验收
|
||||||
|
|
||||||
|
日期:2026-11-18。分支:`codex/issue29-blocking-cleanup`,基础提交:`cdbc92f`。范围为保存后的源文件绑定、占锁交接、诊断与收尾错误;不涉及独立校验工作台。
|
||||||
|
|
||||||
|
## 问题与处理
|
||||||
|
|
||||||
|
先前 `mentor-live/first-project` 的 RL02、RL05 两处替换及 Save/CloseProject 已返回,随后 `bind_project_commit_source()` 读取 `database/icdb.dat` 时发生 PermissionError。该异常被归为通用错误,外层资源释放错误又掩盖了原始位置。历史日志缺少底层 Windows 代码和持锁者证据,仍不能认定当时的具体持锁进程。
|
||||||
|
|
||||||
|
现在先验证 CAD 身份及工程确实关闭,固定保存 marker、原始尝试和目标证据到 `project-save-pending.json`,再进行源文件绑定。只有绑定成功才发布完整 `project-checkpoint.json` 并登记工程检查点。等待期间显示“工程已保存,等待数据库释放后核验”;不是已经核验成功。
|
||||||
|
|
||||||
|
```mermaid
|
||||||
|
flowchart TD
|
||||||
|
A[替换、保存及关闭工程] --> B[验证空工程与本批身份]
|
||||||
|
B --> C[保留保存 marker 和原始尝试证据]
|
||||||
|
C --> D[读取保存源文件]
|
||||||
|
D --> E{读取结果}
|
||||||
|
E -- 正常 --> F[绑定稳定源文件及命令摘要]
|
||||||
|
E -- Windows 32 / 33 --> G[记录错误及持锁观察,最多等待 3 秒]
|
||||||
|
E -- 权限、缺失等 --> P[已保存但待核验,保留首发原因]
|
||||||
|
G --> D
|
||||||
|
G -- 仍占用 --> H[再检查暂停意图,正常退出本批 Mentor 一次]
|
||||||
|
H -- 正常退出 --> I[再次读取,最多等待 3 秒]
|
||||||
|
H -- 强杀或收尾未确认 --> P
|
||||||
|
I -- 仍占用或暂停 --> P
|
||||||
|
I -- 可稳定读取 --> F
|
||||||
|
F --> J[从保存副本导出原生数据并核验目标]
|
||||||
|
J --> K[提交真实回执,任务完成]
|
||||||
|
```
|
||||||
|
|
||||||
|
Windows 读文件使用 CreateFile 保留原生错误码,使用与后续 CRT 校验一致的 READ/WRITE 共享模式。仅 32(共享冲突)、33(锁冲突)进入等待;5(权限不足)、2(文件缺失)等直接形成明确的 `saved_source_pending` 错误。源文件读前后的工程摘要必须一致,改变或不可确认时保留待核验。
|
||||||
|
|
||||||
|
退出回调只存在于受管理 runtime 的已关闭工程、已验证保存 marker 分支。正常可读时继续复用 CAD;异常才走现有身份绑定的正常 Quit。该路径不派发替换,也不重新打开原工程。退出失败或需要强杀时,不绑定成功证明;资源释放和业务待核验分别保留。暂停会阻止进入退出回调,并在诊断、读取恢复后重新检查。已请求普通暂停但未遇锁的安全保存收尾仍沿用原流程。
|
||||||
|
|
||||||
|
首次锁冲突使用 Windows Restart Manager 只读查询候选进程,记录 PID、创建时间和名称。结果是该接口返回的观察,不是穷举全部内核句柄;空结果或查询失败均不授权结束任何外部进程。查询后重读,防止用已经过时的锁状态触发 CAD 回收。
|
||||||
|
|
||||||
|
`saved-source-status.json` 保留同一 session token、同一工程的首发错误、持锁观察及回收事实,后续 SQL 回执再次绑定时不会覆盖它;新 token 重置诊断。该文件不是成功证明,实际源文件始终重新验证。`operation-events.jsonl` 保留绑定及 Mentor 退出调用的先后顺序。多层资源异常仍显示最初的保存读取错误;诊断写入失败通过附注保留,不能替换首发错误。
|
||||||
|
|
||||||
|
## 验收结果
|
||||||
|
|
||||||
|
证据根目录:`D:/CodexValidation/saved-source-20261118/`。测试 XML 在仓库 `build/managed-desktop/`,集合有交集,不累加为独立用例或业务样本数。
|
||||||
|
|
||||||
|
| 验证 | 结果 | 证据 |
|
||||||
|
| --- | --- | --- |
|
||||||
|
| 保存、runtime、回执、恢复与反馈相关回归 | 124 passed,108.18 秒 | `saved-source-regression-final.xml` |
|
||||||
|
| 源文件交接及资源状态增量回归 | 64 passed,26.56 秒 | `saved-source-delta-final.xml` |
|
||||||
|
| 最终专项,Windows 默认 GBK 环境 | 21 passed,5.52 秒 | `saved-source-handoff-final.xml` |
|
||||||
|
| 最终原生文件锁探针 | 20 个样本通过,28.320 秒 | `native-final-02/report.json` |
|
||||||
|
| 原失败双目标工程,正常运行 | 2 saved / 0 failed,原生回读通过 | `mentor-dual/report.json` |
|
||||||
|
| 双目标工程,保存后注入真实锁 | 2 saved / 0 failed,正常退出后核验通过 | `mentor-dual-fault/report.json`、`fault-result.json` |
|
||||||
|
|
||||||
|
新逻辑均先观察失败再修复;覆盖权限/缺失不重试、短暂锁、持续外部锁、源文件变化、暂停在诊断中到达和在退出提示后到达、强杀/退出未确认不发布证明、日志写失败、嵌套异常、诊断再绑定历史、下一工程新代次和可选进度损坏。独立只读审查提出的具体问题已修复,最终复查无剩余可操作发现。
|
||||||
|
|
||||||
|
### 20 个原生文件锁样本
|
||||||
|
|
||||||
|
脚本:`tools/probe_saved_source_handoff.py`。使用合成工程与文件,不启动 CAD。五种场景各 4 次:短暂独占锁、退出持有者后读取、持续外部锁、等待中暂停、文件缺失。真实 CreateFile 独占锁返回 32;Restart Manager 查到已知 fixture 进程。仅前两类最终绑定成功,其余保留 pending,退出回调次数受限,均不执行替换。真正 ACL 拒绝不通过修改用户 ACL 制造,错误 5 由专项测试模拟。
|
||||||
|
|
||||||
|
探针中的退出回调只释放其自建 fixture 进程,不能当成真实 Mentor 回收测试。首轮 `native-01` 曾发现诊断耗时导致使用旧冲突触发退出,报告保留;补重读及回归后通过,最终又以默认编码环境运行。20 个文件锁样本不是 20 个 BOM 业务样本。
|
||||||
|
|
||||||
|
### 两次真实 Mentor 双目标验收
|
||||||
|
|
||||||
|
两个独立的新副本均替换 RL02、RL05:`4100-CA3300-T7` → `4100-CA3300-2200`。从保存后的原生数据独立读取两个目标及其余未选位号;每次仅一个 VBS worker、一次 OpenProject、一次保存,没有重放。
|
||||||
|
|
||||||
|
| 指标 | 正常双目标 | 注入锁双目标 |
|
||||||
|
| --- | --- | --- |
|
||||||
|
| 队列耗时 | 257.842 秒 | 271.420 秒 |
|
||||||
|
| saved / failed | 2 / 0 | 2 / 0 |
|
||||||
|
| 任务 / 操作状态 | completed / verified | completed / verified |
|
||||||
|
| CAD 代次 | 1 | 1 |
|
||||||
|
| 正常退出 / 强杀 | 正常 / 无 | 正常 / 无 |
|
||||||
|
| CAD 退出耗时 | 16.625 秒 | 5.688 秒 |
|
||||||
|
|
||||||
|
正常运行没有复现历史锁。故障运行由 `build/managed-desktop/live_saved_source_fault.py` 在已保存关闭后,用一个自建独立进程持有副本数据库的只读独占句柄;产品调用正常退出 Mentor,驱动确认退出回调返回后才释放 fixture,然后由产品继续核验。`fault-result.json` 证明注入成功、退出回调确实调用且运行退出码为 0。外部 fixture 并非被产品杀死,不能据此声称 Mentor 的 Quit 可以关闭任意外部文件句柄。
|
||||||
|
|
||||||
|
故障时间线(本地时间):18:16:39.722 开始绑定,18:16:43.192 开始正常退出 Mentor,18:16:48.910 退出返回,18:16:49.806 绑定完成。两次总耗时差异包含 CAD 运行波动,不能直接视为等待逻辑的固定开销。
|
||||||
|
|
||||||
|
任务 ID:正常 `d9a1c9af-7a39-4659-a445-a682c8c41a91`;故障 `be954b05-2b8c-4990-a74f-e18655ca93af`。两次任务数据库均 completed、两个操作均 verified;全部已记录写进程身份退出,受管理桌面消失。原始备份 34 文件 SHA-256 全部未变化。
|
||||||
|
|
||||||
|
真实故障验收后发现并修正同 token 诊断被第二次绑定覆盖的问题;暂停、嵌套报错、编码及诊断保留的最终增量由专项和资源回归验证。真实工程写入场景未为这些诊断增量重复执行。
|
||||||
|
|
||||||
|
## 边界
|
||||||
|
|
||||||
|
历史失败的具体持锁者仍不可从旧日志还原,本次修复并验证的是这类冲突的交接处理。持续的外部锁、真正权限不足、文件变化及强杀后不确定写入继续保留待核验,不能算执行成功,也不会自动重替换。
|
||||||
|
|
||||||
|
如果在完成源文件绑定之前退出程序,只保留保存 marker 和原始尝试,现有恢复逻辑不会把未绑定的 `project-save-pending.json` 当成成功证明。该状态仍需核对原结果,不提供自动重放或自动成功恢复。
|
||||||
|
|
||||||
|
未构建安装包、推送或发布版本;未修改原工程、中心库、系统配置和外部 Agent。
|
||||||
@@ -0,0 +1,41 @@
|
|||||||
|
# 批量添加工程对验收
|
||||||
|
|
||||||
|
分支 `codex/independent-verification`,功能提交 `eda9403`,拒收回执修正 `de16bbd`。2026-11-18 重新 fetch 后,主线仍为 `b19afc6`。本轮只补批量导入,不修改另一任务的既有执行器修复。
|
||||||
|
|
||||||
|
## 已实现
|
||||||
|
|
||||||
|
- 第四页新增“批量添加”,打开非模态窗口,仍能新建其他校验任务。
|
||||||
|
- 读取两个独立根目录,沿用已有只读目录扫描规则,按相对路径精确配对;不按同名文件猜测对应关系。缺失、不唯一的项列出且不能勾选。
|
||||||
|
- 勾选后逐对建立冻结副本,列表与报告保留相对路径名称;同名工程可区分。导入不会启动网表校验或换料。
|
||||||
|
- 单项失败后继续,取消保留已导入项;同一批请求可续传且不重复建项。请求取消后仍绑定原始输入,不允许用相同请求标识替换内容。
|
||||||
|
- 磁盘/存储故障中断整批;任务库拒收单项时明确显示失败,不把函数返回等同于导入成功。超过256字符的批量名称提示缩短层级或逐对添加。
|
||||||
|
- 扫描、复制在后台执行;关闭窗口取消操作,晚到结果不回写已关闭界面,应用关闭协作沿用现有控制器。
|
||||||
|
|
||||||
|
## 自动化验证
|
||||||
|
|
||||||
|
| 范围 | 实际结果 |
|
||||||
|
| --- | --- |
|
||||||
|
| 原独立校验组与本轮两份新测试文件,共18文件 | **92 passed**,`D:/dx-vfy-batch-final.xml` |
|
||||||
|
| 既有关闭生命周期 `tests/ui/test_deferred_close_lifetime.py` | **2 passed**,`D:/dx-vfy-batch-close.xml` |
|
||||||
|
| 最终包运行时、supervisor、创建时间、关闭与资源释放 | 通过;`tools/verify_packaged_runtime.py`,数据根 `D:/dx-vfy-batch-smoke-20261118` |
|
||||||
|
|
||||||
|
本轮新增11项测试覆盖相对路径/缺失、根目录重叠、失败后继续、重复请求、取消续传、存储耗尽、输入绑定、拒收回执,以及Qt勾选导入、并行新建和关闭读取。先确认缺失接口、请求复用及误报成功的反例失败,再实现并复跑。
|
||||||
|
|
||||||
|
解释器为 `D:/dx-vfy-python-20261117/Scripts/python.exe -X utf8`。新文件为 `tests/v1_1/test_verification_batch_import.py` 与 `tests/ui/test_verification_batch_import.py`,与[前轮验收](2026-11-17-independent-verification-acceptance.md)的16文件校验组一起执行,使用独立D盘临时目录,没有放宽旧断言。
|
||||||
|
|
||||||
|
本轮未重新执行全部默认测试。当前默认收集2261项,在已留存的分组通过记录中均有覆盖,`missing=[]`,`D:/dx-vfy-batch-regression-coverage.json`。这属于历史分组覆盖审计,不代表新取得一次连续全量全绿;前轮记录的既有时序波动仍保留。
|
||||||
|
|
||||||
|
## 实际开发包
|
||||||
|
|
||||||
|
更新包:`D:/dx-vfy-release-20261117/DxPartReplace/DxPartReplace.exe`,保留同目录 `_internal`。EXE SHA256:`56ba31c71f61aafed0bdeab88026112adc7362c4a037d94a783cfddb5959a24f`。仍使用前轮完整标准构建的原生运行时,通过官方PyInstaller API重新编译Python代码;`D:/verification-code-refresh.spec` 显式包含新增两个模块。
|
||||||
|
|
||||||
|
实际解包与源码代码对象比较:**24个变更模块匹配,无 mismatch**;`D:/dx-vfy-package-proof.json`,复核脚本 `D:/vfy_verify_archive.py`。前轮EXE及证明另存 `D:/dx-vfy-history-20261117/`,避免覆盖历史证据。
|
||||||
|
|
||||||
|
通过外部Windows UI操作实际EXE,新建任务、点击“批量添加”、填写前后目录、读取配对、导入所选、返回任务、正常关闭。输入是既有已保存工程的复制件,包含两个同名工程对及一项缺失:
|
||||||
|
|
||||||
|
- `A/input.prj`、`B/input.prj` 正确导入,`orphan/input.prj` 因缺少修改后工程未导入。
|
||||||
|
- 校验尝试数0、换料操作数0,所有输入文件摘要不变,退出码0。
|
||||||
|
- 实际操作证明 `D:/dx-vfy-batch-package-20261118/acceptance.json`;预览截图 `batch-preview.png`、完成截图 `batch-imported.png`、任务截图 `batch-workspace.png` 在同目录。
|
||||||
|
- 测试脚本 `D:/vfy_packaged_batch.py` 只通过Windows可访问性接口操作应用窗口,再查询持久结果;没有直接注入任务状态。主窗口PrintWindow截图的灰底来自默认透明材质捕获,不据此改动既有全局UI。
|
||||||
|
|
||||||
|
批量导入仅覆盖目录结构对应的输入登记;本轮未重新执行真实原生网表导出。引脚级Value、确切库内脚到焊盘映射仍按前轮明确未覆盖。未合并、推送或发布。
|
||||||
@@ -0,0 +1,53 @@
|
|||||||
|
# 工程校验闭环验收(2026-11-18)
|
||||||
|
|
||||||
|
后续剩余四项已完成,最新状态见[最终闭环验收](2026-11-18-verification-final-closure.md)。本文保留当时的原始范围与未测记录,不作为最新缺口清单。
|
||||||
|
|
||||||
|
按[闭环标准 v1](verification-closed-loop-standard.md)补齐 N12。代码与工具提交 `e65bed0`,分支 `codex/independent-verification`。本次没有修改另一修复任务的旧执行器,没有合并、推送或发布。
|
||||||
|
|
||||||
|
## 实现与标准
|
||||||
|
|
||||||
|
新增 `tools/verification_closed_loop.py`:开始前冻结范围、源文件摘要和换料操作基线,逐项检查实际运行成员、终态、预期结论、输入/尝试/策略绑定、原文摘要、资源退出证明与报告。空任务、漏项、停止/中断、错误预期、旧报告或源文件变化不能通过。
|
||||||
|
|
||||||
|
HTML报告增加 item、attempt、generation、输入版本/摘要和证据摘要的可核对绑定。已有换料历史允许保留;只读标准检查运行前后计数不变,而非历史总数必须为0。整任务报告中只验证选定项时必须明确指定范围,其余项不冒充已验证。
|
||||||
|
|
||||||
|
单次服务验收入口 `tools/verify_independent_verification.py` 增加 `--expect-verdict`,默认 CONSISTENT;预期警告应事先传 WARNING。输出 `frozen-scope.json` 和 `closed-loop.json`,检查不通过非零退出。它明确只覆盖 C01~C05,C06~C08 保留 not_run。
|
||||||
|
|
||||||
|
实际包入口 `tools/accept_verification_closed_loop.py` 通过Windows可访问性操作EXE,公开服务和SQLite用于读取及核对,不直接注入执行状态。必须事先给出预期名单和结论;`--fault-batch` 在私有复制件中加入明确无效的数据库反例,原输入目录不改写。
|
||||||
|
|
||||||
|
## 实际通过范围
|
||||||
|
|
||||||
|
| 场景 | 结果 | 证据 |
|
||||||
|
| --- | --- | --- |
|
||||||
|
| 两份真实保存副本批量导入、原生执行、查看、报告、重启、重校验 | C01~C07通过,两个 WARNING 符合事先指定的预期;重校验后尝试为1、1、2,旧结果和报告不变 | `D:/dx-vfy-loop-package-20261118-v2/acceptance.json`,16条检查通过 |
|
||||||
|
| 首项原生失败,后续两个真实保存副本继续 | 00-invalid 为 failed/INCOMPLETE,随后 A、B 均完成 WARNING;混合报告、重启和A单项重校验通过 | `D:/dx-vfy-loop-faults-20261118-v2/acceptance.json`,17条检查通过 |
|
||||||
|
| 只读与正常关闭 | 两个现场的所有记录输入摘要不变,换料操作数0;所有测试实例正常关闭,未按PID杀进程 | 各现场 JSON、应用正常退出日志和资源退出证明 |
|
||||||
|
| 校验功能组 | 104 passed,19个测试文件 | `D:/dx-vfy-loop-final.xml` |
|
||||||
|
| 闭环选定范围补充复核 | 19 passed,覆盖本轮验收器、CLI和报告 | `D:/dx-vfy-loop-scope.xml` |
|
||||||
|
|
||||||
|
第二现场的失败项是自建无效数据库,证据类型 `native-real-copies-and-invalid-database-fixture`。它证明真实原生导出失败后的隔离行为,不能冒充真实客户工程反脚。物理脚互换、断线、短接、loop→outloop、必查未知等判断仍由明确标注的受控服务/Qt反例验证。
|
||||||
|
|
||||||
|
各现场保存 `01-pairs.png`、`02-result.png`、`03-restart.png`、`frozen-scope.json`、`first-run.json`、`restart-readback.json`、`rerun.json` 和两个不可覆盖的报告目录。重校验报告绑定新attempt,原报告摘要未变。
|
||||||
|
|
||||||
|
## 可复现命令
|
||||||
|
|
||||||
|
使用本机独立验证环境,下面的输入目录是前轮保存副本,不是源工程;输出必须为新目录。
|
||||||
|
|
||||||
|
```powershell
|
||||||
|
& 'D:/dx-vfy-python-20261117/Scripts/python.exe' -X utf8 tools/accept_verification_closed_loop.py --exe D:/dx-vfy-release-20261117/DxPartReplace/DxPartReplace.exe --before-root D:/dx-vfy-batch-package-20261118/before --after-root D:/dx-vfy-batch-package-20261118/after --expected-items A/input.prj B/input.prj --expect-verdict WARNING --output D:/NEW-normal-loop
|
||||||
|
```
|
||||||
|
|
||||||
|
加入 `--fault-batch` 并换用新输出目录,可重复故障隔离场景。工具只在自己的输出目录复制输入并生成 `00-invalid`,该名称为反例保留名。
|
||||||
|
|
||||||
|
测试使用同一解释器 `-X utf8 -m pytest`,原18文件校验组增加 `tests/v1_1/test_verification_closed_loop.py`,参数 `-q --basetemp D:/dx-vfy-loop-delta-final --junitxml D:/dx-vfy-loop-final.xml`。补充复核为 `tests/v1_1/test_verification_closed_loop.py tests/v1_1/test_independent_verification_acceptance.py tests/v1_1/test_verification_reports.py`,输出 `D:/dx-vfy-loop-scope.xml`。
|
||||||
|
|
||||||
|
## 包身份与失败现场
|
||||||
|
|
||||||
|
本地开发包仍位于 `D:/dx-vfy-release-20261117/DxPartReplace/DxPartReplace.exe`,须保留同目录 `_internal`。本轮EXE SHA256为 `c52c43d8b4a864b85f0a39b92a5b3aab2bc36095240d42968d2d34971c270a91`。复用此前标准构建的未变原生运行时,通过官方PyInstaller API重新编译Python;`D:/vfy_verify_archive.py` 对本分支24个变更模块逐个比较代码对象,全部一致,记录 `D:/dx-vfy-package-proof.json`。上一批量版EXE和证明保留在 `D:/dx-vfy-history-20261118-batch/`。
|
||||||
|
|
||||||
|
失败记录保留:首个正常现场因自动化误用文件选择器而无法操作目录选择器;首个故障现场在重启等待中触发驱动内部15秒超时。已依据真实控件ID修正目录选择器,并让外层90秒等待正确处理内部超时;没有改产品文件对话框或伪造结果。旧现场分别为 `D:/dx-vfy-loop-package-20261118/`、`D:/dx-vfy-loop-faults-20261118/`,测试实例均正常关闭。通过结果来自修正后的全新目录,不是改写旧失败记录。
|
||||||
|
|
||||||
|
## 未测与发布门槛
|
||||||
|
|
||||||
|
仍未取得实际包中停止/资源未知的独立故障现场;其服务/Qt受控回归已通过。真实成功换料回执触发自动交接的包内闭环尚未测,不能用独立输入替代;本轮没有为此重新执行客户换料。连续默认全量没有重跑,前轮既有时序波动仍未解决。因此本次只证明上表范围,未达到发布门槛。
|
||||||
|
|
||||||
|
引脚级Value、确切封装库内部脚位到焊盘映射仍未覆盖,不能从网表校验推断这些能力通过。后续按计划中未勾选项推进。
|
||||||
@@ -0,0 +1,59 @@
|
|||||||
|
# 剩余四项闭环验收
|
||||||
|
|
||||||
|
执行分支 `codex/independent-verification`,验收工具与回归提交 `b038951`。按[确认的剩余计划](../superpowers/plans/2026-11-18-verification-remaining-closure.md)顺序执行,未修改其他修复工作区,未合并、推送或发布。
|
||||||
|
|
||||||
|
**剩余四项均已取得对应闭环证据。** 停止/恢复、资源未知保护、真实已保存回执自动交接,以及固定提交上的连续默认全量均通过;此前历史记录中的未测状态以本文更新为准。
|
||||||
|
|
||||||
|
## 业务闭环现场
|
||||||
|
|
||||||
|
| 项目 | 已验证的实际行为 | 现场 |
|
||||||
|
| --- | --- | --- |
|
||||||
|
| 三工程停止与继续 | 第一项运行时点击停止;两项未派发保持待校验;重启不自动运行;开始全部只继续这两项,已停止项明确重校验;最终三项均WARNING,旧停止记录保留 | `D:/dx-vfy-stop-three-20261118/acceptance.json` |
|
||||||
|
| 自有实例异常退出 | 核对PID、创建时间与owner后仅中断本工具启动的实例;没有原生退出证明时重启保留stopping/unknown,不显示有效结论、不给后续项创建导出目录 | `D:/dx-vfy-owner-exit-register-20261118/acceptance.json` |
|
||||||
|
| 资源未知下可用性 | 可新建另一任务并导入两项;共4输入、仍只有原来的2次尝试;暂停原因在“检查与范围”中实际可见,应用正常关闭 | 同目录 `reason-visible.json`、`resource-unknown-reason.png` |
|
||||||
|
| 真实保存回执自动交接 | 临时副本RV05从4100-CA0000-T7到4100-CA0000-T0,RV11保持;恰好一条verified换料记录,自动交接只有一个工程项 | `D:/dx-vfy-real-handoff-20261118-v2/acceptance.json` |
|
||||||
|
| 交接后校验、报告、重启与重校验 | 两次尝试generation 1/2,均WARNING;声明属性为expected_change,物理脚/连接/位号/覆盖/网名等必查equal;14条闭环检查通过,换料记录完整内容未变,重复交接未重复建项 | 同目录 `verification-loop/acceptance.json` |
|
||||||
|
|
||||||
|
所有只读校验现场的输入摘要再次核对未变。真实换料只发生于新测试副本,原始样例及共享库LMC摘要仍与执行前一致。资源未知现场按设计保留,不补造退出证明;测试应用实例均已退出。
|
||||||
|
|
||||||
|
预期在开始前保存:停止/异常场景的 `frozen-scope.json`,真实换料的 `predeclared.json`。后者先真实原生导出证明RV05/RV11前提,再准备BOM并通过实际EXE点击确认执行;无直接SQLite写入来伪造换料结果。
|
||||||
|
|
||||||
|
停止现场有 `continued.json`、`stopped-item-rerun.json` 和各自报告。真实交接有确认截图、自动交接截图、原生before/after、不可变快照、实际运行回执、报告以及重启截图。未知资源场景有本工具记录的owner身份和界面截图,未终止其他进程。
|
||||||
|
|
||||||
|
## 实现与验证边界
|
||||||
|
|
||||||
|
新增控制场景验收检查器和真实交接验收工具;`accept_verification_closed_loop.py` 增加 `--control-scenario stop|owner-exit`、`--handoff-data`。产品没有新增故障开关,也没有更改旧换料执行器。
|
||||||
|
|
||||||
|
真实交接的before是历史不可变快照,替换保存后,其原路径自然已有新内容。验收器仅在明确的 `historical_before=True` 且存在预期清单时使用历史快照证明before,以after源摘要作为后续校验只读基线,不重新捕获旧before。普通独立导入仍检查源文件未偏离导入版本。
|
||||||
|
|
||||||
|
只读检查增加执行日志摘要,除了记录数不变,还要求原有command、receipt和generation不变;相应反例已先失败再修正。真实实际包外层另外比较校验前后全部换料记录,证明不会原地重放已有操作。
|
||||||
|
|
||||||
|
针对验收器/控制/CLI/报告的相关回归:**22 passed**,`D:/dx-vfy-final-closure-related.xml`。
|
||||||
|
|
||||||
|
第一次连续默认全量:**2276 passed,0 failures,0 errors**,`D:/dx-vfy-continuous-default-20261118.xml`,耗时1214.45秒。此轮启动后补充过验收器的日志摘要反例,因此仍追加在固定提交 `b038951` 上的最终全量运行,不把首轮当作最终固定测试版本的全部证据。
|
||||||
|
|
||||||
|
执行恢复/回执及打包扩展:**120 passed,1 skipped**,`D:/dx-vfy-final-closure-extended.xml`。范围为 `tests/dsh/test_execution_recovery.py`、`test_run_journal.py`、`test_large_execution_scope.py` 和 `tests/packaging`;跳过的是未配置官方7-Zip的自解压验证。
|
||||||
|
|
||||||
|
固定提交上的最终默认全量:**2276 passed,0 failures,0 errors,0 skipped**,输出 `D:/dx-vfy-fixed-default-20261118.xml`,耗时1271.60秒。启动前记录631个已跟踪产品/测试/工具文件的SHA256:`D:/dx-vfy-fixed-default-20261118-manifest.json`;结束后实际复核全部不变。它与第一轮分开留证,不能用历史分组覆盖代替。
|
||||||
|
|
||||||
|
两轮均只有pywinauto的STA COM线程模式提示,没有失败或错误。本轮未改写旧测试的时序断言;当前完整回归通过不等于声称根治所有环境中的历史时序波动。
|
||||||
|
|
||||||
|
第一次真实交接现场 `D:/dx-vfy-real-handoff-20261118` 因自动化尚未选择任务导致执行按钮不可用,记录失败并正常关闭,换料操作数0。修正测试驱动为先选择任务,再使用全新v2副本完成实际执行;没有对已替换副本重复派发。
|
||||||
|
|
||||||
|
## 包身份
|
||||||
|
|
||||||
|
仍使用 `D:/dx-vfy-release-20261117/DxPartReplace/DxPartReplace.exe` 和完整 `_internal`。EXE SHA256:`c52c43d8b4a864b85f0a39b92a5b3aab2bc36095240d42968d2d34971c270a91`。本轮只改验收工具、测试和文档,产品代码没有改变,无需重新构建。
|
||||||
|
|
||||||
|
`D:/vfy_verify_archive.py` 已对本分支24个变更产品模块逐个比较最终包代码对象,全部匹配。身份记录 `D:/dx-vfy-package-proof.json`。校验源码与包的一致性不能替代厂商工具或库内部能力验证。
|
||||||
|
|
||||||
|
最终运行时复核通过:`tools/verify_packaged_runtime.py` 对全新数据根 `D:/dx-vfy-final-closure-runtime-20261118` 验证frozen supervisor、win32timezone、进程创建时间、正常退出和资源释放,均为true。开发包保持原SHA256。
|
||||||
|
|
||||||
|
## 复现入口
|
||||||
|
|
||||||
|
使用 `D:/dx-vfy-python-20261117/Scripts/python.exe -X utf8`,工作目录为本分支。所有输出目录必须新建且不能位于源工程/库内。
|
||||||
|
|
||||||
|
- 停止/异常退出:`tools/accept_verification_closed_loop.py --exe <EXE> --before-root <前目录> --after-root <后目录> --expected-items A/input.prj B/input.prj C/input.prj --expect-verdict WARNING --control-scenario stop --output <新目录>`;未知资源用 `owner-exit`,至少保留两项供未派发检查。
|
||||||
|
- 真实交接:`tools/accept_verification_saved_handoff.py --source <原始已保存工程.prj> --library <已安装库.lmc> --exe <EXE> --output <新目录>`;固定RV05/RV11和料号前提不满足时失败,不临时换测试目标。
|
||||||
|
- 连续默认全量:`-m pytest -q --basetemp D:/dx-vfy-fixed-default-20261118-long-temporary-root --junitxml D:/dx-vfy-fixed-default-20261118.xml`;重复执行须换用全新临时根和XML文件,保留本次原始记录。
|
||||||
|
|
||||||
|
引脚级Value和确切封装库内部映射仍未覆盖,不属于四项验收缺口,也未宣称完成ERC/PCB验证。官方7-Zip缺失导致的自解压安装包检查仍为skip;本轮交付已验证的本地开发包,没有制作、合并或发布新安装包。
|
||||||
@@ -0,0 +1,37 @@
|
|||||||
|
# Issue 33 D2 · 工程路径错误提示验收
|
||||||
|
|
||||||
|
工程读取和任务创建的路径检查直接调用 `lstat()`。目录不存在或扫描后工程移走时,文件系统异常进入统一兜底,现场报告仅能看到“发生未处理异常”。目录存在且能读取属性时,`scandir()` 仍可能因缺少列目录权限失败。
|
||||||
|
|
||||||
|
修复在路径检查和读取处分类处理这些预期错误。读取对话框和创建任务的错误提示均显示完整路径、分类代码、处理建议和可关联日志的 `DXT` 编号。预期错误写入一条应用日志。未知异常保留 traceback。
|
||||||
|
|
||||||
|
## Windows 11 实测
|
||||||
|
|
||||||
|
使用 Qt 按钮启动读取、真实文件系统与任务库。第五例在成功扫描两个候选工程后重命名其中一个文件,从实际服务入口创建选定任务并检查主窗口所用的错误格式和任务数据库。
|
||||||
|
|
||||||
|
| 输入 | 基线 `46deb9c` | 修复后代码 | 修复后错误编号 |
|
||||||
|
| --- | --- | --- | --- |
|
||||||
|
| 不存在的目录 | 通用兜底 | `path_missing` | `DXT-20261125-3EE8F667` |
|
||||||
|
| 普通文件作为目录 | 英文非目录文案 | `path_not_directory` | `DXT-20261125-92876D74` |
|
||||||
|
| 路径中途遇到普通文件 | 通用兜底 | `path_not_directory` | `DXT-20261125-0C615FE8` |
|
||||||
|
| ACL 拒绝列目录 | 通用兜底 | `path_denied` | `DXT-20261125-ED64EEA9` |
|
||||||
|
| 工程在扫描后被移走 | 通用兜底 | `path_missing` | `DXT-20261125-CA48D2FF` |
|
||||||
|
|
||||||
|
ACL 测试对临时目录中的当前用户拒绝 `FILE_LIST_DIRECTORY`,两个版本的文件系统操作均触发原生 `WinError 5`。创建任务失败后库中仍有 0 条任务。五个路径输入的通用兜底率从 4/5 降到 0/5。额外注入的 `RuntimeError` 对照组仍触发一次 `unhandled_exception`,并保留 traceback。
|
||||||
|
|
||||||
|
## 复跑
|
||||||
|
|
||||||
|
在仓库根目录运行。使用未占用的临时目录保存测试日志。
|
||||||
|
|
||||||
|
```powershell
|
||||||
|
$env:PYTHONUTF8 = '1'
|
||||||
|
python -m pytest -q -s tests/v1_1/test_project_path_errors.py tests/v1_1/test_scan_responsiveness.py tests/v1_1/test_project_long_paths.py tests/v1_1/test_path_access.py tests/trial_task_center/test_logging_setup.py --basetemp build/issue33-d2
|
||||||
|
```
|
||||||
|
|
||||||
|
实测 35 项通过。以下命令按错误记录统计扫描和创建任务的通用兜底率。路径用例与故障对照分别统计时,从相应测试目录读取日志。
|
||||||
|
|
||||||
|
```powershell
|
||||||
|
$rows = Get-ChildItem build/issue33-d2 -Recurse -Filter application.log |
|
||||||
|
Select-String 'error_id=\S+ operation=(scan_project_directory|create_project_tasks) (code=\S+ )?message='
|
||||||
|
$generic = $rows | Where-Object { $_.Line -match 'code=unhandled_exception |message=发生未处理异常$' }
|
||||||
|
'{0}/{1}' -f @($generic).Count, @($rows).Count
|
||||||
|
```
|
||||||
@@ -0,0 +1,31 @@
|
|||||||
|
# Issue 33 D5 · BOM 未知列验收
|
||||||
|
|
||||||
|
现场 B3 的 `INVALID_C1_bad_header_extra_col.xlsx` 带有 `extra_column`。名称归一化将未知列映射为空,后续只复制模板定义的列。导入成功时,工作区原先只报告保存行数与失败行数。
|
||||||
|
|
||||||
|
现在 BOM 导入保留模板列的精确映射,并为每个被忽略的具名列显示来源文件、原始列名与警告计数。详情和任务事件同时记录这些警告。缺失必需列时,导入停止,错误详情列出具体缺失项并对相近列名给出改名建议。
|
||||||
|
|
||||||
|
## Windows 11 重放
|
||||||
|
|
||||||
|
通过 Qt 工作区的“导入 BOM”按钮和真实任务服务运行,测试替换的是文件选择对话框的返回值。现场文件复制到临时目录,仅把第一条记录的工程名称与路径绑定到临时工程,保留了原始表头和替换字段。
|
||||||
|
|
||||||
|
| 工作簿 | 结果 |
|
||||||
|
| --- | --- |
|
||||||
|
| 两个额外列「供应商」「备注」 | 保存 1 行、失败 0 行、警告 2 项。详情逐列列名,任务事件记录同一组警告 |
|
||||||
|
| 现场 B3 `extra_column` | 保存 1 行、失败 0 行、警告 1 项。详情保留该列名 |
|
||||||
|
| 用「新料号编码」替换必需的「新料号」 | 指出缺少「新料号」,并建议将「新料号编码」改为「新料号」 |
|
||||||
|
| 缺少「新料号」 | 指出具体缺失项 |
|
||||||
|
| 表头公式与额外列中的数据公式 | 分别拒绝表头公式和第 2 行公式 |
|
||||||
|
| 原模板 | 保存 1 行、失败 0 行,无警告 |
|
||||||
|
|
||||||
|
BOM 草稿导入时未启动工程位号采集。回归还检查了由监督子进程返回的真实预览报告能携带同样的警告。包含现场工作簿重放的定向回归共通过 110 项。
|
||||||
|
|
||||||
|
## 复跑
|
||||||
|
|
||||||
|
在仓库根目录运行。现场文件从工单附件 `05_实测证据/paper2_bom` 解出。普通回归可省略 `DX_ISSUE33_D5_FIELD`,此时跳过现场文件重放。
|
||||||
|
|
||||||
|
```powershell
|
||||||
|
$env:PYTHONUTF8 = '1'
|
||||||
|
$env:PYTHONPATH = (Resolve-Path src).Path
|
||||||
|
$env:DX_ISSUE33_D5_FIELD = 'C:/path/to/INVALID_C1_bad_header_extra_col.xlsx'
|
||||||
|
python -m pytest -q -s tests/v1_1/test_bom_header_feedback.py tests/v1_1/test_bom_import_report.py tests/v1_1/test_bom_pending.py tests/v1_1/test_bom_sources_supervision.py tests/trial_task_center/test_bom_import_review.py tests/trial_task_center/test_item_value_and_bom_sources.py
|
||||||
|
```
|
||||||
@@ -0,0 +1,26 @@
|
|||||||
|
# Issue #33 D6 · DxDataBook 加载失败验证
|
||||||
|
|
||||||
|
现场 `WIFI_RTL8723DU` 的 `LWB01` 在加载目标 `4885-S018D0-M220` 时超时。原报告记录了可见列表窗口,阶段为 `preflight`,本项写入凭据为 `prepared`。同代次此前的项已有写入凭据,项目进入保留和对账流程。类似的失败也出现在 `BOB` 与 `BOB_SHIELD` 的目标 `4885-S033D0-M220` 上。现场空标题窗口 `10750260` 属于同批后续 `WIFI_RTL8192FC` 会话的启动阶段。它与 `LWB01` 超时分属不同 CAD 进程和代次。现场日志能定位超时阶段及保留原因,库服务状态和窗口复建情况仍待同代次采样。
|
||||||
|
|
||||||
|
加载阶段根据 DxDataBook 控件是否已存在采用 45 秒或 20 秒窗口。加载过程重新发现同一窗口下的列表与筛选器,控件重建后重发筛选并重新验证行稳定性。超时前写下本项凭据状态,超时后至多重试一次。重试要求本项仍有身份匹配的 `prepared` 凭据。空窗口处理进一步要求窗口在本次浏览后出现,属于同一 CAD 进程、线程和替换对话框,且替换对话框已被禁用。窗口和子控件证据先写盘,随后才发送关闭消息并观察结果。替换提交、属性恢复和保存继续使用既有的写入凭据与关闭检查点。
|
||||||
|
|
||||||
|
## Windows 验证
|
||||||
|
|
||||||
|
| 场景 | 观测结果 |
|
||||||
|
| --- | --- |
|
||||||
|
| 冷加载列表重建注入 | 原列表 `10` 更新为 `20`,筛选器从 `11` 切换到 `21`,稳定性窗口重新计时,最终使用新列表。 |
|
||||||
|
| 控件枚举与访问之间发生重建 | 筛选消息返回 Win32 `1400`,或列表读取返回 UIA `0x80040201`。两种故障都在当前加载时限内重取控件,访问新筛选器并选中正确的行。 |
|
||||||
|
| 真实 Win32 空窗口,凭据 `prepared` | 私有桌面创建的 HWND `19728876` 属于替换对话框,保存窗口树后只关闭该窗口。加载重试一次后返回目标,原有同 PID 无关窗口仍打开,凭据仍为 `prepared`。 |
|
||||||
|
| 真实 Win32 空窗口,凭据 `mutation_possible` | 窗口 `1183362` 具备同样的结构和归属,仅留下诊断。未重试,窗口与写入凭据均保留。 |
|
||||||
|
| 先前已有暂存写入,当前项失败 | Windows `cscript.exe` 执行生产 VBS 清理过程。当前未写且无暂存项时经过原始状态核验并以 `SaveChanges=False` 关闭。已有前项暂存写入、当前项写入状态无法确认或保存已请求时,保留工程供对账。 |
|
||||||
|
|
||||||
|
真实 HWND 注入运行生产窗口检查和加载重试代码,测试用 Win32 窗口模拟 DxDataBook 的无按钮提示。测试将等待时间缩短到 1.5 秒,筛选响应由测试控制。原始诊断见 [prepared.json](evidence/2026-11-25-issue33-d6/prepared.json) 和 [mutation_possible.json](evidence/2026-11-25-issue33-d6/mutation_possible.json)。
|
||||||
|
|
||||||
|
另一组注入使用原生 ListView、Edit、UIA 行读取和消息驱动生产 `run_native`,CAD COM 属性与菜单资源由替身提供。先销毁筛选框触发 Win32 `1400`,再销毁列表触发 UIA `0x80040201`。程序复取新列表和筛选器,扫描两行后命中精确料号。提交回调只触发一次并读到持久化状态 `mutation_possible`。只有相似料号的对照执行两次筛选后超时,提交数为零,凭据仍为 `prepared`。 [精确命中](evidence/2026-11-25-issue33-d6/native-controls-positive.json) [没有精确命中](evidence/2026-11-25-issue33-d6/native-controls-negative.json)
|
||||||
|
|
||||||
|
定向回归 114 项通过,包含加载、窗口归属、写入凭据、VBS 失败收尾和现有目标 Cell 路径。另执行扩展集成测试时,丢失 UID 的旧测试出现保存回读证明缺失,用 `origin/main` 的原始 VBS 同例复现。
|
||||||
|
|
||||||
|
## 真实工程副本
|
||||||
|
|
||||||
|
- 现场备份 `WIFI_RTL8723DU` 使用本机 `Skyworth_Lib` 中央库替代现场 `S:\mentor_lib.lmc`,BOM 核验找到 `LWB01` 并确认 UID。执行停在 `open_project` 249 秒,回到 `open_sheet` 安全边界时停止,关闭检查点仍观测到工程打开。写入凭据为 `prepared`,工程保护标记保留。此次在进入 DxDataBook 前结束,现场目标件换料及保存回读尚待验证。 [现场副本记录](evidence/2026-11-25-issue33-d6/field-copy.json)
|
||||||
|
- `Audio_D2128` 副本上,`RV05` 从 `4100-CA0000-T7` 换为 `4100-CA0000-T0`。已存在的 DxDataBook 控件在 2.703 秒内返回目标。原生替换报告成功,保存请求和返回各一次,工程完成关闭及重新读取,状态为 `saved_ok/project_committed`,独立网表比对为 `verified`。关闭整个 CAD 进程时超出 15 秒并触发资源释放保护标记,任务目录未产生业务不确定标记。 [正常副本记录](evidence/2026-11-25-issue33-d6/normal-copy.json)
|
||||||
@@ -0,0 +1,14 @@
|
|||||||
|
# Issue #33 D7 · 已保存工程的资源收尾验证
|
||||||
|
|
||||||
|
Audio_D2128 历史副本的 `RV05` 换料已保存并通过独立网表核验。Quit 助手退出码为 0,CAD 根进程 15 秒内未退出。执行自有 Job 强退后,Job 活动进程数降到 0,两条后代进程的退出句柄已核验,根进程句柄在随后 5 秒内仍未发出信号。批次保留了根进程的创建时间和强退记录,桌面还未进入关闭阶段。首次失败后,运行时缺少自动复核这一迟到的退出结果的路径。
|
||||||
|
|
||||||
|
运行时在已请求强退的收尾失败后等待 0.5、1、2 秒,最多复核三次原有进程树。进程树仍活跃时保留原句柄与阻塞,确认退出时再收尾该代桌面。Windows 进程已收到强退请求后只等待原句柄。已保存工程的任务状态和独立网表回执继续作为业务证据。
|
||||||
|
|
||||||
|
历史记录通过 PID 和创建时间确认写进程退出,还要求自有清理记录或绑定到该代 CAD 的空 Job 证明。桌面存在性通过枚举核验。同名受管理桌面经槽位互斥锁检查,新的活动租约在观察期间保持运行。资源记录和业务保护独立持久化。启动和批次收尾的自动观察耗尽后保留已有保护,下一次资源清理可重新取证。
|
||||||
|
|
||||||
|
## Windows 证据
|
||||||
|
|
||||||
|
- 用原始受阻历史数据的独立副本运行资源清理。槽位锁内确认桌面已经消失,六个已绑定进程均退出,批次由 `blocked` 更新为 `released`。比较前后 SHA-256,任务状态、保存回读、独立网表、关闭检查点和原有 `uncertain.flag` 保持逐字节一致。 [历史副本记录](evidence/2026-11-25-issue33-d7/historical.json)
|
||||||
|
- 用真实 Win32 私有桌面和独立 Job 验证晚退出。故障注入使 CAD 收尾在子进程实际退出前返回异常,之后自动等待并证明原进程退出,随后退还同一租约。原异常和注入的强退诊断均保留。外部持有者场景确认外部进程存活,桌面先保持隔离,外部持有者退出后复核到物理释放。 [晚退出](evidence/2026-11-25-issue33-d7/delayed-owned-exit.json) [外部持有](evidence/2026-11-25-issue33-d7/external-reference.json)
|
||||||
|
- 真实 Mentor 7.9.5 空闲会话运行正常退出。Quit 助手和 CAD 根进程的退出码均为 0,约 4.375 秒完成关停,桌面释放后资源待处理数为 0。 [正常退出](evidence/2026-11-25-issue33-d7/mentor-idle.json)
|
||||||
|
- 新建的 Audio_D2128 真实 Mentor 对照在本机完成 BOM 位号核验,执行时停在 `open_project` 276 秒,到 `open_sheet` 安全检查点才返回。工程仍打开,任务保持保护。本轮未在该副本复现保存后的 Mentor 退出,保存侧证据来自上述真实历史数据。
|
||||||
@@ -0,0 +1,21 @@
|
|||||||
|
# Issue #33 D8 · 原批次资源恢复验证
|
||||||
|
|
||||||
|
现场 100 工程按同一个任务队列执行。第 10 项已经隔离,第 11 项留下业务阻断回执,原队列仍有 89 项待派发。后台资源复核完成后,应用界面更新了资源状态,队列执行入口未再次读取原检查点。现场归档队列编号为 `55e1032ac965453b8adf307da1400511`。
|
||||||
|
|
||||||
|
候选在延续执行前核对监督进程与结束回执、原始请求摘要、队列编号、有序任务范围和计划哈希。现有写入资源和监督进程须通过释放核验。新暂停记录保存每个工程的写入源,恢复时重新读取工程声明,源不明确或变更时保留暂停。已经出具结果待核验回执的工程与共享其写入源的后续工程继续隔离。队列租约内消费原暂停记录并保存隔离状态,防止重复接续。同一用户授权运行可在资源释放后继续,用户主动暂停仍走原确认流程。
|
||||||
|
|
||||||
|
| Windows 场景 | 验证结果 |
|
||||||
|
| --- | --- |
|
||||||
|
| D7 基线,100 工程 | Windows 写进程退出后,首次返回 9 项完成、2 项阻断、89 项待执行。 [基线记录](evidence/2026-11-25-issue33-d8/baseline-100.json) |
|
||||||
|
| D8 候选,100 工程 | 写进程存活时,89 项仍待执行。退出后原队列自动继续,最终 97 项完成、3 项阻断。第 10、11 项各保留一条待核验回执,第 12 项共享数据库且零次替换派发。成功项各保存一次。 [候选记录](evidence/2026-11-25-issue33-d8/candidate-100.json) |
|
||||||
|
| D8 候选,8 工程 | 人工在第 3 项保存后暂停,保留 5 项待执行。启动不同 PID 的 Python 进程,以同一队列及冻结计划恢复到 8 项完成。每个作业 ID 仅派发一次。 [重启记录](evidence/2026-11-25-issue33-d8/candidate-8-restart.json) |
|
||||||
|
|
||||||
|
夹具使用生产任务服务、队列、SQLite、监督协议和 Windows 进程退出检查。CAD 替换与保存结果使用故障注入回执。验收覆盖调度和恢复路径,真实 Mentor 批量替换另有实机环境依赖。
|
||||||
|
|
||||||
|
```powershell
|
||||||
|
$env:PYTHONPATH = (Resolve-Path src).Path
|
||||||
|
py -3.12 tools/verify_issue33_queue.py --projects 100 --output <新候选目录>
|
||||||
|
py -3.12 tools/verify_issue33_queue.py --projects 8 --output <新暂停目录>
|
||||||
|
```
|
||||||
|
|
||||||
|
将 `PYTHONPATH` 指向 D7 基线源码,并在 100 项命令追加 `--expect-baseline`,即可复跑基线。输出目录首次运行时应当不存在。
|
||||||
@@ -0,0 +1,71 @@
|
|||||||
|
{
|
||||||
|
"verification_method": "Full main/UI run plus focused reruns for amended behavior; not a second whole-suite run.",
|
||||||
|
"unique_verified_cases": 2438,
|
||||||
|
"unresolved_failures": 0,
|
||||||
|
"junit_sha256": {
|
||||||
|
"final-regression.xml": "3e06b8c07bb057a039d67ce62eb2dcc133a52c0a24af1158c0f32cb8658dc277",
|
||||||
|
"root-delta.xml": "9124ddb63d063f4c07319e83541d4b8da2dfe0376d03ba4307568e8631d98f00",
|
||||||
|
"lifecycle-delta.xml": "1a753e128f82aad2c93ac6a56ff02201141bb7a2df178066d4376d8252a4cdb5",
|
||||||
|
"project-recovery-delta.xml": "a6834285d840263bcddd908d86594c9f742f696490a52bb2b2b382e4c7ffecaf",
|
||||||
|
"identity-final-delta.xml": "7990ce9459db3dec29c3ddbec3b6080569f5c527f3240bc8d896bb659e34329c",
|
||||||
|
"lifecycle-deleted-delta.xml": "fbdc727e207b747f5d4f95db437e04f573572fe74828d9d85dc9f3c6ad1fc445"
|
||||||
|
},
|
||||||
|
"real_mentor": {
|
||||||
|
"verified": true,
|
||||||
|
"real_mentor": true,
|
||||||
|
"targets": [
|
||||||
|
"RL02",
|
||||||
|
"RL05"
|
||||||
|
],
|
||||||
|
"native_inventory_readback_targets": 13,
|
||||||
|
"source_unchanged": true,
|
||||||
|
"source_files": 34,
|
||||||
|
"save_calls": 1,
|
||||||
|
"project_open_calls": 2,
|
||||||
|
"worker_starts": 1,
|
||||||
|
"saved_items": 2,
|
||||||
|
"operations": [
|
||||||
|
[
|
||||||
|
"verified",
|
||||||
|
1
|
||||||
|
],
|
||||||
|
[
|
||||||
|
"verified",
|
||||||
|
1
|
||||||
|
]
|
||||||
|
],
|
||||||
|
"project_commits": [
|
||||||
|
[
|
||||||
|
"verified"
|
||||||
|
]
|
||||||
|
],
|
||||||
|
"queue_seconds": 1450.341202999989,
|
||||||
|
"independent_readback_seconds": 1.5047315999981947,
|
||||||
|
"resource_state": "released",
|
||||||
|
"forced_termination": false,
|
||||||
|
"limitation": "Two replacement items on one copied project; concurrent tests/build affected timing; no speedup claim."
|
||||||
|
},
|
||||||
|
"review_reports": [
|
||||||
|
"identity-review.md",
|
||||||
|
"progress-review.md",
|
||||||
|
"lifecycle-review.md",
|
||||||
|
"final-review.md"
|
||||||
|
],
|
||||||
|
"candidate_published": false,
|
||||||
|
"packaged_source_verification": {
|
||||||
|
"passed": true,
|
||||||
|
"compiled_application_modules": 162,
|
||||||
|
"mismatches": [],
|
||||||
|
"executable_sha256": "4b19948b6a008912851f3ab674afa361bf4a28de4b74f20d3d04b80719200cc1",
|
||||||
|
"full_harness_present": true
|
||||||
|
},
|
||||||
|
"packaged_runtime_verification": {
|
||||||
|
"passed": true,
|
||||||
|
"frozen_supervisor": true,
|
||||||
|
"win32timezone_archived": true,
|
||||||
|
"process_creation_time_read": true,
|
||||||
|
"resources_released": true,
|
||||||
|
"executable": "D:\\CodexValidation\\batch-closure-20261117\\candidate\\dist\\DxPartReplace\\DxPartReplace.exe",
|
||||||
|
"data_root": "D:\\CodexValidation\\batch-closure-20261117\\candidate\\runtime-smoke"
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,17 @@
|
|||||||
|
# Issue #33 D1 同数据目录单实例
|
||||||
|
|
||||||
|
`application.main` 原先直接配置日志、打开 `task-center.db` 并执行启动恢复。现场 `data_lock` 日志有两次同根 `application_start`,两实例均成功读取任务列表。现有执行租约只在执行操作中生效。
|
||||||
|
|
||||||
|
GUI 现在先取得 `.gui-instance.lock` 的内核文件锁,再打开日志和数据库。第二次启动经 Qt 本地套接字请求激活现有窗口,该窗口写入 `instance_conflict` 并在状态栏提示。锁保持到 SQLite 和后台读线程关闭,进程强制结束时由操作系统回收。启动参数中的工作进程和 CLI 在 GUI 文件锁之前分流。
|
||||||
|
|
||||||
|
## Windows 复测
|
||||||
|
|
||||||
|
```powershell
|
||||||
|
$env:QT_QPA_PLATFORM = 'offscreen'
|
||||||
|
python -m pytest -q tests/v1_1/test_single_instance.py
|
||||||
|
```
|
||||||
|
|
||||||
|
- 四个真实 GUI 子进程并发打开同一目录,其中两个使用大写路径。日志有一次 `application_start`、一次启动恢复和三次 `instance_conflict`,三个转发进程均返回 0。
|
||||||
|
- 另一个数据目录的窗口与持锁窗口同时存活。同根 `--native-helper` 执行自身参数校验并返回 2,冲突计数仍为三次。
|
||||||
|
- 强制结束持锁进程后,同根 `--smoke-test` 成功启动并正常关闭,预先写入的任务 ID 仍在 SQLite。另一数据目录的进程继续运行。
|
||||||
|
- 修改前运行同一并发场景时,三个竞争进程没有退出,测试失败。测试使用 Qt offscreen,验证激活请求已处理。Windows 桌面前台切换和实际 CAD 写入需通过交互式验收复核。
|
||||||
@@ -0,0 +1,21 @@
|
|||||||
|
# Issue #33 D3 主窗口布局恢复
|
||||||
|
|
||||||
|
原来的 `ui-layout.ini` 只保存分栏、表头与排序,`TrialTaskCenterWindow` 每次启动都会重用默认窗口尺寸。复现时,保存进程关闭前的普通窗口为 `(45, 55, 1200, 760)` 且已最大化,重启后普通窗口变为 `(2, 2, 1280, 880)` 且未最大化。
|
||||||
|
|
||||||
|
正常接受关闭后,现通过 Qt `saveGeometry()` 持久化普通窗口几何和最大化状态。启动时调用 `restoreGeometry()`。若配置损坏、DPI 改变导致 Qt 拒绝恢复,或普通窗口超出当前可用屏幕,窗口会在当前可用屏幕内重新定位,并保留产品定义的最小尺寸。
|
||||||
|
|
||||||
|
## Windows 原生窗口实测
|
||||||
|
|
||||||
|
```powershell
|
||||||
|
$env:QT_QPA_PLATFORM = 'windows'
|
||||||
|
python -m pytest -q -s tests/v1_1/test_window_geometry.py
|
||||||
|
```
|
||||||
|
|
||||||
|
| 场景 | 结果 |
|
||||||
|
| --- | --- |
|
||||||
|
| 正常退出并启动新进程 | 普通窗口几何保持 `(45, 55, 1200, 760)`,最大化状态保持为真 |
|
||||||
|
| 新进程设 `QT_SCALE_FACTOR=1.5` | 普通窗口回退为 `(8, 36, 1008, 700)`,窗口位于可用屏幕,采用普通状态 |
|
||||||
|
| 配置值为错误类型或截断的字节 | 窗口仍能打开,普通窗口位置可达 |
|
||||||
|
| 配置保存位置为 `(50000, 50000)` | 窗口回到可用屏幕 |
|
||||||
|
|
||||||
|
测试通过 4 项。屏外场景用坐标模拟显示器移除,DPI 变化由 Qt 环境设置触发。
|
||||||
@@ -0,0 +1,36 @@
|
|||||||
|
{
|
||||||
|
"mode": "field",
|
||||||
|
"environment": "Windows, DxDesigner 7.9.5, source runtime",
|
||||||
|
"library_mapping": "Skyworth_Lib",
|
||||||
|
"library_lmc_unchanged": true,
|
||||||
|
"project": "WIFI_RTL8723DU.prj",
|
||||||
|
"request_old_new_refdes": [
|
||||||
|
"483C-S018D0-M210",
|
||||||
|
"4885-S018D0-M220",
|
||||||
|
"LWB01"
|
||||||
|
],
|
||||||
|
"attempt": {
|
||||||
|
"session_id": "bf846ff076254e5fbb3bc7ccf1ee859d",
|
||||||
|
"generation": 1,
|
||||||
|
"attempt_id": "44a747ec3c5d440fb60d5a2a407b8037",
|
||||||
|
"job_id": "08d6ebdc6cc540f7b2296a2ef737947a_0",
|
||||||
|
"state": "prepared"
|
||||||
|
},
|
||||||
|
"native": [],
|
||||||
|
"status_log": [
|
||||||
|
"job_id\tstate\tcode\tmessage"
|
||||||
|
],
|
||||||
|
"operation_log_excerpt": [
|
||||||
|
"2026/11/25 9:57:21\tINFO\tstage=open_project target=<copy-root>\\project\\WIFI_RTL8723DU.prj",
|
||||||
|
"2026/11/25 10:01:30\tERROR\tstage=open_sheet number=-2147220644 source=QuickPartReplace.SafeStop description=stopped at a safe boundary before native mutation after inactivity; prewrite pause closure was not proven: %7F3A%5C11%5BF9%8C61",
|
||||||
|
"quick_run_uncertain monitor_failure error=project close checkpoint failed: owned CAD still has a project open; no implicit save or discard\\r\\n"
|
||||||
|
],
|
||||||
|
"independent_verification": [
|
||||||
|
"not_completed"
|
||||||
|
],
|
||||||
|
"uncertain_flags_relative_to_data_root": [
|
||||||
|
"batch-resources/bf846ff076254e5fbb3bc7ccf1ee859d/generation-1/uncertain.flag",
|
||||||
|
"tasks/546160ef-0e8f-4b15-8394-e35f8c562366/quick-run/uncertain.flag"
|
||||||
|
],
|
||||||
|
"queue_outcome": "project remained open at the close checkpoint"
|
||||||
|
}
|
||||||
@@ -0,0 +1,33 @@
|
|||||||
|
[
|
||||||
|
{
|
||||||
|
"stage": "preflight",
|
||||||
|
"databook": {
|
||||||
|
"loads": [
|
||||||
|
{
|
||||||
|
"mode": "warm",
|
||||||
|
"timeout_seconds": 20,
|
||||||
|
"attempt_state_before_load": "mutation_possible",
|
||||||
|
"list_handle": 17,
|
||||||
|
"filter_handle": 18,
|
||||||
|
"error": "Native DxDataBook did not finish loading target part: NEW",
|
||||||
|
"elapsed_seconds": 1.594,
|
||||||
|
"dialogs": [
|
||||||
|
{
|
||||||
|
"hwnd": 1183362,
|
||||||
|
"owner": 200514,
|
||||||
|
"pid": 56180,
|
||||||
|
"title": "",
|
||||||
|
"children": [],
|
||||||
|
"browser": false,
|
||||||
|
"dismissible": true
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"attempt_state": "mutation_possible",
|
||||||
|
"retry": false
|
||||||
|
}
|
||||||
|
]
|
||||||
|
},
|
||||||
|
"window_closed": [],
|
||||||
|
"marker_state": "mutation_possible"
|
||||||
|
}
|
||||||
|
]
|
||||||
@@ -0,0 +1,91 @@
|
|||||||
|
{
|
||||||
|
"attempt": "prepared",
|
||||||
|
"events": [
|
||||||
|
{
|
||||||
|
"controls": [
|
||||||
|
21630720,
|
||||||
|
528470
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"edit_hwnd": 528470,
|
||||||
|
"text": "NEW"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"read_list": 21630720,
|
||||||
|
"row_count": 1
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"read_list": 21630720,
|
||||||
|
"row_count": 1
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"edit_hwnd": 528470,
|
||||||
|
"text": "NEW"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"read_list": 21630720,
|
||||||
|
"row_count": 1
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"read_list": 21630720,
|
||||||
|
"row_count": 1
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"report": {
|
||||||
|
"native_command": {
|
||||||
|
"id": 33977,
|
||||||
|
"executable": "C:\\Users\\ABS_Windows\\AppData\\Local\\Programs\\Python\\Python312\\python.exe",
|
||||||
|
"trigger": "resource_command"
|
||||||
|
},
|
||||||
|
"native_options": {
|
||||||
|
"1704": {
|
||||||
|
"text": "Option",
|
||||||
|
"checked": true
|
||||||
|
},
|
||||||
|
"1105": {
|
||||||
|
"text": "Option",
|
||||||
|
"checked": true
|
||||||
|
},
|
||||||
|
"1697": {
|
||||||
|
"text": "Option",
|
||||||
|
"checked": true
|
||||||
|
},
|
||||||
|
"1700": {
|
||||||
|
"text": "Option",
|
||||||
|
"checked": true
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"databook": {
|
||||||
|
"main_visible_before_browse": true,
|
||||||
|
"browse_button": 3017658,
|
||||||
|
"loads": [
|
||||||
|
{
|
||||||
|
"mode": "cold",
|
||||||
|
"timeout_seconds": 45,
|
||||||
|
"attempt_state_before_load": "prepared",
|
||||||
|
"list_handle": 21630720,
|
||||||
|
"filter_handle": 528470,
|
||||||
|
"error": "Native DxDataBook did not finish loading target part: NEW",
|
||||||
|
"elapsed_seconds": 3.437,
|
||||||
|
"dialogs": [],
|
||||||
|
"attempt_state": "prepared",
|
||||||
|
"retry": true
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"mode": "warm",
|
||||||
|
"timeout_seconds": 20,
|
||||||
|
"attempt_state_before_load": "prepared",
|
||||||
|
"list_handle": 21630720,
|
||||||
|
"filter_handle": 528470,
|
||||||
|
"error": "Native DxDataBook did not finish loading target part: NEW",
|
||||||
|
"elapsed_seconds": 3.344,
|
||||||
|
"dialogs": [],
|
||||||
|
"attempt_state": "prepared",
|
||||||
|
"retry": false
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"error": "TimeoutError('Native DxDataBook did not finish loading target part: NEW')"
|
||||||
|
}
|
||||||
@@ -0,0 +1,143 @@
|
|||||||
|
{
|
||||||
|
"attempt": "mutation_possible",
|
||||||
|
"events": [
|
||||||
|
{
|
||||||
|
"controls": [
|
||||||
|
21696256,
|
||||||
|
594006
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"controls": [
|
||||||
|
21761792,
|
||||||
|
659542
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"dead_edit": 594006,
|
||||||
|
"winerror": 1400
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"edit_hwnd": 659542,
|
||||||
|
"text": "NEW"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"read_list": 21761792,
|
||||||
|
"row_count": 2
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"controls": [
|
||||||
|
21827328,
|
||||||
|
725078
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"dead_ui_list": 21761792,
|
||||||
|
"hresult": -2147220991,
|
||||||
|
"exception": "COMError(-2147220991, '\u4e8b\u4ef6\u65e0\u6cd5\u8c03\u7528\u4efb\u4f55\u8ba2\u6237', (None, None, None, 0, None))"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"edit_hwnd": 725078,
|
||||||
|
"text": "NEW"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"read_list": 21827328,
|
||||||
|
"row_count": 2
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"read_list": 21827328,
|
||||||
|
"row_count": 2
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"submit": "mutation_possible"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"report": {
|
||||||
|
"native_command": {
|
||||||
|
"id": 33977,
|
||||||
|
"executable": "C:\\Users\\ABS_Windows\\AppData\\Local\\Programs\\Python\\Python312\\python.exe",
|
||||||
|
"trigger": "resource_command"
|
||||||
|
},
|
||||||
|
"native_options": {
|
||||||
|
"1704": {
|
||||||
|
"text": "Option",
|
||||||
|
"checked": true
|
||||||
|
},
|
||||||
|
"1105": {
|
||||||
|
"text": "Option",
|
||||||
|
"checked": true
|
||||||
|
},
|
||||||
|
"1697": {
|
||||||
|
"text": "Option",
|
||||||
|
"checked": true
|
||||||
|
},
|
||||||
|
"1700": {
|
||||||
|
"text": "Option",
|
||||||
|
"checked": true
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"databook": {
|
||||||
|
"main_visible_before_browse": true,
|
||||||
|
"browse_button": 3017658,
|
||||||
|
"loads": [
|
||||||
|
{
|
||||||
|
"mode": "warm",
|
||||||
|
"timeout_seconds": 20,
|
||||||
|
"attempt_state_before_load": "prepared",
|
||||||
|
"list_handle": 21827328,
|
||||||
|
"filter_handle": 725078,
|
||||||
|
"elapsed_seconds": 6.125
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"list_handle": 21827328,
|
||||||
|
"list_visible": true,
|
||||||
|
"main_visible_after_load": true
|
||||||
|
},
|
||||||
|
"library_row": [
|
||||||
|
"DATA",
|
||||||
|
"NEW",
|
||||||
|
"LIB:EXACT",
|
||||||
|
"",
|
||||||
|
"Exact",
|
||||||
|
"Target"
|
||||||
|
],
|
||||||
|
"slot_count": 1,
|
||||||
|
"row_rectangle": [
|
||||||
|
157,
|
||||||
|
398,
|
||||||
|
769,
|
||||||
|
422
|
||||||
|
],
|
||||||
|
"list_handle": 21827328,
|
||||||
|
"target_text": "NEW",
|
||||||
|
"symbol_text": "LIB:EXACT",
|
||||||
|
"target_submit_enabled": true,
|
||||||
|
"transaction": {
|
||||||
|
"snapshot_sha256": "d36e0c485331eac7b3c0d25de6dbfc5e915b761dd7eb738caf49b69d89640daa",
|
||||||
|
"project_path": "g:\\dx33\\acceptance\\d6-native-controls-03\\positive\\synthetic.prj",
|
||||||
|
"sheet_identity": "MAIN:1",
|
||||||
|
"old_part_number": "OLD",
|
||||||
|
"new_part_number": "NEW",
|
||||||
|
"source_uids": [
|
||||||
|
"uid"
|
||||||
|
],
|
||||||
|
"target_selectors": null,
|
||||||
|
"library_row": [
|
||||||
|
"DATA",
|
||||||
|
"NEW",
|
||||||
|
"LIB:EXACT",
|
||||||
|
"",
|
||||||
|
"Exact",
|
||||||
|
"Target"
|
||||||
|
],
|
||||||
|
"target_symbol": "LIB:EXACT",
|
||||||
|
"slot_count": 1
|
||||||
|
},
|
||||||
|
"stage": "native_replace_verified",
|
||||||
|
"replaced_uids": [
|
||||||
|
"uid"
|
||||||
|
],
|
||||||
|
"promoted_pins": []
|
||||||
|
},
|
||||||
|
"error": null
|
||||||
|
}
|
||||||
@@ -0,0 +1,78 @@
|
|||||||
|
{
|
||||||
|
"mode": "normal",
|
||||||
|
"environment": "Windows, DxDesigner 7.9.5, source runtime",
|
||||||
|
"library_mapping": "Skyworth_CBB_Lib",
|
||||||
|
"library_lmc_unchanged": true,
|
||||||
|
"project": "Audio_D2128.prj",
|
||||||
|
"request_old_new_refdes": [
|
||||||
|
"4100-CA0000-T7",
|
||||||
|
"4100-CA0000-T0",
|
||||||
|
"RV05"
|
||||||
|
],
|
||||||
|
"attempt": {
|
||||||
|
"session_id": "588db35caf664589a499f02800559ff0",
|
||||||
|
"generation": 1,
|
||||||
|
"attempt_id": "65d0375a0a3e4e02a0e0225f5cd7da1d",
|
||||||
|
"job_id": "3fd4cca09997419cbf0850fe2907f1b5_0",
|
||||||
|
"state": "mutation_possible"
|
||||||
|
},
|
||||||
|
"native": [
|
||||||
|
{
|
||||||
|
"ok": true,
|
||||||
|
"stage": "native_replace_applied",
|
||||||
|
"databook": {
|
||||||
|
"main_visible_before_browse": true,
|
||||||
|
"browse_button": 1577092,
|
||||||
|
"loads": [
|
||||||
|
{
|
||||||
|
"mode": "warm",
|
||||||
|
"timeout_seconds": 20,
|
||||||
|
"attempt_state_before_load": "prepared",
|
||||||
|
"list_handle": 266464,
|
||||||
|
"filter_handle": 266532,
|
||||||
|
"elapsed_seconds": 2.703
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"list_handle": 266464,
|
||||||
|
"list_visible": true,
|
||||||
|
"main_visible_after_load": true
|
||||||
|
},
|
||||||
|
"library_row": [
|
||||||
|
"RESISTOR",
|
||||||
|
"4100-CA0000-T0",
|
||||||
|
"skyworth:res01",
|
||||||
|
"unassigned",
|
||||||
|
"RESC1608N",
|
||||||
|
"0R",
|
||||||
|
""
|
||||||
|
],
|
||||||
|
"replaced_uids": [
|
||||||
|
"$2I2014"
|
||||||
|
],
|
||||||
|
"pin_promotion_phase": "promotion_complete"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"status_log": [
|
||||||
|
"job_id\tstate\tcode\tmessage",
|
||||||
|
"3fd4cca09997419cbf0850fe2907f1b5_0\tawaiting_native_replace\t\tSnapshot captured; automatic native replacement is starting.",
|
||||||
|
"3fd4cca09997419cbf0850fe2907f1b5_0\tpending_save\tsession_staged\tWrites staged; awaiting engineering project save and saved native data verification.",
|
||||||
|
"3fd4cca09997419cbf0850fe2907f1b5_0\tpending_save\tproject_saved\tEngineering project saved and closed; awaiting saved native data verification.",
|
||||||
|
"3fd4cca09997419cbf0850fe2907f1b5_0\tsaved_ok\tproject_committed\t%5DE5%7A0B%7EDF%4E00%4FDD%5B58%FF0C%539F%751F%6570%636E%6838%9A8C%901A%8FC7%3002"
|
||||||
|
],
|
||||||
|
"operation_log_excerpt": [
|
||||||
|
"2026/11/25 10:03:45\tINFO\tstage=open_project target=<copy-root>\\project\\Audio_D2128.prj",
|
||||||
|
"2026/11/25 10:03:59\tINFO\tstage=open_sheet schematic=Audio-D2128 sheet=S905L CVBS-LR",
|
||||||
|
"2026/11/25 10:04:49\tINFO\tnative_helper_exit code=0",
|
||||||
|
"2026/11/25 10:05:16\tINFO\treplacement RV05 4100-CA0000-T7 -> 4100-CA0000-T0",
|
||||||
|
"2026/11/25 10:05:17\tINFO\tsave_requested job=3fd4cca09997419cbf0850fe2907f1b5_0",
|
||||||
|
"2026/11/25 10:05:17\tINFO\tsave_returned job=3fd4cca09997419cbf0850fe2907f1b5_0",
|
||||||
|
"2026/11/25 10:05:22\tINFO\tproject_closed job=3fd4cca09997419cbf0850fe2907f1b5_0"
|
||||||
|
],
|
||||||
|
"independent_verification": [
|
||||||
|
"verified"
|
||||||
|
],
|
||||||
|
"uncertain_flags_relative_to_data_root": [
|
||||||
|
"batch-resources/588db35caf664589a499f02800559ff0/generation-1/uncertain.flag"
|
||||||
|
],
|
||||||
|
"queue_outcome": "CAD exit exceeded 15 seconds during batch resource cleanup after the saved business receipt"
|
||||||
|
}
|
||||||
@@ -0,0 +1,44 @@
|
|||||||
|
[
|
||||||
|
{
|
||||||
|
"stage": "preflight",
|
||||||
|
"databook": {
|
||||||
|
"loads": [
|
||||||
|
{
|
||||||
|
"mode": "warm",
|
||||||
|
"timeout_seconds": 20,
|
||||||
|
"attempt_state_before_load": "prepared",
|
||||||
|
"list_handle": 17,
|
||||||
|
"filter_handle": 18,
|
||||||
|
"error": "Native DxDataBook did not finish loading target part: NEW",
|
||||||
|
"elapsed_seconds": 1.547,
|
||||||
|
"dialogs": [
|
||||||
|
{
|
||||||
|
"hwnd": 19728876,
|
||||||
|
"owner": 134972,
|
||||||
|
"pid": 5004,
|
||||||
|
"title": "",
|
||||||
|
"children": [],
|
||||||
|
"browser": false,
|
||||||
|
"dismissible": true
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"attempt_state": "prepared",
|
||||||
|
"retry": true,
|
||||||
|
"closed_dialog": 19728876
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"mode": "warm",
|
||||||
|
"timeout_seconds": 20,
|
||||||
|
"attempt_state_before_load": "prepared",
|
||||||
|
"list_handle": 17,
|
||||||
|
"filter_handle": 18,
|
||||||
|
"elapsed_seconds": 0.187
|
||||||
|
}
|
||||||
|
]
|
||||||
|
},
|
||||||
|
"window_closed": [
|
||||||
|
19728876
|
||||||
|
],
|
||||||
|
"marker_state": "prepared"
|
||||||
|
}
|
||||||
|
]
|
||||||
@@ -0,0 +1,74 @@
|
|||||||
|
{
|
||||||
|
"state": "released",
|
||||||
|
"generation": 1,
|
||||||
|
"desktop": "dx-7f3f2f5227fc2de985373cc53acedcd9",
|
||||||
|
"release_proof": {
|
||||||
|
"session_id": "61c734f3d79d42579ca635bbdb996673",
|
||||||
|
"generation": 1,
|
||||||
|
"desktop": "dx-7f3f2f5227fc2de985373cc53acedcd9",
|
||||||
|
"desktop_handle_closed": true,
|
||||||
|
"desktop_released": true,
|
||||||
|
"processes_exited": true,
|
||||||
|
"processes": [
|
||||||
|
{
|
||||||
|
"pid": 11236,
|
||||||
|
"creation_time": "2026-11-25 02:26:52.007000+00:00"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"observed_at": 1795573613.951475,
|
||||||
|
"method": "owned_cleanup"
|
||||||
|
},
|
||||||
|
"release_rechecks": [
|
||||||
|
{
|
||||||
|
"attempt": 1,
|
||||||
|
"delay_seconds": 0.5
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"attempt": 2,
|
||||||
|
"delay_seconds": 1
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"event_timeline": [
|
||||||
|
{
|
||||||
|
"phase": "releasing",
|
||||||
|
"desktop_disappeared": null,
|
||||||
|
"release_rechecks": []
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"phase": "blocked",
|
||||||
|
"desktop_disappeared": null,
|
||||||
|
"release_rechecks": []
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"phase": "releasing",
|
||||||
|
"desktop_disappeared": null,
|
||||||
|
"release_rechecks": [
|
||||||
|
{
|
||||||
|
"attempt": 1,
|
||||||
|
"delay_seconds": 0.5
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"attempt": 2,
|
||||||
|
"delay_seconds": 1
|
||||||
|
}
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"phase": "released",
|
||||||
|
"desktop_disappeared": true,
|
||||||
|
"release_rechecks": [
|
||||||
|
{
|
||||||
|
"attempt": 1,
|
||||||
|
"delay_seconds": 0.5
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"attempt": 2,
|
||||||
|
"delay_seconds": 1
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"shutdown": {
|
||||||
|
"forced_termination": true
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,36 @@
|
|||||||
|
{
|
||||||
|
"state": "released",
|
||||||
|
"generation": 1,
|
||||||
|
"desktop": "dx-7f3f2f5227fc2de985373cc53acedcd9",
|
||||||
|
"release_proof": {
|
||||||
|
"generation": 1,
|
||||||
|
"desktop_released": true,
|
||||||
|
"processes_exited": true,
|
||||||
|
"processes": [],
|
||||||
|
"method": "restart_observation"
|
||||||
|
},
|
||||||
|
"release_rechecks": [],
|
||||||
|
"event_timeline": [
|
||||||
|
{
|
||||||
|
"phase": "releasing",
|
||||||
|
"desktop_disappeared": null,
|
||||||
|
"release_rechecks": []
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"phase": "isolated",
|
||||||
|
"desktop_disappeared": false,
|
||||||
|
"release_rechecks": []
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"phase": "releasing",
|
||||||
|
"desktop_disappeared": false,
|
||||||
|
"release_rechecks": []
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"phase": "released",
|
||||||
|
"desktop_disappeared": true,
|
||||||
|
"release_rechecks": []
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"shutdown": null
|
||||||
|
}
|
||||||
@@ -0,0 +1,88 @@
|
|||||||
|
{
|
||||||
|
"original_state": "blocked",
|
||||||
|
"confirmed_state": "released",
|
||||||
|
"desktop": "dx-7f3f2f5227fc2de985373cc53acedcd9",
|
||||||
|
"desktop_absent_under_slot_mutex": true,
|
||||||
|
"owned_root_observations": [
|
||||||
|
{
|
||||||
|
"pid": 62180,
|
||||||
|
"creation_time": "2026-11-25 02:02:37.882000+00:00",
|
||||||
|
"gone": true
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"pid": 59508,
|
||||||
|
"creation_time": "2026-11-25 02:02:38.250000+00:00",
|
||||||
|
"gone": true
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"pid": 58980,
|
||||||
|
"creation_time": "2026-11-25 02:03:40.779000+00:00",
|
||||||
|
"gone": true
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"pid": 60628,
|
||||||
|
"creation_time": "2026-11-25 02:03:43.660000+00:00",
|
||||||
|
"gone": true
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"pid": 23736,
|
||||||
|
"creation_time": "2026-11-25 02:05:22.446000+00:00",
|
||||||
|
"gone": true
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"pid": 54872,
|
||||||
|
"creation_time": "2026-11-25 02:05:44.928000+00:00",
|
||||||
|
"gone": true
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"original_shutdown": {
|
||||||
|
"orderly_shutdown": false,
|
||||||
|
"forced_termination": true,
|
||||||
|
"forced_root_termination": true,
|
||||||
|
"forced_descendant_pids": [
|
||||||
|
5216,
|
||||||
|
51620
|
||||||
|
],
|
||||||
|
"quit_helper_exit_code": 0
|
||||||
|
},
|
||||||
|
"release_proof": {
|
||||||
|
"generation": 1,
|
||||||
|
"desktop_released": true,
|
||||||
|
"processes_exited": true,
|
||||||
|
"processes": [
|
||||||
|
{
|
||||||
|
"pid": 62180,
|
||||||
|
"creation_time": "2026-11-25 02:02:37.882000+00:00"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"pid": 59508,
|
||||||
|
"creation_time": "2026-11-25 02:02:38.250000+00:00"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"pid": 58980,
|
||||||
|
"creation_time": "2026-11-25 02:03:40.779000+00:00"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"pid": 60628,
|
||||||
|
"creation_time": "2026-11-25 02:03:43.660000+00:00"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"pid": 23736,
|
||||||
|
"creation_time": "2026-11-25 02:05:22.446000+00:00"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"pid": 54872,
|
||||||
|
"creation_time": "2026-11-25 02:05:44.928000+00:00"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"method": "restart_observation"
|
||||||
|
},
|
||||||
|
"preserved_sha256": {
|
||||||
|
"batch-resources/588db35caf664589a499f02800559ff0/generation-1/uncertain.flag": "4a131c344827d0bbe9667dc5534af3d52e472737ec1d1c1c44a792c1ac66f360",
|
||||||
|
"tasks/d5810026-3117-4b2e-9eca-c16b22396dc3/quick-run/status.tsv": "2afdeacd43812445f616f89da425efe6adf565ff75052e7f587e332b70066338",
|
||||||
|
"tasks/d5810026-3117-4b2e-9eca-c16b22396dc3/execution-proof/saved-netlist-6f55dbc86cc94adeb3561dfedd30e44a/export/verification.json": "3579e55e5987f9aababe167801c127f4404511f96cc0334de663fc449990b955",
|
||||||
|
"tasks/d5810026-3117-4b2e-9eca-c16b22396dc3/netlist-checks/2af39a6d4d6143afa3352b8cbe4e4180/verification.json": "f0ed2209fa9de4c97a01da3079da1097e8ab2dc091631c625440a299e23728e3",
|
||||||
|
"tasks/d5810026-3117-4b2e-9eca-c16b22396dc3/quick-run/project-checkpoint.json": "04d6b04e85b23671b2ce92dd2adc64d673b8c3209813a148214a7322bf0e7e4a"
|
||||||
|
},
|
||||||
|
"project_descriptor_sha256_unchanged": true
|
||||||
|
}
|
||||||
@@ -0,0 +1,36 @@
|
|||||||
|
{
|
||||||
|
"state": "released",
|
||||||
|
"desktop": "dx-7f3f2f5227fc2de985373cc53acedcd9",
|
||||||
|
"shutdown": {
|
||||||
|
"state": "session_closed",
|
||||||
|
"clean": true,
|
||||||
|
"cad_exit_code": 0,
|
||||||
|
"quit_helper_exit_code": 0,
|
||||||
|
"cleanup_errors": [],
|
||||||
|
"shutdown_seconds": 4.375,
|
||||||
|
"orderly_shutdown": true,
|
||||||
|
"diagnostic_errors": [],
|
||||||
|
"forced_termination": false,
|
||||||
|
"forced_root_termination": false,
|
||||||
|
"forced_descendant_pids": [],
|
||||||
|
"termination_reason": null,
|
||||||
|
"dialog_supervision": {
|
||||||
|
"evidence_path": "G:\\dx33\\acceptance\\d7-mentor-idle\\batch-resources\\765ec10f41134b80b4d2d7a49ef01fe5\\generation-1\\cad-dialogs-408b2726a75547929b58a0f1fe3bcfbe.json",
|
||||||
|
"dialogs_seen": 2,
|
||||||
|
"blocked": false,
|
||||||
|
"blocking_titles": [],
|
||||||
|
"current_dialogs": [],
|
||||||
|
"error": "",
|
||||||
|
"monitor_error": ""
|
||||||
|
},
|
||||||
|
"release_state": "released",
|
||||||
|
"project_close_policy": "saved_only"
|
||||||
|
},
|
||||||
|
"release_results": {
|
||||||
|
"mentor_released": true,
|
||||||
|
"desktop_released": true
|
||||||
|
},
|
||||||
|
"release_rechecks": [],
|
||||||
|
"error": null,
|
||||||
|
"pending": 0
|
||||||
|
}
|
||||||
@@ -0,0 +1,80 @@
|
|||||||
|
{
|
||||||
|
"projects": 100,
|
||||||
|
"first_return": {
|
||||||
|
"completed": 9,
|
||||||
|
"blocked": 2,
|
||||||
|
"pending": 89
|
||||||
|
},
|
||||||
|
"before_release": {
|
||||||
|
"completed": 9,
|
||||||
|
"blocked": 2,
|
||||||
|
"pending": 89
|
||||||
|
},
|
||||||
|
"queue_id": "d935388f7bab4bf98c882280ec6c76a3",
|
||||||
|
"writer_pid": 56064,
|
||||||
|
"writer_gone": true,
|
||||||
|
"calls": [
|
||||||
|
{
|
||||||
|
"project": 1,
|
||||||
|
"job_id": "c959a1eba7fb46f9b22d95f9afdff465_0",
|
||||||
|
"result": "saved_ok"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"project": 2,
|
||||||
|
"job_id": "ab1fb1a7058a4b41b5886c3c01008aa7_0",
|
||||||
|
"result": "saved_ok"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"project": 3,
|
||||||
|
"job_id": "490c1abb2a9441d8b5a8d70cbe5c0aa8_0",
|
||||||
|
"result": "saved_ok"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"project": 4,
|
||||||
|
"job_id": "56b8dfaacb514a94ab506c632b37b647_0",
|
||||||
|
"result": "saved_ok"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"project": 5,
|
||||||
|
"job_id": "d0d223381b9e4a01ababa484fcc07e82_0",
|
||||||
|
"result": "saved_ok"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"project": 6,
|
||||||
|
"job_id": "abe6fa9a9919494ba433983cd125d1ac_0",
|
||||||
|
"result": "saved_ok"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"project": 7,
|
||||||
|
"job_id": "2f103677ed4347938888e03b9b26b87f_0",
|
||||||
|
"result": "saved_ok"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"project": 8,
|
||||||
|
"job_id": "5d4eeaed50bd46e89fd6830b51e8c3fb_0",
|
||||||
|
"result": "saved_ok"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"project": 9,
|
||||||
|
"job_id": "ff4f78bf6e834c758fcb0fe9382a28fe_0",
|
||||||
|
"result": "saved_ok"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"project": 10,
|
||||||
|
"job_id": "31ad660420e74b8499bd54abfbe250f5_0",
|
||||||
|
"result": "batch_saved_unverified"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"project": 11,
|
||||||
|
"job_id": "321e40d86fe147bb977ba9865c1d24b9_0",
|
||||||
|
"result": "batch_saved_unverified"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"supervisor_calls": [
|
||||||
|
{
|
||||||
|
"batch_id": "d31e906c280e4849a22a3176ced4bee0",
|
||||||
|
"queue_id": null,
|
||||||
|
"resource_batch_id": null
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
@@ -0,0 +1,542 @@
|
|||||||
|
{
|
||||||
|
"projects": 100,
|
||||||
|
"first_return": {
|
||||||
|
"completed": 97,
|
||||||
|
"blocked": 3
|
||||||
|
},
|
||||||
|
"before_release": {
|
||||||
|
"completed": 9,
|
||||||
|
"blocked": 2,
|
||||||
|
"pending": 89
|
||||||
|
},
|
||||||
|
"final": {
|
||||||
|
"completed": 97,
|
||||||
|
"blocked": 3
|
||||||
|
},
|
||||||
|
"supervisor_calls": [
|
||||||
|
{
|
||||||
|
"batch_id": "15fcc3425d5f4a9ea172b7725023dd91",
|
||||||
|
"queue_id": null,
|
||||||
|
"resource_batch_id": null
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"batch_id": "78718bb8a02147358b441c540c902899",
|
||||||
|
"queue_id": "af07e3269bcd4a08afbf064af9126123",
|
||||||
|
"resource_batch_id": "15fcc3425d5f4a9ea172b7725023dd91"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"batch_id": "862fad3b3d754c4a944135ff8256b1d8",
|
||||||
|
"queue_id": "af07e3269bcd4a08afbf064af9126123",
|
||||||
|
"resource_batch_id": null
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"batch_id": "69c5a03140bc4c5ca7d9bb52f6ff528f",
|
||||||
|
"queue_id": "af07e3269bcd4a08afbf064af9126123",
|
||||||
|
"resource_batch_id": null
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"queue_id": "af07e3269bcd4a08afbf064af9126123",
|
||||||
|
"shared_source_blocked": 12,
|
||||||
|
"writer_pid": 25028,
|
||||||
|
"release_checks": [
|
||||||
|
10,
|
||||||
|
11
|
||||||
|
],
|
||||||
|
"calls": [
|
||||||
|
{
|
||||||
|
"project": 1,
|
||||||
|
"job_id": "388bad5bafc54ae3b766a574f07feb44_0",
|
||||||
|
"result": "saved_ok"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"project": 2,
|
||||||
|
"job_id": "78c6aa3632484ef795705071c4f6871e_0",
|
||||||
|
"result": "saved_ok"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"project": 3,
|
||||||
|
"job_id": "b1e96b8625df4e8cb50f44c2faed14be_0",
|
||||||
|
"result": "saved_ok"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"project": 4,
|
||||||
|
"job_id": "1c1419a896374821ac7c51a3117b75e1_0",
|
||||||
|
"result": "saved_ok"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"project": 5,
|
||||||
|
"job_id": "df4e71b52bf842f093029d4dad56f797_0",
|
||||||
|
"result": "saved_ok"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"project": 6,
|
||||||
|
"job_id": "1fcb7b6d75f44cdcbaed93accaa1c07d_0",
|
||||||
|
"result": "saved_ok"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"project": 7,
|
||||||
|
"job_id": "6eeb02803cde4b2483ee776c9afeba1c_0",
|
||||||
|
"result": "saved_ok"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"project": 8,
|
||||||
|
"job_id": "84c54eeb256d404582eda32019de17d8_0",
|
||||||
|
"result": "saved_ok"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"project": 9,
|
||||||
|
"job_id": "05cf0fb9ad8b4c7d90d039d466de25a7_0",
|
||||||
|
"result": "saved_ok"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"project": 10,
|
||||||
|
"job_id": "7c2ea733df924c1a9e04750f22134738_0",
|
||||||
|
"result": "batch_saved_unverified"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"project": 11,
|
||||||
|
"job_id": "807cafae32bc495a894f5b35a6d1cb5e_0",
|
||||||
|
"result": "batch_saved_unverified"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"project": 13,
|
||||||
|
"job_id": "304752f4d4c64e1bbabcbf55bff365fb_0",
|
||||||
|
"result": "saved_ok"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"project": 14,
|
||||||
|
"job_id": "2040d066abc4482da2323b1b313e6e0e_0",
|
||||||
|
"result": "saved_ok"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"project": 15,
|
||||||
|
"job_id": "908898c13c47472bb6f115f4910cccf4_0",
|
||||||
|
"result": "saved_ok"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"project": 16,
|
||||||
|
"job_id": "3abda0f30178471c9af61afd5738b530_0",
|
||||||
|
"result": "saved_ok"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"project": 17,
|
||||||
|
"job_id": "6c7365afea284aa3854b66af096bd098_0",
|
||||||
|
"result": "saved_ok"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"project": 18,
|
||||||
|
"job_id": "f210b5d510344eb08f8d93ce05d001fe_0",
|
||||||
|
"result": "saved_ok"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"project": 19,
|
||||||
|
"job_id": "eaaa69c064f0433fbab3874e0b331090_0",
|
||||||
|
"result": "saved_ok"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"project": 20,
|
||||||
|
"job_id": "edc20d8c922f4bbaad379a3ce0db6891_0",
|
||||||
|
"result": "saved_ok"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"project": 21,
|
||||||
|
"job_id": "f5cdef2f94b54d7da8c9c9c730557b8e_0",
|
||||||
|
"result": "saved_ok"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"project": 22,
|
||||||
|
"job_id": "1dfc6665bfcf455e9246e212f92c689c_0",
|
||||||
|
"result": "saved_ok"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"project": 23,
|
||||||
|
"job_id": "75385b75cf9140629f9aa1022bb2c53c_0",
|
||||||
|
"result": "saved_ok"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"project": 24,
|
||||||
|
"job_id": "809cef1ba35b44d9be4ffd1dbd1ab000_0",
|
||||||
|
"result": "saved_ok"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"project": 25,
|
||||||
|
"job_id": "367c3ffd715c4ef586f2e8824bbef491_0",
|
||||||
|
"result": "saved_ok"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"project": 26,
|
||||||
|
"job_id": "bf5f3bdd3fb14fcc9740436fa464be37_0",
|
||||||
|
"result": "saved_ok"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"project": 27,
|
||||||
|
"job_id": "a60a8566d058464495773969e6a99017_0",
|
||||||
|
"result": "saved_ok"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"project": 28,
|
||||||
|
"job_id": "0c4c8103d7104788a5da9f017c0f1ace_0",
|
||||||
|
"result": "saved_ok"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"project": 29,
|
||||||
|
"job_id": "eaa9e2e922e44c39a012af2519d951cf_0",
|
||||||
|
"result": "saved_ok"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"project": 30,
|
||||||
|
"job_id": "e84022b8f6f949ddaee69e8067b9a795_0",
|
||||||
|
"result": "saved_ok"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"project": 31,
|
||||||
|
"job_id": "8ab8ba8bad0e4b859e4720d0af2d56d8_0",
|
||||||
|
"result": "saved_ok"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"project": 32,
|
||||||
|
"job_id": "0e7d3863480e4382b6b07ededa94f012_0",
|
||||||
|
"result": "saved_ok"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"project": 33,
|
||||||
|
"job_id": "fbe7d3bf153644859f9b6a785fc98d64_0",
|
||||||
|
"result": "saved_ok"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"project": 34,
|
||||||
|
"job_id": "6e1e4e3e44ad4aeeb51896837e6b84fb_0",
|
||||||
|
"result": "saved_ok"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"project": 35,
|
||||||
|
"job_id": "efe7a9fb23944560bdac2212b2154cbe_0",
|
||||||
|
"result": "saved_ok"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"project": 36,
|
||||||
|
"job_id": "50ef7be31e7740bbbf337e570690de86_0",
|
||||||
|
"result": "saved_ok"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"project": 37,
|
||||||
|
"job_id": "8696162e1e7b4169b562f5454f8ddfb0_0",
|
||||||
|
"result": "saved_ok"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"project": 38,
|
||||||
|
"job_id": "657ca58af33a4b7db33b19007e1ce071_0",
|
||||||
|
"result": "saved_ok"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"project": 39,
|
||||||
|
"job_id": "a18f78199fd74601a007e8eb9ee15433_0",
|
||||||
|
"result": "saved_ok"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"project": 40,
|
||||||
|
"job_id": "badd43d9a5624a689cc693bb7ea31652_0",
|
||||||
|
"result": "saved_ok"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"project": 41,
|
||||||
|
"job_id": "bab81db14eb54782b869252fac15e570_0",
|
||||||
|
"result": "saved_ok"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"project": 42,
|
||||||
|
"job_id": "92617c885ead4d838432c68e2255f7d0_0",
|
||||||
|
"result": "saved_ok"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"project": 43,
|
||||||
|
"job_id": "216b4cda3f4148e7bc9d75ee5be8b6cb_0",
|
||||||
|
"result": "saved_ok"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"project": 44,
|
||||||
|
"job_id": "3d57183d53304ce69933c982311b0f35_0",
|
||||||
|
"result": "saved_ok"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"project": 45,
|
||||||
|
"job_id": "528549b58fd64769bc5016d3a4357aab_0",
|
||||||
|
"result": "saved_ok"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"project": 46,
|
||||||
|
"job_id": "f8d51cf682604a08bd046123ab6a509a_0",
|
||||||
|
"result": "saved_ok"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"project": 47,
|
||||||
|
"job_id": "c73cc80bbc35445b8e4ffbb26a884bb0_0",
|
||||||
|
"result": "saved_ok"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"project": 48,
|
||||||
|
"job_id": "40a362b535034d15b4c89c4bc9af0c91_0",
|
||||||
|
"result": "saved_ok"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"project": 49,
|
||||||
|
"job_id": "4df4aafeb2c841b494b9949c8ca230d2_0",
|
||||||
|
"result": "saved_ok"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"project": 50,
|
||||||
|
"job_id": "7064b1e06df642c9a6c2fca037287ec4_0",
|
||||||
|
"result": "saved_ok"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"project": 51,
|
||||||
|
"job_id": "f6caf03914f74a26b769873941506bd1_0",
|
||||||
|
"result": "saved_ok"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"project": 52,
|
||||||
|
"job_id": "a2dea8f52ac04ed6ac1a2a28d9f8ef63_0",
|
||||||
|
"result": "saved_ok"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"project": 53,
|
||||||
|
"job_id": "42e312a4cf6d453a88ee9b2163b191b5_0",
|
||||||
|
"result": "saved_ok"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"project": 54,
|
||||||
|
"job_id": "45dbef10be42411c9a2a0248946d9037_0",
|
||||||
|
"result": "saved_ok"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"project": 55,
|
||||||
|
"job_id": "2d6bfff0905149659324f152a5a37053_0",
|
||||||
|
"result": "saved_ok"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"project": 56,
|
||||||
|
"job_id": "687a85f8e4684ebb99ae3371f08da745_0",
|
||||||
|
"result": "saved_ok"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"project": 57,
|
||||||
|
"job_id": "f03c1b7e292d458fa1cf34fa32fcc6dc_0",
|
||||||
|
"result": "saved_ok"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"project": 58,
|
||||||
|
"job_id": "2ddfbc06b4864f6cb76f7253fa35fab5_0",
|
||||||
|
"result": "saved_ok"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"project": 59,
|
||||||
|
"job_id": "14e6219fdebe4b54bbd95cd95d82fe27_0",
|
||||||
|
"result": "saved_ok"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"project": 60,
|
||||||
|
"job_id": "328b84460d394545a8b3a1701bb4668e_0",
|
||||||
|
"result": "saved_ok"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"project": 61,
|
||||||
|
"job_id": "932ee1968d8548cb9b20d2205cbda07f_0",
|
||||||
|
"result": "saved_ok"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"project": 62,
|
||||||
|
"job_id": "d61878a4fb6b42f69bc29d5a9039151f_0",
|
||||||
|
"result": "saved_ok"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"project": 63,
|
||||||
|
"job_id": "df606318c32a445f83fe0aaafa47dd8b_0",
|
||||||
|
"result": "saved_ok"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"project": 64,
|
||||||
|
"job_id": "810306d724314216b533239129fa5f00_0",
|
||||||
|
"result": "saved_ok"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"project": 65,
|
||||||
|
"job_id": "95d51023c87b4fa6be5ed8c36b884b02_0",
|
||||||
|
"result": "saved_ok"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"project": 66,
|
||||||
|
"job_id": "490361523d184a738048546ad39c5051_0",
|
||||||
|
"result": "saved_ok"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"project": 67,
|
||||||
|
"job_id": "d51096842332404b97c5bd9b320e2b72_0",
|
||||||
|
"result": "saved_ok"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"project": 68,
|
||||||
|
"job_id": "07beb872e39e4ed99bd63520b0b6f9e9_0",
|
||||||
|
"result": "saved_ok"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"project": 69,
|
||||||
|
"job_id": "7fd5188c1c1d4eb3874c45629db474b2_0",
|
||||||
|
"result": "saved_ok"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"project": 70,
|
||||||
|
"job_id": "b1690759022045288b9e3cec1089284f_0",
|
||||||
|
"result": "saved_ok"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"project": 71,
|
||||||
|
"job_id": "f7e247a2619642f2a1f881891e8eeb57_0",
|
||||||
|
"result": "saved_ok"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"project": 72,
|
||||||
|
"job_id": "aea8b540c89842d6869bc34564aa8a8f_0",
|
||||||
|
"result": "saved_ok"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"project": 73,
|
||||||
|
"job_id": "1deab0ea04ee4ee2be2bf8a5564fcf7c_0",
|
||||||
|
"result": "saved_ok"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"project": 74,
|
||||||
|
"job_id": "8808d235aba149bd8651675f2b10ceed_0",
|
||||||
|
"result": "saved_ok"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"project": 75,
|
||||||
|
"job_id": "30505f56d58848be97ce2af31bf8590d_0",
|
||||||
|
"result": "saved_ok"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"project": 76,
|
||||||
|
"job_id": "1aceadb5a89d4d068f318f8eeed650e4_0",
|
||||||
|
"result": "saved_ok"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"project": 77,
|
||||||
|
"job_id": "b75a90feeb3f4737a3bbc31c55aa418c_0",
|
||||||
|
"result": "saved_ok"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"project": 78,
|
||||||
|
"job_id": "21fe6401ceb34a80865a0d548ef707e5_0",
|
||||||
|
"result": "saved_ok"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"project": 79,
|
||||||
|
"job_id": "4ca98380c3494062bbca254f3efb91e6_0",
|
||||||
|
"result": "saved_ok"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"project": 80,
|
||||||
|
"job_id": "2eee50b616934bf9849d116fe4e313f4_0",
|
||||||
|
"result": "saved_ok"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"project": 81,
|
||||||
|
"job_id": "32cf6eb628bd4039a6d591682c96c661_0",
|
||||||
|
"result": "saved_ok"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"project": 82,
|
||||||
|
"job_id": "966a29d95f7040ceb044d818e0abcde0_0",
|
||||||
|
"result": "saved_ok"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"project": 83,
|
||||||
|
"job_id": "8aa901efbd6149bc9744714992fd6021_0",
|
||||||
|
"result": "saved_ok"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"project": 84,
|
||||||
|
"job_id": "9e6b5ecf9b714354b191e92add01d6c3_0",
|
||||||
|
"result": "saved_ok"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"project": 85,
|
||||||
|
"job_id": "08bd3aac43aa4b7ea9dd980540951c8f_0",
|
||||||
|
"result": "saved_ok"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"project": 86,
|
||||||
|
"job_id": "b70f927d89354785939daa703ae65dc3_0",
|
||||||
|
"result": "saved_ok"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"project": 87,
|
||||||
|
"job_id": "e1f98f7188b6446c8218d83a2041d906_0",
|
||||||
|
"result": "saved_ok"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"project": 88,
|
||||||
|
"job_id": "9c75b996f185424d9507fd00f2262fae_0",
|
||||||
|
"result": "saved_ok"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"project": 89,
|
||||||
|
"job_id": "2671fb1be481453cbd382973d8d3807c_0",
|
||||||
|
"result": "saved_ok"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"project": 90,
|
||||||
|
"job_id": "20044c501cf84140bc54114f903d40fd_0",
|
||||||
|
"result": "saved_ok"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"project": 91,
|
||||||
|
"job_id": "a5eda4530b8940178dabf9f8e85b1a2a_0",
|
||||||
|
"result": "saved_ok"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"project": 92,
|
||||||
|
"job_id": "fafda99d5f8344f18c574d4440c57518_0",
|
||||||
|
"result": "saved_ok"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"project": 93,
|
||||||
|
"job_id": "b3247626d9e441208779273cd3e607bc_0",
|
||||||
|
"result": "saved_ok"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"project": 94,
|
||||||
|
"job_id": "4dc0c755982f4fc1bd63803b83466aab_0",
|
||||||
|
"result": "saved_ok"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"project": 95,
|
||||||
|
"job_id": "b41bcead3e0c45fe855f2fa08dfc668b_0",
|
||||||
|
"result": "saved_ok"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"project": 96,
|
||||||
|
"job_id": "397b58aa73b042719410592f9b6ed4a1_0",
|
||||||
|
"result": "saved_ok"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"project": 97,
|
||||||
|
"job_id": "012bde1609484512b83f23809f333c9d_0",
|
||||||
|
"result": "saved_ok"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"project": 98,
|
||||||
|
"job_id": "00a4507a1c1f45f797e3f9e466c633b1_0",
|
||||||
|
"result": "saved_ok"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"project": 99,
|
||||||
|
"job_id": "300db9dee9b947be85a596b9f538128e_0",
|
||||||
|
"result": "saved_ok"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"project": 100,
|
||||||
|
"job_id": "c748b639f5034e8baaa0b2a6bed638ae_0",
|
||||||
|
"result": "saved_ok"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
@@ -0,0 +1,55 @@
|
|||||||
|
{
|
||||||
|
"projects": 8,
|
||||||
|
"first_return": {
|
||||||
|
"completed": 3,
|
||||||
|
"pending": 5
|
||||||
|
},
|
||||||
|
"final": {
|
||||||
|
"completed": 8
|
||||||
|
},
|
||||||
|
"queue_id": "6bbbdf75c72e4a21844c51d1938ee725",
|
||||||
|
"calls": [
|
||||||
|
{
|
||||||
|
"project": 1,
|
||||||
|
"job_id": "d4a210a4bea9478dbbe552f6fe87e125_0",
|
||||||
|
"result": "saved_ok"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"project": 2,
|
||||||
|
"job_id": "b595108e12e24858ae8faa006b63c103_0",
|
||||||
|
"result": "saved_ok"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"project": 3,
|
||||||
|
"job_id": "c74e034af94c4fdabaedee1b1d482771_0",
|
||||||
|
"result": "saved_ok"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"project": 4,
|
||||||
|
"job_id": "1a7c1b81b15844f2bce705755164e2d9_0",
|
||||||
|
"result": "saved_ok"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"project": 5,
|
||||||
|
"job_id": "267ea09123c44f20be66b0141f94177c_0",
|
||||||
|
"result": "saved_ok"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"project": 6,
|
||||||
|
"job_id": "8d9f2932a57846da8d087d80ddaed2fb_0",
|
||||||
|
"result": "saved_ok"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"project": 7,
|
||||||
|
"job_id": "a7e1d97f74d6495aa112831364ec47cc_0",
|
||||||
|
"result": "saved_ok"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"project": 8,
|
||||||
|
"job_id": "6a77966ac69a47c1b8c984bcc655cd7e_0",
|
||||||
|
"result": "saved_ok"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"paused_in_pid": 54160,
|
||||||
|
"resumed_in_pid": 60636
|
||||||
|
}
|
||||||
@@ -0,0 +1,35 @@
|
|||||||
|
# 工程校验闭环标准 v1
|
||||||
|
|
||||||
|
本标准用于 N12 及后续功能。写完代码、测试通过、工程检查一致、业务闭环通过、允许发布,是不同结论。每次验收必须声明正在证明哪一个结论。
|
||||||
|
|
||||||
|
## 单次功能闭环的通过条件
|
||||||
|
|
||||||
|
| 编号 | 必须证明 | 不满足时 |
|
||||||
|
| --- | --- | --- |
|
||||||
|
| C01 输入冻结 | 开始前写下预期工程名单、数量、前后摘要、输入版本和检查策略;配对预览与实际导入相符 | 失败;不能从运行后的结果反推预期 |
|
||||||
|
| C02 完整执行 | 用户显式开始;运行成员与冻结范围完全相同,每项都有属于本次运行的终态尝试 | 有排队、运行、停止、中断、漏项或重复项,均不能算完整闭环 |
|
||||||
|
| C03 判断正确 | 每项结论符合事先指定的预期;执行成功与 CONSISTENT/WARNING/DIFFERENT 分开;必查未知不得通过 | 误报、漏报、未知充当一致都失败 |
|
||||||
|
| C04 事实同源 | 页面、逐脚表、JSON和HTML报告绑定同一 item、输入版本、attempt、generation、输入摘要和证据摘要;原文摘要可复核 | 任何串版本、旧结果、缺证据或报告不符都失败 |
|
||||||
|
| C05 只读安全 | 校验前后全部已冻结源文件摘要不变,新增换料操作数为0,执行资源退出有证明;已有换料历史以开始前基线计数核对 | 不变性或退出证明缺失,失败并保留现场 |
|
||||||
|
| C06 重启回读 | 正常退出后重启,结果及证据仍可查看,尝试数不增加、不自动重跑 | 失败 |
|
||||||
|
| C07 重校验 | 同一输入重新执行时 attempt 更新、generation 递增;旧结果保留,新旧报告均可追溯 | 失败 |
|
||||||
|
| C08 异常隔离 | 反脚/断线等业务异常不挡后续工程;停止后未派发项仍待校验;资源/存储未知暂停正确范围;仍可新建独立任务 | 相应异常用例失败;不能以“正常样本跑过”替代 |
|
||||||
|
|
||||||
|
只有本次要求的检查全部通过,才写“该功能闭环通过”。验证程序对失败必须非零退出;结构性检查失败不能被 WARNING、正常进程退出或成功生成文件覆盖。某项故障测试验证了预期失败,不等于故障工程已经检查通过。
|
||||||
|
|
||||||
|
## 固定业务反例
|
||||||
|
|
||||||
|
物理脚1/2互换、断线、短接、位号或物理脚号变化必须为 DIFFERENT;loop→outloop 且连接不变必须为 WARNING;必查字段缺失必须为 INCOMPLETE。图中固定物理脚号位置,异常端点可与逐脚表和原文对应。自建格式夹具用于反例和可复现测试,必须明确标注,不能当成真实CAD导出证据。
|
||||||
|
|
||||||
|
## 两条业务路径分别验收
|
||||||
|
|
||||||
|
1. 独立输入:实际开发包中批量添加 → 开始全部 → 原生导出 → 查看图表 → 导出报告 → 正常关闭 → 重启查看 → 重校验 → 再导出。
|
||||||
|
2. 成功结果交接:真正已落盘的成功换料回执 → 自动登记校验 → 同一套执行、复核与报告。重复接收不重复建项,未保存项不得作为成功项。
|
||||||
|
|
||||||
|
两条路径不能互相代替。受控服务测试可证明交接合同、幂等和非阻塞;没有取得实际成功回执触发的包内证据时,该路径记“实际闭环未测”。本任务不为补验收重新执行客户换料,也不修改其他任务的旧执行器。
|
||||||
|
|
||||||
|
## 留证与发布
|
||||||
|
|
||||||
|
验收记录至少包含:代码提交、EXE SHA256、证据类型、预期清单、输入和报告摘要、任务/运行/尝试身份、每项标准的 passed/failed/not_run、失败原因、截图和实际命令。前一次运行、仅有截图、历史分组测试覆盖均不能替代本次闭环。
|
||||||
|
|
||||||
|
发布还要求相关回归通过、连续默认全量无未解决失败、实际包身份与源码相符、声明的两条实际路径通过。现有时序波动仍是发布保留项,不在本功能中改断言掩盖。引脚级Value和确切库内脚到焊盘映射仍未覆盖;不能写成“封装全部正确”。
|
||||||
@@ -4,7 +4,7 @@
|
|||||||
|
|
||||||
主工具顶部固定显示左右两个入口:左侧 **任务中心**,右侧 **DSH助手**,单击直接切换,无需展开菜单。助手也可按 `Ctrl+Shift+D` 打开;切回任务中心再进入助手时保留同一个网页、会话和未发送草稿。右侧“任务监管”读取主工具当前选中的任务。
|
主工具顶部固定显示左右两个入口:左侧 **任务中心**,右侧 **DSH助手**,单击直接切换,无需展开菜单。助手也可按 `Ctrl+Shift+D` 打开;切回任务中心再进入助手时保留同一个网页、会话和未发送草稿。右侧“任务监管”读取主工具当前选中的任务。
|
||||||
|
|
||||||
这里直接运行 [DeepSeek Harness](https://github.com/deepseek-ai/deepseek-harness) 的官方前端与运行时,固定 npm 版本 `0.2.1-rc.5`,通过 Qt WebEngine 嵌入主窗口。官方三栏框架、原生 SVG、鲸鱼悬停动画、输入编辑器、模型选择、侧栏与停靠交互均由上游代码提供。项目增加任务监管插件和“DSH助手”名称,不再使用 Qt 控件重画聊天页面。上游许可见 `licenses/DeepSeek-Harness-MIT.txt`。
|
这里直接运行 [DeepSeek Harness](https://github.com/deepseek-ai/deepseek-harness) 的官方前端与运行时,通过 Qt WebEngine 嵌入主窗口。当前 npm 版本以 `integration/dsh/package.json` 为准。官方三栏框架、原生 SVG、鲸鱼悬停动画、输入编辑器、模型选择、侧栏与停靠交互均由上游代码提供。项目增加任务监管插件和“DSH助手”名称,不再使用 Qt 控件重画聊天页面。上游许可见 `licenses/DeepSeek-Harness-MIT.txt`。
|
||||||
|
|
||||||
不显示上游账户登录、注册、充值和首次产品引导,也不注册其账户模型提供方。左下角 **工具设置** 单击打开原生设置页,包含“DSH工具”“通用设置”和“模型”;首页提示和任务监管面板围绕器件替换任务。输入框下方选择已配置的模型。
|
不显示上游账户登录、注册、充值和首次产品引导,也不注册其账户模型提供方。左下角 **工具设置** 单击打开原生设置页,包含“DSH工具”“通用设置”和“模型”;首页提示和任务监管面板围绕器件替换任务。输入框下方选择已配置的模型。
|
||||||
|
|
||||||
@@ -178,6 +178,14 @@ node tools/verify_dsh_runtime.mjs
|
|||||||
python tools/accept_dsh_desktop.py
|
python tools/accept_dsh_desktop.py
|
||||||
```
|
```
|
||||||
|
|
||||||
|
源码工作区可从 npm 更新 DSH。先退出任务中心,运行更新命令,再重新打开任务中心。
|
||||||
|
|
||||||
|
```powershell
|
||||||
|
powershell -ExecutionPolicy Bypass -File tools/Install-DshRuntime.ps1 -Version latest
|
||||||
|
```
|
||||||
|
|
||||||
|
将 `latest` 换成 `0.2.2-rc.5` 这样的完整版本号即可安装指定版本。脚本先在临时目录启动候选运行时并验证任务插件,通过后更新依赖声明、锁文件和实际依赖。更新成功时会打印 `build/dsh-update-…` 路径,其中 `previous` 保存旧运行时,`verification/report.json` 记录验收结果。便携版随应用打包 DSH,通过重新构建的应用发行包更新。
|
||||||
|
|
||||||
CLI 验证启动真实官方内核,检查工具与 preset 名单,实际读取快照、执行禁止工具探针,并测试本机请求认证、跨任务与过期动作边界。桌面验收启动真实主工具,用 Qt 鼠标事件单击左右导航,用 Chromium Input 事件操作官方页面,核对全新数据下无账户或引导弹窗、工具设置、任务刷新、会话、侧栏、SVG 动画、模型选择、草稿保留、取消确认和正常退出。验收只使用独立测试数据,不启动 CAD 或修改用户工程;未配置模型的验收不计为真实模型回复验证。
|
CLI 验证启动真实官方内核,检查工具与 preset 名单,实际读取快照、执行禁止工具探针,并测试本机请求认证、跨任务与过期动作边界。桌面验收启动真实主工具,用 Qt 鼠标事件单击左右导航,用 Chromium Input 事件操作官方页面,核对全新数据下无账户或引导弹窗、工具设置、任务刷新、会话、侧栏、SVG 动画、模型选择、草稿保留、取消确认和正常退出。验收只使用独立测试数据,不启动 CAD 或修改用户工程;未配置模型的验收不计为真实模型回复验证。
|
||||||
|
|
||||||
已配置本机模型时,可执行真实 API 桌面验收:
|
已配置本机模型时,可执行真实 API 桌面验收:
|
||||||
|
|||||||
@@ -0,0 +1,25 @@
|
|||||||
|
# 工程校验
|
||||||
|
|
||||||
|
在第四个“工程校验”页面随时新建任务。选择修改前、修改后两份已保存的 `.prj` 工程添加比较项,不能选择同一文件或共用数据库的两个工程。已有替换任务不影响新建;替换已保存的成功项会自动交接,缺少前后副本的项显示无法校验,不能用当前工程补造历史版本。
|
||||||
|
|
||||||
|
大量工程可点击“批量添加”,选择修改前、修改后两个根目录,再点“读取配对”。两个目录不能相同或互相包含。工具沿用工程目录扫描规则:发现含原理图工程的目录后,不再扫描其子目录;数据目录不参与扫描。
|
||||||
|
|
||||||
|
配对只认相对路径,例如前目录的 `Board-A/board.prj` 对应后目录的 `Board-A/board.prj`;不同子目录中同名工程不会混配。预览列出缺失或无法唯一配对的项,它们不能勾选。不符合这个目录结构的工程,仍可用“添加工程对”逐对指定。
|
||||||
|
|
||||||
|
批量导入后,任务内保留这个相对路径作为工程名称,列表、历史和报告中都能区分不同目录里的同名工程。
|
||||||
|
|
||||||
|
批量名称沿用任务库的 256 字符上限;相对路径超过上限时该项显示导入失败,可缩短目录层级或使用“添加工程对”单独添加。不会把任务库拒收误报成导入成功。
|
||||||
|
|
||||||
|
勾选后点“导入所选”,只建立前后只读副本,随后回到任务点击“开始全部”或“校验所选”。单项导入失败后继续其他项,失败原因保留在状态提示中;取消或关闭导入窗口时保留已导入项,未处理项可继续选择导入。磁盘空间或存储故障会中断整批并保留已导入项。此窗口不阻止新建其他校验任务。
|
||||||
|
|
||||||
|
“开始全部”处理当前任务中当时待校验/中断的工程;筛选不会缩小这个范围。“校验所选”和“重校验”明确处理所选工程当前版本。运行期间后到的新项或新版本留待下次开始。校验只读副本,不会重新换料或自动换脚。
|
||||||
|
|
||||||
|
工程表每页最多显示 100 项,点击“下一页”继续查看;自动刷新保留当前页,修改搜索或筛选后回到第一页。分页和筛选都不影响“开始全部”的范围。
|
||||||
|
|
||||||
|
一致表示已覆盖的必查项未发现差异;需关注表示有文字或属性变化需要人工判断;异常表示已证明位号、物理脚号、连接或声明目标等不符合;无法校验表示证据不足。没有固定换料清单时始终显示“未核对换料规则”。执行结束不等于工程一致。
|
||||||
|
|
||||||
|
选择工程,在右侧选择位号查看固定脚号的前后接线图和逐脚事实。红线对应连接变化;纯名称变化以关注提示。图由网表生成,不是原理图截图。原始证据入口会核对摘要;历史版本仅供查看,不改变当前结论。导出报告包含同一份图表、检查范围、输入和尝试摘要,不复制整个工程。
|
||||||
|
|
||||||
|
停止采用安全收尾。未派发项保留待校验,已开始项保留停止记录。重启不会自动重跑;缺少进程退出证明的项保留现场并暂停新的原生导出,不按 PID 猜测或终止其他进程。
|
||||||
|
|
||||||
|
首版未证明引脚级 Value 读取和确切库内部引脚→焊盘映射,页面明确未覆盖。电气类型按原生码展示,不臆造语义。本网表比较不宣称完成 ERC、PCB 或封装库内部正确性验证。普通操作历史清空和运行日志保留不会删除校验快照与证据。
|
||||||
Generated
+4138
-3271
File diff suppressed because it is too large.
Load diff
@@ -2,7 +2,15 @@
|
|||||||
"name": "dxdesigner-dsh-runtime",
|
"name": "dxdesigner-dsh-runtime",
|
||||||
"private": true,
|
"private": true,
|
||||||
"type": "module",
|
"type": "module",
|
||||||
"scripts": {"doctor": "node start.mjs --doctor", "start": "node start.mjs"},
|
"scripts": {
|
||||||
"engines": {"node": ">=24.9.0"},
|
"doctor": "node start.mjs --doctor",
|
||||||
"dependencies": {"@deepseek-ai/dsh": "0.2.1-rc.5", "fflate": "0.8.3"}
|
"start": "node start.mjs"
|
||||||
|
},
|
||||||
|
"engines": {
|
||||||
|
"node": ">=24.9.0"
|
||||||
|
},
|
||||||
|
"dependencies": {
|
||||||
|
"@deepseek-ai/dsh": "0.2.2-rc.5",
|
||||||
|
"fflate": "0.8.3"
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@@ -12,7 +12,7 @@ export const FILE_TOOLS=['read','read_image','write','edit','glob','grep','worki
|
|||||||
|
|
||||||
const root = path.dirname(fileURLToPath(import.meta.url));
|
const root = path.dirname(fileURLToPath(import.meta.url));
|
||||||
const require = createRequire(import.meta.url);
|
const require = createRequire(import.meta.url);
|
||||||
export const VERSION = '0.2.1-rc.5';
|
export const VERSION = require('./package.json').dependencies['@deepseek-ai/dsh'];
|
||||||
export const DISABLED = [
|
export const DISABLED = [
|
||||||
'desktop-product-telemetry','product-analytics','session-telemetry-otel',
|
'desktop-product-telemetry','product-analytics','session-telemetry-otel',
|
||||||
];
|
];
|
||||||
|
|||||||
@@ -295,7 +295,7 @@ window.__ModuleLoader__.load({id:'@dx/dsh-task',factory:require=>{
|
|||||||
tab==='tickets'?h(TicketsPanel,{operations,perform,pending:pending||operations.busy}):h(UsagePanel,{runtime,control,pending})),
|
tab==='tickets'?h(TicketsPanel,{operations,perform,pending:pending||operations.busy}):h(UsagePanel,{runtime,control,pending})),
|
||||||
tab!=='overview'&&h('p',{'data-testid':'dx-operations-notice',role:'status',style:{fontSize:12,color:secondary,lineHeight:1.8,whiteSpace:'pre-wrap'}},operations.activity?.message||notice||''));
|
tab!=='overview'&&h('p',{'data-testid':'dx-operations-notice',role:'status',style:{fontSize:12,color:secondary,lineHeight:1.8,whiteSpace:'pre-wrap'}},operations.activity?.message||notice||''));
|
||||||
}
|
}
|
||||||
return{inject:['slots','sidebarRightTabs','sidebarRight','uiSession','uiWorkspace'],apply(ctx){
|
return{inject:['slots','sidebarRightTabs','sidebarRight','uiSession','uiWorkspace','workspaces'],apply(ctx){
|
||||||
ctx.effect(()=>{
|
ctx.effect(()=>{
|
||||||
let live=true,opened='';
|
let live=true,opened='';
|
||||||
const check=()=>fetch('/dx/context').then(r=>r.json()).then(data=>{
|
const check=()=>fetch('/dx/context').then(r=>r.json()).then(data=>{
|
||||||
@@ -318,10 +318,11 @@ window.__ModuleLoader__.load({id:'@dx/dsh-task',factory:require=>{
|
|||||||
if(sessionId){
|
if(sessionId){
|
||||||
if(openedSession===sessionId)return;
|
if(openedSession===sessionId)return;
|
||||||
try{ctx.sidebarRight.openTab('dx-task');if(ctx.sidebarRight.isExpanded()){openedSession=sessionId;return;}}catch{}
|
try{ctx.sidebarRight.openTab('dx-task');if(ctx.sidebarRight.isExpanded()){openedSession=sessionId;return;}}catch{}
|
||||||
}else if(!connecting&&!adopted){
|
}else if(!connecting&&!adopted&&ctx.workspaces.list.getSnapshot().phase==='ready'){
|
||||||
connecting=true;
|
connecting=true;
|
||||||
fetch('/dx/workspace').then(r=>{if(!r.ok&&r.ok!==undefined)throw Error();return r.json();}).then(value=>{
|
fetch('/dx/workspace').then(r=>{if(!r.ok&&r.ok!==undefined)throw Error();return r.json();}).then(value=>{
|
||||||
if(live&&!current.getSnapshot()&&typeof value.workspace_id==='string'){
|
if(live&&!current.getSnapshot()&&typeof value.workspace_id==='string'&&
|
||||||
|
ctx.workspaces.list.getSnapshot().items.some(row=>row.workspaceId===value.workspace_id)){
|
||||||
adopted=true;return ctx.uiWorkspace.openWorkspace(value.workspace_id);
|
adopted=true;return ctx.uiWorkspace.openWorkspace(value.workspace_id);
|
||||||
}
|
}
|
||||||
}).catch(()=>{adopted=false;}).finally(()=>{connecting=false;if(live)queue();});
|
}).catch(()=>{adopted=false;}).finally(()=>{connecting=false;if(live)queue();});
|
||||||
|
|||||||
@@ -249,6 +249,7 @@ Function QPNativeCollectMode(ByRef SelectedUids, ByVal Token, ByVal Project, ByV
|
|||||||
QPNativeRequireContext Project, Sheet, Guid
|
QPNativeRequireContext Project, Sheet, Guid
|
||||||
QPInvalidatePinIndex
|
QPInvalidatePinIndex
|
||||||
Set Components = QP_App.ActiveView.Query(VDM_COMP, VD_ALL)
|
Set Components = QP_App.ActiveView.Query(VDM_COMP, VD_ALL)
|
||||||
|
QPBindSheetReferences Components
|
||||||
Set Seen = CreateObject("Scripting.Dictionary")
|
Set Seen = CreateObject("Scripting.Dictionary")
|
||||||
Set Found = CreateObject("Scripting.Dictionary")
|
Set Found = CreateObject("Scripting.Dictionary")
|
||||||
Text = "NR1" & vbTab & Token & vbTab & QPEncode(Project) & vbTab & QPEncode(Sheet) & vbCrLf
|
Text = "NR1" & vbTab & Token & vbTab & QPEncode(Project) & vbTab & QPEncode(Sheet) & vbCrLf
|
||||||
@@ -306,6 +307,13 @@ Function QPBuildNativeReadScript(ByVal Source, ByRef SelectedUids, ByVal Token,
|
|||||||
For Each Uid In SelectedUids.Keys
|
For Each Uid In SelectedUids.Keys
|
||||||
Body = Body & "QP_NR_Selected.Add " & QPNativeExpression(Uid) & ",True" & vbCrLf
|
Body = Body & "QP_NR_Selected.Add " & QPNativeExpression(Uid) & ",True" & vbCrLf
|
||||||
Next
|
Next
|
||||||
|
If IsObject(QP_ReferenceAliases) Then
|
||||||
|
Body=Body & "Set QP_ReferenceAliases=CreateObject(""Scripting.Dictionary"")" & vbCrLf
|
||||||
|
For Each Uid In QP_ReferenceAliases.Keys
|
||||||
|
Body=Body & "QP_ReferenceAliases.Add " & QPNativeExpression(Uid) & "," & _
|
||||||
|
QPNativeExpression(QP_ReferenceAliases(Uid)) & vbCrLf
|
||||||
|
Next
|
||||||
|
End If
|
||||||
Body = Body & "On Error Resume Next" & vbCrLf & _
|
Body = Body & "On Error Resume Next" & vbCrLf & _
|
||||||
"Set QP_App=GetObject(,""Viewdraw.Application"")" & vbCrLf & _
|
"Set QP_App=GetObject(,""Viewdraw.Application"")" & vbCrLf & _
|
||||||
"If Err.Number=0 Then QP_NR_Text=QPNativeCollectMode(QP_NR_Selected," & _
|
"If Err.Number=0 Then QP_NR_Text=QPNativeCollectMode(QP_NR_Selected," & _
|
||||||
@@ -315,7 +323,7 @@ Function QPBuildNativeReadScript(ByVal Source, ByRef SelectedUids, ByVal Token,
|
|||||||
"If QP_NR_Code<>0 Then QP_NR_Text=""ERROR"" & vbTab & " & QPNativeExpression(Token) & _
|
"If QP_NR_Code<>0 Then QP_NR_Text=""ERROR"" & vbTab & " & QPNativeExpression(Token) & _
|
||||||
" & vbTab & CStr(QP_NR_Code) & vbTab & QPEncode(QP_NR_Source) & vbTab & QPEncode(QP_NR_Description) & vbCrLf" & vbCrLf & _
|
" & vbTab & CStr(QP_NR_Code) & vbTab & QPEncode(QP_NR_Source) & vbTab & QPEncode(QP_NR_Description) & vbCrLf" & vbCrLf & _
|
||||||
"QPWriteUtf8 " & QPNativeExpression(ResultPath) & ",QP_NR_Text" & vbCrLf & "On Error GoTo 0" & vbCrLf
|
"QPWriteUtf8 " & QPNativeExpression(ResultPath) & ",QP_NR_Text" & vbCrLf & "On Error GoTo 0" & vbCrLf
|
||||||
Names = Split("QPNativeCollectMode QPNativeRequireContext QPNativeReadInvalid QPSnapshotComponent QPUntouchedComponent QPUntouchedFullState QPUntouchedIdentity QPComponentPins QPComponentIdentityKey QPInvalidatePinIndex QPConnectionSignatureFromPins QPAddSortedSignature QPSnapshotAttribute QPReadOptionalAttributeValue QPOptionalAttributeField QPSortSnapshotLines QPLog QPAppendAscii QPEncode QPDecode QPProjectPath QPSheetIdentity QPCanonicalPath QPEnsureProjectAccess QPReadUtf8 QPWriteUtf8", " ")
|
Names = Split("QPNativeCollectMode QPNativeRequireContext QPNativeReadInvalid QPSnapshotComponent QPUntouchedComponent QPUntouchedFullState QPUntouchedIdentity QPComponentPins QPComponentIdentityKey QPComponentUnitKey QPBindSheetReferences QPInvalidatePinIndex QPConnectionSignatureFromPins QPAddSortedSignature QPSnapshotAttribute QPReadOptionalAttributeValue QPOptionalAttributeField QPSortSnapshotLines QPLog QPAppendAscii QPEncode QPDecode QPProjectPath QPSheetIdentity QPCanonicalPath QPEnsureProjectAccess QPReadUtf8 QPWriteUtf8", " ")
|
||||||
Pattern.Global = False
|
Pattern.Global = False
|
||||||
For Each Name In Names
|
For Each Name In Names
|
||||||
Pattern.Pattern = "^(Function|Sub) " & Name & "\([^\n]*\n[\s\S]*?^End \1[ \t]*"
|
Pattern.Pattern = "^(Function|Sub) " & Name & "\([^\n]*\n[\s\S]*?^End \1[ \t]*"
|
||||||
|
|||||||
File diff suppressed because it is too large.
Load diff
@@ -1,5 +1,5 @@
|
|||||||
DeepSeek Harness native frontend and runtime
|
DeepSeek Harness native frontend and runtime
|
||||||
Pinned release: @deepseek-ai/dsh 0.2.1-rc.5
|
Package: @deepseek-ai/dsh
|
||||||
Source: https://github.com/deepseek-ai/deepseek-harness
|
Source: https://github.com/deepseek-ai/deepseek-harness
|
||||||
|
|
||||||
MIT License
|
MIT License
|
||||||
|
|||||||
@@ -1,8 +1,8 @@
|
|||||||
# UTF-8
|
# UTF-8
|
||||||
VSVersionInfo(
|
VSVersionInfo(
|
||||||
ffi=FixedFileInfo(
|
ffi=FixedFileInfo(
|
||||||
filevers=(1, 3, 1, 0),
|
filevers=(1, 3, 3, 1),
|
||||||
prodvers=(1, 3, 1, 0),
|
prodvers=(1, 3, 3, 1),
|
||||||
mask=0x3f,
|
mask=0x3f,
|
||||||
flags=0x0,
|
flags=0x0,
|
||||||
OS=0x40004,
|
OS=0x40004,
|
||||||
@@ -15,11 +15,11 @@ VSVersionInfo(
|
|||||||
StringTable('040904B0', [
|
StringTable('040904B0', [
|
||||||
StringStruct('CompanyName', 'DxProductivity'),
|
StringStruct('CompanyName', 'DxProductivity'),
|
||||||
StringStruct('FileDescription', 'DxDesigner Part Replacement'),
|
StringStruct('FileDescription', 'DxDesigner Part Replacement'),
|
||||||
StringStruct('FileVersion', '1.3.1.0'),
|
StringStruct('FileVersion', '1.3.3.1'),
|
||||||
StringStruct('InternalName', 'DxPartReplace'),
|
StringStruct('InternalName', 'DxPartReplace'),
|
||||||
StringStruct('OriginalFilename', 'DxPartReplace.exe'),
|
StringStruct('OriginalFilename', 'DxPartReplace.exe'),
|
||||||
StringStruct('ProductName', 'DxDesigner Part Replacement'),
|
StringStruct('ProductName', 'DxDesigner Part Replacement'),
|
||||||
StringStruct('ProductVersion', '1.3.1')
|
StringStruct('ProductVersion', '1.3.3-beta.1')
|
||||||
])
|
])
|
||||||
]),
|
]),
|
||||||
VarFileInfo([VarStruct('Translation', [1033, 1200])])
|
VarFileInfo([VarStruct('Translation', [1033, 1200])])
|
||||||
|
|||||||
+1
-1
@@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"
|
|||||||
|
|
||||||
[project]
|
[project]
|
||||||
name = "dx-productivity"
|
name = "dx-productivity"
|
||||||
version = "1.3.1"
|
version = "1.3.3b1"
|
||||||
requires-python = ">=3.12,<3.13"
|
requires-python = ">=3.12,<3.13"
|
||||||
dependencies = ["PySide6>=6.7,<7", "pywin32>=306", "pywinauto>=0.6.9,<1", "openpyxl>=3.1,<4"]
|
dependencies = ["PySide6>=6.7,<7", "pywin32>=306", "pywinauto>=0.6.9,<1", "openpyxl>=3.1,<4"]
|
||||||
|
|
||||||
|
|||||||
@@ -87,10 +87,12 @@ def _execute_confirmed_run(service, root, task_ids, report, stop, run_id, *, res
|
|||||||
else:
|
else:
|
||||||
journal.begin(run_id, task_ids, report['plan_hashes'], schedule_id=schedule['schedule_id'] if schedule else None)
|
journal.begin(run_id, task_ids, report['plan_hashes'], schedule_id=schedule['schedule_id'] if schedule else None)
|
||||||
initialized = True
|
initialized = True
|
||||||
|
resource_batch_id = inspected.get('resource_batch_id') if resume else None
|
||||||
result = execute_task_queue(service, tuple(task_ids), stop_event=stop,
|
result = execute_task_queue(service, tuple(task_ids), stop_event=stop,
|
||||||
expected_plan_hashes=report['plan_hashes'],
|
expected_plan_hashes=report['plan_hashes'],
|
||||||
queue_id=run_id if resume and resume['queue_available'] else None,
|
queue_id=run_id if resume and resume['queue_available'] else None,
|
||||||
checkpoint_id=None if resume and resume['queue_available'] else run_id)
|
checkpoint_id=None if resume and resume['queue_available'] else run_id,
|
||||||
|
**({'resource_batch_id': resource_batch_id} if resource_batch_id else {}))
|
||||||
except Exception as error:
|
except Exception as error:
|
||||||
failure = {**(_failure_evidence(service, journal, run_id, baseline) if initialized else {}),
|
failure = {**(_failure_evidence(service, journal, run_id, baseline) if initialized else {}),
|
||||||
'status': 'interrupted', 'run_id': run_id, 'queue_id': run_id,
|
'status': 'interrupted', 'run_id': run_id, 'queue_id': run_id,
|
||||||
@@ -118,6 +120,13 @@ def _finish_execution_run(service, root, task_ids, stop, run_id, result, *, base
|
|||||||
'user_pause_requested': bool(stop.is_set()), 'awaiting_user_resume': bool(result.paused and stop.is_set()),
|
'user_pause_requested': bool(stop.is_set()), 'awaiting_user_resume': bool(result.paused and stop.is_set()),
|
||||||
'entries': entries, 'tasks': [], 'reporting_errors': [],
|
'entries': entries, 'tasks': [], 'reporting_errors': [],
|
||||||
'message': '请按每项实际计数判断;未命中不表示已替换保存。'}
|
'message': '请按每项实际计数判断;未命中不表示已替换保存。'}
|
||||||
|
batch_id = getattr(service, '_last_supervisor_batch_id', None)
|
||||||
|
if result.paused and not stop.is_set() and batch_id:
|
||||||
|
from ..trial_task_center.task_queue import resource_pause_admitted
|
||||||
|
run = journal.get(run_id)
|
||||||
|
if (run and resource_pause_admitted(root, batch_id, tuple(task_ids), run['plan_hashes'],
|
||||||
|
result, require_released=False)):
|
||||||
|
receipt['resource_batch_id'] = batch_id
|
||||||
if result.netlist_verification:
|
if result.netlist_verification:
|
||||||
receipt['netlist_verification'] = result.netlist_verification
|
receipt['netlist_verification'] = result.netlist_verification
|
||||||
# Persist the executor's known outcome before optional readback/enrichment.
|
# Persist the executor's known outcome before optional readback/enrichment.
|
||||||
@@ -152,6 +161,20 @@ def _finish_execution_run(service, root, task_ids, stop, run_id, result, *, base
|
|||||||
receipt['reporting_errors'].append({'code': getattr(error, 'code', 'schedule_receipt_unavailable')})
|
receipt['reporting_errors'].append({'code': getattr(error, 'code', 'schedule_receipt_unavailable')})
|
||||||
_persist_execution_receipt(service, journal, run_id, receipt, baseline)
|
_persist_execution_receipt(service, journal, run_id, receipt, baseline)
|
||||||
raise
|
raise
|
||||||
|
# Optional downstream delivery follows the durable replacement receipt.
|
||||||
|
# Delivery failure must never turn a saved replacement into a repeat request.
|
||||||
|
try:
|
||||||
|
verification = getattr(service, 'verification', None)
|
||||||
|
if verification is not None:
|
||||||
|
from ..trial_task_center.verification.contracts import digest
|
||||||
|
delivery = verification.receive_successful_results(
|
||||||
|
receipt, submission_id=f'run:{run_id}:{digest(receipt)}')
|
||||||
|
if delivery['rejected']:
|
||||||
|
receipt['reporting_errors'].append({'code': 'verification_delivery_pending',
|
||||||
|
'rejected': delivery['rejected']})
|
||||||
|
except Exception as error:
|
||||||
|
receipt['reporting_errors'].append({'code': 'verification_delivery_pending',
|
||||||
|
'error': type(error).__name__})
|
||||||
return receipt
|
return receipt
|
||||||
|
|
||||||
|
|
||||||
@@ -286,7 +309,8 @@ def _execute_incident_retry(service, root, task_id, run_id, *, expected_item, st
|
|||||||
raise TaskCenterError('run_scope', '原队列检查点身份或范围已变化;保留本次结果。')
|
raise TaskCenterError('run_scope', '原队列检查点身份或范围已变化;保留本次结果。')
|
||||||
checkpoint['entries'][task_id].update(state=state, message=message)
|
checkpoint['entries'][task_id].update(state=state, message=message)
|
||||||
if path.parent.name == 'workspace-queues':
|
if path.parent.name == 'workspace-queues':
|
||||||
checkpoint['entries'][task_id].update(released=not bool(service.pending_batch_resources()), problems_done=True)
|
from ..trial_task_center.batch_resources import resource_blockers
|
||||||
|
checkpoint['entries'][task_id].update(released=not bool(resource_blockers(service.pending_batch_resources())), problems_done=True)
|
||||||
if reports:
|
if reports:
|
||||||
checkpoint['entries'][task_id]['netlist_verification'] = reports[task_id]
|
checkpoint['entries'][task_id]['netlist_verification'] = reports[task_id]
|
||||||
elif reports:
|
elif reports:
|
||||||
|
|||||||
@@ -316,7 +316,8 @@ class IncidentRunner:
|
|||||||
remaining = tuple(self.service.pending_batch_resources())
|
remaining = tuple(self.service.pending_batch_resources())
|
||||||
cleanup['remaining_resources'] = _bounded_details(remaining)
|
cleanup['remaining_resources'] = _bounded_details(remaining)
|
||||||
cleanup['remaining_resources_observed'] = True
|
cleanup['remaining_resources_observed'] = True
|
||||||
released = not remaining
|
from ..trial_task_center.batch_resources import resource_blockers
|
||||||
|
released = not resource_blockers(remaining)
|
||||||
except Exception as error:
|
except Exception as error:
|
||||||
cleanup['verification_error'] = scrub({'type': type(error).__name__, 'detail': str(error)[:1000]})
|
cleanup['verification_error'] = scrub({'type': type(error).__name__, 'detail': str(error)[:1000]})
|
||||||
cleanup['remaining_resources'], released = None, None
|
cleanup['remaining_resources'], released = None, None
|
||||||
|
|||||||
@@ -12,9 +12,6 @@ from uuid import uuid4
|
|||||||
from .snapshot import TaskSnapshot
|
from .snapshot import TaskSnapshot
|
||||||
from ..trial_task_center.path_access import retry_sharing_violation
|
from ..trial_task_center.path_access import retry_sharing_violation
|
||||||
|
|
||||||
HARNESS_VERSION = '0.2.1-rc.5'
|
|
||||||
|
|
||||||
|
|
||||||
def integration_root() -> Path:
|
def integration_root() -> Path:
|
||||||
if getattr(sys, 'frozen', False):
|
if getattr(sys, 'frozen', False):
|
||||||
return Path(sys._MEIPASS) / 'dsh-runtime'
|
return Path(sys._MEIPASS) / 'dsh-runtime'
|
||||||
|
|||||||
@@ -332,6 +332,31 @@ class RunJournal:
|
|||||||
released_primary = {key for key, entry in (queue['entries'].items() if workspace and queue else ())
|
released_primary = {key for key, entry in (queue['entries'].items() if workspace and queue else ())
|
||||||
if entry['released'] and entry['state'] in {'completed', 'failed', 'skipped', 'blocked'}}
|
if entry['released'] and entry['state'] in {'completed', 'failed', 'skipped', 'blocked'}}
|
||||||
isolated = {key for key in released_primary if queue['entries'][key]['state'] == 'blocked'}
|
isolated = {key for key in released_primary if queue['entries'][key]['state'] == 'blocked'}
|
||||||
|
resource_batch_id = None
|
||||||
|
if queue and not workspace:
|
||||||
|
isolated.update(key for key in queue.get('isolated_tasks', {})
|
||||||
|
if key in queue['entries'] and queue['entries'][key]['state'] == 'blocked')
|
||||||
|
receipt = row.get('result') or {}
|
||||||
|
if (receipt.get('paused') is True and receipt.get('user_pause_requested') is False
|
||||||
|
and any(entry['state'] == 'blocked' and key not in isolated
|
||||||
|
for key, entry in queue['entries'].items())):
|
||||||
|
from ..trial_task_center.task_queue import resource_pause_admitted
|
||||||
|
pause = queue.get('resource_pause') or {}
|
||||||
|
known_batch = receipt.get('resource_batch_id') or pause.get('batch_id')
|
||||||
|
candidates = (known_batch,) if known_batch else (
|
||||||
|
path.parent.name for path in (self.data_root / 'batch-resources').glob('*/result.json'))
|
||||||
|
matches = []
|
||||||
|
for batch_id in candidates:
|
||||||
|
paused = resource_pause_admitted(self.data_root, batch_id,
|
||||||
|
tuple(row['task_ids']), row['plan_hashes'])
|
||||||
|
if paused and paused.queue_id == run_id:
|
||||||
|
matches.append((batch_id, paused))
|
||||||
|
if len(matches) > 1:
|
||||||
|
break
|
||||||
|
if len(matches) == 1:
|
||||||
|
resource_batch_id, paused = matches[0]
|
||||||
|
isolated.add(paused.current_task_id)
|
||||||
|
released_primary.update(isolated)
|
||||||
safe_continuations = set()
|
safe_continuations = set()
|
||||||
for task_id in row["task_ids"]:
|
for task_id in row["task_ids"]:
|
||||||
item = {"task_id": task_id, "status": "unknown", "saved_items": 0, "failed_items": 0, "no_match_items": 0}
|
item = {"task_id": task_id, "status": "unknown", "saved_items": 0, "failed_items": 0, "no_match_items": 0}
|
||||||
@@ -380,7 +405,8 @@ class RunJournal:
|
|||||||
counters["completed"] = sum(queue["entries"][task_id]["state"] in {"completed", "failed", "skipped"} for task_id in row["task_ids"])
|
counters["completed"] = sum(queue["entries"][task_id]["state"] in {"completed", "failed", "skipped"} for task_id in row["task_ids"])
|
||||||
remaining = [task_id for task_id in row["task_ids"] if not queue or queue["entries"][task_id]["state"] not in {"completed", "failed", "skipped"}]
|
remaining = [task_id for task_id in row["task_ids"] if not queue or queue["entries"][task_id]["state"] not in {"completed", "failed", "skipped"}]
|
||||||
if queue and not workspace and queue.get('phase') in {'primary', 'problems'}:
|
if queue and not workspace and queue.get('phase') in {'primary', 'problems'}:
|
||||||
remaining = [key for key in row['task_ids'] if key in remaining or key in released_primary]
|
remaining = [key for key in row['task_ids'] if key not in isolated and
|
||||||
|
(key in remaining or key in released_primary)]
|
||||||
if workspace and queue:
|
if workspace and queue:
|
||||||
primary_exhausted = all(entry['state'] in {'completed', 'failed', 'skipped', 'blocked'} for entry in queue['entries'].values())
|
primary_exhausted = all(entry['state'] in {'completed', 'failed', 'skipped', 'blocked'} for entry in queue['entries'].values())
|
||||||
remaining = [key for key in row['task_ids'] if key not in isolated and (
|
remaining = [key for key in row['task_ids'] if key not in isolated and (
|
||||||
@@ -402,10 +428,12 @@ class RunJournal:
|
|||||||
blockers.append("preflight_blocked")
|
blockers.append("preflight_blocked")
|
||||||
except Exception:
|
except Exception:
|
||||||
blockers.append("preflight_unavailable")
|
blockers.append("preflight_unavailable")
|
||||||
if service.pending_batch_resources():
|
from ..trial_task_center.batch_resources import resource_blockers
|
||||||
|
if resource_blockers(service.pending_batch_resources()):
|
||||||
blockers.append("resources_pending")
|
blockers.append("resources_pending")
|
||||||
blockers = list(dict.fromkeys(blockers))
|
blockers = list(dict.fromkeys(blockers))
|
||||||
value = {**row, "queue_available": queue is not None, "tasks": tasks, "counters": counters,
|
value = {**row, "queue_available": queue is not None, "tasks": tasks, "counters": counters,
|
||||||
|
'resource_batch_id': resource_batch_id,
|
||||||
'isolated_task_ids': [key for key in row['task_ids'] if key in isolated],
|
'isolated_task_ids': [key for key in row['task_ids'] if key in isolated],
|
||||||
'released_primary_task_ids': [key for key in row['task_ids'] if key in released_primary],
|
'released_primary_task_ids': [key for key in row['task_ids'] if key in released_primary],
|
||||||
'safe_continuation_task_ids': [key for key in row['task_ids'] if key in safe_continuations],
|
'safe_continuation_task_ids': [key for key in row['task_ids'] if key in safe_continuations],
|
||||||
|
|||||||
@@ -246,7 +246,8 @@ class ScheduleStore:
|
|||||||
with self.execution_lease(schedule_id):
|
with self.execution_lease(schedule_id):
|
||||||
assert_task_queue_idle(self.data_root)
|
assert_task_queue_idle(self.data_root)
|
||||||
with _queue_lease(self.data_root):
|
with _queue_lease(self.data_root):
|
||||||
if service.pending_batch_resources():
|
from ..trial_task_center.batch_resources import resource_blockers
|
||||||
|
if resource_blockers(service.pending_batch_resources()):
|
||||||
raise TaskCenterError('schedule_busy', '后台资源尚未释放,请先在任务中心核验和清理。')
|
raise TaskCenterError('schedule_busy', '后台资源尚未释放,请先在任务中心核验和清理。')
|
||||||
with self._connect() as db:
|
with self._connect() as db:
|
||||||
db.execute('BEGIN IMMEDIATE')
|
db.execute('BEGIN IMMEDIATE')
|
||||||
|
|||||||
@@ -50,7 +50,8 @@ def preflight(service, task_ids, *, allow_completed=False):
|
|||||||
from .impact import _scope
|
from .impact import _scope
|
||||||
task_ids = _scope(task_ids)
|
task_ids = _scope(task_ids)
|
||||||
tasks, paths, hashes = [], set(), {}
|
tasks, paths, hashes = [], set(), {}
|
||||||
pending = bool(service.pending_batch_resources())
|
from ..trial_task_center.batch_resources import resource_blockers
|
||||||
|
pending = bool(resource_blockers(service.pending_batch_resources()))
|
||||||
for task_id in task_ids:
|
for task_id in task_ids:
|
||||||
context = _context(service, task_id)
|
context = _context(service, task_id)
|
||||||
state = execution_state(context)
|
state = execution_state(context)
|
||||||
|
|||||||
@@ -9,12 +9,13 @@ import platform
|
|||||||
import sys
|
import sys
|
||||||
from typing import Sequence
|
from typing import Sequence
|
||||||
|
|
||||||
from PySide6.QtCore import QTimer, QThreadPool
|
from PySide6.QtCore import QTimer, QThreadPool, Qt
|
||||||
from PySide6.QtGui import QIcon
|
from PySide6.QtGui import QIcon
|
||||||
from PySide6.QtWidgets import QApplication
|
from PySide6.QtWidgets import QApplication
|
||||||
|
|
||||||
from dx_productivity.trial_task_center.logging_setup import LoggingContext, configure_logging, install_exception_hooks
|
from dx_productivity.trial_task_center.logging_setup import LoggingContext, configure_logging, install_exception_hooks
|
||||||
from dx_productivity.trial_task_center.service import TaskCenterService
|
from dx_productivity.trial_task_center.service import TaskCenterService
|
||||||
|
from dx_productivity.trial_task_center.single_instance import InstanceUnavailable, gui_instance, listen_for_activation
|
||||||
from dx_productivity.trial_task_center.store import TaskStore
|
from dx_productivity.trial_task_center.store import TaskStore
|
||||||
from dx_productivity.trial_task_center.version import VERSION
|
from dx_productivity.trial_task_center.version import VERSION
|
||||||
|
|
||||||
@@ -161,10 +162,28 @@ def main(argv: Sequence[str] | None = None) -> int:
|
|||||||
from dx_productivity.trial_task_center.sceneos_cli import run
|
from dx_productivity.trial_task_center.sceneos_cli import run
|
||||||
|
|
||||||
return run(data_root)
|
return run(data_root)
|
||||||
|
try:
|
||||||
|
with gui_instance(data_root) as endpoint:
|
||||||
|
if endpoint is None:
|
||||||
|
return 0
|
||||||
|
return _run_gui(argv, arguments, data_root, endpoint)
|
||||||
|
except (OSError, InstanceUnavailable) as error:
|
||||||
|
message = f'无法打开 DxPartReplace。\n{data_root}\n{error}'
|
||||||
|
if sys.stderr is not None:
|
||||||
|
print(message, file=sys.stderr)
|
||||||
|
if os.name == 'nt' and bool(getattr(sys, 'frozen', False)):
|
||||||
|
import ctypes
|
||||||
|
|
||||||
|
ctypes.windll.user32.MessageBoxW(None, message, 'DxPartReplace', 0x30)
|
||||||
|
return 1
|
||||||
|
|
||||||
|
|
||||||
|
def _run_gui(argv, arguments, data_root, endpoint):
|
||||||
logging_context = configure_logging(data_root)
|
logging_context = configure_logging(data_root)
|
||||||
install_exception_hooks(logging_context)
|
install_exception_hooks(logging_context)
|
||||||
store: TaskStore | None = None
|
store: TaskStore | None = None
|
||||||
window = None
|
window = None
|
||||||
|
activation_server = None
|
||||||
try:
|
try:
|
||||||
database_path = data_root / "task-center.db"
|
database_path = data_root / "task-center.db"
|
||||||
_log_startup(logging_context, data_root, database_path)
|
_log_startup(logging_context, data_root, database_path)
|
||||||
@@ -177,6 +196,16 @@ def main(argv: Sequence[str] | None = None) -> int:
|
|||||||
configure_application_identity(qt_application)
|
configure_application_identity(qt_application)
|
||||||
window = _load_window()(service)
|
window = _load_window()(service)
|
||||||
window.show()
|
window.show()
|
||||||
|
|
||||||
|
def activate():
|
||||||
|
logging_context.logger.info('instance_conflict data_root=%s', data_root)
|
||||||
|
window.setWindowState(window.windowState() & ~Qt.WindowState.WindowMinimized)
|
||||||
|
window.show()
|
||||||
|
window.raise_()
|
||||||
|
window.activateWindow()
|
||||||
|
window.statusBar().showMessage('此数据目录已在使用,已切换到现有窗口。', 6000)
|
||||||
|
|
||||||
|
activation_server = listen_for_activation(endpoint, activate)
|
||||||
if arguments.smoke_test:
|
if arguments.smoke_test:
|
||||||
QTimer.singleShot(0, lambda: (window.close(), qt_application.quit()))
|
QTimer.singleShot(0, lambda: (window.close(), qt_application.quit()))
|
||||||
exit_code = qt_application.exec()
|
exit_code = qt_application.exec()
|
||||||
@@ -187,6 +216,8 @@ def main(argv: Sequence[str] | None = None) -> int:
|
|||||||
logging_context.report_exception("startup", error)
|
logging_context.report_exception("startup", error)
|
||||||
return 1
|
return 1
|
||||||
finally:
|
finally:
|
||||||
|
if activation_server is not None:
|
||||||
|
activation_server.close()
|
||||||
if store is not None:
|
if store is not None:
|
||||||
# The window invalidates queued UI results on close. Finish the
|
# The window invalidates queued UI results on close. Finish the
|
||||||
# remaining read before releasing the shared SQLite connection.
|
# remaining read before releasing the shared SQLite connection.
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
"""Serial, confirmed queue execution with safe between-item pausing."""
|
"""Serial, confirmed queue execution with safe between-item pausing."""
|
||||||
|
|
||||||
from dataclasses import dataclass
|
from dataclasses import dataclass, replace
|
||||||
import json
|
import json
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
import shutil
|
import shutil
|
||||||
@@ -121,6 +121,9 @@ def execute_batch(
|
|||||||
**({'runtime': runtime} if runtime is not None else {})) as project_session:
|
**({'runtime': runtime} if runtime is not None else {})) as project_session:
|
||||||
while not progress.queue_complete:
|
while not progress.queue_complete:
|
||||||
if stop_event.is_set():
|
if stop_event.is_set():
|
||||||
|
if project_session.enabled and project_session.worker is not None:
|
||||||
|
progress = preparer.complete_project_session(task_id, project_session, session, projects)
|
||||||
|
progress = service._synchronize_quick_run_progress(task_id, progress=progress)
|
||||||
backups.commit_prefetched(progress)
|
backups.commit_prefetched(progress)
|
||||||
return BatchRunResult(
|
return BatchRunResult(
|
||||||
progress, True, last_result, tuple(item_messages), tuple(backups.unbacked_project_paths)
|
progress, True, last_result, tuple(item_messages), tuple(backups.unbacked_project_paths)
|
||||||
@@ -133,6 +136,9 @@ def execute_batch(
|
|||||||
backups.prepare(current, progress)
|
backups.prepare(current, progress)
|
||||||
service._batch_feedback = (task_id, progress, f'正在处理 {current.name}')
|
service._batch_feedback = (task_id, progress, f'正在处理 {current.name}')
|
||||||
if stop_event.is_set():
|
if stop_event.is_set():
|
||||||
|
if project_session.enabled and project_session.worker is not None:
|
||||||
|
progress = preparer.complete_project_session(task_id, project_session, session, projects)
|
||||||
|
progress = service._synchronize_quick_run_progress(task_id, progress=progress)
|
||||||
backups.commit_prefetched(progress)
|
backups.commit_prefetched(progress)
|
||||||
return BatchRunResult(
|
return BatchRunResult(
|
||||||
progress, True, last_result, tuple(item_messages), tuple(backups.unbacked_project_paths)
|
progress, True, last_result, tuple(item_messages), tuple(backups.unbacked_project_paths)
|
||||||
@@ -194,10 +200,16 @@ def execute_batch(
|
|||||||
item_messages.append(last_result.message)
|
item_messages.append(last_result.message)
|
||||||
if last_result.progress is None:
|
if last_result.progress is None:
|
||||||
raise TaskCenterError('quick_run_queue_progress', '批量执行器未返回增量进度,队列已停止。')
|
raise TaskCenterError('quick_run_queue_progress', '批量执行器未返回增量进度,队列已停止。')
|
||||||
|
failed_component = (task.primary_project_id and last_result.state in {BATCH_FAILED_STATE, 'batch_skipped'}
|
||||||
|
and session.journal_rows.get(metric['job_id'], {}).get('execution_unit') == 'component')
|
||||||
candidate = last_result.progress
|
candidate = last_result.progress
|
||||||
|
if failed_component and project_session.worker is not None:
|
||||||
|
# Verify the retained prefix before admitting another component.
|
||||||
|
candidate = preparer.complete_project_session(task_id, project_session, session, projects)
|
||||||
|
last_result = replace(last_result, progress=candidate)
|
||||||
project_completed = candidate.completed_project_paths != progress.completed_project_paths
|
project_completed = candidate.completed_project_paths != progress.completed_project_paths
|
||||||
synchronize = (
|
synchronize = (
|
||||||
progress.completed_items == 0
|
(progress.completed_items == 0 and last_result.state != 'pending_save')
|
||||||
or project_completed
|
or project_completed
|
||||||
or candidate.queue_complete
|
or candidate.queue_complete
|
||||||
or last_result.state in {BATCH_FAILED_STATE, BATCH_SAVED_UNVERIFIED_STATE}
|
or last_result.state in {BATCH_FAILED_STATE, BATCH_SAVED_UNVERIFIED_STATE}
|
||||||
@@ -208,7 +220,8 @@ def execute_batch(
|
|||||||
persistence['completed_units'] = 1
|
persistence['completed_units'] = 1
|
||||||
else:
|
else:
|
||||||
updated = candidate
|
updated = candidate
|
||||||
if updated.completed_items <= progress.completed_items or updated.total_items != progress.total_items:
|
if ((updated.completed_items <= progress.completed_items and last_result.state != 'pending_save')
|
||||||
|
or updated.total_items != progress.total_items):
|
||||||
_write_uncertain_flag(preparer.data_root / 'quick-run/uncertain.flag', 'batch_progress_mismatch')
|
_write_uncertain_flag(preparer.data_root / 'quick-run/uncertain.flag', 'batch_progress_mismatch')
|
||||||
raise TaskCenterError('quick_run_queue_progress', '执行器返回后队列进度异常,已停止,避免重复执行。')
|
raise TaskCenterError('quick_run_queue_progress', '执行器返回后队列进度异常,已停止,避免重复执行。')
|
||||||
# Keep every verified step: one project can contain many sheets and rules.
|
# Keep every verified step: one project can contain many sheets and rules.
|
||||||
@@ -233,12 +246,7 @@ def execute_batch(
|
|||||||
progress = updated
|
progress = updated
|
||||||
if task.primary_project_id and last_result.state in {BATCH_FAILED_STATE, 'batch_skipped'}:
|
if task.primary_project_id and last_result.state in {BATCH_FAILED_STATE, 'batch_skipped'}:
|
||||||
row = session.journal_rows.get(metric['job_id'], {})
|
row = session.journal_rows.get(metric['job_id'], {})
|
||||||
if row.get('execution_unit') == 'component':
|
if failed_component:
|
||||||
# A failed component is terminal; rebuild its session before
|
|
||||||
# admitting another UID against the last verified baseline.
|
|
||||||
if project_session.worker is not None:
|
|
||||||
project_session.worker.close()
|
|
||||||
project_session.worker = None
|
|
||||||
from .quick_run import _run_process
|
from .quick_run import _run_process
|
||||||
if journal is None:
|
if journal is None:
|
||||||
raise TaskCenterError('quick_run_uncertain', '缺少失败回执及工程健康证明,暂缓剩余位号。')
|
raise TaskCenterError('quick_run_uncertain', '缺少失败回执及工程健康证明,暂缓剩余位号。')
|
||||||
@@ -266,7 +274,7 @@ def execute_batch(
|
|||||||
feedback = '未命中已跳过,继续下一项' if last_result.state == 'no_match' else (
|
feedback = '未命中已跳过,继续下一项' if last_result.state == 'no_match' else (
|
||||||
'失败已记录,继续下一项'
|
'失败已记录,继续下一项'
|
||||||
if last_result.state == BATCH_FAILED_STATE
|
if last_result.state == BATCH_FAILED_STATE
|
||||||
else '已保存并校验,继续下一项'
|
else '替换已暂存,等待工程统一保存回读' if last_result.state == 'pending_save' else '已保存并校验,继续下一项'
|
||||||
)
|
)
|
||||||
service._batch_feedback = (task_id, progress, feedback)
|
service._batch_feedback = (task_id, progress, feedback)
|
||||||
return BatchRunResult(
|
return BatchRunResult(
|
||||||
|
|||||||
@@ -31,16 +31,19 @@ def write_release_event(root, path, record, phase, *, context=None, reason='batc
|
|||||||
'generation': record.get('generation'), 'desktop': record.get('desktop'),
|
'generation': record.get('generation'), 'desktop': record.get('desktop'),
|
||||||
'cad_pid': record.get('cad_pid'), 'cad_guid': record.get('cad_guid'),
|
'cad_pid': record.get('cad_pid'), 'cad_guid': record.get('cad_guid'),
|
||||||
'reason': reason, 'result': 'releasing' if phase == 'started' else (
|
'reason': reason, 'result': 'releasing' if phase == 'started' else (
|
||||||
'released' if phase == 'succeeded' else 'blocked'),
|
'released' if phase == 'succeeded' else 'isolated' if phase == 'isolated' else 'blocked'),
|
||||||
'elapsed_seconds': elapsed, 'record_path': str(path),
|
'elapsed_seconds': elapsed, 'record_path': str(path),
|
||||||
'desktop_handle_closed': cleanup.get('desktop_handle_closed'),
|
'desktop_handle_closed': cleanup.get('desktop_handle_closed'),
|
||||||
'desktop_disappeared': disappeared, 'cad_exit_code': cad.get('cad_exit_code'),
|
'desktop_disappeared': disappeared, 'cad_exit_code': cad.get('cad_exit_code'),
|
||||||
'quit_helper_exit_code': cad.get('quit_helper_exit_code'),
|
'quit_helper_exit_code': cad.get('quit_helper_exit_code'),
|
||||||
'cad_shutdown': cad, 'shutdown_warning': record.get('shutdown_warning'),
|
'cad_shutdown': cad, 'shutdown_warning': record.get('shutdown_warning'),
|
||||||
'retries': record.get('retries', {}), 'cleanup': cleanup, 'error': str(error)}
|
'retries': record.get('retries', {}), 'release_rechecks': record.get('release_rechecks', []),
|
||||||
|
'cleanup': cleanup, 'error': str(error)}
|
||||||
title = {'started': '开始释放后台资源', 'succeeded': '后台资源释放成功',
|
title = {'started': '开始释放后台资源', 'succeeded': '后台资源释放成功',
|
||||||
'failed': '后台资源释放失败,资源释放待处理'}[phase]
|
'failed': '后台资源释放失败,资源释放待处理',
|
||||||
|
'isolated': '后台写入进程已退出,残留桌面已隔离(未确认释放)'}[phase]
|
||||||
purpose = {'batch_end': '批次结束', 'rebuild': '安全重建', 'manual_retry': '重新清理',
|
purpose = {'batch_end': '批次结束', 'rebuild': '安全重建', 'manual_retry': '重新清理',
|
||||||
|
'automatic_recheck': '自动复核释放',
|
||||||
'restart_recheck': '重启后重新检查'}.get(reason, reason)
|
'restart_recheck': '重启后重新检查'}.get(reason, reason)
|
||||||
cad_text = f"CAD PID={details['cad_pid']}" if details['cad_pid'] else (
|
cad_text = f"CAD PID={details['cad_pid']}" if details['cad_pid'] else (
|
||||||
'CAD 未启动' if record.get('cad_start_requested') is False else
|
'CAD 未启动' if record.get('cad_start_requested') is False else
|
||||||
@@ -56,7 +59,7 @@ def write_release_event(root, path, record, phase, *, context=None, reason='batc
|
|||||||
if error:
|
if error:
|
||||||
message += ' · 原因:' + str(error)
|
message += ' · 原因:' + str(error)
|
||||||
message = message.replace('\r', '\\r').replace('\n', '\\n')
|
message = message.replace('\r', '\\r').replace('\n', '\\n')
|
||||||
level = 'ERROR' if phase == 'failed' else 'INFO'
|
level = 'ERROR' if phase == 'failed' else 'WARNING' if phase == 'isolated' else 'INFO'
|
||||||
timestamp = datetime.now(timezone.utc).isoformat(timespec='milliseconds')
|
timestamp = datetime.now(timezone.utc).isoformat(timespec='milliseconds')
|
||||||
errors = []
|
errors = []
|
||||||
try:
|
try:
|
||||||
|
|||||||
@@ -15,10 +15,38 @@ from .path_access import canonical_path, internal_path, retry_sharing_violation
|
|||||||
# Recovery retains owned native handles after failed cleanup. This registry is
|
# Recovery retains owned native handles after failed cleanup. This registry is
|
||||||
# never an implicit execution context and never contains COM application objects.
|
# never an implicit execution context and never contains COM application objects.
|
||||||
LIVE_RESOURCES = {}
|
LIVE_RESOURCES = {}
|
||||||
|
RESOURCE_RELEASE_BACKOFF_SECONDS = (0.5, 1, 2)
|
||||||
|
|
||||||
|
|
||||||
|
def _observe_release(observe, record):
|
||||||
|
"""Check once immediately, then at most three times after backoff."""
|
||||||
|
record['release_rechecks'] = []
|
||||||
|
for attempt, delay in enumerate((0, *RESOURCE_RELEASE_BACKOFF_SECONDS)):
|
||||||
|
if delay:
|
||||||
|
time.sleep(delay)
|
||||||
|
try:
|
||||||
|
confirmed = observe()
|
||||||
|
except (OSError, TaskCenterError) as error:
|
||||||
|
confirmed, detail = False, str(error)
|
||||||
|
else:
|
||||||
|
detail = ''
|
||||||
|
if attempt:
|
||||||
|
record['release_rechecks'].append({'attempt': attempt, 'delay_seconds': delay,
|
||||||
|
'confirmed': confirmed, 'error': detail})
|
||||||
|
if confirmed:
|
||||||
|
return True
|
||||||
|
return False
|
||||||
|
|
||||||
|
|
||||||
class BatchResourceCleanupError(TaskCenterError):
|
class BatchResourceCleanupError(TaskCenterError):
|
||||||
def __init__(self, message, *, completed_result=None, primary_error=None, cleanup_error=None):
|
def __init__(self, message, *, completed_result=None, primary_error=None, cleanup_error=None):
|
||||||
|
original, seen = primary_error, set()
|
||||||
|
while original is not None and id(original) not in seen:
|
||||||
|
if getattr(original, 'code', None) in {'saved_source_pending', 'saved_source_changed'}:
|
||||||
|
message = str(original) + ';资源收尾异常:' + message
|
||||||
|
break
|
||||||
|
seen.add(id(original))
|
||||||
|
original = getattr(original, 'primary_error', None)
|
||||||
super().__init__('batch_resources_pending', message)
|
super().__init__('batch_resources_pending', message)
|
||||||
self.completed_result = completed_result
|
self.completed_result = completed_result
|
||||||
self.primary_error = primary_error
|
self.primary_error = primary_error
|
||||||
@@ -51,7 +79,7 @@ def _valid_record(record, path):
|
|||||||
and type(record.get('generation')) is int and record['generation'] >= 1
|
and type(record.get('generation')) is int and record['generation'] >= 1
|
||||||
and isinstance(record.get('desktop'), str)
|
and isinstance(record.get('desktop'), str)
|
||||||
and re.fullmatch('dx-[0-9a-f]{32}', record['desktop']) is not None
|
and re.fullmatch('dx-[0-9a-f]{32}', record['desktop']) is not None
|
||||||
and record.get('state') in {'starting', 'ready', 'recycling', 'closing', 'blocked', 'released'}
|
and record.get('state') in {'starting', 'ready', 'recycling', 'closing', 'blocked', 'released', 'isolated'}
|
||||||
and isinstance(processes, list) and all(isinstance(item, dict)
|
and isinstance(processes, list) and all(isinstance(item, dict)
|
||||||
and type(item.get('pid')) is int and item['pid'] > 0
|
and type(item.get('pid')) is int and item['pid'] > 0
|
||||||
and 'creation_time' in item and (item['creation_time'] is None
|
and 'creation_time' in item and (item['creation_time'] is None
|
||||||
@@ -66,14 +94,17 @@ def _valid_record(record, path):
|
|||||||
|
|
||||||
def pending_resources(root):
|
def pending_resources(root):
|
||||||
pending = []
|
pending = []
|
||||||
for path in sorted(internal_path(canonical_path(root) / 'batch-resources').glob('*/session.json')):
|
directory = internal_path(canonical_path(root) / 'batch-resources')
|
||||||
|
paths = (*directory.glob('*/session.json'), *directory.glob('*/isolated-generation-*.json'))
|
||||||
|
for path in sorted(paths):
|
||||||
path = canonical_path(path)
|
path = canonical_path(path)
|
||||||
try:
|
try:
|
||||||
record = json.loads(internal_path(path).read_text(encoding='utf-8'))
|
record = json.loads(internal_path(path).read_text(encoding='utf-8'))
|
||||||
if not _valid_record(record, path):
|
if not _valid_record(record, path):
|
||||||
raise ValueError('invalid resource ownership record')
|
raise ValueError('invalid resource ownership record')
|
||||||
if record.get('state') != 'released' or not _released_evidence(record):
|
if record.get('state') != 'released' or not _released_evidence(record):
|
||||||
pending.append(dict(record, record_path=str(path)))
|
pending.append(dict(record, record_path=str(path),
|
||||||
|
blocking=not (record.get('state') == 'isolated' and _isolation_evidence(record))))
|
||||||
except (OSError, ValueError, TypeError) as error:
|
except (OSError, ValueError, TypeError) as error:
|
||||||
pending.append({'state': 'blocked', 'record_path': str(path), 'error': str(error)})
|
pending.append({'state': 'blocked', 'record_path': str(path), 'error': str(error)})
|
||||||
import sys
|
import sys
|
||||||
@@ -109,9 +140,76 @@ def pending_resources(root):
|
|||||||
return tuple(pending)
|
return tuple(pending)
|
||||||
|
|
||||||
|
|
||||||
|
def resource_blockers(records):
|
||||||
|
"""Only a validated isolated desktop warning may leave the resource gate open."""
|
||||||
|
return tuple(item for item in records
|
||||||
|
if not (item.get('state') == 'isolated' and item.get('blocking') is False))
|
||||||
|
|
||||||
|
|
||||||
|
def blocking_resources(root):
|
||||||
|
return resource_blockers(pending_resources(root))
|
||||||
|
|
||||||
|
|
||||||
|
def writer_identities(record):
|
||||||
|
identities = []
|
||||||
|
for item in [*record.get('writer_identities', ()), *record.get('processes', ()),
|
||||||
|
*([record['cad_process']] if record.get('cad_process') else [])]:
|
||||||
|
if item not in identities:
|
||||||
|
identities.append(item)
|
||||||
|
if record.get('cad_pid') is not None and not any(
|
||||||
|
item.get('pid') == record['cad_pid'] for item in identities):
|
||||||
|
raise ValueError('CAD process identity is missing')
|
||||||
|
if any(type(item.get('pid')) is not int or item['pid'] <= 0
|
||||||
|
or not isinstance(item.get('creation_time'), str) or not item['creation_time']
|
||||||
|
for item in identities):
|
||||||
|
raise ValueError('Exact writer process identity is missing')
|
||||||
|
return identities
|
||||||
|
|
||||||
|
|
||||||
|
def isolation_proof(record):
|
||||||
|
"""Certify handle closure and exact writer exit, never a desktop disappearance."""
|
||||||
|
cleanup = record.get('cleanup') or {}
|
||||||
|
if cleanup.get('desktop_lease_pending') is True:
|
||||||
|
raise ValueError('Managed desktop lease is still held')
|
||||||
|
if cleanup.get('desktop_lease'):
|
||||||
|
from .desktop_slot import returned_lease_intact
|
||||||
|
if not returned_lease_intact(cleanup['desktop_lease'], record['desktop']):
|
||||||
|
raise ValueError('Managed desktop return proof changed')
|
||||||
|
if (cleanup.get('desktop_handle_closed') is not True
|
||||||
|
or cleanup.get('owned_cleanup_complete') is not True):
|
||||||
|
raise ValueError('Owned resource cleanup is not proven')
|
||||||
|
identities = writer_identities(record)
|
||||||
|
if not all(_process_gone(item) for item in identities):
|
||||||
|
raise ValueError('Owned writer process is still active')
|
||||||
|
return {'session_id': record['session_id'], 'generation': record['generation'],
|
||||||
|
'desktop': record['desktop'], 'desktop_handle_closed': True, 'desktop_released': False,
|
||||||
|
'processes_exited': True, 'processes': identities, 'observed_at': time.time()}
|
||||||
|
|
||||||
|
|
||||||
|
def _isolation_evidence(record):
|
||||||
|
try:
|
||||||
|
proof = record.get('isolation_proof', {})
|
||||||
|
current = isolation_proof(record)
|
||||||
|
return (isinstance(proof, dict) and all(proof.get(key) == current[key] for key in
|
||||||
|
('session_id', 'generation', 'desktop', 'desktop_handle_closed', 'desktop_released',
|
||||||
|
'processes_exited', 'processes')))
|
||||||
|
except Exception:
|
||||||
|
return False
|
||||||
|
|
||||||
|
|
||||||
def _released_evidence(record):
|
def _released_evidence(record):
|
||||||
"""A state label alone must never reopen the physical resource gate."""
|
"""A state label alone must never reopen the physical resource gate."""
|
||||||
proof = record.get('release_proof', {})
|
proof = record.get('release_proof', {})
|
||||||
|
cleanup = record.get('cleanup') or {}
|
||||||
|
if (proof.get('generation') == record['generation'] and proof.get('desktop_not_acquired') is True
|
||||||
|
and cleanup.get('desktop_not_acquired') is True and cleanup.get('desktop_handle_closed') is True
|
||||||
|
and cleanup.get('owned_cleanup_complete') is True and not cleanup.get('errors')
|
||||||
|
and record.get('cad_pid') is None and not writer_identities(record)):
|
||||||
|
return True
|
||||||
|
if cleanup.get('desktop_lease'):
|
||||||
|
from .desktop_slot import returned_lease_intact
|
||||||
|
if not returned_lease_intact(cleanup['desktop_lease'], record['desktop']):
|
||||||
|
return False
|
||||||
if (isinstance(proof, dict) and proof.get('generation') == record['generation']
|
if (isinstance(proof, dict) and proof.get('generation') == record['generation']
|
||||||
and proof.get('desktop_released') is True and proof.get('processes_exited') is True):
|
and proof.get('desktop_released') is True and proof.get('processes_exited') is True):
|
||||||
return True
|
return True
|
||||||
@@ -126,7 +224,7 @@ def _released_evidence(record):
|
|||||||
|
|
||||||
|
|
||||||
def guard_pending_resources(root):
|
def guard_pending_resources(root):
|
||||||
if pending_resources(root):
|
if blocking_resources(root):
|
||||||
raise BatchResourceCleanupError('上一批资源尚未确认释放;请先重试释放资源,再开始新批次。')
|
raise BatchResourceCleanupError('上一批资源尚未确认释放;请先重试释放资源,再开始新批次。')
|
||||||
|
|
||||||
|
|
||||||
@@ -160,6 +258,31 @@ def _process_gone(identity):
|
|||||||
handle.Close()
|
handle.Close()
|
||||||
|
|
||||||
|
|
||||||
|
def _historical_writer_trees_closed(record, path):
|
||||||
|
cleanup = record.get('cleanup') or {}
|
||||||
|
if cleanup.get('owned_cleanup_complete') is True:
|
||||||
|
return True
|
||||||
|
if not record.get('processes'):
|
||||||
|
return record.get('cad_pid') is None and record.get('cad_start_requested') is not True
|
||||||
|
if not record.get('cad_process') or record['processes'] != [record['cad_process']]:
|
||||||
|
return False # Older Job snapshots only bind the CAD root's process creation time.
|
||||||
|
# Older blocked records can miss the latest desktop cleanup while already
|
||||||
|
# retaining a complete per-CAD Job accounting record.
|
||||||
|
marker = path.parent / f"generation-{record['generation']}" / 'private-desktop.json'
|
||||||
|
native = json.loads(internal_path(marker).read_text(encoding='utf-8'))
|
||||||
|
if ((native.get('token'), native.get('guid'), native.get('desktop'), native.get('cad_process'))
|
||||||
|
!= (record.get('cad_token'), record.get('cad_guid'), record.get('desktop'), record.get('cad_process'))
|
||||||
|
or not record.get('cad_token') or not record.get('cad_guid') or not record.get('cad_process')):
|
||||||
|
return False
|
||||||
|
observations = (native.get('desktop_cleanup') or {}).get('processes', ())
|
||||||
|
return sum(observation.get('pid') == record['cad_pid']
|
||||||
|
and observation.get('job_membership_verified') is True
|
||||||
|
and observation.get('job_active_processes') == 0
|
||||||
|
and observation.get('job_handle_closed') is True
|
||||||
|
and observation.get('unconfirmed_descendant_handles') == 0
|
||||||
|
for observation in observations) == 1
|
||||||
|
|
||||||
|
|
||||||
def cleanup_pending_resources(root, *, logging_context=None, retry_failed=False):
|
def cleanup_pending_resources(root, *, logging_context=None, retry_failed=False):
|
||||||
from .isolated_desktop import _Win32Api
|
from .isolated_desktop import _Win32Api
|
||||||
from .batch_release_log import write_release_event
|
from .batch_release_log import write_release_event
|
||||||
@@ -192,6 +315,8 @@ def cleanup_pending_resources(root, *, logging_context=None, retry_failed=False)
|
|||||||
continue
|
continue
|
||||||
live = LIVE_RESOURCES.get(str(path))
|
live = LIVE_RESOURCES.get(str(path))
|
||||||
if live is not None:
|
if live is not None:
|
||||||
|
if live.record.get('state') != 'blocked':
|
||||||
|
continue # An active generation has not asked for release.
|
||||||
try:
|
try:
|
||||||
live.close(reason='manual_retry' if retry_failed else 'resource_recheck')
|
live.close(reason='manual_retry' if retry_failed else 'resource_recheck')
|
||||||
except Exception:
|
except Exception:
|
||||||
@@ -216,7 +341,7 @@ def cleanup_pending_resources(root, *, logging_context=None, retry_failed=False)
|
|||||||
if not record.get('session_id'):
|
if not record.get('session_id'):
|
||||||
continue # Corrupt evidence cannot authorize resource actions.
|
continue # Corrupt evidence cannot authorize resource actions.
|
||||||
log('started')
|
log('started')
|
||||||
identities = list(record.get('processes', ()))
|
identities = writer_identities(record)
|
||||||
cad_identity = record.get('cad_process')
|
cad_identity = record.get('cad_process')
|
||||||
if record.get('cad_pid') is not None:
|
if record.get('cad_pid') is not None:
|
||||||
if (not isinstance(cad_identity, dict) or cad_identity.get('pid') != record['cad_pid']
|
if (not isinstance(cad_identity, dict) or cad_identity.get('pid') != record['cad_pid']
|
||||||
@@ -228,13 +353,54 @@ def cleanup_pending_resources(root, *, logging_context=None, retry_failed=False)
|
|||||||
if not all(_process_gone(item) for item in identities):
|
if not all(_process_gone(item) for item in identities):
|
||||||
log('failed', '记录中的进程仍未确认退出')
|
log('failed', '记录中的进程仍未确认退出')
|
||||||
continue
|
continue
|
||||||
|
if not _historical_writer_trees_closed(record, path):
|
||||||
|
log('failed', '缺少历史写入进程树退出证明')
|
||||||
|
continue
|
||||||
desktop = record.get('desktop')
|
desktop = record.get('desktop')
|
||||||
if desktop:
|
if (record.get('cleanup') or {}).get('desktop_lease'):
|
||||||
_Win32Api().confirm_desktop_released(desktop)
|
# A return belongs to this past lease, even while the same name
|
||||||
|
# is now serving another batch. Never open or stop its new owner.
|
||||||
|
proof = isolation_proof(record)
|
||||||
|
from .desktop_slot import managed_desktop_disappeared
|
||||||
|
receipt = record['cleanup']['desktop_lease']
|
||||||
|
absent = _observe_release(lambda: managed_desktop_disappeared(receipt), record)
|
||||||
|
if not absent:
|
||||||
|
record.pop('record_path', None)
|
||||||
|
record.update(state='isolated', blocking=False, isolation_proof=proof)
|
||||||
|
write_record(path, record)
|
||||||
|
log('isolated')
|
||||||
|
continue
|
||||||
|
elif desktop:
|
||||||
|
from .desktop_slot import observe_current_desktop_name
|
||||||
|
api = None
|
||||||
|
|
||||||
|
def observe():
|
||||||
|
nonlocal api
|
||||||
|
managed = observe_current_desktop_name(desktop) if os.name == 'nt' else None
|
||||||
|
if managed is not None:
|
||||||
|
return managed
|
||||||
|
if api is None:
|
||||||
|
api = _Win32Api()
|
||||||
|
api.confirm_desktop_released(desktop)
|
||||||
|
return True
|
||||||
|
|
||||||
|
if not _observe_release(observe, record):
|
||||||
|
# A residual desktop name is only a warning after owned
|
||||||
|
# handle closure and independently revalidated writer exit.
|
||||||
|
proof = isolation_proof(record)
|
||||||
|
record.pop('record_path', None)
|
||||||
|
warning = '桌面仍在或同名桌面正在使用,未取得桌面消失证明'
|
||||||
|
record.update(state='isolated', blocking=False, isolation_proof=proof,
|
||||||
|
isolation_warning=warning)
|
||||||
|
write_record(path, record)
|
||||||
|
log('isolated', warning)
|
||||||
|
continue
|
||||||
# After restart only confirm disappearance. Never attach to COM,
|
# After restart only confirm disappearance. Never attach to COM,
|
||||||
# close a project, or terminate a PID whose handles we no longer own.
|
# close a project, or terminate a PID whose handles we no longer own.
|
||||||
record.pop('record_path', None)
|
record.pop('record_path', None)
|
||||||
record = dict(record, state='released', reconciled=True, released_at=time.time(),
|
record = dict(record, state='released', blocking=False, reconciled=True, released_at=time.time(),
|
||||||
|
release_results={'mentor_released': True, 'desktop_released': True},
|
||||||
|
release_state={'mentor': 'released', 'desktop': 'released'}, wait_reason='',
|
||||||
release_proof={'generation': record['generation'], 'desktop_released': True,
|
release_proof={'generation': record['generation'], 'desktop_released': True,
|
||||||
'processes_exited': True, 'processes': identities, 'method': 'restart_observation'})
|
'processes_exited': True, 'processes': identities, 'method': 'restart_observation'})
|
||||||
write_record(path, record)
|
write_record(path, record)
|
||||||
|
|||||||
@@ -11,7 +11,8 @@ from threading import Lock
|
|||||||
from uuid import UUID, uuid4
|
from uuid import UUID, uuid4
|
||||||
|
|
||||||
from .batch_resources import (BatchResourceCleanupError, LIVE_RESOURCES, cleanup_pending_resources,
|
from .batch_resources import (BatchResourceCleanupError, LIVE_RESOURCES, cleanup_pending_resources,
|
||||||
guard_pending_resources, pending_resources, process_identity, project_checkpoint_released, write_record)
|
guard_pending_resources, pending_resources, process_identity, project_checkpoint_released, write_record,
|
||||||
|
isolation_proof, RESOURCE_RELEASE_BACKOFF_SECONDS)
|
||||||
from .errors import TaskCenterError
|
from .errors import TaskCenterError
|
||||||
from .path_access import canonical_path, internal_path, legacy_path
|
from .path_access import canonical_path, internal_path, legacy_path
|
||||||
from .isolated_desktop import PrivateDesktop, ProcessNotStartedError
|
from .isolated_desktop import PrivateDesktop, ProcessNotStartedError
|
||||||
@@ -192,7 +193,9 @@ class BatchCadRuntime:
|
|||||||
|
|
||||||
def _save(self, **values):
|
def _save(self, **values):
|
||||||
record = dict(self.record, **values)
|
record = dict(self.record, **values)
|
||||||
write_record(self.path, record)
|
# Prelaunch retries can change runtime state before it owns resources.
|
||||||
|
if record['generation']:
|
||||||
|
write_record(self.path, record)
|
||||||
self.record = record
|
self.record = record
|
||||||
|
|
||||||
def _timing(self, phase, started, **details):
|
def _timing(self, phase, started, **details):
|
||||||
@@ -202,21 +205,40 @@ class BatchCadRuntime:
|
|||||||
def _ensure_desktop(self, abort_event=None):
|
def _ensure_desktop(self, abort_event=None):
|
||||||
if self.record['state'] == 'blocked':
|
if self.record['state'] == 'blocked':
|
||||||
raise BatchResourceCleanupError('当前批次资源已阻断,不能启动新的工作进程。')
|
raise BatchResourceCleanupError('当前批次资源已阻断,不能启动新的工作进程。')
|
||||||
|
if self.record['state'] == 'isolated':
|
||||||
|
if self.desktop is not None:
|
||||||
|
raise BatchResourceCleanupError('隔离桌面已停止使用,请为后续工程创建新的运行会话。')
|
||||||
|
write_record(self.path.parent / f'isolated-generation-{self.generation}.json', self.record)
|
||||||
if self.desktop is None:
|
if self.desktop is None:
|
||||||
check_cancelled(self.stop_event if abort_event is None else abort_event)
|
check_cancelled(self.stop_event if abort_event is None else abort_event)
|
||||||
self.generation += 1
|
generation = self.generation + 1
|
||||||
name = 'dx-' + uuid4().hex
|
name = 'dx-' + uuid4().hex
|
||||||
self._save(state='starting', generation=self.generation, desktop=name,
|
desktop = (self.desktop_factory(name, enabled=True, managed=True)
|
||||||
processes=[], cad_pid=None, cad_guid=None, checkpoints={}, native_operations={},
|
if self.desktop_factory is PrivateDesktop else self.desktop_factory(name, enabled=True))
|
||||||
|
# The factory does not acquire a desktop. Commit the starting
|
||||||
|
# record before assigning cleanup ownership or entering it.
|
||||||
|
self._save(state='starting', generation=generation, desktop=desktop.name,
|
||||||
|
processes=[], writer_identities=[], cad_pid=None, cad_guid=None, checkpoints={}, native_operations={},
|
||||||
|
blocking=True, isolation_proof=None,
|
||||||
|
stopping_reason='', wait_reason='', primary_error=None,
|
||||||
cad_process=None, cad_token=None, cad_shutdown=None, cad_start_requested=False, cleanup=None,
|
cad_process=None, cad_token=None, cad_shutdown=None, cad_start_requested=False, cleanup=None,
|
||||||
|
release_rechecks=[],
|
||||||
release_state={'mentor': 'not_started', 'desktop': 'pending'})
|
release_state={'mentor': 'not_started', 'desktop': 'pending'})
|
||||||
|
self.generation = generation
|
||||||
|
self.desktop = desktop
|
||||||
LIVE_RESOURCES[str(self.path)] = self
|
LIVE_RESOURCES[str(self.path)] = self
|
||||||
self.desktop = self.desktop_factory(name, enabled=True)
|
|
||||||
started = time.monotonic()
|
started = time.monotonic()
|
||||||
try:
|
try:
|
||||||
self.desktop.__enter__()
|
self.desktop.__enter__()
|
||||||
except Exception:
|
except Exception:
|
||||||
self._save(state='blocked', error='private desktop startup failed')
|
if getattr(self.desktop, '_slot', None) is not None and not self.desktop._slot_acquired:
|
||||||
|
self.desktop.close()
|
||||||
|
self._save(state='released', blocking=False, cleanup=self.desktop.cleanup_record,
|
||||||
|
release_proof=dict(generation=self.generation, desktop_not_acquired=True))
|
||||||
|
self.desktop = None
|
||||||
|
LIVE_RESOURCES.pop(str(self.path), None)
|
||||||
|
else:
|
||||||
|
self._save(state='blocked', error='private desktop startup failed')
|
||||||
raise
|
raise
|
||||||
self._timing('desktop_start', started)
|
self._timing('desktop_start', started)
|
||||||
self._save(state='ready')
|
self._save(state='ready')
|
||||||
@@ -226,6 +248,8 @@ class BatchCadRuntime:
|
|||||||
identity = process_identity(process)
|
identity = process_identity(process)
|
||||||
if identity not in self.record['processes']:
|
if identity not in self.record['processes']:
|
||||||
self.record['processes'].append(identity)
|
self.record['processes'].append(identity)
|
||||||
|
if identity not in self.record.setdefault('writer_identities', []):
|
||||||
|
self.record['writer_identities'].append(identity)
|
||||||
self._save()
|
self._save()
|
||||||
|
|
||||||
def _release_process(self, process, *, desktop=None, generation=None):
|
def _release_process(self, process, *, desktop=None, generation=None):
|
||||||
@@ -245,6 +269,9 @@ class BatchCadRuntime:
|
|||||||
cad_process = getattr(self.cad, 'cad', None)
|
cad_process = getattr(self.cad, 'cad', None)
|
||||||
if cad_process is not None and cad_process not in processes:
|
if cad_process is not None and cad_process not in processes:
|
||||||
processes.append(cad_process)
|
processes.append(cad_process)
|
||||||
|
for process in getattr(self.cad, '_retained_processes', ()):
|
||||||
|
if process not in processes:
|
||||||
|
processes.append(process)
|
||||||
if not processes:
|
if not processes:
|
||||||
cleanup = getattr(self.desktop, 'cleanup_record', None) or {}
|
cleanup = getattr(self.desktop, 'cleanup_record', None) or {}
|
||||||
# Closing our handle follows owned-process cleanup. An external
|
# Closing our handle follows owned-process cleanup. An external
|
||||||
@@ -401,14 +428,107 @@ class BatchCadRuntime:
|
|||||||
def _checkpoint(self, root, project, attempt_id):
|
def _checkpoint(self, root, project, attempt_id):
|
||||||
self.cad.checkpoint(root / ('cad-closed-' + attempt_id + '.json'))
|
self.cad.checkpoint(root / ('cad-closed-' + attempt_id + '.json'))
|
||||||
key = str(root).casefold()
|
key = str(root).casefold()
|
||||||
self.record['checkpoints'][key] = attempt_id
|
checkpoint = {'version': 1, 'resource_record': str(self.path),
|
||||||
self._save(state='ready')
|
|
||||||
write_record(root / 'project-checkpoint.json', {'version': 1, 'resource_record': str(self.path),
|
|
||||||
'session_id': self.session_id, 'generation': self.generation, 'attempt_id': attempt_id,
|
'session_id': self.session_id, 'generation': self.generation, 'attempt_id': attempt_id,
|
||||||
'evidence_root': str(root), 'project_path': str(project), 'project_closed': True,
|
'evidence_root': str(root), 'project_path': str(project), 'project_closed': True,
|
||||||
'worker_closed': True, 'cad_pid': self.record['cad_pid'], 'cad_guid': self.record['cad_guid']})
|
'worker_closed': True, 'cad_pid': self.record['cad_pid'], 'cad_guid': self.record['cad_guid']}
|
||||||
|
request_path = internal_path(root / 'project-session.request')
|
||||||
|
if request_path.is_file():
|
||||||
|
request = request_path.read_text(encoding='utf-8-sig').strip().split('\t')
|
||||||
|
if (len(request) == 3 and len(request[0]) == 32
|
||||||
|
and all(character in '0123456789abcdef' for character in request[0])
|
||||||
|
and canonical_path(request[1]) == project):
|
||||||
|
marker = internal_path(root / ('project-commit-' + request[0] + '.tsv'))
|
||||||
|
if marker.is_file():
|
||||||
|
from .execution_proof import capture_project_commit, bind_project_commit_source
|
||||||
|
from .quick_run import _decode_vbs_field
|
||||||
|
rows = [line.split('\t') for line in marker.read_text(encoding='utf-8-sig').splitlines() if line]
|
||||||
|
if (not rows or len(rows[0]) != 3 or rows[0][0] != request[0]
|
||||||
|
or rows[0][2] not in {'project_verified', 'project_saved'}
|
||||||
|
or canonical_path(_decode_vbs_field(rows[0][1])) != project
|
||||||
|
or any(len(row) != 2 for row in rows[1:])):
|
||||||
|
raise WorkerMonitorError('native project commit marker is not bound to the closed project')
|
||||||
|
jobs = [row[0] for row in rows[1:]]
|
||||||
|
expected_jobs = [record['job_id'] for _, record in self._current_attempts]
|
||||||
|
expected_jobs = expected_jobs[expected_jobs.index(self.record['active_job']):]
|
||||||
|
if not jobs or len(set(jobs)) != len(jobs) or jobs != expected_jobs[:len(jobs)]:
|
||||||
|
raise WorkerMonitorError('native project commit marker does not cover an authorized prefix')
|
||||||
|
saved_only = rows[0][2] == 'project_saved'
|
||||||
|
allowed_outcomes = {'pending_save', 'no_match'} if saved_only else {'saved_ok', 'no_match'}
|
||||||
|
if any(row[1] not in allowed_outcomes for row in rows[1:]):
|
||||||
|
raise WorkerMonitorError('native project commit marker has an invalid outcome')
|
||||||
|
proof = capture_project_commit(self.root, root, {'session_token': request[0],
|
||||||
|
'project_path': str(project).casefold(), 'jobs_json': json.dumps(jobs)})
|
||||||
|
proof['marker_sha256'] = hashlib.sha256(marker.read_bytes()).hexdigest()
|
||||||
|
proof['files'].append({'path': str(canonical_path(marker)), 'sha256': proof['marker_sha256']})
|
||||||
|
readback_names = []
|
||||||
|
for job, outcome in proof['outcomes'].items():
|
||||||
|
if saved_only:
|
||||||
|
from .batch_attempt import read_attempt
|
||||||
|
path, expected = next((path, expected) for path, expected in self._current_attempts
|
||||||
|
if expected['job_id'] == job)
|
||||||
|
actual = read_attempt(path)
|
||||||
|
if any(actual.get(name) != value for name, value in expected.items() if name != 'state'):
|
||||||
|
raise WorkerMonitorError('saved project attempt identity changed')
|
||||||
|
if outcome == 'no_match' and actual['state'] != 'prepared':
|
||||||
|
raise WorkerMonitorError('saved project no-match outcome has a possible native write')
|
||||||
|
snapshot = internal_path(root / ('snapshot-' + job + '.tsv'))
|
||||||
|
report_path = internal_path(str(snapshot) + '.native.json')
|
||||||
|
if snapshot.exists():
|
||||||
|
if b'X\tsaved_netlist_v1' not in snapshot.read_bytes().splitlines():
|
||||||
|
raise WorkerMonitorError('saved project snapshot does not authorize native export validation')
|
||||||
|
readback_names.append(snapshot.name)
|
||||||
|
if outcome in {'saved_ok', 'pending_save'} or report_path.exists():
|
||||||
|
report = json.loads(report_path.read_text(encoding='utf-8'))
|
||||||
|
native = report.get('batch_attempt', {})
|
||||||
|
if (report.get('ok') is not True
|
||||||
|
or outcome in {'saved_ok', 'pending_save'} and report.get('stage') != 'native_replace_applied'
|
||||||
|
or any(native.get(name) != expected[name] for name in
|
||||||
|
('session_id', 'generation', 'attempt_id', 'task_id', 'job_id'))
|
||||||
|
or canonical_path(native.get('project_path', '')) != project):
|
||||||
|
raise WorkerMonitorError('saved project native write attempt is not bound')
|
||||||
|
readback_names.append(report_path.name)
|
||||||
|
if outcome in {'saved_ok', 'pending_save'}:
|
||||||
|
if not snapshot.is_file() or actual['state'] != 'mutation_possible':
|
||||||
|
raise WorkerMonitorError('saved project applied write lacks its original mutation attempt')
|
||||||
|
readback_names.append('writer-expectations-' + job + '.tsv')
|
||||||
|
proof.setdefault('batch_attempts', []).append({'path': str(path), 'expected': expected})
|
||||||
|
proof['files'].append({'path': str(path), 'sha256': hashlib.sha256(internal_path(path).read_bytes()).hexdigest()})
|
||||||
|
else:
|
||||||
|
readback_names.append('post-state-' + job + '.tsv')
|
||||||
|
if not saved_only and outcome == 'saved_ok':
|
||||||
|
readback_names.extend(('snapshot-' + job + '.tsv', 'snapshot-' + job + '.tsv.native.json',
|
||||||
|
'value-readback-' + job + '.tsv'))
|
||||||
|
proof['readback_files'] = {name: hashlib.sha256(internal_path(root / name).read_bytes()).hexdigest()
|
||||||
|
for name in readback_names}
|
||||||
|
proof['native_attempt'] = {'session_id': self.session_id, 'generation': self.generation,
|
||||||
|
'attempt_id': attempt_id}
|
||||||
|
if saved_only:
|
||||||
|
proof.update(marker_state='project_saved', saved_only=True, validation_required='saved_netlist_v1',
|
||||||
|
native_outcomes=dict(rows[1:]), outcomes=dict(rows[1:]))
|
||||||
|
# Keep the saved marker and attempt evidence before any file-lock wait.
|
||||||
|
write_record(root / 'project-save-pending.json', dict(checkpoint, project_commit_pending=proof))
|
||||||
|
proof = bind_project_commit_source(proof, self.root, root, project,
|
||||||
|
stop_event=self.stop_event, release_mentor=self._release_saved_source_owner if saved_only else None)
|
||||||
|
checkpoint['project_commit_source'] = proof
|
||||||
|
write_record(root / 'project-checkpoint.json', checkpoint)
|
||||||
|
self.record['checkpoints'][key] = attempt_id
|
||||||
|
self._save()
|
||||||
self._active_attempts = []
|
self._active_attempts = []
|
||||||
|
|
||||||
|
def _release_saved_source_owner(self, error):
|
||||||
|
"""Only a closed project's read handoff may recycle an idle CAD here."""
|
||||||
|
try:
|
||||||
|
self.close(rebuilding=True, reason='saved_source_locked')
|
||||||
|
except Exception as cleanup:
|
||||||
|
self.record['primary_error'] = {'type': type(error).__name__, 'code': error.code, 'message': str(error)}
|
||||||
|
try:
|
||||||
|
self._save()
|
||||||
|
except Exception as diagnostic:
|
||||||
|
error.add_note('资源收尾记录写入失败:' + str(diagnostic))
|
||||||
|
raise BatchResourceCleanupError(str(cleanup), primary_error=error, cleanup_error=cleanup) from cleanup
|
||||||
|
self.desktop = self.cad = None
|
||||||
|
|
||||||
def _certify_unlaunched_worker(self, root, project, command, attempt_id, expected, before, inputs, *, failure=None,
|
def _certify_unlaunched_worker(self, root, project, command, attempt_id, expected, before, inputs, *, failure=None,
|
||||||
worker_creation_rejected=False):
|
worker_creation_rejected=False):
|
||||||
"""Certify no worker was created, using exact launch and release provenance."""
|
"""Certify no worker was created, using exact launch and release provenance."""
|
||||||
@@ -514,6 +634,11 @@ class BatchCadRuntime:
|
|||||||
cooperative_abort=cooperative_abort, process_factory=start_worker,
|
cooperative_abort=cooperative_abort, process_factory=start_worker,
|
||||||
**({'owner_loss_path': self.path.parent / 'owner-loss.json'} if self.read_only else {}),
|
**({'owner_loss_path': self.path.parent / 'owner-loss.json'} if self.read_only else {}),
|
||||||
**({'force_control': self.stop_event} if hasattr(self.stop_event, 'force_event') else {}))
|
**({'force_control': self.stop_event} if hasattr(self.stop_event, 'force_event') else {}))
|
||||||
|
if result.returncode == 75 and not self.read_only:
|
||||||
|
result.prewrite_pause = self._certify_prewrite_pause(
|
||||||
|
root, project, attempt_id, expected, before, inputs,
|
||||||
|
getattr(result, 'prewrite_pause', {}), abort_event)
|
||||||
|
return result
|
||||||
if result.returncode == 74 and not self.read_only:
|
if result.returncode == 74 and not self.read_only:
|
||||||
from .batch_attempt import can_retry_attempt
|
from .batch_attempt import can_retry_attempt
|
||||||
pause = getattr(result, 'startup_pause', {})
|
pause = getattr(result, 'startup_pause', {})
|
||||||
@@ -643,6 +768,92 @@ class BatchCadRuntime:
|
|||||||
self.close(rebuilding=True) # Prove disappearance before creating another.
|
self.close(rebuilding=True) # Prove disappearance before creating another.
|
||||||
self.desktop = self.cad = None
|
self.desktop = self.cad = None
|
||||||
|
|
||||||
|
def _certify_prewrite_pause(self, root, project, attempt_id, expected, before, inputs, pause, abort_event):
|
||||||
|
from .batch_attempt import can_retry_attempt, read_attempt
|
||||||
|
from .discovery_cache import project_fingerprint
|
||||||
|
from .project_session_health import _source_parameters
|
||||||
|
from .quick_run import _decode_vbs_field
|
||||||
|
try:
|
||||||
|
request_path = internal_path(root / 'project-session.request')
|
||||||
|
request_bytes = request_path.read_bytes()
|
||||||
|
request = request_bytes.decode('utf-8-sig').strip().split('\t')
|
||||||
|
original = inputs['project-session.request'].decode('utf-8-sig').strip().split('\t')
|
||||||
|
if (len(request) != 3 or len(original) != 3 or request[:2] != original[:2]
|
||||||
|
or pause.get('session_token') != request[0] or len(request[0]) != 32
|
||||||
|
or pause.get('job_id') != request[2] or canonical_path(request[1]) != project
|
||||||
|
or canonical_path(pause.get('project_path', '')) != project
|
||||||
|
or pause.get('worker_tree_exited') is not True
|
||||||
|
or type(pause.get('sequence')) is not int or pause['sequence'] <= 0
|
||||||
|
or not ((abort_event is not None and abort_event.is_set())
|
||||||
|
or (self.stop_event is not None and self.stop_event.is_set()))
|
||||||
|
or getattr(getattr(self.stop_event, 'force_event', None), 'is_set', lambda: False)()
|
||||||
|
or internal_path(root / 'command.tsv').read_bytes() != inputs['command.tsv']):
|
||||||
|
raise ValueError('prewrite pause ownership is not bound')
|
||||||
|
selected = [(path, record) for path, record in expected if record['job_id'] == request[2]]
|
||||||
|
if len(selected) != 1 or not can_retry_attempt(*selected[0]):
|
||||||
|
raise ValueError('current paused job may have mutated')
|
||||||
|
jobs = [record['job_id'] for _, record in expected]
|
||||||
|
prefix_jobs = set(jobs[:jobs.index(request[2])])
|
||||||
|
mutated = set()
|
||||||
|
for path, record in expected:
|
||||||
|
actual = read_attempt(path)
|
||||||
|
if any(actual.get(key) != value for key, value in record.items() if key != 'state'):
|
||||||
|
raise ValueError('batch attempt identity changed')
|
||||||
|
if actual['state'] == 'mutation_possible':
|
||||||
|
mutated.add(record['job_id'])
|
||||||
|
marker_path = root / ('project-pause-' + request[0] + '.tsv')
|
||||||
|
marker = internal_path(marker_path).read_text(encoding='utf-8-sig').strip().split('\t')
|
||||||
|
if (len(marker) != 4 or marker[0] != request[0] or marker[2:] != [request[2], 'prewrite_closed']
|
||||||
|
or canonical_path(_decode_vbs_field(marker[1])) != project):
|
||||||
|
raise ValueError('prewrite project closure marker is missing or stale')
|
||||||
|
manifest_path = root / ('project-commit-' + request[0] + '.tsv')
|
||||||
|
committed = {}
|
||||||
|
prefix_marker_state = None
|
||||||
|
files = [marker_path, *(path for path, _ in expected)]
|
||||||
|
if internal_path(manifest_path).exists():
|
||||||
|
rows = [line.split('\t') for line in internal_path(manifest_path).read_text(encoding='utf-8-sig').splitlines()]
|
||||||
|
if (not rows or len(rows[0]) != 3 or rows[0][0] != request[0]
|
||||||
|
or canonical_path(_decode_vbs_field(rows[0][1])) != project
|
||||||
|
or rows[0][2] not in {'project_verified', 'project_saved'}):
|
||||||
|
raise ValueError('committed prefix manifest is not bound')
|
||||||
|
prefix_marker_state = rows[0][2]
|
||||||
|
allowed_outcomes = {'pending_save', 'no_match'} if prefix_marker_state == 'project_saved' else {'saved_ok', 'no_match'}
|
||||||
|
for row in rows[1:]:
|
||||||
|
if (len(row) != 2 or row[0] not in prefix_jobs or row[0] in committed
|
||||||
|
or row[1] not in allowed_outcomes):
|
||||||
|
raise ValueError('committed prefix manifest contains an unrelated result')
|
||||||
|
committed[row[0]] = row[1]
|
||||||
|
files.append(manifest_path)
|
||||||
|
after = project_fingerprint(project, self.root)
|
||||||
|
if (after is None or not mutated <= committed.keys()
|
||||||
|
or not committed and (before is None or before != after)):
|
||||||
|
raise ValueError('source changes lack a verified committed prefix')
|
||||||
|
self._checkpoint(root, project, attempt_id)
|
||||||
|
files.append(root / 'project-checkpoint.json')
|
||||||
|
current = internal_path(root / 'current-command.tsv')
|
||||||
|
status = internal_path(root / 'status.tsv')
|
||||||
|
proof = dict(pause, phase='before_native_dispatch', task_id=selected[0][1]['task_id'],
|
||||||
|
session_id=self.session_id, generation=self.generation, attempt_id=attempt_id,
|
||||||
|
resource_record=str(self.path), project_closed=True, native_dispatch_not_started=True,
|
||||||
|
source_sha256=hashlib.sha256(repr(after).encode()).hexdigest(), committed_prefix=committed,
|
||||||
|
prefix_marker_state=prefix_marker_state, prefix_validation_required=prefix_marker_state == 'project_saved',
|
||||||
|
pause_marker_path=str(marker_path),
|
||||||
|
pause_marker_sha256=hashlib.sha256(internal_path(marker_path).read_bytes()).hexdigest(),
|
||||||
|
commit_manifest_path=str(manifest_path) if committed else None,
|
||||||
|
commit_manifest_sha256=hashlib.sha256(internal_path(manifest_path).read_bytes()).hexdigest() if committed else None,
|
||||||
|
request_sha256=hashlib.sha256(request_bytes).hexdigest(),
|
||||||
|
status_sha256=hashlib.sha256(status.read_bytes()).hexdigest() if status.exists() else None,
|
||||||
|
current_command_sha256=hashlib.sha256(current.read_bytes()).hexdigest() if current.exists() else None,
|
||||||
|
batch_attempts=[{'path': str(path), 'expected': record} for path, record in selected])
|
||||||
|
proof.update(_source_parameters(project, self.root))
|
||||||
|
proof_path = root / ('prewrite-pause-' + attempt_id + '.json')
|
||||||
|
write_record(proof_path, proof)
|
||||||
|
proof['files'] = [{'path': str(path), 'sha256': hashlib.sha256(internal_path(path).read_bytes()).hexdigest()}
|
||||||
|
for path in [proof_path, *files]]
|
||||||
|
return proof
|
||||||
|
except (OSError, ValueError, TypeError, KeyError, AttributeError) as error:
|
||||||
|
raise WorkerMonitorError('prewrite pause lacks bound current-job and committed-prefix proof: ' + str(error)) from error
|
||||||
|
|
||||||
def _retain_uncertain(self, root, project, expected, error):
|
def _retain_uncertain(self, root, project, expected, error):
|
||||||
if self.read_only:
|
if self.read_only:
|
||||||
return
|
return
|
||||||
@@ -740,14 +951,45 @@ class BatchCadRuntime:
|
|||||||
if not self._release_lock.acquire(blocking=False):
|
if not self._release_lock.acquire(blocking=False):
|
||||||
raise BatchResourceCleanupError('资源释放正在进行,请等待当前释放结果。')
|
raise BatchResourceCleanupError('资源释放正在进行,请等待当前释放结果。')
|
||||||
try:
|
try:
|
||||||
return self._close_once(rebuilding=rebuilding, reason=reason)
|
try:
|
||||||
|
return self._close_once(rebuilding=rebuilding, reason=reason)
|
||||||
|
except BatchResourceCleanupError as initial:
|
||||||
|
shutdown = self.record.get('cad_shutdown') or {}
|
||||||
|
if (reason in {'resource_recheck', 'automatic_recheck'}
|
||||||
|
or not shutdown.get('forced_termination')
|
||||||
|
or self.record['state'] not in {'blocked', 'released'}):
|
||||||
|
raise
|
||||||
|
self.record['shutdown_warning'] = str(initial)
|
||||||
|
for attempt, delay in enumerate(RESOURCE_RELEASE_BACKOFF_SECONDS, start=1):
|
||||||
|
time.sleep(delay)
|
||||||
|
self.record.setdefault('release_rechecks', []).append({'attempt': attempt, 'delay_seconds': delay})
|
||||||
|
try:
|
||||||
|
self._close_once(rebuilding=rebuilding, reason='automatic_recheck')
|
||||||
|
except BatchResourceCleanupError:
|
||||||
|
continue
|
||||||
|
self._save()
|
||||||
|
if self._completed_project_after_shutdown():
|
||||||
|
return
|
||||||
|
break
|
||||||
|
self._save()
|
||||||
|
raise
|
||||||
finally:
|
finally:
|
||||||
self._release_lock.release()
|
self._release_lock.release()
|
||||||
|
|
||||||
|
def _completed_project_after_shutdown(self):
|
||||||
|
shutdown = self.record.get('cad_shutdown') or {}
|
||||||
|
proof = self.record.get('release_proof') or {}
|
||||||
|
return (self.result is not None and getattr(self, '_cad_close_error', None) is None
|
||||||
|
and self._active_evidence is not None and not self._active_attempts
|
||||||
|
and shutdown.get('project_close_policy') == 'saved_only'
|
||||||
|
and proof.get('method') == 'owned_cleanup'
|
||||||
|
and not internal_path(self._active_evidence / 'uncertain.flag').exists()
|
||||||
|
and project_checkpoint_released(self._active_evidence))
|
||||||
|
|
||||||
def _close_once(self, *, rebuilding=False, reason=None):
|
def _close_once(self, *, rebuilding=False, reason=None):
|
||||||
if self.desktop is None and not self.generation:
|
if self.desktop is None and not self.generation:
|
||||||
return # A cache-only batch never acquired resources.
|
return # A cache-only batch never acquired resources.
|
||||||
if self.record['state'] == 'released':
|
if self.record['state'] in {'released', 'isolated'}:
|
||||||
return
|
return
|
||||||
reason = reason or ('rebuild' if rebuilding else 'batch_end')
|
reason = reason or ('rebuild' if rebuilding else 'batch_end')
|
||||||
if self._close_failure is not None:
|
if self._close_failure is not None:
|
||||||
@@ -757,7 +999,7 @@ class BatchCadRuntime:
|
|||||||
for event in cleanup.get('desktop_handle_history', ()))):
|
for event in cleanup.get('desktop_handle_history', ()))):
|
||||||
raise BatchResourceCleanupError(str(self._close_failure),
|
raise BatchResourceCleanupError(str(self._close_failure),
|
||||||
completed_result=self.result, cleanup_error=self._close_failure)
|
completed_result=self.result, cleanup_error=self._close_failure)
|
||||||
if (reason == 'resource_recheck'
|
if (reason in {'resource_recheck', 'automatic_recheck'}
|
||||||
and self.record.get('release_results', {}).get('desktop_released') is not True
|
and self.record.get('release_results', {}).get('desktop_released') is not True
|
||||||
and cleanup.get('desktop_handle_closed') is True
|
and cleanup.get('desktop_handle_closed') is True
|
||||||
and not getattr(self.desktop, '_processes', getattr(self.desktop, 'processes', ()))
|
and not getattr(self.desktop, '_processes', getattr(self.desktop, 'processes', ()))
|
||||||
@@ -775,7 +1017,7 @@ class BatchCadRuntime:
|
|||||||
completed_result=self.result, cleanup_error=self._close_failure)
|
completed_result=self.result, cleanup_error=self._close_failure)
|
||||||
cleanup = self.desktop.cleanup_record or {}
|
cleanup = self.desktop.cleanup_record or {}
|
||||||
self.record['cleanup'] = cleanup
|
self.record['cleanup'] = cleanup
|
||||||
if cleanup.get('desktop_confirmation', {}).get('released') is True:
|
if (cleanup.get('desktop_confirmation') or {}).get('released') is True:
|
||||||
self.record['release_results'] = {'mentor_released': True, 'desktop_released': True}
|
self.record['release_results'] = {'mentor_released': True, 'desktop_released': True}
|
||||||
self.record['release_state'] = {'mentor': 'released', 'desktop': 'released'}
|
self.record['release_state'] = {'mentor': 'released', 'desktop': 'released'}
|
||||||
self._release_log('started', reason=reason)
|
self._release_log('started', reason=reason)
|
||||||
@@ -807,30 +1049,41 @@ class BatchCadRuntime:
|
|||||||
raise
|
raise
|
||||||
self._close_failure = None
|
self._close_failure = None
|
||||||
self._close_failure_rebuild = False
|
self._close_failure_rebuild = False
|
||||||
self._release_log('succeeded', reason=reason, elapsed=time.monotonic() - started)
|
self._release_log('isolated' if self.record['state'] == 'isolated' else 'succeeded',
|
||||||
|
reason=reason, elapsed=time.monotonic() - started)
|
||||||
|
|
||||||
def _close_resources(self, *, rebuilding=False):
|
def _close_resources(self, *, rebuilding=False):
|
||||||
|
from .operation_diagnostics import record_operation
|
||||||
|
operation_root = self._active_evidence or self.path.parent
|
||||||
started = time.monotonic()
|
started = time.monotonic()
|
||||||
errors = []
|
errors = []
|
||||||
|
shutdown_errors = []
|
||||||
retained_cad = False
|
retained_cad = False
|
||||||
phases = {'mentor': 'closing' if self.cad is not None else 'released', 'desktop': 'waiting_for_mentor'}
|
phases = {'mentor': 'closing' if self.cad is not None else 'released', 'desktop': 'waiting_for_mentor'}
|
||||||
try:
|
try:
|
||||||
self._save(state='closing', release_state=phases)
|
self._save(state='closing', release_state=phases,
|
||||||
|
wait_reason='mentor_exit' if self.cad is not None else 'desktop_release',
|
||||||
|
stopping_reason=getattr(self.stop_event, 'stopping_reason', ''),
|
||||||
|
primary_error=self.record.get('primary_error') or getattr(self.stop_event, 'primary_error', ''))
|
||||||
except Exception as error:
|
except Exception as error:
|
||||||
errors.append('resource journal: ' + str(error))
|
errors.append('resource journal: ' + str(error))
|
||||||
if self.cad is not None:
|
if self.cad is not None:
|
||||||
cad = self.cad
|
cad = self.cad
|
||||||
try:
|
try:
|
||||||
failure = getattr(self, '_cad_close_error', None)
|
failure = getattr(self, '_cad_close_error', None)
|
||||||
|
record_operation(operation_root, 'mentor_exit', 'enter')
|
||||||
cad.__exit__(type(failure) if failure is not None else None, failure, None)
|
cad.__exit__(type(failure) if failure is not None else None, failure, None)
|
||||||
|
record_operation(operation_root, 'mentor_exit', 'return')
|
||||||
self.cad = None
|
self.cad = None
|
||||||
except Exception as error:
|
except Exception as error:
|
||||||
|
record_operation(operation_root, 'mentor_exit', 'error', error=str(error))
|
||||||
if rebuilding:
|
if rebuilding:
|
||||||
self.record['shutdown_warning'] = str(error)
|
self.record['shutdown_warning'] = str(error)
|
||||||
# A rebuild must not proceed while the previous CAD owner has
|
# A rebuild must not proceed while the previous CAD owner has
|
||||||
# an unconfirmed shutdown. Keep the warning for diagnostics,
|
# an unconfirmed shutdown. Keep the warning for diagnostics,
|
||||||
# but retain the failure in the resource gate as well.
|
# but retain the failure in the resource gate as well.
|
||||||
errors.append(str(error))
|
errors.append(str(error))
|
||||||
|
shutdown_errors.append(str(error))
|
||||||
from .read_recovery import process_tree_exited
|
from .read_recovery import process_tree_exited
|
||||||
process = getattr(cad, 'cad', None)
|
process = getattr(cad, 'cad', None)
|
||||||
processes = [*getattr(cad, '_retained_processes', ()),
|
processes = [*getattr(cad, '_retained_processes', ()),
|
||||||
@@ -853,9 +1106,13 @@ class BatchCadRuntime:
|
|||||||
phases['mentor'] = 'failed' if retained_cad else 'released'
|
phases['mentor'] = 'failed' if retained_cad else 'released'
|
||||||
if self.desktop is not None and not retained_cad:
|
if self.desktop is not None and not retained_cad:
|
||||||
phases['desktop'] = 'closing'
|
phases['desktop'] = 'closing'
|
||||||
|
self.record['wait_reason'] = 'desktop_release'
|
||||||
try:
|
try:
|
||||||
|
record_operation(operation_root, 'desktop_release', 'enter')
|
||||||
self.desktop.close()
|
self.desktop.close()
|
||||||
|
record_operation(operation_root, 'desktop_release', 'return')
|
||||||
except Exception as error:
|
except Exception as error:
|
||||||
|
record_operation(operation_root, 'desktop_release', 'error', error=str(error))
|
||||||
errors.append(str(error))
|
errors.append(str(error))
|
||||||
self._timing('batch_release', started)
|
self._timing('batch_release', started)
|
||||||
self.record['cleanup'] = getattr(self.desktop, 'cleanup_record', None)
|
self.record['cleanup'] = getattr(self.desktop, 'cleanup_record', None)
|
||||||
@@ -863,12 +1120,32 @@ class BatchCadRuntime:
|
|||||||
self.record['release_results'] = {
|
self.record['release_results'] = {
|
||||||
'mentor_released': not retained_cad,
|
'mentor_released': not retained_cad,
|
||||||
'desktop_released': cleanup.get('desktop_handle_closed') is True
|
'desktop_released': cleanup.get('desktop_handle_closed') is True
|
||||||
and cleanup.get('desktop_confirmation', {}).get('released') is True}
|
and (cleanup.get('desktop_confirmation') or {}).get('released') is True}
|
||||||
phases['desktop'] = ('waiting_for_mentor' if retained_cad else
|
phases['desktop'] = ('waiting_for_mentor' if retained_cad else
|
||||||
'released' if self.record['release_results']['desktop_released'] else 'failed')
|
'released' if self.record['release_results']['desktop_released'] else 'failed')
|
||||||
self.record['release_state'] = phases
|
self.record['release_state'] = phases
|
||||||
self.record['cleanup_mode'] = getattr(self.stop_event, 'cleanup_mode', None)
|
self.record['cleanup_mode'] = getattr(self.stop_event, 'cleanup_mode', None)
|
||||||
|
if not retained_cad and not self.record['release_results']['desktop_released']:
|
||||||
|
try:
|
||||||
|
proof = isolation_proof(self.record)
|
||||||
|
if not self._other_writers_exited():
|
||||||
|
raise ValueError('Retained writer ownership is still active')
|
||||||
|
except Exception:
|
||||||
|
pass
|
||||||
|
else:
|
||||||
|
phases['desktop'] = 'isolated'
|
||||||
|
self._save(state='isolated', blocking=False, isolation_proof=proof,
|
||||||
|
isolation_warning='; '.join(errors), release_state=phases, wait_reason='')
|
||||||
|
LIVE_RESOURCES.pop(str(self.path), None)
|
||||||
|
if shutdown_errors:
|
||||||
|
raise BatchResourceCleanupError('; '.join(shutdown_errors), completed_result=self.result)
|
||||||
|
return
|
||||||
if errors:
|
if errors:
|
||||||
|
if (errors == shutdown_errors and not retained_cad and self.owned_processes_exited()
|
||||||
|
and self._other_writers_exited() and self.record['release_results']['desktop_released']):
|
||||||
|
self.record['shutdown_warning'] = '; '.join(shutdown_errors)
|
||||||
|
self._record_release()
|
||||||
|
raise BatchResourceCleanupError('; '.join(errors), completed_result=self.result)
|
||||||
self._save(state='blocked', error='; '.join(errors))
|
self._save(state='blocked', error='; '.join(errors))
|
||||||
raise BatchResourceCleanupError('; '.join(errors), completed_result=self.result)
|
raise BatchResourceCleanupError('; '.join(errors), completed_result=self.result)
|
||||||
self._record_release()
|
self._record_release()
|
||||||
@@ -879,5 +1156,61 @@ class BatchCadRuntime:
|
|||||||
'cad_pid': self.record['cad_pid'], 'cad_guid': self.record['cad_guid'],
|
'cad_pid': self.record['cad_pid'], 'cad_guid': self.record['cad_guid'],
|
||||||
'cleanup': self.record['cleanup'], 'released_at': released_at}
|
'cleanup': self.record['cleanup'], 'released_at': released_at}
|
||||||
releases = [*self.record.get('generation_releases', ()), release]
|
releases = [*self.record.get('generation_releases', ()), release]
|
||||||
self._save(state='released', released_at=released_at, processes=[], generation_releases=releases)
|
shutdown = self.record.get('cad_shutdown') or {}
|
||||||
|
if shutdown.get('forced_termination') and (release['cleanup'] or {}).get('owned_cleanup_complete') is True:
|
||||||
|
proof = isolation_proof(self.record)
|
||||||
|
self.record['release_proof'] = dict(proof, desktop_released=True, method='owned_cleanup')
|
||||||
|
self._save(state='released', blocking=False, released_at=released_at, processes=[], generation_releases=releases,
|
||||||
|
wait_reason='')
|
||||||
LIVE_RESOURCES.pop(str(self.path), None)
|
LIVE_RESOURCES.pop(str(self.path), None)
|
||||||
|
|
||||||
|
def _other_writers_exited(self):
|
||||||
|
from .isolated_cad import RETAINED_CAD_SESSIONS
|
||||||
|
from .read_recovery import process_tree_exited
|
||||||
|
from .worker_monitor import RETAINED_WORKERS, _worker_tree_exited
|
||||||
|
return (all(all(process_tree_exited(process) for process in session._owned_processes())
|
||||||
|
for session in tuple(RETAINED_CAD_SESSIONS.values())
|
||||||
|
if session.root.is_relative_to(self.root))
|
||||||
|
and all(_worker_tree_exited(entry['process'], entry['owned'])
|
||||||
|
for entry in tuple(RETAINED_WORKERS.values()) if entry['root'].is_relative_to(self.root)))
|
||||||
|
|
||||||
|
def release_failed_project(self, error, evidence_root):
|
||||||
|
"""Release proven stopped writers; the failed project's business evidence stays untouched."""
|
||||||
|
from .stop_control import protect_interruption
|
||||||
|
protect_interruption(evidence_root, 'project_failure: ' + str(error))
|
||||||
|
request = getattr(self.stop_event, 'request_failure_cleanup', None)
|
||||||
|
if request is not None:
|
||||||
|
request(evidence_root, error)
|
||||||
|
if self.cad is not None:
|
||||||
|
self.cad.stop_control = self.stop_event
|
||||||
|
self._cad_close_error = error
|
||||||
|
cleanup_warning = None
|
||||||
|
try:
|
||||||
|
self.close(reason='project_failure')
|
||||||
|
except BatchResourceCleanupError as cleanup:
|
||||||
|
from .batch_resources import blocking_resources
|
||||||
|
if (self.record['state'] not in {'released', 'isolated'} or blocking_resources(self.root)
|
||||||
|
or not self.owned_processes_exited() or not self._other_writers_exited()):
|
||||||
|
raise
|
||||||
|
cleanup_warning = str(cleanup)
|
||||||
|
error.shutdown_warning = cleanup_warning
|
||||||
|
self.record.setdefault('generation_shutdown_warnings', []).append({
|
||||||
|
'generation': self.generation, 'error': cleanup_warning, 'cad_shutdown': self.record.get('cad_shutdown')})
|
||||||
|
self._save(shutdown_warning=cleanup_warning)
|
||||||
|
if ((self.generation and not self.owned_processes_exited()) or not self._other_writers_exited()):
|
||||||
|
return False
|
||||||
|
from .batch_resources import blocking_resources
|
||||||
|
if blocking_resources(self.root):
|
||||||
|
return False
|
||||||
|
write_record(canonical_path(evidence_root) / 'project-resource-release.json', {
|
||||||
|
'version': 1, 'session_id': self.session_id, 'generation': self.generation,
|
||||||
|
'resource_record': str(self.path), 'writers_exited': True,
|
||||||
|
'resource_state': self.record['state'], 'desktop_released':
|
||||||
|
self.record.get('release_results', {}).get('desktop_released') is True,
|
||||||
|
'business_uncertainty_preserved': True})
|
||||||
|
self.desktop = self.cad = None
|
||||||
|
self._active_evidence = None
|
||||||
|
self._active_attempts = []
|
||||||
|
self._close_failure = None
|
||||||
|
self._cad_close_error = None
|
||||||
|
return True
|
||||||
@@ -305,9 +305,9 @@ def pending_supervisors(root):
|
|||||||
|
|
||||||
def reconcile_supervisors(root):
|
def reconcile_supervisors(root):
|
||||||
"""Recheck orphan ownership only; this never launches or replays a job."""
|
"""Recheck orphan ownership only; this never launches or replays a job."""
|
||||||
from .batch_resources import _process_gone, pending_resources, write_record
|
from .batch_resources import _process_gone, blocking_resources, write_record
|
||||||
from .read_recovery import process_tree_exited
|
from .read_recovery import process_tree_exited
|
||||||
physical = pending_resources(root)
|
physical = blocking_resources(root)
|
||||||
for record in pending_supervisors(root):
|
for record in pending_supervisors(root):
|
||||||
owner = (_LIVE_SUPERVISORS.get(canonical_path(record['record_path']))
|
owner = (_LIVE_SUPERVISORS.get(canonical_path(record['record_path']))
|
||||||
or _ACTIVE_SUPERVISORS.get(canonical_path(record['record_path'])))
|
or _ACTIVE_SUPERVISORS.get(canonical_path(record['record_path'])))
|
||||||
@@ -348,21 +348,26 @@ def _environment():
|
|||||||
|
|
||||||
def _finish_response(root, journal, response, context):
|
def _finish_response(root, journal, response, context):
|
||||||
"""A supervisor exit may release its last USER reference. Never repeat work."""
|
"""A supervisor exit may release its last USER reference. Never repeat work."""
|
||||||
from .batch_resources import cleanup_pending_resources, write_record
|
from .batch_resources import cleanup_pending_resources, resource_blockers, write_record
|
||||||
from .supervisor_result import validated_outcome, resource_pending_error, application_shutdown_error
|
from .supervisor_result import validated_outcome, resource_pending_error, application_shutdown_error
|
||||||
result, error, primary = validated_outcome(journal['operation'], response)
|
result, error, primary = validated_outcome(journal['operation'], response)
|
||||||
pending = cleanup_pending_resources(root, logging_context=context)
|
pending = cleanup_pending_resources(root, logging_context=context)
|
||||||
related = tuple(item for item in pending if item.get('session_id') == journal['batch_id'] or not item.get('session_id'))
|
related = tuple(item for item in pending if item.get('session_id') == journal['batch_id'] or not item.get('session_id'))
|
||||||
journal['state'] = 'blocked' if related else 'finished'
|
blockers = resource_blockers(related)
|
||||||
journal['outcome'] = ('completed_resources_pending' if related and response.get('business_succeeded')
|
warnings = tuple(item for item in related if item not in blockers)
|
||||||
|
journal['state'] = 'blocked' if blockers else 'finished'
|
||||||
|
journal['outcome'] = ('completed_resources_pending' if blockers and response.get('business_succeeded')
|
||||||
else response.get('status', 'interrupted'))
|
else response.get('status', 'interrupted'))
|
||||||
journal['resource_recheck'] = {'pending': bool(related), 'checked_at': time.time()}
|
journal['resource_recheck'] = {'pending': bool(blockers), 'warnings': list(warnings),
|
||||||
|
'desktop_released': not related, 'owned_writers_exited': not blockers, 'checked_at': time.time()}
|
||||||
write_record(Path(root) / 'batch-resources' / journal['batch_id'] / 'supervisor.json', journal)
|
write_record(Path(root) / 'batch-resources' / journal['batch_id'] / 'supervisor.json', journal)
|
||||||
if related:
|
if blockers:
|
||||||
raise resource_pending_error(journal['operation'], result, error, primary)
|
raise resource_pending_error(journal['operation'], result, error, primary)
|
||||||
for failure in (error, primary):
|
for failure in (error, primary):
|
||||||
if failure is not None:
|
if failure is not None:
|
||||||
failure.resources_released = True
|
failure.resources_released = not warnings
|
||||||
|
failure.owned_writers_exited = True
|
||||||
|
failure.resource_warnings = warnings
|
||||||
resource_path = internal_path(Path(root) / 'batch-resources' / journal['batch_id'] / 'session.json')
|
resource_path = internal_path(Path(root) / 'batch-resources' / journal['batch_id'] / 'session.json')
|
||||||
def preserve_shutdown_failure(detail):
|
def preserve_shutdown_failure(detail):
|
||||||
try:
|
try:
|
||||||
@@ -373,7 +378,9 @@ def _finish_response(root, journal, response, context):
|
|||||||
journal['shutdown_record_error'] = str(record_error)
|
journal['shutdown_record_error'] = str(record_error)
|
||||||
def shutdown_failure():
|
def shutdown_failure():
|
||||||
failure = application_shutdown_error(result, error, primary)
|
failure = application_shutdown_error(result, error, primary)
|
||||||
failure.resources_released = True
|
failure.resources_released = not warnings
|
||||||
|
failure.owned_writers_exited = True
|
||||||
|
failure.resource_warnings = warnings
|
||||||
return failure
|
return failure
|
||||||
try:
|
try:
|
||||||
resource = json.loads(resource_path.read_text(encoding='utf-8'))
|
resource = json.loads(resource_path.read_text(encoding='utf-8'))
|
||||||
@@ -558,6 +565,7 @@ def run_supervised(service, operation, arguments, *, stop_event=None, on_progres
|
|||||||
on_phase(*payload)
|
on_phase(*payload)
|
||||||
elif value['type'] == 'state':
|
elif value['type'] == 'state':
|
||||||
state = decode(value['payload'])
|
state = decode(value['payload'])
|
||||||
|
service._supervisor_state = state
|
||||||
business_watch.observe('state', state, time.monotonic())
|
business_watch.observe('state', state, time.monotonic())
|
||||||
service._task_queue_feedback = getattr(service, '_workspace_queue_context', None) or state['queue']
|
service._task_queue_feedback = getattr(service, '_workspace_queue_context', None) or state['queue']
|
||||||
service._batch_feedback = state['batch']
|
service._batch_feedback = state['batch']
|
||||||
@@ -578,6 +586,7 @@ def run_supervised(service, operation, arguments, *, stop_event=None, on_progres
|
|||||||
service._task_queue_feedback = None
|
service._task_queue_feedback = None
|
||||||
service._batch_feedback = None
|
service._batch_feedback = None
|
||||||
service._supervisor_waiting = False
|
service._supervisor_waiting = False
|
||||||
|
service._supervisor_state = None
|
||||||
service._supervisor_business_stalled = False
|
service._supervisor_business_stalled = False
|
||||||
service._supervisor_dialog_state = None
|
service._supervisor_dialog_state = None
|
||||||
try:
|
try:
|
||||||
@@ -616,10 +625,10 @@ def run_supervised(service, operation, arguments, *, stop_event=None, on_progres
|
|||||||
exit_code=getattr(process, 'returncode', None),
|
exit_code=getattr(process, 'returncode', None),
|
||||||
stdout_chars=len(stdout_tail), stderr_chars=len(stderr_tail))
|
stdout_chars=len(stdout_tail), stderr_chars=len(stderr_tail))
|
||||||
if force_accepted:
|
if force_accepted:
|
||||||
from .batch_resources import cleanup_pending_resources
|
from .batch_resources import cleanup_pending_resources, resource_blockers
|
||||||
try:
|
try:
|
||||||
pending = cleanup_pending_resources(root, logging_context=service._logging)
|
pending = cleanup_pending_resources(root, logging_context=service._logging)
|
||||||
if pending:
|
if resource_blockers(pending):
|
||||||
ownership_cleanup_error = TaskCenterError('batch_resources_pending', '强制结束后的资源仍待清理。')
|
ownership_cleanup_error = TaskCenterError('batch_resources_pending', '强制结束后的资源仍待清理。')
|
||||||
except Exception as error:
|
except Exception as error:
|
||||||
ownership_cleanup_error = error
|
ownership_cleanup_error = error
|
||||||
@@ -628,7 +637,8 @@ def run_supervised(service, operation, arguments, *, stop_event=None, on_progres
|
|||||||
failure = TaskCenterError('mentor_release_required' if automatic else 'user_forced_stop',
|
failure = TaskCenterError('mentor_release_required' if automatic else 'user_forced_stop',
|
||||||
'执行失败,已自动收尾本批后台进程;已有结果保留,当前结果待核验。' if automatic else
|
'执行失败,已自动收尾本批后台进程;已有结果保留,当前结果待核验。' if automatic else
|
||||||
'已按确认强制结束;已保存的执行证据保留,当前结果待核验。请先核验恢复,不要重复替换。')
|
'已按确认强制结束;已保存的执行证据保留,当前结果待核验。请先核验恢复,不要重复替换。')
|
||||||
failure.resources_released = ownership_cleanup_error is None
|
failure.resources_released = ownership_cleanup_error is None and not pending
|
||||||
|
failure.owned_writers_exited = ownership_cleanup_error is None
|
||||||
failure.primary_error = transport_error
|
failure.primary_error = transport_error
|
||||||
if ownership_cleanup_error is not None:
|
if ownership_cleanup_error is not None:
|
||||||
journal.update(force_state='confirmation_failed', force_cleanup_error=str(ownership_cleanup_error))
|
journal.update(force_state='confirmation_failed', force_cleanup_error=str(ownership_cleanup_error))
|
||||||
@@ -688,7 +698,7 @@ def run_supervised(service, operation, arguments, *, stop_event=None, on_progres
|
|||||||
raise failure from protection_error
|
raise failure from protection_error
|
||||||
# Recheck physical resources even when final business results are
|
# Recheck physical resources even when final business results are
|
||||||
# missing; this never authorizes repeating the interrupted job.
|
# missing; this never authorizes repeating the interrupted job.
|
||||||
from .batch_resources import cleanup_pending_resources
|
from .batch_resources import cleanup_pending_resources, resource_blockers
|
||||||
outstanding = cleanup_pending_resources(root, logging_context=service._logging)
|
outstanding = cleanup_pending_resources(root, logging_context=service._logging)
|
||||||
failure = cause if isinstance(cause, TaskCenterError) else TaskCenterError(
|
failure = cause if isinstance(cause, TaskCenterError) else TaskCenterError(
|
||||||
'supervisor_interrupted', '批次监督进程未留下可信结果;保留保护记录,不自动重试。' +
|
'supervisor_interrupted', '批次监督进程未留下可信结果;保留保护记录,不自动重试。' +
|
||||||
@@ -697,6 +707,8 @@ def run_supervised(service, operation, arguments, *, stop_event=None, on_progres
|
|||||||
from .read_recovery import process_tree_exited
|
from .read_recovery import process_tree_exited
|
||||||
failure.resources_released = (not outstanding and ownership_cleanup_error is None
|
failure.resources_released = (not outstanding and ownership_cleanup_error is None
|
||||||
and (process is None or process_tree_exited(process)))
|
and (process is None or process_tree_exited(process)))
|
||||||
|
failure.owned_writers_exited = (not resource_blockers(outstanding) and ownership_cleanup_error is None
|
||||||
|
and (process is None or process_tree_exited(process)))
|
||||||
raise failure from (transport_error or error)
|
raise failure from (transport_error or error)
|
||||||
if transport_error is not None:
|
if transport_error is not None:
|
||||||
if response['payload']['business_succeeded']:
|
if response['payload']['business_succeeded']:
|
||||||
@@ -705,9 +717,13 @@ def run_supervised(service, operation, arguments, *, stop_event=None, on_progres
|
|||||||
else:
|
else:
|
||||||
_mark_interrupted(root, journal, transport_error)
|
_mark_interrupted(root, journal, transport_error)
|
||||||
failure = resource_pending_error(operation, decoded_result, transport_error, decoded_primary)
|
failure = resource_pending_error(operation, decoded_result, transport_error, decoded_primary)
|
||||||
from .batch_resources import pending_resources
|
from .batch_resources import pending_resources, resource_blockers
|
||||||
from .read_recovery import process_tree_exited
|
from .read_recovery import process_tree_exited
|
||||||
failure.resources_released = (ownership_cleanup_error is None and not pending_resources(root)
|
pending = pending_resources(root)
|
||||||
|
failure.resources_released = (ownership_cleanup_error is None and not pending
|
||||||
and process is not None and process_tree_exited(process))
|
and process is not None and process_tree_exited(process))
|
||||||
|
failure.owned_writers_exited = (ownership_cleanup_error is None and not resource_blockers(pending)
|
||||||
|
and process is not None and process_tree_exited(process))
|
||||||
|
failure.resource_warnings = tuple(row for row in pending if row not in resource_blockers(pending))
|
||||||
raise failure
|
raise failure
|
||||||
return _finish_response(root, journal, response['payload'], service._logging)
|
return _finish_response(root, journal, response['payload'], service._logging)
|
||||||
@@ -14,6 +14,14 @@ from uuid import UUID
|
|||||||
from .path_access import internal_path, canonical_path
|
from .path_access import internal_path, canonical_path
|
||||||
from .supervisor_protocol import VERSION, OPERATIONS, valid_journal, encode, decode, encode_error
|
from .supervisor_protocol import VERSION, OPERATIONS, valid_journal, encode, decode, encode_error
|
||||||
|
|
||||||
|
|
||||||
|
def _persist_result(directory, envelope):
|
||||||
|
from .batch_resources import write_record
|
||||||
|
from .operation_diagnostics import operation_span
|
||||||
|
with operation_span(directory, 'result_persistence', item_id=envelope['attempt_id']):
|
||||||
|
write_record(directory / 'result.json', envelope)
|
||||||
|
|
||||||
|
|
||||||
def _output_stream():
|
def _output_stream():
|
||||||
if sys.stdout is not None:
|
if sys.stdout is not None:
|
||||||
return sys.stdout, False
|
return sys.stdout, False
|
||||||
@@ -85,7 +93,7 @@ def consume_manual_dialog_actions(directory, runtime, batch_id, attempt_id):
|
|||||||
write_record(claimed.with_suffix('.result'), result)
|
write_record(claimed.with_suffix('.result'), result)
|
||||||
|
|
||||||
|
|
||||||
def _wait_for_owned_writes(runtime, control):
|
def _wait_for_owned_writes(runtime, control) -> Exception | None:
|
||||||
"""Process exit would close kill-on-close Jobs, so it is also a write boundary."""
|
"""Process exit would close kill-on-close Jobs, so it is also a write boundary."""
|
||||||
if runtime.read_only:
|
if runtime.read_only:
|
||||||
return
|
return
|
||||||
@@ -103,15 +111,21 @@ def _wait_for_owned_writes(runtime, control):
|
|||||||
return False
|
return False
|
||||||
return all(_worker_tree_exited(entry['process'], entry['owned'])
|
return all(_worker_tree_exited(entry['process'], entry['owned'])
|
||||||
for entry in tuple(RETAINED_WORKERS.values()) if entry['root'].is_relative_to(runtime.root))
|
for entry in tuple(RETAINED_WORKERS.values()) if entry['root'].is_relative_to(runtime.root))
|
||||||
if not exited():
|
try:
|
||||||
try:
|
if not exited():
|
||||||
wait_for_resolution(control, runtime.path.parent,
|
try:
|
||||||
'supervisor exit still has owned write processes', resolved=exited, release_on_failure=True)
|
wait_for_resolution(control, runtime.path.parent,
|
||||||
except MentorReleaseRequired:
|
'supervisor exit still has owned write processes', resolved=exited, release_on_failure=True)
|
||||||
cleanup_retained_workers(runtime.root, force=True)
|
except MentorReleaseRequired:
|
||||||
cleanup_retained_workers(runtime.root)
|
cleanup_retained_workers(runtime.root, force=True)
|
||||||
if runtime.desktop is not None or runtime.cad is not None:
|
cleanup_retained_workers(runtime.root)
|
||||||
runtime.close(reason='resource_recheck')
|
if runtime.desktop is not None or runtime.cad is not None:
|
||||||
|
runtime.close(reason='resource_recheck')
|
||||||
|
except Exception as error:
|
||||||
|
# Desktop references may remain after writers exit; publish that failure.
|
||||||
|
if not exited():
|
||||||
|
raise
|
||||||
|
return error
|
||||||
|
|
||||||
|
|
||||||
def run(request_path):
|
def run(request_path):
|
||||||
@@ -154,7 +168,7 @@ def run(request_path):
|
|||||||
'generation': max(1, runtime.generation), 'sequence': sequence,
|
'generation': max(1, runtime.generation), 'sequence': sequence,
|
||||||
'type': kind, 'payload': payload}
|
'type': kind, 'payload': payload}
|
||||||
if persist:
|
if persist:
|
||||||
write_record(directory / 'result.json', envelope)
|
_persist_result(directory, envelope)
|
||||||
try:
|
try:
|
||||||
output.write(json.dumps(envelope, ensure_ascii=True, allow_nan=False) + '\n')
|
output.write(json.dumps(envelope, ensure_ascii=True, allow_nan=False) + '\n')
|
||||||
output.flush()
|
output.flush()
|
||||||
@@ -175,9 +189,13 @@ def run(request_path):
|
|||||||
emit('heartbeat')
|
emit('heartbeat')
|
||||||
feedback = getattr(service, '_task_queue_feedback', None)
|
feedback = getattr(service, '_task_queue_feedback', None)
|
||||||
emit('state', encode({'phase': runtime.record['state'], 'queue': feedback,
|
emit('state', encode({'phase': runtime.record['state'], 'queue': feedback,
|
||||||
|
'release_state': runtime.record.get('release_state'),
|
||||||
'batch': service.batch_feedback(),
|
'batch': service.batch_feedback(),
|
||||||
'active_project': runtime.record.get('active_project'),
|
'active_project': runtime.record.get('active_project'),
|
||||||
'business_progress': runtime.business_progress(),
|
'business_progress': runtime.business_progress(),
|
||||||
|
'stopping_reason': runtime.record.get('stopping_reason') or getattr(runtime.stop_event, 'stopping_reason', ''),
|
||||||
|
'wait_reason': runtime.record.get('wait_reason') or getattr(runtime.stop_event, 'wait_reason', ''),
|
||||||
|
'primary_error': runtime.record.get('primary_error') or getattr(runtime.stop_event, 'primary_error', ''),
|
||||||
'dialog_supervision': runtime.dialog_state(),
|
'dialog_supervision': runtime.dialog_state(),
|
||||||
'dialog_binding': {'batch_id': batch_id, 'attempt_id': attempt_id,
|
'dialog_binding': {'batch_id': batch_id, 'attempt_id': attempt_id,
|
||||||
'generation': runtime.generation, 'session_token': getattr(runtime.cad, 'token', None)},
|
'generation': runtime.generation, 'session_token': getattr(runtime.cad, 'token', None)},
|
||||||
@@ -201,7 +219,7 @@ def run(request_path):
|
|||||||
def phase(value, message):
|
def phase(value, message):
|
||||||
emit('phase', encode((value, str(message))))
|
emit('phase', encode((value, str(message))))
|
||||||
if operation == 'cleanup_batch_resources':
|
if operation == 'cleanup_batch_resources':
|
||||||
result = service.cleanup_batch_resources()
|
result = service.cleanup_batch_resources(automatic=arguments.get('automatic') is True)
|
||||||
response.update(status='ok', business_succeeded=True, result=encode(result))
|
response.update(status='ok', business_succeeded=True, result=encode(result))
|
||||||
else:
|
else:
|
||||||
with runtime:
|
with runtime:
|
||||||
@@ -249,7 +267,15 @@ def run(request_path):
|
|||||||
context.report_exception('batch_supervisor', error)
|
context.report_exception('batch_supervisor', error)
|
||||||
response.update(status='error', error=encode_error(error))
|
response.update(status='error', error=encode_error(error))
|
||||||
finally:
|
finally:
|
||||||
_wait_for_owned_writes(runtime, stop)
|
cleanup_error = _wait_for_owned_writes(runtime, stop)
|
||||||
|
if cleanup_error is not None:
|
||||||
|
context.report_exception('batch_supervisor_resource_recheck', cleanup_error)
|
||||||
|
response['status'] = 'error'
|
||||||
|
response.setdefault('error', encode_error(cleanup_error))
|
||||||
|
if runtime.record.get('state') == 'isolated':
|
||||||
|
response['resource_warning'] = {'state': 'isolated', 'blocking': False,
|
||||||
|
'desktop': runtime.record['desktop'], 'desktop_released': False,
|
||||||
|
'owned_writers_exited': True}
|
||||||
evidence.try_append('worker_closing', status=response.get('status'), business_succeeded=response.get('business_succeeded'))
|
evidence.try_append('worker_closing', status=response.get('status'), business_succeeded=response.get('business_succeeded'))
|
||||||
finished.set()
|
finished.set()
|
||||||
thread.join(3)
|
thread.join(3)
|
||||||
|
|||||||
@@ -48,6 +48,7 @@ class BomImportReport:
|
|||||||
source_map_path: Path | None = None
|
source_map_path: Path | None = None
|
||||||
passed_preview: BomBatchPreview | None = None
|
passed_preview: BomBatchPreview | None = None
|
||||||
deferred: bool = False
|
deferred: bool = False
|
||||||
|
warnings: tuple[str, ...] = ()
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def total_rows(self):
|
def total_rows(self):
|
||||||
|
|||||||
@@ -40,8 +40,9 @@ def retained_bom_rows(pending, existing_rows):
|
|||||||
candidates = tuple(index for identity in dict.fromkeys(((record.old.casefold(), ref.casefold()),
|
candidates = tuple(index for identity in dict.fromkeys(((record.old.casefold(), ref.casefold()),
|
||||||
(record.new.casefold(), ref.casefold()))) for index in by_identity.get(identity, ())
|
(record.new.casefold(), ref.casefold()))) for index in by_identity.get(identity, ())
|
||||||
if (not record.schematic or existing_rows[index].target.schematic_name.casefold() == record.schematic.casefold())
|
if (not record.schematic or existing_rows[index].target.schematic_name.casefold() == record.schematic.casefold())
|
||||||
and (not record.sheet or existing_rows[index].target.sheet_number.casefold() == record.sheet.casefold())
|
and (not record.sheet or existing_rows[index].target.sheet_number.casefold() == record.sheet.casefold()))
|
||||||
and (not record.uid or existing_rows[index].target.uid == record.uid))
|
if len(candidates) > 1 and record.uid:
|
||||||
|
candidates = tuple(index for index in candidates if existing_rows[index].target.uid == record.uid)
|
||||||
if len(candidates) > 1:
|
if len(candidates) > 1:
|
||||||
raise TaskCenterError('bom_scope_ambiguous', f'位号 {ref} 无法唯一匹配已保存位号;请填写原理图、图页或 UID:'
|
raise TaskCenterError('bom_scope_ambiguous', f'位号 {ref} 无法唯一匹配已保存位号;请填写原理图、图页或 UID:'
|
||||||
f'{request.source_file} 第 {request.source_row} 行')
|
f'{request.source_file} 第 {request.source_row} 行')
|
||||||
@@ -76,7 +77,9 @@ def resolution_binding(store, task_id):
|
|||||||
|
|
||||||
def import_drafts(service, task_id, sources, *, stop_event=None, on_progress=None, on_phase=None, allow_partial=False):
|
def import_drafts(service, task_id, sources, *, stop_event=None, on_progress=None, on_phase=None, allow_partial=False):
|
||||||
"""Persist routed spreadsheet requests without opening CAD or resolving parts."""
|
"""Persist routed spreadsheet requests without opening CAD or resolving parts."""
|
||||||
rows = load_sources(sources, stop_event=stop_event, on_progress=on_progress, allow_partial=allow_partial)
|
warnings = []
|
||||||
|
rows = load_sources(sources, stop_event=stop_event, on_progress=on_progress,
|
||||||
|
allow_partial=allow_partial, warnings=warnings)
|
||||||
scope = _scope(service._store, task_id)
|
scope = _scope(service._store, task_id)
|
||||||
paths = tuple(project.path for _, project in scope)
|
paths = tuple(project.path for _, project in scope)
|
||||||
names = {project.path: task.name for task, project in scope}
|
names = {project.path: task.name for task, project in scope}
|
||||||
@@ -92,7 +95,8 @@ def import_drafts(service, task_id, sources, *, stop_event=None, on_progress=Non
|
|||||||
write_routed_bom(normalized, rows, routes, project_names=names)
|
write_routed_bom(normalized, rows, routes, project_names=names)
|
||||||
append_task_event(service._logging, level='INFO', task_id=task_id,
|
append_task_event(service._logging, level='INFO', task_id=task_id,
|
||||||
operation='import_bom_drafts', message='BOM 表格来源记录已保存,工程位号待核验',
|
operation='import_bom_drafts', message='BOM 表格来源记录已保存,工程位号待核验',
|
||||||
details={'source_map_path': str(mapping), 'source_count': len({row.source for row in rows})})
|
details={'source_map_path': str(mapping), 'source_count': len({row.source for row in rows}),
|
||||||
|
'warnings': warnings})
|
||||||
try:
|
try:
|
||||||
report = inspect_batch(service, task_id, normalized, stop_event=stop_event, on_progress=on_progress,
|
report = inspect_batch(service, task_id, normalized, stop_event=stop_event, on_progress=on_progress,
|
||||||
on_phase=on_phase, spreadsheet_only=True, allow_partial=allow_partial)
|
on_phase=on_phase, spreadsheet_only=True, allow_partial=allow_partial)
|
||||||
@@ -109,7 +113,7 @@ def import_drafts(service, task_id, sources, *, stop_event=None, on_progress=Non
|
|||||||
if report.deferred and result.project_path not in failed_paths:
|
if report.deferred and result.project_path not in failed_paths:
|
||||||
reason = '表格已保存,执行前核验工程位号'
|
reason = '表格已保存,执行前核验工程位号'
|
||||||
annotated.append(replace(result, source_file=str(source.source), source_row=source.excel_row, reason=reason))
|
annotated.append(replace(result, source_file=str(source.source), source_row=source.excel_row, reason=reason))
|
||||||
report = replace(report, rows=tuple(annotated), source_map_path=mapping)
|
report = replace(report, rows=tuple(annotated), source_map_path=mapping, warnings=tuple(warnings))
|
||||||
if report.deferred:
|
if report.deferred:
|
||||||
accepted_sources = tuple(source for result, source in zip(report.rows, rows, strict=True)
|
accepted_sources = tuple(source for result, source in zip(report.rows, rows, strict=True)
|
||||||
if result.project_path not in failed_paths)
|
if result.project_path not in failed_paths)
|
||||||
|
|||||||
@@ -25,7 +25,7 @@ _HEADER_HELP = (
|
|||||||
'位号,必填。一行可填 R1,R2,R3,支持逗号、分号、空格或顿号分隔。',
|
'位号,必填。一行可填 R1,R2,R3,支持逗号、分号、空格或顿号分隔。',
|
||||||
'原理图名称,可选。位号重复时用于精确匹配。',
|
'原理图名称,可选。位号重复时用于精确匹配。',
|
||||||
'图页,可选。位号跨页重复时应填写图页或 UID。',
|
'图页,可选。位号跨页重复时应填写图页或 UID。',
|
||||||
'器件 UID,可选;填写时必须与采集结果一致。',
|
'器件 UID,可选。工程、图页和位号已唯一匹配时忽略;仅用于区分仍有多个候选的位号。',
|
||||||
'是否替换:TRUE/FALSE 或 是/否;留空默认替换。未列出的位号保留。',
|
'是否替换:TRUE/FALSE 或 是/否;留空默认替换。未列出的位号保留。',
|
||||||
'自定义 Value,可选;留空沿用工具原有 Value 策略。',
|
'自定义 Value,可选;留空沿用工具原有 Value 策略。',
|
||||||
'同步 NC:TRUE/FALSE 或 是/否;留空默认开启。',
|
'同步 NC:TRUE/FALSE 或 是/否;留空默认开启。',
|
||||||
@@ -209,8 +209,9 @@ class BomMatcher:
|
|||||||
for key, target in self.by_identity.get(identity, ())
|
for key, target in self.by_identity.get(identity, ())
|
||||||
if (not record.project_path or self.identities.project(record.project_path) == key[0])
|
if (not record.project_path or self.identities.project(record.project_path) == key[0])
|
||||||
and (not record.schematic or target.schematic_name.casefold() == record.schematic.casefold())
|
and (not record.schematic or target.schematic_name.casefold() == record.schematic.casefold())
|
||||||
and (not record.sheet or target.sheet_number.casefold() == record.sheet.casefold())
|
and (not record.sheet or target.sheet_number.casefold() == record.sheet.casefold())]
|
||||||
and (not record.uid or target.uid == record.uid)]
|
if len(candidates) > 1 and record.uid:
|
||||||
|
candidates = [(key, target) for key, target in candidates if target.uid == record.uid]
|
||||||
if len(candidates) != 1:
|
if len(candidates) != 1:
|
||||||
raise TaskCenterError('bom_import', f'位号 {refdes} 无法唯一匹配当前采集清单')
|
raise TaskCenterError('bom_import', f'位号 {refdes} 无法唯一匹配当前采集清单')
|
||||||
key, target = candidates[0]
|
key, target = candidates[0]
|
||||||
|
|||||||
@@ -156,7 +156,10 @@ def _catalog_from_evidence(evidence, library, part, partition, fingerprint, path
|
|||||||
def _require_cleanup(cleanup):
|
def _require_cleanup(cleanup):
|
||||||
def pending(message):
|
def pending(message):
|
||||||
raise TaskCenterError('batch_resources_pending', message)
|
raise TaskCenterError('batch_resources_pending', message)
|
||||||
if not isinstance(cleanup, dict) or cleanup.get('errors') or not cleanup.get('desktop_handle_closed') or not cleanup.get('desktop_confirmation', {}).get('released'):
|
from .desktop_slot import returned_lease_intact
|
||||||
|
returned = isinstance(cleanup, dict) and returned_lease_intact(cleanup.get('desktop_lease', {}), cleanup.get('desktop'))
|
||||||
|
if (not isinstance(cleanup, dict) or cleanup.get('errors') or not cleanup.get('desktop_handle_closed')
|
||||||
|
or not ((cleanup.get('desktop_confirmation') or {}).get('released') or returned)):
|
||||||
pending('catalog private desktop cleanup was not proven')
|
pending('catalog private desktop cleanup was not proven')
|
||||||
if not cleanup.get('processes'):
|
if not cleanup.get('processes'):
|
||||||
pending('catalog owned process cleanup is missing')
|
pending('catalog owned process cleanup is missing')
|
||||||
@@ -419,7 +422,7 @@ def _run_owned_reader(clone, part, partition, root):
|
|||||||
from .isolated_desktop import PrivateDesktop
|
from .isolated_desktop import PrivateDesktop
|
||||||
from .legacy_paths import _AliasPool, _fits, _short_path
|
from .legacy_paths import _AliasPool, _fits, _short_path
|
||||||
exe = _library_manager_executable()
|
exe = _library_manager_executable()
|
||||||
desktop = PrivateDesktop('dx-cell-' + uuid.uuid4().hex, enabled=True)
|
desktop = PrivateDesktop('dx-cell-' + uuid.uuid4().hex, enabled=True, managed=True)
|
||||||
aliases = _AliasPool()
|
aliases = _AliasPool()
|
||||||
report_path = root / 'worker-result.json'
|
report_path = root / 'worker-result.json'
|
||||||
clone_fingerprint = _content_fingerprint(_library_manifest(clone))
|
clone_fingerprint = _content_fingerprint(_library_manifest(clone))
|
||||||
|
|||||||
@@ -0,0 +1,238 @@
|
|||||||
|
"""One desktop per user/logon, with independent durable leases and named Jobs."""
|
||||||
|
import hashlib
|
||||||
|
import json
|
||||||
|
import os
|
||||||
|
from pathlib import Path
|
||||||
|
import re
|
||||||
|
from threading import Event, Thread
|
||||||
|
from uuid import uuid4
|
||||||
|
|
||||||
|
from .batch_resources import write_record
|
||||||
|
from .errors import TaskCenterError
|
||||||
|
from .path_access import canonical_path, internal_path
|
||||||
|
|
||||||
|
|
||||||
|
def _fail(message):
|
||||||
|
raise TaskCenterError('desktop_slot_busy', message)
|
||||||
|
|
||||||
|
|
||||||
|
def _context():
|
||||||
|
import win32api
|
||||||
|
import win32con
|
||||||
|
import win32security
|
||||||
|
import win32service
|
||||||
|
token = win32security.OpenProcessToken(win32api.GetCurrentProcess(), win32con.TOKEN_QUERY)
|
||||||
|
try:
|
||||||
|
sid = win32security.GetTokenInformation(token, win32security.TokenUser)[0]
|
||||||
|
groups = win32security.GetTokenInformation(token, win32security.TokenGroups)
|
||||||
|
logon = [value for value, flags in groups if flags & 0xC0000000 == 0xC0000000]
|
||||||
|
if len(logon) != 1:
|
||||||
|
_fail('无法确认当前 Windows 登录会话,未创建桌面。')
|
||||||
|
return dict(sid=win32security.ConvertSidToStringSid(sid),
|
||||||
|
logon=win32security.ConvertSidToStringSid(logon[0]),
|
||||||
|
station=win32service.GetUserObjectInformation(win32service.GetProcessWindowStation(), 2))
|
||||||
|
finally:
|
||||||
|
token.Close()
|
||||||
|
|
||||||
|
|
||||||
|
class _Windows:
|
||||||
|
def lock(self, name):
|
||||||
|
import win32event
|
||||||
|
mutex = win32event.CreateMutex(None, False, name)
|
||||||
|
# A mutex is recursive on one thread; separate desktop owners are not.
|
||||||
|
if name in _held:
|
||||||
|
mutex.Close()
|
||||||
|
_fail('当前进程已有桌面租用,等待本批收尾后再领取。')
|
||||||
|
ready, release = Event(), Event()
|
||||||
|
result = {}
|
||||||
|
def own_mutex():
|
||||||
|
try:
|
||||||
|
result['acquired'] = win32event.WaitForSingleObject(mutex, 0) in (0, 0x80)
|
||||||
|
except Exception as error:
|
||||||
|
result['error'] = error
|
||||||
|
finally:
|
||||||
|
ready.set()
|
||||||
|
if result.get('acquired'):
|
||||||
|
release.wait()
|
||||||
|
try: win32event.ReleaseMutex(mutex)
|
||||||
|
except Exception as error: result['error'] = error
|
||||||
|
# Runtime setup and worker-monitor cleanup occur on different threads;
|
||||||
|
# keep Windows mutex ownership on one short-lived dedicated thread.
|
||||||
|
thread = Thread(target=own_mutex, name='desktop-slot-mutex', daemon=True)
|
||||||
|
thread.start(); ready.wait()
|
||||||
|
if not result.get('acquired'):
|
||||||
|
thread.join(); mutex.Close()
|
||||||
|
if 'error' in result: raise result['error']
|
||||||
|
_fail('桌面正在由另一批任务使用,请等待其收尾。')
|
||||||
|
_held.add(name)
|
||||||
|
return mutex, name, release, thread, result
|
||||||
|
|
||||||
|
def unlock(self, value):
|
||||||
|
handle, name, release, thread, result = value
|
||||||
|
release.set(); thread.join()
|
||||||
|
try:
|
||||||
|
if 'error' in result:
|
||||||
|
raise result['error']
|
||||||
|
finally:
|
||||||
|
try:
|
||||||
|
handle.Close()
|
||||||
|
finally:
|
||||||
|
_held.discard(name)
|
||||||
|
|
||||||
|
def desktop_exists(self, name):
|
||||||
|
import win32service
|
||||||
|
return name.casefold() in {s.casefold() for s in win32service.GetProcessWindowStation().EnumDesktops()}
|
||||||
|
|
||||||
|
def process_gone(self, identity):
|
||||||
|
from .batch_resources import _process_gone
|
||||||
|
return _process_gone(identity)
|
||||||
|
|
||||||
|
def job_empty(self, name):
|
||||||
|
import win32job
|
||||||
|
try:
|
||||||
|
handle = win32job.OpenJobObject(4, False, name) # JOB_OBJECT_QUERY
|
||||||
|
except Exception as error:
|
||||||
|
if getattr(error, 'winerror', error.args[0] if error.args else None) == 2:
|
||||||
|
return True # No handle remains; KILL_ON_JOB_CLOSE has been applied.
|
||||||
|
raise
|
||||||
|
try:
|
||||||
|
return win32job.QueryInformationJobObject(handle, win32job.JobObjectBasicAccountingInformation)['ActiveProcesses'] == 0
|
||||||
|
finally:
|
||||||
|
handle.Close()
|
||||||
|
|
||||||
|
def current_process(self):
|
||||||
|
import win32api
|
||||||
|
import win32process
|
||||||
|
return dict(pid=os.getpid(), creation_time=str(win32process.GetProcessTimes(win32api.GetCurrentProcess())['CreationTime']))
|
||||||
|
|
||||||
|
|
||||||
|
_held = set()
|
||||||
|
|
||||||
|
|
||||||
|
def returned_lease_intact(receipt, name):
|
||||||
|
"""Read an immutable *past* return; never query or close a newer lease."""
|
||||||
|
try:
|
||||||
|
data = internal_path(receipt['path']).read_bytes()
|
||||||
|
record = json.loads(data)
|
||||||
|
return (receipt['returned'] is True and receipt['name'] == name
|
||||||
|
and hashlib.sha256(data).hexdigest() == receipt['sha256']
|
||||||
|
and record['lease_id'] == receipt['lease_id'] and record['scope'] == receipt['scope']
|
||||||
|
and record['name'] == name and record['state'] == 'idle' and record['writers_exited'] is True)
|
||||||
|
except (OSError, ValueError, KeyError, TypeError):
|
||||||
|
return False
|
||||||
|
|
||||||
|
|
||||||
|
def managed_desktop_disappeared(receipt):
|
||||||
|
"""Observe under the same mutex; an active newer lease is left untouched."""
|
||||||
|
backend = _Windows()
|
||||||
|
try:
|
||||||
|
mutex = backend.lock('Local\\DxPartReplace-Desktop-' + receipt['scope'])
|
||||||
|
except TaskCenterError:
|
||||||
|
return False
|
||||||
|
try:
|
||||||
|
return not backend.desktop_exists(receipt['name'])
|
||||||
|
finally:
|
||||||
|
backend.unlock(mutex)
|
||||||
|
|
||||||
|
|
||||||
|
def observe_current_desktop_name(name):
|
||||||
|
"""Observe a historical name in this logon without opening a desktop handle."""
|
||||||
|
slot = DesktopSlot()
|
||||||
|
if slot.name != name:
|
||||||
|
return None
|
||||||
|
return managed_desktop_disappeared({'scope': slot.scope, 'name': slot.name})
|
||||||
|
|
||||||
|
|
||||||
|
class DesktopSlot:
|
||||||
|
def __init__(self, *, root=None, context=None, backend=None):
|
||||||
|
self.context = _context() if context is None else context
|
||||||
|
digest = hashlib.sha256(json.dumps(self.context, sort_keys=True).encode()).hexdigest()[:32]
|
||||||
|
self.name = 'dx-' + digest
|
||||||
|
self.scope = digest
|
||||||
|
self.backend = _Windows() if backend is None else backend
|
||||||
|
base = Path(root) if root is not None else Path(os.environ['LOCALAPPDATA']) / 'DxPartReplace/desktop-slots'
|
||||||
|
internal_path(base).mkdir(parents=True, exist_ok=True)
|
||||||
|
base = canonical_path(base)
|
||||||
|
self.path = base / digest / 'slot.json'
|
||||||
|
self.lease_id = uuid4().hex
|
||||||
|
self.return_path = self.path.parent / 'leases' / (self.lease_id + '.json')
|
||||||
|
self.handle = None
|
||||||
|
self.receipt = None
|
||||||
|
self.record = None
|
||||||
|
|
||||||
|
def _save(self, record):
|
||||||
|
write_record(self.path, record)
|
||||||
|
self.record = record
|
||||||
|
|
||||||
|
def _validate(self, record):
|
||||||
|
if (record.get('version') != 1 or record.get('context') != self.context
|
||||||
|
or record.get('name') != self.name or record.get('scope') != self.scope
|
||||||
|
or not re.fullmatch('[0-9a-f]{32}', record.get('lease_id', ''))
|
||||||
|
or record.get('state') not in {'leased', 'idle'} or not isinstance(record.get('launches'), list)):
|
||||||
|
_fail('桌面租用记录不完整,未打开桌面。')
|
||||||
|
identities = [record['owner'], *(r['process'] for r in record['launches'] if r.get('process'))]
|
||||||
|
if any(type(item.get('pid')) is not int or not isinstance(item.get('creation_time'), str)
|
||||||
|
or not item['creation_time'] for item in identities):
|
||||||
|
_fail('桌面原进程身份不完整,未打开桌面。')
|
||||||
|
for launch in record['launches']:
|
||||||
|
recoverable = launch.get('state') in {'started', 'closed'} or (
|
||||||
|
launch.get('state') == 'launching' and launch.get('atomic_job') is True)
|
||||||
|
if (not recoverable
|
||||||
|
or not re.fullmatch(r'Local\\DxPartReplace-Job-[0-9a-f]{32}', launch.get('job', ''))
|
||||||
|
or not self.backend.job_empty(launch['job'])
|
||||||
|
or launch.get('process') and not self.backend.process_gone(launch['process'])):
|
||||||
|
_fail('前批进程或启动尝试尚未确认退出,保留原桌面租用。')
|
||||||
|
|
||||||
|
def acquire(self):
|
||||||
|
if self.handle is not None or self.receipt is not None:
|
||||||
|
_fail('该租用已领取或归还,不能重复派发。')
|
||||||
|
self.handle = self.backend.lock('Local\\DxPartReplace-Desktop-' + self.scope)
|
||||||
|
try:
|
||||||
|
if internal_path(self.path).exists():
|
||||||
|
previous = json.loads(internal_path(self.path).read_text(encoding='utf-8'))
|
||||||
|
self._validate(previous)
|
||||||
|
if previous['state'] == 'leased' and not self.backend.process_gone(previous['owner']):
|
||||||
|
_fail('前批桌面持有者尚未退出,保留原租用。')
|
||||||
|
elif self.backend.desktop_exists(self.name):
|
||||||
|
_fail('同名桌面缺少归属记录,未收养现有桌面。')
|
||||||
|
self._save(dict(version=1, context=self.context, name=self.name, scope=self.scope,
|
||||||
|
lease_id=self.lease_id, owner=self.backend.current_process(), state='leased', launches=[]))
|
||||||
|
except Exception as error:
|
||||||
|
handle, self.handle = self.handle, None
|
||||||
|
self.backend.unlock(handle)
|
||||||
|
if isinstance(error, TaskCenterError): raise
|
||||||
|
raise TaskCenterError('desktop_slot_busy', '桌面租用记录无法核对,未创建新桌面。') from error
|
||||||
|
return self
|
||||||
|
|
||||||
|
def prepare_launch(self, *, atomic_job=False):
|
||||||
|
if self.handle is None or self.receipt is not None:
|
||||||
|
_fail('桌面租用已结束,禁止派发。')
|
||||||
|
job = 'Local\\DxPartReplace-Job-' + uuid4().hex
|
||||||
|
record = dict(self.record, launches=[*self.record['launches'],
|
||||||
|
dict(job=job, state='launching', process=None, atomic_job=atomic_job)])
|
||||||
|
self._save(record)
|
||||||
|
return job
|
||||||
|
|
||||||
|
def launched(self, job, process):
|
||||||
|
launches = [dict(item, state='started', process=process) if item['job'] == job else item
|
||||||
|
for item in self.record['launches']]
|
||||||
|
self._save(dict(self.record, launches=launches))
|
||||||
|
|
||||||
|
def launch_closed(self, job):
|
||||||
|
launches = [dict(item, state='closed') if item['job'] == job else item for item in self.record['launches']]
|
||||||
|
self._save(dict(self.record, launches=launches))
|
||||||
|
|
||||||
|
def release(self, *, desktop_disappeared):
|
||||||
|
if self.receipt is not None: return self.receipt
|
||||||
|
if self.handle is None: _fail('桌面租用未领取。')
|
||||||
|
self._validate(self.record)
|
||||||
|
record = dict(self.record, state='idle', writers_exited=True, desktop_disappeared=desktop_disappeared)
|
||||||
|
write_record(self.return_path, record)
|
||||||
|
self._save(record)
|
||||||
|
receipt = dict(returned=True, name=self.name, scope=self.scope, lease_id=self.lease_id,
|
||||||
|
desktop_disappeared=desktop_disappeared, path=str(self.return_path),
|
||||||
|
sha256=hashlib.sha256(internal_path(self.return_path).read_bytes()).hexdigest())
|
||||||
|
handle, self.handle = self.handle, None
|
||||||
|
self.receipt = receipt
|
||||||
|
self.backend.unlock(handle)
|
||||||
|
return receipt
|
||||||
@@ -9,16 +9,20 @@ import stat
|
|||||||
import zipfile
|
import zipfile
|
||||||
|
|
||||||
from .path_access import canonical_path, internal_path
|
from .path_access import canonical_path, internal_path
|
||||||
|
from .operation_diagnostics import summarize_operations
|
||||||
|
|
||||||
MAX_FILE_BYTES = 4 * 1024 * 1024
|
MAX_FILE_BYTES = 4 * 1024 * 1024
|
||||||
MAX_BUNDLE_BYTES = 32 * 1024 * 1024
|
MAX_BUNDLE_BYTES = 32 * 1024 * 1024
|
||||||
MAX_FILES = 512
|
MAX_FILES = 512
|
||||||
_BATCH_NAMES = {'session.json', 'supervisor.json', 'request.json', 'result.json',
|
_BATCH_NAMES = {'session.json', 'supervisor.json', 'request.json', 'result.json',
|
||||||
'business-result.json', 'supervisor.log', 'resource-release.log', 'cancel.json',
|
'business-result.json', 'supervisor.log', 'resource-release.log', 'cancel.json',
|
||||||
'process.json', 'lifecycle.jsonl', 'owner-loss.json', 'claim.json', 'force-request.json'}
|
'process.json', 'lifecycle.jsonl', 'owner-loss.json', 'claim.json', 'force-request.json',
|
||||||
|
'operation-events.jsonl'}
|
||||||
_QUICK_NAMES = {'private-desktop.json', 'checkpoint.json', 'status.json',
|
_QUICK_NAMES = {'private-desktop.json', 'checkpoint.json', 'status.json',
|
||||||
'uncertain.flag', 'resolved-uncertain.flag', 'protection.json', 'cleanup.json',
|
'uncertain.flag', 'resolved-uncertain.flag', 'protection.json', 'cleanup.json',
|
||||||
'project-session.json', 'project-checkpoint.json', 'project-read-release.json', 'status.tsv'}
|
'project-session.json', 'project-checkpoint.json', 'project-read-release.json', 'status.tsv',
|
||||||
|
'worker-progress.json', 'quick-part-replace.log', 'native-inventory.json', 'operation-events.jsonl',
|
||||||
|
'recovery-commit.json', 'retry-preparation.json'}
|
||||||
_SECRET_KEY = re.compile(r'(?:password|passwd|(?:client[_-]?)?secret|credentials?|authorization|api[_-]?key|access[_-]?token|refresh[_-]?token|token)', re.I)
|
_SECRET_KEY = re.compile(r'(?:password|passwd|(?:client[_-]?)?secret|credentials?|authorization|api[_-]?key|access[_-]?token|refresh[_-]?token|token)', re.I)
|
||||||
_USER_KEY = re.compile(r'(?:user(?:[_-]?name)?|login[_-]?name)', re.I)
|
_USER_KEY = re.compile(r'(?:user(?:[_-]?name)?|login[_-]?name)', re.I)
|
||||||
_SECRET_TEXT = re.compile(r'''(?ix)(\b(?:password|passwd|(?:client[_-]?)?secret|credentials?|authorization|api[_-]?key|access[_-]?token|refresh[_-]?token|token)\b["']?\s*[=:]\s*)(?:"[^"\r\n]*"|'[^'\r\n]*'|[^\s,;}]+)''')
|
_SECRET_TEXT = re.compile(r'''(?ix)(\b(?:password|passwd|(?:client[_-]?)?secret|credentials?|authorization|api[_-]?key|access[_-]?token|refresh[_-]?token|token)\b["']?\s*[=:]\s*)(?:"[^"\r\n]*"|'[^'\r\n]*'|[^\s,;}]+)''')
|
||||||
@@ -52,6 +56,15 @@ def _scrub_json(value):
|
|||||||
|
|
||||||
|
|
||||||
def _allowed(parts):
|
def _allowed(parts):
|
||||||
|
if parts[0] == 'execution-proof' or (len(parts) > 3 and parts[0] == 'tasks' and parts[2] == 'execution-proof'):
|
||||||
|
return (parts[-1] == 'completion.json'
|
||||||
|
or bool(re.fullmatch(r'project-(?:commit|pause)-[a-f0-9]{32}\.tsv', parts[-1]))
|
||||||
|
or bool(re.fullmatch(r'(?:post-state|value-readback)-[A-Za-z0-9_.-]+\.(?:tsv|json)', parts[-1])))
|
||||||
|
if (len(parts) >= 5 and parts[:1] == ('tasks',) and parts[2] == 'netlist-checks'):
|
||||||
|
return parts[-1] in {'verification.json', 'netlist.json', 'capture.json', 'export-cache.json'}
|
||||||
|
if (any(re.fullmatch(r'native-inventory-[A-Za-z0-9-]+', part) for part in parts)
|
||||||
|
and len(parts) >= 3 and parts[-2] == 'output'):
|
||||||
|
return parts[-1] in {'scope.txt', 'effective.txt'} or bool(re.fullmatch(r'icdb2ascii-(?:scope|effective)\.(?:stdout|stderr)\.txt', parts[-1], re.I))
|
||||||
if re.fullmatch(r'cad-dialogs-[a-f0-9]{32}\.json', parts[-1]):
|
if re.fullmatch(r'cad-dialogs-[a-f0-9]{32}\.json', parts[-1]):
|
||||||
return ((len(parts) == 4 and parts[0] == 'batch-resources' and re.fullmatch(r'generation-\d+', parts[2])) or
|
return ((len(parts) == 4 and parts[0] == 'batch-resources' and re.fullmatch(r'generation-\d+', parts[2])) or
|
||||||
any(value in parts for value in ('quick-run', 'quickrun', 'quick-run-history')))
|
any(value in parts for value in ('quick-run', 'quickrun', 'quick-run-history')))
|
||||||
@@ -71,7 +84,10 @@ def _allowed(parts):
|
|||||||
if len(parts) >= 2 and parts[0] in {'queue', 'queues', 'task-queues', 'workspace-queues'}:
|
if len(parts) >= 2 and parts[0] in {'queue', 'queues', 'task-queues', 'workspace-queues'}:
|
||||||
return parts[-1].endswith('.json')
|
return parts[-1].endswith('.json')
|
||||||
if len(parts) >= 2 and any(value in parts for value in ('quick-run', 'quickrun', 'quick-run-history')):
|
if len(parts) >= 2 and any(value in parts for value in ('quick-run', 'quickrun', 'quick-run-history')):
|
||||||
return parts[-1] in _QUICK_NAMES or bool(re.fullmatch(r'retained-worker-[a-f0-9]{32}\.json', parts[-1]))
|
return (parts[-1] in _QUICK_NAMES
|
||||||
|
or bool(re.fullmatch(r'retained-worker-[a-f0-9]{32}\.json', parts[-1]))
|
||||||
|
or bool(re.fullmatch(r'project-(?:commit|pause)-[a-f0-9]{32}\.tsv', parts[-1]))
|
||||||
|
or bool(re.fullmatch(r'(?:post-state|value-readback)-[A-Za-z0-9_.-]+\.(?:tsv|json)', parts[-1])))
|
||||||
return False
|
return False
|
||||||
|
|
||||||
|
|
||||||
@@ -84,11 +100,13 @@ def export_diagnostic_bundle(data_root, destination: Path) -> Path:
|
|||||||
root, destination = canonical_path(data_root), canonical_path(destination)
|
root, destination = canonical_path(data_root), canonical_path(destination)
|
||||||
if destination.suffix.lower() != '.zip':
|
if destination.suffix.lower() != '.zip':
|
||||||
raise ValueError('diagnostic destination must have a .zip suffix')
|
raise ValueError('diagnostic destination must have a .zip suffix')
|
||||||
manifest = {'version': 1, 'included': [], 'omissions': [], 'unknowns': [
|
manifest = {'version': 2, 'included': [], 'omissions': [], 'truncated': [], 'unknowns': [
|
||||||
'External desktop handle holders are unknown; empty window/thread lists do not prove release.',
|
|
||||||
'Active logs and metadata are point-in-time reads; no source CAD, libraries, BOM, database or environment configuration is included.'],
|
'Active logs and metadata are point-in-time reads; no source CAD, libraries, BOM, database or environment configuration is included.'],
|
||||||
'limits': {'max_file_bytes': MAX_FILE_BYTES, 'max_bundle_bytes': MAX_BUNDLE_BYTES, 'max_files': MAX_FILES}}
|
'limits': {'max_file_bytes': MAX_FILE_BYTES, 'max_bundle_bytes': MAX_BUNDLE_BYTES, 'max_files': MAX_FILES}}
|
||||||
total = 0
|
total = 0
|
||||||
|
candidates = []
|
||||||
|
operations = {}
|
||||||
|
items = {}
|
||||||
physical = internal_path(root)
|
physical = internal_path(root)
|
||||||
# os.walk does not descend symlinks; explicitly prune Windows junctions too.
|
# os.walk does not descend symlinks; explicitly prune Windows junctions too.
|
||||||
with zipfile.ZipFile(internal_path(destination), 'x', compression=zipfile.ZIP_DEFLATED) as archive:
|
with zipfile.ZipFile(internal_path(destination), 'x', compression=zipfile.ZIP_DEFLATED) as archive:
|
||||||
@@ -101,7 +119,7 @@ def export_diagnostic_bundle(data_root, destination: Path) -> Path:
|
|||||||
info = entry.lstat()
|
info = entry.lstat()
|
||||||
if stat.S_ISLNK(info.st_mode) or getattr(info, 'st_file_attributes', 0) & 0x400:
|
if stat.S_ISLNK(info.st_mode) or getattr(info, 'st_file_attributes', 0) & 0x400:
|
||||||
manifest['omissions'].append({'path': _scrub_text(relative), 'reason': 'link_or_reparse_point'})
|
manifest['omissions'].append({'path': _scrub_text(relative), 'reason': 'link_or_reparse_point'})
|
||||||
elif base == physical and name not in {'logs', 'batch-resources', 'attempts', 'tasks', 'queue', 'queues', 'task-queues', 'workspace-queues', 'quick-run', 'quick-run-history'}:
|
elif base == physical and name not in {'logs', 'batch-resources', 'attempts', 'tasks', 'queue', 'queues', 'task-queues', 'workspace-queues', 'quick-run', 'quick-run-history', 'execution-proof'}:
|
||||||
manifest['omissions'].append({'path': _scrub_text(relative), 'reason': 'outside_allowlist'})
|
manifest['omissions'].append({'path': _scrub_text(relative), 'reason': 'outside_allowlist'})
|
||||||
else:
|
else:
|
||||||
safe_folders.append(name)
|
safe_folders.append(name)
|
||||||
@@ -119,28 +137,94 @@ def export_diagnostic_bundle(data_root, destination: Path) -> Path:
|
|||||||
reason = 'link_or_reparse_point'
|
reason = 'link_or_reparse_point'
|
||||||
elif not stat.S_ISREG(info.st_mode):
|
elif not stat.S_ISREG(info.st_mode):
|
||||||
reason = 'not_regular_file'
|
reason = 'not_regular_file'
|
||||||
elif info.st_size > MAX_FILE_BYTES or total + info.st_size > MAX_BUNDLE_BYTES or len(manifest['included']) >= MAX_FILES:
|
|
||||||
reason = 'size_or_count_limit'
|
|
||||||
else:
|
else:
|
||||||
with path.open('rb') as source:
|
candidates.append((info.st_mtime_ns, path, relative, label, info.st_size))
|
||||||
payload = source.read(MAX_FILE_BYTES + 1)
|
|
||||||
if len(payload) > MAX_FILE_BYTES or b'\x00' in payload:
|
|
||||||
reason = 'binary_or_size_limit'
|
|
||||||
else:
|
|
||||||
text = payload.decode('utf-8-sig')
|
|
||||||
if relative.suffix == '.json':
|
|
||||||
text = json.dumps(_scrub_json(json.loads(text)), ensure_ascii=False, indent=2)
|
|
||||||
elif '.jsonl' in relative.name:
|
|
||||||
text = '\n'.join(json.dumps(_scrub_json(json.loads(line)), ensure_ascii=False)
|
|
||||||
for line in text.splitlines() if line.strip()) + '\n'
|
|
||||||
else:
|
|
||||||
text = _scrub_text(text)
|
|
||||||
archive.writestr(label, text)
|
|
||||||
total += len(payload)
|
|
||||||
manifest['included'].append(label)
|
|
||||||
except (OSError, UnicodeError, ValueError):
|
except (OSError, UnicodeError, ValueError):
|
||||||
reason = 'unreadable_or_invalid_text'
|
reason = 'unreadable_or_invalid_text'
|
||||||
if reason:
|
if reason:
|
||||||
manifest['omissions'].append({'path': label, 'reason': reason})
|
manifest['omissions'].append({'path': label, 'reason': reason})
|
||||||
|
# Current failures must survive a busy workspace's file/count budget.
|
||||||
|
for _, path, relative, label, size in sorted(candidates, key=lambda row: (-row[0], row[3])):
|
||||||
|
reason = None
|
||||||
|
budget = min(MAX_FILE_BYTES, MAX_BUNDLE_BYTES - total)
|
||||||
|
try:
|
||||||
|
tail = bool(re.search(r'\.(?:log|jsonl)(?:\.\d+)?$', relative.name))
|
||||||
|
truncated = size > budget
|
||||||
|
if len(manifest['included']) >= MAX_FILES or budget <= 0 or (truncated and (not tail or budget < 64)):
|
||||||
|
reason = 'size_or_count_limit'
|
||||||
|
else:
|
||||||
|
info = path.lstat()
|
||||||
|
if stat.S_ISLNK(info.st_mode) or getattr(info, 'st_file_attributes', 0) & 0x400 or info.st_nlink != 1:
|
||||||
|
manifest['omissions'].append({'path': label, 'reason': 'link_or_reparse_point'})
|
||||||
|
continue
|
||||||
|
with path.open('rb') as source:
|
||||||
|
if truncated:
|
||||||
|
source.seek(max(0, size - budget))
|
||||||
|
source.readline(budget + 1) # Discard clipped credentials and UTF-8 lines.
|
||||||
|
payload = source.read(budget + 1)
|
||||||
|
if len(payload) > budget or b'\x00' in payload:
|
||||||
|
reason = 'binary_or_size_limit'
|
||||||
|
elif not payload and size:
|
||||||
|
reason = 'no_complete_tail_line'
|
||||||
|
else:
|
||||||
|
try:
|
||||||
|
content = payload.decode('utf-8-sig')
|
||||||
|
except UnicodeDecodeError:
|
||||||
|
if relative.name not in {'scope.txt', 'effective.txt'}:
|
||||||
|
raise
|
||||||
|
content = payload.decode('mbcs' if os.name == 'nt' else 'cp1252')
|
||||||
|
if relative.suffix == '.json':
|
||||||
|
content = json.dumps(_scrub_json(json.loads(content)), ensure_ascii=False, indent=2)
|
||||||
|
elif '.jsonl' in relative.name:
|
||||||
|
records, invalid = [], 0
|
||||||
|
for line in content.splitlines():
|
||||||
|
if not line.strip():
|
||||||
|
continue
|
||||||
|
try:
|
||||||
|
records.append(_scrub_json(json.loads(line)))
|
||||||
|
except ValueError:
|
||||||
|
invalid += 1
|
||||||
|
content = '\n'.join(json.dumps(record, ensure_ascii=False) for record in records) + '\n'
|
||||||
|
if invalid:
|
||||||
|
manifest['omissions'].append({'path': label, 'reason': 'invalid_jsonl_lines', 'lines': invalid})
|
||||||
|
else:
|
||||||
|
content = _scrub_text(content)
|
||||||
|
encoded = content.encode('utf-8')
|
||||||
|
if tail and budget >= 64 and len(encoded) > budget:
|
||||||
|
# Redaction may grow a short secret. Trim complete oldest lines again.
|
||||||
|
offset, remaining = 0, len(encoded)
|
||||||
|
for line in encoded.splitlines(keepends=True):
|
||||||
|
if remaining <= budget:
|
||||||
|
break
|
||||||
|
offset += len(line)
|
||||||
|
remaining -= len(line)
|
||||||
|
encoded = encoded[offset:]
|
||||||
|
content = encoded.decode('utf-8')
|
||||||
|
truncated = True
|
||||||
|
if '.jsonl' in relative.name:
|
||||||
|
records = [json.loads(line) for line in content.splitlines() if line.strip()]
|
||||||
|
if len(encoded) > budget:
|
||||||
|
reason = 'size_or_count_limit'
|
||||||
|
else:
|
||||||
|
archive.writestr(label, encoded)
|
||||||
|
total += len(encoded)
|
||||||
|
manifest['included'].append(label)
|
||||||
|
if truncated:
|
||||||
|
manifest['truncated'].append({'path': label, 'mode': 'tail', 'source_bytes': size})
|
||||||
|
if relative.name == 'operation-events.jsonl':
|
||||||
|
operations[_scrub_text(relative.parent.as_posix())] = summarize_operations(records)
|
||||||
|
elif relative.name == 'status.tsv':
|
||||||
|
rows = [line.split('\t') for line in content.splitlines() if line.strip()]
|
||||||
|
rows = [row for row in rows if len(row) >= 4 and row[0] != 'job_id']
|
||||||
|
if rows:
|
||||||
|
saved = [row[0] for row in rows if row[1] in {'saved_ok', 'restored_ok'}]
|
||||||
|
items[_scrub_text(relative.parent.as_posix())] = {
|
||||||
|
'last_successful_item': saved[-1] if saved else None,
|
||||||
|
'latest_item': {'job_id': rows[-1][0], 'state': rows[-1][1]}}
|
||||||
|
except (OSError, UnicodeError, ValueError):
|
||||||
|
reason = 'unreadable_or_invalid_text'
|
||||||
|
if reason:
|
||||||
|
manifest['omissions'].append({'path': label, 'reason': reason})
|
||||||
|
archive.writestr('closure-summary.json', json.dumps({'operations': operations, 'items': items}, ensure_ascii=False, indent=2))
|
||||||
archive.writestr('manifest.json', json.dumps(manifest, ensure_ascii=False, indent=2))
|
archive.writestr('manifest.json', json.dumps(manifest, ensure_ascii=False, indent=2))
|
||||||
return destination
|
return destination
|
||||||
@@ -27,3 +27,7 @@ class TaskCenterError(ValueError):
|
|||||||
def _new_error_id() -> str:
|
def _new_error_id() -> str:
|
||||||
date = datetime.now(timezone.utc).strftime("%Y%m%d")
|
date = datetime.now(timezone.utc).strftime("%Y%m%d")
|
||||||
return f"DXT-{date}-{secrets.token_hex(4).upper()}"
|
return f"DXT-{date}-{secrets.token_hex(4).upper()}"
|
||||||
|
|
||||||
|
|
||||||
|
class ProjectPathError(TaskCenterError):
|
||||||
|
"""An expected filesystem failure while reading or selecting projects."""
|
||||||
@@ -14,25 +14,43 @@ class ExecutionFeedback:
|
|||||||
stage: str = ''
|
stage: str = ''
|
||||||
stage_seconds: float = 0.0
|
stage_seconds: float = 0.0
|
||||||
waiting_for_safe_completion: bool = False
|
waiting_for_safe_completion: bool = False
|
||||||
|
stopping_reason: str = ''
|
||||||
|
wait_reason: str = ''
|
||||||
|
primary_error: str = ''
|
||||||
|
|
||||||
|
|
||||||
|
def wait_reason_for_stage(stage):
|
||||||
|
return {'save_and_close': 'save', 'verify_saved_project': 'readback', 'saved_source_wait': 'readback',
|
||||||
|
'native_snapshot_read': 'readback', 'capture_semantic_state': 'readback',
|
||||||
|
'private_shutdown': 'desktop_release',
|
||||||
|
'awaiting_reconciliation': 'reconciliation', 'mentor_exit': 'mentor_exit',
|
||||||
|
'desktop_release': 'desktop_release'}.get(stage,
|
||||||
|
'native_call' if stage in {'native_replace', 'restore_attributes',
|
||||||
|
'restore_attribute_fields', 'verify_restoration', 'verify_attribute_fields'} else '')
|
||||||
|
|
||||||
|
|
||||||
def read_feedback(task_id, position, total, message, root: Path, started_after: float):
|
def read_feedback(task_id, position, total, message, root: Path, started_after: float):
|
||||||
|
private_state = ''
|
||||||
|
private_seconds = 0.0
|
||||||
private = root / 'quick-run' / 'private-desktop.json'
|
private = root / 'quick-run' / 'private-desktop.json'
|
||||||
try:
|
try:
|
||||||
modified = private.stat().st_mtime
|
modified = private.stat().st_mtime
|
||||||
if modified >= started_after:
|
if modified >= started_after:
|
||||||
state = json.loads(private.read_text(encoding='utf-8')).get('state')
|
state = json.loads(private.read_text(encoding='utf-8')).get('state')
|
||||||
if state in {'starting', 'closing'}:
|
if state in {'starting', 'closing'}:
|
||||||
return ExecutionFeedback(task_id, position, total, message,
|
private_state = 'private_startup' if state == 'starting' else 'private_shutdown'
|
||||||
'private_startup' if state == 'starting' else 'private_shutdown', max(0, time.time() - modified))
|
private_seconds = max(0, time.time() - modified)
|
||||||
except (OSError, ValueError, TypeError, AttributeError):
|
except (OSError, ValueError, TypeError, AttributeError):
|
||||||
pass
|
pass
|
||||||
path = root / 'quick-run' / 'worker-progress.json'
|
path = root / 'quick-run' / 'worker-progress.json'
|
||||||
stage, seconds, waiting = '', 0.0, False
|
stage, seconds, waiting = '', 0.0, False
|
||||||
|
record = {}
|
||||||
try:
|
try:
|
||||||
modified = path.stat().st_mtime
|
modified = path.stat().st_mtime
|
||||||
if modified >= started_after:
|
if modified >= started_after:
|
||||||
record = json.loads(path.read_text(encoding='utf-8'))
|
record = json.loads(path.read_text(encoding='utf-8'))
|
||||||
|
if not isinstance(record, dict):
|
||||||
|
record = {}
|
||||||
waiting = record.get('waiting_for_safe_completion') is True
|
waiting = record.get('waiting_for_safe_completion') is True
|
||||||
candidate = record.get('stage', '')
|
candidate = record.get('stage', '')
|
||||||
if candidate and candidate != 'finished':
|
if candidate and candidate != 'finished':
|
||||||
@@ -40,4 +58,14 @@ def read_feedback(task_id, position, total, message, root: Path, started_after:
|
|||||||
stage = candidate
|
stage = candidate
|
||||||
except (OSError, ValueError, TypeError, AttributeError):
|
except (OSError, ValueError, TypeError, AttributeError):
|
||||||
pass # Display feedback is optional; it never changes execution state.
|
pass # Display feedback is optional; it never changes execution state.
|
||||||
return ExecutionFeedback(task_id, position, total, message, stage, seconds, waiting)
|
if private_state:
|
||||||
|
stage, seconds = private_state, private_seconds
|
||||||
|
stopping_reason = record.get('stopping_reason', '')
|
||||||
|
if not stopping_reason and record.get('stop_requested'):
|
||||||
|
stopping_reason = 'inactivity'
|
||||||
|
wait_reason = record.get('wait_reason') or wait_reason_for_stage(stage)
|
||||||
|
if private_state and wait_reason not in {'mentor_exit', 'desktop_release'}:
|
||||||
|
wait_reason = wait_reason_for_stage(stage)
|
||||||
|
return ExecutionFeedback(task_id, position, total, message, stage, seconds, waiting,
|
||||||
|
stopping_reason, wait_reason,
|
||||||
|
record.get('primary_error') or record.get('resolution_error') or '')
|
||||||
@@ -33,6 +33,11 @@ def create_execution_schema(connection):
|
|||||||
connection.execute('''CREATE TABLE IF NOT EXISTS execution_target_claims (
|
connection.execute('''CREATE TABLE IF NOT EXISTS execution_target_claims (
|
||||||
task_id TEXT NOT NULL, round_id TEXT NOT NULL, target_key TEXT NOT NULL,
|
task_id TEXT NOT NULL, round_id TEXT NOT NULL, target_key TEXT NOT NULL,
|
||||||
operation_key TEXT NOT NULL, PRIMARY KEY(task_id,round_id,target_key))''')
|
operation_key TEXT NOT NULL, PRIMARY KEY(task_id,round_id,target_key))''')
|
||||||
|
connection.execute('''CREATE TABLE IF NOT EXISTS execution_project_commits (
|
||||||
|
task_id TEXT NOT NULL, round_id TEXT NOT NULL, session_token TEXT NOT NULL,
|
||||||
|
project_path TEXT NOT NULL, evidence_root TEXT NOT NULL, state TEXT NOT NULL,
|
||||||
|
jobs_json TEXT NOT NULL, proof_json TEXT,
|
||||||
|
PRIMARY KEY(task_id,round_id,session_token))''')
|
||||||
|
|
||||||
|
|
||||||
def _json(value):
|
def _json(value):
|
||||||
@@ -115,7 +120,7 @@ class ExecutionJournal:
|
|||||||
current=self._round(task_id)
|
current=self._round(task_id)
|
||||||
if current:
|
if current:
|
||||||
unsafe=self.store._connection.execute('''SELECT 1 FROM execution_operations
|
unsafe=self.store._connection.execute('''SELECT 1 FROM execution_operations
|
||||||
WHERE task_id=? AND round_id=? AND state IN ('prepared','uncertain') LIMIT 1''',
|
WHERE task_id=? AND round_id=? AND state IN ('prepared','uncertain','pending_save') LIMIT 1''',
|
||||||
(task_id,current['round_id'])).fetchone()
|
(task_id,current['round_id'])).fetchone()
|
||||||
if unsafe:raise TaskCenterError('quick_run_uncertain','原执行项尚待核验,不能准备重试。')
|
if unsafe:raise TaskCenterError('quick_run_uncertain','原执行项尚待核验,不能准备重试。')
|
||||||
self.store._connection.execute('DELETE FROM execution_retry_selections WHERE task_id=?',(task_id,))
|
self.store._connection.execute('DELETE FROM execution_retry_selections WHERE task_id=?',(task_id,))
|
||||||
@@ -154,7 +159,7 @@ class ExecutionJournal:
|
|||||||
(task_id, current['round_id']))}
|
(task_id, current['round_id']))}
|
||||||
for key in json.loads(current['plan_json']):
|
for key in json.loads(current['plan_json']):
|
||||||
record = records.get(key)
|
record = records.get(key)
|
||||||
if record is None or record['state'] in {'prepared', 'uncertain'}:return False
|
if record is None or record['state'] in {'prepared', 'uncertain', 'pending_save'}:return False
|
||||||
if record['state'] == 'pending':
|
if record['state'] == 'pending':
|
||||||
command = json.loads(record['command_json'])
|
command = json.loads(record['command_json'])
|
||||||
return bool(self.can_continue_component(task_id, command))
|
return bool(self.can_continue_component(task_id, command))
|
||||||
@@ -392,13 +397,18 @@ class ExecutionJournal:
|
|||||||
if record is None or not self.certified_startup_pause(task_id, record):
|
if record is None or not self.certified_startup_pause(task_id, record):
|
||||||
return
|
return
|
||||||
proof = json.loads(record['receipt_json'] or '{}').get('startup_pause', {})
|
proof = json.loads(record['receipt_json'] or '{}').get('startup_pause', {})
|
||||||
|
status = internal_path(root / 'status.tsv').read_bytes()
|
||||||
|
status_size = proof.get('status_size')
|
||||||
|
if proof.get('phase') == 'before_native_dispatch' and type(status_size) is int and 0 < status_size <= len(status):
|
||||||
|
# A delayed marker retirement can follow appends to the certified stream.
|
||||||
|
status = status[:status_size]
|
||||||
if (proof.get('task_id') != task_id or proof.get('job_id') != row['job_id']
|
if (proof.get('task_id') != task_id or proof.get('job_id') != row['job_id']
|
||||||
or proof.get('native_dispatch_not_started') is not True
|
or proof.get('native_dispatch_not_started') is not True
|
||||||
or proof.get('project_closed') is not True or proof.get('worker_tree_exited') is not True
|
or proof.get('project_closed') is not True or proof.get('worker_tree_exited') is not True
|
||||||
or not proof.get('files') or not proof_intact(proof)
|
or not proof.get('files') or not proof_intact(proof)
|
||||||
or _source_digest(proof) != proof.get('source_sha256')
|
or _source_digest(proof) != proof.get('source_sha256')
|
||||||
or hashlib.sha256(marker.read_bytes()).hexdigest() != proof.get('current_command_sha256')
|
or hashlib.sha256(marker.read_bytes()).hexdigest() != proof.get('current_command_sha256')
|
||||||
or hashlib.sha256(internal_path(root / 'status.tsv').read_bytes()).hexdigest() != proof.get('status_sha256')
|
or hashlib.sha256(status).hexdigest() != proof.get('status_sha256')
|
||||||
# Scope cleanup removes this request after the durable pause;
|
# Scope cleanup removes this request after the durable pause;
|
||||||
# a surviving request must still match the certified one.
|
# a surviving request must still match the certified one.
|
||||||
or internal_path(root / 'project-session.request').exists() and hashlib.sha256(
|
or internal_path(root / 'project-session.request').exists() and hashlib.sha256(
|
||||||
@@ -430,7 +440,7 @@ class ExecutionJournal:
|
|||||||
with self.store._lock:
|
with self.store._lock:
|
||||||
current=self._round(task_id)
|
current=self._round(task_id)
|
||||||
return bool(current and self.store._connection.execute('''SELECT 1 FROM execution_operations
|
return bool(current and self.store._connection.execute('''SELECT 1 FROM execution_operations
|
||||||
WHERE task_id=? AND round_id=? AND state='prepared' LIMIT 1''',
|
WHERE task_id=? AND round_id=? AND state IN ('prepared','pending_save') LIMIT 1''',
|
||||||
(task_id,current['round_id'])).fetchone())
|
(task_id,current['round_id'])).fetchone())
|
||||||
|
|
||||||
def unresolved_jobs(self,task_id,rows):
|
def unresolved_jobs(self,task_id,rows):
|
||||||
@@ -438,7 +448,7 @@ class ExecutionJournal:
|
|||||||
current=self._round(task_id)
|
current=self._round(task_id)
|
||||||
if current is None:return ()
|
if current is None:return ()
|
||||||
keys={record[0] for record in self.store._connection.execute('''SELECT operation_key
|
keys={record[0] for record in self.store._connection.execute('''SELECT operation_key
|
||||||
FROM execution_operations WHERE task_id=? AND round_id=? AND state IN ('prepared','uncertain')''',
|
FROM execution_operations WHERE task_id=? AND round_id=? AND state IN ('prepared','uncertain','pending_save')''',
|
||||||
(task_id,current['round_id']))}
|
(task_id,current['round_id']))}
|
||||||
return tuple(row['job_id'] for row in rows if _hash(command_identity(row)) in keys)
|
return tuple(row['job_id'] for row in rows if _hash(command_identity(row)) in keys)
|
||||||
|
|
||||||
@@ -506,6 +516,8 @@ class ExecutionJournal:
|
|||||||
elif record['state']=='failed':
|
elif record['state']=='failed':
|
||||||
restored[row['job_id']]=tuple(json.loads(record['receipt_json'])[name] for name in ('native_state','code','message'))
|
restored[row['job_id']]=tuple(json.loads(record['receipt_json'])[name] for name in ('native_state','code','message'))
|
||||||
continue
|
continue
|
||||||
|
elif record['state']=='pending_save':
|
||||||
|
raise TaskCenterError('quick_run_uncertain','工程替换尚待统一保存回读,禁止重放;请先核验工程提交记录。')
|
||||||
outcome=latest.get(row['job_id'])
|
outcome=latest.get(row['job_id'])
|
||||||
if outcome and outcome[0] in _TERMINAL:
|
if outcome and outcome[0] in _TERMINAL:
|
||||||
record=connection.execute('''SELECT * FROM execution_operations
|
record=connection.execute('''SELECT * FROM execution_operations
|
||||||
@@ -546,6 +558,186 @@ class ExecutionJournal:
|
|||||||
WHERE task_id=? AND round_id=? AND operation_key=?''',(identifier,generation,task_id,current['round_id'],key))
|
WHERE task_id=? AND round_id=? AND operation_key=?''',(identifier,generation,task_id,current['round_id'],key))
|
||||||
return JournalAttempt(task_id,current['round_id'],key,identifier,generation,row['job_id'])
|
return JournalAttempt(task_id,current['round_id'],key,identifier,generation,row['job_id'])
|
||||||
|
|
||||||
|
def stage_project_result(self, attempt, row, *, session_token, root, proof):
|
||||||
|
"""Retain an applied operation without granting a saved receipt or retry."""
|
||||||
|
from .execution_proof import proof_intact
|
||||||
|
if not session_token or not proof_intact(proof):
|
||||||
|
raise TaskCenterError('quick_run_uncertain', '工程暂存证据不完整。')
|
||||||
|
with self.store.transaction():
|
||||||
|
connection = self.store._connection
|
||||||
|
record = connection.execute('''SELECT * FROM execution_operations
|
||||||
|
WHERE task_id=? AND round_id=? AND operation_key=?''',
|
||||||
|
(attempt.task_id, attempt.round_id, attempt.operation_key)).fetchone()
|
||||||
|
if (record is None or record['state'] != 'prepared' or record['attempt_id'] != attempt.attempt_id
|
||||||
|
or record['generation'] != attempt.generation or _hash(command_identity(row)) != attempt.operation_key):
|
||||||
|
raise TaskCenterError('quick_run_uncertain', '工程暂存结果不属于当前执行声明。')
|
||||||
|
project = command_identity(row)['project_path']
|
||||||
|
commit = connection.execute('''SELECT * FROM execution_project_commits
|
||||||
|
WHERE task_id=? AND round_id=? AND session_token=?''',
|
||||||
|
(attempt.task_id, attempt.round_id, session_token)).fetchone()
|
||||||
|
if commit and (commit['state'] != 'pending_save' or commit['project_path'] != project
|
||||||
|
or commit['evidence_root'] != str(canonical_path(root))):
|
||||||
|
raise TaskCenterError('quick_run_uncertain', '工程提交身份发生变化。')
|
||||||
|
jobs = json.loads(commit['jobs_json']) if commit else []
|
||||||
|
if row['job_id'] in jobs:
|
||||||
|
raise TaskCenterError('quick_run_uncertain', '工程暂存操作重复。')
|
||||||
|
jobs.append(row['job_id'])
|
||||||
|
connection.execute('''INSERT INTO execution_project_commits VALUES (?,?,?,?,?, 'pending_save',?,NULL)
|
||||||
|
ON CONFLICT(task_id,round_id,session_token) DO UPDATE SET jobs_json=excluded.jobs_json''',
|
||||||
|
(attempt.task_id, attempt.round_id, session_token, project, str(canonical_path(root)), _json(jobs)))
|
||||||
|
receipt = dict(native_state='pending_save', code='session_staged', message='替换已暂存,等待工程统一保存回读。',
|
||||||
|
job_id=row['job_id'], session_token=session_token, row=row, proof=proof,
|
||||||
|
operation_attempt=[attempt.operation_key, attempt.attempt_id, attempt.generation])
|
||||||
|
connection.execute('''UPDATE execution_operations SET state='pending_save',receipt_json=?
|
||||||
|
WHERE task_id=? AND round_id=? AND operation_key=?''',
|
||||||
|
(_json(receipt), attempt.task_id, attempt.round_id, attempt.operation_key))
|
||||||
|
|
||||||
|
def pending_project_commits(self, task_id):
|
||||||
|
with self.store._lock:
|
||||||
|
current = self._round(task_id)
|
||||||
|
if not current:return ()
|
||||||
|
return tuple(dict(row) for row in self.store._connection.execute('''SELECT * FROM execution_project_commits
|
||||||
|
WHERE task_id=? AND round_id=? AND state='pending_save' ''', (task_id, current['round_id'])))
|
||||||
|
|
||||||
|
def project_commit_records(self, task_id):
|
||||||
|
with self.store._lock:
|
||||||
|
current = self._round(task_id)
|
||||||
|
return tuple(dict(row) for row in self.store._connection.execute('''SELECT * FROM execution_project_commits
|
||||||
|
WHERE task_id=? AND round_id=?''', (task_id, current['round_id']))) if current else ()
|
||||||
|
|
||||||
|
def project_commit_attempts(self, task_id, session_token, *, require_recorded=False):
|
||||||
|
with self.store._lock:
|
||||||
|
current = self._round(task_id)
|
||||||
|
if not current:return {}
|
||||||
|
result = {}
|
||||||
|
for row in self.store._connection.execute('''SELECT * FROM execution_operations
|
||||||
|
WHERE task_id=? AND round_id=?''', (task_id, current['round_id'])):
|
||||||
|
receipt = json.loads(row['receipt_json'] or '{}')
|
||||||
|
token = receipt.get('session_token') or receipt.get('proof', {}).get('project_commit', {}).get('session_token')
|
||||||
|
if token == session_token:
|
||||||
|
actual = [row['operation_key'], row['attempt_id'], row['generation']]
|
||||||
|
original = receipt.get('operation_attempt') or receipt.get('proof', {}).get('project_commit', {}).get('operation_attempts', {}).get(receipt['job_id'])
|
||||||
|
if original != actual and (require_recorded or original is not None):
|
||||||
|
raise TaskCenterError('quick_run_uncertain', '原工程暂存尝试与当前执行记录不同。')
|
||||||
|
result[receipt['job_id']] = actual
|
||||||
|
return result
|
||||||
|
|
||||||
|
def project_commit_recovery_attempts(self, task_id):
|
||||||
|
"""Include actual attempts outside the frozen command rows as well."""
|
||||||
|
with self.store._lock:
|
||||||
|
current = self._round(task_id)
|
||||||
|
if not current:return ()
|
||||||
|
return tuple([row['operation_key'], row['attempt_id'], row['generation']]
|
||||||
|
for row in self.store._connection.execute('''SELECT operation_key,attempt_id,generation
|
||||||
|
FROM execution_operations WHERE task_id=? AND round_id=?
|
||||||
|
AND (attempt_id IS NOT NULL OR generation>0)''', (task_id, current['round_id'])))
|
||||||
|
|
||||||
|
def bind_project_commit_proof(self, task_id, session_token, proof):
|
||||||
|
with self.store.transaction():
|
||||||
|
current = self._round(task_id)
|
||||||
|
self.store._connection.execute('''UPDATE execution_project_commits SET proof_json=?
|
||||||
|
WHERE task_id=? AND round_id=? AND session_token=? AND state='pending_save' AND proof_json IS NULL''',
|
||||||
|
(_json(proof), task_id, current['round_id'], session_token))
|
||||||
|
|
||||||
|
def promote_project_commit_proof(self, task_id, session_token, expected_proof, verified_proof):
|
||||||
|
"""Attach native verification to the same saved attempt without replacing its source binding."""
|
||||||
|
from .execution_proof import proof_intact
|
||||||
|
with self.store.transaction():
|
||||||
|
current = self._round(task_id)
|
||||||
|
record = self.store._connection.execute('''SELECT * FROM execution_project_commits
|
||||||
|
WHERE task_id=? AND round_id=? AND session_token=?''',
|
||||||
|
(task_id, current['round_id'], session_token)).fetchone() if current else None
|
||||||
|
original = {key: value for key, value in expected_proof.items() if key not in {'files', 'outcomes', 'saved_netlist'}}
|
||||||
|
if (record is None or record['state'] != 'pending_save'
|
||||||
|
or expected_proof.get('session_token') != session_token
|
||||||
|
or expected_proof.get('validation_required') != 'saved_netlist_v1'
|
||||||
|
or verified_proof.get('saved_netlist', {}).get('status') != 'verified'
|
||||||
|
or any(verified_proof.get(key) != value for key, value in original.items())
|
||||||
|
or any(item not in verified_proof.get('files', []) for item in expected_proof.get('files', []))
|
||||||
|
or not proof_intact(verified_proof)
|
||||||
|
or json.loads(record['proof_json'] or 'null') not in (expected_proof, verified_proof)):
|
||||||
|
raise TaskCenterError('quick_run_uncertain', '原工程保存证明发生变化,不能覆盖核验结果。')
|
||||||
|
self.store._connection.execute('''UPDATE execution_project_commits SET proof_json=?
|
||||||
|
WHERE task_id=? AND round_id=? AND session_token=?''',
|
||||||
|
(_json(verified_proof), task_id, current['round_id'], session_token))
|
||||||
|
|
||||||
|
def staged_project_rows(self, task_id, session_token):
|
||||||
|
with self.store._lock:
|
||||||
|
current = self._round(task_id)
|
||||||
|
if not current:return ()
|
||||||
|
records = self.store._connection.execute('''SELECT receipt_json FROM execution_operations
|
||||||
|
WHERE task_id=? AND round_id=? AND state='pending_save' ''', (task_id, current['round_id']))
|
||||||
|
return tuple(receipt for record in records
|
||||||
|
if (receipt := json.loads(record[0])).get('session_token') == session_token)
|
||||||
|
|
||||||
|
def commit_project_results(self, task_id, session_token, proofs, commit_proof):
|
||||||
|
"""Commit a whole staged prefix and its history in one SQL transaction."""
|
||||||
|
from .execution_proof import proof_intact
|
||||||
|
statuses = []
|
||||||
|
with self.store.transaction():
|
||||||
|
connection = self.store._connection
|
||||||
|
current = self._round(task_id)
|
||||||
|
commit = connection.execute('''SELECT * FROM execution_project_commits
|
||||||
|
WHERE task_id=? AND round_id=? AND session_token=?''', (task_id, current['round_id'], session_token)).fetchone() if current else None
|
||||||
|
if commit is None:
|
||||||
|
raise TaskCenterError('quick_run_uncertain', '缺少原工程暂存提交记录。')
|
||||||
|
if commit['state'] == 'verified':return ()
|
||||||
|
jobs = json.loads(commit['jobs_json'])
|
||||||
|
if (commit_proof.get('session_token') != session_token
|
||||||
|
or str(canonical_path(commit_proof.get('project_path', ''))).casefold() != commit['project_path']
|
||||||
|
or commit_proof.get('jobs') != jobs or set(proofs) != set(jobs)
|
||||||
|
or not commit_proof.get('files') or not proof_intact(commit_proof)
|
||||||
|
or any(not proof.get('files') or not proof_intact(proof) for proof in proofs.values())):
|
||||||
|
raise TaskCenterError('quick_run_uncertain', '工程保存回读证明未覆盖全部暂存项。')
|
||||||
|
saved_protocol = commit_proof.get('marker_state') == 'project_saved' or commit_proof.get('validation_required') == 'saved_netlist_v1'
|
||||||
|
saved = commit_proof.get('saved_netlist', {})
|
||||||
|
if saved_protocol and (commit_proof.get('validation_required') != 'saved_netlist_v1'
|
||||||
|
or saved.get('status') != 'verified' or set(saved.get('jobs', {})) != set(jobs)
|
||||||
|
or set(commit_proof.get('native_outcomes', {})) != set(jobs)
|
||||||
|
or any(state not in {'pending_save', 'no_match'} for state in commit_proof['native_outcomes'].values())
|
||||||
|
or commit_proof.get('outcomes') != {job: 'saved_ok' if state == 'pending_save' else state
|
||||||
|
for job, state in commit_proof['native_outcomes'].items()}
|
||||||
|
or not saved.get('files') or not proof_intact(saved)):
|
||||||
|
raise TaskCenterError('quick_run_uncertain', '工程已保存,尚未完成原生数据核验。')
|
||||||
|
records = connection.execute('''SELECT * FROM execution_operations
|
||||||
|
WHERE task_id=? AND round_id=? AND state='pending_save' ''', (task_id, current['round_id'])).fetchall()
|
||||||
|
records = [record for record in records if json.loads(record['receipt_json']).get('session_token') == session_token]
|
||||||
|
if {json.loads(record['receipt_json'])['job_id'] for record in records} != set(jobs):
|
||||||
|
raise TaskCenterError('quick_run_uncertain', '工程暂存前缀与提交证明不一致。')
|
||||||
|
for record in records:
|
||||||
|
receipt = json.loads(record['receipt_json'])
|
||||||
|
job = receipt['job_id']
|
||||||
|
proof = dict(proofs[job])
|
||||||
|
if proof.get('native_attempt') != receipt.get('proof', {}).get('native_attempt'):
|
||||||
|
raise TaskCenterError('quick_run_uncertain', '保存回读与原暂存原生尝试不一致。')
|
||||||
|
if saved_protocol:
|
||||||
|
proof['project_commit'] = dict(session_token=session_token, project_path=commit_proof['project_path'],
|
||||||
|
validation_required='saved_netlist_v1',
|
||||||
|
operation_attempts={job: [record['operation_key'], record['attempt_id'], record['generation']]},
|
||||||
|
saved_netlist={key: saved[key] for key in ('status', 'export_path', 'export_sha256')})
|
||||||
|
command = json.loads(record['command_json'])
|
||||||
|
proof['baseline'] = dict(project_path=command['project_path'], schematic_name=command['schematic_name'],
|
||||||
|
sheet_number=command['sheet_number'], validation_mode='saved_netlist_v1',
|
||||||
|
state='N\tsaved_netlist_v1\t' + saved['export_sha256'])
|
||||||
|
shared = [{'path': saved['export_path'], 'sha256': saved['export_sha256']}]
|
||||||
|
if saved.get('verification_path'):
|
||||||
|
shared.append({'path': saved['verification_path'], 'sha256': saved['verification_sha256']})
|
||||||
|
proof['files'] = list(proof['files']) + [item for item in shared if item not in proof['files']]
|
||||||
|
else:
|
||||||
|
proof['project_commit'] = commit_proof
|
||||||
|
proof['files'] = list(proof['files']) + list(commit_proof['files'])
|
||||||
|
attempt = JournalAttempt(task_id, current['round_id'], record['operation_key'],
|
||||||
|
record['attempt_id'], record['generation'], job)
|
||||||
|
connection.execute('''UPDATE execution_operations SET state='prepared'
|
||||||
|
WHERE task_id=? AND round_id=? AND operation_key=?''', (task_id, current['round_id'], record['operation_key']))
|
||||||
|
native_state = commit_proof.get('outcomes', {}).get(job, 'saved_ok')
|
||||||
|
message = '工程统一保存,原生数据核验通过。' if saved_protocol else '工程统一保存、关闭重开及回读校验通过。'
|
||||||
|
self.finish(attempt, native_state, 'project_committed', message, proof=proof)
|
||||||
|
statuses.append((job, native_state, 'project_committed', message))
|
||||||
|
connection.execute('''UPDATE execution_project_commits SET state='verified',proof_json=?
|
||||||
|
WHERE task_id=? AND round_id=? AND session_token=?''', (_json(commit_proof), task_id, current['round_id'], session_token))
|
||||||
|
return tuple(statuses)
|
||||||
|
|
||||||
def finish(self,attempt,native_state,code,message,*,progress=None,proof=None):
|
def finish(self,attempt,native_state,code,message,*,progress=None,proof=None):
|
||||||
if native_state not in _TERMINAL:raise TaskCenterError('quick_run_uncertain','不能提交未知的执行结果。')
|
if native_state not in _TERMINAL:raise TaskCenterError('quick_run_uncertain','不能提交未知的执行结果。')
|
||||||
state=({'saved_ok':'verified','no_match':'no_match','restored_ok':'restored',
|
state=({'saved_ok':'verified','no_match':'no_match','restored_ok':'restored',
|
||||||
@@ -682,7 +874,7 @@ class ExecutionJournal:
|
|||||||
from .execution_proof import proof_intact
|
from .execution_proof import proof_intact
|
||||||
if not proof_intact(receipt.get('proof',{})):return True
|
if not proof_intact(receipt.get('proof',{})):return True
|
||||||
if not outcome or tuple(outcome[:2])!=(receipt['native_state'],receipt['code']):return True
|
if not outcome or tuple(outcome[:2])!=(receipt['native_state'],receipt['code']):return True
|
||||||
elif record['state']=='uncertain':return True
|
elif record['state'] in {'uncertain','pending_save'}:return True
|
||||||
elif record['state']=='prepared' and (not outcome or outcome[0] not in _TERMINAL):return True
|
elif record['state']=='prepared' and (not outcome or outcome[0] not in _TERMINAL):return True
|
||||||
return False
|
return False
|
||||||
|
|
||||||
|
|||||||
@@ -17,14 +17,35 @@ def proof_intact(proof):
|
|||||||
except (OSError,ValueError,KeyError,TypeError):return False
|
except (OSError,ValueError,KeyError,TypeError):return False
|
||||||
|
|
||||||
|
|
||||||
def capture_result(data_root,root,row,outcome,*,strict=False,persist=True):
|
def capture_result(data_root,root,row,outcome,*,strict=False,persist=True,project_commit=None):
|
||||||
from .quick_run import _decode_vbs_field, _safe_run_token
|
from .quick_run import _decode_vbs_field, _safe_run_token
|
||||||
from .native_helper import read_snapshot, require_resumable_transaction, snapshot_target_cell
|
from .native_helper import read_snapshot, require_resumable_transaction, snapshot_target_cell, saved_netlist_snapshot
|
||||||
state,code,_=outcome
|
state,code,_=outcome
|
||||||
proof={'files':[]}
|
proof={'files':[]}
|
||||||
paths=[]
|
paths=[]
|
||||||
try:
|
try:
|
||||||
_safe_run_token(row['job_id'])
|
_safe_run_token(row['job_id'])
|
||||||
|
snapshot = internal_path(root/f'snapshot-{row["job_id"]}.tsv')
|
||||||
|
saved_protocol = ((snapshot.is_file() and saved_netlist_snapshot(snapshot))
|
||||||
|
or bool(project_commit and project_commit.get('validation_required') == 'saved_netlist_v1'))
|
||||||
|
if saved_protocol:
|
||||||
|
proof['validation_required'] = 'saved_netlist_v1'
|
||||||
|
if state in {'saved_ok', 'no_match'}:
|
||||||
|
saved = (project_commit or {}).get('saved_netlist', {})
|
||||||
|
if saved.get('status') != 'verified' or row['job_id'] not in saved.get('jobs', {}):
|
||||||
|
raise ValueError('saved native netlist proof is required')
|
||||||
|
proof['saved_netlist'] = {key:saved[key] for key in ('status','export_path','export_sha256')}
|
||||||
|
proof['value_readback'] = saved['jobs'][row['job_id']]
|
||||||
|
if state == 'no_match' and persist:
|
||||||
|
destination = internal_path(data_root/'execution-proof'/uuid4().hex)
|
||||||
|
destination.mkdir(parents=True,exist_ok=False)
|
||||||
|
target = destination/f'no-match-{row["job_id"]}.json'
|
||||||
|
reference = dict(command=dict(row),session_token=project_commit['session_token'],
|
||||||
|
**{key:saved[key] for key in ('export_path','export_sha256','verification_path','verification_sha256')})
|
||||||
|
data = json.dumps(reference,ensure_ascii=False,sort_keys=True).encode('utf-8')
|
||||||
|
with target.open('xb') as stream:
|
||||||
|
stream.write(data);stream.flush();os.fsync(stream.fileno())
|
||||||
|
proof['files'].append({'path':str(canonical_path(target)),'sha256':hashlib.sha256(data).hexdigest()})
|
||||||
if row.get('execution_unit') == 'inventory_empty':
|
if row.get('execution_unit') == 'inventory_empty':
|
||||||
from .component_scope import validate_empty_command
|
from .component_scope import validate_empty_command
|
||||||
if state != 'batch_skipped' or not validate_empty_command(root, row):
|
if state != 'batch_skipped' or not validate_empty_command(root, row):
|
||||||
@@ -33,13 +54,13 @@ def capture_result(data_root,root,row,outcome,*,strict=False,persist=True):
|
|||||||
checked_manifest = manifest.read_bytes()
|
checked_manifest = manifest.read_bytes()
|
||||||
paths.append(manifest)
|
paths.append(manifest)
|
||||||
proof['inventory_empty'] = True
|
proof['inventory_empty'] = True
|
||||||
if strict and state in {'saved_ok','no_match'} and code not in {'batch_closed','session_verified'}:
|
if strict and state in {'saved_ok','no_match'} and code not in {'batch_closed','session_verified','project_committed'}:
|
||||||
raise ValueError('save/close was not verified')
|
raise ValueError('save/close was not verified')
|
||||||
checked={}
|
checked={}
|
||||||
if row.get('execution_unit') == 'inventory_empty':
|
if row.get('execution_unit') == 'inventory_empty':
|
||||||
checked[manifest] = checked_manifest
|
checked[manifest] = checked_manifest
|
||||||
baseline=internal_path(root/f'post-state-{row["job_id"]}.tsv')
|
baseline=internal_path(root/f'post-state-{row["job_id"]}.tsv')
|
||||||
if baseline.is_file():
|
if baseline.is_file() and not saved_protocol:
|
||||||
checked[baseline]=baseline.read_bytes()
|
checked[baseline]=baseline.read_bytes()
|
||||||
with baseline.open(encoding='utf-8-sig',newline='') as stream:
|
with baseline.open(encoding='utf-8-sig',newline='') as stream:
|
||||||
rows=list(csv.DictReader(stream,delimiter='\t'))
|
rows=list(csv.DictReader(stream,delimiter='\t'))
|
||||||
@@ -53,9 +74,9 @@ def capture_result(data_root,root,row,outcome,*,strict=False,persist=True):
|
|||||||
proof['baseline']={'project_path':str(canonical_path(row['project_path'])).casefold(),
|
proof['baseline']={'project_path':str(canonical_path(row['project_path'])).casefold(),
|
||||||
'schematic_name':actual['schematic_name'],'sheet_number':actual['sheet_number'],'state':actual['semantic_state']}
|
'schematic_name':actual['schematic_name'],'sheet_number':actual['sheet_number'],'state':actual['semantic_state']}
|
||||||
paths.append(baseline)
|
paths.append(baseline)
|
||||||
elif strict and state in {'saved_ok','no_match','restored_ok','recovery_readback'}:
|
elif strict and not saved_protocol and state in {'saved_ok','no_match','restored_ok','recovery_readback'}:
|
||||||
raise ValueError('missing verified semantic state')
|
raise ValueError('missing verified semantic state')
|
||||||
if state=='saved_ok' or (state=='restored_ok' and code in {'recovery_verified','recovery_saved_verified'}):
|
if state=='saved_ok' or (state=='pending_save' and code == 'session_staged') or (state=='restored_ok' and code in {'recovery_verified','recovery_saved_verified'}):
|
||||||
snapshot=internal_path(root/f'snapshot-{row["job_id"]}.tsv')
|
snapshot=internal_path(root/f'snapshot-{row["job_id"]}.tsv')
|
||||||
report_path=Path(str(snapshot)+'.native.json')
|
report_path=Path(str(snapshot)+'.native.json')
|
||||||
if strict or snapshot.is_file() or report_path.is_file():
|
if strict or snapshot.is_file() or report_path.is_file():
|
||||||
@@ -74,7 +95,8 @@ def capture_result(data_root,root,row,outcome,*,strict=False,persist=True):
|
|||||||
raise ValueError('snapshot command changed')
|
raise ValueError('snapshot command changed')
|
||||||
attempt=report.get('batch_attempt')
|
attempt=report.get('batch_attempt')
|
||||||
if strict:
|
if strict:
|
||||||
if report.get('stage')!='native_replace_verified' or report.get('ok') is not True:
|
required_stage = 'native_replace_applied' if saved_protocol else 'native_replace_verified'
|
||||||
|
if report.get('stage')!=required_stage or report.get('ok') is not True:
|
||||||
raise ValueError('native result is not verified')
|
raise ValueError('native result is not verified')
|
||||||
if (not isinstance(attempt,dict) or attempt.get('job_id')!=row['job_id'] or
|
if (not isinstance(attempt,dict) or attempt.get('job_id')!=row['job_id'] or
|
||||||
attempt.get('task_id')!=row['task_id'] or
|
attempt.get('task_id')!=row['task_id'] or
|
||||||
@@ -84,6 +106,10 @@ def capture_result(data_root,root,row,outcome,*,strict=False,persist=True):
|
|||||||
raise ValueError('native attempt differs from this job')
|
raise ValueError('native attempt differs from this job')
|
||||||
proof['native_attempt']=attempt
|
proof['native_attempt']=attempt
|
||||||
paths.extend((snapshot,report_path))
|
paths.extend((snapshot,report_path))
|
||||||
|
if saved_protocol:
|
||||||
|
writer = internal_path(root/f'writer-expectations-{row["job_id"]}.tsv')
|
||||||
|
checked[writer] = writer.read_bytes()
|
||||||
|
paths.append(writer)
|
||||||
if any(path.read_bytes()!=data for path,data in checked.items()):
|
if any(path.read_bytes()!=data for path,data in checked.items()):
|
||||||
raise ValueError('execution evidence changed during receipt binding')
|
raise ValueError('execution evidence changed during receipt binding')
|
||||||
if persist and paths:
|
if persist and paths:
|
||||||
@@ -101,6 +127,57 @@ def capture_result(data_root,root,row,outcome,*,strict=False,persist=True):
|
|||||||
raise TaskCenterError('quick_run_uncertain','原生回执、尝试身份或工程语义基线无法核验,已停止以避免重复替换。') from error
|
raise TaskCenterError('quick_run_uncertain','原生回执、尝试身份或工程语义基线无法核验,已停止以避免重复替换。') from error
|
||||||
|
|
||||||
|
|
||||||
|
def capture_project_commit(data_root, root, commit):
|
||||||
|
"""Bind a durable project marker to the exact staged prefix before SQL commit."""
|
||||||
|
from .quick_run import _decode_vbs_field
|
||||||
|
try:
|
||||||
|
path = internal_path(Path(root) / f'project-commit-{commit["session_token"]}.tsv')
|
||||||
|
data = path.read_bytes()
|
||||||
|
lines = data.decode('utf-8-sig').splitlines()
|
||||||
|
token, project, state = lines[0].split('\t')
|
||||||
|
outcomes = [line.split('\t') for line in lines[1:] if line]
|
||||||
|
jobs = json.loads(commit['jobs_json'])
|
||||||
|
saved_only = state == 'project_saved'
|
||||||
|
allowed = {'pending_save', 'no_match'} if saved_only else {'saved_ok', 'no_match'}
|
||||||
|
if (token != commit['session_token'] or state not in {'project_verified', 'project_saved'}
|
||||||
|
or str(canonical_path(_decode_vbs_field(project))).casefold() != commit['project_path']
|
||||||
|
or [outcome[0] for outcome in outcomes] != jobs
|
||||||
|
or any(len(outcome) != 2 or outcome[1] not in allowed for outcome in outcomes)):
|
||||||
|
raise ValueError('project commit does not cover staged prefix')
|
||||||
|
destination = internal_path(data_root / 'execution-proof' / uuid4().hex)
|
||||||
|
destination.mkdir(parents=True, exist_ok=False)
|
||||||
|
target = destination / path.name
|
||||||
|
with target.open('xb') as stream:
|
||||||
|
stream.write(data); stream.flush(); os.fsync(stream.fileno())
|
||||||
|
if path.read_bytes() != data:
|
||||||
|
raise ValueError('project marker changed during binding')
|
||||||
|
proof = dict(session_token=token, project_path=commit['project_path'], jobs=jobs,
|
||||||
|
outcomes=dict(outcomes), files=[dict(path=str(canonical_path(target)), sha256=hashlib.sha256(data).hexdigest())])
|
||||||
|
if saved_only:
|
||||||
|
proof.update(marker_state=state, saved_only=True, validation_required='saved_netlist_v1', native_outcomes=dict(outcomes))
|
||||||
|
return proof
|
||||||
|
except (OSError, UnicodeError, ValueError, KeyError, TypeError, IndexError) as error:
|
||||||
|
raise TaskCenterError('quick_run_uncertain', '工程统一保存或回读尚未得到完整证明,保留全部暂存项待核验。') from error
|
||||||
|
|
||||||
|
|
||||||
|
def bind_project_commit_source(proof, data_root, root, project, *, stop_event=None, release_mentor=None):
|
||||||
|
"""Capture saved bytes only at the completed native-close callback."""
|
||||||
|
from .saved_source import bind_sources
|
||||||
|
return bind_sources(proof, data_root, root, project,
|
||||||
|
stop_event=stop_event, release_mentor=release_mentor)
|
||||||
|
|
||||||
|
|
||||||
|
def validate_project_commit_source(proof, root):
|
||||||
|
from .project_session_health import _source_digest
|
||||||
|
try:
|
||||||
|
return (proof.get('source_sha256') and _source_digest(proof) == proof['source_sha256']
|
||||||
|
and proof.get('command_sha256') == hashlib.sha256(internal_path(root / 'command.tsv').read_bytes()).hexdigest()
|
||||||
|
and bool(proof.get('saved_sources')) and all(
|
||||||
|
hashlib.sha256(internal_path(source).read_bytes()).hexdigest() == digest
|
||||||
|
for source, digest in proof['saved_sources'].items()) and proof_intact(proof))
|
||||||
|
except (OSError, KeyError, TypeError, ValueError):return False
|
||||||
|
|
||||||
|
|
||||||
def capture_recovery(data_root,audit,row,outcome,*,strict=False):
|
def capture_recovery(data_root,audit,row,outcome,*,strict=False):
|
||||||
"""The recovery audit proves readback; it never asserts a second replacement."""
|
"""The recovery audit proves readback; it never asserts a second replacement."""
|
||||||
worker=audit/'worker'
|
worker=audit/'worker'
|
||||||
|
|||||||
@@ -0,0 +1,51 @@
|
|||||||
|
"""Read-only Restart Manager observations; never shut down registered applications."""
|
||||||
|
import ctypes
|
||||||
|
from ctypes import wintypes as w
|
||||||
|
import os
|
||||||
|
|
||||||
|
from .path_access import strip_extended_prefix
|
||||||
|
|
||||||
|
|
||||||
|
def locking_processes(path):
|
||||||
|
result = dict(method='windows_restart_manager', processes=[], complete=False)
|
||||||
|
if os.name != 'nt':
|
||||||
|
return dict(result, error='unsupported platform')
|
||||||
|
class UniqueProcess(ctypes.Structure):
|
||||||
|
_fields_ = [('pid', w.DWORD), ('started', w.FILETIME)]
|
||||||
|
class ProcessInfo(ctypes.Structure):
|
||||||
|
_fields_ = [('process', UniqueProcess), ('name', w.WCHAR*256), ('service', w.WCHAR*64),
|
||||||
|
('type', ctypes.c_int), ('status', w.ULONG), ('session', w.DWORD), ('restartable', w.BOOL)]
|
||||||
|
session = w.DWORD()
|
||||||
|
api = ctypes.WinDLL('rstrtmgr')
|
||||||
|
api.RmStartSession.argtypes = [ctypes.POINTER(w.DWORD), w.DWORD, w.LPWSTR]
|
||||||
|
api.RmRegisterResources.argtypes = [w.DWORD, w.UINT, ctypes.POINTER(w.LPCWSTR), w.UINT,
|
||||||
|
ctypes.POINTER(UniqueProcess), w.UINT, ctypes.POINTER(w.LPCWSTR)]
|
||||||
|
api.RmGetList.argtypes = [w.DWORD, ctypes.POINTER(w.UINT), ctypes.POINTER(w.UINT),
|
||||||
|
ctypes.POINTER(ProcessInfo), ctypes.POINTER(w.DWORD)]
|
||||||
|
api.RmEndSession.argtypes = [w.DWORD]
|
||||||
|
started = False
|
||||||
|
try:
|
||||||
|
code = api.RmStartSession(ctypes.byref(session), 0, ctypes.create_unicode_buffer(33))
|
||||||
|
if code: raise OSError(code, 'RmStartSession')
|
||||||
|
started = True
|
||||||
|
files = (w.LPCWSTR*1)(strip_extended_prefix(path))
|
||||||
|
code = api.RmRegisterResources(session, 1, files, 0, None, 0, None)
|
||||||
|
if code: raise OSError(code, 'RmRegisterResources')
|
||||||
|
needed, count, reboot = w.UINT(), w.UINT(), w.DWORD()
|
||||||
|
code = api.RmGetList(session, ctypes.byref(needed), ctypes.byref(count), None, ctypes.byref(reboot))
|
||||||
|
for _ in range(3):
|
||||||
|
if code != 234: break # ERROR_MORE_DATA
|
||||||
|
count.value = needed.value
|
||||||
|
items = (ProcessInfo*count.value)()
|
||||||
|
code = api.RmGetList(session, ctypes.byref(needed), ctypes.byref(count), items, ctypes.byref(reboot))
|
||||||
|
if code == 0:
|
||||||
|
result['processes'] = [dict(pid=item.process.pid, name=item.name,
|
||||||
|
creation_filetime=(item.process.started.dwHighDateTime << 32) | item.process.started.dwLowDateTime)
|
||||||
|
for item in items[:count.value]]
|
||||||
|
if code: raise OSError(code, 'RmGetList')
|
||||||
|
result['complete'] = True # Complete RM result, not an exhaustive kernel-handle scan.
|
||||||
|
except Exception as error:
|
||||||
|
result['error'] = str(error)
|
||||||
|
finally:
|
||||||
|
if started: api.RmEndSession(session)
|
||||||
|
return result
|
||||||
@@ -99,7 +99,7 @@ class IsolatedCadSession:
|
|||||||
self.root = canonical_path(root)
|
self.root = canonical_path(root)
|
||||||
self.token = uuid4().hex
|
self.token = uuid4().hex
|
||||||
self.borrowed_desktop = desktop is not None
|
self.borrowed_desktop = desktop is not None
|
||||||
self.desktop = desktop if desktop is not None else PrivateDesktop('dx-' + self.token, enabled=True)
|
self.desktop = desktop if desktop is not None else PrivateDesktop('dx-' + self.token, enabled=True, managed=True)
|
||||||
self.cad = None
|
self.cad = None
|
||||||
self.binding = None
|
self.binding = None
|
||||||
self.started = time.monotonic()
|
self.started = time.monotonic()
|
||||||
|
|||||||
@@ -87,6 +87,7 @@ def build_startup_info(desktop_name: str) -> StartupInfo:
|
|||||||
|
|
||||||
|
|
||||||
class _Win32Api:
|
class _Win32Api:
|
||||||
|
atomic_job_launch = True
|
||||||
def __init__(self) -> None:
|
def __init__(self) -> None:
|
||||||
try:
|
try:
|
||||||
import win32api, win32con, win32event, win32job, win32process, win32service
|
import win32api, win32con, win32event, win32job, win32process, win32service
|
||||||
@@ -101,6 +102,12 @@ class _Win32Api:
|
|||||||
def create_desktop(self, name: str):
|
def create_desktop(self, name: str):
|
||||||
return self.service.CreateDesktop(name, 0, self.con.GENERIC_ALL, None)
|
return self.service.CreateDesktop(name, 0, self.con.GENERIC_ALL, None)
|
||||||
|
|
||||||
|
def validate_desktop_owner(self, handle, sid):
|
||||||
|
import win32security
|
||||||
|
security = win32security.GetUserObjectSecurity(handle, win32security.OWNER_SECURITY_INFORMATION)
|
||||||
|
if win32security.ConvertSidToStringSid(security.GetSecurityDescriptorOwner()) != sid:
|
||||||
|
raise TaskCenterError('desktop_slot_busy', '同名桌面的所有者不匹配,未启动工作进程。')
|
||||||
|
|
||||||
def confirm_desktop_released(self, name: str):
|
def confirm_desktop_released(self, name: str):
|
||||||
started = time.monotonic()
|
started = time.monotonic()
|
||||||
# USER references can outlive the owned processes briefly. Allow a
|
# USER references can outlive the owned processes briefly. Allow a
|
||||||
@@ -166,7 +173,7 @@ class _Win32Api:
|
|||||||
return windows
|
return windows
|
||||||
|
|
||||||
def create_process(self, command: Sequence[str], desktop: str, cwd: Path | None, env: Mapping[str, str] | None,
|
def create_process(self, command: Sequence[str], desktop: str, cwd: Path | None, env: Mapping[str, str] | None,
|
||||||
*, stdout=None, stderr=None):
|
*, stdout=None, stderr=None, job_name=None):
|
||||||
# Windows venv python.exe redirects to a second process. Launch the
|
# Windows venv python.exe redirects to a second process. Launch the
|
||||||
# interpreter directly with its venv identity, so the handle we own is
|
# interpreter directly with its venv identity, so the handle we own is
|
||||||
# also the process that admits the request and creates desktop windows.
|
# also the process that admits the request and creates desktop windows.
|
||||||
@@ -176,18 +183,23 @@ class _Win32Api:
|
|||||||
command = (sys._base_executable, *command[1:])
|
command = (sys._base_executable, *command[1:])
|
||||||
env = dict(os.environ if env is None else env)
|
env = dict(os.environ if env is None else env)
|
||||||
env['__PYVENV_LAUNCHER__'] = sys.executable
|
env['__PYVENV_LAUNCHER__'] = sys.executable
|
||||||
startup = self.process.STARTUPINFO()
|
try:
|
||||||
startup.lpDesktop = desktop
|
startup = self.process.STARTUPINFO()
|
||||||
flags = self.con.CREATE_NO_WINDOW | self.con.CREATE_SUSPENDED
|
startup.lpDesktop = desktop
|
||||||
job = self.job.CreateJobObject(None, "")
|
flags = self.con.CREATE_NO_WINDOW | self.con.CREATE_SUSPENDED
|
||||||
|
job = self.job.CreateJobObject(None, job_name or "")
|
||||||
|
except Exception as error:
|
||||||
|
error.desktop_launch_cleanup_proven = True # CreateProcess has not been called.
|
||||||
|
raise
|
||||||
process = None
|
process = None
|
||||||
try:
|
try:
|
||||||
info = self.job.QueryInformationJobObject(job, self.job.JobObjectExtendedLimitInformation)
|
info = self.job.QueryInformationJobObject(job, self.job.JobObjectExtendedLimitInformation)
|
||||||
info["BasicLimitInformation"]["LimitFlags"] |= self.job.JOB_OBJECT_LIMIT_KILL_ON_JOB_CLOSE
|
info["BasicLimitInformation"]["LimitFlags"] |= self.job.JOB_OBJECT_LIMIT_KILL_ON_JOB_CLOSE
|
||||||
self.job.SetInformationJobObject(job, self.job.JobObjectExtendedLimitInformation, info)
|
self.job.SetInformationJobObject(job, self.job.JobObjectExtendedLimitInformation, info)
|
||||||
streams = (None, None)
|
streams = (None, None)
|
||||||
if stdout is not None or stderr is not None:
|
if stdout is not None or stderr is not None or job_name:
|
||||||
(handle, thread, pid, _), streams = _create_redirected_process(command, desktop, cwd, env, flags, stdout, stderr)
|
(handle, thread, pid, _), streams = _create_redirected_process(command, desktop, cwd, env, flags, stdout, stderr,
|
||||||
|
**({'job': job} if job_name else {}))
|
||||||
else:
|
else:
|
||||||
handle, thread, pid, _ = self.process.CreateProcess(
|
handle, thread, pid, _ = self.process.CreateProcess(
|
||||||
str(command[0]), subprocess.list2cmdline([str(item) for item in command]),
|
str(command[0]), subprocess.list2cmdline([str(item) for item in command]),
|
||||||
@@ -197,7 +209,7 @@ class _Win32Api:
|
|||||||
open_process=getattr(self, 'open_process', None), process_ids=self.process_ids)
|
open_process=getattr(self, 'open_process', None), process_ids=self.process_ids)
|
||||||
process.stdout, process.stderr = streams
|
process.stdout, process.stderr = streams
|
||||||
process.thread = thread
|
process.thread = thread
|
||||||
self.job.AssignProcessToJobObject(job, handle)
|
if not job_name: self.job.AssignProcessToJobObject(job, handle)
|
||||||
process.job_assigned = True
|
process.job_assigned = True
|
||||||
if not self.job.IsProcessInJob(handle, job):
|
if not self.job.IsProcessInJob(handle, job):
|
||||||
raise TaskCenterError('private_desktop', 'Owned process Job membership was not confirmed')
|
raise TaskCenterError('private_desktop', 'Owned process Job membership was not confirmed')
|
||||||
@@ -218,6 +230,7 @@ class _Win32Api:
|
|||||||
self._pending_cleanup = pending = []
|
self._pending_cleanup = pending = []
|
||||||
pending.append(process if process is not None else job)
|
pending.append(process if process is not None else job)
|
||||||
raise TaskCenterError('private_desktop', f'launch failed: {error}; cleanup failed: {cleanup_error}') from error
|
raise TaskCenterError('private_desktop', f'launch failed: {error}; cleanup failed: {cleanup_error}') from error
|
||||||
|
error.desktop_launch_cleanup_proven = True
|
||||||
raise
|
raise
|
||||||
return process
|
return process
|
||||||
|
|
||||||
@@ -245,7 +258,9 @@ def _stop_and_wait(process):
|
|||||||
running = process.poll() is None
|
running = process.poll() is None
|
||||||
except Exception as error:
|
except Exception as error:
|
||||||
errors.append(error)
|
errors.append(error)
|
||||||
if running:
|
termination_requested = (isinstance(process, _Win32Process)
|
||||||
|
and process.cleanup_record.get('forced_root_termination'))
|
||||||
|
if running and not termination_requested:
|
||||||
try:
|
try:
|
||||||
if isinstance(process, _Win32Process):
|
if isinstance(process, _Win32Process):
|
||||||
process.terminate(reason='root_process_active')
|
process.terminate(reason='root_process_active')
|
||||||
@@ -260,7 +275,7 @@ def _stop_and_wait(process):
|
|||||||
return errors
|
return errors
|
||||||
|
|
||||||
|
|
||||||
def _create_redirected_process(command, desktop, cwd, env, flags, stdout, stderr):
|
def _create_redirected_process(command, desktop, cwd, env, flags, stdout, stderr, *, job=None):
|
||||||
"""Use an explicit inheritance list; never inherit unrelated parent handles."""
|
"""Use an explicit inheritance list; never inherit unrelated parent handles."""
|
||||||
import msvcrt
|
import msvcrt
|
||||||
import pywintypes
|
import pywintypes
|
||||||
@@ -323,13 +338,19 @@ def _create_redirected_process(command, desktop, cwd, env, flags, stdout, stderr
|
|||||||
handles = list(dict.fromkeys((stdin_handle, stdout_handle, stderr_handle)))
|
handles = list(dict.fromkeys((stdin_handle, stdout_handle, stderr_handle)))
|
||||||
inherited = (wintypes.HANDLE * len(handles))(*handles)
|
inherited = (wintypes.HANDLE * len(handles))(*handles)
|
||||||
size = ctypes.c_size_t()
|
size = ctypes.c_size_t()
|
||||||
initialize(None, 1, 0, ctypes.byref(size))
|
count = 2 if job is not None else 1
|
||||||
|
initialize(None, count, 0, ctypes.byref(size))
|
||||||
attributes = ctypes.create_string_buffer(size.value)
|
attributes = ctypes.create_string_buffer(size.value)
|
||||||
if not initialize(attributes, 1, 0, ctypes.byref(size)):
|
if not initialize(attributes, count, 0, ctypes.byref(size)):
|
||||||
raise ctypes.WinError(ctypes.get_last_error())
|
raise ctypes.WinError(ctypes.get_last_error())
|
||||||
try:
|
try:
|
||||||
if not update(attributes, 0, 0x20002, inherited, ctypes.sizeof(inherited), None, None):
|
if not update(attributes, 0, 0x20002, inherited, ctypes.sizeof(inherited), None, None):
|
||||||
raise ctypes.WinError(ctypes.get_last_error())
|
raise ctypes.WinError(ctypes.get_last_error())
|
||||||
|
if job is not None:
|
||||||
|
jobs = (wintypes.HANDLE * 1)(int(job))
|
||||||
|
# Assign before the initial thread exists, including owner-loss windows.
|
||||||
|
if not update(attributes, 0, 0x2000D, jobs, ctypes.sizeof(jobs), None, None):
|
||||||
|
raise ctypes.WinError(ctypes.get_last_error())
|
||||||
startup = ExtendedStartup()
|
startup = ExtendedStartup()
|
||||||
startup.StartupInfo.cb = ctypes.sizeof(startup)
|
startup.StartupInfo.cb = ctypes.sizeof(startup)
|
||||||
startup.StartupInfo.lpDesktop = desktop
|
startup.StartupInfo.lpDesktop = desktop
|
||||||
@@ -570,8 +591,13 @@ class _Win32Process:
|
|||||||
class PrivateDesktop:
|
class PrivateDesktop:
|
||||||
"""Own a private Windows desktop and processes started on it."""
|
"""Own a private Windows desktop and processes started on it."""
|
||||||
|
|
||||||
def __init__(self, name: str, *, enabled: bool = False, api=None) -> None:
|
def __init__(self, name: str, *, enabled: bool = False, api=None, managed=False, slot=None) -> None:
|
||||||
self.name = name
|
if managed and slot is None and os.name == 'nt':
|
||||||
|
from .desktop_slot import DesktopSlot
|
||||||
|
slot = DesktopSlot()
|
||||||
|
self._slot = slot
|
||||||
|
self._slot_acquired = False
|
||||||
|
self.name = slot.name if slot is not None else name
|
||||||
self.enabled = enabled
|
self.enabled = enabled
|
||||||
self._handle = None
|
self._handle = None
|
||||||
self._processes: list[subprocess.Popen[str]] = []
|
self._processes: list[subprocess.Popen[str]] = []
|
||||||
@@ -583,7 +609,16 @@ class PrivateDesktop:
|
|||||||
def __enter__(self) -> "PrivateDesktop":
|
def __enter__(self) -> "PrivateDesktop":
|
||||||
if not self.enabled:
|
if not self.enabled:
|
||||||
raise TaskCenterError("private_desktop_opt_in", "private desktop backend requires explicit opt-in")
|
raise TaskCenterError("private_desktop_opt_in", "private desktop backend requires explicit opt-in")
|
||||||
self._create()
|
if self._slot is not None:
|
||||||
|
self._slot.acquire()
|
||||||
|
self._slot_acquired = True
|
||||||
|
try:
|
||||||
|
self._create()
|
||||||
|
if self._slot is not None and hasattr(self._api, 'validate_desktop_owner'):
|
||||||
|
self._api.validate_desktop_owner(self._handle, self._slot.context['sid'])
|
||||||
|
except Exception:
|
||||||
|
self.close()
|
||||||
|
raise
|
||||||
if self._handle is None:
|
if self._handle is None:
|
||||||
raise TaskCenterError("private_desktop", "private desktop could not be created")
|
raise TaskCenterError("private_desktop", "private desktop could not be created")
|
||||||
return self
|
return self
|
||||||
@@ -638,8 +673,23 @@ class PrivateDesktop:
|
|||||||
if self._api is None:
|
if self._api is None:
|
||||||
raise TaskCenterError("private_desktop", "private desktop process API is unavailable")
|
raise TaskCenterError("private_desktop", "private desktop process API is unavailable")
|
||||||
options = {} if stdout is None and stderr is None else {'stdout': stdout, 'stderr': stderr}
|
options = {} if stdout is None and stderr is None else {'stdout': stdout, 'stderr': stderr}
|
||||||
process = self._api.create_process(command, build_startup_info(self.name).lpDesktop, cwd, env, **options)
|
job = self._slot.prepare_launch(atomic_job=bool(getattr(self._api, 'atomic_job_launch', False))) if self._slot is not None else None
|
||||||
|
if job is not None: options['job_name'] = job
|
||||||
|
try:
|
||||||
|
process = self._api.create_process(command, build_startup_info(self.name).lpDesktop, cwd, env, **options)
|
||||||
|
except Exception as error:
|
||||||
|
if job is not None and getattr(error, 'desktop_launch_cleanup_proven', False):
|
||||||
|
self._slot.launch_closed(job)
|
||||||
|
raise
|
||||||
self._processes.append(process)
|
self._processes.append(process)
|
||||||
|
if job is not None:
|
||||||
|
from .batch_resources import process_identity
|
||||||
|
try:
|
||||||
|
self._slot.launched(job, process_identity(process))
|
||||||
|
except Exception:
|
||||||
|
process.close()
|
||||||
|
self._slot.launch_closed(job)
|
||||||
|
raise
|
||||||
self._process_history.append({'pid': getattr(process, 'pid', None),
|
self._process_history.append({'pid': getattr(process, 'pid', None),
|
||||||
'owner_pid': os.getpid(), 'owner_thread_id': get_native_id(),
|
'owner_pid': os.getpid(), 'owner_thread_id': get_native_id(),
|
||||||
'started_time_ns': time.time_ns(), 'process_handle': _native_handle(getattr(process, 'handle', None)),
|
'started_time_ns': time.time_ns(), 'process_handle': _native_handle(getattr(process, 'handle', None)),
|
||||||
@@ -666,6 +716,12 @@ class PrivateDesktop:
|
|||||||
self._remember_process_cleanup(process, forgotten=True)
|
self._remember_process_cleanup(process, forgotten=True)
|
||||||
|
|
||||||
def close(self) -> None:
|
def close(self) -> None:
|
||||||
|
if self._slot is not None and not self._slot_acquired:
|
||||||
|
self.cleanup_record = dict(desktop=self.name, desktop_not_acquired=True,
|
||||||
|
desktop_handle_closed=True, owned_cleanup_complete=True, processes=[], errors=[])
|
||||||
|
return
|
||||||
|
if self._slot is not None and self._slot.receipt is not None:
|
||||||
|
return # A past lease must never observe or close a newer owner.
|
||||||
errors, remaining = [], []
|
errors, remaining = [], []
|
||||||
self.cleanup_record = {'desktop': self.name, 'processes': []}
|
self.cleanup_record = {'desktop': self.name, 'processes': []}
|
||||||
for process in reversed(self._processes):
|
for process in reversed(self._processes):
|
||||||
@@ -689,6 +745,7 @@ class PrivateDesktop:
|
|||||||
close_pending()
|
close_pending()
|
||||||
except Exception as error:
|
except Exception as error:
|
||||||
errors.append(error)
|
errors.append(error)
|
||||||
|
self.cleanup_record['owned_cleanup_complete'] = not errors and not self._processes
|
||||||
try:
|
try:
|
||||||
self.release_desktop()
|
self.release_desktop()
|
||||||
except Exception as error:
|
except Exception as error:
|
||||||
@@ -703,6 +760,10 @@ class PrivateDesktop:
|
|||||||
errors = []
|
errors = []
|
||||||
if self.cleanup_record is None:
|
if self.cleanup_record is None:
|
||||||
self.cleanup_record = {'desktop': self.name, 'processes': []}
|
self.cleanup_record = {'desktop': self.name, 'processes': []}
|
||||||
|
if self._slot is not None and self._slot.receipt is not None:
|
||||||
|
return
|
||||||
|
if self._slot is not None and self.cleanup_record.get('owned_cleanup_complete') is not True:
|
||||||
|
raise TaskCenterError('desktop_waiting_for_mentor', '自有进程和句柄尚未收尾,桌面租用保持。')
|
||||||
from .read_recovery import process_tree_exited
|
from .read_recovery import process_tree_exited
|
||||||
if any(not process_tree_exited(process) for process in self._processes):
|
if any(not process_tree_exited(process) for process in self._processes):
|
||||||
self.cleanup_record.update(desktop_release_state='waiting_for_mentor',
|
self.cleanup_record.update(desktop_release_state='waiting_for_mentor',
|
||||||
@@ -720,20 +781,35 @@ class PrivateDesktop:
|
|||||||
event['error'] = str(error)
|
event['error'] = str(error)
|
||||||
self._desktop_handle_history.append(event)
|
self._desktop_handle_history.append(event)
|
||||||
confirm = getattr(self._api, 'confirm_desktop_released', None)
|
confirm = getattr(self._api, 'confirm_desktop_released', None)
|
||||||
if confirm and self._handle is None:
|
confirmation = None
|
||||||
|
if self._slot is not None and self._handle is None and not errors:
|
||||||
|
try:
|
||||||
|
disappeared = not self._slot.backend.desktop_exists(self.name)
|
||||||
|
self._slot.release(desktop_disappeared=disappeared)
|
||||||
|
confirmation = dict(desktop=self.name, released=disappeared,
|
||||||
|
method='managed_lease_return', elapsed_seconds=0.0)
|
||||||
|
except Exception as error:
|
||||||
|
errors.append(error)
|
||||||
|
if self._slot.receipt is not None:
|
||||||
|
self.cleanup_record['desktop_lease'] = self._slot.receipt
|
||||||
|
elif confirm and self._handle is None:
|
||||||
try:
|
try:
|
||||||
confirm(self.name)
|
confirm(self.name)
|
||||||
except Exception as error:
|
except Exception as error:
|
||||||
errors.append(error)
|
errors.append(error)
|
||||||
|
confirmation = getattr(self._api, 'desktop_release_check', None)
|
||||||
self.cleanup_record.update(desktop_handle_closed=self._handle is None,
|
self.cleanup_record.update(desktop_handle_closed=self._handle is None,
|
||||||
desktop_release_state='failed' if errors else 'released',
|
desktop_release_state='failed' if errors else 'released',
|
||||||
desktop_confirmation=getattr(self._api, 'desktop_release_check', None),
|
desktop_confirmation=confirmation,
|
||||||
|
desktop_lease_pending=self._slot is not None and self._slot.receipt is None,
|
||||||
desktop_handle_history=deepcopy(self._desktop_handle_history),
|
desktop_handle_history=deepcopy(self._desktop_handle_history),
|
||||||
process_history=deepcopy(self._process_history),
|
process_history=deepcopy(self._process_history),
|
||||||
diagnostic_scope={'external_handle_holders': 'unknown',
|
diagnostic_scope={'external_handle_holders': 'unknown',
|
||||||
'thread_desktops': 'unknown unless observed through residual windows; no exhaustive holder scan',
|
'thread_desktops': 'unknown unless observed through residual windows; no exhaustive holder scan',
|
||||||
'empty_windows_prove_no_holders': False},
|
'empty_windows_prove_no_holders': False},
|
||||||
errors=[str(error) for error in errors])
|
errors=[str(error) for error in errors])
|
||||||
|
if confirmation and self._slot is not None and not confirmation['released']:
|
||||||
|
self.cleanup_record['desktop_release_state'] = 'reusable'
|
||||||
if errors:
|
if errors:
|
||||||
self.cleanup_record['owned_resource_diagnostics'] = self._owned_resource_diagnostics()
|
self.cleanup_record['owned_resource_diagnostics'] = self._owned_resource_diagnostics()
|
||||||
_raise_cleanup_errors(errors)
|
_raise_cleanup_errors(errors)
|
||||||
|
|||||||
@@ -17,7 +17,7 @@ import time
|
|||||||
import traceback
|
import traceback
|
||||||
from typing import Any, Mapping
|
from typing import Any, Mapping
|
||||||
|
|
||||||
from .errors import TaskCenterError
|
from .errors import ProjectPathError, TaskCenterError
|
||||||
from .path_access import internal_path
|
from .path_access import internal_path
|
||||||
from .retention import rotate_text_log
|
from .retention import rotate_text_log
|
||||||
|
|
||||||
@@ -62,15 +62,18 @@ class LoggingContext:
|
|||||||
reported = error
|
reported = error
|
||||||
else:
|
else:
|
||||||
reported = TaskCenterError("unhandled_exception", "发生未处理异常")
|
reported = TaskCenterError("unhandled_exception", "发生未处理异常")
|
||||||
detail = "".join(
|
message = reported.message
|
||||||
traceback.format_exception(type(error), error, traceback_object or error.__traceback__)
|
if not isinstance(error, ProjectPathError):
|
||||||
)
|
detail = "".join(
|
||||||
|
traceback.format_exception(type(error), error, traceback_object or error.__traceback__)
|
||||||
|
)
|
||||||
|
message += "\n" + detail.rstrip()
|
||||||
self.logger.error(
|
self.logger.error(
|
||||||
"error_id=%s operation=%s message=%s\n%s",
|
"error_id=%s operation=%s code=%s message=%s",
|
||||||
reported.error_id,
|
reported.error_id,
|
||||||
operation,
|
operation,
|
||||||
reported.message,
|
reported.code,
|
||||||
detail.rstrip(),
|
message,
|
||||||
)
|
)
|
||||||
_flush_handlers(self.logger)
|
_flush_handlers(self.logger)
|
||||||
return reported
|
return reported
|
||||||
|
|||||||
@@ -15,6 +15,7 @@ class TaskStatus(str, Enum):
|
|||||||
PAUSED = "paused"
|
PAUSED = "paused"
|
||||||
COMPLETED = "completed"
|
COMPLETED = "completed"
|
||||||
FAILED = "failed"
|
FAILED = "failed"
|
||||||
|
BLOCKED = "blocked"
|
||||||
DELETED = "deleted"
|
DELETED = "deleted"
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -1,6 +1,9 @@
|
|||||||
"""Native current-sheet replacement adapter for the existing QuickPartReplace runner."""
|
"""Native current-sheet replacement adapter for the existing QuickPartReplace runner."""
|
||||||
import argparse
|
import argparse
|
||||||
from collections import Counter
|
from collections import Counter
|
||||||
|
from contextlib import contextmanager
|
||||||
|
from contextvars import ContextVar
|
||||||
|
from functools import wraps
|
||||||
import faulthandler
|
import faulthandler
|
||||||
import ctypes
|
import ctypes
|
||||||
import csv
|
import csv
|
||||||
@@ -15,6 +18,46 @@ import time
|
|||||||
import traceback
|
import traceback
|
||||||
|
|
||||||
|
|
||||||
|
_SNAPSHOT_REFERENCE_KEYS = ContextVar('snapshot_reference_keys', default={})
|
||||||
|
|
||||||
|
|
||||||
|
@contextmanager
|
||||||
|
def snapshot_identity_scope(snapshot):
|
||||||
|
"""Keep original receipt keys while resolving live COM objects by reference."""
|
||||||
|
rows = [line.split('\t') for line in Path(snapshot).read_text(encoding='utf-8-sig').splitlines()]
|
||||||
|
references, owners, spelling = {}, {}, {}
|
||||||
|
for row in rows:
|
||||||
|
if len(row) >= 3 and row[0] in {'C', 'U'}:
|
||||||
|
uid, ref = decode(row[1]), decode(row[2]).strip().casefold()
|
||||||
|
spelling[ref] = decode(row[2]).strip()
|
||||||
|
transform = tuple(decode(value) for value in row[3:7]) if row[0] == 'C' and len(row) == 8 else None
|
||||||
|
references.setdefault(ref, []).append((uid, transform))
|
||||||
|
owners.setdefault(uid, set()).add(ref)
|
||||||
|
for row in rows:
|
||||||
|
if len(row) == 3 and row[0] == 'G':
|
||||||
|
headers = [line.split('\t') for line in decode(row[2]).splitlines() if line.startswith('C\t')]
|
||||||
|
if len(headers) == 1 and len(headers[0]) == 8:
|
||||||
|
header = [decode(value) for value in headers[0]]
|
||||||
|
ref = header[2].strip().casefold()
|
||||||
|
references[ref] = [(uid, tuple(header[3:7]) if uid == header[1] else transform)
|
||||||
|
for uid, transform in references.get(ref, ())]
|
||||||
|
keys = {ref: [(uid if len(owners[uid]) == 1 else '@REFDES|' + spelling[ref], transform)
|
||||||
|
for uid, transform in values] for ref, values in references.items() if ref}
|
||||||
|
token = _SNAPSHOT_REFERENCE_KEYS.set(keys)
|
||||||
|
try:
|
||||||
|
yield
|
||||||
|
finally:
|
||||||
|
_SNAPSHOT_REFERENCE_KEYS.reset(token)
|
||||||
|
|
||||||
|
|
||||||
|
def _bound_snapshot_identity(action):
|
||||||
|
@wraps(action)
|
||||||
|
def bound(snapshot, *args, **kwargs):
|
||||||
|
with snapshot_identity_scope(snapshot):
|
||||||
|
return action(snapshot, *args, **kwargs)
|
||||||
|
return bound
|
||||||
|
|
||||||
|
|
||||||
def snapshot_attempt(snapshot):
|
def snapshot_attempt(snapshot):
|
||||||
"""Bind batch evidence to the actual snapshot and its confirmed queue row."""
|
"""Bind batch evidence to the actual snapshot and its confirmed queue row."""
|
||||||
from .batch_attempt import _bound_attempt
|
from .batch_attempt import _bound_attempt
|
||||||
@@ -99,6 +142,22 @@ def read_snapshot(path):
|
|||||||
return metadata[0], components
|
return metadata[0], components
|
||||||
|
|
||||||
|
|
||||||
|
def saved_netlist_snapshot(snapshot):
|
||||||
|
rows = [line.split('\t') for line in Path(snapshot).read_text(encoding='utf-8-sig').splitlines() if line]
|
||||||
|
markers = [row for row in rows if row[0] == 'X']
|
||||||
|
if ['X', 'saved_netlist_v1'] not in markers:
|
||||||
|
return False
|
||||||
|
if (markers != [['X', 'saved_netlist_v1']] or any(row[0] not in {'M', 'C', 'A', 'X', 'L'} for row in rows)
|
||||||
|
or not any(row[0] == 'C' for row in rows)
|
||||||
|
or any(len(row) != 8 or row[7] != 'NETLIST' for row in rows if row[0] == 'C')):
|
||||||
|
raise ValueError('Invalid saved native data snapshot scope')
|
||||||
|
_, components = read_snapshot(snapshot)
|
||||||
|
selected = {row[1] for row in components}
|
||||||
|
if any(len(row) != 12 or decode(row[1]) not in selected for row in rows if row[0] == 'A'):
|
||||||
|
raise ValueError('Invalid saved native data snapshot attributes')
|
||||||
|
return True
|
||||||
|
|
||||||
|
|
||||||
def snapshot_value_mode(metadata):
|
def snapshot_value_mode(metadata):
|
||||||
return metadata[5] if len(metadata) >= 6 else "part_label"
|
return metadata[5] if len(metadata) >= 6 else "part_label"
|
||||||
|
|
||||||
@@ -233,7 +292,8 @@ def wait_for(callback, description, timeout=15):
|
|||||||
raise TimeoutError(description)
|
raise TimeoutError(description)
|
||||||
|
|
||||||
|
|
||||||
def wait_for_library_rows(callback, target, timeout=30, stable_for=0.45, poll_interval=0.15):
|
def wait_for_library_rows(callback, target, timeout=30, stable_for=0.45, poll_interval=0.15,
|
||||||
|
scope=lambda: None):
|
||||||
deadline = time.monotonic() + timeout
|
deadline = time.monotonic() + timeout
|
||||||
previous = None
|
previous = None
|
||||||
stable_since = None
|
stable_since = None
|
||||||
@@ -250,7 +310,7 @@ def wait_for_library_rows(callback, target, timeout=30, stable_for=0.45, poll_in
|
|||||||
previous = stable_since = None
|
previous = stable_since = None
|
||||||
time.sleep(poll_interval)
|
time.sleep(poll_interval)
|
||||||
continue
|
continue
|
||||||
signature = tuple(tuple(str(value) for value in columns) for _, columns in latest)
|
signature = (scope(), tuple(tuple(str(value) for value in columns) for _, columns in latest))
|
||||||
now = time.monotonic()
|
now = time.monotonic()
|
||||||
if signature != previous:
|
if signature != previous:
|
||||||
previous = signature
|
previous = signature
|
||||||
@@ -262,6 +322,106 @@ def wait_for_library_rows(callback, target, timeout=30, stable_for=0.45, poll_in
|
|||||||
raise TimeoutError(f"Native DxDataBook did not finish loading target part: {target}")
|
raise TimeoutError(f"Native DxDataBook did not finish loading target part: {target}")
|
||||||
|
|
||||||
|
|
||||||
|
def load_databook_target(snapshot, report, target, *, controls, browse, filter_part,
|
||||||
|
list_rows, dialogs, close_dialog):
|
||||||
|
"""Load the target before the native submit boundary and retry a prepared batch once."""
|
||||||
|
from .batch_attempt import can_retry_attempt
|
||||||
|
|
||||||
|
diagnostic = report.setdefault('databook', {})
|
||||||
|
loads = diagnostic['loads'] = []
|
||||||
|
baseline = {row['hwnd'] for row in dialogs()}
|
||||||
|
initial = snapshot_attempt(snapshot)
|
||||||
|
warm = controls() is not None
|
||||||
|
for index in range(2):
|
||||||
|
timeout = 20 if warm else 45
|
||||||
|
started = time.monotonic()
|
||||||
|
load = {'mode': 'warm' if warm else 'cold', 'timeout_seconds': timeout,
|
||||||
|
'attempt_state_before_load': initial[1]['state'] if initial else None}
|
||||||
|
loads.append(load)
|
||||||
|
save_report(snapshot, report)
|
||||||
|
pair = None
|
||||||
|
|
||||||
|
def read():
|
||||||
|
nonlocal pair
|
||||||
|
current = controls()
|
||||||
|
if current is None:
|
||||||
|
pair = None
|
||||||
|
return []
|
||||||
|
try:
|
||||||
|
if current != pair:
|
||||||
|
filter_part(current[1])
|
||||||
|
pair = current
|
||||||
|
load.update(list_handle=pair[0], filter_handle=pair[1])
|
||||||
|
return list_rows(pair[0])
|
||||||
|
except Exception as error:
|
||||||
|
if (getattr(error, 'winerror', None) != 1400 # ERROR_INVALID_WINDOW_HANDLE
|
||||||
|
and getattr(error, 'hresult', None) != -2147220991): # UIA_E_ELEMENTNOTAVAILABLE
|
||||||
|
raise
|
||||||
|
pair = None
|
||||||
|
return []
|
||||||
|
|
||||||
|
try:
|
||||||
|
if index == 0 or controls() is None:
|
||||||
|
browse()
|
||||||
|
rows = wait_for_library_rows(read, target, timeout=timeout, scope=lambda: pair)
|
||||||
|
except TimeoutError as error:
|
||||||
|
load['error'] = str(error)
|
||||||
|
load['elapsed_seconds'] = round(time.monotonic() - started, 3)
|
||||||
|
load['dialogs'] = [row for row in dialogs() if row['hwnd'] not in baseline]
|
||||||
|
bound = snapshot_attempt(snapshot)
|
||||||
|
prepared = initial is not None and initial[1]['state'] == 'prepared' and can_retry_attempt(*initial)
|
||||||
|
load['attempt_state'] = bound[1]['state'] if bound else None
|
||||||
|
blockers = [row for row in load['dialogs'] if not row.get('browser')]
|
||||||
|
candidates = [row for row in blockers if row['dismissible']]
|
||||||
|
retry = index == 0 and prepared and bool(os.environ.get('DXPART_DESKTOP'))
|
||||||
|
# A different modal must get its normal operator handling.
|
||||||
|
retry = retry and (not blockers or len(blockers) == len(candidates) == 1)
|
||||||
|
load['retry'] = retry
|
||||||
|
save_report(snapshot, report)
|
||||||
|
if not retry:
|
||||||
|
raise
|
||||||
|
if candidates:
|
||||||
|
close_dialog(candidates[0])
|
||||||
|
load['closed_dialog'] = candidates[0]['hwnd']
|
||||||
|
warm = True
|
||||||
|
else:
|
||||||
|
load['elapsed_seconds'] = round(time.monotonic() - started, 3)
|
||||||
|
return pair[0], rows
|
||||||
|
|
||||||
|
|
||||||
|
def databook_dialogs(gui, process, pid, replacement, main_handle):
|
||||||
|
from .cad_dialogs import _text
|
||||||
|
|
||||||
|
replacement_thread, _ = process.GetWindowThreadProcessId(replacement)
|
||||||
|
rows = []
|
||||||
|
|
||||||
|
def dialog(handle, _):
|
||||||
|
if (handle in {replacement, main_handle} or not gui.IsWindowVisible(handle)
|
||||||
|
or process.GetWindowThreadProcessId(handle)[1] != pid
|
||||||
|
or gui.GetClassName(handle) != '#32770'):
|
||||||
|
return
|
||||||
|
owner = gui.GetWindow(handle, 4) # GW_OWNER
|
||||||
|
row = {'hwnd': handle, 'owner': owner, 'pid': pid, 'title': '', 'children': [],
|
||||||
|
'browser': False, 'dismissible': False}
|
||||||
|
rows.append(row)
|
||||||
|
children = []
|
||||||
|
try:
|
||||||
|
row['title'] = _text(handle)
|
||||||
|
gui.EnumChildWindows(handle, lambda child, _: children.append(child), None)
|
||||||
|
row['children'] = [{'hwnd': child, 'parent': gui.GetParent(child), 'class': gui.GetClassName(child),
|
||||||
|
'id': gui.GetDlgCtrlID(child)} for child in children[:64]]
|
||||||
|
row['browser'] = {('SysListView32', 4000), ('Edit', 4006)} <= {
|
||||||
|
(child['class'], child['id']) for child in row['children']}
|
||||||
|
row['dismissible'] = (not row['title'].strip() and not children and owner == replacement
|
||||||
|
and process.GetWindowThreadProcessId(handle)[0] == replacement_thread
|
||||||
|
and not gui.IsWindowEnabled(replacement))
|
||||||
|
except (OSError, gui.error) as error:
|
||||||
|
row['read_error'] = str(error)
|
||||||
|
|
||||||
|
gui.EnumWindows(dialog, None)
|
||||||
|
return rows
|
||||||
|
|
||||||
|
|
||||||
def target_symbol_matches(displayed, library_symbol, slot_count):
|
def target_symbol_matches(displayed, library_symbol, slot_count):
|
||||||
actual = str(displayed).casefold()
|
actual = str(displayed).casefold()
|
||||||
expected = str(library_symbol).casefold()
|
expected = str(library_symbol).casefold()
|
||||||
@@ -392,16 +552,35 @@ def components_on_sheet(app, api):
|
|||||||
|
|
||||||
|
|
||||||
def _component_uid(component):
|
def _component_uid(component):
|
||||||
value = getattr(component, 'UID', None)
|
refdes = str(getattr(component, 'Refdes', '') or '').strip()
|
||||||
|
identities = _SNAPSHOT_REFERENCE_KEYS.get().get(refdes.casefold(), ())
|
||||||
|
if len(identities) == 1:
|
||||||
|
return identities[0][0]
|
||||||
|
if identities:
|
||||||
|
matches = [uid for uid, transform in identities if transform and _same_unit(component, transform)]
|
||||||
|
if len(matches) != 1:
|
||||||
|
raise ValueError('Snapshot physical unit association is missing or ambiguous')
|
||||||
|
return matches[0]
|
||||||
|
try:
|
||||||
|
value = getattr(component, 'UID', None)
|
||||||
|
except Exception:
|
||||||
|
value = None
|
||||||
uid = '' if value is None else str(value).strip()
|
uid = '' if value is None else str(value).strip()
|
||||||
if uid:
|
if uid:
|
||||||
return uid
|
return uid
|
||||||
refdes = str(getattr(component, 'Refdes', '') or '').strip()
|
|
||||||
if not refdes:
|
if not refdes:
|
||||||
raise ValueError("Component UID and Refdes are empty; cannot safely identify the target")
|
raise ValueError("Component UID and Refdes are empty; cannot safely identify the target")
|
||||||
return '@REFDES|' + refdes
|
return '@REFDES|' + refdes
|
||||||
|
|
||||||
|
|
||||||
|
def _same_unit(component, transform):
|
||||||
|
point = component.GetLocation()
|
||||||
|
return (abs(float(point.X) - float(transform[0])) <= 10
|
||||||
|
and abs(float(point.Y) - float(transform[1])) <= 10
|
||||||
|
and float(component.Orientation) == float(transform[2])
|
||||||
|
and float(component.Scale) == float(transform[3]))
|
||||||
|
|
||||||
|
|
||||||
def check_active_context(app, metadata):
|
def check_active_context(app, metadata):
|
||||||
from .cad_identity import verify_application, project_file_path
|
from .cad_identity import verify_application, project_file_path
|
||||||
verify_application(app)
|
verify_application(app)
|
||||||
@@ -418,18 +597,24 @@ def check_context(app, api, metadata, records, require_selection=True):
|
|||||||
by_uid = {_component_uid(component): component for component in components}
|
by_uid = {_component_uid(component): component for component in components}
|
||||||
if len(by_uid) != len(components):
|
if len(by_uid) != len(components):
|
||||||
raise ValueError("Duplicate component UID on sheet")
|
raise ValueError("Duplicate component UID on sheet")
|
||||||
|
for record in records:
|
||||||
|
component = by_uid.get(record[1])
|
||||||
|
if component is None or str(component.Refdes).strip().casefold() != record[2].strip().casefold():
|
||||||
|
raise ValueError('Snapshot reference differs from the selected live component')
|
||||||
if len(metadata) == 10:
|
if len(metadata) == 10:
|
||||||
selectors = _target_selectors(metadata[9])
|
selectors = _target_selectors(metadata[9])
|
||||||
if set(selectors) != wanted:
|
selected_refs = {ref.strip().casefold() for ref, _ in selectors.values()}
|
||||||
|
if selected_refs != {record[2].strip().casefold() for record in records}:
|
||||||
raise ValueError("Target selector differs from snapshot components")
|
raise ValueError("Target selector differs from snapshot components")
|
||||||
for uid, (refdes, old_value) in selectors.items():
|
for uid, (refdes, old_value) in selectors.items():
|
||||||
component = by_uid.get(uid)
|
candidates = [component for component in components if str(component.Refdes).strip().casefold() == refdes.strip().casefold()]
|
||||||
if (component is None or str(component.Refdes) != refdes or
|
if (not candidates or any(_component_uid(component) not in wanted
|
||||||
attribute_value(component, "Part Number", required=True).casefold() != metadata[2].casefold() or
|
or attribute_value(component, "Part Number", required=True).casefold() != metadata[2].casefold()
|
||||||
attribute_value(component, "Value") != old_value):
|
or attribute_value(component, "Value") != old_value for component in candidates)):
|
||||||
raise ValueError("Selected target changed since inventory")
|
raise ValueError("Selected target changed since inventory")
|
||||||
else:
|
else:
|
||||||
actual = {_component_uid(component) for component in components if attribute_value(component, "Part Number", required=True).casefold() == metadata[2].casefold()}
|
scope = [component for component in components if _component_uid(component) in wanted] if all(row[7] == "NETLIST" for row in records) else components
|
||||||
|
actual = {_component_uid(component) for component in scope if attribute_value(component, "Part Number", required=True).casefold() == metadata[2].casefold()}
|
||||||
if actual != wanted:
|
if actual != wanted:
|
||||||
raise ValueError(f"Source batch changed since snapshot: expected={sorted(wanted)!r} actual={sorted(actual)!r}")
|
raise ValueError(f"Source batch changed since snapshot: expected={sorted(wanted)!r} actual={sorted(actual)!r}")
|
||||||
if require_selection:
|
if require_selection:
|
||||||
@@ -545,6 +730,21 @@ def select_snapshot_batch(app, api, metadata, records):
|
|||||||
return components
|
return components
|
||||||
|
|
||||||
|
|
||||||
|
def applied_replacement_uids(components, records, target):
|
||||||
|
"""Associate just the written targets while the native operation completes."""
|
||||||
|
wanted = {row[1] for row in records}
|
||||||
|
targets = {_component_uid(component): component for component in components
|
||||||
|
if _component_uid(component) in wanted}
|
||||||
|
if len(targets) != len(records):
|
||||||
|
return None
|
||||||
|
for record in records:
|
||||||
|
component = targets[record[1]]
|
||||||
|
if (str(component.Refdes).strip().casefold() != record[2].strip().casefold()
|
||||||
|
or attribute_value(component, 'Part Number', required=True).casefold() != target.casefold()):
|
||||||
|
return None
|
||||||
|
return [record[1] for record in records]
|
||||||
|
|
||||||
|
|
||||||
def existing_replacement_uids(components, records, target, binding, require_part_label=True):
|
def existing_replacement_uids(components, records, target, binding, require_part_label=True):
|
||||||
matches = replacement_matches(components, records, target, require_part_label,
|
matches = replacement_matches(components, records, target, require_part_label,
|
||||||
library_row=binding['library_row'])
|
library_row=binding['library_row'])
|
||||||
@@ -553,7 +753,7 @@ def existing_replacement_uids(components, records, target, binding, require_part
|
|||||||
return matches
|
return matches
|
||||||
|
|
||||||
|
|
||||||
def promote_pin_numbers(app, api, replacement_uids, slot_count=1, on_progress=None):
|
def promote_pin_numbers(app, api, replacement_uids, slot_count=1, on_progress=None, *, verify_pins=True):
|
||||||
def progress(phase):
|
def progress(phase):
|
||||||
if on_progress:
|
if on_progress:
|
||||||
on_progress(phase)
|
on_progress(phase)
|
||||||
@@ -567,6 +767,8 @@ def promote_pin_numbers(app, api, replacement_uids, slot_count=1, on_progress=No
|
|||||||
for slot in range(1, int(slot_count) + 1):
|
for slot in range(1, int(slot_count) + 1):
|
||||||
progress(f'promote_slot_{slot}')
|
progress(f'promote_slot_{slot}')
|
||||||
app.ActiveView.Block.PromoteSymbolNumbers(1, slot)
|
app.ActiveView.Block.PromoteSymbolNumbers(1, slot)
|
||||||
|
if not verify_pins:
|
||||||
|
return []
|
||||||
progress('query_promoted_pins')
|
progress('query_promoted_pins')
|
||||||
promoted = []
|
promoted = []
|
||||||
for item in app.ActiveView.Query(4096, 0):
|
for item in app.ActiveView.Query(4096, 0):
|
||||||
@@ -591,20 +793,26 @@ def _promotion_phase(snapshot, report, phase):
|
|||||||
|
|
||||||
|
|
||||||
def replacement_matches(components, records, target, require_part_label, *, library_row=None):
|
def replacement_matches(components, records, target, require_part_label, *, library_row=None):
|
||||||
current_by_uid = {_component_uid(component): component for component in components}
|
current_by_ref = {}
|
||||||
if len(current_by_uid) != len(components):
|
for component in components:
|
||||||
raise ValueError('Duplicate component UID on sheet')
|
current_by_ref.setdefault(str(component.Refdes).strip().casefold(), []).append(component)
|
||||||
expected_name = expected_label = None
|
expected_name = expected_label = None
|
||||||
if library_row is not None:
|
if library_row is not None:
|
||||||
if (len(library_row) < 6 or str(library_row[1]).casefold() != target.casefold()
|
if (len(library_row) < 6 or str(library_row[1]).casefold() != target.casefold()
|
||||||
or not str(library_row[4]).strip()):
|
or not str(library_row[4]).strip()):
|
||||||
raise ValueError('Recorded target library identity is incomplete or inconsistent')
|
raise ValueError('Recorded target library identity is incomplete or inconsistent')
|
||||||
expected_name, expected_label = str(library_row[4]), str(library_row[5])
|
expected_name, expected_label = str(library_row[4]), str(library_row[5])
|
||||||
matches = []
|
matches, used = [], set()
|
||||||
for record in records:
|
for record in records:
|
||||||
candidate = current_by_uid.get(record[1])
|
candidates = current_by_ref.get(str(record[2]).strip().casefold(), [])
|
||||||
if candidate is None:
|
if len(candidates) > 1:
|
||||||
raise ValueError('Native replacement lost component UID identity')
|
candidates = [candidate for candidate in candidates if len(record) >= 7 and _same_unit(candidate, record[3:7])]
|
||||||
|
if len(candidates) != 1:
|
||||||
|
raise ValueError('Native replacement reference is missing or ambiguous')
|
||||||
|
candidate = candidates[0]
|
||||||
|
if id(candidate) in used:
|
||||||
|
raise ValueError('Duplicate physical unit association')
|
||||||
|
used.add(id(candidate))
|
||||||
if attribute_value(candidate, "Part Number", required=True).casefold() != target.casefold():
|
if attribute_value(candidate, "Part Number", required=True).casefold() != target.casefold():
|
||||||
return None
|
return None
|
||||||
identity = str(candidate.Refdes).strip() or f"UID={candidate.UID}"
|
identity = str(candidate.Refdes).strip() or f"UID={candidate.UID}"
|
||||||
@@ -622,7 +830,7 @@ def replacement_matches(components, records, target, require_part_label, *, libr
|
|||||||
if expected_name is not None and (part_name != expected_name
|
if expected_name is not None and (part_name != expected_name
|
||||||
or (expected_label and part_label != expected_label)):
|
or (expected_label and part_label != expected_label)):
|
||||||
raise ValueError(f'Native replacement does not match the selected target library identity; uid={candidate.UID}')
|
raise ValueError(f'Native replacement does not match the selected target library identity; uid={candidate.UID}')
|
||||||
matches.append(_component_uid(candidate))
|
matches.append(record[1])
|
||||||
if len(set(matches)) != len(records):
|
if len(set(matches)) != len(records):
|
||||||
raise ValueError("Duplicate replacement association")
|
raise ValueError("Duplicate replacement association")
|
||||||
return matches
|
return matches
|
||||||
@@ -651,6 +859,7 @@ def verify_replacement_readback(snapshot, components, metadata, records, before_
|
|||||||
return verified
|
return verified
|
||||||
|
|
||||||
|
|
||||||
|
@_bound_snapshot_identity
|
||||||
def run_native(snapshot, report):
|
def run_native(snapshot, report):
|
||||||
import win32api
|
import win32api
|
||||||
import win32con
|
import win32con
|
||||||
@@ -659,6 +868,7 @@ def run_native(snapshot, report):
|
|||||||
from pywinauto import Desktop
|
from pywinauto import Desktop
|
||||||
|
|
||||||
metadata, records = read_snapshot(snapshot)
|
metadata, records = read_snapshot(snapshot)
|
||||||
|
native_mode = saved_netlist_snapshot(snapshot)
|
||||||
target_cell = snapshot_target_cell(snapshot, required=False)
|
target_cell = snapshot_target_cell(snapshot, required=False)
|
||||||
require_part_label = snapshot_value_mode(metadata) == "part_label"
|
require_part_label = snapshot_value_mode(metadata) == "part_label"
|
||||||
app, api = attach()
|
app, api = attach()
|
||||||
@@ -666,7 +876,7 @@ def run_native(snapshot, report):
|
|||||||
cell_proof = target_cell_catalog(app, snapshot, metadata, target_cell) if target_cell is not None else None
|
cell_proof = target_cell_catalog(app, snapshot, metadata, target_cell) if target_cell is not None else None
|
||||||
components = components_on_sheet(app, api)
|
components = components_on_sheet(app, api)
|
||||||
wanted = {row[1] for row in records}
|
wanted = {row[1] for row in records}
|
||||||
if len(metadata) == 10:
|
if len(metadata) == 10 and not native_mode:
|
||||||
verify_unselected_snapshot(snapshot, components, wanted, api=api)
|
verify_unselected_snapshot(snapshot, components, wanted, api=api)
|
||||||
source_uids = {
|
source_uids = {
|
||||||
_component_uid(component)
|
_component_uid(component)
|
||||||
@@ -677,6 +887,11 @@ def run_native(snapshot, report):
|
|||||||
binding = require_resumable_transaction(snapshot, report, metadata, records)
|
binding = require_resumable_transaction(snapshot, report, metadata, records)
|
||||||
if binding.get("cell_catalog") != cell_proof:
|
if binding.get("cell_catalog") != cell_proof:
|
||||||
raise ValueError("Current Cell catalog differs from recorded native transaction")
|
raise ValueError("Current Cell catalog differs from recorded native transaction")
|
||||||
|
if native_mode:
|
||||||
|
if report.get("stage") == "native_replace_applied" and report.get("pin_promotion_phase") == "promotion_complete":
|
||||||
|
report["already_replaced"] = True
|
||||||
|
return
|
||||||
|
raise ValueError("Native replacement may already have been applied; verify saved native data before continuing")
|
||||||
report["replaced_uids"] = existing_replacement_uids(
|
report["replaced_uids"] = existing_replacement_uids(
|
||||||
components, records, metadata[3], binding, require_part_label=require_part_label
|
components, records, metadata[3], binding, require_part_label=require_part_label
|
||||||
)
|
)
|
||||||
@@ -696,7 +911,7 @@ def run_native(snapshot, report):
|
|||||||
return
|
return
|
||||||
components = select_snapshot_batch(app, api, metadata, records)
|
components = select_snapshot_batch(app, api, metadata, records)
|
||||||
before_uids = {_component_uid(component) for component in components}
|
before_uids = {_component_uid(component) for component in components}
|
||||||
untouched = None if len(metadata) == 10 else {_component_uid(component): (
|
untouched = None if native_mode or len(metadata) == 10 else {_component_uid(component): (
|
||||||
str(component.Refdes),
|
str(component.Refdes),
|
||||||
*(attribute_value(component, name) for name in ("Part Number", "Value", "Part Name", "Part Label"))
|
*(attribute_value(component, name) for name in ("Part Number", "Value", "Part Name", "Part Label"))
|
||||||
) for component in components if _component_uid(component) not in wanted}
|
) for component in components if _component_uid(component) not in wanted}
|
||||||
@@ -734,8 +949,8 @@ def run_native(snapshot, report):
|
|||||||
raise ValueError("Multiple replacement dialogs")
|
raise ValueError("Multiple replacement dialogs")
|
||||||
return matches[0] if matches else None
|
return matches[0] if matches else None
|
||||||
|
|
||||||
def message(handle, code, wparam=0, lparam=0):
|
def message(handle, code, wparam=0, lparam=0, *, timeout=15000):
|
||||||
return win32gui.SendMessageTimeout(handle, code, wparam, lparam, win32con.SMTO_ABORTIFHUNG, 15000)
|
return win32gui.SendMessageTimeout(handle, code, wparam, lparam, win32con.SMTO_ABORTIFHUNG, timeout)
|
||||||
|
|
||||||
def control_text(control):
|
def control_text(control):
|
||||||
buffer = ctypes.create_unicode_buffer(2048)
|
buffer = ctypes.create_unicode_buffer(2048)
|
||||||
@@ -751,9 +966,9 @@ def run_native(snapshot, report):
|
|||||||
control = dlg_item(dialog, identifier)
|
control = dlg_item(dialog, identifier)
|
||||||
if not control:
|
if not control:
|
||||||
raise ValueError(f"Required native option {identifier} is unavailable")
|
raise ValueError(f"Required native option {identifier} is unavailable")
|
||||||
if win32gui.SendMessage(control, 0x00F0, 0, 0) != 1:
|
if message(control, 0x00F0)[1] != 1:
|
||||||
click(control)
|
click(control)
|
||||||
if win32gui.SendMessage(control, 0x00F0, 0, 0) != 1:
|
if message(control, 0x00F0)[1] != 1:
|
||||||
raise ValueError(f"Native option {identifier} was not enabled")
|
raise ValueError(f"Native option {identifier} was not enabled")
|
||||||
report.setdefault("native_options", {})[str(identifier)] = {
|
report.setdefault("native_options", {})[str(identifier)] = {
|
||||||
"text": control_text(control),
|
"text": control_text(control),
|
||||||
@@ -782,31 +997,68 @@ def run_native(snapshot, report):
|
|||||||
"main_visible_before_browse": bool(win32gui.IsWindowVisible(main_handle)),
|
"main_visible_before_browse": bool(win32gui.IsWindowVisible(main_handle)),
|
||||||
"browse_button": int(dlg_item(dialog, 1366)),
|
"browse_button": int(dlg_item(dialog, 1366)),
|
||||||
}
|
}
|
||||||
click(dlg_item(dialog, 1366))
|
|
||||||
|
|
||||||
def part_list():
|
def query_message(handle, code, wparam=0, lparam=0):
|
||||||
report["databook"]["main_visible_during_wait"] = bool(
|
try:
|
||||||
win32gui.IsWindowVisible(main_handle)
|
message(handle, code, wparam, lparam, timeout=5000)
|
||||||
)
|
except win32gui.error as error:
|
||||||
|
if error.winerror == 1460:
|
||||||
|
raise TimeoutError('Native DxDataBook browse or filter did not respond') from error
|
||||||
|
raise
|
||||||
|
|
||||||
|
def browse():
|
||||||
|
button = dlg_item(dialog, 1366)
|
||||||
|
if button and win32gui.IsWindowEnabled(dialog) and win32gui.IsWindowEnabled(button):
|
||||||
|
query_message(button, 0x00F5) # BM_CLICK
|
||||||
|
|
||||||
|
def controls():
|
||||||
|
lists, filters = {}, {}
|
||||||
for handle in owned_windows(include_hidden=True):
|
for handle in owned_windows(include_hidden=True):
|
||||||
if win32gui.GetClassName(handle) == "SysListView32" and win32gui.GetDlgCtrlID(handle) == 4000:
|
try:
|
||||||
return handle
|
kind = (win32gui.GetClassName(handle), win32gui.GetDlgCtrlID(handle))
|
||||||
return None
|
if kind == ('SysListView32', 4000):
|
||||||
list_handle = wait_for(part_list, "Native DxDataBook part list did not open", timeout=30)
|
lists[handle] = win32gui.GetAncestor(handle, 2)
|
||||||
|
elif kind == ('Edit', 4006):
|
||||||
|
filters[handle] = win32gui.GetAncestor(handle, 2)
|
||||||
|
except win32gui.error:
|
||||||
|
if win32gui.IsWindow(handle):
|
||||||
|
raise
|
||||||
|
pairs = [(part_list, part_filter) for part_list, list_root in lists.items()
|
||||||
|
for part_filter, filter_root in filters.items() if list_root == filter_root]
|
||||||
|
visible = [pair for pair in pairs if all(win32gui.IsWindowVisible(handle) for handle in pair)]
|
||||||
|
pairs = visible or pairs
|
||||||
|
return pairs[0] if len(pairs) == 1 else None
|
||||||
|
|
||||||
|
def filter_part(handle):
|
||||||
|
query_message(handle, win32con.WM_SETTEXT, 0, metadata[3])
|
||||||
|
|
||||||
|
def current_library_rows(list_handle):
|
||||||
|
try:
|
||||||
|
return [(row, [text.window_text() for text in row.children(control_type="Text")])
|
||||||
|
for row in desktop.window(handle=list_handle).descendants(control_type="ListItem")]
|
||||||
|
except Exception:
|
||||||
|
if win32gui.IsWindow(list_handle):
|
||||||
|
raise
|
||||||
|
return []
|
||||||
|
|
||||||
|
def dialogs():
|
||||||
|
return databook_dialogs(win32gui, win32process, process_id, dialog, main_handle)
|
||||||
|
|
||||||
|
def close_dialog(expected):
|
||||||
|
if expected not in dialogs():
|
||||||
|
raise OSError('DxDataBook dialog changed before close')
|
||||||
|
win32gui.PostMessage(expected['hwnd'], win32con.WM_CLOSE, 0, 0)
|
||||||
|
wait_for(lambda: not win32gui.IsWindowVisible(expected['hwnd']),
|
||||||
|
'Native DxDataBook dialog did not close', timeout=3)
|
||||||
|
|
||||||
|
list_handle, rows = load_databook_target(snapshot, report, metadata[3], controls=controls,
|
||||||
|
browse=browse, filter_part=filter_part, list_rows=current_library_rows,
|
||||||
|
dialogs=dialogs, close_dialog=close_dialog)
|
||||||
report["databook"].update(
|
report["databook"].update(
|
||||||
list_handle=int(list_handle),
|
list_handle=int(list_handle),
|
||||||
list_visible=bool(win32gui.IsWindowVisible(list_handle)),
|
list_visible=bool(win32gui.IsWindowVisible(list_handle)),
|
||||||
main_visible_after_load=bool(win32gui.IsWindowVisible(main_handle)),
|
main_visible_after_load=bool(win32gui.IsWindowVisible(main_handle)),
|
||||||
)
|
)
|
||||||
filter_handles = [handle for handle in owned_windows(include_hidden=True)
|
|
||||||
if win32gui.GetDlgCtrlID(handle) == 4006 and win32gui.GetClassName(handle) == "Edit"]
|
|
||||||
if len(filter_handles) != 1:
|
|
||||||
raise ValueError("Cannot uniquely identify native Part Number filter")
|
|
||||||
message(filter_handles[0], win32con.WM_SETTEXT, 0, metadata[3])
|
|
||||||
def current_library_rows():
|
|
||||||
return [(row, [text.window_text() for text in row.children(control_type="Text")])
|
|
||||||
for row in desktop.window(handle=list_handle).descendants(control_type="ListItem")]
|
|
||||||
rows = wait_for_library_rows(current_library_rows, metadata[3])
|
|
||||||
row, columns = exact_target(rows, metadata[3])
|
row, columns = exact_target(rows, metadata[3])
|
||||||
report["library_row"] = columns
|
report["library_row"] = columns
|
||||||
symbol_parts = columns[2].split(":", 1)
|
symbol_parts = columns[2].split(":", 1)
|
||||||
@@ -816,6 +1068,9 @@ def run_native(snapshot, report):
|
|||||||
report["slot_count"] = slot_count
|
report["slot_count"] = slot_count
|
||||||
if slot_count < 1:
|
if slot_count < 1:
|
||||||
raise ValueError("Library target has no valid slots")
|
raise ValueError("Library target has no valid slots")
|
||||||
|
current_pair = controls()
|
||||||
|
if current_pair is None or current_pair[0] != list_handle:
|
||||||
|
raise ValueError("DxDataBook controls changed after target selection")
|
||||||
rectangle = row.rectangle()
|
rectangle = row.rectangle()
|
||||||
list_rectangle = win32gui.GetWindowRect(list_handle)
|
list_rectangle = win32gui.GetWindowRect(list_handle)
|
||||||
if rectangle.height() <= 0 or rectangle.top < list_rectangle[1] or rectangle.bottom > list_rectangle[3]:
|
if rectangle.height() <= 0 or rectangle.top < list_rectangle[1] or rectangle.bottom > list_rectangle[3]:
|
||||||
@@ -854,13 +1109,17 @@ def run_native(snapshot, report):
|
|||||||
report["stage"] = "native_replace_started"
|
report["stage"] = "native_replace_started"
|
||||||
save_report(snapshot, report)
|
save_report(snapshot, report)
|
||||||
mark_snapshot_mutation(snapshot)
|
mark_snapshot_mutation(snapshot)
|
||||||
click(dlg_item(dialog, 1695))
|
from .operation_diagnostics import operation_span
|
||||||
|
with operation_span(Path(snapshot).parent, 'native_replace', item_id=Path(snapshot).stem):
|
||||||
|
click(dlg_item(dialog, 1695))
|
||||||
|
|
||||||
replacement_poll_count = 0
|
replacement_poll_count = 0
|
||||||
|
|
||||||
def selected_replaced():
|
def selected_replaced():
|
||||||
nonlocal replacement_poll_count
|
nonlocal replacement_poll_count
|
||||||
replacement_poll_count += 1
|
replacement_poll_count += 1
|
||||||
|
if native_mode:
|
||||||
|
return applied_replacement_uids(components_on_sheet(app, api), records, metadata[3])
|
||||||
selected = [api.IVdComp(component._oleobj_) for component in app.ActiveView.Query(128, 1)]
|
selected = [api.IVdComp(component._oleobj_) for component in app.ActiveView.Query(128, 1)]
|
||||||
if len(selected) == len(records):
|
if len(selected) == len(records):
|
||||||
matches = replacement_matches(selected, records, metadata[3], require_part_label, library_row=columns)
|
matches = replacement_matches(selected, records, metadata[3], require_part_label, library_row=columns)
|
||||||
@@ -880,7 +1139,7 @@ def run_native(snapshot, report):
|
|||||||
# Preserve the last observed identities without retrying a mutation.
|
# Preserve the last observed identities without retrying a mutation.
|
||||||
report['replacement_timeout'] = {'polls': replacement_poll_count}
|
report['replacement_timeout'] = {'polls': replacement_poll_count}
|
||||||
try:
|
try:
|
||||||
current = components_on_sheet(app, api)
|
current = [] if native_mode else components_on_sheet(app, api)
|
||||||
refs = {record[2] for record in records}
|
refs = {record[2] for record in records}
|
||||||
report['replacement_timeout'].update(
|
report['replacement_timeout'].update(
|
||||||
component_count=len(current),
|
component_count=len(current),
|
||||||
@@ -895,16 +1154,17 @@ def run_native(snapshot, report):
|
|||||||
except Exception as error:
|
except Exception as error:
|
||||||
report['replacement_timeout']['target_control_error'] = str(error)
|
report['replacement_timeout']['target_control_error'] = str(error)
|
||||||
raise
|
raise
|
||||||
current = components_on_sheet(app, api)
|
if not native_mode:
|
||||||
verify_replacement_readback(snapshot, current, metadata, records, before_uids,
|
current = components_on_sheet(app, api)
|
||||||
untouched, require_part_label, columns, report['replaced_uids'], api=api)
|
verify_replacement_readback(snapshot, current, metadata, records, before_uids,
|
||||||
|
untouched, require_part_label, columns, report['replaced_uids'], api=api)
|
||||||
report["stage"] = "native_replace_applied"
|
report["stage"] = "native_replace_applied"
|
||||||
save_report(snapshot, report)
|
save_report(snapshot, report)
|
||||||
report["stage"] = "pin_promotion_started"
|
report["stage"] = "pin_promotion_started"
|
||||||
save_report(snapshot, report)
|
save_report(snapshot, report)
|
||||||
report["promoted_pins"] = promote_pin_numbers(app, api, report["replaced_uids"], slot_count,
|
report["promoted_pins"] = promote_pin_numbers(app, api, report["replaced_uids"], slot_count,
|
||||||
lambda phase: _promotion_phase(snapshot, report, phase))
|
lambda phase: _promotion_phase(snapshot, report, phase), verify_pins=not native_mode)
|
||||||
report["stage"] = "native_replace_verified"
|
report["stage"] = "native_replace_applied" if native_mode else "native_replace_verified"
|
||||||
finally:
|
finally:
|
||||||
if dialog and win32gui.IsWindow(dialog):
|
if dialog and win32gui.IsWindow(dialog):
|
||||||
close_button = dlg_item(dialog, 1696)
|
close_button = dlg_item(dialog, 1696)
|
||||||
|
|||||||
@@ -2,7 +2,7 @@
|
|||||||
from __future__ import annotations
|
from __future__ import annotations
|
||||||
|
|
||||||
import os
|
import os
|
||||||
from collections import Counter
|
from collections import Counter, defaultdict
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
import re
|
import re
|
||||||
|
|
||||||
@@ -38,38 +38,45 @@ def _require_report(text, mode):
|
|||||||
|
|
||||||
|
|
||||||
def _effective_properties(text):
|
def _effective_properties(text):
|
||||||
|
from .native_netlist import _is_pcb
|
||||||
_require_report(text, 'FLAT BLOCKS')
|
_require_report(text, 'FLAT BLOCKS')
|
||||||
if len(re.findall(r'^Config .+', text, re.MULTILINE)) != 1:
|
if len(re.findall(r'^Config .+', text, re.MULTILINE)) != 1:
|
||||||
raise NativeInventoryUnsupported('展开报告必须具有唯一配置')
|
raise NativeInventoryUnsupported('展开报告必须具有唯一配置')
|
||||||
result, attributes, paths = {}, {}, []
|
result, attributes, paths = {}, {}, []
|
||||||
inconsistent_refs = set()
|
inconsistent_refs = set()
|
||||||
symbol = None
|
symbol = symbol_type = None
|
||||||
|
|
||||||
def finish():
|
def finish():
|
||||||
if symbol is None:
|
if symbol is None:
|
||||||
return
|
return
|
||||||
uid, ref = symbol
|
if symbol_type is not None and not _is_pcb({'symbol': symbol_type, 'attributes': attributes}):
|
||||||
if not _UID.fullmatch(uid):
|
|
||||||
if attributes.get('Part Number'):
|
|
||||||
raise NativeInventoryUnsupported('展开报告的物料缺少唯一 UID')
|
|
||||||
return
|
return
|
||||||
if uid in result or paths != ['']:
|
uid, ref, page = symbol
|
||||||
raise NativeInventoryUnsupported('展开报告含重复或嵌套实例,需由 CAD 核验')
|
if not ref:
|
||||||
|
if attributes.get('Part Number') and symbol_type and _is_pcb({'symbol': symbol_type,'attributes':attributes}):
|
||||||
|
raise NativeInventoryUnsupported('展开报告的请求物料缺少位号')
|
||||||
|
return
|
||||||
|
unit = symbol_type.split(' type ', 1)[0] if symbol_type else ''
|
||||||
|
key = (ref.strip().casefold(), page.strip(), unit)
|
||||||
|
if key in result or paths != ['']:
|
||||||
|
raise NativeInventoryUnsupported('展开报告含重复位号或嵌套实例,无法明确定位')
|
||||||
if ref != attributes.get('Ref Designator', ''):
|
if ref != attributes.get('Ref Designator', ''):
|
||||||
inconsistent_refs.add(uid)
|
inconsistent_refs.add(key)
|
||||||
result[uid] = dict(attributes)
|
result[key] = (uid, dict(attributes))
|
||||||
if len(result) > 100000:
|
if len(result) > 100000:
|
||||||
raise NativeInventoryUnsupported('原生器件数量超过读取上限')
|
raise NativeInventoryUnsupported('原生器件数量超过读取上限')
|
||||||
|
|
||||||
for line in text.splitlines():
|
for line in text.splitlines():
|
||||||
if line.startswith(' Symbol '):
|
if line.startswith(' Symbol '):
|
||||||
finish()
|
finish()
|
||||||
match = re.fullmatch(r' Symbol (.+?)\tref des ([^\t]*)\tpage [^\t]*', line)
|
match = re.fullmatch(r' Symbol (.*?)\tref des ([^\t]*)\tpage ([^\t]*)', line)
|
||||||
if match is None:
|
if match is None:
|
||||||
raise NativeInventoryUnsupported('展开报告含不明确的器件身份')
|
raise NativeInventoryUnsupported('展开报告含不明确的器件身份')
|
||||||
symbol, attributes, paths = match.groups(), {}, []
|
symbol, attributes, paths, symbol_type = match.groups(), {}, [], None
|
||||||
elif symbol is not None and line.startswith('\tPath '):
|
elif symbol is not None and line.startswith('\tPath '):
|
||||||
paths.append(line[6:])
|
paths.append(line[6:])
|
||||||
|
elif symbol is not None and line.startswith('\tSymbol name '):
|
||||||
|
symbol_type = line[13:]
|
||||||
elif symbol is not None:
|
elif symbol is not None:
|
||||||
match = _PROPERTY.fullmatch(line)
|
match = _PROPERTY.fullmatch(line)
|
||||||
if match:
|
if match:
|
||||||
@@ -82,39 +89,61 @@ def _effective_properties(text):
|
|||||||
|
|
||||||
|
|
||||||
def _parse_scope(text, requested, effective, inconsistent_refs):
|
def _parse_scope(text, requested, effective, inconsistent_refs):
|
||||||
|
from .native_netlist import _is_pcb
|
||||||
blocks, sheets, targets = set(), set(), set()
|
blocks, sheets, targets = set(), set(), set()
|
||||||
seen_uids = set()
|
seen_uids = set()
|
||||||
block, symbol, attributes = '', None, {}
|
physical_targets = {}
|
||||||
|
by_ref = defaultdict(list)
|
||||||
|
uid_counts = Counter(uid for uid, _ in effective.values())
|
||||||
|
unit_counts = Counter(key[:2] for key in effective)
|
||||||
|
for key in effective:
|
||||||
|
by_ref[key[0]].append(key)
|
||||||
|
block, symbol, attributes, symbol_type = '', None, {}, None
|
||||||
def finish():
|
def finish():
|
||||||
if symbol is None:
|
if symbol is None:
|
||||||
return
|
return
|
||||||
uid, sheet = symbol
|
if symbol_type is not None and not _is_pcb({'symbol': symbol_type, 'attributes': attributes}):
|
||||||
if not _UID.fullmatch(uid):
|
|
||||||
if attributes.get('Part Number'):
|
|
||||||
raise NativeInventoryUnsupported('全工程报告中的请求物料缺少唯一身份')
|
|
||||||
return
|
return
|
||||||
if uid in seen_uids or uid not in effective:
|
uid, sheet = symbol
|
||||||
raise NativeInventoryUnsupported('分层与展开报告的 UID 不完整或重复,需由 CAD 核验')
|
ref = attributes.get('Ref Designator','')
|
||||||
seen_uids.add(uid)
|
if not ref:
|
||||||
values = effective[uid]
|
if attributes.get('Part Number','').casefold() in requested:
|
||||||
|
raise NativeInventoryUnsupported('全工程报告中的请求物料缺少位号')
|
||||||
|
return
|
||||||
|
unit = symbol_type.split(' type ', 1)[0] if symbol_type else ''
|
||||||
|
candidates = [key for key in by_ref[ref.strip().casefold()]
|
||||||
|
if (not key[1] or key[1] == sheet.strip())
|
||||||
|
and (not key[2] or not unit or key[2] == unit)]
|
||||||
|
if len(candidates) != 1 or candidates[0] in seen_uids:
|
||||||
|
raise NativeInventoryUnsupported('分层与展开报告的器件范围不完整或位号重复')
|
||||||
|
key = candidates[0]
|
||||||
|
seen_uids.add(key)
|
||||||
|
flat_uid, values = effective[key]
|
||||||
if attributes.get('Part Number') and 'Part Number' not in values:
|
if attributes.get('Part Number') and 'Part Number' not in values:
|
||||||
raise NativeInventoryUnsupported('展开报告缺少物料生效属性')
|
raise NativeInventoryUnsupported('展开报告缺少物料生效属性')
|
||||||
if 'Value' in attributes and 'Value' not in values:
|
if 'Value' in attributes and 'Value' not in values:
|
||||||
raise NativeInventoryUnsupported('展开报告缺少 Value 生效属性')
|
raise NativeInventoryUnsupported('展开报告缺少 Value 生效属性')
|
||||||
if values.get('Part Number', '').casefold() in requested:
|
if values.get('Part Number', '').casefold() in requested:
|
||||||
# A library reference override on an unrelated part cannot affect
|
# A library reference override on an unrelated part cannot affect
|
||||||
# the requested identities. Still validate every UID/config/path,
|
# the requested identities. Still validate every reference/config/path,
|
||||||
# and require CAD whenever the ambiguous component is requested.
|
# and require CAD whenever the ambiguous component is requested.
|
||||||
if uid in inconsistent_refs:
|
if key in inconsistent_refs:
|
||||||
raise NativeInventoryUnsupported('展开报告的位号与属性不一致')
|
raise NativeInventoryUnsupported('展开报告的位号与属性不一致')
|
||||||
ref, part = values.get('Ref Designator', ''), values['Part Number']
|
ref, part = values.get('Ref Designator', ''), values['Part Number']
|
||||||
if not ref or 'Ref Designator' not in attributes:
|
if not ref or 'Ref Designator' not in attributes:
|
||||||
raise NativeInventoryUnsupported('全工程报告中的请求物料缺少位号')
|
raise NativeInventoryUnsupported('全工程报告中的请求物料缺少位号')
|
||||||
target = (block, sheet, uid, ref, part, values.get('Value', ''),
|
multiunit = unit_counts[key[:2]] > 1
|
||||||
|
identity = uid if not multiunit and _UID.fullmatch(uid) and uid == flat_uid and uid_counts[uid] == 1 else '@REFDES|' + ref
|
||||||
|
target = (block, sheet, identity, ref, part, values.get('Value', ''),
|
||||||
values.get('Part Label'), values.get('Cell Name'))
|
values.get('Part Label'), values.get('Cell Name'))
|
||||||
if target in targets:
|
physical_key = block, sheet, ref
|
||||||
|
prior = physical_targets.get(physical_key)
|
||||||
|
if prior and prior[3:] != target[3:]:
|
||||||
|
raise NativeInventoryUnsupported('Conflicting effective attributes across physical symbol units')
|
||||||
|
if target in targets and not multiunit:
|
||||||
raise NativeInventoryUnsupported('全工程报告含重复器件身份')
|
raise NativeInventoryUnsupported('全工程报告含重复器件身份')
|
||||||
targets.add(target)
|
targets.add(target)
|
||||||
|
physical_targets[physical_key] = target
|
||||||
if len(targets) > 100000:
|
if len(targets) > 100000:
|
||||||
raise NativeInventoryUnsupported('原生器件数量超过读取上限')
|
raise NativeInventoryUnsupported('原生器件数量超过读取上限')
|
||||||
for line in text.splitlines():
|
for line in text.splitlines():
|
||||||
@@ -124,14 +153,16 @@ def _parse_scope(text, requested, effective, inconsistent_refs):
|
|||||||
if not name or name in blocks:
|
if not name or name in blocks:
|
||||||
raise NativeInventoryUnsupported('全工程报告含不明确的原理图身份')
|
raise NativeInventoryUnsupported('全工程报告含不明确的原理图身份')
|
||||||
blocks.add(name)
|
blocks.add(name)
|
||||||
block, symbol, attributes = name, None, {}
|
block, symbol, attributes, symbol_type = name, None, {}, None
|
||||||
elif line.startswith(' Symbol '):
|
elif line.startswith(' Symbol '):
|
||||||
finish()
|
finish()
|
||||||
match = re.fullmatch(r' Symbol (.+?)\tpage (.+)', line)
|
match = re.fullmatch(r' Symbol (.*?)\tpage (.+)', line)
|
||||||
if not block or match is None:
|
if not block or match is None:
|
||||||
raise NativeInventoryUnsupported('全工程报告含不明确的图页身份')
|
raise NativeInventoryUnsupported('全工程报告含不明确的图页身份')
|
||||||
symbol, attributes = match.groups(), {}
|
symbol, attributes, symbol_type = match.groups(), {}, None
|
||||||
sheets.add((block, symbol[1]))
|
sheets.add((block, symbol[1]))
|
||||||
|
elif symbol is not None and line.startswith('\tSymbol name '):
|
||||||
|
symbol_type = line[13:]
|
||||||
elif symbol is not None and line.startswith('\tProp '):
|
elif symbol is not None and line.startswith('\tProp '):
|
||||||
# Pin properties have two tabs and must never override a component.
|
# Pin properties have two tabs and must never override a component.
|
||||||
match = _PROPERTY.fullmatch(line)
|
match = _PROPERTY.fullmatch(line)
|
||||||
@@ -149,49 +180,46 @@ def _parse_scope(text, requested, effective, inconsistent_refs):
|
|||||||
|
|
||||||
|
|
||||||
def _hierarchical_root_discovery(project, report_path, effective_path, requested, expected_root):
|
def _hierarchical_root_discovery(project, report_path, effective_path, requested, expected_root):
|
||||||
# ComponentTarget has no instance path: certify only globally unique root selections.
|
|
||||||
from .native_netlist import _parse_ascii, _check_hierarchy_graph, _is_pcb
|
from .native_netlist import _parse_ascii, _check_hierarchy_graph, _is_pcb
|
||||||
text = read_native_text(report_path)
|
text = read_native_text(report_path)
|
||||||
roots = re.findall(r'^Block ([^\t\r\n]+)\tRoot$', text, re.MULTILINE)
|
roots = re.findall(r'^Block ([^\t\r\n]+)\tRoot$', text, re.MULTILINE)
|
||||||
root = expected_root or (roots[0].rstrip() if len(roots) == 1 else None)
|
root = expected_root or (roots[0].rstrip() if len(roots) == 1 else None)
|
||||||
try:
|
try:
|
||||||
components, _ = _parse_ascii(effective_path, require_connections=False)
|
components, _ = _parse_ascii(effective_path, require_connections=False)
|
||||||
_check_hierarchy_graph(report_path, {'components': components}, root)
|
_, _, expanded = _check_hierarchy_graph(report_path, {'components': components}, root, include_rows=True)
|
||||||
except ValueError as error:
|
except ValueError as error:
|
||||||
raise NativeInventoryUnsupported(str(error)) from error
|
raise NativeInventoryUnsupported(str(error)) from error
|
||||||
physical = {uid: row for uid, row in components.items() if _is_pcb(row)}
|
sheets = {(row['source_schematic'], row['source_page']) for row in expanded}
|
||||||
source_uids = Counter(row.get('source_uid', uid) for uid, row in components.items())
|
counts = Counter(row.get('source_uid', uid) for uid, row in components.items())
|
||||||
references = Counter(row['refdes'] for row in physical.values())
|
targets = {}
|
||||||
scopes, sheets, block = {}, set(), None
|
for scope in expanded:
|
||||||
for line in text.splitlines():
|
row = components[scope['graph_key']]
|
||||||
if line.startswith('Block '):
|
|
||||||
block = line[6:].split('\t', 1)[0].rstrip()
|
|
||||||
elif line.startswith(' Symbol '):
|
|
||||||
match = re.fullmatch(r' Symbol (.+?)\tpage (.+)', line)
|
|
||||||
if match is None or block is None:
|
|
||||||
raise NativeInventoryUnsupported('分层报告图页身份不明确')
|
|
||||||
scopes[(block, match[1])] = match[2]
|
|
||||||
sheets.add((block, match[2]))
|
|
||||||
targets = []
|
|
||||||
for uid, row in physical.items():
|
|
||||||
attributes = row['attributes']
|
attributes = row['attributes']
|
||||||
if attributes.get('Part Number', '').casefold() not in requested:
|
if not _is_pcb(row) or attributes.get('Part Number', '').casefold() not in requested:
|
||||||
continue
|
continue
|
||||||
if row.get('instance_path') or source_uids[uid] != 1 or references[row['refdes']] != 1:
|
if not scope.get('refdes'):
|
||||||
raise NativeInventoryUnsupported('请求物料含子实例或非唯一 UID/位号,当前写入选择器不能安全定位')
|
raise NativeInventoryUnsupported('Hierarchical physical component is missing its reference observation')
|
||||||
if 'source_refdes' in row or row.get('ambiguous_attributes'):
|
if 'Value' in scope['attributes'] and 'Value' not in attributes:
|
||||||
raise NativeInventoryUnsupported('请求物料的位号或生效属性存在歧义')
|
raise NativeInventoryUnsupported('Effective physical component is missing its Value observation')
|
||||||
sheet = scopes.get((root, uid))
|
if row.get('ambiguous_attributes'):
|
||||||
if not sheet:
|
raise NativeInventoryUnsupported('Requested physical component has ambiguous effective attributes')
|
||||||
raise NativeInventoryUnsupported('请求物料缺少唯一根块图页')
|
source_uid = row.get('source_uid', scope['source_uid'])
|
||||||
targets.append(ComponentTarget(Path(project), root, sheet, uid, row['refdes'],
|
identity = source_uid if (_UID.fullmatch(source_uid) and counts[source_uid] == 1
|
||||||
attributes['Part Number'], attributes.get('Value', ''), attributes.get('Part Label'),
|
and source_uid == scope['source_uid']) else '@REFDES|' + row['refdes']
|
||||||
attributes.get('Cell Name')))
|
target = ComponentTarget(Path(project), scope['source_schematic'], scope['source_page'],
|
||||||
|
identity, row['refdes'], attributes['Part Number'], attributes.get('Value', ''),
|
||||||
|
attributes.get('Part Label'), attributes.get('Cell Name'))
|
||||||
|
previous = targets.get(target.key)
|
||||||
|
if previous and (previous.old_part_number, previous.old_value, previous.actual_part_label,
|
||||||
|
previous.actual_cell) != (target.old_part_number, target.old_value,
|
||||||
|
target.actual_part_label, target.actual_cell):
|
||||||
|
raise NativeInventoryUnsupported('Conflicting effective attributes across physical symbol units')
|
||||||
|
targets[target.key] = target
|
||||||
matches = {sheet: set() for sheet in sheets}
|
matches = {sheet: set() for sheet in sheets}
|
||||||
for target in targets:
|
for target in targets.values():
|
||||||
matches[(target.schematic_name, target.sheet_number)].add(target.old_part_number.casefold())
|
matches[(target.schematic_name, target.sheet_number)].add(target.old_part_number.casefold())
|
||||||
return ProjectDiscovery(tuple(sorted(sheets)), {key: frozenset(value) for key, value in matches.items()},
|
return ProjectDiscovery(tuple(sorted(sheets)), {key: frozenset(value) for key, value in matches.items()},
|
||||||
tuple(sorted(targets, key=lambda target: target.key)), complete_sheet_manifest=False)
|
tuple(sorted(targets.values(), key=lambda target: target.key)), complete_sheet_manifest=False)
|
||||||
|
|
||||||
|
|
||||||
def read_ascii_discovery(project, report_path, old_part_numbers, *, expected_root=None,
|
def read_ascii_discovery(project, report_path, old_part_numbers, *, expected_root=None,
|
||||||
|
|||||||
@@ -107,10 +107,11 @@ def _parse_ascii(path, *, hierarchy_boundaries=(), require_connections=True):
|
|||||||
symbol = pin = net = conn = None
|
symbol = pin = net = conn = None
|
||||||
for line in text.splitlines():
|
for line in text.splitlines():
|
||||||
if line.startswith(' Symbol '):
|
if line.startswith(' Symbol '):
|
||||||
match = re.fullmatch(r' Symbol (.+?)\tref des ([^\t]*)\tpage [^\t]*', line)
|
match = re.fullmatch(r' Symbol (.*?)\tref des ([^\t]*)\tpage ([^\t]*)', line)
|
||||||
if not match:
|
if not match:
|
||||||
raise ValueError('Invalid effective symbol identity')
|
raise ValueError('Invalid effective symbol identity')
|
||||||
symbol = {'uid': match[1], 'refdes': match[2], 'attributes': {}, 'pins': {}, 'paths': []}
|
symbol = {'uid': match[1], 'refdes': match[2], 'source_page': match[3].strip(),
|
||||||
|
'attributes': {}, 'pins': {}, 'paths': []}
|
||||||
symbols.append(symbol)
|
symbols.append(symbol)
|
||||||
pin = None
|
pin = None
|
||||||
elif symbol is not None:
|
elif symbol is not None:
|
||||||
@@ -155,7 +156,7 @@ def _parse_ascii(path, *, hierarchy_boundaries=(), require_connections=True):
|
|||||||
raise ValueError('Duplicate or empty net')
|
raise ValueError('Duplicate or empty net')
|
||||||
expected[net] = Counter()
|
expected[net] = Counter()
|
||||||
elif line.startswith('\t\tConn '):
|
elif line.startswith('\t\tConn '):
|
||||||
match = re.fullmatch(r'\t\tConn (.+?) pin (.+?) page .*', line)
|
match = re.fullmatch(r'\t\tConn (.*?) pin (.+?) page .*', line)
|
||||||
if net is None or not match:
|
if net is None or not match:
|
||||||
raise ValueError('Invalid net endpoint')
|
raise ValueError('Invalid net endpoint')
|
||||||
conn = match.groups()
|
conn = match.groups()
|
||||||
@@ -168,12 +169,15 @@ def _parse_ascii(path, *, hierarchy_boundaries=(), require_connections=True):
|
|||||||
conn = None
|
conn = None
|
||||||
if conn is not None:
|
if conn is not None:
|
||||||
raise ValueError('Endpoint missing path')
|
raise ValueError('Endpoint missing path')
|
||||||
|
raw_counts = Counter((row['uid'], tuple(row['paths'])) for row in symbols)
|
||||||
|
endpoint_aliases = defaultdict(list)
|
||||||
for symbol in symbols:
|
for symbol in symbols:
|
||||||
uid = symbol.pop('uid')
|
uid = symbol.pop('uid')
|
||||||
paths = symbol.pop('paths')
|
paths = symbol.pop('paths')
|
||||||
if len(paths) != 1:
|
if len(paths) != 1:
|
||||||
raise ValueError('Symbol instance path is missing or ambiguous')
|
raise ValueError('Symbol instance path is missing or ambiguous')
|
||||||
source_uid = uid
|
source_uid = uid
|
||||||
|
symbol['source_uid'] = source_uid
|
||||||
uid = _instance_identity(uid, paths[0])
|
uid = _instance_identity(uid, paths[0])
|
||||||
attrs = symbol['attributes']
|
attrs = symbol['attributes']
|
||||||
if paths[0]:
|
if paths[0]:
|
||||||
@@ -181,8 +185,16 @@ def _parse_ascii(path, *, hierarchy_boundaries=(), require_connections=True):
|
|||||||
symbol['refdes'] = attrs.get('Ref Designator', '')
|
symbol['refdes'] = attrs.get('Ref Designator', '')
|
||||||
elif attrs.get('Ref Designator') and attrs['Ref Designator'] != symbol['refdes']:
|
elif attrs.get('Ref Designator') and attrs['Ref Designator'] != symbol['refdes']:
|
||||||
symbol['source_refdes'], symbol['refdes'] = symbol['refdes'], attrs['Ref Designator']
|
symbol['source_refdes'], symbol['refdes'] = symbol['refdes'], attrs['Ref Designator']
|
||||||
if _is_pcb(symbol) and (not re.fullmatch(r'\$\d+I\d+', source_uid) or not symbol['refdes'] or attrs.get('Ref Designator') != symbol['refdes']):
|
# Port names can contain '/', so retain the reported path even at the root.
|
||||||
|
symbol['instance_path'] = '' if paths[0] == 'root' else paths[0]
|
||||||
|
if _is_pcb(symbol) and (not symbol['refdes'] or attrs.get('Ref Designator') != symbol['refdes']):
|
||||||
raise ValueError(f'PCB component identity is ambiguous: {uid!r} / {symbol["refdes"]!r}')
|
raise ValueError(f'PCB component identity is ambiguous: {uid!r} / {symbol["refdes"]!r}')
|
||||||
|
raw_identity = uid
|
||||||
|
if _is_pcb(symbol) and (not re.fullmatch(r'\$\d+I\d+', source_uid)
|
||||||
|
or raw_counts[(source_uid, tuple(paths))] > 1):
|
||||||
|
slot = re.match(r'\S+\.(\d+) type ', symbol.get('symbol', ''))
|
||||||
|
uid = _instance_identity('@REFDES|' + symbol['refdes'] + ('|slot=' + slot[1] if slot else ''), paths[0])
|
||||||
|
endpoint_aliases[raw_identity].append(uid)
|
||||||
symbol['other_attributes'] = sorted(symbol.get('other_attributes', []))
|
symbol['other_attributes'] = sorted(symbol.get('other_attributes', []))
|
||||||
if uid in components:
|
if uid in components:
|
||||||
old = components[uid]
|
old = components[uid]
|
||||||
@@ -203,6 +215,16 @@ def _parse_ascii(path, *, hierarchy_boundaries=(), require_connections=True):
|
|||||||
for net in row['nets']:
|
for net in row['nets']:
|
||||||
nets[net][(uid, pin)] += 1
|
nets[net][(uid, pin)] += 1
|
||||||
for name, endpoints in expected.items():
|
for name, endpoints in expected.items():
|
||||||
|
normalized = Counter()
|
||||||
|
for (uid, pin), count in endpoints.items():
|
||||||
|
candidates = [key for key in endpoint_aliases.get(uid, [uid])
|
||||||
|
if key in components and pin in components[key]['pins']
|
||||||
|
and name in components[key]['pins'][pin]['nets']]
|
||||||
|
if len(set(candidates)) == 1:
|
||||||
|
uid = candidates[0]
|
||||||
|
normalized[(uid, pin)] += count
|
||||||
|
endpoints.clear()
|
||||||
|
endpoints.update(normalized)
|
||||||
for (uid, port), count in list(endpoints.items()):
|
for (uid, port), count in list(endpoints.items()):
|
||||||
if uid not in hierarchy_boundaries:
|
if uid not in hierarchy_boundaries:
|
||||||
continue
|
continue
|
||||||
@@ -316,18 +338,19 @@ def read_graph(ascii_path, keyin_path, *, hierarchy_path=None, root_block=None):
|
|||||||
return graph
|
return graph
|
||||||
|
|
||||||
|
|
||||||
def _check_hierarchy_graph(path, graph, root_block):
|
def _check_hierarchy_graph(path, graph, root_block, *, include_rows=False):
|
||||||
"""Expand native child links independently; inventory UID selectors stay root-only."""
|
"""Bind expanded instances by reference/page/unit while retaining raw UID evidence."""
|
||||||
text = read_native_text(path)
|
text = read_native_text(path)
|
||||||
_require_report(text, 'HIER BLOCKS')
|
_require_report(text, 'HIER BLOCKS')
|
||||||
blocks, roots, block = {}, [], None
|
blocks, roots, block, symbol = {}, [], None, None
|
||||||
for line in text.splitlines():
|
for line in text.splitlines():
|
||||||
if line.startswith('Block '):
|
if line.startswith('Block '):
|
||||||
fields = line[6:].split('\t')
|
fields = line[6:].split('\t')
|
||||||
block = fields[0].rstrip()
|
block = fields[0].rstrip()
|
||||||
if not block or block in blocks:
|
if not block or block in blocks:
|
||||||
raise ValueError('Duplicate or missing native hierarchy block')
|
raise ValueError('Duplicate or missing native hierarchy block')
|
||||||
blocks[block] = {'children': {}, 'symbols': Counter()}
|
blocks[block] = {'children': {}, 'symbols': Counter(), 'rows': []}
|
||||||
|
symbol = None
|
||||||
if fields[1:] == ['Root']:
|
if fields[1:] == ['Root']:
|
||||||
roots.append(block)
|
roots.append(block)
|
||||||
elif line.startswith('\tChild '):
|
elif line.startswith('\tChild '):
|
||||||
@@ -336,13 +359,23 @@ def _check_hierarchy_graph(path, graph, root_block):
|
|||||||
raise ValueError('Ambiguous native hierarchy child')
|
raise ValueError('Ambiguous native hierarchy child')
|
||||||
blocks[block]['children'][match[2]] = match[1]
|
blocks[block]['children'][match[2]] = match[1]
|
||||||
elif line.startswith(' Symbol '):
|
elif line.startswith(' Symbol '):
|
||||||
match = re.fullmatch(r' Symbol (.+?)\tpage (.+)', line)
|
match = re.fullmatch(r' Symbol (.*?)\tpage (.+)', line)
|
||||||
if block is None or match is None:
|
if block is None or match is None:
|
||||||
raise ValueError('Ambiguous native hierarchy symbol')
|
raise ValueError('Ambiguous native hierarchy symbol')
|
||||||
blocks[block]['symbols'][match[1]] += 1
|
blocks[block]['symbols'][match[1]] += 1
|
||||||
|
symbol = {'source_uid': match[1], 'source_page': match[2], 'attributes': {}}
|
||||||
|
blocks[block]['rows'].append(symbol)
|
||||||
|
elif symbol is not None and line.startswith('\tProp Ref Designator '):
|
||||||
|
symbol['refdes'] = line[len('\tProp Ref Designator '):]
|
||||||
|
elif symbol is not None and line.startswith('\tProp Part Number '):
|
||||||
|
symbol['attributes']['Part Number'] = line[len('\tProp Part Number '):]
|
||||||
|
elif symbol is not None and (line == '\tProp Value' or line.startswith('\tProp Value ')):
|
||||||
|
symbol['attributes']['Value'] = line[len('\tProp Value '):]
|
||||||
|
elif symbol is not None and line.startswith('\tSymbol name '):
|
||||||
|
symbol['symbol'] = line[len('\tSymbol name '):]
|
||||||
if roots != [root_block]:
|
if roots != [root_block]:
|
||||||
raise ValueError('Native hierarchy root differs from captured project')
|
raise ValueError('Native hierarchy root differs from captured project')
|
||||||
identities, boundaries = Counter(), set()
|
identities, boundaries, expanded, source_sheets = Counter(), set(), [], set()
|
||||||
|
|
||||||
pending = [(root_block, '', set())]
|
pending = [(root_block, '', set())]
|
||||||
while pending:
|
while pending:
|
||||||
@@ -352,6 +385,11 @@ def _check_hierarchy_graph(path, graph, root_block):
|
|||||||
row = blocks[name]
|
row = blocks[name]
|
||||||
identities.update({_instance_identity(uid, path): count for uid, count in row['symbols'].items()
|
identities.update({_instance_identity(uid, path): count for uid, count in row['symbols'].items()
|
||||||
if uid not in row['children']})
|
if uid not in row['children']})
|
||||||
|
for item in row['rows']:
|
||||||
|
source_sheets.add((name, item['source_page']))
|
||||||
|
if item['source_uid'] in row['children'] and not _is_pcb(item):
|
||||||
|
continue
|
||||||
|
expanded.append(dict(item, instance_path=path, source_schematic=name))
|
||||||
for uid, child in row['children'].items():
|
for uid, child in row['children'].items():
|
||||||
if uid not in row['symbols']:
|
if uid not in row['symbols']:
|
||||||
raise ValueError('Native hierarchy child symbol missing')
|
raise ValueError('Native hierarchy child symbol missing')
|
||||||
@@ -359,10 +397,41 @@ def _check_hierarchy_graph(path, graph, root_block):
|
|||||||
boundaries.add(identity)
|
boundaries.add(identity)
|
||||||
pending.append((child, identity, ancestors | {name}))
|
pending.append((child, identity, ancestors | {name}))
|
||||||
if graph is not None:
|
if graph is not None:
|
||||||
effective = Counter({uid: len(row.get('annotation_instances', [row])) for uid, row in graph['components'].items()})
|
remaining = [(uid, item) for uid, row in graph['components'].items()
|
||||||
if identities != effective:
|
for item in row.get('annotation_instances', [row])]
|
||||||
|
indices, consumed = defaultdict(list), set()
|
||||||
|
for index, (uid, row) in enumerate(remaining):
|
||||||
|
instance = row.get('instance_path', uid.rsplit('/', 1)[0] if '/' in uid else '')
|
||||||
|
ref = row.get('source_refdes', row.get('refdes', '')).strip().casefold()
|
||||||
|
indices[(instance, 'ref', ref)].append(index)
|
||||||
|
indices[(instance, 'uid', row.get('source_uid', uid.rsplit('/', 1)[-1]))].append(index)
|
||||||
|
for item in expanded:
|
||||||
|
ref = item.get('refdes', '').strip().casefold()
|
||||||
|
key = item['instance_path'], 'ref' if ref else 'uid', ref or item['source_uid']
|
||||||
|
candidates = [(index, remaining[index][0], remaining[index][1]) for index in indices[key]
|
||||||
|
if index not in consumed and (not remaining[index][1].get('source_page')
|
||||||
|
or remaining[index][1]['source_page'] == item['source_page'])]
|
||||||
|
if len(candidates) > 1 and item.get('symbol'):
|
||||||
|
unit = item['symbol'].split(' type ', 1)[0]
|
||||||
|
candidates = [candidate for candidate in candidates if candidate[2].get('symbol', '').split(' type ', 1)[0] == unit]
|
||||||
|
if len(candidates) > 1:
|
||||||
|
exact = [candidate for candidate in candidates if candidate[2].get('source_uid') == item['source_uid']]
|
||||||
|
if exact:
|
||||||
|
candidates = exact
|
||||||
|
# Identical nonphysical annotations are counted, not mistaken for devices.
|
||||||
|
if not candidates or (len(candidates) > 1 and ref):
|
||||||
|
raise ValueError('Hierarchical/effective instance coverage differs')
|
||||||
|
index, uid, row = candidates[0]
|
||||||
|
item['graph_key'] = uid
|
||||||
|
if row:
|
||||||
|
row['source_schematic'] = item['source_schematic']
|
||||||
|
row['source_page'] = row.get('source_page') or item['source_page']
|
||||||
|
consumed.add(index)
|
||||||
|
if len(consumed) != len(remaining):
|
||||||
raise ValueError('Hierarchical/effective instance coverage differs')
|
raise ValueError('Hierarchical/effective instance coverage differs')
|
||||||
return identities, boundaries
|
# A page may contain only a child block absent from the flat component graph.
|
||||||
|
graph['source_sheets'] = [list(sheet) for sheet in sorted(source_sheets)]
|
||||||
|
return (identities, boundaries, expanded) if include_rows else (identities, boundaries)
|
||||||
|
|
||||||
|
|
||||||
def export_netlist(capture: dict, output: Path, *, stop_event=None) -> dict:
|
def export_netlist(capture: dict, output: Path, *, stop_event=None) -> dict:
|
||||||
@@ -466,6 +535,80 @@ def _connections(graph):
|
|||||||
return sorted(nets)
|
return sorted(nets)
|
||||||
|
|
||||||
|
|
||||||
|
def reference_targets(graph, refdes, *, sheet='', schematic=''):
|
||||||
|
"""Return every native unit for a physical reference within the requested sheet."""
|
||||||
|
ref = refdes.strip().casefold()
|
||||||
|
candidates = [(uid, row) for uid, row in graph['components'].items()
|
||||||
|
if _is_pcb(row) and row.get('refdes', '').strip().casefold() == ref]
|
||||||
|
pages_known = any(row.get('source_page') for _, row in candidates)
|
||||||
|
blocks_known = any(row.get('source_schematic') for _, row in candidates)
|
||||||
|
return tuple(uid for uid, row in candidates
|
||||||
|
if (not sheet or not pages_known or row.get('source_page') == sheet)
|
||||||
|
and (not schematic or not blocks_known or row.get('source_schematic') == schematic))
|
||||||
|
|
||||||
|
|
||||||
|
def _reference_graph(graph):
|
||||||
|
"""Normalize physical endpoints without changing the captured source evidence."""
|
||||||
|
from copy import deepcopy
|
||||||
|
result = deepcopy(graph)
|
||||||
|
identities, components = {}, {}
|
||||||
|
groups = defaultdict(list)
|
||||||
|
for row in result['components'].values():
|
||||||
|
if _is_pcb(row):
|
||||||
|
groups[row.get('refdes', '').strip().casefold()].append(row)
|
||||||
|
for uid, row in result['components'].items():
|
||||||
|
if _is_pcb(row):
|
||||||
|
ref = row.get('refdes', '').strip().casefold()
|
||||||
|
if not ref:
|
||||||
|
raise ValueError('Physical component has no reference designator')
|
||||||
|
# Separate slots of the same physical device remain independently checked.
|
||||||
|
peers = groups[ref]
|
||||||
|
scopes = {(item.get('source_schematic', ''), item.get('source_page', '')) for item in peers}
|
||||||
|
scope = (row.get('source_schematic', ''), row.get('source_page', ''))
|
||||||
|
same_scope = sum((item.get('source_schematic', ''), item.get('source_page', '')) == scope for item in peers)
|
||||||
|
slot = re.match(r'\S+\.(\d+) type ', row.get('symbol', ''))
|
||||||
|
identity = '@REFDES|' + ref
|
||||||
|
if len(scopes) > 1:
|
||||||
|
identity += '|sheet=' + json.dumps(scope, ensure_ascii=False)
|
||||||
|
if same_scope > 1 and slot:
|
||||||
|
repeated_slot = sum(bool(re.match(r'\S+\.' + re.escape(slot[1]) + r' type ', item.get('symbol', '')))
|
||||||
|
for item in peers if (item.get('source_schematic', ''), item.get('source_page', '')) == scope) > 1
|
||||||
|
if repeated_slot:
|
||||||
|
numbers = [pin.get('number') for pin in row.get('pins', {}).values()]
|
||||||
|
if not numbers or any(not number for number in numbers):
|
||||||
|
raise ValueError('Repeated symbol slots lack a unique physical pin partition')
|
||||||
|
identity += '|pins=' + json.dumps(sorted(numbers), ensure_ascii=False)
|
||||||
|
else:
|
||||||
|
identity += '|slot=' + slot[1]
|
||||||
|
row.pop('source_uid', None)
|
||||||
|
row.pop('instance_path', None)
|
||||||
|
else:
|
||||||
|
identity = uid
|
||||||
|
if identity in components:
|
||||||
|
raise ValueError('Reference designator and symbol slot are ambiguous')
|
||||||
|
identities[uid] = identity
|
||||||
|
components[identity] = row
|
||||||
|
result['components'] = components
|
||||||
|
for net in result['nets']:
|
||||||
|
net['endpoints'] = [[identities.get(uid, uid), pin] for uid, pin in net['endpoints']]
|
||||||
|
return result, identities
|
||||||
|
|
||||||
|
|
||||||
|
def _reference_expectations(graph, aliases, values):
|
||||||
|
result = {}
|
||||||
|
for uid, value in (values or {}).items():
|
||||||
|
targets = (uid,) if uid in aliases else ()
|
||||||
|
if not targets and uid.startswith('@REFDES|'):
|
||||||
|
targets = reference_targets(graph, uid[len('@REFDES|'):])
|
||||||
|
scopes = {(graph['components'][key].get('source_schematic', ''),
|
||||||
|
graph['components'][key].get('source_page', '')) for key in targets}
|
||||||
|
if len(scopes) > 1:
|
||||||
|
raise ValueError('Expected reference requires a sheet-qualified native identity')
|
||||||
|
for target in targets or (uid,):
|
||||||
|
result[aliases.get(target, target)] = value
|
||||||
|
return result
|
||||||
|
|
||||||
|
|
||||||
def compare_netlists(before: dict, after: dict, *, expected_changes=None, expected_symbols=None) -> dict:
|
def compare_netlists(before: dict, after: dict, *, expected_changes=None, expected_symbols=None) -> dict:
|
||||||
"""Compare complete nonempty exports, allowing only declared attribute/symbol changes.
|
"""Compare complete nonempty exports, allowing only declared attribute/symbol changes.
|
||||||
|
|
||||||
@@ -476,7 +619,13 @@ def compare_netlists(before: dict, after: dict, *, expected_changes=None, expect
|
|||||||
graph = result.get('graph', {})
|
graph = result.get('graph', {})
|
||||||
if result.get('status') != 'success' or result.get('complete') is not True or not graph.get('components') or not graph.get('nets'):
|
if result.get('status') != 'success' or result.get('complete') is not True or not graph.get('components') or not graph.get('nets'):
|
||||||
return {'status': 'unavailable', 'verified': False, 'reason': 'Complete nonempty native graphs required'}
|
return {'status': 'unavailable', 'verified': False, 'reason': 'Complete nonempty native graphs required'}
|
||||||
left, right = before['graph'], after['graph']
|
try:
|
||||||
|
left, aliases = _reference_graph(before['graph'])
|
||||||
|
right, _ = _reference_graph(after['graph'])
|
||||||
|
expected_changes = _reference_expectations(before['graph'], aliases, expected_changes)
|
||||||
|
expected_symbols = _reference_expectations(before['graph'], aliases, expected_symbols)
|
||||||
|
except (KeyError, TypeError, ValueError) as error:
|
||||||
|
return {'status': 'unavailable', 'verified': False, 'reason': str(error)}
|
||||||
differences = []
|
differences = []
|
||||||
try:
|
try:
|
||||||
connections_changed = _connections(left) != _connections(right)
|
connections_changed = _connections(left) != _connections(right)
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
"""Overlap native exports with replacement, keeping each saved input immutable."""
|
"""Overlap native exports with replacement, keeping each saved input immutable."""
|
||||||
from concurrent.futures import ThreadPoolExecutor
|
from concurrent.futures import Future, ThreadPoolExecutor
|
||||||
from dataclasses import asdict
|
from dataclasses import asdict
|
||||||
import json
|
import json
|
||||||
import hashlib
|
import hashlib
|
||||||
@@ -54,7 +54,7 @@ def library_from_receipt(command, receipt):
|
|||||||
if receipt.get('native_state') not in {'saved_ok', 'restored_ok'}:
|
if receipt.get('native_state') not in {'saved_ok', 'restored_ok'}:
|
||||||
return {}
|
return {}
|
||||||
from .execution_proof import proof_intact
|
from .execution_proof import proof_intact
|
||||||
from .native_helper import read_snapshot, require_resumable_transaction
|
from .native_helper import read_snapshot, require_resumable_transaction, saved_netlist_snapshot
|
||||||
from .path_access import canonical_path, internal_path
|
from .path_access import canonical_path, internal_path
|
||||||
proof = receipt.get('proof', {})
|
proof = receipt.get('proof', {})
|
||||||
native_files = [Path(item['path']) for item in proof.get('files', ())
|
native_files = [Path(item['path']) for item in proof.get('files', ())
|
||||||
@@ -70,13 +70,18 @@ def library_from_receipt(command, receipt):
|
|||||||
if str(snapshot) not in paths:
|
if str(snapshot) not in paths:
|
||||||
raise ValueError('原生库件证据缺少配套快照')
|
raise ValueError('原生库件证据缺少配套快照')
|
||||||
report = json.loads(internal_path(path).read_text(encoding='utf-8'))
|
report = json.loads(internal_path(path).read_text(encoding='utf-8'))
|
||||||
if report.get('ok') is not True or report.get('stage') != 'native_replace_verified':
|
saved_native = saved_netlist_snapshot(snapshot)
|
||||||
|
if saved_native and proof.get('saved_netlist', proof.get('project_commit', {}).get('saved_netlist', {})).get('status') != 'verified':
|
||||||
|
raise ValueError('已保存的原生数据尚未核验,不能使用写入回执声明成功')
|
||||||
|
stage = 'native_replace_applied' if saved_native else 'native_replace_verified'
|
||||||
|
if report.get('ok') is not True or report.get('stage') != stage:
|
||||||
raise ValueError('原生库件回执未通过实际替换核验')
|
raise ValueError('原生库件回执未通过实际替换核验')
|
||||||
metadata, records = read_snapshot(snapshot)
|
metadata, records = read_snapshot(snapshot)
|
||||||
binding = require_resumable_transaction(snapshot, report, metadata, records)
|
binding = require_resumable_transaction(snapshot, report, metadata, records)
|
||||||
if (canonical_path(metadata[1]) != canonical_path(command['project_path'])
|
if (canonical_path(metadata[1]) != canonical_path(command['project_path'])
|
||||||
or metadata[2:4] != [command['old_part'], command['new_part']]
|
or metadata[2:4] != [command['old_part'], command['new_part']]
|
||||||
or metadata[4] != f"{command['schematic_name']}:{command['sheet_number']}"):
|
or metadata[4] != f"{command['schematic_name']}:{command['sheet_number']}"
|
||||||
|
or (metadata[9] if len(metadata) == 10 else '') != command.get('target_selectors', '')):
|
||||||
raise ValueError('原生库件证据属于不同执行项')
|
raise ValueError('原生库件证据属于不同执行项')
|
||||||
row = binding['library_row']
|
row = binding['library_row']
|
||||||
if row[1].casefold() != command['new_part'].casefold() or not row[4]:
|
if row[1].casefold() != command['new_part'].casefold() or not row[4]:
|
||||||
@@ -95,12 +100,16 @@ def library_from_receipt(command, receipt):
|
|||||||
raise ValueError('Value 回读证据的器件范围不完整')
|
raise ValueError('Value 回读证据的器件范围不完整')
|
||||||
for uid in binding['source_uids']:
|
for uid in binding['source_uids']:
|
||||||
identity = {'attributes': {'Part Number': row[1], 'Part Name': row[4], 'Part Label': row[5]},
|
identity = {'attributes': {'Part Number': row[1], 'Part Name': row[4], 'Part Label': row[5]},
|
||||||
'target_symbol': binding['target_symbol'], 'slot_count': binding['slot_count']}
|
'target_symbol': binding['target_symbol'], 'slot_count': binding['slot_count'],
|
||||||
|
'refdes': next(record[2] for record in records if record[1] == uid),
|
||||||
|
'schematic_name': command.get('schematic_name',''), 'sheet_number': command.get('sheet_number','')}
|
||||||
if uid in values:
|
if uid in values:
|
||||||
value = values[uid]
|
value = values[uid]
|
||||||
|
native_empty = (saved_native and value['actual_value'] == '' and value['actual_value_present'] is None
|
||||||
|
and value.get('value_presence_coverage') == 'native_ascii_empty_presence_unknown')
|
||||||
if (value['actual_part_number'].casefold() != row[1].casefold()
|
if (value['actual_part_number'].casefold() != row[1].casefold()
|
||||||
or not isinstance(value['actual_value'], str)
|
or not isinstance(value['actual_value'], str)
|
||||||
or type(value['actual_value_present']) is not bool):
|
or (type(value['actual_value_present']) is not bool and not native_empty)):
|
||||||
raise ValueError('Value 回读证据与目标库件不符')
|
raise ValueError('Value 回读证据与目标库件不符')
|
||||||
identity.update(preserved_value=value['actual_value'],
|
identity.update(preserved_value=value['actual_value'],
|
||||||
preserved_value_present=value['actual_value_present'])
|
preserved_value_present=value['actual_value_present'])
|
||||||
@@ -180,30 +189,86 @@ def _rule_rows(child, task_id, plan, before):
|
|||||||
if not identities:
|
if not identities:
|
||||||
raise ValueError('规则替换缺少绑定实际 sheet/UID 的原生事务证据')
|
raise ValueError('规则替换缺少绑定实际 sheet/UID 的原生事务证据')
|
||||||
if selector is not None:
|
if selector is not None:
|
||||||
original = before['graph']['components'].get(selector[0], {})
|
keys = native_netlist.reference_targets(before['graph'], selector[1],
|
||||||
if (set(identities) != {selector[0]} or original.get('refdes') != selector[1]
|
sheet=command.get('sheet_number',''),schematic=command.get('schematic_name',''))
|
||||||
or original.get('attributes', {}).get('Value', '') != selector[2]):
|
if ((set(identities) != {selector[0]} and not all(
|
||||||
|
identity.get('refdes','').strip().casefold() == selector[1].strip().casefold()
|
||||||
|
for identity in identities.values())) or not keys or any(
|
||||||
|
before['graph']['components'][key].get('attributes', {}).get('Value', '') != selector[2]
|
||||||
|
for key in keys)):
|
||||||
raise ValueError('规则位号选择器与替换前器件及原生 UID 范围不一致')
|
raise ValueError('规则位号选择器与替换前器件及原生 UID 范围不一致')
|
||||||
scopes.append({key: command.get(key, '') for key in
|
scopes.append({key: command.get(key, '') for key in
|
||||||
('project_path', 'schematic_name', 'sheet_number', 'old_part', 'new_part')}
|
('project_path', 'schematic_name', 'sheet_number', 'old_part', 'new_part')}
|
||||||
| {'source_uids': sorted(identities)})
|
| {'source_uids': sorted(identities)})
|
||||||
for uid in identities:
|
for uid in identities:
|
||||||
component = before['graph']['components'].get(uid)
|
identity = identities[uid]
|
||||||
if component is None or component['attributes'].get('Part Number', '').casefold() != command['old_part'].casefold():
|
keys = _reference_keys(before['graph'], dict(identity, uid=uid,
|
||||||
|
sheet_number=command.get('sheet_number',''), schematic_name=command.get('schematic_name','')))
|
||||||
|
if not keys or any(before['graph']['components'][key]['attributes'].get('Part Number', '').casefold()
|
||||||
|
!= command['old_part'].casefold() for key in keys):
|
||||||
raise ValueError('原生 UID 无法唯一对应替换前的原料号;不能按同料号猜测图页')
|
raise ValueError('原生 UID 无法唯一对应替换前的原料号;不能按同料号猜测图页')
|
||||||
row = {'enabled': True, 'target': {'uid': uid, 'old_value': component['attributes'].get('Value', '')},
|
for key in keys:
|
||||||
|
component = before['graph']['components'][key]
|
||||||
|
row = {'enabled': True, 'target': {'uid': key, 'refdes': component['refdes'],
|
||||||
|
'schematic_name':command.get('schematic_name',''),'sheet_number':command.get('sheet_number',''),
|
||||||
|
'old_value': component['attributes'].get('Value', '')},
|
||||||
'new_part_number': command['new_part'], 'value_mode': command['value_mode'],
|
'new_part_number': command['new_part'], 'value_mode': command['value_mode'],
|
||||||
'custom_value_enabled': command['value_mode'] == 'custom',
|
'custom_value_enabled': command['value_mode'] == 'custom',
|
||||||
'custom_value': command.get('custom_value', ''), 'sync_nc': command.get('sync_nc', '1') == '1',
|
'custom_value': command.get('custom_value', ''), 'sync_nc': command.get('sync_nc', '1') == '1',
|
||||||
'target_cell': command.get('target_cell', '')}
|
'target_cell': command.get('target_cell', '')}
|
||||||
if uid in rows and rows[uid] != row:
|
if key in rows and rows[key] != row:
|
||||||
raise ValueError('同一 UID 对应多个不同规则结果,不能独立核验')
|
raise ValueError('同一位号对应多个不同规则结果,不能独立核验')
|
||||||
rows[uid] = row
|
rows[key] = row
|
||||||
if not rows:
|
if not rows:
|
||||||
raise ValueError('已保存的规则替换缺少可核验的原生 UID 事务')
|
raise ValueError('已保存的规则替换缺少可核验的原生 UID 事务')
|
||||||
return list(rows.values()), scopes
|
return list(rows.values()), scopes
|
||||||
|
|
||||||
|
|
||||||
|
def _reference_keys(graph, identity):
|
||||||
|
ref = identity.get('refdes', '').strip().casefold()
|
||||||
|
keys = native_netlist.reference_targets(graph, ref, sheet=identity.get('sheet_number',''),
|
||||||
|
schematic=identity.get('schematic_name','')) if ref else ()
|
||||||
|
uid = identity.get('uid')
|
||||||
|
if not keys and uid in graph['components']:
|
||||||
|
component = graph['components'][uid]
|
||||||
|
constraints = ((ref, component.get('refdes','').strip().casefold()),
|
||||||
|
(identity.get('sheet_number',''), component.get('source_page','')),
|
||||||
|
(identity.get('schematic_name',''), component.get('source_schematic','')))
|
||||||
|
if not any(expected and actual and expected != actual for expected, actual in constraints):
|
||||||
|
keys = (uid,)
|
||||||
|
return keys
|
||||||
|
|
||||||
|
|
||||||
|
def _reference_plan(plan, before, library):
|
||||||
|
from copy import deepcopy
|
||||||
|
result, rebound = deepcopy(plan), {}
|
||||||
|
graph = before['graph']
|
||||||
|
rows, plan_keys = [], {}
|
||||||
|
for row in result['rows']:
|
||||||
|
target = row['target']
|
||||||
|
keys = _reference_keys(graph, target)
|
||||||
|
if not keys and row['enabled']:
|
||||||
|
raise ValueError('独立网表无法定位计划中的位号')
|
||||||
|
plan_keys[target['uid']] = keys
|
||||||
|
for key in keys:
|
||||||
|
item = deepcopy(row)
|
||||||
|
item['target']['uid'] = key
|
||||||
|
rows.append(item)
|
||||||
|
for uid, identity in library.items():
|
||||||
|
keys = _reference_keys(graph, dict(identity, uid=uid))
|
||||||
|
if not keys and not identity.get('refdes'):
|
||||||
|
keys = plan_keys.get(uid, ())
|
||||||
|
if not keys:
|
||||||
|
raise ValueError('独立网表无法定位回执中的位号或图页')
|
||||||
|
exact = tuple(key for key in keys if key == uid or graph['components'][key].get('source_uid') == uid)
|
||||||
|
for key in exact or keys:
|
||||||
|
if key in rebound and rebound[key] != identity:
|
||||||
|
raise ValueError('独立网表无法区分同一位号的原生单元回执')
|
||||||
|
rebound[key] = identity
|
||||||
|
result['rows'] = rows
|
||||||
|
return result, rebound
|
||||||
|
|
||||||
|
|
||||||
class NetlistVerification:
|
class NetlistVerification:
|
||||||
def __init__(self, root, run_id, stop_event):
|
def __init__(self, root, run_id, stop_event):
|
||||||
self.root, self.run_id, self.stop = Path(root), run_id, stop_event
|
self.root, self.run_id, self.stop = Path(root), run_id, stop_event
|
||||||
@@ -305,6 +370,18 @@ class NetlistVerification:
|
|||||||
return
|
return
|
||||||
try:
|
try:
|
||||||
record['library'] = _library_expectations(record['child'], task_id)
|
record['library'] = _library_expectations(record['child'], task_id)
|
||||||
|
preparer = getattr(record['child'], '_quick_run_preparer', None)
|
||||||
|
if preparer is not None:
|
||||||
|
from .saved_netlist_verification import load_saved_export
|
||||||
|
saved = load_saved_export(preparer.data_root / 'quick-run',
|
||||||
|
Path(record['before_capture']['project']))
|
||||||
|
if saved is not None:
|
||||||
|
exported = Future()
|
||||||
|
exported.set_result(saved['result'])
|
||||||
|
record.update(after_capture=saved['capture'],
|
||||||
|
after_export=Path(saved['export_path']).parent,
|
||||||
|
after=exported)
|
||||||
|
return
|
||||||
directory = record['directory']
|
directory = record['directory']
|
||||||
attempt = uuid4().hex
|
attempt = uuid4().hex
|
||||||
capture = native_netlist.capture_project(Path(record['before_capture']['project']),
|
capture = native_netlist.capture_project(Path(record['before_capture']['project']),
|
||||||
@@ -398,6 +475,7 @@ class NetlistVerification:
|
|||||||
rows, scopes = _rule_rows(record['child'], task_id, plan, before)
|
rows, scopes = _rule_rows(record['child'], task_id, plan, before)
|
||||||
plan = dict(plan, rows=rows)
|
plan = dict(plan, rows=rows)
|
||||||
result['rule_scopes'] = scopes
|
result['rule_scopes'] = scopes
|
||||||
|
plan, library = _reference_plan(plan, before, library)
|
||||||
expected = self._expected(plan, after, library)
|
expected = self._expected(plan, after, library)
|
||||||
symbols = {uid: {key: item[key] for key in ('target_symbol', 'slot_count')}
|
symbols = {uid: {key: item[key] for key in ('target_symbol', 'slot_count')}
|
||||||
for uid, item in library.items() if uid in expected}
|
for uid, item in library.items() if uid in expected}
|
||||||
|
|||||||
@@ -0,0 +1,64 @@
|
|||||||
|
"""Small append-only call timeline; diagnostics never replace an execution error."""
|
||||||
|
from datetime import datetime, timezone
|
||||||
|
from contextlib import contextmanager
|
||||||
|
import json
|
||||||
|
import os
|
||||||
|
|
||||||
|
from .path_access import internal_path
|
||||||
|
|
||||||
|
|
||||||
|
def record_operation(root, operation, event, *, item_id='', error=''):
|
||||||
|
if event not in {'enter', 'return', 'error'}:
|
||||||
|
raise ValueError('operation event must be enter, return or error')
|
||||||
|
try:
|
||||||
|
record = {'timestamp_utc': datetime.now(timezone.utc).isoformat(),
|
||||||
|
'operation': operation, 'event': event, 'item_id': item_id}
|
||||||
|
if error:
|
||||||
|
record['error'] = str(error)
|
||||||
|
line = json.dumps(record, ensure_ascii=False) + '\n'
|
||||||
|
path = internal_path(root) / 'operation-events.jsonl'
|
||||||
|
path.parent.mkdir(parents=True, exist_ok=True)
|
||||||
|
with path.open('a', encoding='utf-8') as stream:
|
||||||
|
stream.write(line)
|
||||||
|
stream.flush()
|
||||||
|
os.fsync(stream.fileno())
|
||||||
|
return True
|
||||||
|
except Exception:
|
||||||
|
return False
|
||||||
|
|
||||||
|
|
||||||
|
@contextmanager
|
||||||
|
def operation_span(root, operation, *, item_id=''):
|
||||||
|
"""Trace a real call without letting diagnostics change its outcome."""
|
||||||
|
def publish(event, error=''):
|
||||||
|
try:
|
||||||
|
record_operation(root, operation, event, item_id=item_id, error=error)
|
||||||
|
except Exception:
|
||||||
|
pass
|
||||||
|
publish('enter')
|
||||||
|
try:
|
||||||
|
yield
|
||||||
|
except BaseException as error:
|
||||||
|
publish('error', error)
|
||||||
|
raise
|
||||||
|
else:
|
||||||
|
publish('return')
|
||||||
|
|
||||||
|
|
||||||
|
def summarize_operations(records):
|
||||||
|
active, errors, last_item = {}, [], None
|
||||||
|
for record in records:
|
||||||
|
if not isinstance(record, dict) or not all(isinstance(record.get(name, ''), str)
|
||||||
|
for name in ('operation', 'item_id', 'event')):
|
||||||
|
continue
|
||||||
|
key = record.get('operation'), record.get('item_id', '')
|
||||||
|
if record.get('event') == 'enter':
|
||||||
|
active[key] = record
|
||||||
|
elif record.get('event') in {'return', 'error'}:
|
||||||
|
active.pop(key, None)
|
||||||
|
if record['event'] == 'error':
|
||||||
|
errors.append(record)
|
||||||
|
elif record.get('operation') == 'item' and record.get('item_id'):
|
||||||
|
last_item = record['item_id']
|
||||||
|
return {'last_successful_item': last_item, 'incomplete_operations': list(active.values()),
|
||||||
|
'errors': errors}
|
||||||
@@ -0,0 +1,167 @@
|
|||||||
|
"""Keep uncertain engineering sources quarantined without stopping unrelated work."""
|
||||||
|
from pathlib import Path
|
||||||
|
import json
|
||||||
|
import re
|
||||||
|
|
||||||
|
from .path_access import canonical_path, internal_path
|
||||||
|
|
||||||
|
|
||||||
|
def write_sources(project, *, strict=False):
|
||||||
|
project = canonical_path(project)
|
||||||
|
sources = {str(project).casefold()}
|
||||||
|
try:
|
||||||
|
from .native_inventory_protocol import read_native_text
|
||||||
|
text = read_native_text(internal_path(project))
|
||||||
|
if strict:
|
||||||
|
definitions = re.findall(r'^[ \t]*KEY[ \t]+iCDBDir\b([^\r\n]*)', text,
|
||||||
|
re.MULTILINE | re.IGNORECASE)
|
||||||
|
match = re.fullmatch(r'[ \t]+"([^"\r\n]+)"[ \t]*', definitions[0]) if len(definitions) == 1 else None
|
||||||
|
if not match:
|
||||||
|
raise ValueError('The iCDBDir write source must be declared once')
|
||||||
|
else:
|
||||||
|
match = re.search(r'^\s*KEY\s+iCDBDir\s+"([^"\r\n]+)"', text, re.MULTILINE | re.IGNORECASE)
|
||||||
|
if match:
|
||||||
|
directory = Path(match[1])
|
||||||
|
if not directory.is_absolute():
|
||||||
|
directory = project.parent / directory
|
||||||
|
sources.add(str(canonical_path(directory / 'icdb.dat')).casefold())
|
||||||
|
except (OSError, UnicodeError, ValueError):
|
||||||
|
if strict:
|
||||||
|
raise
|
||||||
|
return sources
|
||||||
|
|
||||||
|
|
||||||
|
def record_task_outcome(child, task_id, state, message):
|
||||||
|
store = getattr(child, '_store', None)
|
||||||
|
if store is None:
|
||||||
|
return
|
||||||
|
from .models import TaskStatus
|
||||||
|
target = {'blocked': TaskStatus.BLOCKED, 'failed': TaskStatus.FAILED, 'paused': TaskStatus.PAUSED}.get(state)
|
||||||
|
if target is None:
|
||||||
|
return # Successful completion is committed with its actual execution receipts.
|
||||||
|
with store.transaction():
|
||||||
|
task = store.get_task(task_id)
|
||||||
|
if task.status not in {TaskStatus.COMPLETED, TaskStatus.DELETED}:
|
||||||
|
store.set_task_status(task_id, target, summary=message)
|
||||||
|
|
||||||
|
|
||||||
|
def isolate_project(runtime, child, task_id, error):
|
||||||
|
release = getattr(runtime, 'release_failed_project', None)
|
||||||
|
if release is None:
|
||||||
|
return False
|
||||||
|
preparer = getattr(child, '_quick_run_preparer', None)
|
||||||
|
root = preparer.data_root / 'quick-run' if preparer is not None else runtime.root / 'tasks' / task_id / 'quick-run'
|
||||||
|
released = release(error, root)
|
||||||
|
return released
|
||||||
|
|
||||||
|
|
||||||
|
def dependency_path(root, task_id):
|
||||||
|
return canonical_path(root) / 'dependency-blocks' / (task_id + '.json')
|
||||||
|
|
||||||
|
|
||||||
|
def dependency_block(root, task_id):
|
||||||
|
from .errors import TaskCenterError
|
||||||
|
try:
|
||||||
|
value = json.loads(internal_path(dependency_path(root, task_id)).read_text(encoding='utf-8'))
|
||||||
|
if (not isinstance(value, dict) or value.get('version') != 1 or value.get('task_id') != task_id or value.get('undispatched') is not True
|
||||||
|
or value.get('state') not in {'blocked', 'readmission_prepared', 'readmitted'}
|
||||||
|
or not isinstance(value.get('dependency_task_id'), str)
|
||||||
|
or Path(value['dependency_task_id']).name != value['dependency_task_id']
|
||||||
|
or not isinstance(value.get('sources'), list) or not value['sources']
|
||||||
|
or not all(isinstance(source, str) and Path(source).is_absolute() for source in value['sources'])
|
||||||
|
or not isinstance(value.get('plan_hash'), str) or not re.fullmatch('[0-9a-f]{64}', value['plan_hash'])
|
||||||
|
or not isinstance(value.get('queue_id'), str) or not re.fullmatch('[0-9a-f]{32}', value['queue_id'])
|
||||||
|
or not isinstance(value.get('project_path'), str) or not Path(value['project_path']).is_absolute()):
|
||||||
|
raise ValueError('invalid dependency block')
|
||||||
|
return value
|
||||||
|
except FileNotFoundError:
|
||||||
|
return None
|
||||||
|
except (OSError, ValueError, TypeError) as error:
|
||||||
|
raise TaskCenterError('quick_run_dependency', '共享数据源隔离记录无法核验,请保留证据。') from error
|
||||||
|
|
||||||
|
|
||||||
|
def block_dependency(root, child, task_id, dependency_task_id, sources, plan_hash, queue_id):
|
||||||
|
from .batch_resources import write_record
|
||||||
|
projects = child.projects(task_id)
|
||||||
|
write_record(dependency_path(root, task_id), {'version': 1, 'task_id': task_id,
|
||||||
|
'dependency_task_id': dependency_task_id, 'sources': sorted(sources), 'plan_hash': plan_hash,
|
||||||
|
'project_path': str(canonical_path(projects[0].path)).casefold(),
|
||||||
|
'queue_id': queue_id, 'state': 'blocked', 'undispatched': True})
|
||||||
|
record_task_outcome(child, task_id, 'blocked', f'共享数据源依赖 {dependency_task_id} 尚待核验;本任务未派发替换。')
|
||||||
|
|
||||||
|
|
||||||
|
def _validate_dependency(service, task_id, block):
|
||||||
|
from .batch_resources import resource_blockers
|
||||||
|
from .errors import TaskCenterError
|
||||||
|
from .models import TaskStatus
|
||||||
|
from .task_queue import _plan_hash
|
||||||
|
child = service.for_project_task(task_id)
|
||||||
|
dependency = service.for_project_task(block['dependency_task_id'])
|
||||||
|
projects = child.projects(task_id)
|
||||||
|
dependency_projects = dependency.projects(block['dependency_task_id'])
|
||||||
|
queue_path = next((path for directory in ('task-queues', 'workspace-queues')
|
||||||
|
if internal_path(path := canonical_path(service._logging.root) / directory / (block['queue_id'] + '.json')).is_file()), None)
|
||||||
|
try:
|
||||||
|
queue = json.loads(internal_path(queue_path).read_text(encoding='utf-8')) if queue_path else {}
|
||||||
|
queue_bound = (queue['plan_hashes'][task_id] == block['plan_hash']
|
||||||
|
and queue['dependency_tasks'][task_id] == block['dependency_task_id']
|
||||||
|
and queue['entries'][task_id]['state'] == 'blocked')
|
||||||
|
except (OSError, ValueError, TypeError, KeyError):
|
||||||
|
queue_bound = False
|
||||||
|
store = getattr(child, '_store', None)
|
||||||
|
with store._lock:
|
||||||
|
dispatched = store._connection.execute('''SELECT 1 FROM execution_operations o
|
||||||
|
JOIN execution_rounds r ON r.task_id=o.task_id AND r.round_id=o.round_id
|
||||||
|
WHERE o.task_id=? AND (o.attempt_id IS NOT NULL OR o.generation>0 OR o.state!='pending') LIMIT 1''',
|
||||||
|
(task_id,)).fetchone()
|
||||||
|
evidence = child._quick_run_preparer.data_root / 'quick-run'
|
||||||
|
absent_attempt = not dispatched and not any(internal_path(evidence).glob('snapshot-*'))
|
||||||
|
if (len(projects) != 1 or len(dependency_projects) != 1
|
||||||
|
or not queue_bound or not absent_attempt
|
||||||
|
or str(canonical_path(projects[0].path)).casefold() != block['project_path']
|
||||||
|
or _plan_hash(child, task_id) != block['plan_hash']
|
||||||
|
or not set(block['sources']) <= write_sources(projects[0].path) & write_sources(dependency_projects[0].path)
|
||||||
|
or child.has_interrupted_quick_run(task_id)
|
||||||
|
or dependency.has_interrupted_quick_run(block['dependency_task_id'])
|
||||||
|
or dependency.get_task(block['dependency_task_id']).status not in {TaskStatus.READY, TaskStatus.COMPLETED}
|
||||||
|
or resource_blockers(service.pending_batch_resources())):
|
||||||
|
raise TaskCenterError('quick_run_dependency', '原依赖工程尚未核验、写入资源未退出或冻结计划已变化,不能解除隔离。')
|
||||||
|
|
||||||
|
|
||||||
|
def recover_dependency(service, task_id, *, confirmed):
|
||||||
|
from .batch_resources import write_record
|
||||||
|
from .errors import TaskCenterError
|
||||||
|
from .models import TaskStatus
|
||||||
|
from .quick_run_protocol import QuickRunStepResult
|
||||||
|
root = service._logging.root
|
||||||
|
block = dependency_block(root, task_id)
|
||||||
|
if not confirmed:
|
||||||
|
raise TaskCenterError('quick_run_dependency', '请确认核验共享数据源依赖后解除未派发任务的隔离。')
|
||||||
|
_validate_dependency(service, task_id, block)
|
||||||
|
path = dependency_path(root, task_id)
|
||||||
|
write_record(path, dict(block, state='readmission_prepared'))
|
||||||
|
with service._store.transaction():
|
||||||
|
task = service._store.get_task(task_id)
|
||||||
|
if task.status is TaskStatus.BLOCKED:
|
||||||
|
service._store.set_task_status(task_id, TaskStatus.READY, summary='共享数据源依赖已核验;原计划未派发,可重新确认执行。')
|
||||||
|
elif task.status not in {TaskStatus.READY, TaskStatus.COMPLETED}:
|
||||||
|
raise TaskCenterError('quick_run_dependency', '当前任务状态已变化,请重新读取隔离记录。')
|
||||||
|
write_record(path, dict(block, state='readmitted'))
|
||||||
|
child = service.for_project_task(task_id)
|
||||||
|
progress = child.quick_run_progress(task_id)
|
||||||
|
handoff = child._quick_run_preparer.data_root / 'quick-run'
|
||||||
|
return QuickRunStepResult(handoff / 'QuickPartReplace.vbs', handoff / 'command.tsv', handoff / 'status.tsv', path,
|
||||||
|
'pending', '共享数据源依赖已核验;本任务从未派发替换,已恢复原待执行计划。',
|
||||||
|
progress.next_project_path, progress.next_old_part_number, progress.next_new_part_number,
|
||||||
|
progress.next_schematic_name, progress.next_sheet_number, progress)
|
||||||
|
|
||||||
|
|
||||||
|
def dependency_readmitted(service, task_id, plan_hash):
|
||||||
|
from .models import TaskStatus
|
||||||
|
block = dependency_block(service._logging.root, task_id)
|
||||||
|
if not block or block['state'] not in {'readmission_prepared', 'readmitted'} or block['plan_hash'] != plan_hash:
|
||||||
|
return False
|
||||||
|
if service.get_task(task_id).status not in {TaskStatus.READY, TaskStatus.COMPLETED}:
|
||||||
|
return False
|
||||||
|
_validate_dependency(service, task_id, block)
|
||||||
|
return True
|
||||||
@@ -2,12 +2,14 @@
|
|||||||
from __future__ import annotations
|
from __future__ import annotations
|
||||||
|
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
|
import json
|
||||||
import subprocess
|
import subprocess
|
||||||
import time
|
import time
|
||||||
from threading import Event, Thread
|
from threading import Event, Thread
|
||||||
from uuid import uuid4
|
from uuid import uuid4
|
||||||
|
|
||||||
from .worker_monitor import WorkerMonitorError, run_monitored_process
|
from .worker_monitor import WorkerMonitorError, run_monitored_process
|
||||||
|
from .operation_diagnostics import operation_span
|
||||||
|
|
||||||
|
|
||||||
def _write_control(path: Path, value: str):
|
def _write_control(path: Path, value: str):
|
||||||
@@ -28,7 +30,7 @@ def _write_control(path: Path, value: str):
|
|||||||
|
|
||||||
|
|
||||||
class ProjectSessionWorker:
|
class ProjectSessionWorker:
|
||||||
"""Only a saved-and-reopened checkpoint releases the caller for its next step.
|
"""Retain applied steps; engineering close performs the save/readback commit.
|
||||||
|
|
||||||
The VBS worker owns CAD. This driver never attaches to COM or terminates CAD.
|
The VBS worker owns CAD. This driver never attaches to COM or terminates CAD.
|
||||||
A separate monitor thread retains the existing idle watchdog and worker job.
|
A separate monitor thread retains the existing idle watchdog and worker job.
|
||||||
@@ -61,6 +63,10 @@ class ProjectSessionWorker:
|
|||||||
self._done.set()
|
self._done.set()
|
||||||
|
|
||||||
def run_step(self, command: tuple[str, ...], timeout: float):
|
def run_step(self, command: tuple[str, ...], timeout: float):
|
||||||
|
with operation_span(self.root, 'native_step', item_id=command[-1]):
|
||||||
|
return self._run_step(command, timeout)
|
||||||
|
|
||||||
|
def _run_step(self, command: tuple[str, ...], timeout: float):
|
||||||
if self._closed:
|
if self._closed:
|
||||||
raise WorkerMonitorError('project session is already closed')
|
raise WorkerMonitorError('project session is already closed')
|
||||||
if Path(command[3]).resolve() != self.root.resolve():
|
if Path(command[3]).resolve() != self.root.resolve():
|
||||||
@@ -82,6 +88,7 @@ class ProjectSessionWorker:
|
|||||||
if not self._waiting:
|
if not self._waiting:
|
||||||
raise WorkerMonitorError('project session has no verified checkpoint')
|
raise WorkerMonitorError('project session has no verified checkpoint')
|
||||||
self._waiting = False
|
self._waiting = False
|
||||||
|
_write_control(self.root / 'project-session.request', f'{self.token}\t{self.project}\t{job}')
|
||||||
_write_control(self.root / 'project-session-next.tsv', f'{self.token}\t{job}')
|
_write_control(self.root / 'project-session-next.tsv', f'{self.token}\t{job}')
|
||||||
while True:
|
while True:
|
||||||
if self._done.is_set():
|
if self._done.is_set():
|
||||||
@@ -92,8 +99,8 @@ class ProjectSessionWorker:
|
|||||||
raise self._error
|
raise self._error
|
||||||
if self._result.returncode == 0:
|
if self._result.returncode == 0:
|
||||||
raise WorkerMonitorError('project session exited before authorized closing')
|
raise WorkerMonitorError('project session exited before authorized closing')
|
||||||
if self._result.returncode == 74:
|
if self._result.returncode in {74, 75}:
|
||||||
pause = getattr(self._result, 'startup_pause', {})
|
pause = getattr(self._result, 'startup_pause' if self._result.returncode == 74 else 'prewrite_pause', {})
|
||||||
if (pause.get('session_token') != self.token or pause.get('job_id') != job
|
if (pause.get('session_token') != self.token or pause.get('job_id') != job
|
||||||
or Path(pause.get('project_path', '')).resolve() != self.project.resolve()
|
or Path(pause.get('project_path', '')).resolve() != self.project.resolve()
|
||||||
or pause.get('worker_tree_exited') is not True):
|
or pause.get('worker_tree_exited') is not True):
|
||||||
@@ -110,13 +117,20 @@ class ProjectSessionWorker:
|
|||||||
except (FileNotFoundError, PermissionError):
|
except (FileNotFoundError, PermissionError):
|
||||||
fields = ()
|
fields = ()
|
||||||
if len(fields) == 4 and fields[:2] == [self.token, job]:
|
if len(fields) == 4 and fields[:2] == [self.token, job]:
|
||||||
if fields[2] not in {'saved_ok', 'no_match'} or fields[3] != 'session_verified':
|
if (fields[2], fields[3]) not in {('saved_ok', 'session_verified'), ('no_match', 'session_verified'),
|
||||||
|
('pending_save', 'session_staged'), ('pending_save', 'session_staged_no_match')}:
|
||||||
raise WorkerMonitorError('project session returned an invalid checkpoint')
|
raise WorkerMonitorError('project session returned an invalid checkpoint')
|
||||||
self._waiting = True
|
self._waiting = True
|
||||||
return subprocess.CompletedProcess(command, 0, '', '')
|
return subprocess.CompletedProcess(command, 0, '', '')
|
||||||
self._done.wait(0.025)
|
self._done.wait(0.025)
|
||||||
|
|
||||||
def close(self):
|
def close(self):
|
||||||
|
if not self._closed and self._thread is not None and not self._done.is_set():
|
||||||
|
with operation_span(self.root, 'close_project', item_id=self.token):
|
||||||
|
return self._close()
|
||||||
|
return self._close()
|
||||||
|
|
||||||
|
def _close(self):
|
||||||
if self._closed:
|
if self._closed:
|
||||||
return
|
return
|
||||||
try:
|
try:
|
||||||
@@ -128,25 +142,33 @@ class ProjectSessionWorker:
|
|||||||
from .stop_control import StopControl
|
from .stop_control import StopControl
|
||||||
interactive = isinstance(getattr(self.runtime, 'stop_event', None), StopControl)
|
interactive = isinstance(getattr(self.runtime, 'stop_event', None), StopControl)
|
||||||
close_grace = 60 if self.private_desktop else min(30, max(10, self._timeout))
|
close_grace = 60 if self.private_desktop else min(30, max(10, self._timeout))
|
||||||
if interactive:
|
force_event = getattr(getattr(self.runtime, 'stop_event', None), 'force_event', None)
|
||||||
# A failed close has its own deadline, separate from pause.
|
last_notice = time.monotonic()
|
||||||
force_event = getattr(getattr(self.runtime, 'stop_event', None), 'force_event', None)
|
deadline = last_notice + close_grace
|
||||||
last_notice = time.monotonic()
|
last_progress = (-1, -1)
|
||||||
deadline = last_notice + close_grace
|
while not self._done.wait(.1):
|
||||||
while not self._done.wait(.1):
|
if force_event is not None and force_event.is_set():
|
||||||
if force_event is not None and force_event.is_set():
|
self._abort.set()
|
||||||
self._abort.set()
|
break
|
||||||
break
|
try:
|
||||||
if time.monotonic() >= deadline:
|
native = json.loads((self.root / 'worker-progress.json').read_text(encoding='utf-8'))
|
||||||
|
progress = (native['sequence'], native.get('native_progress_frames', 0))
|
||||||
|
if all(type(value) is int for value in progress) and progress > last_progress:
|
||||||
|
last_progress = progress
|
||||||
|
deadline = time.monotonic() + close_grace
|
||||||
|
except (OSError, ValueError, KeyError, TypeError):
|
||||||
|
pass
|
||||||
|
if time.monotonic() >= deadline:
|
||||||
|
if interactive:
|
||||||
self.runtime.stop_event.request_failure_cleanup(self.root,
|
self.runtime.stop_event.request_failure_cleanup(self.root,
|
||||||
'project session did not acknowledge closing within its grace period')
|
'project session did not acknowledge closing within its grace period')
|
||||||
self._abort.set()
|
self._abort.set()
|
||||||
break
|
break
|
||||||
if time.monotonic() - last_notice >= 15:
|
if time.monotonic() - last_notice >= 15:
|
||||||
import logging
|
import logging
|
||||||
logging.getLogger(__name__).warning(
|
logging.getLogger(__name__).warning(
|
||||||
'project_session_awaiting_close token=%s', self.token)
|
'project_session_awaiting_close token=%s', self.token)
|
||||||
last_notice = time.monotonic()
|
last_notice = time.monotonic()
|
||||||
if not self._done.wait(close_grace):
|
if not self._done.wait(close_grace):
|
||||||
self._abort.set()
|
self._abort.set()
|
||||||
if not self._done.wait(30):
|
if not self._done.wait(30):
|
||||||
@@ -174,6 +196,7 @@ class ProjectSessionScope:
|
|||||||
self.worker = None
|
self.worker = None
|
||||||
self.private_desktop = private_desktop
|
self.private_desktop = private_desktop
|
||||||
self.runtime = runtime
|
self.runtime = runtime
|
||||||
|
self.on_commit = None
|
||||||
|
|
||||||
def __enter__(self):
|
def __enter__(self):
|
||||||
return self
|
return self
|
||||||
@@ -189,13 +212,25 @@ class ProjectSessionScope:
|
|||||||
def prepare(self, project):
|
def prepare(self, project):
|
||||||
if self.worker is not None and (self.worker.project.resolve() != Path(project).resolve()
|
if self.worker is not None and (self.worker.project.resolve() != Path(project).resolve()
|
||||||
or self.worker._done.is_set()):
|
or self.worker._done.is_set()):
|
||||||
self.worker.close()
|
self.close()
|
||||||
self.worker = None
|
|
||||||
|
def close(self):
|
||||||
|
if self.worker is None:return
|
||||||
|
worker = self.worker
|
||||||
|
worker.close()
|
||||||
|
if self.on_commit is not None:
|
||||||
|
self.on_commit(worker)
|
||||||
|
self.on_commit = None
|
||||||
|
self.worker = None
|
||||||
|
|
||||||
def __exit__(self, error_type, error, traceback):
|
def __exit__(self, error_type, error, traceback):
|
||||||
if self.worker is not None:
|
if self.worker is not None:
|
||||||
try:
|
try:
|
||||||
self.worker.close()
|
self.close()
|
||||||
except Exception:
|
except Exception as cleanup_error:
|
||||||
self.worker._abort.set()
|
self.worker._abort.set()
|
||||||
|
if error is not None:
|
||||||
|
if hasattr(error, 'add_note'):
|
||||||
|
error.add_note('Project session cleanup: ' + str(cleanup_error))
|
||||||
|
return False
|
||||||
raise
|
raise
|
||||||
@@ -3,6 +3,7 @@
|
|||||||
from __future__ import annotations
|
from __future__ import annotations
|
||||||
|
|
||||||
from collections.abc import Callable
|
from collections.abc import Callable
|
||||||
|
from contextlib import contextmanager
|
||||||
from threading import Event
|
from threading import Event
|
||||||
|
|
||||||
import os
|
import os
|
||||||
@@ -10,20 +11,44 @@ from pathlib import Path
|
|||||||
import stat
|
import stat
|
||||||
from uuid import uuid4
|
from uuid import uuid4
|
||||||
|
|
||||||
from .errors import TaskCenterError
|
from .errors import ProjectPathError, TaskCenterError
|
||||||
from .path_access import canonical_path, internal_path, strip_extended_prefix
|
from .path_access import canonical_path, internal_path, strip_extended_prefix
|
||||||
from .models import TaskRecord, TaskStatus
|
from .models import TaskRecord, TaskStatus
|
||||||
from .scanner import _is_schematic_project, _reject_reparse
|
from .scanner import _is_schematic_project, _reject_reparse
|
||||||
from .store import TaskStore
|
from .store import TaskStore
|
||||||
|
|
||||||
|
|
||||||
|
@contextmanager
|
||||||
|
def _path_errors(path: Path):
|
||||||
|
try:
|
||||||
|
yield
|
||||||
|
except FileNotFoundError as error:
|
||||||
|
raise ProjectPathError(
|
||||||
|
"path_missing", f"找不到路径「{path}」。请确认目录或工程是否已移动或删除,然后重新选择并读取。"
|
||||||
|
) from error
|
||||||
|
except PermissionError as error:
|
||||||
|
raise ProjectPathError(
|
||||||
|
"path_denied", f"无法读取路径「{path}」。请检查当前用户的读取权限,然后重试。"
|
||||||
|
) from error
|
||||||
|
except NotADirectoryError as error:
|
||||||
|
raise _not_directory(path) from error
|
||||||
|
|
||||||
|
|
||||||
|
def _not_directory(path: Path) -> ProjectPathError:
|
||||||
|
return ProjectPathError(
|
||||||
|
"path_not_directory", f"路径「{path}」中有一项不是目录。请选择工程目录后重试。"
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
def _validated_root(root: Path, excluded_roots: tuple[Path, ...]) -> tuple[Path, tuple[Path, ...]]:
|
def _validated_root(root: Path, excluded_roots: tuple[Path, ...]) -> tuple[Path, tuple[Path, ...]]:
|
||||||
root = Path(os.path.abspath(strip_extended_prefix(root)))
|
root = Path(os.path.abspath(strip_extended_prefix(root)))
|
||||||
for ancestor in (*reversed(root.parents), root):
|
with _path_errors(root):
|
||||||
_reject_reparse(internal_path(ancestor).lstat(), ancestor)
|
for ancestor in (*reversed(root.parents), root):
|
||||||
root = canonical_path(root, strict=True)
|
details = internal_path(ancestor).lstat()
|
||||||
if not internal_path(root).is_dir():
|
_reject_reparse(details, ancestor)
|
||||||
raise TaskCenterError("discovery_root", "project root is not a directory")
|
if not stat.S_ISDIR(details.st_mode):
|
||||||
|
raise _not_directory(root)
|
||||||
|
root = canonical_path(root, strict=True)
|
||||||
excluded = tuple(canonical_path(path) for path in excluded_roots)
|
excluded = tuple(canonical_path(path) for path in excluded_roots)
|
||||||
if any(root.is_relative_to(blocked) for blocked in excluded):
|
if any(root.is_relative_to(blocked) for blocked in excluded):
|
||||||
raise TaskCenterError("discovery_root", "project root is inside an excluded directory")
|
raise TaskCenterError("discovery_root", "project root is inside an excluded directory")
|
||||||
@@ -50,12 +75,13 @@ def scan_project_directory(root: Path, *, excluded_roots: tuple[Path, ...] = (),
|
|||||||
while pending:
|
while pending:
|
||||||
check_cancelled()
|
check_cancelled()
|
||||||
directory = pending.pop()
|
directory = pending.pop()
|
||||||
_reject_reparse(internal_path(directory).lstat(), directory)
|
|
||||||
children = []
|
children = []
|
||||||
with os.scandir(internal_path(directory)) as entries:
|
with _path_errors(directory):
|
||||||
for entry in entries:
|
_reject_reparse(internal_path(directory).lstat(), directory)
|
||||||
check_cancelled()
|
with os.scandir(internal_path(directory)) as entries:
|
||||||
children.append(entry)
|
for entry in entries:
|
||||||
|
check_cancelled()
|
||||||
|
children.append(entry)
|
||||||
projects: list[Path] = []
|
projects: list[Path] = []
|
||||||
folders: list[Path] = []
|
folders: list[Path] = []
|
||||||
for entry in sorted(children, key=lambda item: item.name.casefold()):
|
for entry in sorted(children, key=lambda item: item.name.casefold()):
|
||||||
@@ -63,12 +89,13 @@ def scan_project_directory(root: Path, *, excluded_roots: tuple[Path, ...] = (),
|
|||||||
path = Path(strip_extended_prefix(entry.path))
|
path = Path(strip_extended_prefix(entry.path))
|
||||||
if any(path.is_relative_to(blocked) for blocked in excluded):
|
if any(path.is_relative_to(blocked) for blocked in excluded):
|
||||||
continue
|
continue
|
||||||
details = entry.stat(follow_symlinks=False)
|
with _path_errors(path):
|
||||||
_reject_reparse(details, path)
|
details = entry.stat(follow_symlinks=False)
|
||||||
if stat.S_ISDIR(details.st_mode):
|
_reject_reparse(details, path)
|
||||||
folders.append(path)
|
if stat.S_ISDIR(details.st_mode):
|
||||||
elif stat.S_ISREG(details.st_mode) and path.suffix.casefold() == ".prj" and _is_schematic_project(path):
|
folders.append(path)
|
||||||
projects.append(canonical_path(path, strict=True))
|
elif stat.S_ISREG(details.st_mode) and path.suffix.casefold() == ".prj" and _is_schematic_project(path):
|
||||||
|
projects.append(canonical_path(path, strict=True))
|
||||||
found.extend(projects)
|
found.extend(projects)
|
||||||
visited += 1
|
visited += 1
|
||||||
if on_progress is not None:
|
if on_progress is not None:
|
||||||
@@ -84,35 +111,41 @@ def _validate_selected(root: Path, selected_paths: tuple[Path, ...], excluded: t
|
|||||||
ancestor_projects: dict[Path, bool] = {}
|
ancestor_projects: dict[Path, bool] = {}
|
||||||
for candidate in selected_paths:
|
for candidate in selected_paths:
|
||||||
path = Path(os.path.abspath(strip_extended_prefix(candidate)))
|
path = Path(os.path.abspath(strip_extended_prefix(candidate)))
|
||||||
if not path.is_relative_to(root) or any(path.is_relative_to(blocked) for blocked in excluded):
|
if path == root or not path.is_relative_to(root) or any(path.is_relative_to(blocked) for blocked in excluded):
|
||||||
raise TaskCenterError("project_selection", "selected project is outside discovery results")
|
raise TaskCenterError("project_selection", "selected project is outside discovery results")
|
||||||
relative = path.relative_to(root)
|
relative = path.relative_to(root)
|
||||||
cursor = root
|
cursor = root
|
||||||
for part in relative.parts:
|
with _path_errors(path):
|
||||||
cursor /= part
|
for part in relative.parts:
|
||||||
_reject_reparse(internal_path(cursor).lstat(), cursor)
|
cursor /= part
|
||||||
if not internal_path(path).is_file() or path.suffix.casefold() != ".prj" or not _is_schematic_project(path):
|
details = internal_path(cursor).lstat()
|
||||||
raise TaskCenterError("project_selection", "selected file is not a schematic project")
|
_reject_reparse(details, cursor)
|
||||||
|
if cursor != path and not stat.S_ISDIR(details.st_mode):
|
||||||
|
raise _not_directory(path)
|
||||||
|
if not stat.S_ISREG(details.st_mode) or path.suffix.casefold() != ".prj" or not _is_schematic_project(path):
|
||||||
|
raise TaskCenterError("project_selection", "selected file is not a schematic project")
|
||||||
# A project in any ancestor directory stops discovery below that directory.
|
# A project in any ancestor directory stops discovery below that directory.
|
||||||
directory = path.parent
|
directory = path.parent
|
||||||
while directory != root:
|
while directory != root:
|
||||||
directory = directory.parent
|
directory = directory.parent
|
||||||
if directory not in ancestor_projects:
|
if directory not in ancestor_projects:
|
||||||
has_project = False
|
has_project = False
|
||||||
with os.scandir(internal_path(directory)) as entries:
|
with _path_errors(directory), os.scandir(internal_path(directory)) as entries:
|
||||||
for entry in entries:
|
for entry in entries:
|
||||||
sibling = Path(strip_extended_prefix(entry.path))
|
sibling = Path(strip_extended_prefix(entry.path))
|
||||||
if sibling.suffix.casefold() != ".prj" or any(sibling.is_relative_to(b) for b in excluded):
|
if sibling.suffix.casefold() != ".prj" or any(sibling.is_relative_to(b) for b in excluded):
|
||||||
continue
|
continue
|
||||||
details = entry.stat(follow_symlinks=False)
|
with _path_errors(sibling):
|
||||||
_reject_reparse(details, sibling)
|
details = entry.stat(follow_symlinks=False)
|
||||||
if stat.S_ISREG(details.st_mode) and _is_schematic_project(sibling):
|
_reject_reparse(details, sibling)
|
||||||
has_project = True
|
if stat.S_ISREG(details.st_mode) and _is_schematic_project(sibling):
|
||||||
break
|
has_project = True
|
||||||
|
break
|
||||||
ancestor_projects[directory] = has_project
|
ancestor_projects[directory] = has_project
|
||||||
if ancestor_projects[directory]:
|
if ancestor_projects[directory]:
|
||||||
raise TaskCenterError("project_selection", "selected project is hidden by an ancestor project")
|
raise TaskCenterError("project_selection", "selected project is hidden by an ancestor project")
|
||||||
selected.add(canonical_path(path, strict=True))
|
with _path_errors(path):
|
||||||
|
selected.add(canonical_path(path, strict=True))
|
||||||
return tuple(sorted(selected, key=lambda path: str(path).casefold()))
|
return tuple(sorted(selected, key=lambda path: str(path).casefold()))
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -373,24 +373,289 @@ class QuickRunPreparer:
|
|||||||
if journal is None or not journal.needs_reconciliation(task_id):
|
if journal is None or not journal.needs_reconciliation(task_id):
|
||||||
return
|
return
|
||||||
root = self._data_root/'quick-run'
|
root = self._data_root/'quick-run'
|
||||||
|
flag = root/'uncertain.flag'
|
||||||
|
if _io_path(flag).exists():
|
||||||
|
raise TaskCenterError('quick_run_uncertain', '工程已保留待核验保护,请先核验原执行证据。')
|
||||||
from .handoff_guard import assert_handoff_intact
|
from .handoff_guard import assert_handoff_intact
|
||||||
assert_handoff_intact(root, task_id)
|
assert_handoff_intact(root, task_id)
|
||||||
try:
|
try:
|
||||||
|
self._commit_staged_project(task_id)
|
||||||
self._bind_journal_handoff(task_id, QuickRunResult(root/'QuickPartReplace.vbs',
|
self._bind_journal_handoff(task_id, QuickRunResult(root/'QuickPartReplace.vbs',
|
||||||
root/'command.tsv', root/'status.tsv', root/'quick-part-replace.log', self.vbs_root_compatible))
|
root/'command.tsv', root/'status.tsv', root/'quick-part-replace.log', self.vbs_root_compatible))
|
||||||
except TaskCenterError:
|
except (OSError, ValueError, KeyError, TypeError) as error:
|
||||||
_write_uncertain_flag(root/'uncertain.flag','uncommitted_receipt_requires_verification')
|
_write_uncertain_flag(flag, 'uncommitted_receipt_requires_verification')
|
||||||
raise
|
if isinstance(error, TaskCenterError):
|
||||||
|
raise
|
||||||
|
raise TaskCenterError('quick_run_uncertain', '无法核验原工程提交回执;请保留执行证据。') from error
|
||||||
|
|
||||||
def result_proof(self, root, row, outcome, *, persist=True):
|
def result_proof(self, root, row, outcome, *, persist=True, project_commit=None):
|
||||||
from .execution_proof import capture_result
|
from .execution_proof import capture_result
|
||||||
return capture_result(self._data_root,root,row,outcome,
|
return capture_result(self._data_root,root,row,outcome,
|
||||||
strict=self._process_runner is _run_process,persist=persist)
|
strict=self._process_runner is _run_process,persist=persist,project_commit=project_commit)
|
||||||
|
|
||||||
|
def _commit_staged_project(self, task_id, *, session_token=None, bind_source=False):
|
||||||
|
journal = getattr(self, 'journal', None)
|
||||||
|
if journal is None:return
|
||||||
|
from .execution_proof import capture_project_commit, validate_project_commit_source
|
||||||
|
from .operation_diagnostics import record_operation
|
||||||
|
for commit in journal.pending_project_commits(task_id):
|
||||||
|
if session_token is not None and commit['session_token'] != session_token:continue
|
||||||
|
root = Path(commit['evidence_root'])
|
||||||
|
record_operation(root, 'readback_proof', 'enter', item_id=commit['session_token'])
|
||||||
|
try:
|
||||||
|
marker = capture_project_commit(self._data_root, root, commit)
|
||||||
|
saved_protocol = marker.get('validation_required') == 'saved_netlist_v1'
|
||||||
|
persisted = json.loads(commit['proof_json']) if commit.get('proof_json') else None
|
||||||
|
commit_proof = dict(persisted or marker)
|
||||||
|
if persisted:
|
||||||
|
if ((saved_protocol or commit_proof.get('saved_sources'))
|
||||||
|
and not validate_project_commit_source(commit_proof, root)
|
||||||
|
or marker['files'][0]['sha256'] != commit_proof['files'][0]['sha256']):
|
||||||
|
raise ValueError('saved project proof changed before receipt commit')
|
||||||
|
elif saved_protocol and not bind_source:
|
||||||
|
commit_proof, _ = self._closed_project_commit_proof(root, commit)
|
||||||
|
if (not validate_project_commit_source(commit_proof, root)
|
||||||
|
or marker['files'][0]['sha256'] != commit_proof['files'][0]['sha256']
|
||||||
|
or commit_proof.get('native_outcomes') != marker['native_outcomes']):
|
||||||
|
raise ValueError('saved project proof changed after native closure')
|
||||||
|
elif bind_source:
|
||||||
|
if _io_path(root/'uncertain.flag').exists():
|
||||||
|
raise TaskCenterError('quick_run_uncertain', '工程已保留待核验保护,不能重新绑定保存源。')
|
||||||
|
from .execution_proof import bind_project_commit_source
|
||||||
|
commit_proof = bind_project_commit_source(commit_proof, self._data_root, root, commit['project_path'])
|
||||||
|
attempts = journal.project_commit_attempts(task_id, commit['session_token'])
|
||||||
|
if commit_proof.get('operation_attempts', attempts) != attempts:
|
||||||
|
raise ValueError('original project attempts changed')
|
||||||
|
commit_proof['operation_attempts'] = attempts
|
||||||
|
staged = journal.staged_project_rows(task_id, commit['session_token'])
|
||||||
|
if saved_protocol:
|
||||||
|
from .saved_netlist_verification import verify_saved_project
|
||||||
|
for receipt in staged:
|
||||||
|
for item in receipt['proof'].get('files', ()):
|
||||||
|
name = Path(item['path']).name
|
||||||
|
if hashlib.sha256(_io_path(root/name).read_bytes()).hexdigest() != item['sha256']:
|
||||||
|
raise ValueError('staged native target evidence changed before saved export')
|
||||||
|
if bind_source and not persisted:
|
||||||
|
names = [name for job, state in commit_proof['native_outcomes'].items() if state == 'pending_save'
|
||||||
|
for name in (f'snapshot-{job}.tsv', f'snapshot-{job}.tsv.native.json', f'writer-expectations-{job}.tsv')]
|
||||||
|
commit_proof['readback_files'] = {name:hashlib.sha256(_io_path(root/name).read_bytes()).hexdigest() for name in names}
|
||||||
|
journal.bind_project_commit_proof(task_id, commit['session_token'], commit_proof)
|
||||||
|
before_validation = persisted or commit_proof
|
||||||
|
commit_proof = verify_saved_project(self._data_root, root, commit_proof, [receipt['row'] for receipt in staged])
|
||||||
|
journal.promote_project_commit_proof(task_id, commit['session_token'], before_validation, commit_proof)
|
||||||
|
proofs = {}
|
||||||
|
for receipt in staged:
|
||||||
|
row = receipt['row']
|
||||||
|
outcome = (commit_proof['outcomes'][row['job_id']], 'project_committed',
|
||||||
|
'工程统一保存,原生数据核验通过。' if saved_protocol else '工程保存回读校验通过。')
|
||||||
|
proof = self.result_proof(root, row, outcome, project_commit=commit_proof) if saved_protocol else self.result_proof(root,row,outcome)
|
||||||
|
if outcome[0] == 'saved_ok':
|
||||||
|
from .value_readback import capture_value_readback
|
||||||
|
proof['value_readback'] = capture_value_readback(root, row, outcome, project_commit=commit_proof)
|
||||||
|
proofs[row['job_id']] = proof
|
||||||
|
if bind_source and not commit.get('proof_json') and not saved_protocol:
|
||||||
|
commit_proof['readback_files'] = {Path(item['path']).name: item['sha256']
|
||||||
|
for proof in proofs.values() for item in proof.get('files', ())}
|
||||||
|
for job, outcome in commit_proof['outcomes'].items():
|
||||||
|
if outcome == 'saved_ok':
|
||||||
|
value_path = _io_path(root / f'value-readback-{job}.tsv')
|
||||||
|
if value_path.is_file():commit_proof['readback_files'][value_path.name] = hashlib.sha256(value_path.read_bytes()).hexdigest()
|
||||||
|
journal.bind_project_commit_proof(task_id, commit['session_token'], commit_proof)
|
||||||
|
statuses = journal.commit_project_results(task_id, commit['session_token'], proofs, commit_proof)
|
||||||
|
if saved_protocol and statuses:
|
||||||
|
_append_status_details(root/'status.tsv', statuses)
|
||||||
|
record_operation(root, 'readback_proof', 'return', item_id=commit['session_token'])
|
||||||
|
for job in commit_proof['jobs']:
|
||||||
|
record_operation(root, 'item', 'return', item_id=job)
|
||||||
|
except Exception as error:
|
||||||
|
record_operation(root, 'readback_proof', 'error', item_id=commit['session_token'], error=str(error))
|
||||||
|
raise
|
||||||
|
|
||||||
|
def _closed_project_commit_proof(self, root, commit):
|
||||||
|
from .batch_resources import _valid_record
|
||||||
|
|
||||||
|
checkpoint = json.loads(_io_path(root / 'project-checkpoint.json').read_text(encoding='utf-8'))
|
||||||
|
owner_path = Path(checkpoint['resource_record'])
|
||||||
|
owner = json.loads(_io_path(owner_path).read_text(encoding='utf-8'))
|
||||||
|
proof = checkpoint['project_commit_source']
|
||||||
|
native = {key: checkpoint[key] for key in ('session_id', 'generation', 'attempt_id')}
|
||||||
|
if (not _valid_record(owner, owner_path) or checkpoint.get('worker_closed') is not True
|
||||||
|
or checkpoint.get('project_closed') is not True
|
||||||
|
or Path(checkpoint['evidence_root']).resolve() != root.resolve()
|
||||||
|
or _path_key(checkpoint['project_path']) != _path_key(commit['project_path'])
|
||||||
|
or owner['session_id'] != native['session_id'] or owner['generation'] != native['generation']
|
||||||
|
or owner['checkpoints'].get(str(root.resolve()).casefold()) != native['attempt_id']
|
||||||
|
or proof.get('native_attempt') != native or proof.get('session_token') != commit['session_token']
|
||||||
|
or proof.get('jobs') != json.loads(commit['jobs_json'])):
|
||||||
|
raise ValueError('native close checkpoint is not bound to this project commit')
|
||||||
|
return proof, owner_path
|
||||||
|
|
||||||
|
def recover_project_commit(self, task_id, *, confirmed=False):
|
||||||
|
"""Reconcile an already closed/saved project without acquiring CAD."""
|
||||||
|
journal = getattr(self, 'journal', None)
|
||||||
|
if journal is None:return None
|
||||||
|
commits = journal.project_commit_records(task_id)
|
||||||
|
root = self._data_root / 'quick-run'
|
||||||
|
flag = _io_path(root / 'uncertain.flag')
|
||||||
|
audit = root / 'project-commit-recovery.json'
|
||||||
|
if not commits:return None
|
||||||
|
protection = flag.read_bytes() if flag.is_file() else None
|
||||||
|
allowed = {f'reason={reason}; manual reconciliation required\n'.encode() for reason in
|
||||||
|
('receipt_commit_failed', 'project_commit_unverified', 'uncommitted_receipt_requires_verification')}
|
||||||
|
interrupted = None
|
||||||
|
if protection is not None:
|
||||||
|
import re
|
||||||
|
match = re.fullmatch(rb'reason=supervisor_interrupted; batch=([0-9a-f]{32}); manual reconciliation required\r?\n', protection)
|
||||||
|
if match:interrupted = match[1].decode('ascii')
|
||||||
|
if protection is None:
|
||||||
|
try:
|
||||||
|
completed = json.loads(_io_path(audit).read_text(encoding='utf-8'))
|
||||||
|
if (completed.get('task_id') != task_id or completed.get('native_replacement_called') is not False
|
||||||
|
or completed.get('session_tokens') != [commit['session_token'] for commit in commits]):return None
|
||||||
|
except (OSError, ValueError, TypeError):return None
|
||||||
|
elif protection not in allowed and interrupted is None:return None
|
||||||
|
if not confirmed:
|
||||||
|
raise TaskCenterError('quick_run_recovery_confirmation', '工程提交回执核验需要明确确认。')
|
||||||
|
from .execution_proof import capture_project_commit, validate_project_commit_source, proof_intact
|
||||||
|
from .execution_journal import read_command_rows, command_identity, _hash
|
||||||
|
from .batch_resources import write_record
|
||||||
|
try:
|
||||||
|
rows = read_command_rows(root / 'command.tsv')
|
||||||
|
if not rows or any(row['task_id'] != task_id for row in rows):raise ValueError('foreign command plan')
|
||||||
|
current = journal._round(task_id)
|
||||||
|
if json.loads(current['plan_json']) != [_hash(command_identity(row)) for row in rows]:
|
||||||
|
raise ValueError('frozen command plan changed')
|
||||||
|
positions = {row['job_id']:index for index,row in enumerate(rows)}
|
||||||
|
markers = {commit['session_token']:capture_project_commit(self._data_root,root,commit) for commit in commits}
|
||||||
|
ends = {token:max(positions[job] for job in marker['jobs']) for token,marker in markers.items()}
|
||||||
|
latest = {}
|
||||||
|
for commit in commits:
|
||||||
|
token = commit['session_token']
|
||||||
|
if markers[token].get('validation_required') == 'saved_netlist_v1':
|
||||||
|
latest[commit['project_path']] = max(latest.get(commit['project_path'],-1),ends[token])
|
||||||
|
historical = set()
|
||||||
|
def historical_intact(proof):
|
||||||
|
saved = proof['saved_netlist']
|
||||||
|
verified = json.loads(_io_path(saved['verification_path']).read_text(encoding='utf-8'))
|
||||||
|
context = {key:proof[key] for key in ('session_token','project_path','saved_sources','command_sha256')}
|
||||||
|
context['marker_sha256'] = proof['files'][0]['sha256']
|
||||||
|
return (proof_intact(proof) and saved.get('status') == 'verified'
|
||||||
|
and proof['command_sha256'] == hashlib.sha256(_io_path(root/'command.tsv').read_bytes()).hexdigest()
|
||||||
|
and hashlib.sha256(_io_path(saved['verification_path']).read_bytes()).hexdigest() == saved['verification_sha256']
|
||||||
|
and hashlib.sha256(_io_path(saved['export_path']).read_bytes()).hexdigest() == saved['export_sha256']
|
||||||
|
and verified.get('status') == 'verified' and verified.get('context') == context
|
||||||
|
and verified.get('export_path') == saved['export_path'] and verified.get('export_sha256') == saved['export_sha256']
|
||||||
|
and verified.get('jobs') == saved.get('jobs') and set(saved['jobs']) == set(proof['jobs'])
|
||||||
|
and proof['outcomes'] == {job:'saved_ok' if state == 'pending_save' else state
|
||||||
|
for job,state in proof['native_outcomes'].items()})
|
||||||
|
covered = set()
|
||||||
|
covered_attempts = []
|
||||||
|
for commit in commits:
|
||||||
|
if Path(commit['evidence_root']).resolve() != root.resolve():raise ValueError('foreign commit root')
|
||||||
|
proof = json.loads(commit['proof_json'] or '{}')
|
||||||
|
prior = (commit['state'] == 'verified' and proof.get('validation_required') == 'saved_netlist_v1'
|
||||||
|
and ends[commit['session_token']] < latest.get(commit['project_path'],-1))
|
||||||
|
if prior:historical.add(commit['session_token'])
|
||||||
|
if proof:
|
||||||
|
attempts = journal.project_commit_attempts(task_id, commit['session_token'], require_recorded=True)
|
||||||
|
if (proof.get('operation_attempts', attempts) != attempts
|
||||||
|
or set(attempts) != set(proof['jobs'])):
|
||||||
|
raise ValueError('original project attempts changed')
|
||||||
|
proof.setdefault('operation_attempts', attempts)
|
||||||
|
if not proof or interrupted is not None and not prior:
|
||||||
|
proof, owner_path = self._closed_project_commit_proof(root, commit)
|
||||||
|
if interrupted is not None:
|
||||||
|
supervisor = json.loads(_io_path(owner_path.parent / 'supervisor.json').read_text(encoding='utf-8'))
|
||||||
|
if (proof['native_attempt']['session_id'] != interrupted or supervisor.get('batch_id') != interrupted
|
||||||
|
or supervisor.get('state') != 'blocked' or supervisor.get('business_uncertain') is not True
|
||||||
|
or task_id not in supervisor.get('protected_task_ids', ())):
|
||||||
|
raise ValueError('supervisor interruption is not bound to the closed native worker')
|
||||||
|
proof = dict(proof, operation_attempts=journal.project_commit_attempts(task_id, commit['session_token']))
|
||||||
|
if (not (historical_intact(proof) if prior else validate_project_commit_source(proof, root))
|
||||||
|
or proof.get('operation_attempts') != journal.project_commit_attempts(task_id, commit['session_token'])):
|
||||||
|
raise ValueError('saved source or original attempts changed')
|
||||||
|
marker = markers[commit['session_token']]
|
||||||
|
if (marker['jobs'] != proof.get('jobs') or marker['outcomes'] != proof.get('native_outcomes',proof.get('outcomes'))
|
||||||
|
or marker['files'][0]['sha256'] != proof['files'][0]['sha256']):
|
||||||
|
raise ValueError('native project marker changed')
|
||||||
|
covered.update(proof['jobs'])
|
||||||
|
covered_attempts.extend(proof['operation_attempts'].values())
|
||||||
|
for row in rows:
|
||||||
|
if row['job_id'] not in proof['jobs']:continue
|
||||||
|
saved_protocol = proof.get('validation_required') == 'saved_netlist_v1'
|
||||||
|
state = proof.get('native_outcomes',proof['outcomes'])[row['job_id']] if saved_protocol else proof['outcomes'][row['job_id']]
|
||||||
|
if saved_protocol and state == 'no_match':continue
|
||||||
|
outcome = (state, 'session_staged' if saved_protocol else 'project_committed', '工程保存回读校验通过。')
|
||||||
|
result = self.result_proof(root, row, outcome)
|
||||||
|
if proof.get('native_attempt') and outcome[0] in {'saved_ok','pending_save'} and any(
|
||||||
|
result.get('native_attempt', {}).get(key) != value for key, value in proof['native_attempt'].items()):
|
||||||
|
raise ValueError('native result differs from the exited project worker')
|
||||||
|
if any(proof.get('readback_files', {}).get(Path(item['path']).name) != item['sha256'] for item in result.get('files', ())):
|
||||||
|
raise ValueError('saved native readback evidence changed')
|
||||||
|
if outcome[0] == 'saved_ok' and not saved_protocol:
|
||||||
|
from .value_readback import capture_value_readback
|
||||||
|
if capture_value_readback(root, row, outcome, project_commit=proof).get('value_readback_status') != 'verified':
|
||||||
|
raise ValueError('saved target Value readback is incomplete')
|
||||||
|
if any(Path(name).name != name or hashlib.sha256(_io_path(root / name).read_bytes()).hexdigest() != digest
|
||||||
|
for name, digest in proof.get('readback_files', {}).items()):
|
||||||
|
raise ValueError('native/readback files changed since project closure')
|
||||||
|
if not commit.get('proof_json'):
|
||||||
|
journal.bind_project_commit_proof(task_id, commit['session_token'], proof)
|
||||||
|
commit['proof_json'] = json.dumps(proof)
|
||||||
|
if (not set(journal.unresolved_jobs(task_id, rows)) <= covered
|
||||||
|
or any(attempt not in covered_attempts for attempt in journal.project_commit_recovery_attempts(task_id))):
|
||||||
|
raise ValueError('another native attempt is unresolved')
|
||||||
|
# SQL/history may already have committed before a publication failure.
|
||||||
|
self._commit_staged_project(task_id)
|
||||||
|
for commit in commits:
|
||||||
|
proof = json.loads(commit['proof_json'])
|
||||||
|
if not (historical_intact(proof) if commit['session_token'] in historical else validate_project_commit_source(proof, root)):
|
||||||
|
raise ValueError('saved source or historical proof changed during recovery')
|
||||||
|
handoff = QuickRunResult(root/'QuickPartReplace.vbs', root/'command.tsv', root/'status.tsv', root/'quick-part-replace.log', self.vbs_root_compatible)
|
||||||
|
self._bind_journal_handoff(task_id, handoff)
|
||||||
|
if protection is not None:
|
||||||
|
if flag.read_bytes() != protection:raise ValueError('protection reason changed')
|
||||||
|
write_record(audit, {'task_id': task_id, 'session_tokens': [commit['session_token'] for commit in commits],
|
||||||
|
'native_replacement_called': False, 'original_protection_sha256': hashlib.sha256(protection).hexdigest()})
|
||||||
|
flag.replace(root / 'project-commit-resolved-uncertain.flag')
|
||||||
|
details = _read_status_details(root / 'status.tsv')
|
||||||
|
projects = tuple(project for project in journal.store.list_projects(task_id) if project.selected and project.available)
|
||||||
|
progress = _progress_from_queue(projects, _read_commands(root/'command.tsv'), details, _read_command_sheet_targets(root/'command.tsv'))
|
||||||
|
return QuickRunStepResult(handoff.script_path, handoff.command_path, handoff.status_path, audit,
|
||||||
|
'saved_ok', '完整工程保存回读证明已恢复原回执;未启动 CAD 或重复替换。', progress.next_project_path,
|
||||||
|
progress.next_old_part_number, progress.next_new_part_number, progress.next_schematic_name, progress.next_sheet_number, progress)
|
||||||
|
except (OSError, ValueError, KeyError, TypeError) as error:
|
||||||
|
raise TaskCenterError('quick_run_uncertain', '工程提交证明、保存源或原尝试无法核验,保护记录保持。') from error
|
||||||
|
|
||||||
|
def complete_project_session(self, task_id, scope, session, projects):
|
||||||
|
"""Close the retained owner before exposing saved progress to the queue."""
|
||||||
|
from .operation_diagnostics import record_operation
|
||||||
|
worker = scope.worker
|
||||||
|
if worker is not None:
|
||||||
|
record_operation(worker.root, 'save', 'enter', item_id=worker.token)
|
||||||
|
try:
|
||||||
|
scope.close()
|
||||||
|
record_operation(worker.root, 'save', 'return', item_id=worker.token)
|
||||||
|
except Exception as error:
|
||||||
|
record_operation(worker.root, 'save', 'error', item_id=worker.token, error=str(error))
|
||||||
|
_write_uncertain_flag(worker.root / 'uncertain.flag', 'project_commit_unverified')
|
||||||
|
raise
|
||||||
|
if session is not None:
|
||||||
|
appended, offset, identity, stamp = _read_appended_status_details(session)
|
||||||
|
session.statuses += appended
|
||||||
|
session.status_offset, session.status_identity, session.status_stamp = offset, identity, stamp
|
||||||
|
session.latest = {job: (state, code) for job, state, code, _ in session.statuses}
|
||||||
|
session.next_index = _next_unfinished_index(session.commands, session.latest)
|
||||||
|
session.progress = _progress_from_queue(tuple(project for project in projects if project.selected and project.available),
|
||||||
|
session.commands, session.statuses, session.sheets)
|
||||||
|
session.completed_project_keys = {_path_key(path) for path in session.progress.completed_project_paths}
|
||||||
|
return session.progress
|
||||||
|
|
||||||
def write_expected_baselines(self, task_id, root, project_path):
|
def write_expected_baselines(self, task_id, root, project_path):
|
||||||
journal=getattr(self,'journal',None)
|
journal=getattr(self,'journal',None)
|
||||||
if journal is None:return
|
if journal is None:return
|
||||||
rows=journal.expected_baselines(task_id,project_path)
|
rows=tuple(row for row in journal.expected_baselines(task_id,project_path)
|
||||||
|
if row.get('validation_mode') != 'saved_netlist_v1')
|
||||||
text='project_path\tschematic_name\tsheet_number\tsemantic_state\r\n'
|
text='project_path\tschematic_name\tsheet_number\tsemantic_state\r\n'
|
||||||
text+=''.join('\t'.join(_encode_vbs_field(row[key]) for key in
|
text+=''.join('\t'.join(_encode_vbs_field(row[key]) for key in
|
||||||
('project_path','schematic_name','sheet_number','state'))+'\r\n' for row in rows)
|
('project_path','schematic_name','sheet_number','state'))+'\r\n' for row in rows)
|
||||||
@@ -403,7 +668,8 @@ class QuickRunPreparer:
|
|||||||
from .worker_monitor import WorkerMonitorError
|
from .worker_monitor import WorkerMonitorError
|
||||||
try:
|
try:
|
||||||
with ProjectSessionScope(self._process_runner,
|
with ProjectSessionScope(self._process_runner,
|
||||||
enabled=enabled and self._process_runner is _run_process, private_desktop=True, runtime=runtime) as scope:
|
enabled=enabled and self._process_runner is _run_process and getattr(self, 'journal', None) is not None,
|
||||||
|
private_desktop=True, runtime=runtime) as scope:
|
||||||
yield scope
|
yield scope
|
||||||
except (WorkerMonitorError, subprocess.TimeoutExpired) as error:
|
except (WorkerMonitorError, subprocess.TimeoutExpired) as error:
|
||||||
_write_uncertain_flag(self._data_root / 'quick-run/uncertain.flag', 'project_session_cleanup')
|
_write_uncertain_flag(self._data_root / 'quick-run/uncertain.flag', 'project_session_cleanup')
|
||||||
@@ -428,6 +694,31 @@ class QuickRunPreparer:
|
|||||||
uncertain_path = self._data_root / "quick-run" / "uncertain.flag"
|
uncertain_path = self._data_root / "quick-run" / "uncertain.flag"
|
||||||
if _io_path(uncertain_path).exists():
|
if _io_path(uncertain_path).exists():
|
||||||
raise TaskCenterError("quick_run_uncertain", "a previous quick-run worker timed out or returned an uncorrelated status; reconcile the project before retrying")
|
raise TaskCenterError("quick_run_uncertain", "a previous quick-run worker timed out or returned an uncorrelated status; reconcile the project before retrying")
|
||||||
|
if (self._process_runner is _run_process and getattr(self,'journal',None) is not None
|
||||||
|
and (project_session is None or not project_session.enabled)):
|
||||||
|
if not batch_mode:
|
||||||
|
from .single_step import prepare_private_single_step
|
||||||
|
prepare_private_single_step(self,task_id,projects,rules,copy_part_number_to_value,
|
||||||
|
**({'runtime':runtime} if runtime is not None else {}))
|
||||||
|
session = batch_session or self.begin_batch_session(task_id,projects,rules,
|
||||||
|
copy_part_number_to_value=copy_part_number_to_value,runtime=runtime)
|
||||||
|
if session.next_index >= len(session.commands):
|
||||||
|
raise TaskCenterError('quick_run_complete','all replacement rules in this queue are complete')
|
||||||
|
job = session.commands[session.next_index][1]
|
||||||
|
# A standalone or explicitly nonretained call still needs one closed,
|
||||||
|
# saved native prefix. The scope is held for this invocation only.
|
||||||
|
with self.project_session_scope(enabled=True,runtime=runtime) as scope:
|
||||||
|
result = self.execute_step(task_id,projects,rules,copy_part_number_to_value=copy_part_number_to_value,
|
||||||
|
expected_item=expected_item,batch_mode=True,batch_session=session,project_session=scope,
|
||||||
|
runtime=runtime,stop_event=stop_event)
|
||||||
|
if result.state == 'pending_save':
|
||||||
|
self.complete_project_session(task_id,scope,session,projects)
|
||||||
|
if result.state not in DONE_STATES | {'pending_save'}:return result
|
||||||
|
terminal = next(entry for entry in reversed(session.statuses) if entry[0] == job)
|
||||||
|
progress = session.progress
|
||||||
|
return QuickRunStepResult(result.script_path,result.command_path,result.status_path,result.log_path,
|
||||||
|
terminal[1],terminal[3],progress.next_project_path,progress.next_old_part_number,
|
||||||
|
progress.next_new_part_number,progress.next_schematic_name,progress.next_sheet_number,progress)
|
||||||
if self._process_runner is _run_process and not batch_mode:
|
if self._process_runner is _run_process and not batch_mode:
|
||||||
from .single_step import prepare_private_single_step
|
from .single_step import prepare_private_single_step
|
||||||
prepare_private_single_step(self, task_id, projects, rules, copy_part_number_to_value,
|
prepare_private_single_step(self, task_id, projects, rules, copy_part_number_to_value,
|
||||||
@@ -636,6 +927,56 @@ class QuickRunPreparer:
|
|||||||
_write_uncertain_flag(uncertain_path, "malformed_status_after_worker")
|
_write_uncertain_flag(uncertain_path, "malformed_status_after_worker")
|
||||||
_append_log(handoff.log_path, "quick_run_uncertain malformed_status_after_worker")
|
_append_log(handoff.log_path, "quick_run_uncertain malformed_status_after_worker")
|
||||||
raise TaskCenterError("quick_run_uncertain", "quick-run worker left an unreadable status; reconcile the project before retrying") from error
|
raise TaskCenterError("quick_run_uncertain", "quick-run worker left an unreadable status; reconcile the project before retrying") from error
|
||||||
|
if completed.returncode == 75:
|
||||||
|
if project_session is not None:
|
||||||
|
project_session.on_commit = None
|
||||||
|
if _io_path(uncertain_path).exists():
|
||||||
|
raise TaskCenterError('quick_run_uncertain', '工程已保留待核验保护,请先核验原执行证据。')
|
||||||
|
prefix_commit_pending = False
|
||||||
|
try:
|
||||||
|
proof = getattr(completed, 'prewrite_pause', {})
|
||||||
|
pause_token = proof.get('session_token', '')
|
||||||
|
marker = _io_path(handoff.command_path.parent / f'project-pause-{pause_token}.tsv')
|
||||||
|
fields = marker.read_text(encoding='utf-8-sig').strip().split('\t')
|
||||||
|
status_bytes = _io_path(handoff.status_path).read_bytes()
|
||||||
|
if (runtime is None or journal_attempt is None or project_session is None
|
||||||
|
or project_session.worker is None or pause_token != project_session.worker.token
|
||||||
|
or proof.get('phase') != 'before_native_dispatch'
|
||||||
|
or proof.get('session_id') != runtime.session_id or proof.get('generation') != runtime.generation
|
||||||
|
or proof.get('attempt_id') != runtime.record.get('active_attempt')
|
||||||
|
or proof.get('resource_record') != str(runtime.path)
|
||||||
|
or len(fields) != 4 or fields[0] != pause_token or fields[2:] != [row['job_id'], 'prewrite_closed']
|
||||||
|
or _path_key(_decode_vbs_field(fields[1])) != _path_key(row['project_path'])
|
||||||
|
or proof.get('request_sha256') != hashlib.sha256(
|
||||||
|
_io_path(handoff.command_path.with_name('project-session.request')).read_bytes()).hexdigest()
|
||||||
|
or proof.get('current_command_sha256') != hashlib.sha256(
|
||||||
|
_io_path(handoff.command_path.with_name('current-command.tsv')).read_bytes()).hexdigest()
|
||||||
|
or proof.get('status_sha256') != hashlib.sha256(status_bytes).hexdigest()
|
||||||
|
or any(entry[0] == row['job_id'] and entry[1] in TERMINAL_STATES for entry in after)
|
||||||
|
or not ((stop_event is not None and stop_event.is_set())
|
||||||
|
or (runtime.stop_event is not None and runtime.stop_event.is_set()))):
|
||||||
|
raise ValueError('prewrite pause is not bound to the retained owner')
|
||||||
|
journal.pause_before_dispatch(journal_attempt, row, dict(proof, status_size=len(status_bytes)))
|
||||||
|
journal.finalize_startup_pause(task_id, handoff.command_path.parent)
|
||||||
|
_append_status_details(handoff.status_path, (
|
||||||
|
(row['job_id'], 'pending', 'prewrite_paused', '工程安全关闭;当前项确认未替换,保留待执行。'),))
|
||||||
|
if proof.get('committed_prefix'):
|
||||||
|
# Confirmed recovery can publish the prefix if the process
|
||||||
|
# stops after committing SQL but before appending status.
|
||||||
|
_write_uncertain_flag(uncertain_path, 'project_commit_unverified')
|
||||||
|
prefix_commit_pending = True
|
||||||
|
self._commit_staged_project(task_id, session_token=pause_token)
|
||||||
|
if not any(commit['session_token'] == pause_token and commit['state'] == 'verified'
|
||||||
|
and set(json.loads(commit['jobs_json'])) == set(proof['committed_prefix'])
|
||||||
|
for commit in journal.project_commit_records(task_id)):
|
||||||
|
raise ValueError('certified prewrite prefix has no matching verified receipt')
|
||||||
|
_io_path(uncertain_path).unlink()
|
||||||
|
except Exception as error:
|
||||||
|
if not prefix_commit_pending:
|
||||||
|
_write_uncertain_flag(uncertain_path, 'unproven_prewrite_pause')
|
||||||
|
raise TaskCenterError('quick_run_uncertain', '暂停缺少完整的未写入与工程关闭证明;保留保护并核验。') from error
|
||||||
|
_append_log(handoff.log_path, 'quick_run_paused prewrite_closed')
|
||||||
|
raise TaskCenterError('operation_cancelled', '工程已安全关闭,已暂存前缀完成保存回读;当前项保留待执行。')
|
||||||
if completed.returncode == 74:
|
if completed.returncode == 74:
|
||||||
try:
|
try:
|
||||||
proof = getattr(completed, 'startup_pause', {})
|
proof = getattr(completed, 'startup_pause', {})
|
||||||
@@ -771,7 +1112,8 @@ class QuickRunPreparer:
|
|||||||
_append_log(handoff.log_path, "quick_run_uncertain native_failure_after_snapshot")
|
_append_log(handoff.log_path, "quick_run_uncertain native_failure_after_snapshot")
|
||||||
raise TaskCenterError("quick_run_uncertain", detail)
|
raise TaskCenterError("quick_run_uncertain", detail)
|
||||||
raise TaskCenterError("quick_run_execution", detail)
|
raise TaskCenterError("quick_run_execution", detail)
|
||||||
if state not in TERMINAL_STATES:
|
if state not in TERMINAL_STATES and not (state == 'pending_save' and project_session is not None
|
||||||
|
and project_session.enabled and code in {'session_staged', 'session_staged_no_match'}):
|
||||||
raise TaskCenterError("quick_run_execution", f"unexpected quick-run state: {state}")
|
raise TaskCenterError("quick_run_execution", f"unexpected quick-run state: {state}")
|
||||||
if batch_mode and state == "saved_ok":
|
if batch_mode and state == "saved_ok":
|
||||||
try:
|
try:
|
||||||
@@ -804,6 +1146,23 @@ class QuickRunPreparer:
|
|||||||
progress = _progress_from_queue(tuple(project for project in projects if project.selected and project.available),
|
progress = _progress_from_queue(tuple(project for project in projects if project.selected and project.available),
|
||||||
commands, after, _read_command_sheet_targets(handoff.command_path))
|
commands, after, _read_command_sheet_targets(handoff.command_path))
|
||||||
try:
|
try:
|
||||||
|
if state == 'pending_save':
|
||||||
|
proof = self.result_proof(handoff.command_path.parent, row, (state, code, message))
|
||||||
|
journal.stage_project_result(journal_attempt, row, session_token=project_session.worker.token,
|
||||||
|
root=handoff.command_path.parent, proof=proof)
|
||||||
|
project_session.on_commit = lambda worker: self._commit_staged_project(task_id, session_token=worker.token, bind_source=True)
|
||||||
|
if (next_command is None or _path_key(next_command[2]) != _path_key(row['project_path'])
|
||||||
|
or (stop_event is not None and stop_event.is_set())):
|
||||||
|
progress = self.complete_project_session(task_id, project_session, batch_session, projects)
|
||||||
|
state = 'no_match' if code == 'session_staged_no_match' else 'saved_ok'
|
||||||
|
message = ('工程统一保存,原生数据核验通过。' if proof.get('validation_required') == 'saved_netlist_v1'
|
||||||
|
else '工程统一保存、关闭重开及回读校验通过。')
|
||||||
|
next_command = commands[batch_session.next_index] if batch_session is not None and batch_session.next_index < len(commands) else None
|
||||||
|
next_sheet = batch_session.sheets.get(next_command[1], (None, None)) if batch_session is not None and next_command is not None and batch_session.sheets is not None else (None, None)
|
||||||
|
return QuickRunStepResult(handoff.script_path, handoff.command_path, handoff.status_path, handoff.log_path,
|
||||||
|
state, message, Path(next_command[2]) if next_command is not None else None,
|
||||||
|
next_command[3] if next_command is not None else None, next_command[4] if next_command is not None else None,
|
||||||
|
next_sheet[0], next_sheet[1], progress)
|
||||||
verified_source_health = None
|
verified_source_health = None
|
||||||
if (state in {'saved_ok', 'restored_ok', 'no_match'} and self._process_runner is _run_process
|
if (state in {'saved_ok', 'restored_ok', 'no_match'} and self._process_runner is _run_process
|
||||||
and journal.failure_health_references(task_id, row['project_path'])):
|
and journal.failure_health_references(task_id, row['project_path'])):
|
||||||
@@ -1196,9 +1555,21 @@ def _advance_batch_session(
|
|||||||
current_index = session.next_index
|
current_index = session.next_index
|
||||||
current = session.commands[current_index]
|
current = session.commands[current_index]
|
||||||
job_id, state, code, _ = changed
|
job_id, state, code, _ = changed
|
||||||
if job_id != current[1] or state not in TERMINAL_STATES:
|
if job_id != current[1] or state not in TERMINAL_STATES | {'pending_save'}:
|
||||||
raise TaskCenterError("quick_run_queue_progress", "batch result does not complete the expected queue item")
|
raise TaskCenterError("quick_run_queue_progress", "batch result does not complete the expected queue item")
|
||||||
session.latest[job_id] = (state, code)
|
session.latest[job_id] = (state, code)
|
||||||
|
if state == 'pending_save':
|
||||||
|
from dataclasses import replace
|
||||||
|
next_index = current_index + 1
|
||||||
|
while next_index < len(session.commands) and session.latest.get(session.commands[next_index][1], ('', ''))[0] in TERMINAL_STATES | {'pending_save'}:
|
||||||
|
next_index += 1
|
||||||
|
session.next_index = next_index
|
||||||
|
next_command = session.commands[next_index] if next_index < len(session.commands) else None
|
||||||
|
next_sheet = session.sheets.get(next_command[1], (None, None)) if session.sheets is not None and next_command is not None else (None, None)
|
||||||
|
session.progress = replace(session.progress, next_project_path=Path(next_command[2]) if next_command else None,
|
||||||
|
next_old_part_number=next_command[3] if next_command else None, next_new_part_number=next_command[4] if next_command else None,
|
||||||
|
next_schematic_name=next_sheet[0], next_sheet_number=next_sheet[1], queue_complete=False)
|
||||||
|
return
|
||||||
current_key = session.project_keys_by_index[current_index]
|
current_key = session.project_keys_by_index[current_index]
|
||||||
partial_failures = {
|
partial_failures = {
|
||||||
_path_key(path): (path, summary)
|
_path_key(path): (path, summary)
|
||||||
@@ -1512,6 +1883,22 @@ def _recover_pre_mutation_hard_failures(
|
|||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
def _append_status_details(path: Path, statuses: tuple[tuple[str, str, str, str], ...]) -> None:
|
||||||
|
"""Publish closed-project receipts without replacing an active batch stream."""
|
||||||
|
payload = ''.join('\t'.join(_encode_vbs_field(field) for field in entry)+'\r\n' for entry in statuses).encode('utf-8')
|
||||||
|
try:
|
||||||
|
with _io_path(path).open('r+b') as stream:
|
||||||
|
stream.seek(0,os.SEEK_END)
|
||||||
|
end = stream.tell()
|
||||||
|
if end:
|
||||||
|
stream.seek(-1,os.SEEK_END)
|
||||||
|
if stream.read(1) != b'\n':raise ValueError('cannot append to an incomplete status stream')
|
||||||
|
stream.seek(0,os.SEEK_END)
|
||||||
|
stream.write(payload);stream.flush();os.fsync(stream.fileno())
|
||||||
|
except (OSError,ValueError) as error:
|
||||||
|
raise TaskCenterError('quick_run_status','cannot publish saved project status') from error
|
||||||
|
|
||||||
|
|
||||||
def _write_status_details(path: Path, statuses: tuple[tuple[str, str, str, str], ...]) -> None:
|
def _write_status_details(path: Path, statuses: tuple[tuple[str, str, str, str], ...]) -> None:
|
||||||
temporary = path.with_name(f".{path.name}.{uuid4().hex}.tmp")
|
temporary = path.with_name(f".{path.name}.{uuid4().hex}.tmp")
|
||||||
text = "job_id\tstate\tcode\tmessage\r\n"
|
text = "job_id\tstate\tcode\tmessage\r\n"
|
||||||
@@ -2074,10 +2461,12 @@ def _correlated_status_change(
|
|||||||
job_id = appended[0][0]
|
job_id = appended[0][0]
|
||||||
prior_state = next((state for status_job_id, state, _, _ in reversed(before) if status_job_id == job_id), None)
|
prior_state = next((state for status_job_id, state, _, _ in reversed(before) if status_job_id == job_id), None)
|
||||||
transitions = {
|
transitions = {
|
||||||
None: {"awaiting_native_replace", "hard_failure", "batch_failed", "batch_saved_unverified", "no_match"},
|
None: {"awaiting_native_replace", "hard_failure", "batch_failed", "batch_saved_unverified", "no_match", "pending_save"},
|
||||||
|
"pending": {"awaiting_native_replace", "hard_failure", "batch_failed", "batch_saved_unverified", "no_match", "pending_save"},
|
||||||
"awaiting_native_replace": {
|
"awaiting_native_replace": {
|
||||||
"restored_ok",
|
"restored_ok",
|
||||||
"saved_ok",
|
"saved_ok",
|
||||||
|
"pending_save",
|
||||||
"hard_failure",
|
"hard_failure",
|
||||||
"batch_failed",
|
"batch_failed",
|
||||||
"batch_saved_unverified",
|
"batch_saved_unverified",
|
||||||
|
|||||||
@@ -0,0 +1,328 @@
|
|||||||
|
"""Validate a closed project's applied targets through one saved native export."""
|
||||||
|
import hashlib
|
||||||
|
import json
|
||||||
|
import re
|
||||||
|
from collections import Counter
|
||||||
|
from pathlib import Path
|
||||||
|
|
||||||
|
from . import native_netlist
|
||||||
|
from .batch_resources import write_record
|
||||||
|
from .execution_proof import proof_intact, validate_project_commit_source
|
||||||
|
from .path_access import canonical_path, internal_path
|
||||||
|
from .quick_run_protocol import _decode_vbs_field
|
||||||
|
|
||||||
|
|
||||||
|
def _hash(path):
|
||||||
|
return hashlib.sha256(internal_path(path).read_bytes()).hexdigest()
|
||||||
|
|
||||||
|
|
||||||
|
def _fields(line):
|
||||||
|
return [_decode_vbs_field(value) for value in line.split('\t')]
|
||||||
|
|
||||||
|
|
||||||
|
def _context(proof):
|
||||||
|
return {key: proof[key] for key in ('session_token', 'project_path', 'saved_sources', 'command_sha256')}
|
||||||
|
|
||||||
|
|
||||||
|
def _intact(record):
|
||||||
|
return (record.get('files') and proof_intact(record)
|
||||||
|
and _saved_sources_intact(record['context']['saved_sources'])
|
||||||
|
and _hash(record['export_path']) == record['export_sha256'])
|
||||||
|
|
||||||
|
|
||||||
|
def _saved_sources_intact(sources):
|
||||||
|
return bool(sources) and all(_hash(path) == digest for path, digest in sources.items())
|
||||||
|
|
||||||
|
|
||||||
|
def _read_export_pointer(root):
|
||||||
|
try:
|
||||||
|
record = json.loads(internal_path(root / 'saved-netlist-export.json').read_text(encoding='utf-8'))
|
||||||
|
except FileNotFoundError:
|
||||||
|
return None
|
||||||
|
if not isinstance(record, dict) or record.get('status') not in {'exported', 'verified'}:
|
||||||
|
raise ValueError('invalid saved native export lookup')
|
||||||
|
return record
|
||||||
|
|
||||||
|
|
||||||
|
def _authoritative_export(record):
|
||||||
|
"""The mutable lookup record cannot supply graph data or captured inputs."""
|
||||||
|
result = json.loads(internal_path(record['export_path']).read_text(encoding='utf-8'))
|
||||||
|
capture = result['capture']
|
||||||
|
source_hashes = {str(canonical_path(path)).casefold():digest for path,digest in capture['source_hashes'].items()}
|
||||||
|
if (result.get('status') != 'success' or result.get('complete') is not True
|
||||||
|
or canonical_path(capture['project']) != canonical_path(record['context']['project_path'])
|
||||||
|
or any(source_hashes.get(str(canonical_path(path)).casefold()) != digest
|
||||||
|
for path,digest in record['context']['saved_sources'].items())
|
||||||
|
or set(result['outputs'].values()) != set(record['output_hashes'])
|
||||||
|
or any(_hash(path) != record['output_hashes'][path] for path in result['outputs'].values())):
|
||||||
|
raise ValueError('immutable saved native export differs from its original source binding')
|
||||||
|
native_netlist._check_capture(capture)
|
||||||
|
return result
|
||||||
|
|
||||||
|
|
||||||
|
def load_saved_export(root, project):
|
||||||
|
"""Return a verified intact shared export for the current saved source, or None."""
|
||||||
|
root = Path(root)
|
||||||
|
try:
|
||||||
|
record = _read_export_pointer(root)
|
||||||
|
if record is None or record['status'] == 'exported':
|
||||||
|
return None
|
||||||
|
context = record['context']
|
||||||
|
if (canonical_path(context['project_path']) != canonical_path(project)
|
||||||
|
or context['command_sha256'] != _hash(root / 'command.tsv')):
|
||||||
|
return None
|
||||||
|
if _hash(record['verification_path']) != record['verification_sha256']:
|
||||||
|
raise ValueError('immutable saved target verification changed')
|
||||||
|
verified = json.loads(internal_path(record['verification_path']).read_text(encoding='utf-8'))
|
||||||
|
if any(verified[key] != record[key] for key in ('status', 'context', 'export_path', 'export_sha256')):
|
||||||
|
raise ValueError('saved target lookup differs from its immutable verification')
|
||||||
|
if not context['saved_sources']:
|
||||||
|
raise ValueError('saved source hashes are missing')
|
||||||
|
if not _saved_sources_intact(context['saved_sources']):
|
||||||
|
return None
|
||||||
|
marker = root / f'project-commit-{context["session_token"]}.tsv'
|
||||||
|
if _hash(marker) != context['marker_sha256'] or not _intact(record):
|
||||||
|
raise ValueError('saved marker or export artifacts changed')
|
||||||
|
record['jobs'] = verified['jobs']
|
||||||
|
record['result'] = _authoritative_export(record)
|
||||||
|
record['capture'] = record['result']['capture']
|
||||||
|
return record
|
||||||
|
except (OSError, ValueError, KeyError, TypeError, AttributeError) as error:
|
||||||
|
raise ValueError(f'saved native export integrity check failed: {error}') from error
|
||||||
|
|
||||||
|
|
||||||
|
def compact_saved_netlist(record, *, include_jobs=True):
|
||||||
|
result = {key: record[key] for key in ('status', 'export_path', 'export_sha256')}
|
||||||
|
result.update(verification_path=record['verification_path'], verification_sha256=record['verification_sha256'])
|
||||||
|
if include_jobs:
|
||||||
|
result.update(context=record['context'], jobs=record['jobs'], files=record['files'])
|
||||||
|
return result
|
||||||
|
|
||||||
|
|
||||||
|
def _expectations(root, row):
|
||||||
|
from .execution_proof import capture_result
|
||||||
|
from .native_helper import read_snapshot, require_resumable_transaction, saved_netlist_snapshot
|
||||||
|
snapshot = internal_path(root / f'snapshot-{row["job_id"]}.tsv')
|
||||||
|
if not saved_netlist_snapshot(snapshot):raise ValueError('saved netlist target snapshot protocol required')
|
||||||
|
# This validates the command, selected original target set and native attempt.
|
||||||
|
capture_result(root.parent, root, row, ('pending_save', 'session_staged', ''), strict=True, persist=False)
|
||||||
|
metadata, components = read_snapshot(snapshot)
|
||||||
|
report_path = Path(str(snapshot) + '.native.json')
|
||||||
|
report = json.loads(report_path.read_text(encoding='utf-8'))
|
||||||
|
binding = require_resumable_transaction(snapshot, report, metadata, components)
|
||||||
|
library = binding['library_row']
|
||||||
|
if library[1].casefold() != row['new_part'].casefold():raise ValueError('native library target changed')
|
||||||
|
writer = internal_path(root / f'writer-expectations-{row["job_id"]}.tsv')
|
||||||
|
records = [_fields(line) for line in writer.read_text(encoding='utf-8-sig').splitlines() if line]
|
||||||
|
header = ['W', '1', row['task_id'], row['job_id'], row['project_path'],
|
||||||
|
row.get('schematic_name',''), row.get('sheet_number',''), snapshot.read_bytes().decode('utf-8-sig')]
|
||||||
|
if not records or records[0] != header:raise ValueError('writer expectations are not bound to the original snapshot and command')
|
||||||
|
original = {item[1]: item[2] for item in components}
|
||||||
|
if row.get('target_scope') == 'targets':
|
||||||
|
selectors = [value.split('\x1f') for value in row.get('target_selectors','').split('\x1e')]
|
||||||
|
if (not selectors or any(len(value) != 3 or not value[1].strip() for value in selectors)
|
||||||
|
or {value[1].strip().casefold() for value in selectors} != {ref.strip().casefold() for ref in original.values()}):
|
||||||
|
raise ValueError('native snapshot reference set differs from the frozen target selectors')
|
||||||
|
old_values = {}
|
||||||
|
for line in snapshot.read_text(encoding='utf-8-sig').splitlines():
|
||||||
|
fields = _fields(line)
|
||||||
|
if fields[0] == 'A' and len(fields) == 12 and fields[2].casefold() == 'value':
|
||||||
|
if fields[1] in old_values:raise ValueError('original Value is ambiguous')
|
||||||
|
old_values[fields[1]] = fields[4] or fields[3]
|
||||||
|
has_nc = lambda text: '/' in text and any(part.strip().casefold() == 'nc' for part in text.split('/'))
|
||||||
|
expected = {}
|
||||||
|
for fields in records[1:]:
|
||||||
|
if len(fields) != 9 or fields[0] != 'C':raise ValueError('malformed writer target expectation')
|
||||||
|
_, uid, ref, value, present, name, label, part, cell = fields
|
||||||
|
if (uid not in original or uid in expected or ref != original[uid] or present not in {'0','1'}
|
||||||
|
or name != library[4] or label != library[5] or part.casefold() != row['new_part'].casefold()
|
||||||
|
or cell != row.get('target_cell','')):
|
||||||
|
raise ValueError('writer target expectation differs from native library/command')
|
||||||
|
mode = row['value_mode']
|
||||||
|
if mode != 'preserve':
|
||||||
|
policy_value = {'custom': row.get('custom_value',''), 'part_number': row['new_part'], 'part_label': library[5]}[mode]
|
||||||
|
if row.get('sync_nc','1') == '1' and has_nc(old_values.get(uid,'')) and not has_nc(policy_value):
|
||||||
|
policy_value = policy_value.rstrip(' ') + ('NC' if policy_value.rstrip(' ').endswith('/') else '/NC')
|
||||||
|
if present != '1' or value != policy_value:raise ValueError('writer Value contradicts the frozen write policy')
|
||||||
|
if row.get('sync_nc','1') == '1' and has_nc(old_values.get(uid,'')) and not has_nc(value):
|
||||||
|
raise ValueError('required original NC marker was not retained')
|
||||||
|
expected[uid] = dict(refdes=ref, value=value, present=present == '1', old_value=old_values.get(uid),
|
||||||
|
attributes={'Part Number': part, 'Part Name': name, 'Part Label': label}, target_cell=cell)
|
||||||
|
if set(expected) != set(original):raise ValueError('writer target set is incomplete')
|
||||||
|
return expected, binding, [snapshot, report_path, writer]
|
||||||
|
|
||||||
|
|
||||||
|
def _scope(component, row):
|
||||||
|
return all(not row.get(key) or component.get(field) == row[key]
|
||||||
|
for key, field in (('schematic_name','source_schematic'), ('sheet_number','source_page')))
|
||||||
|
|
||||||
|
|
||||||
|
def _verify_no_match(graph, row):
|
||||||
|
components = graph['components']
|
||||||
|
if row.get('target_scope') == 'targets':
|
||||||
|
selectors = [item.split('\x1f') for item in row.get('target_selectors', '').split('\x1e')]
|
||||||
|
if any(len(item) != 3 or not item[1].strip() for item in selectors):
|
||||||
|
raise ValueError('saved native no-match coverage lacks valid frozen target selectors')
|
||||||
|
for _, ref, _ in selectors:
|
||||||
|
keys = native_netlist.reference_targets(graph, ref, sheet=row.get('sheet_number', ''),
|
||||||
|
schematic=row.get('schematic_name', ''))
|
||||||
|
if not keys or any(not _scope(components[key], row) for key in keys):
|
||||||
|
raise ValueError(f'saved native no-match coverage lacks selected reference {ref}')
|
||||||
|
# A frozen selector can return no_match only through already_target in the writer.
|
||||||
|
if any(components[key]['attributes'].get('Part Number', '').casefold() != row['new_part'].casefold()
|
||||||
|
for key in keys):
|
||||||
|
raise ValueError(f'saved native no-match Part Number differs from the target for {ref}')
|
||||||
|
return
|
||||||
|
candidates = [item for component in components.values()
|
||||||
|
for item in component.get('annotation_instances', [component]) if _scope(item, row)]
|
||||||
|
if not candidates and [row['schematic_name'], row['sheet_number']] not in graph.get('source_sheets', ()):
|
||||||
|
raise ValueError('saved native no-match coverage lacks the frozen schematic or sheet')
|
||||||
|
if any(item['attributes'].get('Part Number', '').casefold() == row['old_part'].casefold() for item in candidates):
|
||||||
|
raise ValueError('native no-match claim still has original targets in the saved scope')
|
||||||
|
|
||||||
|
|
||||||
|
def _observations(graph, row, expected, binding):
|
||||||
|
observations = []
|
||||||
|
counts = Counter(item['refdes'].strip().casefold() for item in expected.values())
|
||||||
|
remaining = {}
|
||||||
|
for uid, item in expected.items():
|
||||||
|
ref = item['refdes'].strip().casefold()
|
||||||
|
if ref not in remaining:
|
||||||
|
keys = native_netlist.reference_targets(graph, item['refdes'],
|
||||||
|
sheet=row.get('sheet_number',''), schematic=row.get('schematic_name',''))
|
||||||
|
if len(keys) != counts[ref] or not keys:
|
||||||
|
raise ValueError('saved native target units are missing or ambiguous')
|
||||||
|
if any(not _scope(graph['components'][key],row) or graph['components'][key].get('ambiguous_attributes') for key in keys):
|
||||||
|
raise ValueError('saved native target sheet or attributes are ambiguous')
|
||||||
|
remaining[ref] = list(keys)
|
||||||
|
# Match the declared multiset within one physical reference. Native UIDs
|
||||||
|
# may change; no expected property is inferred from the exported graph.
|
||||||
|
matches = []
|
||||||
|
for key in remaining[ref]:
|
||||||
|
attrs = graph['components'][key]['attributes']
|
||||||
|
if (all(attrs.get(name) is not None and
|
||||||
|
(attrs[name].casefold() == value.casefold() if name == 'Part Number' else attrs[name] == value)
|
||||||
|
for name,value in item['attributes'].items())
|
||||||
|
and (not item['target_cell'] or attrs.get('Cell Name') == item['target_cell'])
|
||||||
|
and attrs.get('Value','') == item['value']):
|
||||||
|
matches.append(key)
|
||||||
|
if not matches:raise ValueError('saved native target library attributes, Cell or Value differ from the write policy')
|
||||||
|
key = matches[0]
|
||||||
|
remaining[ref].remove(key)
|
||||||
|
symbol = graph['components'][key].get('symbol','')
|
||||||
|
if symbol:
|
||||||
|
target = re.fullmatch(r'(?:[^:\s]+:)?([^:\s]+?)(?:\.(\d+))?', binding['target_symbol'])
|
||||||
|
actual = re.match(r'([^\s]+?)\.(\d+) type ', symbol)
|
||||||
|
if (not target or not actual or target[1] != actual[1]
|
||||||
|
or target[2] is not None and target[2] != actual[2]
|
||||||
|
or not 1 <= int(actual[2]) <= binding['slot_count']):
|
||||||
|
raise ValueError('saved native target symbol differs from the selected library')
|
||||||
|
actual = graph['components'][key]['attributes']
|
||||||
|
observations.append(dict(uid=uid, refdes=item['refdes'], old_part_number=row['old_part'],
|
||||||
|
actual_part_number=actual['Part Number'], old_value=item['old_value'], actual_value=actual.get('Value',''),
|
||||||
|
old_value_present=item['old_value'] is not None,
|
||||||
|
actual_value_present=True if actual.get('Value') else None,
|
||||||
|
value_presence_coverage='native_ascii_empty_presence_unknown', actual_cell=actual.get('Cell Name','')))
|
||||||
|
return dict(value_readback_status='verified', value_readback=observations, value_readback_job_id=row['job_id'],
|
||||||
|
project_path=row['project_path'], schematic_name=row.get('schematic_name',''), sheet_number=row.get('sheet_number',''),
|
||||||
|
coverage_limits=['Native ASCII empty Value does not prove attribute presence; CAD display/layout is not checked.'])
|
||||||
|
|
||||||
|
|
||||||
|
def verify_saved_project(data_root, root, proof, rows, *, stop_event=None):
|
||||||
|
"""Export once, validate all applied targets, and return the verified commit proof."""
|
||||||
|
from .netlist_verification import _export_saved_capture
|
||||||
|
root, data_root = Path(root), Path(data_root)
|
||||||
|
if proof.get('validation_required') != 'saved_netlist_v1' or not validate_project_commit_source(proof, root):
|
||||||
|
raise ValueError('saved source-bound project proof is required')
|
||||||
|
outcomes = proof.get('native_outcomes', proof['outcomes'])
|
||||||
|
readbacks = proof.get('readback_files')
|
||||||
|
required = {name for job, state in outcomes.items() if state == 'pending_save'
|
||||||
|
for name in (f'snapshot-{job}.tsv', f'snapshot-{job}.tsv.native.json', f'writer-expectations-{job}.tsv')}
|
||||||
|
|
||||||
|
def readbacks_intact():
|
||||||
|
return (isinstance(readbacks, dict) and required <= readbacks.keys()
|
||||||
|
and all(Path(name).name == name and _hash(root / name) == digest
|
||||||
|
for name, digest in readbacks.items()))
|
||||||
|
|
||||||
|
if not readbacks_intact():raise ValueError('native writer evidence changed before saved export')
|
||||||
|
rows = {row['job_id']: row for row in rows}
|
||||||
|
if not set(proof['jobs']) <= rows.keys():raise ValueError('saved prefix is outside the frozen command plan')
|
||||||
|
context = _context(proof)
|
||||||
|
context['marker_sha256'] = proof['files'][0]['sha256']
|
||||||
|
evidence, inputs = {}, []
|
||||||
|
for job in proof['jobs']:
|
||||||
|
if outcomes[job] == 'pending_save':
|
||||||
|
evidence[job] = _expectations(root, rows[job])
|
||||||
|
inputs.extend(evidence[job][2])
|
||||||
|
elif not rows[job].get('schematic_name') or not rows[job].get('sheet_number'):
|
||||||
|
raise ValueError('saved native no-match coverage requires a frozen schematic and sheet')
|
||||||
|
pointer = root / 'saved-netlist-export.json'
|
||||||
|
record = None
|
||||||
|
candidate = _read_export_pointer(root)
|
||||||
|
if candidate is not None and candidate['context'] == context:
|
||||||
|
if not _intact(candidate):
|
||||||
|
raise ValueError('saved native export changed before target validation')
|
||||||
|
record = candidate
|
||||||
|
if record is None:
|
||||||
|
directory = data_root / 'execution-proof' / ('saved-netlist-' + proof['session_token'])
|
||||||
|
capture_path = directory / 'capture/capture.json'
|
||||||
|
if capture_path.is_file():
|
||||||
|
capture = json.loads(capture_path.read_text(encoding='utf-8'))
|
||||||
|
native_netlist._check_capture(capture)
|
||||||
|
source_hashes = {str(canonical_path(path)).casefold():digest for path,digest in capture['source_hashes'].items()}
|
||||||
|
if (canonical_path(capture['project']) != canonical_path(proof['project_path'])
|
||||||
|
or any(source_hashes.get(str(canonical_path(path)).casefold()) != digest for path,digest in proof['saved_sources'].items())):
|
||||||
|
raise ValueError('saved native capture belongs to a different original source')
|
||||||
|
else:
|
||||||
|
capture = native_netlist.capture_project(Path(proof['project_path']), directory / 'capture')
|
||||||
|
if not validate_project_commit_source(proof, root):raise ValueError('saved source changed while capturing the native database')
|
||||||
|
result = _export_saved_capture(capture, directory / 'export', stop_event=stop_event)
|
||||||
|
if result.get('status') != 'success' or result.get('complete') is not True:
|
||||||
|
raise ValueError('complete native saved export unavailable: ' + str(result.get('reason','')))
|
||||||
|
manifest = directory / 'export/netlist.json'
|
||||||
|
paths = [Path(capture['manifest_path']), manifest, *map(Path,result['outputs'].values()),
|
||||||
|
*(Path(capture['root']) / name for name in capture['capture_hashes'])]
|
||||||
|
for path in inputs:
|
||||||
|
target = internal_path(directory / 'inputs' / path.name)
|
||||||
|
target.parent.mkdir(parents=True,exist_ok=True)
|
||||||
|
data = internal_path(path).read_bytes()
|
||||||
|
if hashlib.sha256(data).hexdigest() != readbacks[path.name]:
|
||||||
|
raise ValueError('native target evidence changed during capture')
|
||||||
|
target.write_bytes(data)
|
||||||
|
if internal_path(path).read_bytes() != data:raise ValueError('native target evidence changed during capture')
|
||||||
|
paths.append(target)
|
||||||
|
files = [{'path':str(canonical_path(path)), 'sha256':_hash(path)} for path in dict.fromkeys(paths)]
|
||||||
|
record = dict(status='exported', context=context, capture=capture, result=result,
|
||||||
|
export_path=str(canonical_path(manifest)), export_sha256=_hash(manifest),
|
||||||
|
output_hashes={str(canonical_path(path)):_hash(path) for path in result['outputs'].values()}, files=files)
|
||||||
|
write_record(pointer, record)
|
||||||
|
record['result'] = _authoritative_export(record)
|
||||||
|
record['capture'] = record['result']['capture']
|
||||||
|
graph, jobs = record['result']['graph'], {}
|
||||||
|
for job in proof['jobs']:
|
||||||
|
row = rows[job]
|
||||||
|
if job in evidence:
|
||||||
|
expected, binding, _ = evidence[job]
|
||||||
|
jobs[job] = _observations(graph, row, expected, binding)
|
||||||
|
else:
|
||||||
|
_verify_no_match(graph, row)
|
||||||
|
jobs[job] = dict(value_readback_status='verified',value_readback=[],value_readback_job_id=job,
|
||||||
|
project_path=row['project_path'],schematic_name=row.get('schematic_name',''),sheet_number=row.get('sheet_number',''))
|
||||||
|
if not validate_project_commit_source(proof,root) or not _intact(record) or not readbacks_intact():
|
||||||
|
raise ValueError('saved source/export or writer evidence changed during target validation')
|
||||||
|
record.update(status='verified',jobs=jobs)
|
||||||
|
verification = Path(record['export_path']).parent / 'verification.json'
|
||||||
|
verification_value = {key:record[key] for key in ('status','context','export_path','export_sha256','jobs')}
|
||||||
|
if verification.is_file():
|
||||||
|
if json.loads(verification.read_text(encoding='utf-8')) != verification_value:
|
||||||
|
raise ValueError('saved native target verification changed on resume')
|
||||||
|
else:write_record(verification,verification_value)
|
||||||
|
record.update(verification_path=str(canonical_path(verification)),verification_sha256=_hash(verification))
|
||||||
|
if not any(item['path'] == str(canonical_path(verification)) for item in record['files']):
|
||||||
|
record['files'].append({'path':str(canonical_path(verification)),'sha256':_hash(verification)})
|
||||||
|
write_record(pointer,record)
|
||||||
|
result = dict(proof, saved_netlist=compact_saved_netlist(record))
|
||||||
|
result['native_outcomes'] = outcomes
|
||||||
|
result['outcomes'] = {job:'saved_ok' if state == 'pending_save' else state for job,state in result['native_outcomes'].items()}
|
||||||
|
result['files'] = list({(item['path'],item['sha256']):item for item in [*proof['files'],*record['files']]}.values())
|
||||||
|
return result
|
||||||
@@ -0,0 +1,160 @@
|
|||||||
|
"""Read saved sources after native close, retrying only actual Windows locks."""
|
||||||
|
import hashlib
|
||||||
|
import json
|
||||||
|
import os
|
||||||
|
from pathlib import Path
|
||||||
|
import time
|
||||||
|
|
||||||
|
from .errors import TaskCenterError
|
||||||
|
from .file_lock_diagnostics import locking_processes
|
||||||
|
from .path_access import internal_path
|
||||||
|
|
||||||
|
|
||||||
|
LOCK_WAIT_SECONDS = 3.0
|
||||||
|
|
||||||
|
|
||||||
|
class SavedSourceReadError(TaskCenterError):
|
||||||
|
def __init__(self, error, path, *, interrupted=False):
|
||||||
|
self.winerror = getattr(error, 'winerror', None)
|
||||||
|
self.path = str(path)
|
||||||
|
self.retryable = self.winerror in (32, 33)
|
||||||
|
self.interrupted = interrupted
|
||||||
|
reason = '核验已暂停' if interrupted else '数据库仍被占用' if self.retryable else '源文件读取失败'
|
||||||
|
super().__init__('saved_source_pending',
|
||||||
|
f'工程已返回保存,{reason},结果待核验;不会重复替换。文件:{path};Windows 错误码:{self.winerror};{error}')
|
||||||
|
|
||||||
|
|
||||||
|
def source_hash(path):
|
||||||
|
"""Retain CreateFile's error code; Python open can reduce sharing errors to EACCES."""
|
||||||
|
path = internal_path(path)
|
||||||
|
if os.name != 'nt':
|
||||||
|
with path.open('rb') as stream:
|
||||||
|
return hashlib.file_digest(stream, 'sha256').hexdigest()
|
||||||
|
import msvcrt
|
||||||
|
import pywintypes
|
||||||
|
import win32file
|
||||||
|
try:
|
||||||
|
# Match the CRT reads used by subsequent source validation.
|
||||||
|
handle = win32file.CreateFile(str(path), 0x80000000, 3, None, 3, 0, None)
|
||||||
|
except pywintypes.error as error:
|
||||||
|
failure = OSError(error.winerror, error.strerror, str(path))
|
||||||
|
failure.winerror = error.winerror
|
||||||
|
raise failure from error
|
||||||
|
try:
|
||||||
|
fd = msvcrt.open_osfhandle(int(handle), os.O_RDONLY | os.O_BINARY)
|
||||||
|
handle.Detach() # The file descriptor now owns this handle.
|
||||||
|
finally:
|
||||||
|
handle.Close()
|
||||||
|
with os.fdopen(fd, 'rb') as stream:
|
||||||
|
return hashlib.file_digest(stream, 'sha256').hexdigest()
|
||||||
|
|
||||||
|
|
||||||
|
def bind_sources(proof, data_root, root, project, *, stop_event=None, release_mentor=None):
|
||||||
|
from .batch_resources import write_record
|
||||||
|
from .operation_diagnostics import record_operation
|
||||||
|
from .project_session_health import _source_parameters, _source_digest
|
||||||
|
from .project_isolation import write_sources
|
||||||
|
from .worker_monitor import _publish_progress
|
||||||
|
root = Path(root)
|
||||||
|
parameters = _source_parameters(Path(project), data_root)
|
||||||
|
started = time.monotonic()
|
||||||
|
deadline = started + LOCK_WAIT_SECONDS
|
||||||
|
status = dict(session_token=proof.get('session_token'), project_path=str(project),
|
||||||
|
replacement_replayed=False, mentor_released_for_read=False)
|
||||||
|
try:
|
||||||
|
prior = json.loads(internal_path(root / 'saved-source-status.json').read_text(encoding='utf-8'))
|
||||||
|
if (proof.get('session_token') and prior.get('session_token') == proof['session_token']
|
||||||
|
and prior.get('project_path', '').casefold() == str(project).casefold()):
|
||||||
|
status.update({key: prior[key] for key in ('first_error', 'last_error', 'lock_observation') if key in prior})
|
||||||
|
status['mentor_released_for_read'] = prior.get('mentor_released_for_read') is True
|
||||||
|
except (OSError, ValueError, AttributeError, TypeError):
|
||||||
|
pass # Historical diagnostics never authorize a saved result.
|
||||||
|
last_lock = None
|
||||||
|
observed = False
|
||||||
|
released_this_call = False
|
||||||
|
|
||||||
|
def publish(state, error=None):
|
||||||
|
status.update(state=state, elapsed_seconds=time.monotonic()-started)
|
||||||
|
if error is not None:
|
||||||
|
status['last_error'] = dict(path=getattr(error, 'path', str(project)),
|
||||||
|
winerror=getattr(error, 'winerror', None), message=str(error))
|
||||||
|
status.setdefault('first_error', status['last_error'])
|
||||||
|
write_record(root / 'saved-source-status.json', status)
|
||||||
|
try:
|
||||||
|
progress = json.loads(internal_path(root / 'worker-progress.json').read_text(encoding='utf-8'))
|
||||||
|
except (OSError, ValueError):
|
||||||
|
progress = {}
|
||||||
|
if not isinstance(progress, dict) or type(progress.get('sequence', 0)) is not int:
|
||||||
|
progress = {}
|
||||||
|
progress.update(stage='saved_source_wait' if state in {'waiting', 'releasing_mentor'} else
|
||||||
|
'awaiting_reconciliation' if state == 'pending' else 'verify_saved_project',
|
||||||
|
wait_reason='readback', waiting_for_safe_completion=False,
|
||||||
|
sequence=progress.get('sequence', 0)+1, stage_seconds={})
|
||||||
|
if state == 'pending': progress['primary_error'] = str(error)
|
||||||
|
_publish_progress(internal_path(root / 'worker-progress.json'), progress)
|
||||||
|
|
||||||
|
def publish_read(state, error):
|
||||||
|
try:
|
||||||
|
publish(state, error)
|
||||||
|
except Exception as diagnostic:
|
||||||
|
error.add_note('保存源文件交接状态记录失败:' + str(diagnostic))
|
||||||
|
raise error from diagnostic
|
||||||
|
|
||||||
|
def check_paused():
|
||||||
|
if last_lock is not None and stop_event is not None and stop_event.is_set():
|
||||||
|
raise SavedSourceReadError(last_lock[0], last_lock[1], interrupted=True) from last_lock[0]
|
||||||
|
|
||||||
|
record_operation(root, 'saved_source_bind', 'enter', item_id=proof.get('session_token', ''))
|
||||||
|
try:
|
||||||
|
while True:
|
||||||
|
check_paused()
|
||||||
|
path = project
|
||||||
|
try:
|
||||||
|
before = _source_digest(parameters)
|
||||||
|
hashes = {}
|
||||||
|
for path in sorted(write_sources(project)):
|
||||||
|
hashes[path] = source_hash(path)
|
||||||
|
if not before or before != _source_digest(parameters):
|
||||||
|
raise TaskCenterError('saved_source_changed', '保存后的源文件仍在变化,结果待核验;不会重复替换。')
|
||||||
|
except OSError as failure:
|
||||||
|
error = SavedSourceReadError(failure, path)
|
||||||
|
stopped = stop_event is not None and stop_event.is_set()
|
||||||
|
if stopped:
|
||||||
|
raise SavedSourceReadError(failure, path, interrupted=True) from failure
|
||||||
|
if not error.retryable:
|
||||||
|
raise error from failure
|
||||||
|
last_lock = failure, path
|
||||||
|
if not observed:
|
||||||
|
publish_read('waiting', error)
|
||||||
|
status['lock_observation'] = locking_processes(path)
|
||||||
|
observed = True
|
||||||
|
continue # The lock may have disappeared during this diagnostic.
|
||||||
|
if time.monotonic() >= deadline:
|
||||||
|
if release_mentor is None or released_this_call:
|
||||||
|
raise error from failure
|
||||||
|
publish_read('releasing_mentor', error)
|
||||||
|
check_paused()
|
||||||
|
release_mentor(error)
|
||||||
|
released_this_call = True
|
||||||
|
status['mentor_released_for_read'] = True
|
||||||
|
deadline = time.monotonic() + LOCK_WAIT_SECONDS
|
||||||
|
else:
|
||||||
|
if status.get('state') != 'waiting': publish_read('waiting', error)
|
||||||
|
time.sleep(.05)
|
||||||
|
continue
|
||||||
|
|
||||||
|
command_hash = hashlib.sha256(internal_path(root / 'command.tsv').read_bytes()).hexdigest()
|
||||||
|
check_paused()
|
||||||
|
try:
|
||||||
|
publish('bound')
|
||||||
|
except OSError as diagnostic:
|
||||||
|
record_operation(root, 'saved_source_diagnostic', 'error', error=str(diagnostic))
|
||||||
|
record_operation(root, 'saved_source_bind', 'return', item_id=proof.get('session_token', ''))
|
||||||
|
return dict(proof, **parameters, source_sha256=before, saved_sources=hashes, command_sha256=command_hash)
|
||||||
|
except Exception as error:
|
||||||
|
record_operation(root, 'saved_source_bind', 'error', item_id=proof.get('session_token', ''), error=str(error))
|
||||||
|
try:
|
||||||
|
publish('pending', error)
|
||||||
|
except Exception as diagnostic:
|
||||||
|
error.add_note('保存源文件交接状态记录失败:' + str(diagnostic))
|
||||||
|
raise
|
||||||
@@ -102,6 +102,14 @@ def _default_path_opener(path: Path) -> None:
|
|||||||
class TaskCenterService:
|
class TaskCenterService:
|
||||||
"""The only API used by UI workers and widgets."""
|
"""The only API used by UI workers and widgets."""
|
||||||
|
|
||||||
|
@property
|
||||||
|
def verification(self):
|
||||||
|
with self._store._lock:
|
||||||
|
if not hasattr(self, '_verification_service'):
|
||||||
|
from .verification.service import VerificationService
|
||||||
|
self._verification_service = VerificationService(self._store, self._logging.root)
|
||||||
|
return self._verification_service
|
||||||
|
|
||||||
def __init__(
|
def __init__(
|
||||||
self,
|
self,
|
||||||
store: TaskStore,
|
store: TaskStore,
|
||||||
@@ -237,7 +245,8 @@ class TaskCenterService:
|
|||||||
on_phase(BomImportPhase.READING, message)
|
on_phase(BomImportPhase.READING, message)
|
||||||
if on_progress is not None:
|
if on_progress is not None:
|
||||||
on_progress(message)
|
on_progress(message)
|
||||||
rows = load_sources(sources, stop_event=stop_event, on_progress=on_progress,
|
warnings = []
|
||||||
|
rows = load_sources(sources, stop_event=stop_event, on_progress=on_progress, warnings=warnings,
|
||||||
**({'allow_partial': True} if allow_partial else {}))
|
**({'allow_partial': True} if allow_partial else {}))
|
||||||
scope = _scope(self._store, task_id)
|
scope = _scope(self._store, task_id)
|
||||||
paths = tuple(project.path for _, project in scope)
|
paths = tuple(project.path for _, project in scope)
|
||||||
@@ -270,7 +279,7 @@ class TaskCenterService:
|
|||||||
reason = '位号在 BOM 中重复(' + ';'.join(locations) + ')'
|
reason = '位号在 BOM 中重复(' + ';'.join(locations) + ')'
|
||||||
annotated.append(replace(row, source_file=str(source.source), source_row=source.excel_row,
|
annotated.append(replace(row, source_file=str(source.source), source_row=source.excel_row,
|
||||||
reason=reason + f';来源:{source.source} 第 {source.excel_row} 行'))
|
reason=reason + f';来源:{source.source} 第 {source.excel_row} 行'))
|
||||||
annotated_report = replace(report, rows=tuple(annotated), source_map_path=mapping)
|
annotated_report = replace(report, rows=tuple(annotated), source_map_path=mapping, warnings=tuple(warnings))
|
||||||
return bind_source_report(annotated_report,
|
return bind_source_report(annotated_report,
|
||||||
tuple(dict.fromkeys((str(row.source), row.source_sha256) for row in rows)), mapping)
|
tuple(dict.fromkeys((str(row.source), row.source_sha256) for row in rows)), mapping)
|
||||||
|
|
||||||
@@ -282,7 +291,8 @@ class TaskCenterService:
|
|||||||
write_routed_bom(normalized, rows, routes, project_names=names)
|
write_routed_bom(normalized, rows, routes, project_names=names)
|
||||||
append_task_event(self._logging, level='INFO', task_id=task_id,
|
append_task_event(self._logging, level='INFO', task_id=task_id,
|
||||||
operation='preview_bom_sources', message='BOM 导入来源记录已保存',
|
operation='preview_bom_sources', message='BOM 导入来源记录已保存',
|
||||||
details={'source_map_path': str(mapping), 'source_count': len({row.source for row in rows})})
|
details={'source_map_path': str(mapping), 'source_count': len({row.source for row in rows}),
|
||||||
|
'warnings': warnings})
|
||||||
report = inspect_batch(self, task_id, normalized, stop_event=stop_event,
|
report = inspect_batch(self, task_id, normalized, stop_event=stop_event,
|
||||||
on_progress=on_progress, on_phase=inspection_phase, runtime=runtime,
|
on_progress=on_progress, on_phase=inspection_phase, runtime=runtime,
|
||||||
**({'allow_partial': True} if allow_partial else {}))
|
**({'allow_partial': True} if allow_partial else {}))
|
||||||
@@ -1070,10 +1080,10 @@ class TaskCenterService:
|
|||||||
return self._operation('force_pending_owned_resources', None,
|
return self._operation('force_pending_owned_resources', None,
|
||||||
lambda: force_pending_owned_resources(self._logging.root, confirmed=confirmed))
|
lambda: force_pending_owned_resources(self._logging.root, confirmed=confirmed))
|
||||||
|
|
||||||
def cleanup_batch_resources(self):
|
def cleanup_batch_resources(self, *, automatic=False):
|
||||||
"""Retry owned-resource release without opening or changing any project."""
|
"""Retry owned-resource release without opening or changing any project."""
|
||||||
if self._supervised:
|
if self._supervised:
|
||||||
result = self._supervise('cleanup_batch_resources', {})
|
self._supervise('cleanup_batch_resources', {'automatic': True} if automatic else {})
|
||||||
from .batch_supervisor import reconcile_supervisors
|
from .batch_supervisor import reconcile_supervisors
|
||||||
reconcile_supervisors(self._logging.root)
|
reconcile_supervisors(self._logging.root)
|
||||||
return self.pending_batch_resources()
|
return self.pending_batch_resources()
|
||||||
@@ -1082,7 +1092,7 @@ class TaskCenterService:
|
|||||||
assert_task_queue_idle(self._logging.root)
|
assert_task_queue_idle(self._logging.root)
|
||||||
with _quick_run_lease(self._logging.root):
|
with _quick_run_lease(self._logging.root):
|
||||||
return self._operation('cleanup_batch_resources', None,
|
return self._operation('cleanup_batch_resources', None,
|
||||||
lambda: cleanup_pending_resources(self._logging.root, logging_context=self._logging, retry_failed=True))
|
lambda: cleanup_pending_resources(self._logging.root, logging_context=self._logging, retry_failed=not automatic))
|
||||||
|
|
||||||
def inspect_bom_batch(self, task_id: str, path: Path, *, stop_event=None, on_progress=None, on_phase=None, runtime=None):
|
def inspect_bom_batch(self, task_id: str, path: Path, *, stop_event=None, on_progress=None, on_phase=None, runtime=None):
|
||||||
if runtime is None and self._supervised:
|
if runtime is None and self._supervised:
|
||||||
@@ -1117,8 +1127,9 @@ class TaskCenterService:
|
|||||||
summary='quick_run_result:failed | '+message)
|
summary='quick_run_result:failed | '+message)
|
||||||
if task.status in {TaskStatus.DRAFT,TaskStatus.READY,TaskStatus.PAUSED}:
|
if task.status in {TaskStatus.DRAFT,TaskStatus.READY,TaskStatus.PAUSED}:
|
||||||
self._store.set_task_status(task_id,TaskStatus.RUNNING,summary=summary)
|
self._store.set_task_status(task_id,TaskStatus.RUNNING,summary=summary)
|
||||||
|
self._store.set_task_status(task_id,TaskStatus.FAILED,summary=summary)
|
||||||
elif task.status is TaskStatus.RUNNING:
|
elif task.status is TaskStatus.RUNNING:
|
||||||
self._store.set_task_status(task_id,TaskStatus.RUNNING,summary=summary)
|
self._store.set_task_status(task_id,TaskStatus.FAILED,summary=summary)
|
||||||
HistoryRepository(self._store).append(task_id=task_id,task_name=task.name,
|
HistoryRepository(self._store).append(task_id=task_id,task_name=task.name,
|
||||||
operation='工程执行收尾',state='failed',summary='本工程安全失败,剩余项暂缓;继续后续工程。',
|
operation='工程执行收尾',state='failed',summary='本工程安全失败,剩余项暂缓;继续后续工程。',
|
||||||
details={'reason':message})
|
details={'reason':message})
|
||||||
@@ -1147,7 +1158,15 @@ class TaskCenterService:
|
|||||||
child._quick_run_preparer.data_root, started_after)
|
child._quick_run_preparer.data_root, started_after)
|
||||||
if getattr(self, '_supervisor_waiting', False):
|
if getattr(self, '_supervisor_waiting', False):
|
||||||
from dataclasses import replace
|
from dataclasses import replace
|
||||||
value = replace(value, stage='awaiting_reconciliation', waiting_for_safe_completion=True)
|
from .execution_feedback import wait_reason_for_stage
|
||||||
|
state = getattr(self, '_supervisor_state', None) or {}
|
||||||
|
wait_reason = state.get('wait_reason') or value.wait_reason or wait_reason_for_stage(value.stage)
|
||||||
|
stopping_reason = state.get('stopping_reason') or value.stopping_reason
|
||||||
|
if not stopping_reason and getattr(self, '_supervisor_business_stalled', False):
|
||||||
|
stopping_reason = 'inactivity'
|
||||||
|
value = replace(value, waiting_for_safe_completion=True,
|
||||||
|
wait_reason=wait_reason, stopping_reason=stopping_reason,
|
||||||
|
primary_error=state.get('primary_error') or value.primary_error)
|
||||||
if read_control is not None:
|
if read_control is not None:
|
||||||
read_control.checkpoint()
|
read_control.checkpoint()
|
||||||
return value
|
return value
|
||||||
@@ -1175,6 +1194,38 @@ class TaskCenterService:
|
|||||||
return self._quick_run_preparer.has_interrupted(task_id)
|
return self._quick_run_preparer.has_interrupted(task_id)
|
||||||
|
|
||||||
def recover_quick_run(self, task_id: str, *, confirmed: bool = False, runtime=None, stop_event=None) -> QuickRunStepResult:
|
def recover_quick_run(self, task_id: str, *, confirmed: bool = False, runtime=None, stop_event=None) -> QuickRunStepResult:
|
||||||
|
if self._store.get_task(task_id).status is TaskStatus.DELETED:
|
||||||
|
raise TaskCenterError("quick_run_recovery", "请先恢复已删除的任务记录,再核验其中断步骤。")
|
||||||
|
from .project_isolation import dependency_block, recover_dependency
|
||||||
|
dependency = dependency_block(self._logging.root, task_id)
|
||||||
|
dispatched = None
|
||||||
|
if dependency is not None and dependency['state'] in {'readmission_prepared', 'readmitted'}:
|
||||||
|
with self._store._lock:
|
||||||
|
dispatched = self._store._connection.execute('''SELECT 1 FROM execution_operations o
|
||||||
|
JOIN execution_rounds r ON r.task_id=o.task_id AND r.round_id=o.round_id
|
||||||
|
WHERE o.task_id=? AND (o.attempt_id IS NOT NULL OR o.generation>0) LIMIT 1''', (task_id,)).fetchone()
|
||||||
|
if dependency is not None and not dispatched:
|
||||||
|
if stop_event is not None and stop_event.is_set():
|
||||||
|
raise TaskCenterError('operation_cancelled', '共享数据源依赖核验已取消。')
|
||||||
|
from .task_queue import assert_task_queue_idle
|
||||||
|
assert_task_queue_idle(self._logging.root)
|
||||||
|
with _quick_run_lease(self._logging.root):
|
||||||
|
return self._operation('recover_quick_run', task_id,
|
||||||
|
lambda: recover_dependency(self, task_id, confirmed=confirmed))
|
||||||
|
commit_recovery = getattr(self._project_task_service(task_id)._quick_run_preparer, 'recover_project_commit', None)
|
||||||
|
if commit_recovery is not None:
|
||||||
|
from .batch_resources import guard_pending_resources
|
||||||
|
from .task_queue import assert_task_queue_idle
|
||||||
|
assert_task_queue_idle(self._logging.root)
|
||||||
|
with _quick_run_lease(self._logging.root):
|
||||||
|
guard_pending_resources(self._logging.root)
|
||||||
|
result = self._operation('recover_project_commit', task_id,
|
||||||
|
lambda: commit_recovery(task_id, confirmed=confirmed))
|
||||||
|
if result is not None:
|
||||||
|
if self._store.get_task(task_id).status in {TaskStatus.BLOCKED, TaskStatus.FAILED, TaskStatus.PAUSED}:
|
||||||
|
self._store.set_task_status(task_id, TaskStatus.READY, summary='原工程提交已通过持久化保存回读证据核验。')
|
||||||
|
self._synchronize_quick_run_progress(task_id)
|
||||||
|
return result
|
||||||
if runtime is None and self._supervised:
|
if runtime is None and self._supervised:
|
||||||
return self._supervise('recover_quick_run', {'task_id': task_id, 'confirmed': confirmed}, stop_event=stop_event)
|
return self._supervise('recover_quick_run', {'task_id': task_id, 'confirmed': confirmed}, stop_event=stop_event)
|
||||||
if runtime is None:
|
if runtime is None:
|
||||||
@@ -1221,7 +1272,7 @@ class TaskCenterService:
|
|||||||
self._quick_run_preparer._bind_journal_handoff(task_id,
|
self._quick_run_preparer._bind_journal_handoff(task_id,
|
||||||
QuickRunResult(result.script_path, result.command_path, result.status_path,
|
QuickRunResult(result.script_path, result.command_path, result.status_path,
|
||||||
handoff_root/'quick-part-replace.log', True))
|
handoff_root/'quick-part-replace.log', True))
|
||||||
if task.status in {TaskStatus.PAUSED, TaskStatus.FAILED}:
|
if task.status in {TaskStatus.PAUSED, TaskStatus.FAILED, TaskStatus.BLOCKED}:
|
||||||
self._store.set_task_status(task_id, TaskStatus.READY, summary="interrupted quick-run reconciled")
|
self._store.set_task_status(task_id, TaskStatus.READY, summary="interrupted quick-run reconciled")
|
||||||
from .recovery_commit import marker_path
|
from .recovery_commit import marker_path
|
||||||
marker_path(self._quick_run_preparer).unlink(missing_ok=True)
|
marker_path(self._quick_run_preparer).unlink(missing_ok=True)
|
||||||
@@ -1409,8 +1460,8 @@ class TaskCenterService:
|
|||||||
rules,
|
rules,
|
||||||
copy_part_number_to_value=task.copy_part_number_to_value,
|
copy_part_number_to_value=task.copy_part_number_to_value,
|
||||||
)
|
)
|
||||||
if self._supervised:
|
if self._supervised or task.status is TaskStatus.BLOCKED:
|
||||||
return progress # Only the batch process persists live execution state.
|
return progress # BLOCKED classification changes only through explicit reconciliation.
|
||||||
by_path = {_path_key(project.path): project.project_id for project in projects}
|
by_path = {_path_key(project.path): project.project_id for project in projects}
|
||||||
project_by_id = {project.project_id: project for project in projects}
|
project_by_id = {project.project_id: project for project in projects}
|
||||||
summary_by_id = {
|
summary_by_id = {
|
||||||
@@ -1457,7 +1508,7 @@ class TaskCenterService:
|
|||||||
) or (
|
) or (
|
||||||
progress.queue_complete
|
progress.queue_complete
|
||||||
and (
|
and (
|
||||||
(bool(failed_project_ids) and (task.status is not TaskStatus.RUNNING or task.summary != retry_summary))
|
(bool(failed_project_ids) and (task.status is not TaskStatus.FAILED or task.summary != retry_summary))
|
||||||
or (not failed_project_ids and task.status is not TaskStatus.COMPLETED)
|
or (not failed_project_ids and task.status is not TaskStatus.COMPLETED)
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -0,0 +1,86 @@
|
|||||||
|
"""Hold a data-root lock while the GUI owns its database and layout."""
|
||||||
|
|
||||||
|
from contextlib import contextmanager
|
||||||
|
import errno
|
||||||
|
import os
|
||||||
|
import time
|
||||||
|
|
||||||
|
from PySide6.QtNetwork import QLocalServer, QLocalSocket
|
||||||
|
|
||||||
|
from .path_access import internal_path
|
||||||
|
from .task_queue import _os_lock
|
||||||
|
|
||||||
|
|
||||||
|
class InstanceUnavailable(RuntimeError):
|
||||||
|
pass
|
||||||
|
|
||||||
|
|
||||||
|
@contextmanager
|
||||||
|
def gui_instance(data_root):
|
||||||
|
root = internal_path(data_root)
|
||||||
|
root.mkdir(parents=True, exist_ok=True)
|
||||||
|
# OS locks release on process death. Keep the file so every contender locks the same inode.
|
||||||
|
with (root / '.gui-instance.lock').open('a+b') as handle:
|
||||||
|
identity = os.fstat(handle.fileno())
|
||||||
|
endpoint = f'DxPartReplace-{identity.st_dev:x}-{identity.st_ino:x}'
|
||||||
|
deadline = time.monotonic() + 30
|
||||||
|
while True:
|
||||||
|
try:
|
||||||
|
_os_lock(handle, True)
|
||||||
|
break
|
||||||
|
except OSError as error:
|
||||||
|
if error.errno not in (errno.EACCES, errno.EAGAIN, errno.EDEADLK):
|
||||||
|
raise
|
||||||
|
if _activate(endpoint):
|
||||||
|
yield None
|
||||||
|
return
|
||||||
|
if time.monotonic() >= deadline:
|
||||||
|
raise InstanceUnavailable('此数据目录已在使用,现有窗口暂未响应。')
|
||||||
|
time.sleep(.05)
|
||||||
|
yield endpoint
|
||||||
|
|
||||||
|
|
||||||
|
def _activate(endpoint):
|
||||||
|
socket = QLocalSocket()
|
||||||
|
socket.connectToServer(endpoint)
|
||||||
|
if not socket.waitForConnected(100):
|
||||||
|
return False
|
||||||
|
if os.name == 'nt':
|
||||||
|
import ctypes
|
||||||
|
from ctypes import wintypes
|
||||||
|
|
||||||
|
pid = wintypes.DWORD()
|
||||||
|
get_pipe_pid = ctypes.windll.kernel32.GetNamedPipeServerProcessId
|
||||||
|
get_pipe_pid.argtypes = (wintypes.HANDLE, ctypes.POINTER(wintypes.DWORD))
|
||||||
|
if get_pipe_pid(int(socket.socketDescriptor()), ctypes.byref(pid)):
|
||||||
|
ctypes.windll.user32.AllowSetForegroundWindow(pid.value)
|
||||||
|
socket.write(b'activate\n')
|
||||||
|
socket.flush()
|
||||||
|
return (socket.bytesAvailable() > 0 or socket.waitForReadyRead(1000)) and socket.readAll() == b'1'
|
||||||
|
|
||||||
|
|
||||||
|
def listen_for_activation(endpoint, activate):
|
||||||
|
server = QLocalServer()
|
||||||
|
server.setSocketOptions(QLocalServer.SocketOption.UserAccessOption)
|
||||||
|
if os.name != 'nt':
|
||||||
|
QLocalServer.removeServer(endpoint) # The lock owner can remove a crashed owner's socket.
|
||||||
|
if not server.listen(endpoint):
|
||||||
|
raise RuntimeError(server.errorString())
|
||||||
|
|
||||||
|
def accept():
|
||||||
|
while server.hasPendingConnections():
|
||||||
|
socket = server.nextPendingConnection()
|
||||||
|
|
||||||
|
def respond(socket=socket):
|
||||||
|
if socket.canReadLine() and socket.readLine() == b'activate\n':
|
||||||
|
activate()
|
||||||
|
socket.write(b'1')
|
||||||
|
socket.flush()
|
||||||
|
socket.disconnectFromServer()
|
||||||
|
|
||||||
|
socket.disconnected.connect(socket.deleteLater)
|
||||||
|
socket.readyRead.connect(respond)
|
||||||
|
respond()
|
||||||
|
|
||||||
|
server.newConnection.connect(accept)
|
||||||
|
return server
|
||||||
@@ -80,7 +80,7 @@ def read_target_plan(store, task_id: str, path: Path) -> tuple[TargetPlanRow, ..
|
|||||||
raise ValueError("invalid or formula plan row")
|
raise ValueError("invalid or formula plan row")
|
||||||
identity = tuple("" if value is None else str(value) for value in values[:8])
|
identity = tuple("" if value is None else str(value) for value in values[:8])
|
||||||
key = (str(Path(identity[0]).resolve(strict=False)).casefold(),
|
key = (str(Path(identity[0]).resolve(strict=False)).casefold(),
|
||||||
identity[2], identity[3], identity[4])
|
identity[2], identity[3], identity[5].strip().casefold())
|
||||||
original = expected.get(key)
|
original = expected.get(key)
|
||||||
if original is None or key in by_key:
|
if original is None or key in by_key:
|
||||||
raise ValueError("forged or duplicate target")
|
raise ValueError("forged or duplicate target")
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
"""Separate ordinary stop intent from an explicitly confirmed forced interruption."""
|
"""Separate ordinary stop intent from an explicitly confirmed forced interruption."""
|
||||||
from threading import Event
|
from threading import Event
|
||||||
|
import time
|
||||||
import json
|
import json
|
||||||
import os
|
import os
|
||||||
|
|
||||||
@@ -23,6 +24,13 @@ class StopControl(Event):
|
|||||||
self.resolution_error = ''
|
self.resolution_error = ''
|
||||||
self.cleanup_mode = None
|
self.cleanup_mode = None
|
||||||
self.cleanup_reason = ''
|
self.cleanup_reason = ''
|
||||||
|
self.stopping_reason = ''
|
||||||
|
self.wait_reason = ''
|
||||||
|
self.primary_error = ''
|
||||||
|
|
||||||
|
def set(self):
|
||||||
|
self.stopping_reason = self.stopping_reason or 'user_pause'
|
||||||
|
super().set()
|
||||||
|
|
||||||
def request_force(self):
|
def request_force(self):
|
||||||
self.set()
|
self.set()
|
||||||
@@ -33,10 +41,64 @@ class StopControl(Event):
|
|||||||
protect_interruption(root, MENTOR_RELEASE_REQUIRED + ': ' + str(error))
|
protect_interruption(root, MENTOR_RELEASE_REQUIRED + ': ' + str(error))
|
||||||
self.cleanup_mode = MENTOR_RELEASE_REQUIRED
|
self.cleanup_mode = MENTOR_RELEASE_REQUIRED
|
||||||
self.cleanup_reason = self.cleanup_reason or str(error)
|
self.cleanup_reason = self.cleanup_reason or str(error)
|
||||||
|
self.primary_error = self.primary_error or str(error)
|
||||||
|
self.stopping_reason = 'failure_cleanup'
|
||||||
self.set()
|
self.set()
|
||||||
self.force_event.set()
|
self.force_event.set()
|
||||||
|
|
||||||
|
|
||||||
|
class _ProjectForce:
|
||||||
|
def __init__(self, parent):
|
||||||
|
self.local = Event()
|
||||||
|
self.parent = getattr(parent, 'force_event', None)
|
||||||
|
|
||||||
|
def is_set(self):
|
||||||
|
return self.local.is_set() or self.parent is not None and self.parent.is_set()
|
||||||
|
|
||||||
|
def set(self):
|
||||||
|
self.local.set()
|
||||||
|
|
||||||
|
def clear(self):
|
||||||
|
self.local.clear()
|
||||||
|
if self.parent is not None:
|
||||||
|
self.parent.clear()
|
||||||
|
|
||||||
|
def wait(self, timeout=None):
|
||||||
|
deadline = None if timeout is None else time.monotonic() + timeout
|
||||||
|
while not self.is_set():
|
||||||
|
remaining = .1 if deadline is None else min(.1, deadline - time.monotonic())
|
||||||
|
if remaining <= 0:
|
||||||
|
return False
|
||||||
|
self.local.wait(remaining)
|
||||||
|
return True
|
||||||
|
|
||||||
|
|
||||||
|
class ProjectStopControl(StopControl):
|
||||||
|
"""An engineering failure stops its owner; user pause still stops the batch."""
|
||||||
|
def __init__(self, parent):
|
||||||
|
super().__init__()
|
||||||
|
self.parent = parent
|
||||||
|
self.force_event = _ProjectForce(parent)
|
||||||
|
|
||||||
|
def is_set(self):
|
||||||
|
return self.parent.is_set() or super().is_set()
|
||||||
|
|
||||||
|
def set(self):
|
||||||
|
if self.stopping_reason in {'failure_cleanup','inactivity'}:
|
||||||
|
Event.set(self)
|
||||||
|
else:
|
||||||
|
self.parent.set()
|
||||||
|
|
||||||
|
def request_failure_cleanup(self, root, error):
|
||||||
|
protect_interruption(root, MENTOR_RELEASE_REQUIRED + ': ' + str(error))
|
||||||
|
self.stopping_reason = 'failure_cleanup'
|
||||||
|
self.cleanup_mode = MENTOR_RELEASE_REQUIRED
|
||||||
|
self.cleanup_reason = self.cleanup_reason or str(error)
|
||||||
|
self.primary_error = self.primary_error or str(error)
|
||||||
|
Event.set(self)
|
||||||
|
self.force_event.set()
|
||||||
|
|
||||||
|
|
||||||
def protect_interruption(root, reason):
|
def protect_interruption(root, reason):
|
||||||
"""Create or re-sync a marker without overwriting prior protection evidence."""
|
"""Create or re-sync a marker without overwriting prior protection evidence."""
|
||||||
root = internal_path(root)
|
root = internal_path(root)
|
||||||
@@ -69,9 +131,12 @@ def wait_for_resolution(control, root, error, *, resolved=None, release_on_failu
|
|||||||
return
|
return
|
||||||
from .worker_monitor import WorkerMonitorError, _publish_progress
|
from .worker_monitor import WorkerMonitorError, _publish_progress
|
||||||
root = internal_path(root)
|
root = internal_path(root)
|
||||||
|
control.stopping_reason = 'failure_cleanup' if release_on_failure else (control.stopping_reason or 'inactivity')
|
||||||
|
control.wait_reason = 'reconciliation'
|
||||||
|
control.primary_error = control.primary_error or str(error)
|
||||||
control.set()
|
control.set()
|
||||||
control.waiting_for_resolution = True
|
control.waiting_for_resolution = True
|
||||||
control.resolution_error = str(error)
|
control.resolution_error = control.resolution_error or str(error)
|
||||||
def protect():
|
def protect():
|
||||||
protect_interruption(root, 'operation_interrupted: ' + str(error))
|
protect_interruption(root, 'operation_interrupted: ' + str(error))
|
||||||
try:
|
try:
|
||||||
@@ -91,7 +156,9 @@ def wait_for_resolution(control, root, error, *, resolved=None, release_on_failu
|
|||||||
record = {}
|
record = {}
|
||||||
record.update(stage='awaiting_reconciliation', waiting_for_safe_completion=True,
|
record.update(stage='awaiting_reconciliation', waiting_for_safe_completion=True,
|
||||||
resolution_error=str(error), stop_requested=True, safe_stop=False,
|
resolution_error=str(error), stop_requested=True, safe_stop=False,
|
||||||
cleanup_mode=control.cleanup_mode)
|
cleanup_mode=control.cleanup_mode, stopping_reason=control.stopping_reason,
|
||||||
|
wait_reason=control.wait_reason,
|
||||||
|
primary_error=record.get('primary_error') or control.primary_error)
|
||||||
_publish_progress(root / 'worker-progress.json', record)
|
_publish_progress(root / 'worker-progress.json', record)
|
||||||
while True:
|
while True:
|
||||||
if resolved is not None and resolved():
|
if resolved is not None and resolved():
|
||||||
|
|||||||
@@ -40,7 +40,7 @@ _TASK_TRANSITIONS = {
|
|||||||
TaskStatus.RUNNING: {TaskStatus.PAUSED, TaskStatus.COMPLETED, TaskStatus.FAILED},
|
TaskStatus.RUNNING: {TaskStatus.PAUSED, TaskStatus.COMPLETED, TaskStatus.FAILED},
|
||||||
TaskStatus.PAUSED: {TaskStatus.READY, TaskStatus.RUNNING, TaskStatus.FAILED, TaskStatus.DELETED},
|
TaskStatus.PAUSED: {TaskStatus.READY, TaskStatus.RUNNING, TaskStatus.FAILED, TaskStatus.DELETED},
|
||||||
TaskStatus.COMPLETED: {TaskStatus.DELETED},
|
TaskStatus.COMPLETED: {TaskStatus.DELETED},
|
||||||
TaskStatus.FAILED: {TaskStatus.PAUSED, TaskStatus.READY, TaskStatus.DELETED},
|
TaskStatus.FAILED: {TaskStatus.PAUSED, TaskStatus.READY, TaskStatus.RUNNING, TaskStatus.DELETED},
|
||||||
TaskStatus.DELETED: {
|
TaskStatus.DELETED: {
|
||||||
TaskStatus.DRAFT,
|
TaskStatus.DRAFT,
|
||||||
TaskStatus.READY,
|
TaskStatus.READY,
|
||||||
@@ -49,6 +49,13 @@ _TASK_TRANSITIONS = {
|
|||||||
TaskStatus.FAILED,
|
TaskStatus.FAILED,
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
for _state in (TaskStatus.DRAFT, TaskStatus.READY, TaskStatus.RUNNING, TaskStatus.PAUSED, TaskStatus.FAILED):
|
||||||
|
_TASK_TRANSITIONS[_state].add(TaskStatus.BLOCKED)
|
||||||
|
_TASK_TRANSITIONS[TaskStatus.DRAFT].update({TaskStatus.PAUSED, TaskStatus.FAILED})
|
||||||
|
_TASK_TRANSITIONS[TaskStatus.READY].add(TaskStatus.PAUSED)
|
||||||
|
_TASK_TRANSITIONS[TaskStatus.FAILED].add(TaskStatus.FAILED)
|
||||||
|
_TASK_TRANSITIONS[TaskStatus.BLOCKED] = {TaskStatus.BLOCKED, TaskStatus.PAUSED, TaskStatus.READY, TaskStatus.DELETED}
|
||||||
|
_TASK_TRANSITIONS[TaskStatus.DELETED].add(TaskStatus.BLOCKED)
|
||||||
_PROJECT_TRANSITIONS = {
|
_PROJECT_TRANSITIONS = {
|
||||||
ProjectStatus.PENDING: {ProjectStatus.CAPTURING_BEFORE, ProjectStatus.FAILED, ProjectStatus.SKIPPED},
|
ProjectStatus.PENDING: {ProjectStatus.CAPTURING_BEFORE, ProjectStatus.FAILED, ProjectStatus.SKIPPED},
|
||||||
ProjectStatus.CAPTURING_BEFORE: {ProjectStatus.AWAITING_OPERATOR, ProjectStatus.FAILED},
|
ProjectStatus.CAPTURING_BEFORE: {ProjectStatus.AWAITING_OPERATOR, ProjectStatus.FAILED},
|
||||||
@@ -467,7 +474,8 @@ class TaskStore:
|
|||||||
"""Persist current-sheet quick-run progress independently of manual attempts."""
|
"""Persist current-sheet quick-run progress independently of manual attempts."""
|
||||||
with self.transaction():
|
with self.transaction():
|
||||||
task = self.get_task(task_id)
|
task = self.get_task(task_id)
|
||||||
allowed_task_states = {TaskStatus.DRAFT, TaskStatus.READY, TaskStatus.RUNNING, TaskStatus.PAUSED, TaskStatus.COMPLETED}
|
allowed_task_states = {TaskStatus.DRAFT, TaskStatus.READY, TaskStatus.RUNNING, TaskStatus.PAUSED,
|
||||||
|
TaskStatus.COMPLETED, TaskStatus.FAILED}
|
||||||
if task.status not in allowed_task_states:
|
if task.status not in allowed_task_states:
|
||||||
raise TaskCenterError("quick_run_task_state", "task state does not allow quick-run progress")
|
raise TaskCenterError("quick_run_task_state", "task state does not allow quick-run progress")
|
||||||
for project_id in completed_project_ids:
|
for project_id in completed_project_ids:
|
||||||
@@ -512,7 +520,7 @@ class TaskStore:
|
|||||||
"quick-run queue completed before project states were synchronized",
|
"quick-run queue completed before project states were synchronized",
|
||||||
)
|
)
|
||||||
has_failures = any(project.status is ProjectStatus.FAILED for project in selected)
|
has_failures = any(project.status is ProjectStatus.FAILED for project in selected)
|
||||||
if task.status in {TaskStatus.DRAFT, TaskStatus.READY, TaskStatus.PAUSED}:
|
if task.status in {TaskStatus.DRAFT, TaskStatus.READY, TaskStatus.PAUSED, TaskStatus.FAILED}:
|
||||||
task = self.set_task_status(
|
task = self.set_task_status(
|
||||||
task_id,
|
task_id,
|
||||||
TaskStatus.RUNNING,
|
TaskStatus.RUNNING,
|
||||||
@@ -520,10 +528,10 @@ class TaskStore:
|
|||||||
if has_failures else "current-sheet quick-run queue completed",
|
if has_failures else "current-sheet quick-run queue completed",
|
||||||
)
|
)
|
||||||
if has_failures:
|
if has_failures:
|
||||||
if task.status is TaskStatus.RUNNING and task.summary != "current-sheet quick-run queue completed with retryable failures":
|
if task.status is TaskStatus.RUNNING:
|
||||||
task = self.set_task_status(
|
task = self.set_task_status(
|
||||||
task_id,
|
task_id,
|
||||||
TaskStatus.RUNNING,
|
TaskStatus.FAILED,
|
||||||
summary="current-sheet quick-run queue completed with retryable failures",
|
summary="current-sheet quick-run queue completed with retryable failures",
|
||||||
)
|
)
|
||||||
else:
|
else:
|
||||||
|
|||||||
@@ -65,6 +65,8 @@ class StoreSchema:
|
|||||||
from .execution_journal import create_execution_schema
|
from .execution_journal import create_execution_schema
|
||||||
create_history_schema(self._store._connection)
|
create_history_schema(self._store._connection)
|
||||||
create_execution_schema(self._store._connection)
|
create_execution_schema(self._store._connection)
|
||||||
|
from .verification.store import create_schema as create_verification_schema
|
||||||
|
create_verification_schema(self._store._connection)
|
||||||
|
|
||||||
def _create_schema_v1(self) -> None:
|
def _create_schema_v1(self) -> None:
|
||||||
statements = (
|
statements = (
|
||||||
|
|||||||
@@ -20,7 +20,8 @@ class ProjectIdentityResolver:
|
|||||||
return self._projects[spelling]
|
return self._projects[spelling]
|
||||||
|
|
||||||
def target(self, target):
|
def target(self, target):
|
||||||
return (self.project(target.project_path), target.schematic_name, target.sheet_number, target.uid)
|
return (self.project(target.project_path), target.schematic_name, target.sheet_number,
|
||||||
|
target.refdes.strip().casefold())
|
||||||
|
|
||||||
|
|
||||||
@dataclass(frozen=True, slots=True)
|
@dataclass(frozen=True, slots=True)
|
||||||
@@ -36,6 +37,8 @@ class ComponentTarget:
|
|||||||
actual_cell: str | None = None
|
actual_cell: str | None = None
|
||||||
|
|
||||||
def __post_init__(self) -> None:
|
def __post_init__(self) -> None:
|
||||||
|
if not self.uid and self.refdes:
|
||||||
|
object.__setattr__(self, 'uid', '@REFDES|' + self.refdes.strip())
|
||||||
if any(value is not None and not isinstance(value, str)
|
if any(value is not None and not isinstance(value, str)
|
||||||
for value in (self.actual_part_label, self.actual_cell)):
|
for value in (self.actual_part_label, self.actual_cell)):
|
||||||
raise TaskCenterError('target_inventory', 'effective Part Label and Cell must be text or unknown')
|
raise TaskCenterError('target_inventory', 'effective Part Label and Cell must be text or unknown')
|
||||||
@@ -118,7 +121,7 @@ def compile_target_rules(rows: tuple[TargetPlanRow, ...], *, default_value_mode:
|
|||||||
raise TaskCenterError("target_identity", "component identity is incomplete")
|
raise TaskCenterError("target_identity", "component identity is incomplete")
|
||||||
target_key = identities.target(target)
|
target_key = identities.target(target)
|
||||||
if target_key in seen:
|
if target_key in seen:
|
||||||
raise TaskCenterError("target_overlap", "target UID appears more than once")
|
raise TaskCenterError("target_overlap", "target reference appears more than once")
|
||||||
seen.add(target_key)
|
seen.add(target_key)
|
||||||
if not row.enabled:
|
if not row.enabled:
|
||||||
continue
|
continue
|
||||||
|
|||||||
@@ -23,7 +23,8 @@ def archive_completed_session(service):
|
|||||||
|
|
||||||
def _archive(service):
|
def _archive(service):
|
||||||
store = service._store
|
store = service._store
|
||||||
pending = service.pending_batch_resources()
|
from .batch_resources import resource_blockers
|
||||||
|
pending = resource_blockers(service.pending_batch_resources())
|
||||||
owned = set()
|
owned = set()
|
||||||
unknown = False
|
unknown = False
|
||||||
for record in pending:
|
for record in pending:
|
||||||
@@ -39,7 +40,7 @@ def _archive(service):
|
|||||||
reason = None
|
reason = None
|
||||||
if unknown or task.task_id in owned:
|
if unknown or task.task_id in owned:
|
||||||
reason = '后台资源尚未确认释放;重新打开后使用“重新清理资源”。'
|
reason = '后台资源尚未确认释放;重新打开后使用“重新清理资源”。'
|
||||||
elif task.status is TaskStatus.RUNNING:
|
elif task.status in {TaskStatus.RUNNING, TaskStatus.BLOCKED}:
|
||||||
reason = '任务仍在执行状态;重新打开后暂停或核验恢复。'
|
reason = '任务仍在执行状态;重新打开后暂停或核验恢复。'
|
||||||
elif any(project.status in {ProjectStatus.CAPTURING_BEFORE, ProjectStatus.AWAITING_OPERATOR,
|
elif any(project.status in {ProjectStatus.CAPTURING_BEFORE, ProjectStatus.AWAITING_OPERATOR,
|
||||||
ProjectStatus.CAPTURING_AFTER, ProjectStatus.VERIFYING}
|
ProjectStatus.CAPTURING_AFTER, ProjectStatus.VERIFYING}
|
||||||
|
|||||||
@@ -12,6 +12,8 @@ from uuid import uuid4
|
|||||||
|
|
||||||
from .errors import TaskCenterError
|
from .errors import TaskCenterError
|
||||||
from .quick_run import _write_atomic_queue_text
|
from .quick_run import _write_atomic_queue_text
|
||||||
|
from .project_isolation import (write_sources, record_task_outcome, isolate_project,
|
||||||
|
block_dependency, dependency_block, dependency_readmitted)
|
||||||
|
|
||||||
|
|
||||||
_QUEUE_LOCK = Lock()
|
_QUEUE_LOCK = Lock()
|
||||||
@@ -181,9 +183,76 @@ def reconcile_interrupted_queue(root, journal):
|
|||||||
_save(path, state)
|
_save(path, state)
|
||||||
|
|
||||||
|
|
||||||
|
def resource_pause_admitted(root, batch_id, task_ids, plan_hashes, result=None, *, require_released=True):
|
||||||
|
"""Bind a completed supervisor's resource pause to the frozen queue."""
|
||||||
|
from .batch_resources import _process_gone, blocking_resources
|
||||||
|
from .batch_supervisor import pending_supervisors
|
||||||
|
from .path_access import canonical_path, internal_path
|
||||||
|
from .supervisor_protocol import MessageGate, decode, valid_journal
|
||||||
|
|
||||||
|
def token(value):
|
||||||
|
return isinstance(value, str) and len(value) == 32 and all(c in '0123456789abcdef' for c in value)
|
||||||
|
|
||||||
|
if not token(batch_id) or not plan_hashes:
|
||||||
|
return False
|
||||||
|
root = canonical_path(root)
|
||||||
|
directory = internal_path(root / 'batch-resources' / batch_id)
|
||||||
|
try:
|
||||||
|
journal = json.loads((directory / 'supervisor.json').read_bytes())
|
||||||
|
if (not valid_journal(journal, batch_id) or journal['state'] not in {'blocked', 'finished'}
|
||||||
|
or journal['operation'] != 'execute_task_queue' or journal['task_ids'] != list(task_ids)
|
||||||
|
or not journal['process'] or 'stop_requested_at' in journal
|
||||||
|
or journal.get('stop_mode') in {'safe', 'forced'} or (directory / 'cancel.json').exists()):
|
||||||
|
return False
|
||||||
|
raw_request = (directory / 'request.json').read_bytes()
|
||||||
|
request = json.loads(raw_request)
|
||||||
|
arguments = decode(request['arguments'])
|
||||||
|
if (hashlib.sha256(raw_request).hexdigest() != journal['request_sha256']
|
||||||
|
or request['batch_id'] != batch_id or request['attempt_id'] != journal['attempt_id']
|
||||||
|
or request['operation'] != journal['operation'] or canonical_path(request['root']) != root
|
||||||
|
or list(arguments['task_ids']) != list(task_ids) or arguments['expected_plan_hashes'] != plan_hashes):
|
||||||
|
return False
|
||||||
|
message = json.loads((directory / 'result.json').read_bytes())
|
||||||
|
if not MessageGate(batch_id, journal['attempt_id']).accept(message) or message['type'] != 'result':
|
||||||
|
return False
|
||||||
|
payload = message['payload']
|
||||||
|
recorded = decode(payload['result'])
|
||||||
|
if (payload['business_succeeded'] is not True or not isinstance(recorded, TaskQueueResult)
|
||||||
|
or result is not None and recorded != result or not recorded.paused
|
||||||
|
or not token(recorded.queue_id) or recorded.current_task_id not in task_ids
|
||||||
|
or (arguments['queue_id'] or arguments['checkpoint_id']) != recorded.queue_id):
|
||||||
|
return False
|
||||||
|
result = recorded
|
||||||
|
checkpoint = internal_path(root / 'task-queues' / (result.queue_id + '.json'))
|
||||||
|
state = json.loads(checkpoint.read_bytes())
|
||||||
|
current = result.current_task_id
|
||||||
|
if (state['version'] != 1 or state['task_ids'] != list(task_ids) or state['plan_hashes'] != plan_hashes
|
||||||
|
or state['phase'] != 'primary' or set(state['entries']) != set(task_ids)
|
||||||
|
or list(entry.task_id for entry in result.entries) != list(task_ids)
|
||||||
|
or any(state['entries'][entry.task_id]['state'] != entry.state for entry in result.entries)
|
||||||
|
or state['entries'][current]['state'] != 'blocked'
|
||||||
|
or any(entry.state in {'paused', 'running'} for entry in result.entries)
|
||||||
|
or not any(state['entries'][item]['state'] == 'pending' for item in task_ids[task_ids.index(current) + 1:])):
|
||||||
|
return False
|
||||||
|
if batch_id in state.get('consumed_resource_pauses', {}):
|
||||||
|
return False
|
||||||
|
warning = payload.get('resource_warning') or {}
|
||||||
|
pause = state.get('resource_pause') or {}
|
||||||
|
intended = ((pause.get('task_id'), pause.get('batch_id')) == (current, batch_id)
|
||||||
|
and isinstance(pause.get('sources'), dict)
|
||||||
|
and set(pause['sources']) == set(task_ids)
|
||||||
|
or not pause and warning.get('state') == 'isolated' and warning.get('owned_writers_exited') is True)
|
||||||
|
if intended and (not require_released or (journal['state'] == 'finished'
|
||||||
|
and _process_gone(journal['process']) and not blocking_resources(root) and not pending_supervisors(root))):
|
||||||
|
return result
|
||||||
|
return False
|
||||||
|
except (OSError, ValueError, TypeError, KeyError, AttributeError):
|
||||||
|
return False
|
||||||
|
|
||||||
|
|
||||||
def execute_task_queue(service, task_ids: tuple[str, ...], *, stop_event: Event,
|
def execute_task_queue(service, task_ids: tuple[str, ...], *, stop_event: Event,
|
||||||
queue_id: str | None = None, runtime=None, expected_plan_hashes=None, checkpoint_id=None,
|
queue_id: str | None = None, runtime=None, expected_plan_hashes=None, checkpoint_id=None,
|
||||||
defer_problem_pass=False) -> TaskQueueResult:
|
defer_problem_pass=False, resource_batch_id=None) -> TaskQueueResult:
|
||||||
"""Execute the frozen order; uncertain state stops before the next project."""
|
"""Execute the frozen order; uncertain state stops before the next project."""
|
||||||
if runtime is None and getattr(service, '_supervised', False):
|
if runtime is None and getattr(service, '_supervised', False):
|
||||||
# Existing per-project checkpoints keep their original resume owner.
|
# Existing per-project checkpoints keep their original resume owner.
|
||||||
@@ -194,9 +263,30 @@ def execute_task_queue(service, task_ids: tuple[str, ...], *, stop_event: Event,
|
|||||||
return execute_workspace_projects(service, task_ids, queue_id=queue_id, stop_event=stop_event,
|
return execute_workspace_projects(service, task_ids, queue_id=queue_id, stop_event=stop_event,
|
||||||
expected_plan_hashes=expected_plan_hashes, checkpoint_id=checkpoint_id,
|
expected_plan_hashes=expected_plan_hashes, checkpoint_id=checkpoint_id,
|
||||||
defer_problem_pass=defer_problem_pass)
|
defer_problem_pass=defer_problem_pass)
|
||||||
return service._supervise('execute_task_queue', {'task_ids': tuple(task_ids),
|
arguments = {'task_ids': tuple(task_ids),
|
||||||
'queue_id': queue_id, 'expected_plan_hashes': expected_plan_hashes,
|
'queue_id': queue_id, 'expected_plan_hashes': expected_plan_hashes,
|
||||||
'checkpoint_id': checkpoint_id, 'defer_problem_pass': defer_problem_pass}, stop_event=stop_event)
|
'checkpoint_id': checkpoint_id, 'defer_problem_pass': defer_problem_pass}
|
||||||
|
if resource_batch_id:
|
||||||
|
arguments['resource_batch_id'] = resource_batch_id
|
||||||
|
recovered = set()
|
||||||
|
while True:
|
||||||
|
try:
|
||||||
|
result = service._supervise('execute_task_queue', arguments, stop_event=stop_event)
|
||||||
|
except TaskCenterError as error:
|
||||||
|
result = getattr(error, 'completed_result', None)
|
||||||
|
batch_id = getattr(service, '_last_supervisor_batch_id', None)
|
||||||
|
if (error.code not in {'batch_resources_pending', 'application_shutdown_failed'}
|
||||||
|
or stop_event.is_set() or not isinstance(result, TaskQueueResult)
|
||||||
|
or not resource_pause_admitted(service._logging.root, batch_id, tuple(task_ids),
|
||||||
|
expected_plan_hashes, result, require_released=False)):
|
||||||
|
raise
|
||||||
|
if (not result.paused or stop_event.is_set() or result.current_task_id in recovered
|
||||||
|
or not resource_pause_admitted(service._logging.root,
|
||||||
|
batch_id := getattr(service, '_last_supervisor_batch_id', None), tuple(task_ids),
|
||||||
|
expected_plan_hashes, result)):
|
||||||
|
return result
|
||||||
|
recovered.add(result.current_task_id)
|
||||||
|
arguments = dict(arguments, queue_id=result.queue_id, checkpoint_id=None, resource_batch_id=batch_id)
|
||||||
if runtime is None:
|
if runtime is None:
|
||||||
from .batch_runtime import BatchCadRuntime
|
from .batch_runtime import BatchCadRuntime
|
||||||
with BatchCadRuntime(service._logging.root, 'task_queue', stop_event) as owned_runtime:
|
with BatchCadRuntime(service._logging.root, 'task_queue', stop_event) as owned_runtime:
|
||||||
@@ -211,15 +301,22 @@ def execute_task_queue(service, task_ids: tuple[str, ...], *, stop_event: Event,
|
|||||||
root = service._logging.root
|
root = service._logging.root
|
||||||
with _queue_lease(root):
|
with _queue_lease(root):
|
||||||
children = {task_id: service.for_project_task(task_id) for task_id in ids}
|
children = {task_id: service.for_project_task(task_id) for task_id in ids}
|
||||||
project_paths = []
|
project_paths, projects_by_task = [], {}
|
||||||
|
sources = {}
|
||||||
for task_id, child in children.items():
|
for task_id, child in children.items():
|
||||||
task = child.get_task(task_id)
|
task = child.get_task(task_id)
|
||||||
projects = child.projects(task_id)
|
projects = child.projects(task_id)
|
||||||
if not getattr(task, 'primary_project_id', None) or len(projects) != 1:
|
if not getattr(task, 'primary_project_id', None) or len(projects) != 1:
|
||||||
raise TaskCenterError('project_binding', '顺序执行仅支持绑定单个工程的任务。')
|
raise TaskCenterError('project_binding', '顺序执行仅支持绑定单个工程的任务。')
|
||||||
project_paths.append(str(projects[0].path.resolve(strict=False)).casefold())
|
project_paths.append(str(projects[0].path.resolve(strict=False)).casefold())
|
||||||
|
projects_by_task[task_id] = projects[0].path
|
||||||
|
sources[task_id] = write_sources(projects[0].path)
|
||||||
if len(set(project_paths)) != len(ids):
|
if len(set(project_paths)) != len(ids):
|
||||||
raise TaskCenterError('task_queue_selection', '不能在同一队列重复处理同一个工程。')
|
raise TaskCenterError('task_queue_selection', '不能在同一队列重复处理同一个工程。')
|
||||||
|
try:
|
||||||
|
frozen_sources = {item: sorted(write_sources(projects_by_task[item], strict=True)) for item in ids}
|
||||||
|
except (OSError, UnicodeError, ValueError):
|
||||||
|
frozen_sources = None
|
||||||
runtime.bind_logs(service._logging, ids)
|
runtime.bind_logs(service._logging, ids)
|
||||||
hashes = {task_id: _plan_hash(child, task_id) for task_id, child in children.items()}
|
hashes = {task_id: _plan_hash(child, task_id) for task_id, child in children.items()}
|
||||||
if expected_plan_hashes is not None and hashes != expected_plan_hashes:
|
if expected_plan_hashes is not None and hashes != expected_plan_hashes:
|
||||||
@@ -251,19 +348,75 @@ def execute_task_queue(service, task_ids: tuple[str, ...], *, stop_event: Event,
|
|||||||
_save(path, state)
|
_save(path, state)
|
||||||
paused = False
|
paused = False
|
||||||
current = None
|
current = None
|
||||||
|
from .stop_control import ProjectStopControl
|
||||||
|
parent_control = getattr(runtime, 'stop_event', None)
|
||||||
|
isolated_tasks = state.setdefault('isolated_tasks', {})
|
||||||
|
isolated_sources = state.setdefault('isolated_sources', {})
|
||||||
|
dependency_tasks = state.setdefault('dependency_tasks', {})
|
||||||
|
if resource_batch_id:
|
||||||
|
evidence = resource_pause_admitted(root, resource_batch_id, ids, hashes)
|
||||||
|
if not evidence or evidence.queue_id != queue_id:
|
||||||
|
raise TaskCenterError('task_queue_state', '原队列的资源释放或阻断回执无法核验。')
|
||||||
|
item = evidence.current_task_id
|
||||||
|
if not children[item].has_interrupted_quick_run(item):
|
||||||
|
raise TaskCenterError('task_queue_state', '阻断工程缺少原待核验证据。')
|
||||||
|
pause = state.get('resource_pause')
|
||||||
|
if pause:
|
||||||
|
known_sources = pause['sources']
|
||||||
|
else:
|
||||||
|
before = (state.get('netlist_verification', {}).get(item, {}).get('before') or {})
|
||||||
|
known = [str(Path(name).resolve()).casefold() for name in before.get('source_hashes', {})
|
||||||
|
if Path(name).suffix.casefold() == '.prj' or Path(name).name.casefold() == 'icdb.dat']
|
||||||
|
known_sources = {item: sorted(known)}
|
||||||
|
if not frozen_sources or any(frozen_sources.get(task) != values for task, values in known_sources.items()):
|
||||||
|
raise TaskCenterError('task_queue_state', '工程写入源已变化或无法核验,须重新确认。')
|
||||||
|
sources = {task: set(values) for task, values in frozen_sources.items()}
|
||||||
|
isolated_tasks[item] = state['entries'][item]['message']
|
||||||
|
isolated_sources.update((source, item) for source in sources[item])
|
||||||
|
state.setdefault('consumed_resource_pauses', {})[resource_batch_id] = item
|
||||||
|
state.pop('resource_pause', None)
|
||||||
|
_save(path, state)
|
||||||
from .netlist_verification import NetlistVerification
|
from .netlist_verification import NetlistVerification
|
||||||
checks = NetlistVerification(root, token, stop_event)
|
checks = NetlistVerification(root, token, stop_event)
|
||||||
try:
|
try:
|
||||||
for task_id in ids:
|
for task_id in ids:
|
||||||
|
readmitted = False
|
||||||
|
if task_id in dependency_tasks:
|
||||||
|
try:
|
||||||
|
readmitted = dependency_readmitted(children[task_id], task_id, hashes[task_id])
|
||||||
|
except TaskCenterError:
|
||||||
|
pass
|
||||||
|
if readmitted:
|
||||||
|
isolated_tasks.pop(task_id, None)
|
||||||
|
dependency_tasks.pop(task_id)
|
||||||
|
state['entries'][task_id] = {'state': 'pending', 'message': '共享依赖已核验,恢复未派发原计划。'}
|
||||||
|
if task_id in isolated_tasks:
|
||||||
|
continue
|
||||||
|
conflict = next((isolated_sources[source] for source in sources[task_id]
|
||||||
|
if source in isolated_sources), None)
|
||||||
|
if conflict is not None and not readmitted and state['entries'][task_id]['state'] not in _TERMINAL:
|
||||||
|
message = f'与待核验工程 {conflict} 共享写入源,已隔离;未派发替换。'
|
||||||
|
state['entries'][task_id] = {'state': 'blocked', 'message': message}
|
||||||
|
isolated_tasks[task_id] = message
|
||||||
|
dependency_tasks[task_id] = conflict
|
||||||
|
block_dependency(root, children[task_id], task_id, conflict,
|
||||||
|
sources[task_id] & sources[conflict], hashes[task_id], token)
|
||||||
|
_save(path, state)
|
||||||
|
continue
|
||||||
if state['entries'][task_id]['state'] in _TERMINAL:
|
if state['entries'][task_id]['state'] in _TERMINAL:
|
||||||
if state['entries'][task_id]['state'] == 'completed':
|
if state['entries'][task_id]['state'] == 'completed':
|
||||||
checks.before_task(children[task_id], task_id, existing_only=True)
|
if not resource_batch_id or task_id not in state.get('netlist_verification', {}):
|
||||||
|
checks.before_task(children[task_id], task_id, existing_only=True)
|
||||||
continue
|
continue
|
||||||
if stop_event.is_set():
|
if stop_event.is_set():
|
||||||
paused = True
|
paused = True
|
||||||
break
|
break
|
||||||
current = task_id
|
current = task_id
|
||||||
child = children[task_id]
|
child = children[task_id]
|
||||||
|
project_control = ProjectStopControl(stop_event)
|
||||||
|
runtime.stop_event = project_control
|
||||||
|
if getattr(runtime, 'cad', None) is not None:
|
||||||
|
runtime.cad.stop_control = project_control
|
||||||
service._task_queue_feedback = (token, task_id, ids.index(task_id) + 1, len(ids))
|
service._task_queue_feedback = (token, task_id, ids.index(task_id) + 1, len(ids))
|
||||||
resolving_bom = False
|
resolving_bom = False
|
||||||
execution_dispatched = False
|
execution_dispatched = False
|
||||||
@@ -277,7 +430,7 @@ def execute_task_queue(service, task_ids: tuple[str, ...], *, stop_event: Event,
|
|||||||
if _plan_hash(child, task_id) != hashes[task_id]:
|
if _plan_hash(child, task_id) != hashes[task_id]:
|
||||||
raise TaskCenterError('assistant_stale', '待执行 BOM 已变化,请重新确认。')
|
raise TaskCenterError('assistant_stale', '待执行 BOM 已变化,请重新确认。')
|
||||||
resolving_bom = True
|
resolving_bom = True
|
||||||
resolved = child.resolve_pending_bom(task_id, stop_event=stop_event)
|
resolved = child.resolve_pending_bom(task_id, stop_event=project_control)
|
||||||
resolving_bom = False
|
resolving_bom = False
|
||||||
if not any(row.enabled for row in resolved):
|
if not any(row.enabled for row in resolved):
|
||||||
state['entries'][task_id] = {'state': 'skipped',
|
state['entries'][task_id] = {'state': 'skipped',
|
||||||
@@ -304,7 +457,7 @@ def execute_task_queue(service, task_ids: tuple[str, ...], *, stop_event: Event,
|
|||||||
for parameter in parameters) else {})
|
for parameter in parameters) else {})
|
||||||
checks.before_task(child, task_id)
|
checks.before_task(child, task_id)
|
||||||
execution_dispatched = True
|
execution_dispatched = True
|
||||||
result = execute(task_id, expected_item=expected, stop_event=stop_event,
|
result = execute(task_id, expected_item=expected, stop_event=project_control,
|
||||||
**runtime_options)
|
**runtime_options)
|
||||||
if child.has_interrupted_quick_run(task_id) or (
|
if child.has_interrupted_quick_run(task_id) or (
|
||||||
result.last_result is not None and result.last_result.state == 'batch_saved_unverified'
|
result.last_result is not None and result.last_result.state == 'batch_saved_unverified'
|
||||||
@@ -340,10 +493,31 @@ def execute_task_queue(service, task_ids: tuple[str, ...], *, stop_event: Event,
|
|||||||
entry = {'state': 'failed' if safe else 'paused' if error.code == 'operation_cancelled' else 'blocked',
|
entry = {'state': 'failed' if safe else 'paused' if error.code == 'operation_cancelled' else 'blocked',
|
||||||
'message': f'{error.code}: {error.message}' if resolving_bom else error.message}
|
'message': f'{error.code}: {error.message}' if resolving_bom else error.message}
|
||||||
paused = not safe
|
paused = not safe
|
||||||
|
if not safe and error.code != 'operation_cancelled' and not stop_event.is_set():
|
||||||
|
try:
|
||||||
|
isolated = isolate_project(runtime, child, task_id, error)
|
||||||
|
except Exception as cleanup_error:
|
||||||
|
entry['message'] += '; 资源收尾未确认:' + str(cleanup_error)
|
||||||
|
isolated = False
|
||||||
|
if isolated:
|
||||||
|
isolated_tasks[task_id] = entry['message']
|
||||||
|
isolated_sources.update((source,task_id) for source in sources[task_id])
|
||||||
|
paused = False
|
||||||
except Exception as error:
|
except Exception as error:
|
||||||
entry = {'state': 'blocked', 'message': str(error)}
|
entry = {'state': 'blocked', 'message': str(error)}
|
||||||
paused = True
|
paused = True
|
||||||
|
if not stop_event.is_set():
|
||||||
|
try:
|
||||||
|
isolated = isolate_project(runtime, child, task_id, error)
|
||||||
|
except Exception as cleanup_error:
|
||||||
|
entry['message'] += '; 资源收尾未确认:' + str(cleanup_error)
|
||||||
|
isolated = False
|
||||||
|
if isolated:
|
||||||
|
isolated_tasks[task_id] = entry['message']
|
||||||
|
isolated_sources.update((source,task_id) for source in sources[task_id])
|
||||||
|
paused = False
|
||||||
state['entries'][task_id] = entry
|
state['entries'][task_id] = entry
|
||||||
|
record_task_outcome(child, task_id, entry['state'], entry['message'])
|
||||||
_save(path, state)
|
_save(path, state)
|
||||||
if (entry['state'] in {'completed', 'failed'} and task_id in checks.tasks
|
if (entry['state'] in {'completed', 'failed'} and task_id in checks.tasks
|
||||||
and not child.has_interrupted_quick_run(task_id)):
|
and not child.has_interrupted_quick_run(task_id)):
|
||||||
@@ -352,6 +526,11 @@ def execute_task_queue(service, task_ids: tuple[str, ...], *, stop_event: Event,
|
|||||||
execution_summary={key: getattr(progress, key, None)
|
execution_summary={key: getattr(progress, key, None)
|
||||||
for key in ('saved_items', 'failed_items', 'no_match_items')})
|
for key in ('saved_items', 'failed_items', 'no_match_items')})
|
||||||
if paused:
|
if paused:
|
||||||
|
if (entry['state'] == 'blocked' and not stop_event.is_set()
|
||||||
|
and frozen_sources and hasattr(runtime, 'session_id')):
|
||||||
|
state['resource_pause'] = {'task_id': task_id, 'batch_id': runtime.session_id,
|
||||||
|
'sources': frozen_sources}
|
||||||
|
_save(path, state)
|
||||||
break
|
break
|
||||||
if (not paused and stop_event.is_set() and state.get('phase') != 'finished'
|
if (not paused and stop_event.is_set() and state.get('phase') != 'finished'
|
||||||
and any(entry['state'] == 'failed' for entry in state['entries'].values())):
|
and any(entry['state'] == 'failed' for entry in state['entries'].values())):
|
||||||
@@ -369,7 +548,8 @@ def execute_task_queue(service, task_ids: tuple[str, ...], *, stop_event: Event,
|
|||||||
checks.after_task(task_id, execution_state='failed' if result.progress.failed_items else 'completed',
|
checks.after_task(task_id, execution_state='failed' if result.progress.failed_items else 'completed',
|
||||||
refresh=True, execution_summary={key: getattr(result.progress, key, None)
|
refresh=True, execution_summary={key: getattr(result.progress, key, None)
|
||||||
for key in ('saved_items', 'failed_items', 'no_match_items')})
|
for key in ('saved_items', 'failed_items', 'no_match_items')})
|
||||||
retried = run_problem_pass(service, ids, token, stop_event=stop_event, runtime=runtime,
|
admitted_problem_tasks = tuple(item for item in ids if item not in isolated_tasks)
|
||||||
|
retried = run_problem_pass(service, admitted_problem_tasks, token, stop_event=stop_event, runtime=runtime,
|
||||||
on_result=capture_retry)
|
on_result=capture_retry)
|
||||||
for task_id, result in retried.results.items():
|
for task_id, result in retried.results.items():
|
||||||
state['entries'][task_id] = {'state': 'paused' if result.paused else 'failed' if result.progress.failed_items else 'completed',
|
state['entries'][task_id] = {'state': 'paused' if result.paused else 'failed' if result.progress.failed_items else 'completed',
|
||||||
@@ -416,3 +596,6 @@ def execute_task_queue(service, task_ids: tuple[str, ...], *, stop_event: Event,
|
|||||||
checks.__exit__(None, None, None)
|
checks.__exit__(None, None, None)
|
||||||
finally:
|
finally:
|
||||||
service._task_queue_feedback = None
|
service._task_queue_feedback = None
|
||||||
|
runtime.stop_event = parent_control
|
||||||
|
if getattr(runtime, 'cad', None) is not None:
|
||||||
|
runtime.cad.stop_control = parent_control
|
||||||
Loaded 100 of 241 files, more files were not shown because too many files have changed in this diff.
Show more
Reference in new issue
Block a user