fix: scope runtime release proof and bound native file probes

This commit is contained in:
阿白叔 committed 2026-11-16 17:37:45 +08:00
1 parent a1b38c242f
commit b070837acb
10 files changed
+816 -77

No files matched your search

@@ -0,0 +1,98 @@
# Task 1 — resource scopes, lease release and bounded proof
Date: 2026-11-16. Worktree: `F:/Sync Tool Skyworth/Work Maps/cbb-refresh-verify-795-issue15`.
Branch: `codex/issue15-runtime-unblock`. Baseline: `efb8cae`.
## Result
Implemented and verified the Task 1 backend changes. The final covering run passed **409 tests in 86.98 seconds**, exit code 0. No production library, native address, user process, or original dirty checkout was modified. No push, PR, full-suite run, frozen build, or real Mentor acceptance was performed by this task.
Release now carries selected single/multiple project scope, so another unselected project's address cannot retain the completed task's sidecar. Unknown checkpoints still require fresh whole-library resource proof, but a process explicitly bound to another library/project is not a global exit requirement. Native inspection-only results are used for exactly mapped addressed databases; addresses remain in place. Native `IN_USE`, unconfirmed/unfinished inspection, real exclusive-file failure, or unreturned shared work reject release.
`data_recovery_required` describes native data diagnostics, independently of lease release. A confirmed NOT_IN_USE database requiring repair does not poison the library or block an explicit subsequent repair/replacement. No persistent recovery blocker store was added, following the controller's product ruling.
## Changes and callers audited
- `library_lock.py`: per-library serialization for entry, exit, maintenance adoption, snapshots and release; `_guard` now protects quick in-memory operations only. Before committing a release, the exact retained-owner object and checkpoint bytes are checked again. Added optional multi-block scope and stop propagation. The upload `.lock` is never deleted.
- `residual_sessions.py`: passes the entire confirmed `block_names` selection into proof, including multi-selection. Existing observation-only rows remain excluded from close actions and active-release counts. Unknown records cannot use an arbitrary selection to narrow their proof.
- `file_probe.py` and static `application.py --file-probe` dispatch: a pure read-only subprocess scans native files and address/PRJ bindings, rejects reparse paths (including junctions within the same library), and acquires real Windows read handles. Default readiness deadline is 10 seconds; stop/timeout terminates only that helper. It never launches native tools. The parent duplicates the held handles before commit, so even the probe's exit cannot create an unprotected interval. Native files exclude other access; address and PRJ handles allow reads but prevent changes/deletion until commit finishes. Local stdin EOF releases helper resources.
- `icdb_ownership.py`: declared session resource scope and exact address-target inspection. An addressed database needs exactly one matching PRJ and `icdb.dat`; ambiguous/shared mappings fail closed. Healthy/no-address projects do not start an extra native inspection.
- `session_record.py`: optional scope/lease/recovery fields on initial session records and results; legacy release receipts without an observed resource scope are rechecked. Observer cleanup requires the same retained alias and operation identity, protecting newer work.
- `native_export_guard.py`: actual retained-export checks remain; explicitly unrelated native owners no longer veto unknown-checkpoint recovery. Export begin/finish use the per-library guard.
- `management_transaction.py`: `current_lease` uses per-library serialization for checkpoint reads. This narrow extension was approved by the controller after the global-lock caller audit.
Audited `_guard` imports/usages in `library_lock`, `native_export_guard`, `management_transaction`, and `native_management.prepare_owned_fixture_add`. The remaining native-management `_guard` block contains only in-memory identity comparisons and handle conversion; its disk reads already occur outside the global lock. Lock order is per-library then short global guard. No UI, queue, `failed_session`, `mentor_adapter`, or `native_backup` edits.
## Downstream interfaces
Public VerifyRequest/VerifyResult are unchanged. Existing positional callers remain valid.
```python
release_retained_library(library, evidence_dir, *, block_name=None, block_names=(), stop=None)
recheck_previous_release(library, evidence_dir, *, block_name=None,
required=False, progress=None, stop=None)
```
Successful release proof retains `status='RELEASE_CONFIRMED'` and adds:
- `lease_state='RELEASED'`, `blocked_resources=[]`.
- `resource_scope`: `scope_state='OBSERVED'`, library, roots, actual project/database/shared-dependency paths, block_name/block_names, lease_id, and reconciled operation_ids.
- `proof_scope`: `BLOCK`, `BLOCKS`, or `LIBRARY`; `proof_block_names` and legacy `proof_block_name` remain available.
- `data_recovery_required`: `None` when no native data diagnosis was needed, otherwise the native boolean.
- `data_recovery_resources`: exact databases whose inspection requires recovery; `native_inspections` contains the full inspection-only records.
- `data_recovery_confirmed=False` remains explicit. Release is not a save/repair/data-health claim.
Initial worker records contain `lease_state='ACTIVE'`, declared resource scope from job `project`/`pcb`, and `data_recovery_required=None`. Missing/legacy project scope is `RECHECK_REQUIRED`. Downstream code should provide actual `project` and `pcb` when known and preserve optional fields in evidence. A subsequent operation must still acquire its own lease and perform its own resource admission; a past proof is not replayable authority.
## TDD evidence
All test/native subprocess invocations used this worktree's absolute `src` in `PYTHONPATH`. No editable install or machine environment modification was used. After the controller's baseline clearance, tests were written and run before their corresponding implementation.
| Red command (after setting absolute PYTHONPATH) | Observed result before fix | Green evidence |
|---|---|---|
| `python -m pytest tests/test_issue15_resource_release.py -q` (initial four tests) | 4 failed in 2.06 s: B's address forced PARTIAL; unrelated process rejected unknown checkpoint; slow A blocked B; old observer cleared new operation | Initial four passed; 83 related tests passed in 10.10 s |
| `python -X utf8 -m pytest tests/test_issue15_resource_release.py -q` (address/helper additions) | 6 failed, 4 passed in 2.08 s: blanket address gate, global unknown export owner gate, missing helper API | Later 151 related tests passed in 26.57 s |
| `... -k 'survives or journal_records or replacement_lease'` | 2 failed, 1 passed in 1.26 s: helper exit dropped proof protection; journal lacked lease scope | Real DuplicateHandle transfer and scoped journal passed in final run |
| `... -k 'multiple_selected or without_release'` | 1 failed, 3 passed in 2.46 s: A+B expanded into C | Multi-block regression passed; IN_USE/UNCONFIRMED/not-exited safety tests retained |
| `.../run_tests.py -q tests/test_issue15_resource_release.py -k 'legacy_release or stalled_transaction'` | 2 failed in 1.29 s: legacy receipt trusted; stalled checkpoint held global guard | 2 passed in 0.33 s |
| `... -k 'binding_against'` | 1 failed in 1.02 s: address/PRJ writable during proof | 1 passed in 0.62 s |
| `... -k 'scope_junction'` | 1 failed in 0.99 s: same-library junction silently changed target | Passed in final run |
| `... -k 'legacy_release'` (malformed scope case) | 1 failed, 1 passed in 0.76 s: null old scope raised AttributeError | 2 passed in 0.27 s |
The regression module has 22 cases. Real Windows checks include parent-held sidecar rejecting a child then succeeding after scoped release; duplicated exclusive handles surviving probe termination; actual write rejection on address/project binding files; real sleeping subprocess timeout/cancellation and reaping; and an actual Windows junction. Native inspection output is mocked at the native boundary with complete exact-target records; no actual Mentor was launched by these tests.
Additional related runs: 239 passed in 48.24 s (maintenance/export/management/packaging); 214 passed in 38.77 s after global-lock and legacy receipt changes. A test invocation containing nonexistent `tests/test_management_transaction.py` collected no tests; it was corrected to the actual `test_management_native_transaction.py` in the final run. An intermediate external-owner regression exposed loss of WinError 32 through the helper; error propagation was restored and all final cases pass.
## Final verification
Durable local artifacts:
- `.superpowers/sdd/2026-11-16-issue15-runtime-unblock/task-1-tests.log` — exact command and complete pytest output.
- `.superpowers/sdd/2026-11-16-issue15-runtime-unblock/task-1-tests.xml` — JUnit results.
The covering command used the controller's runner, which asserts canonical imports and sets inherited absolute PYTHONPATH:
```text
python -X utf8 .superpowers/sdd/2026-11-16-issue15-runtime-unblock/run_tests.py -q
--junitxml=.superpowers/sdd/2026-11-16-issue15-runtime-unblock/task-1-tests.xml
tests/test_issue15_resource_release.py tests/test_library_lock.py
tests/test_session_record.py tests/test_residual_sessions.py
tests/test_external_owner_release.py tests/test_review_release_followup.py
tests/test_review_foreign_release_evidence.py tests/test_operation_lifecycle.py
tests/test_owner_probe.py tests/test_native_export_guard.py
tests/test_management_native_transaction.py tests/test_management_retry_blockers.py
tests/test_management_probe_guards.py tests/test_independent_operations.py
tests/test_maintenance_entry.py tests/test_maintenance_owner_scope.py
tests/test_maintenance_review.py tests/test_review_backend_followup.py
tests/test_review_319.py tests/test_review326_dispatch_and_receipts.py
tests/test_packaging.py tests/test_packaging_status_bridge.py
```
Actual summary: `409 passed in 86.98s (0:01:26)`; exit code 0. `git diff --check` also passed.
## Concerns and acceptance boundaries
- **Downstream Task 2/4 requirement:** The 10-second cancellable helper bounds native-tree/address/PRJ discovery and native exclusive-file acquisition. Own checkpoint read/write/archive and existing retained-export evidence paths remain synchronous, but are now per-library and do not hold the global memory guard. A wedged network/filesystem operation in those existing paths can still delay that library. Task 2 must apply deadline/handoff and late-call cancellation guards so this cannot retain the global queue/UI indefinitely; Task 4 must verify it. This is not a whole-call timeout claim. The controller explicitly kept that lifecycle work out of Task 1.
- Native inspection runs through the existing independent inspection-only supervisor and is never killed by the pure file-probe timeout. Its diagnostics use retained local temporary directories; complete native result records are also embedded in release evidence. Native tool behavior, native close timing, and on-site reproduction remain unverified here.
- Ambiguous/shared addresses without an exact unique PRJ-to-database mapping remain protected for manual investigation. No address age, unreachable endpoint, process absence alone, or metadata PID is accepted as ownership/release authority.
- No automatic Repair or automatic whole-library backup was added. Full application cancellation/batch/shutdown policy and UI use of the added fields belong to subsequent tasks. Frozen packaging was covered by existing packaging tests and static helper dispatch import, not a new EXE build.