AutoForge/prompts/Step-10A-Report.md

15 KiB

# Step-10A - Close ownership during pending rehearsal reopen

## Status

COMPLETE. The actual pre-fix interleaving was reproduced safely, the narrow
open/close/disposal coordination fix is implemented, all corrective/original
tests and nine-project Release build pass, and the required native recheck
passed. Step-10 remains NOT ACCEPTED pending manual corrective review.
Step-09/earlier accepted work and original Step-10 reports/evidence remain
unchanged. Step-11 was not started.

## Implementation and files

[CalibrationRehearsalSession.cs](../src/AutoForge.Application/Features/Vehicles/Calibration/CalibrationRehearsalSession.cs)
contains the only production change:

- Start retires the previous completed/failed _closeTask under the existing
  state gate when a new opening owner without a current target is admitted.
  This happens together with owner publication, before synchronous factory
  execution, rather than only after target publication succeeds.
- Open no longer clears the close task on successful target publication.
- EnsureCurrent/CanPublish reject disposed lifetime publication in addition
  to existing cancellation/generation/close checks.
- After outside-gate drainage, Closed state and shared close completion/failure
  publish together under the state gate. Continuations remain asynchronous;
  no cleanup await holds that gate.

CloseAsync retains its existing same-lifetime shared completion, owner
cancellation, target cleanup and explicit failure contract. No public signature,
programming/backup/approval/CAS/audit/target/port design or page implementation
was changed. The production diff is 5 added and 4 removed lines.

[CalibrationRehearsalReopenTests.cs](../src/tests/AutoForge.IntegrationTests/CalibrationRehearsalReopenTests.cs)
adds six focused cases. ReopenBarrierFactory forwards actual
SimulatedCalibrationTargetFactory creation and wraps the actual target. It
holds the second synchronous factory return on a task-owned concurrent Open,
then holds its target disposal independently. Disposal invocation/completion
counts and actual disposed-port reads are checked. There is no production race
selector, workflow mock, oracle, sleep or stress/GC proxy.

## Actual pre-fix reproduction

Command:

dotnet test .\src\tests\AutoForge.IntegrationTests\AutoForge.IntegrationTests.csproj --configuration Release --no-restore --filter "FullyQualifiedName~PendingReopenCloseOrDispose_DrainsCurrentOwnerWithoutPriorCompletionReplay"

Exit 1: 2 failed, 0 passed/skipped. Compilation succeeded.
Both theory cases established the same actual ordering:

1. Open real target A; independently prepare backup/approval; fully await its
   first Close and verify one target disposal.
2. Admit a new Open on a task-owned thread. The real factory creates target B,
   then signals/holds its second return before Application publication.
3. Call Close or Dispose while factory return is held; inspect its completion
   and the current Close task against the old lifetime's close task.
4. Release factory, observe Open completion/state and B's disposal count before
   finally draining/closing all owned work and targets.

Exact failure observations for BOTH Close and Dispose:

PriorTaskReused=True
CloseOrDisposeFinishedWhileFactoryHeld=True
OpenError=none
StateAfterFactoryRelease=Ready
CreatedTargetDisposeCount=0
ActualTargetDisposed=False

The Dispose observation means disposal returned through the prior close
completion and then the opening owner published Ready; it does not claim
the disposed session could authorize a physical operation. The reproduction
released barriers and explicitly closed/drained the late target in finally.
The test process exited normally; no stranded worker/process required killing.
The 10/20-second deadlines are cleanup safety guards, not timing-race evidence.

## Frozen corrective matrix

All rows below are PASSED after the fix.

| ID | Named executed evidence and exact post-fix outcome |
|---|---|
| C-01 | PendingReopenCloseOrDispose_DrainsCurrentOwnerWithoutPriorCompletionReplay(dispose:false), RejectedReopen_PreservesInactiveEvidenceAndDoesNotReuseCompletedClose and original CloseReopen tests. Normal target closes once; repeated same-lifetime Close shares one Task. Later explicit Open gets a different instance, no inherited backup/approval and independently read revision-zero scalar 650. |
| C-02 | PendingReopenCloseOrDispose_DrainsCurrentOwnerWithoutPriorCompletionReplay(dispose:false). Current Close is not prior Close, remains incomplete while actual second factory return is held and remains incomplete while target disposal is held. Repeated current Close shares that new completion. After releases, Open is cancelled, state remains Closed, old inactive backup/approval references remain, B disposal invocation=1/completion=true, and its actual Read throws ObjectDisposedException. No late Ready/current target is published. |
| C-03 | The same regression with dispose:true. Dispose cannot finish through old close completion; it drains current Open and the one real B disposal. Closed/no-busy state and inactive evidence remain. After disposal completes, NewOperationId and Open reject Closed; no Ready/backup/approval publication or disposed-session reuse occurs. Native calibration unmount/re-entry also passed as normal lifecycle evidence. |
| C-04 | PendingReopenAfterFailedClose_CurrentCleanupHasItsOwnSharedOutcome (current cleanup succeeds/fails), PendingFactoryFailure_CurrentCloseDrainsItsOwnFailureAndRetainsInactiveEvidence, RejectedReopen_PreservesInactiveEvidenceAndDoesNotReuseCompletedClose. Prior failed close is not replayed as current completion. Current Close shares its own unfinished Task; actual cleanup occurs once. Current factory/target errors remain explicit IOException/current-error evidence, not stale failure or swallowed success. Rejected/failed Open preserves inactive backup state. A later valid sequential Open remains usable with fresh identity/backup state. |
| C-05 | Combined corrective/original rehearsal selector: 37 passed. Full build/test: all nine Release projects, 179 unit + 263 integration = 442 passes, zero failed/skipped, preserving every one of the 436 baseline cases. Native actual target/backup/Apply/Restore/repeated Close/reopen/route cleanup plus source/unit isolation passed. No target/port/model/programming redesign, physical operation or AI work. |

## Acceptance criteria

| ID | Result | Evidence |
|---|---|---|
| AC-01 | PASSED | Safely cleaned actual pre-fix Close/Dispose reproduction and post-fix factory-return/disposal barriers prove current completion, cancellation/drain, one real disposal and no late publication. |
| AC-02 | PASSED | Prior/current failed close, factory failure, rejected Open, shared completion/error, retained inactive evidence and later valid sequential Open cases; own source-path ordering review. |
| AC-03 | PASSED | All 436 baseline cases plus 6 new cases pass; nine-project Release build has 0 warnings/errors; actual native normal recheck/source-unit/route cleanup passed. |
| AC-04 | PASSED | Surgical session-only production change, directly related docs/README, protected/history/dependencies/manual gate preserved, this single fenced report saved and worker stops. |

## Commands and final outcomes

Current SDK: dotnet --version -> 10.0.403. Existing xUnit v2/VSTest is
unchanged. No package/SDK/workload/tool install, restore, update or repair.

Focused checks, required full build and full regressions ran sequentially:

| Exact command | Exit | Result |
|---|---:|---|
| dotnet test .\src\tests\AutoForge.IntegrationTests\AutoForge.IntegrationTests.csproj --configuration Release --no-restore --filter "FullyQualifiedName~CalibrationRehearsalReopenTests" | 0 | 6 corrective cases passed, zero failed/skipped. |
| dotnet test .\src\tests\AutoForge.IntegrationTests\AutoForge.IntegrationTests.csproj --configuration Release --no-restore --filter "FullyQualifiedName~CalibrationRehearsalReopenTests|FullyQualifiedName~CalibrationRehearsalTests|FullyQualifiedName~RenderedRehearsal|FullyQualifiedName~RehearsalIsolation" | 0 | 37 corrective/original rehearsal cases passed, zero failed/skipped. |
| dotnet build .\src\AutoForge.slnx --configuration Release --no-restore | 0 | All nine projects/native Client; 0 warnings, 0 errors. MAUI XAML source-generation notice was informational. |
| dotnet test .\src\AutoForge.slnx --configuration Release --no-build | 0 | 179 unit + 263 integration = 442 passed, zero failed/skipped. |
| git --no-pager diff --check | 0 | No whitespace errors. Existing README/build-guide LF-to-CRLF notices only. |
| git --no-pager diff --exit-code -- prompts global.json Directory.Build.props Directory.Packages.props NuGet.Config src\AutoForge.Core src\AutoForge.Diagnostics src\AutoForge.Simulation src\AutoForge.Client src\AutoForge.UI src\AutoForge.Application\Features\Vehicles\Telemetry | 0 | Existing assignments/history/dependencies, targets/ports/models, Client/UI and recording/replay implementations unchanged before adding this report. |

Per-project Release results: AutoForge.Core, AutoForge.Diagnostics,
AutoForge.Simulation, AutoForge.Application, AutoForge.Components,
AutoForge.UI, AutoForge.Client, AutoForge.UnitTests and
AutoForge.IntegrationTests all PASSED. The portable projects remain net10.0;
Client remains net10.0-windows10.0.26100.0 / win-x64.

The 436 baseline cases are unchanged (179 unit/257 integration); only six
integration cases were added. Audit maximum remains 32 dispatched outcomes;
supported scalar/table, source/axis/unit/value validation, original backup,
approval/CAS/readback/unknown/reconcile/Restore and authoring/recording/replay
limits and semantics remain unchanged.

## Native versus controlled evidence

The actual rebuilt Windows Client was operated through a task-only WebView2
profile/local DevTools port 9381 using a temporary built-in Node/WebSocket
helper. There was no new host/dependency/production fault selector.

Native recheck:

- Explicit warm configuration/authoring proposal creation remained isolated:
  saving 1250 rpm and 350 N*m at 2000 rpm left rehearsal Inactive/audit 0.
- Explicit target Open and two-read backup succeeded at revision 0.
  Target was bdfed79dadeb44c5a74f46ec20f0320b; original backup
  efc45e9fd5a5418d9b33730d1fa0de9f.
- A Metric->Imperial switch preserved the complete unconsumed approval and
  audit 0. Confirmed Apply produced VerifiedApplied/revision 1 with scalar
  1250, torque cells (240,300,350,350,300,180) and all original rpm axes.
  This was one explicitly combined scalar/table proposal, not a claim to
  replace the preserved Step-10 two-Apply native evidence.
- Separately prepared/confirmed original Restore produced VerifiedRestored/
  revision 2: scalar 650, original torque (240,300,360,350,300,180), with
  axes 650,1000,2000,3200,4200,5000 unchanged. Restore operation was
  42fa9450fe8144e8997718c4f93e9034.
- Close/repeated Close completed normally and labeled the old backup inactive.
  Fresh Open produced a4d9d812ee394efa85b32e04dddfc14e with no prior backup,
  approval or audit. Its independently prepared fresh backup
  b8ea82c74a034c008f07144abd468ee6 was revision zero.
- Navigating away with that fresh target and returning to calibration showed
  a new Inactive page session, audit 0 and no old target identity.
- Original configuration export stayed exactly identical, fingerprint
  sha256:v1:e8991ae139b54959ec53a4fe64b08dc9bfc03feb533496cf741f2c9f3a2342da.
  Source warm-idle parameter remained 650 and torque at 2000 rpm remained 360.
  A separate ordinary dynamics read at model step 7 / 0.7 seconds returned
  631.80416 rpm / Good / SYNTHETIC_DYNAMIC from the unchanged model.
- Original Metric/Road preference values were restored and observed.
  Existing replay and Home routes worked; replay remained Unloaded.
  No unhandled native error overlay occurred.

The pending synchronous factory-return race is controlled test proof, not a
human-timed native claim. Native recheck verifies normal current-lifetime
behavior only. No new physical/model write, durable backup or AI capability is
claimed; original Step-10 programming/native evidence is preserved unchanged.

Cleanup PASSED: task-owned Client PID 43960 completed after route cleanup.
Only task-owned specific PIDs were targeted; transient WebView PIDs 40112/
44776 were checked against the task profile before cleanup. No owned WebView
process/listener remained; port 9381 was closed. Exact task profile/helper
were removed. Native source/proposal/rehearsal data were process-memory only,
and the app-local recordings directory remained empty. No unrelated archive,
default WebView data, user file or preference was reset.

## Own post-green source-path review

Reviewed NewOperationId/Start admission -> actual synchronous factory return ->
Open publication/failed-target cleanup -> Close ownership/cancellation ->
opening-owner and target drainage -> Closed/shared completion ->
Dispose/permanent-use rejection. Reviewed the existing UI disposal consumer
to confirm it invokes the same corrected service lifetime path; no UI change
was required.

Normal, repeated, pending, cancelled, disposed, prior failed-close, current
failed-open/cleanup and later sequential-reopen paths were walked against the
matrix. The old completion is retired only for a newly admitted opening owner,
not an exact cached command replay. Reset and owner publication occur under
the same gate before factory execution. Current Close binds its shared task
before cancellation, invalidates the real owner and awaits outside the gate.
Disposed/generation guards prohibit late publication. Opening owner cleanup
owns a late unregistered target, avoiding double disposal.

After the first six-case green run, the review made Closed state and current
close completion/failure publication atomic under the state gate, eliminating
an exposed Closed-before-completion admission window. Async continuations
remain outside cleanup-required waiting. The test wrapper also safely disposes
an already-created target if its factory safety deadline expires.
Affected focused/original checks and full build/regressions were rerun:
37/442 passed. Barriers are released and opening/closing/provider resources
drained in finally; real target disposal is asserted. No known unresolved
defect in the assigned corrective exit contract remains.

## Documentation and preservation

Updated [README.md](../README.md),
[documentation index](../docs/README.md),
[architecture](../docs/architecture.md),
[build/test guide](../docs/build-and-test.md) and
[rehearsal lifecycle contracts](../docs/calibration-rehearsal.md).
They align admission-time close ownership, current completion/error,
cancellation/drain/disposal and normal versus controlled evidence. Original
Step-10 result counts/native observations/report were not rewritten.
Step-10 remains not accepted pending manual corrective review; Step-11 remains
blocked and unimplemented.

Worktree began clean on main at f2a8c37 and HEAD is unchanged. Existing
prompts/state/roadmap/assignments/shared gate/reports and protected files were
not edited; this is the only new prompts file. The index remains empty.
All nine projects/references/dependencies and real target/port/model/core/UI/
Client/recording/replay/source contracts are preserved.
Source/tests stay under src/src/tests; docs stay under docs.

No project/package/host/protocol/schema/template/unit-limit/programming
redesign, hardware/model mutation, system installation, agent, automatic
handoff, staging, commit, push, destructive Git or unrelated cleanup occurred.

STOP.