plans/correct-state-machines-evaluation.md
The common baseline is merged PR6 commit
0be0cb40a (refactor: add correlated actor request settlement (#4143)).
That is the last merged main commit before either pilot changed its domain.
Image-generation PR8 and app-run PR7 were developed in the opposite order, but
both final pilot diffs descend from this foundation and are present in the PR9
base, 9ffdcca6d.
Reproduce the handwritten glue measurement from the repository root:
node scripts/measure-correct-state-machine-pilots.mjs \
--baseline 0be0cb40a \
--post HEAD
The script uses the TypeScript scanner, excludes blank and comment-only lines, deduplicates overlapping ranges within a category, and prints the exact commit-specific file/range inventory with its JSON result. Tests, generated code, comments, and shared framework implementation are excluded. Moving a domain wrapper into another production file is still counted.
The post-migration inventories are:
src/app_run/remote_manager.ts,
src/app_run/operations.ts, src/ipc/services/app_run_actor_service.ts,
and src/hooks/useRunApp.ts.src/hooks/useGenerateImage.ts,
src/image_generation/hooks.ts,
src/image_generation/request_scope.tsx,
src/ipc/services/image_generation_service.ts,
src/ipc/services/image_generation_actor_service.ts,
src/ipc/services/image_generation_operation_service.ts, and
src/ipc/services/image_generation_definition.ts.defineFrameworkCoveredRemoteMachine brands migrated definitions only when
they provide either a native runtime remote-intent contract or the narrow
completion-aware protocol-v1 declaration/operation pair. App-run and image
generation use that constructor. Production registration accepts only that
capability or the exact legacy compatibility capability for chat stream,
GitHub operations, plan handoff, and version preview.assertNoOwnedResources reports every declared resource class with owner,
machine, key, and generation. Existing pilot tests additionally inspect
operation registries, request scopes, and transport subscriptions at their
domain terminal/disposal boundaries.Unsafe production compatibility remains only in these unmigrated owners:
| Machine/domain | Exact files | Mechanism | Removal owner |
|---|---|---|---|
| chat stream | src/chat_stream/definition.ts, src/chat_stream/remote_manager.ts, src/ipc/services/chat_actor_deletion_fence.ts | protocol-v1 event widening, raw dispatch, ref-counting, deletion fence | Conditional follow-up A/C |
| app/chat creation | src/ipc/services/app_chat_creation_fence.ts | creation/deletion counter | Conditional follow-up C |
| GitHub operations | src/github_ops/useGithubOps.ts, src/ipc/services/github_ops_definition.ts, src/ipc/services/github_ops_service.ts, src/ipc/services/github_ops_presentation_service.ts | protocol-v1 widening, raw dispatch, deletion/reset counters, route map | Conditional follow-up A |
| version preview | src/hooks/useVersionPreview.ts, src/version_preview/VersionPreviewProvider.tsx, src/ipc/services/version_preview_definition.ts, src/ipc/services/version_preview_service.ts, src/ipc/services/version_preview_presentation_service.ts, src/ipc/services/version_preview_window_interest.ts | protocol-v1 widening, raw dispatch, bespoke waiter, deletion/reset counters, route/interest maps | Conditional follow-up A/B |
| plan handoff | src/plan_handoff/definition.ts, src/plan_handoff/remote_manager.ts, src/ipc/services/plan_handoff_service.ts | protocol-v1 widening and raw dispatch/enqueue | Conditional follow-up B/C |
| user input | src/user_input/read_model.ts | independent subscription ownership | Conditional follow-up C |
The executable source of truth, including every exact compatibility owner and
its expected mechanism count, is compatibilityBoundaryInventory in
src/distributed_machines/boundary_inventory.test_support.ts.
Migrated adapters are separately pinned:
The shared primitive suite is
src/distributed_machines/testing/framework_mechanism_conformance.test.ts.
Admission/authorization, request settlement, lifecycle, late producer, and
renderer races that require a full transport or domain state are covered by the
named framework and pilot tests cataloged in:
src/distributed_machines/testing/foundation_finding_catalog.tssrc/distributed_machines/testing/pilot_finding_catalog.tssrc/distributed_machines/remote_transport.test.tssrc/distributed_machines/operation_registry.test.tssrc/distributed_machines/actor_host_admission_gate.test.tssrc/app_run/main_actor.test.tssrc/image_generation/main_actor.test.tssrc/distributed_machines/use_machine_mutation.test.tsxThe shared resource inventory includes prepared requests, admitted operations, pending receipts, waiters, subscriptions/leases, fences/continuations, tasks/timers, producer sinks, actors, terminal payloads, renderer listeners, and renderer request owners. The reusable harness reaches zero in each terminal/disposal scenario it owns using registry and gate inspectors.
This audit does not prove one aggregate zero-resource snapshot for every domain-specific terminal permutation. Existing focused tests prove the individual app-run and image resource owners, but the lack of a unified domain-level inspector remains an authoring/diagnostic gap. There is also no single reusable runtime driver that instantiates both domain façades; the pilot-specific cases remain exact focused tests. This missing cross-pilot adapter is a conformance blocker, not completed evidence.
All exact finding mappings are executable inventory tests. Three applicable image-pilot findings remain negative invariants:
prepareAppDeletion() publishes disposed settlement and cancels provider
work before the database delete commits. If the database deletion fails,
the current fence can reopen, but the provider work and settlement cannot be
restored. The focused regression documents this irreversible pre-commit
boundary.None is hidden by a widened allowlist. They are framework-covered lifecycle or compatibility problems and block expansion.
At the pilot merge cutoffs, accepted HIGH/P1 findings were addressed and no validated HIGH/P1 thread remained open. PR9's six-finder adversarial local review and fix recheck validated 13 deduplicated findings (4 HIGH, 9 MEDIUM). The implementation fixes the production registration bypass, exact-inventory gaps, resource and historical-evidence assertions, and measurement defects; it removes the false cross-pilot conformance claim and records the missing reusable domain driver as a STOP blocker. No validated local-review HIGH/P1 defect remains unresolved. Trusted-author PR review is processed separately before handoff.
Positive percentages mean fewer handwritten framework-category lines. Negative percentages mean growth.
| Category | PR6 baseline LOC | Final pilot/PR9 LOC | Reduction |
|---|---|---|---|
| Admission/mutation | 221 | 467 | -111.3% |
| Subscription/ref-count | 55 | 0 | 100.0% |
| Promise/waiter/settlement | 159 | 116 | 27.0% |
| Deletion/fence | 0 | 12 | new |
| Late-producer guards | 83 | 90 | -8.4% |
| Total | 518 | 685 | -32.2% |
Raw actor dispatch in the ordinary renderer manager fell from three callsites to zero. The app-run hook continues to call its domain manager façade; that is not raw transport. One completion-aware main enqueue and one captured command-output enqueue remain behind framework/domain façades. Unsafe migrated escape hatches: 0.
| Category | PR6 baseline LOC | Final pilot/PR9 LOC | Reduction |
|---|---|---|---|
| Admission/mutation | 49 | 289 | -489.8% |
| Subscription/ref-count | 0 | 0 | n/a |
| Promise/waiter/settlement | 66 | 278 | -321.2% |
| Deletion/fence | 24 | 113 | -370.8% |
| Late-producer guards/effect correlation | 59 | 101 | -71.2% |
| Total | 198 | 781 | -294.4% |
Ordinary hook/component raw dispatch fell from two callsites to zero. Two completion-aware protocol-v1 adapter dispatches and two destructive actor enqueues remain behind the image domain façade. Provider deletion/reset counters and initiator routing are explicitly migrated domain-owned boundaries, not ordinary-caller escape hatches. Unsafe migrated escape hatches: 0.
Both pilots miss the required 30% reduction by a wide margin. The measurement counts new domain-specific request adapters and operation-service wrappers even when they delegate to shared primitives; excluding those handwritten production lines would misstate authoring cost.
Measured on the same macOS checkout and Node/npm environment, after one warm-up:
| Measurement | Command | Result |
|---|---|---|
| Shared conformance wall time | /usr/bin/time -p npm test -- src/distributed_machines/testing/framework_mechanism_conformance.test.ts | 0.86 s wall; 7 tests, 312 ms Vitest duration |
| Targeted pilot suite | the exact 18-file command below | 3.75 s wall; 360 tests, 3.28 s Vitest duration |
PR6 npm run ts | three warm runs | 1.78 s median (1.78, 1.79, 1.78) |
PR9 npm run ts | three warm runs | 1.71 s median (1.82, 1.70, 1.71) |
There is no material type-check regression. The contract/conformance presubmit is far below two minutes.
Reproduce the targeted pilot suite:
/usr/bin/time -p npm test -- \
src/distributed_machines/boundary_inventory.test.ts \
src/distributed_machines/testing/framework_mechanism_conformance.test.ts \
src/distributed_machines/testing/pilot_finding_catalog.test.ts \
src/distributed_machines/testing/machine_conformance.test.ts \
src/distributed_machines/remote_transport.test.ts \
src/distributed_machines/operation_registry.test.ts \
src/distributed_machines/actor_host_admission_gate.test.ts \
src/distributed_machines/actor_host.test.ts \
src/distributed_machines/prepared_request.test.ts \
src/distributed_machines/remote_client.test.ts \
src/distributed_machines/use_machine_mutation.test.tsx \
src/app_run/main_actor.test.ts \
src/ipc/services/app_run_actor_service.test.ts \
src/image_generation/main_actor.test.ts \
src/ipc/services/image_generation_actor_service.test.ts \
src/ipc/services/image_generation_operation_service.test.ts \
src/ipc/services/image_generation_service.test.ts \
src/hooks/useGenerateImage.test.tsx
remoteIntent/correlated
operation outcome path and restore the protocol-v1 manager adapter at the
domain composition root. No persistent data conversion is required.remoteOperation, the operation-wait IPC,
and the completion-aware request adapter to restore the PR6 transport shape.
No persistent data conversion is required.Behavior-preserving pilot refactors do not prove future review-churn reduction. The 50% normalized target remains unproven until two comparable future new machine or lifecycle/protocol migration PRs exist.
For each qualifying PR, record:
Do not combine unlike PRs or infer a reduction when fewer than two qualifying future PRs exist.
All expansion work is blocked. Do not begin presentation routing,
OperationRouteRegistry, remaining remote-intent migrations, durable
checkpoint pilots, chat/plan ownership, GitHub/version-preview migrations,
generated bindings, or host representation work. Narrow corrective work may
reduce the measured domain adapters or repair the two image lifecycle blockers,
but it must be re-measured before reconsidering expansion.
STOP: the framework did not reduce bespoke lifecycle work in either pilot and retains named framework-covered lifecycle gaps; do not expand it.