Skip to content

Commit 9794df6

Browse files
committed
refactor(replay): drop the carried gate wait; replay evidence stays the readiness diagnostic
1 parent abc995e commit 9794df6

7 files changed

Lines changed: 3 additions & 94 deletions

File tree

‎packages/contracts/src/replay.ts‎

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
import type { DaemonError } from '@agent-device/kernel/errors';
22
import type { DaemonResponse } from '@agent-device/kernel/contracts';
33
import type { Rect, SnapshotState } from '@agent-device/kernel/snapshot';
4-
import type { ReadinessWaitEvidence } from './interaction.ts';
54
import type { GestureExecutionProfile } from './gesture-plan-types.ts';
65
import type { SessionScope } from './session-scope.ts';
76
import type { SnapshotDiagnosticsSummary } from './snapshot-diagnostics.ts';
@@ -261,12 +260,6 @@ export type ReplayDispatchOptions = Readonly<{
261260
* (pre-action) when its winner differs in local identity OR structural position.
262261
*/
263262
replayTargetGuard?: ReplayTargetGuardDenotation;
264-
/**
265-
* The wait the replay step's pre-dispatch target gate already spent, set ONLY by the replay step
266-
* loop when it polled more than once. The interaction response builder adds it to the dispatch's
267-
* own wait so a successful step reports one `readiness` for the whole step.
268-
*/
269-
replayReadinessWait?: ReadinessWaitEvidence;
270263
/** Dual-endpoint counterpart of `replayTargetGuard` for target-authored drag. */
271264
replayTargetGuards?: Readonly<{
272265
source: ReplayTargetGuardDenotation;

‎packages/replay-port/src/daemon-port/session-replay-dispatch-narrowing.ts‎

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ import type {
88
} from '@agent-device/ad-replay';
99
import type { LocalIdentity } from '@agent-device/ad-script';
1010
import type { TargetAncestryEntry } from '@agent-device/contracts/replay';
11-
import type { ReadinessWaitEvidence } from '@agent-device/contracts/interaction';
1211
import {
1312
isReplayTargetGuardMismatchResponse,
1413
isWaitLandmarkMismatchResponse,
@@ -63,16 +62,6 @@ export function applyReplayDispatchGuard(
6362
: replayReq;
6463
}
6564

66-
/** Carries the wait the pre-dispatch gate spent into the dispatch, so its success response reports it. */
67-
export function applyReplayReadinessWait(
68-
replayReq: ReplayDispatchRequest,
69-
wait: ReadinessWaitEvidence | undefined,
70-
): ReplayDispatchRequest {
71-
return wait
72-
? { ...replayReq, dispatch: { ...replayReq.dispatch, replayReadinessWait: wait } }
73-
: replayReq;
74-
}
75-
7665
function readGuardMismatchObservedIdentity(value: unknown): LocalIdentity | undefined {
7766
if (!value || typeof value !== 'object' || Array.isArray(value)) return undefined;
7867
const record = value as Record<string, unknown>;

‎packages/replay-port/src/daemon-port/session-replay-runtime-engine-adapter.ts‎

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,6 @@ import type { ObservationEvidence } from '@agent-device/capture-kit/observe-unti
3131
import { collectReplayActionArtifactPaths } from '@agent-device/replay-port/session-replay-runtime-artifacts';
3232
import {
3333
applyReplayDispatchGuard,
34-
applyReplayReadinessWait,
3534
classifyReplayDispatchFailure,
3635
toAdReplayStepFailure,
3736
} from './session-replay-dispatch-narrowing.ts';
@@ -271,10 +270,7 @@ export function createAdReplayStepRuntime(params: {
271270
readinessTimeoutMs: gateWait.remainingBudgetMs,
272271
}
273272
: {}),
274-
req: applyReplayReadinessWait(
275-
applyReplayDispatchGuard(ctx.replayReq, guard),
276-
gateWait && { polls: gateWait.readiness.polls, waitedMs: gateWait.readiness.waitedMs },
277-
),
273+
req: applyReplayDispatchGuard(ctx.replayReq, guard),
278274
sessionName: ctx.sessionName,
279275
action,
280276
resolved: resolvedAction,

‎src/daemon/__tests__/replay-target/session-replay-target-verification-runtime.test.ts‎

Lines changed: 0 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -225,34 +225,6 @@ test('an annotated click whose target renders on the second capture waits for it
225225
]);
226226
});
227227

228-
test('a step that waited in the gate hands its wait to the dispatch for the success response', async () => {
229-
const scene = replayScriptScene('agent-device-replay-target-verify-wait-evidence-', [
230-
SAVE_ANNOTATION,
231-
'click id="save"',
232-
]);
233-
234-
mockDispatchCommand.mockResolvedValueOnce(emptyCapture()).mockResolvedValue(saveButtonCapture());
235-
236-
const response = await scene.replay();
237-
238-
expect(response.ok).toBe(true);
239-
expect(scene.invoked[0]?.internal?.replayReadinessWait).toEqual({ polls: 2, waitedMs: 200 });
240-
});
241-
242-
test('a step whose gate hit on the first capture hands no wait to the dispatch', async () => {
243-
const scene = replayScriptScene('agent-device-replay-target-verify-no-wait-evidence-', [
244-
SAVE_ANNOTATION,
245-
'click id="save"',
246-
]);
247-
248-
mockDispatchCommand.mockResolvedValue(saveButtonCapture());
249-
250-
const response = await scene.replay();
251-
252-
expect(response.ok).toBe(true);
253-
expect(scene.invoked[0]?.internal?.replayReadinessWait).toBeUndefined();
254-
});
255-
256228
test('the dispatch gets only the readiness budget the gate left', async () => {
257229
const scene = replayScriptScene('agent-device-replay-target-verify-shared-budget-', [
258230
SAVE_ANNOTATION,

‎src/daemon/interaction/internal/__tests__/interaction-touch-response.test.ts‎

Lines changed: 0 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -112,26 +112,6 @@ test('the response builder reports the resolved wait and keeps the prior warning
112112
expect(result.readiness).toBeUndefined();
113113
});
114114

115-
test('the response builder adds the wait the request carried to the dispatch wait', () => {
116-
const { responseData } = buildInteractionResponseData({
117-
source: { kind: 'runtime', result: WAITED_SELECTOR_RESULT },
118-
referenceFrame: undefined,
119-
carriedReadiness: { polls: 2, waitedMs: 200 },
120-
});
121-
122-
expect(responseData.readiness).toEqual({ polls: 5, waitedMs: 600 });
123-
});
124-
125-
test('the response builder reports the carried wait when the dispatch resolved on its first capture', () => {
126-
const { responseData } = buildInteractionResponseData({
127-
source: { kind: 'runtime', result: selectorResult() },
128-
referenceFrame: undefined,
129-
carriedReadiness: { polls: 2, waitedMs: 200 },
130-
});
131-
132-
expect(responseData.readiness).toEqual({ polls: 2, waitedMs: 200 });
133-
});
134-
135115
test('the response builder omits readiness when nothing waited', () => {
136116
const { responseData } = buildInteractionResponseData({
137117
source: { kind: 'runtime', result: selectorResult() },

‎src/daemon/interaction/internal/interaction-touch-response.ts‎

Lines changed: 1 addition & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ import type {
44
HoverCommandResult,
55
LongPressCommandResult,
66
PressCommandResult,
7-
ReadinessWaitEvidence,
87
RecordingTargetOverride,
98
ResolutionDisclosure,
109
SettleObservation,
@@ -173,8 +172,6 @@ export function buildInteractionResponseData(params: {
173172
* Only attached when the settle observation actually carries a diff.
174173
*/
175174
settleRefsGeneration?: number;
176-
/** A wait the request already spent before this dispatch (the replay step's pre-dispatch gate). */
177-
carriedReadiness?: ReadinessWaitEvidence;
178175
}): InteractionResponsePayloads {
179176
const { source, referenceFrame, extra } = params;
180177
if (source.kind === 'runner-payload' || source.kind === 'corroborated-tap') {
@@ -237,25 +234,10 @@ export function buildInteractionResponseData(params: {
237234
visualization.warning = warning;
238235
responseData.warning = warning;
239236
}
240-
const readiness = combineReadinessWaits(
241-
'readiness' in result ? result.readiness : undefined,
242-
params.carriedReadiness,
243-
);
244-
if (readiness) responseData.readiness = readiness;
237+
if ('readiness' in result && result.readiness) responseData.readiness = result.readiness;
245238
return { result: visualization, responseData, ...recordedTargetCapture(result) };
246239
}
247240

248-
function combineReadinessWaits(
249-
...waits: Array<ReadinessWaitEvidence | undefined>
250-
): ReadinessWaitEvidence | undefined {
251-
const spent = waits.filter((wait): wait is ReadinessWaitEvidence => wait !== undefined);
252-
if (spent.length === 0) return undefined;
253-
return {
254-
polls: spent.reduce((total, wait) => total + wait.polls, 0),
255-
waitedMs: spent.reduce((total, wait) => total + wait.waitedMs, 0),
256-
};
257-
}
258-
259241
function recordedTargetCapture(
260242
result: InteractionRuntimeResult,
261243
): Pick<InteractionResponsePayloads, 'recordedTarget'> {
@@ -330,7 +312,6 @@ export async function buildTargetedTouchResponsePayloads(params: {
330312
extra,
331313
staleRefsWarning: params.staleRefsWarning,
332314
settleRefsGeneration: issueSettleRefs(session, result.settle),
333-
carriedReadiness: handlerParams.req.internal?.replayReadinessWait,
334315
});
335316
}
336317

‎website/docs/docs/replay-e2e.md‎

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -62,9 +62,7 @@ agent-device replay ~/.agent-device/sessions/e2e-2026-02-09T12-00-00-000Z.ad --s
6262
they fail. A step recorded against a screen that was still loading passes on replay once the
6363
target shows up. The wait covers only a target that is not on screen yet: a target that is
6464
covered, off-screen, or matched by more than one element fails at once, as it does live.
65-
A step that had to wait and then passed reports it in `data.readiness` (`polls`, `waitedMs`).
66-
A step that found its target on the first look has no `readiness` field, so its presence marks a
67-
step that would have failed without the wait.
65+
Under `--debug`, each wait shows up as an `interaction_target_readiness` diagnostic.
6866
- When the target never appears, replay stops with `REPLAY_DIVERGENCE`, and
6967
`error.details.readiness` says how long the step waited and how many times it looked (`waitedMs`,
7068
`polls`, `end`). For a step recorded with a target annotation (the `# agent-device:target-v1`

0 commit comments

Comments
 (0)