fix: prevent iCDB disconnects and recover failed projects

This commit is contained in:
阿白叔 committed 2026-10-27 17:51:53 +08:00
1 parent 8a517d6f38
commit 2490067b2d
19 files changed
+1117 -60

No files matched your search

@@ -0,0 +1,38 @@
# iCDB failure lifecycle and recovery implementation plan
**Goal:** Prevent failed verification from aborting iCDB owners, close owned idle failed documents normally, and attempt native recovery only against a validated idle target with a complete backup.
**Context:** User confirmed the incident used r4 or earlier. r4 enables `JOB_OBJECT_LIMIT_KILL_ON_JOB_CLOSE`, calls `TerminateJobObject` and `taskkill /T /F` on failures and native owners. a11eb3c removed those PCB paths, but content-check timeout still kills a process tree. Failed worker exceptions currently release COM references without requesting normal document closure.
**Architecture:** Keep native transactions alive through timeouts. Signal cooperative cancellation to the worker; let blocking native calls return before closing a document. A separate recovery module owns target checks, backup and the official GUI repair transaction; failed or ambiguous repair remains failed. Work and central-library database ownership are checked separately.
**Tech stack:** Python 3.12, Windows process handles/private desktops, x86 cscript and Mentor EE7.9.5 native tools. Continue on `codex/icdb-lost-session-diagnostics`.
## Task 1 — Retain native owners on content timeout
- [ ] Add a regression that starts a harmless importer with a harmless child, times out, and checks both survive until normal exit or test cleanup.
- [ ] Add a content-timeout batch regression proving the second item does not start.
- [ ] Remove tree/client termination from `_run_process` timeout; retain/drain the process in a background observer, record PID/command/release in evidence, and return TIMEOUT with `safe_to_continue=False`.
- [ ] Verify targeted tests and the existing content-check tests.
## Task 2 — Normal close of failed owned sessions
- [ ] Add x86 cscript harness tests for failed Save and close-only operation, checking `Close(False)`, reference release and Quit, with failure status preserved and mismatched identity untouched.
- [ ] Implement an identity-checked close helper and call it only after the worker has returned from its native call and released Python references. Retain busy helpers instead of terminating them.
- [ ] Add cooperative cancellation at Python/VBS native-operation boundaries; a supervisor timeout/crash must not terminate a pending native Save.
- [ ] Add targeted tests for cancel before Save, cancel after a pending call returns, supervisor loss and blocked native-call retention.
- [ ] Check shared `SymbolLibs/__ReusableBlocksSymb` ownership as well as Work/PCB database ownership before writing and before declaring release.
- [ ] Give the status reader an EOF shutdown grace period before any fallback termination.
## Task 3 — Attempt official native recovery
- [ ] Probe native UI on new isolated copies only; record accepted project/database identity, exact command, backup creation and completion signals. Do not invent CLI Repair flags or manipulate native ownership metadata.
- [ ] Add recovery-policy tests: reject foreign/unresolved targets, active clients, inconsistent backups and repeat repair; preserve the original error; at most one recovery attempt.
- [ ] Implement the supported native repair route with a complete backup and exact target checks. If the installed native tool cannot accept a shared symbol database, retain that explicit blocked result instead of repairing an unrelated Work project.
- [ ] Retry opening/verifying only after native success and confirmed release; authoritative READY remains the success criterion.
## Validation and delivery
- [ ] Run full Python and PowerShell regressions, compilation and whitespace checks, plus independent code review.
- [ ] Verify a successful native run and a controlled failed integration/close on an isolated library, and source fingerprints afterward.
- [ ] Record precisely which recovery target types were actually exercised and any remaining field-only limitations; commit changes on the current branch.