fix: close owned PCB startup failures before ICDB recovery

This commit is contained in:
阿白叔 committed 2026-11-02 17:40:18 +08:00
1 parent 39985f7cfd
commit ec78dd722c
5 files changed
+360 -1

No files matched your search

@@ -0,0 +1,80 @@
# Issue #2: release the PCB launched by a failed database open
Branch: `codex/temp-issue-2-icdb-recovery`.
## Field failure
The issue attachment records an iCDB lost-server-session error while opening
`1GPHY_8211`. The supervisor declined the database log viewer and cancelled the
worker. Because document identity had not been established, the existing
document-close helper was never called. PCB and its launcher remained alive;
the subsequent Repair attempt returned `REPAIR_DATABASE_IN_USE` and the other
380 queued entries were skipped. There is no evidence of native Repair actually
running on that field database.
## Change
The worker now has a separate startup-failure close path. It requires a current
iCDB diagnosis or a database-load-failure dialog belonging to this PCB during
startup. It checks the private desktop, excludes pre-existing process IDs, and
matches the complete PCB path and ReusableCircuit argument. Only an enabled
empty PCB main window, without modal dialogs, MDI documents or database address
records, receives a cooperative `WM_CLOSE`. A requested close is not treated as
success until process exit is observed. Ambiguous or busy sessions are retained.
The supervisor allows up to 40 seconds for fatal-error cleanup so that the
worker's 20-second startup-close window can complete before recovery begins.
The existing repair preconditions, backups and success checks remain in force.
Each attempt writes `startup-close.json` and close-request/result events.
## Verification
Regression tests cover the missing pre-identity cleanup route, real observed
empty-window titles, exact path matching, pre-existing processes, another
desktop, live address records, modal and MDI windows, disabled windows, unrelated
failure records and a close request that does not result in exit.
Delayed dialog/address release and delayed process exit are also covered.
Validation: `python -m pytest -q` — 491 passed, one existing pywinauto COM-mode
warning; `python -m compileall -q src tests` and `git diff --check` passed.
A new isolated local library was created with the existing
`tools/validate_icdb_open_repair_reopen.py` tool, output
`diagnostics/issue2-startup-20261102`. No production library was changed.
The test damages only the new copy's database header; it does not reproduce the
field server-session-loss condition.
The real Mentor opening run produced `MENTOR_DATABASE_LOAD_FAILED`, then:
- `startup_close_requested` for the launched PCB PID 6532;
- `startup_close_result: CLOSED`;
- worker and supervisor both recorded `process_exit_confirmed`, with no
remaining PCB processes.
The subsequent separate native Repair run was able to start and completed as
`RESTORED_REVIEW_REQUIRED`, using the fixture's historical backup. This proves
the failed-open session no longer blocks the next repair operation in this
fixture. It does not prove automatic recovery of the field database or establish
that an older backup contains the desired design revision.
The separate `open-after` run on the same restored fixture completed native
integration, Save/IsSaved/Close/Quit, confirmed process release and returned
`PASS`, `safe_to_continue=True`, `READY (IsVerifiedReuseBlock, raw=1)`.
The `compare` phase passed all seven checks, including absence of the original
opening error and unchanged source-fixture database SHA-256. Its
`server_session_loss_reproduced` field is explicitly `false`.
Reproduction commands (set `PYTHONPATH=src`; setup requires a new output name):
```powershell
python tools/validate_icdb_open_repair_reopen.py setup --output issue2-startup-20261102
python tools/validate_icdb_open_repair_reopen.py open-before --output issue2-startup-20261102
python tools/validate_icdb_open_repair_reopen.py repair --output issue2-startup-20261102
python tools/validate_icdb_open_repair_reopen.py open-after --output issue2-startup-20261102
python tools/validate_icdb_open_repair_reopen.py compare --output issue2-startup-20261102
```
The stages are deliberately separate: the test fixture has a format-corruption
error and historical-backup recovery, not the field lost-session auto-repair
trigger. The test does not change production handling of old-backup recovery.
READY filtering, hash-scope changes and CBB CRUD are outside this focused fix.