diff --git a/docs/testing/2026-10-15-project-session-and-read-model.md b/docs/testing/2026-10-15-project-session-and-read-model.md new file mode 100644 index 0000000..5fb6f7f --- /dev/null +++ b/docs/testing/2026-10-15-project-session-and-read-model.md @@ -0,0 +1,49 @@ +# 工程会话、统一快照与可取消查询验证 + +本轮在原 V1.1.0 上实施用户批准的四项优化,基线为 `bc6b726`,分支为 `codex/execution-responsiveness`。完成后推送同名远端分支,不打包。真实 CAD 操作全部针对 `build/session-live-20261015` 下的独立副本。 + +## 实现 + +1. 同工程多步骤保留一个受监督的 VBS worker。每次修改仍保存、关闭、重开并回读校验,下一步复用回读后的工程;暂停、完成和换工程时关闭自有会话。随机令牌、冻结命令和图页确认继续有效。注入的模拟执行器保留原单步协议。 +2. `TaskBundle` 用一个 SQLite 只读事务读取任务、工程、规则和位号计划;`QuickRunSnapshot` 复用一次证据文件解析,检查读取前后文件代次,最多重试三次,持续变化时禁止给出续跑坐标。创建任务 facade 复用已初始化 runner,避免查询触发启动恢复写入。 +3. UI 查询最多两个运行项、一个合并后的最新待办项。切换或关闭时取消旧 token;文件分块读取、逐行解析、数据库锁和日志锁等待均检查取消。底层单次系统调用仍需返回后才能退出,线程数量保持有界。 +4. 拆出协议、快照、只读工程枚举、会话 transport、数据库迁移、位号计划存储和任务读取模块。`quick_run.py` 从 2100 行降至 1866 行,`store.py` 从 1364 行降至 1083 行;剩余执行状态机继续保留在原模块。 + +工程首次打开可能规范化数据库。发现已知内容变化后丢弃该次枚举,只允许重试一次;仍不稳定则阻断。缓存仅精确排除 `database/cdbsvr/{log,plog,events}` 运行审计目录,权威数据库及图页仍校验内容哈希;初次无法取得指纹时允许一次全新、不缓存的枚举。 + +## 真实替换对照 + +工程为 CBB `1GPHY_8211.prj` 的两份独立副本;同页 `RL02` 与 `RL05` 分两步执行,分别测试 NC 同步开、关。旧料号 `4100-CA3300-T7`,新料号 `4100-CA3300-2200`。两种方式均独立重新枚举确认:2 个选中位号改为新料号,11 个未选中位号保持旧料号。 + +| 指标 | 原单步方式 | 会话复用 | +| --- | ---: | ---: | +| 整个队列 | 113.175 秒 | 100.641 秒 | +| 第一步 | 64.371 秒 | 56.797 秒 | +| 第二步 | 47.418 秒 | 41.168 秒 | +| worker 启动次数 | 2 | 1 | +| OpenProject 调用次数 | 4 | 3 | +| 成功保存并重开验证 | 2 | 2 | +| 独立回读核对 | 13/13 | 13/13 | + +这一次本机样本总耗时减少 11.1%;有 CAD 缓存与机器负载差异,不能推广为所有项目的固定提升。统计含队列准备、备份和最终关闭;独立验证不计入队列耗时。逐步原生阶段耗时见 `build/session-live-20261015/{small-baseline,small-reuse}/report.json`。 + +## 图页、暂停与外部操作保护 + +PON 的 18 页清单中,连续验证 `block`、`01_POWER`、`02_ZX279133L` 三个图页,耗时分别为 16.364、4.627、10.181 秒;一个 worker,三个 `no_match` 检查点,完成 3/18 后退出会话并确认工程关闭。总计 34.737 秒,证据为 `build/session-live-20261015/multi-page/report.json`。此测试验证原生换页和中途关闭,不作为跨页实际替换成功的证据。 + +独立副本上的三项原生边界探针均通过:正常关闭自有工程;等待期间外部修改 Value 时中止并保留编辑;等待期间切换至其他工程时中止并保留其他工程。不能确认关闭时写入 `uncertain.flag`。证据为 `build/session-live-20261015/guards2/{clean,edit,foreign}/guard-report.json`。 + +PON 的原单步替换基线尝试耗时 166.381 秒,三步中一项成功、一项原生替换失败、一项保存后回读失败。失败原生报告停在 `pin_promotion_started`,尚不能证明 COM 崩溃等具体原因。本轮没有把它计作成功性能对照,也没有反复重跑状态不确定的副本。首次尝试还遇到测量脚本未传递 PYTHONPATH 的问题,修正测试脚本后才进行上述统计。 + +## 自动化回归 + +- 集成回归:224 passed,1 deselected,84.85 秒。范围为 V1.1 界面、日志、取消、工程发现,以及原 store、service、batch;单独排除千步性能用例。 +- 快照、数据库只读事务和监督器定向回归:42 passed,13.06 秒。 +- 后续增加 worker 失败后重建的回归,会话专用 6 项通过,4.90 秒;此前集成已覆盖其中 5 项,因此自动化去重合计 267 项通过。 +- 千步压力测试:20 个工程 × 5 页 × 10 条规则,共 1000 步,91 项保存、909 项未命中,全部任务唯一执行并正确完成,峰值 1.94 MiB。当前耗时 41.516 秒(24.09 步/秒),未通过 30 秒门槛。 +- 原基线 `bc6b726` 在同机、同一个用例、同样启用 tracemalloc 条件下的对照为 42.453 秒,也未通过 30 秒门槛。原子命令写入和事件日志在两版没有变化,快照解析不在逐步循环内;未发现新增热点导致退化。旧记录的 22.376 秒不能替代本次实测,不放宽阈值,不把耗时检查记为通过。 +- F 盘指定临时目录的一次压力尝试在第 139 步发布命令时遇到 WinError 5,安全停止,未形成完整性能数据。随后 C/F 盘各 120 次 fsync+replace 探针未复现,不能据此断言具体占用进程;保留该现场限制。 + +版本化的逐步阶段耗时、回读摘要及保护探针结果见 `docs/testing/data/2026-10-15-project-session.json`;完整原生执行证据保留在上述本机构建目录中。 + +可复用的原生测量脚本为 `tools/measure_project_session.py`,保护探针为 `tools/probe_project_session_guards.py`,多页探针为 `tools/probe_project_session_pages.py`。它们运行前要求当前 CAD 没有打开工程。 diff --git a/docs/testing/data/2026-10-15-project-session.json b/docs/testing/data/2026-10-15-project-session.json new file mode 100644 index 0000000..e92da6e --- /dev/null +++ b/docs/testing/data/2026-10-15-project-session.json @@ -0,0 +1,518 @@ +{ + "baseline_commit": "bc6b726", + "note": "Single paired native sample; copied projects only. Thousand-step time gate remains failed in both versions.", + "native": { + "small-baseline": { + "queue_seconds": 113.17540310000186, + "worker_starts": 2, + "open_project_calls": 4, + "verified": true, + "readback_seconds": 9.846703400020488, + "comparisons": [ + { + "refdes": "RL02", + "sheet": "8211_1GPHY_48PIN", + "expected": "4100-CA3300-2200", + "actual": "4100-CA3300-2200" + }, + { + "refdes": "RL05", + "sheet": "8211_1GPHY_48PIN", + "expected": "4100-CA3300-2200", + "actual": "4100-CA3300-2200" + }, + { + "refdes": "RL06", + "sheet": "8211_1GPHY_48PIN", + "expected": "4100-CA3300-T7", + "actual": "4100-CA3300-T7" + }, + { + "refdes": "RL07", + "sheet": "8211_1GPHY_48PIN", + "expected": "4100-CA3300-T7", + "actual": "4100-CA3300-T7" + }, + { + "refdes": "RL08", + "sheet": "8211_1GPHY_48PIN", + "expected": "4100-CA3300-T7", + "actual": "4100-CA3300-T7" + }, + { + "refdes": "RL09", + "sheet": "8211_1GPHY_48PIN", + "expected": "4100-CA3300-T7", + "actual": "4100-CA3300-T7" + }, + { + "refdes": "RL10", + "sheet": "8211_1GPHY_48PIN", + "expected": "4100-CA3300-T7", + "actual": "4100-CA3300-T7" + }, + { + "refdes": "RL11", + "sheet": "8211_1GPHY_48PIN", + "expected": "4100-CA3300-T7", + "actual": "4100-CA3300-T7" + }, + { + "refdes": "RL12", + "sheet": "8211_1GPHY_48PIN", + "expected": "4100-CA3300-T7", + "actual": "4100-CA3300-T7" + }, + { + "refdes": "RL13", + "sheet": "8211_1GPHY_48PIN", + "expected": "4100-CA3300-T7", + "actual": "4100-CA3300-T7" + }, + { + "refdes": "RL14", + "sheet": "8211_1GPHY_48PIN", + "expected": "4100-CA3300-T7", + "actual": "4100-CA3300-T7" + }, + { + "refdes": "RL15", + "sheet": "8211_1GPHY_48PIN", + "expected": "4100-CA3300-T7", + "actual": "4100-CA3300-T7" + }, + { + "refdes": "RL16", + "sheet": "8211_1GPHY_48PIN", + "expected": "4100-CA3300-T7", + "actual": "4100-CA3300-T7" + } + ], + "steps": [ + { + "old_part_number": "4100-CA3300-T7", + "new_part_number": "4100-CA3300-2200", + "sheet": "8211_1GPHY_48PIN", + "phase": "execute_step", + "unit": "step", + "completed_units": 1, + "state": "saved_ok", + "schematic_name": "1GPHY_8211", + "sheet_number": "8211_1GPHY_48PIN", + "job_id": "99f533d93c4a4dcabeb687b2311658af_0", + "worker_stage_seconds": { + "starting": 0.9839999999967404, + "session_startup": 2.4690000000118744, + "check_project": 0.0159999999741558, + "open_project": 15.78100000001723, + "open_sheet": 3.5310000000172295, + "session_ready": 0.0629999999946449, + "query_components": 0.75, + "index_components": 5.203000000008615, + "find_components": 0.7969999999913853, + "index_pins": 4.514999999984866, + "snapshot_attributes": 0.40700000000651926, + "capture": 2.6559999999881256, + "before_native": 0.07800000000861473, + "native_replace": 17.01600000000326, + "restore_preflight": 2.812000000005355, + "before_restore_transaction": 0.25, + "restore_attribute_fields": 0.6089999999967404, + "restore_attributes": 0.0, + "verify_restoration": 0.14199999999254942, + "verify_attribute_fields": 0.1870000000053551, + "finished": 1.9839999999967404, + "save_and_close": 4.062999999994645, + "verify_saved_project": 0.0 + }, + "elapsed_seconds": 64.37054100001114, + "units_per_minute": 0.932103398043363 + }, + { + "old_part_number": "4100-CA3300-T7", + "new_part_number": "4100-CA3300-2200", + "sheet": "8211_1GPHY_48PIN", + "phase": "execute_step", + "unit": "step", + "completed_units": 1, + "state": "saved_ok", + "schematic_name": "1GPHY_8211", + "sheet_number": "8211_1GPHY_48PIN", + "job_id": "99f533d93c4a4dcabeb687b2311658af_1", + "worker_stage_seconds": { + "starting": 0.42199999999138527, + "session_startup": 1.2810000000172295, + "check_project": 0.03199999997741543, + "open_project": 10.96799999999348, + "open_sheet": 2.0789999999979045, + "session_ready": 0.015000000013969839, + "query_components": 0.3129999999946449, + "index_components": 2.1559999999881256, + "find_components": 1.0310000000172295, + "index_pins": 3.6719999999913853, + "snapshot_attributes": 0.25, + "capture": 4.578000000008615, + "before_native": 0.125, + "native_replace": 14.51600000000326, + "restore_preflight": 1.327999999979511, + "before_restore_transaction": 0.21899999998277053, + "restore_attribute_fields": 0.5940000000118744, + "restore_attributes": 0.0, + "verify_restoration": 0.061999999976251274, + "verify_attribute_fields": 0.0940000000409782, + "finished": 1.25, + "save_and_close": 2.4060000000172295, + "verify_saved_project": 0.0 + }, + "elapsed_seconds": 47.418164899980184, + "units_per_minute": 1.2653378747692758 + } + ], + "other_phases": [ + { + "phase": "prepare_queue", + "unit": "step", + "completed_units": 2, + "state": "completed", + "elapsed_seconds": 0.07470610001473688, + "units_per_minute": 1606.2945325258345 + }, + { + "phase": "backup_project", + "unit": "operation", + "completed_units": 1, + "state": "completed", + "elapsed_seconds": 0.9657479999877978, + "units_per_minute": 62.12800854959896 + }, + { + "phase": "persist_progress", + "unit": "operation", + "completed_units": 1, + "state": "completed", + "job_id": "99f533d93c4a4dcabeb687b2311658af_0", + "elapsed_seconds": 0.008863399998517707, + "units_per_minute": 6769.411287997185 + }, + { + "phase": "persist_progress", + "unit": "operation", + "completed_units": 1, + "state": "completed", + "job_id": "99f533d93c4a4dcabeb687b2311658af_1", + "elapsed_seconds": 0.00932809998630546, + "units_per_minute": 6432.178052131272 + }, + { + "phase": "task_total", + "unit": "task", + "completed_units": 1, + "state": "completed", + "completed_steps": 2, + "saved_steps": 2, + "failed_steps": 0, + "elapsed_seconds": 113.10993500001496, + "units_per_minute": 0.5304573820150464 + } + ] + }, + "small-reuse": { + "queue_seconds": 100.6405139999988, + "worker_starts": 1, + "open_project_calls": 3, + "verified": true, + "readback_seconds": 10.346642499993322, + "comparisons": [ + { + "refdes": "RL02", + "sheet": "8211_1GPHY_48PIN", + "expected": "4100-CA3300-2200", + "actual": "4100-CA3300-2200" + }, + { + "refdes": "RL05", + "sheet": "8211_1GPHY_48PIN", + "expected": "4100-CA3300-2200", + "actual": "4100-CA3300-2200" + }, + { + "refdes": "RL06", + "sheet": "8211_1GPHY_48PIN", + "expected": "4100-CA3300-T7", + "actual": "4100-CA3300-T7" + }, + { + "refdes": "RL07", + "sheet": "8211_1GPHY_48PIN", + "expected": "4100-CA3300-T7", + "actual": "4100-CA3300-T7" + }, + { + "refdes": "RL08", + "sheet": "8211_1GPHY_48PIN", + "expected": "4100-CA3300-T7", + "actual": "4100-CA3300-T7" + }, + { + "refdes": "RL09", + "sheet": "8211_1GPHY_48PIN", + "expected": "4100-CA3300-T7", + "actual": "4100-CA3300-T7" + }, + { + "refdes": "RL10", + "sheet": "8211_1GPHY_48PIN", + "expected": "4100-CA3300-T7", + "actual": "4100-CA3300-T7" + }, + { + "refdes": "RL11", + "sheet": "8211_1GPHY_48PIN", + "expected": "4100-CA3300-T7", + "actual": "4100-CA3300-T7" + }, + { + "refdes": "RL12", + "sheet": "8211_1GPHY_48PIN", + "expected": "4100-CA3300-T7", + "actual": "4100-CA3300-T7" + }, + { + "refdes": "RL13", + "sheet": "8211_1GPHY_48PIN", + "expected": "4100-CA3300-T7", + "actual": "4100-CA3300-T7" + }, + { + "refdes": "RL14", + "sheet": "8211_1GPHY_48PIN", + "expected": "4100-CA3300-T7", + "actual": "4100-CA3300-T7" + }, + { + "refdes": "RL15", + "sheet": "8211_1GPHY_48PIN", + "expected": "4100-CA3300-T7", + "actual": "4100-CA3300-T7" + }, + { + "refdes": "RL16", + "sheet": "8211_1GPHY_48PIN", + "expected": "4100-CA3300-T7", + "actual": "4100-CA3300-T7" + } + ], + "steps": [ + { + "old_part_number": "4100-CA3300-T7", + "new_part_number": "4100-CA3300-2200", + "sheet": "8211_1GPHY_48PIN", + "phase": "execute_step", + "unit": "step", + "completed_units": 1, + "state": "saved_ok", + "schematic_name": "1GPHY_8211", + "sheet_number": "8211_1GPHY_48PIN", + "job_id": "246f84be443e4ae2a55a0df40dc4899f_0", + "worker_stage_seconds": { + "starting": 0.28099999998812564, + "session_startup": 1.0, + "check_project": 0.0, + "open_project": 12.10999999998603, + "open_sheet": 2.812000000034459, + "session_ready": 0.01600000000325963, + "query_components": 0.28099999998812564, + "index_components": 2.702999999979511, + "find_components": 0.875, + "index_pins": 4.593000000022585, + "snapshot_attributes": 0.42199999996228144, + "capture": 4.094000000011874, + "before_native": 0.125, + "native_replace": 19.155999999988126, + "restore_preflight": 2.109000000025844, + "before_restore_transaction": 0.28200000000651926, + "restore_attribute_fields": 0.75, + "restore_attributes": 0.014999999984866008, + "verify_restoration": 0.14100000003236346, + "verify_attribute_fields": 0.1879999999946449, + "finished": 3.2189999999827705, + "save_and_close": 1.562000000005355, + "verify_saved_project": 0.01600000000325963, + "session_wait": 0.0 + }, + "elapsed_seconds": 56.79680049998569, + "units_per_minute": 1.0563975342240468 + }, + { + "old_part_number": "4100-CA3300-T7", + "new_part_number": "4100-CA3300-2200", + "sheet": "8211_1GPHY_48PIN", + "phase": "execute_step", + "unit": "step", + "completed_units": 1, + "state": "saved_ok", + "schematic_name": "1GPHY_8211", + "sheet_number": "8211_1GPHY_48PIN", + "job_id": "246f84be443e4ae2a55a0df40dc4899f_1", + "worker_stage_seconds": { + "check_project": 0.015000000013969839, + "open_sheet": 2.187999999965541, + "query_components": 0.4220000000204891, + "index_components": 2.9210000000020955, + "find_components": 0.6089999999967404, + "index_pins": 3.532999999995809, + "snapshot_attributes": 0.24900000003981404, + "capture": 2.85999999998603, + "before_native": 0.07800000000861473, + "native_replace": 16.264999999984866, + "restore_preflight": 1.687999999994645, + "before_restore_transaction": 0.2659999999741558, + "restore_attribute_fields": 0.6870000000053551, + "restore_attributes": 0.0, + "verify_restoration": 0.12600000001839362, + "verify_attribute_fields": 0.10899999999674037, + "finished": 1.687000000005355, + "save_and_close": 1.7039999999979045, + "verify_saved_project": 0.015000000013969839, + "open_project": 5.625, + "session_wait": 0.0 + }, + "elapsed_seconds": 41.16839780000737, + "units_per_minute": 1.4574285910147629 + } + ], + "other_phases": [ + { + "phase": "prepare_queue", + "unit": "step", + "completed_units": 2, + "state": "completed", + "elapsed_seconds": 0.025570099998731166, + "units_per_minute": 4692.981255683576 + }, + { + "phase": "backup_project", + "unit": "operation", + "completed_units": 1, + "state": "completed", + "elapsed_seconds": 0.32834000000730157, + "units_per_minute": 182.73740634301555 + }, + { + "phase": "persist_progress", + "unit": "operation", + "completed_units": 1, + "state": "completed", + "job_id": "246f84be443e4ae2a55a0df40dc4899f_0", + "elapsed_seconds": 0.010178099997574463, + "units_per_minute": 5895.009875546375 + }, + { + "phase": "persist_progress", + "unit": "operation", + "completed_units": 1, + "state": "completed", + "job_id": "246f84be443e4ae2a55a0df40dc4899f_1", + "elapsed_seconds": 0.009127400000579655, + "units_per_minute": 6573.613514931916 + }, + { + "phase": "task_total", + "unit": "task", + "completed_units": 1, + "state": "completed", + "completed_steps": 2, + "saved_steps": 2, + "failed_steps": 0, + "elapsed_seconds": 100.6060615000024, + "units_per_minute": 0.5963855368694516 + } + ] + } + }, + "multi_page": { + "steps": [ + { + "sheet": [ + "PON", + "block" + ], + "state": "no_match", + "seconds": 16.36403070000233 + }, + { + "sheet": [ + "PON", + "01_POWER" + ], + "state": "no_match", + "seconds": 4.627093000017339 + }, + { + "sheet": [ + "PON", + "02_ZX279133L" + ], + "state": "no_match", + "seconds": 10.180998900003033 + } + ], + "passed": true, + "closed_between_steps": true, + "worker_starts": 1, + "completed_items": 3, + "total_items": 18, + "seconds": 34.73681229999056 + }, + "guards": { + "clean": { + "mode": "clean", + "closed_cleanly": true, + "passed": true + }, + "edit": { + "mode": "edit", + "previous_value": "100NF/16V", + "external_edit_written": true, + "error_code": "quick_run_uncertain", + "preserved_external_state": true, + "passed": true + }, + "foreign": { + "mode": "foreign", + "error_code": "quick_run_uncertain", + "preserved_external_state": true, + "passed": true + } + }, + "stress": { + "current": { + "mode": "simulated_worker_with_tracemalloc", + "projects": 20, + "sheets_per_project": 5, + "rules_per_sheet": 10, + "steps": 1000, + "saved_steps": 91, + "elapsed_seconds": 41.516500700003235, + "peak_bytes": 2036758, + "steps_per_second": 24.086808453004377, + "functional_assertions_passed": true, + "time_gate_seconds": 30, + "time_gate_passed": false + }, + "baseline": { + "mode": "simulated_worker_with_tracemalloc", + "projects": 20, + "sheets_per_project": 5, + "rules_per_sheet": 10, + "steps": 1000, + "saved_steps": 91, + "elapsed_seconds": 42.45326560002286, + "peak_bytes": 1992249, + "steps_per_second": 23.555313963867636, + "functional_assertions_passed": true, + "time_gate_seconds": 30, + "time_gate_passed": false + } + } +}