merge: preserve main safety fixes in acrylic workspace

This commit is contained in:
阿白叔 committed 2026-10-31 14:07:20 +08:00
commit a41c6cf928
56 files changed
+2734 -169

No files matched your search

@@ -0,0 +1,85 @@
# Lifecycle Optimization Implementation Plan
> **For agentic workers:** REQUIRED SUB-SKILL: Use superpowers:subagent-driven-development (recommended) or superpowers:executing-plans to implement this plan task-by-task. Steps use checkbox (`- [ ]`) syntax for tracking.
**Goal:** Make CAD save, close, exit, and resource-release outcomes explicit and recoverable across normal, failed, cancelled, and forced-stop paths.
**Architecture:** Keep business completion and infrastructure cleanup as separate outcomes. Extend the existing resource journal and runtime result objects with phase evidence, give owned helper processes a bounded natural-exit window, and preserve cleanup failures instead of converting them into a successful-looking result.
**Tech Stack:** Python 3.12, PySide6, pywin32, pytest, existing `BatchCadRuntime`, `IsolatedCadSession`, supervisor protocol, and VBS worker evidence files.
**Spec:** Approved in chat on 2026-10-30 as Phase 1 of the project optimization.
## Global Constraints
- Preserve the existing no-replay protection for uncertain project mutations.
- Never terminate an unowned process or clear evidence that cannot be verified.
- Keep normal successful replacement behavior and public service method signatures compatible.
- Every production change must have a regression test that fails before the change.
---
### Task 1: Model and persist separate save/close evidence
**Files:**
- Modify: `src/dx_productivity/trial_task_center/batch_runtime.py`
- Modify: `src/dx_productivity/trial_task_center/isolated_cad.py`
- Modify: `src/dx_productivity/trial_task_center/batch_resources.py`
- Test: `tests/v1_1/test_batch_runtime.py`
- Test: `tests/v1_1/test_isolated_cad.py`
**Interfaces:**
- Consumes existing CAD shutdown records and project checkpoints.
- Produces journal fields for save requested, save returned, readback verified, project closed, and cleanup outcome.
- [ ] **Step 1: Write failing tests** for a close failure after a save request and for a cleanup record that reports business completion with infrastructure failure.
- [ ] **Step 2: Run the focused tests** and verify they fail because the current record has no separate save evidence and the completed result hides cleanup failure.
- [ ] **Step 3: Add the smallest evidence fields** with backward-compatible defaults and preserve the existing uncertain/recovery guard.
- [ ] **Step 4: Run the focused tests** and verify both pass.
- [ ] **Step 5: Run the related supervisor and recovery tests** before moving to the next task.
### Task 2: Allow owned helper processes a bounded natural exit window
**Files:**
- Modify: `src/dx_productivity/trial_task_center/isolated_desktop.py`
- Test: `tests/v1_1/test_isolated_desktop.py`
- Test: `tests/v1_1/test_batch_runtime_windows.py`
**Interfaces:**
- Consumes owned process identities and existing Win32 job cleanup records.
- Produces cleanup records that distinguish naturally exited descendants from forced termination.
- [ ] **Step 1: Write a failing test** where the root CAD process has exited and an owned helper exits shortly afterward; assert no forced termination is requested.
- [ ] **Step 2: Run the test** and verify the current implementation calls the force cleanup immediately.
- [ ] **Step 3: Add a bounded wait** only for identities whose owned root has already exited; retain force cleanup after the deadline.
- [ ] **Step 4: Run the focused Windows tests** and verify the cleanup record includes the wait and final state.
- [ ] **Step 5: Run the resource release test group**.
### Task 3: Separate diagnostic journal failures from the CAD Quit protocol
**Files:**
- Modify: `src/dx_productivity/trial_task_center/isolated_cad.py`
- Modify: `src/dx_productivity/trial_task_center/batch_release_log.py`
- Test: `tests/v1_1/test_isolated_cad.py`
- Test: `tests/v1_1/test_batch_runtime.py`
**Interfaces:**
- Consumes the existing owned CAD identity and project-close state.
- Produces an explicit diagnostic-write warning while still attempting a valid Quit sequence.
- [ ] **Step 1: Write a failing test** that injects a closing-record write failure and asserts Quit is still attempted when project state is safe.
- [ ] **Step 2: Run the test** and verify Quit is currently skipped.
- [ ] **Step 3: Isolate diagnostic persistence errors** from the normal Quit decision and record both outcomes.
- [ ] **Step 4: Run the focused tests** and verify both normal and failed-record paths.
- [ ] **Step 5: Run all lifecycle and supervisor tests**.
### Task 4: Verify the phase and document field validation
**Files:**
- Modify: `docs/testing/2026-10-26-application-lifecycle-investigation.md`
- Create: `docs/testing/2026-10-30-phase1-lifecycle-optimization.md`
- [ ] **Step 1: Run the complete test suite** and capture the count and warnings.
- [ ] **Step 2: Run `python -m compileall -q src` and `git diff --check`.**
- [ ] **Step 3: Record the exact scenarios covered and the remaining real DxDesigner field checks.**
- [ ] **Step 4: Review the final diff for accidental changes outside Phase 1.**
@@ -0,0 +1,75 @@
# Reliable Supervision Implementation Plan
> **For agentic workers:** REQUIRED SUB-SKILL: Use superpowers:subagent-driven-development (recommended) or superpowers:executing-plans to implement this plan task-by-task. Steps use checkbox (`- [ ]`) syntax for tracking.
**Goal:** Make batch execution produce durable diagnostics and deterministic forced-stop outcomes when Windows workers or private desktop cleanup fail.
**Architecture:** Add a small lifecycle/evidence writer shared by worker and supervisor. Keep business result validation separate from transport and resource cleanup; classify missing results from recorded process evidence. Make forced stop durable and idempotent before terminating the owned Job Object.
**Tech Stack:** Python 3.12, PySide6, pywin32, Windows Job Objects, pytest.
**Spec:** `docs/superpowers/specs/2026-10-30-reliable-supervision-design.md`
## Global Constraints
- Never automatically replay a write operation after an uncertain or missing result.
- Preserve existing task/business result formats and UI recovery actions.
- Use atomic file replacement for durable JSON records.
- Windows-specific tests must remain isolated from real DxDesigner projects.
---
### Task 1: Durable lifecycle and process evidence
**Files:**
- Create: `src/dx_productivity/trial_task_center/supervisor_evidence.py`
- Modify: `src/dx_productivity/trial_task_center/batch_worker.py`
- Modify: `src/dx_productivity/trial_task_center/batch_supervisor.py`
- Test: `tests/v1_1/test_supervisor_evidence.py`
- [x] Write tests for durable lifecycle append, bounded stdout/stderr capture, and typed missing-result diagnostics.
- [x] Run `..\\..\\.venv\\Scripts\\python.exe -m pytest -q tests/v1_1/test_supervisor_evidence.py`; observe the new tests fail because the evidence API is absent.
- [x] Implement `LifecycleEvidence.append(event, **fields)`, `try_append`, `write_process_evidence`, and typed errors with `from_directory`. JSON uses existing flush/fsync/replace; JSONL tolerates incomplete final lines. Stream tails are bounded in UTF-8 bytes when persisted.
- [x] Make the worker append startup, business completion, result commit, and exception events; preserve the existing result files.
- [x] Make the supervisor record process exit code and bounded output and use evidence when result files are missing.
- [x] Run the focused evidence tests and then the existing supervisor protocol tests.
### Task 2: Deterministic forced-stop precedence
**Files:**
- Modify: `src/dx_productivity/trial_task_center/batch_supervisor.py`
- Reuse unchanged: `src/dx_productivity/trial_task_center/stop_control.py`
- Reuse unchanged: `src/dx_productivity/trial_task_center/supervisor_result.py`
- Test: `tests/v1_1/test_safe_user_stop.py`
- [x] Add failing tests proving protection-write failure preserves a forced-stop state, transport callback failure does not downgrade a confirmed force, and repeated force requests are idempotent.
- [x] Observe missing forced-state evidence, duplicate termination, and raw late-write `PermissionError` before implementing fixes.
- [x] Persist forced intent before protection and termination, classify protection/termination confirmation separately, and return `user_forced_stop` only after Job termination is confirmed.
- [x] Preserve `primary_error`, existing BOM diagnostics, and cleanup evidence, including simultaneous cleanup and confirmation persistence errors.
- [x] Run all safe-stop and supervisor-result tests.
### Task 3: Windows process membership and cleanup evidence
**Files:**
- Modify: `src/dx_productivity/trial_task_center/isolated_desktop.py`
- Reuse unchanged: `src/dx_productivity/trial_task_center/batch_resources.py`
- Test: `tests/v1_1/test_isolated_desktop.py`
- Test: `tests/v1_1/test_desktop_diagnostics.py`
- [x] Add suspended-start membership and real worker PID/venv identity tests; retain existing PID plus creation-time and desktop-release mismatch tests.
- [x] Reproduce launcher PID differing from actual worker PID; captured stderr identifies the admission rejection.
- [x] Normalize only the current non-frozen venv interpreter launch; verify Job assignment before resume and persist existing cleanup/accounting snapshots.
- [x] Verify and reuse existing strict post-release enumeration and durable release proof; no desktop-release rewrite is needed after the identity fix.
- [x] Run the focused Windows resource tests.
### Task 4: Regression and operator documentation
**Files:**
- Modify: `docs/user/safe-stop-and-recovery.md`
- Create: `docs/testing/2026-10-30-reliable-supervision.md`
- Test: `tests/ui/test_ui_execution_feedback.py`
- [x] Add UI assertions for typed missing-result, forced-stop, and resource-pending messages.
- [x] Run the complete current-version UI/V1.1 suite, final affected-path regression, and required release safety subset. The extra full historical execution was stopped and is not reported as passed; see the testing report for exact scope.
- [x] Document evidence locations, recovery order, and the no-replay rule.
- [x] Record unperformed real CAD/frozen EXE validation and incomplete historical execution explicitly; no skipped or incomplete run is reported as passed.