Skip to content

Commit 0ebd254

Browse files
authored
refactor(replay): bind the session and dispatch envelope inside the unit (#2663 PR A′) (#2686)
* refactor(replay): bind the replay session and dispatch envelope in the unit Moves the replay session binding and the request split + private-half merge out of the daemon handler into `src/daemon/replay/internal/`, over a structural `ReplaySessionContainer` and a `ReplaySessionPolicy`. The handler now supplies the daemon's reads and policy instead of owning the binding mechanics, which is what lets the replay unit move out of `src/daemon/` without taking the session store, the repair coordinator, the observation authority or snapshot capture with it. * refactor(replay): share one read set across the replay session's two views The bound session and the repair coordinator read the same session through the same four closures, so the handler names them once instead of writing the read set twice: scoping a read on one side and not the other was the drift this left open. Drops the `unknown` hop from the private-half merge cast, which muted the convertibility check without buying anything. * test(replay): carry the dispatch envelope's merge tests into the unit #2672 grew `session-replay-command.test.ts` coverage for the private-half merge while this branch moved that merge into the replay unit, so the two tests move with it and now sit beside `replay-dispatch-envelope.ts`. Assertions are unchanged. Reads `ReplayDispatchOptions` from its contracts declaration, which is where #2672 now declares it. * refactor(replay): name the replay façade's consumers only `ReplayDispatchRequest` and `ReplayInvoke` reached the façade while the handler still typed the nested dispatch itself. Binding the invoke moved that inside the unit, whose files take both types from `internal/command-types.ts`, so the two re-exports had no importer left and the Fallow gate called them dead on a file this branch already edits. The façade's pinned list shrinks with them. * test(replay): keep the façade bindings real under the handler trust doubles The trust test replaces the replay façade to watch what the handler hands the application command. The façade now also carries the session binding and the request split the handler calls on the way there, so the mock spreads the real module and doubles only the two entry points it observes. * refactor(replay): draw the command envelope from the command it feeds The envelope listed `request`, `publicNetworkOnly` and `resolvedSessionScope` by hand, which meant it also carried a second copy of the public-network doc sentence. Picked from `ReplayCommand` now: the envelope is by definition the part of the command a request answers to, so widening or renaming a member there moves this type with it instead of letting the two drift. * refactor(replay): state the container read contract the binding relies on The binding hands the container's four reads straight to the session store, so a read that needs a receiver would type-check and throw on first call. Says so on the type, and spreads the container instead of naming each read again.
1 parent e7a6b9c commit 0ebd254

20 files changed

Lines changed: 324 additions & 215 deletions

File tree

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
{"type":"replay_test_attempt_start","ts":"2026-09-19T14:27:51.710Z","replayPath":"/tmp/agent-device-test-run-23838-sCm2rx/agent-device-maestro-remote-test-faJ9EM/01-flow.yaml","session":"default:test:req-maestro-test-wire-true:1-01-flow:attempt-1","requestId":"req-maestro-test-wire-true:test:1:01-flow.yaml:attempt:1"}
2-
{"type":"replay_test_attempt_stop","ts":"2026-09-19T14:27:51.712Z","session":"default:test:req-maestro-test-wire-true:1-01-flow:attempt-1","ok":true,"timedOut":false,"durationMs":2}
3-
{"type":"replay_test_finalize_start","ts":"2026-09-19T14:27:51.712Z","session":"default:test:req-maestro-test-wire-true:1-01-flow:attempt-1"}
4-
{"type":"replay_test_finalize_stop","ts":"2026-09-19T14:27:51.712Z","session":"default:test:req-maestro-test-wire-true:1-01-flow:attempt-1","ok":true,"durationMs":0}
5-
{"type":"replay_test_cleanup_start","ts":"2026-09-19T14:27:51.712Z","session":"default:test:req-maestro-test-wire-true:1-01-flow:attempt-1"}
6-
{"type":"replay_test_cleanup_stop","ts":"2026-09-19T14:27:51.712Z","session":"default:test:req-maestro-test-wire-true:1-01-flow:attempt-1","ok":true,"durationMs":0}
1+
{"type":"replay_test_attempt_start","ts":"2026-09-19T14:32:46.818Z","replayPath":"/tmp/agent-device-test-run-75313-0YH0p7/agent-device-maestro-remote-test-pzCEKx/01-flow.yaml","session":"default:test:req-maestro-test-wire-true:1-01-flow:attempt-1","requestId":"req-maestro-test-wire-true:test:1:01-flow.yaml:attempt:1"}
2+
{"type":"replay_test_attempt_stop","ts":"2026-09-19T14:32:46.819Z","session":"default:test:req-maestro-test-wire-true:1-01-flow:attempt-1","ok":true,"timedOut":false,"durationMs":2}
3+
{"type":"replay_test_finalize_start","ts":"2026-09-19T14:32:46.819Z","session":"default:test:req-maestro-test-wire-true:1-01-flow:attempt-1"}
4+
{"type":"replay_test_finalize_stop","ts":"2026-09-19T14:32:46.820Z","session":"default:test:req-maestro-test-wire-true:1-01-flow:attempt-1","ok":true,"durationMs":1}
5+
{"type":"replay_test_cleanup_start","ts":"2026-09-19T14:32:46.820Z","session":"default:test:req-maestro-test-wire-true:1-01-flow:attempt-1"}
6+
{"type":"replay_test_cleanup_stop","ts":"2026-09-19T14:32:46.820Z","session":"default:test:req-maestro-test-wire-true:1-01-flow:attempt-1","ok":true,"durationMs":0}

‎.agent-device/test-artifacts/req-maestro-test-wire-true/01-flow.yaml/attempt-1/result.txt‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
file: /tmp/agent-device-test-run-23838-sCm2rx/agent-device-maestro-remote-test-faJ9EM/01-flow.yaml
1+
file: /tmp/agent-device-test-run-75313-0YH0p7/agent-device-maestro-remote-test-pzCEKx/01-flow.yaml
22
session: default:test:req-maestro-test-wire-true:1-01-flow:attempt-1
33
attempt: 1/1
44
status: passed
Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
{"type":"replay_test_attempt_start","ts":"2026-09-19T14:27:51.713Z","replayPath":"/tmp/agent-device-test-run-23838-sCm2rx/agent-device-maestro-remote-test-faJ9EM/02-flow.yaml","session":"default:test:req-maestro-test-wire-true:2-02-flow:attempt-1","requestId":"req-maestro-test-wire-true:test:2:02-flow.yaml:attempt:1"}
2-
{"type":"replay_test_attempt_stop","ts":"2026-09-19T14:27:51.714Z","session":"default:test:req-maestro-test-wire-true:2-02-flow:attempt-1","ok":true,"timedOut":false,"durationMs":1}
3-
{"type":"replay_test_finalize_start","ts":"2026-09-19T14:27:51.714Z","session":"default:test:req-maestro-test-wire-true:2-02-flow:attempt-1"}
4-
{"type":"replay_test_finalize_stop","ts":"2026-09-19T14:27:51.714Z","session":"default:test:req-maestro-test-wire-true:2-02-flow:attempt-1","ok":true,"durationMs":0}
5-
{"type":"replay_test_cleanup_start","ts":"2026-09-19T14:27:51.714Z","session":"default:test:req-maestro-test-wire-true:2-02-flow:attempt-1"}
6-
{"type":"replay_test_cleanup_stop","ts":"2026-09-19T14:27:51.714Z","session":"default:test:req-maestro-test-wire-true:2-02-flow:attempt-1","ok":true,"durationMs":0}
1+
{"type":"replay_test_attempt_start","ts":"2026-09-19T14:32:46.820Z","replayPath":"/tmp/agent-device-test-run-75313-0YH0p7/agent-device-maestro-remote-test-pzCEKx/02-flow.yaml","session":"default:test:req-maestro-test-wire-true:2-02-flow:attempt-1","requestId":"req-maestro-test-wire-true:test:2:02-flow.yaml:attempt:1"}
2+
{"type":"replay_test_attempt_stop","ts":"2026-09-19T14:32:46.821Z","session":"default:test:req-maestro-test-wire-true:2-02-flow:attempt-1","ok":true,"timedOut":false,"durationMs":1}
3+
{"type":"replay_test_finalize_start","ts":"2026-09-19T14:32:46.821Z","session":"default:test:req-maestro-test-wire-true:2-02-flow:attempt-1"}
4+
{"type":"replay_test_finalize_stop","ts":"2026-09-19T14:32:46.821Z","session":"default:test:req-maestro-test-wire-true:2-02-flow:attempt-1","ok":true,"durationMs":0}
5+
{"type":"replay_test_cleanup_start","ts":"2026-09-19T14:32:46.821Z","session":"default:test:req-maestro-test-wire-true:2-02-flow:attempt-1"}
6+
{"type":"replay_test_cleanup_stop","ts":"2026-09-19T14:32:46.821Z","session":"default:test:req-maestro-test-wire-true:2-02-flow:attempt-1","ok":true,"durationMs":0}

‎.agent-device/test-artifacts/req-maestro-test-wire-true/02-flow.yaml/attempt-1/result.txt‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
file: /tmp/agent-device-test-run-23838-sCm2rx/agent-device-maestro-remote-test-faJ9EM/02-flow.yaml
1+
file: /tmp/agent-device-test-run-75313-0YH0p7/agent-device-maestro-remote-test-pzCEKx/02-flow.yaml
22
session: default:test:req-maestro-test-wire-true:2-02-flow:attempt-1
33
attempt: 1/1
44
status: passed
Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
{"type":"replay_test_attempt_start","ts":"2026-09-19T14:27:51.718Z","replayPath":"/tmp/agent-device-test-run-23838-sCm2rx/agent-device-maestro-remote-test-QE9WSU/01-flow.yaml","session":"default:test:req-maestro-test-wire-undefined:1-01-flow:attempt-1","requestId":"req-maestro-test-wire-undefined:test:1:01-flow.yaml:attempt:1"}
2-
{"type":"replay_test_attempt_stop","ts":"2026-09-19T14:27:51.718Z","session":"default:test:req-maestro-test-wire-undefined:1-01-flow:attempt-1","ok":true,"timedOut":false,"durationMs":0}
3-
{"type":"replay_test_finalize_start","ts":"2026-09-19T14:27:51.718Z","session":"default:test:req-maestro-test-wire-undefined:1-01-flow:attempt-1"}
4-
{"type":"replay_test_finalize_stop","ts":"2026-09-19T14:27:51.719Z","session":"default:test:req-maestro-test-wire-undefined:1-01-flow:attempt-1","ok":true,"durationMs":1}
5-
{"type":"replay_test_cleanup_start","ts":"2026-09-19T14:27:51.719Z","session":"default:test:req-maestro-test-wire-undefined:1-01-flow:attempt-1"}
6-
{"type":"replay_test_cleanup_stop","ts":"2026-09-19T14:27:51.719Z","session":"default:test:req-maestro-test-wire-undefined:1-01-flow:attempt-1","ok":true,"durationMs":0}
1+
{"type":"replay_test_attempt_start","ts":"2026-09-19T14:32:46.823Z","replayPath":"/tmp/agent-device-test-run-75313-0YH0p7/agent-device-maestro-remote-test-Wnbhbp/01-flow.yaml","session":"default:test:req-maestro-test-wire-undefined:1-01-flow:attempt-1","requestId":"req-maestro-test-wire-undefined:test:1:01-flow.yaml:attempt:1"}
2+
{"type":"replay_test_attempt_stop","ts":"2026-09-19T14:32:46.823Z","session":"default:test:req-maestro-test-wire-undefined:1-01-flow:attempt-1","ok":true,"timedOut":false,"durationMs":0}
3+
{"type":"replay_test_finalize_start","ts":"2026-09-19T14:32:46.823Z","session":"default:test:req-maestro-test-wire-undefined:1-01-flow:attempt-1"}
4+
{"type":"replay_test_finalize_stop","ts":"2026-09-19T14:32:46.823Z","session":"default:test:req-maestro-test-wire-undefined:1-01-flow:attempt-1","ok":true,"durationMs":0}
5+
{"type":"replay_test_cleanup_start","ts":"2026-09-19T14:32:46.823Z","session":"default:test:req-maestro-test-wire-undefined:1-01-flow:attempt-1"}
6+
{"type":"replay_test_cleanup_stop","ts":"2026-09-19T14:32:46.823Z","session":"default:test:req-maestro-test-wire-undefined:1-01-flow:attempt-1","ok":true,"durationMs":0}

‎.agent-device/test-artifacts/req-maestro-test-wire-undefined/01-flow.yaml/attempt-1/result.txt‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
file: /tmp/agent-device-test-run-23838-sCm2rx/agent-device-maestro-remote-test-QE9WSU/01-flow.yaml
1+
file: /tmp/agent-device-test-run-75313-0YH0p7/agent-device-maestro-remote-test-Wnbhbp/01-flow.yaml
22
session: default:test:req-maestro-test-wire-undefined:1-01-flow:attempt-1
33
attempt: 1/1
44
status: passed
Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
{"type":"replay_test_attempt_start","ts":"2026-09-19T14:27:51.720Z","replayPath":"/tmp/agent-device-test-run-23838-sCm2rx/agent-device-maestro-remote-test-QE9WSU/02-flow.yaml","session":"default:test:req-maestro-test-wire-undefined:2-02-flow:attempt-1","requestId":"req-maestro-test-wire-undefined:test:2:02-flow.yaml:attempt:1"}
2-
{"type":"replay_test_attempt_stop","ts":"2026-09-19T14:27:51.720Z","session":"default:test:req-maestro-test-wire-undefined:2-02-flow:attempt-1","ok":true,"timedOut":false,"durationMs":0}
3-
{"type":"replay_test_finalize_start","ts":"2026-09-19T14:27:51.720Z","session":"default:test:req-maestro-test-wire-undefined:2-02-flow:attempt-1"}
4-
{"type":"replay_test_finalize_stop","ts":"2026-09-19T14:27:51.720Z","session":"default:test:req-maestro-test-wire-undefined:2-02-flow:attempt-1","ok":true,"durationMs":0}
5-
{"type":"replay_test_cleanup_start","ts":"2026-09-19T14:27:51.721Z","session":"default:test:req-maestro-test-wire-undefined:2-02-flow:attempt-1"}
6-
{"type":"replay_test_cleanup_stop","ts":"2026-09-19T14:27:51.721Z","session":"default:test:req-maestro-test-wire-undefined:2-02-flow:attempt-1","ok":true,"durationMs":0}
1+
{"type":"replay_test_attempt_start","ts":"2026-09-19T14:32:46.824Z","replayPath":"/tmp/agent-device-test-run-75313-0YH0p7/agent-device-maestro-remote-test-Wnbhbp/02-flow.yaml","session":"default:test:req-maestro-test-wire-undefined:2-02-flow:attempt-1","requestId":"req-maestro-test-wire-undefined:test:2:02-flow.yaml:attempt:1"}
2+
{"type":"replay_test_attempt_stop","ts":"2026-09-19T14:32:46.824Z","session":"default:test:req-maestro-test-wire-undefined:2-02-flow:attempt-1","ok":true,"timedOut":false,"durationMs":0}
3+
{"type":"replay_test_finalize_start","ts":"2026-09-19T14:32:46.824Z","session":"default:test:req-maestro-test-wire-undefined:2-02-flow:attempt-1"}
4+
{"type":"replay_test_finalize_stop","ts":"2026-09-19T14:32:46.824Z","session":"default:test:req-maestro-test-wire-undefined:2-02-flow:attempt-1","ok":true,"durationMs":0}
5+
{"type":"replay_test_cleanup_start","ts":"2026-09-19T14:32:46.824Z","session":"default:test:req-maestro-test-wire-undefined:2-02-flow:attempt-1"}
6+
{"type":"replay_test_cleanup_stop","ts":"2026-09-19T14:32:46.824Z","session":"default:test:req-maestro-test-wire-undefined:2-02-flow:attempt-1","ok":true,"durationMs":0}

‎.agent-device/test-artifacts/req-maestro-test-wire-undefined/02-flow.yaml/attempt-1/result.txt‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
file: /tmp/agent-device-test-run-23838-sCm2rx/agent-device-maestro-remote-test-QE9WSU/02-flow.yaml
1+
file: /tmp/agent-device-test-run-75313-0YH0p7/agent-device-maestro-remote-test-Wnbhbp/02-flow.yaml
22
session: default:test:req-maestro-test-wire-undefined:2-02-flow:attempt-1
33
attempt: 1/1
44
status: passed

‎scripts/layering/architecture-ownership.ts‎

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,19 +16,20 @@ const DAEMON_REPLAY_FACADE = {
1616
exports: [
1717
'ReplayCoordinator',
1818
'ReplayDaemonDependencies',
19-
'ReplayDispatchRequest',
20-
'ReplayInvoke',
2119
'ReplayResumeStamper',
2220
'ReplaySession',
2321
'ReplaySessionView',
2422
'ReplayTestVideoOwner',
2523
'appTargetResolutionOptions',
24+
'bindReplaySession',
2625
'buildMaestroReplayTargetDeviceResolutionOptions',
2726
'buildReplayScriptPlatformFlags',
2827
'healedScriptSiblingPath',
2928
'readScriptReplaySelection',
29+
'replayInvokeOverDispatch',
3030
'runReplayCommand',
3131
'runReplayTestCommand',
32+
'splitReplayCommandRequest',
3233
],
3334
} as const;
3435

‎src/daemon/handlers/__tests__/session-replay-command-trust.test.ts‎

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,11 @@ const { runReplayCommand, runReplayTestCommand } = vi.hoisted(() => ({
3434
})),
3535
}));
3636

37-
vi.mock('../../replay/index.ts', () => ({
37+
// The doubles replace only the two entry points. The handler also binds the session and splits the
38+
// request through this façade, and those bindings are part of what is pinned here, so the rest of
39+
// the module stays real.
40+
vi.mock('../../replay/index.ts', async (importOriginal) => ({
41+
...(await importOriginal<typeof import('../../replay/index.ts')>()),
3842
runReplayCommand,
3943
runReplayTestCommand,
4044
}));

0 commit comments

Comments
 (0)