Skip to content

Commit 6dc1e34

Browse files
authored
fix(interaction): measure the moving-target gate by adoption, not bounds (#3471) (#3548)
* fix(interaction): measure the moving-target gate by adoption, not bounds (#3471) The gate's `measured` flag accepted any capture whose rect agreed with the dispatched one. ADR 0014 keeps the authorized frame node when a captured node's identity differs, so a replacement control that took over the ref at the frame's own coordinates produced two agreeing "observations" while the dispatch went to the stale point. A look now counts only when the captured node matches the dispatched node's rect AND its local identity — the ADR 0014 adoption question in the value form that survives the session store's clone. One unmeasured look ends the recheck, so the refusal reports no `movedToRect` rather than a stale one, which is what its published shape now says. Screening for `stationary` compared positions across surfaces: a same-identity node on a newly arrived iOS system sheet could excuse both re-observations. The baseline's `surfaceBundleId` must now match the resolved surface's, the same line `post-action-surface.ts` draws. The hint interpolated a raw selector inside single quotes, so a label carrying an apostrophe taught a `wait` command that cannot run; it goes through the kernel's `shellQuoteIfNeeded` like the daemon's other recovery hints. That also moves the hint beside the refusal that publishes it, since contracts may not reach `device-shell` without growing its own eager closure. The lost-target test asserted only "not the motion refusal" and now names `ref_not_found` with `dispatched: 'no'`. * fix(interaction): keep a cross-surface look from certifying rest (#3471) The re-observations that certify a resting position agreed on the rect alone, while the screening that decides whether to recheck at all already compares surfaces. The same line has to hold in both: an iOS system sheet presented during the sample gap carries the same control at the same rect, and the gate would have read that as rest and dispatched onto the sheet (#2438's transition, guarding the other half of the same decision). A measured look now carries the surface it was measured on, and two looks agree only on one surface. The unmeasured refusals also pin what they withhold — no `movedToRect` when no look measured a position — and the `@ref` branch of the published recovery is now asserted on a real refusal rather than in the contracts suite the hint left. * ref(kernel): decide one position for two captured rects in one place (#3471) `movingTargetRectsStable` and `MOVING_TARGET_GATE_RECT_TOLERANCE_PX` copied the 4-field abs-compare against `RECT_TOLERANCE_PX = 1` that `rectsWithinTolerance` already ran for the post-gesture surface checks, and its own comment named that file as the source of the band. Two copies of one rule: change either band and the gate and the no-effect check disagree about the same pair of rects. `areCapturedRectsAtSamePosition` is that comparison, exported once from `@agent-device/kernel/rect-center` beside `normalizeRect` and `areRectsApproximatelyEqual`. It normalizes first, so a rect that reports no position never reports one position with another, and it owns the 1 px band while `areRectsApproximatelyEqual` keeps its 0.5 px band for "do these two values denote one point" — a different question, with a different reason to be strict. Both call sites now delegate: `rectsWithinTolerance`'s five surface comparisons call the helper directly, and the gate imports it in place of the contracts copy. The contracts module keeps the decision and the window; the band was never its fact to hold, so its constant and loop are gone along with the tests that pinned the constant's value. The band's assertions moved to `rect-center.test.ts` with the rule, including the per-axis 1 px / 2 px boundary and the asymmetry check the old suite made on the moved-to values rather than on the rule. Verified by mutating the band: at 0.5 px `a one-pixel shift is capture rounding, not motion` reddens, and relaxing the comparison to ignore the `width` axis reddens `the declared window is the 500 ms transition budget`'s neighbour, `one axis is enough to move`. * fix(ref): let the frame model report which tree a ref's node was read from (#3471) `measureRefObservation` re-derived the adoption rule that `reconcileFreshObservation` had already applied: it looked the ref up in the capture again and required the dispatched node to match it on rect and local identity. Two implementations of one ADR 0014 step 5 decision, so the day reconciliation gains or drops a rule, the gate can call a look "measured" on an adoption the rule no longer grants — or refuse one it does grant. `reconcileFreshObservation` now states what it chose, on every branch: `adoptedFrom: 'observation' | 'authorized-frame'`. The value rides the ref's `ResolvedInteractionTarget`, which is where a caller reads the node, rect and `preAction` it dispatched, so the provenance travels with the evidence it describes rather than being inferred from it afterwards. The gate reads that field: a look measured the target exactly when the resolution says it read the dispatched node out of the observation, and the look's surface now comes from that same capture through `surfaceScopedNodes` — the way the selector branch reads its resolution's `preAction` — instead of reaching for `snapshot.iosSystemSurfaceBundleId` directly. The two refusal tests are the ones that pay for this, and they are the reason rect agreement is still not enough: a different control that took over the ref at the frame's own coordinates produces two agreeing rects, and only the reported provenance says the dispatch read them from the authorized frame. Verified by mutating the reported value on each branch: reporting 'authorized-frame' where the observation was adopted reddens `the @ref path takes its own observations, because its resolution spends none`; reporting 'observation' on either keep-the-frame branch reddens `a ref the second observation cannot re-measure is refused, never self-agreed` and `a replacement that took the ref at the frame coordinates is refused, not agreed`. * ref(capture): give the settle loop the one capture-position rule too (#3471) `stableCaptureSignalsEqual` kept the repository's third copy of the "did this rect move" band: a 4-field abs-compare against a local `GEOMETRY_TOLERANCE_PX = 1` that rounded each field first. `areCapturedRectsAtSamePosition` is now the one place that decides it, so the quiet window, the post-gesture surface check and the moving-target gate cannot drift apart when the band changes. The rounding was load-bearing rather than cosmetic: comparing raw backend geometry against 1 px would restart the quiet window on pairs this loop has always called at rest, because a rect quantized to the pixel can sit up to 2 px apart raw and still be one pixel apart in the unit the band is measured in. So the quantization moves to `stableCaptureNodeSignal`, the one place a signal mints a rect, and the comparison becomes the shared rule over integers. The band is therefore unchanged, stated as a test rather than as a claim: 0.51 against 2.4 is rest, 0.51 against 3.4 is not, and reverting the quantization reddens it. `GEOMETRY_TOLERANCE_PX` and the local loop are deleted.
1 parent da29d7f commit 6dc1e34

13 files changed

Lines changed: 523 additions & 258 deletions

‎packages/ad-script/src/internal/target-annotation-identity.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@ export function demoteNonUniqueLocalIdentity(
126126
* role/id/label, NOT element identity, so two sibling rows both reading `label="Item"` are one
127127
* identity — and an ambiguous identity answers nothing, the same fail-closed direction
128128
* `demoteNonUniqueLocalIdentity` takes for a non-unique id. `#3471`'s moving-target gate pairs this
129-
* with `movingTargetRectsStable` to ask whether one node held its position between two trees.
129+
* with `areCapturedRectsAtSamePosition` to ask whether one node held its position between two trees.
130130
*/
131131
export function nodeRectByIdentity(
132132
nodes: readonly IdentityPositionedNode[],

‎packages/contracts/src/interaction.ts‎

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,9 @@ export type SurfaceScopedNodes = {
150150
surfaceBundleId?: string;
151151
};
152152

153+
/** Which tree a resolved `@ref`'s node was read from (ADR 0014 step 5). */
154+
export type RefObservationSource = 'observation' | 'authorized-frame';
155+
153156
export type ResolvedInteractionTarget =
154157
| {
155158
kind: 'point';
@@ -168,6 +171,16 @@ export type ResolvedInteractionTarget =
168171
resolution?: ResolutionDisclosure;
169172
recordingTarget?: RecordingTargetOverride;
170173
preAction?: SurfaceScopedNodes;
174+
/**
175+
* ADR 0014 step 5: which tree the dispatched node was read from, reported by the
176+
* reconciliation that chose it. `'observation'` means the session's newest capture, so the
177+
* node's rect is a position that capture measured; `'authorized-frame'` means the older tree
178+
* the ref was authorized against, whose rect says nothing about where the target sits now.
179+
* Reported rather than re-derived downstream from node or rect identity, so no caller can
180+
* disagree with the rule after the rule has decided. Absent on a node a caller carried in
181+
* (#1654), which no reconciliation chose.
182+
*/
183+
adoptedFrom?: RefObservationSource;
171184
}
172185
| {
173186
kind: 'selector';

‎packages/contracts/src/moving-target-gate.test.ts‎

Lines changed: 5 additions & 68 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,18 @@
11
import assert from 'node:assert/strict';
22
import { test } from 'vitest';
33
import {
4-
MOVING_TARGET_GATE_RECT_TOLERANCE_PX,
54
MOVING_TARGET_GATE_SAMPLE_GAP_MS,
65
MOVING_TARGET_GATE_WINDOW_MS,
76
movingTargetGateDecision,
8-
movingTargetRectsStable,
9-
targetStillMovingHint,
107
} from './moving-target-gate.ts';
118

129
// #3471: the two judgements the moving-target gate makes, isolated from both callers so the window
13-
// and the stability rule have exactly one reading. The runtime half (what a press does with these
10+
// and the stability rule have exactly one reading. Whether two captures count as one position is
11+
// kernel's `areCapturedRectsAtSamePosition`, tested beside the band it owns
12+
// (`packages/kernel/src/rect-center.test.ts`). The runtime half (what a press does with these
1413
// answers) is `src/commands/interaction/runtime/moving-target-gate.ts`; the Layer-3 scenarios behind
1514
// the ADR 0011 `targetStability` cells drive the whole press.
1615

17-
const RECT = { x: 100, y: 200, width: 120, height: 44 };
18-
19-
function shifted(over: Partial<typeof RECT> = {}) {
20-
return { ...RECT, ...over };
21-
}
22-
2316
// --- is a second observation owed? ---
2417

2518
test('a session with no mutation clock is idle and owes nothing', () => {
@@ -123,61 +116,5 @@ test('a clock skew ahead of the mutation does not produce a negative wait', () =
123116
assert.ok(decision.waitMs >= MOVING_TARGET_GATE_SAMPLE_GAP_MS);
124117
});
125118

126-
// --- has the target stopped? ---
127-
128-
test('two observations at the same rect are a resting position', () => {
129-
assert.equal(movingTargetRectsStable(RECT, shifted()), true);
130-
});
131-
132-
test('capture rounding within the declared tolerance is not motion', () => {
133-
assert.equal(MOVING_TARGET_GATE_RECT_TOLERANCE_PX, 1);
134-
assert.equal(movingTargetRectsStable(RECT, shifted({ x: RECT.x + 1 })), true);
135-
assert.equal(movingTargetRectsStable(RECT, shifted({ height: RECT.height + 1 })), true);
136-
});
137-
138-
test('one axis moving is enough to still be moving', () => {
139-
// The slide-in case from the #3471 repro (ADB Android): a translate animation keeps width and
140-
// height constant, so only one axis says the target moved.
141-
assert.equal(movingTargetRectsStable(RECT, shifted({ x: RECT.x + 2 })), false);
142-
assert.equal(movingTargetRectsStable(RECT, shifted({ y: RECT.y + 2 })), false);
143-
assert.equal(movingTargetRectsStable(RECT, shifted({ width: RECT.width + 2 })), false);
144-
assert.equal(movingTargetRectsStable(RECT, shifted({ height: RECT.height + 2 })), false);
145-
});
146-
147-
test('an observation that could not measure the target never agrees with one that could', () => {
148-
// Absence is the surface having changed under the point, which is the exposure the gate exists
149-
// to catch — so it can never be the observation that certifies rest.
150-
assert.equal(movingTargetRectsStable(RECT, undefined), false);
151-
assert.equal(movingTargetRectsStable(undefined, RECT), false);
152-
assert.equal(movingTargetRectsStable(undefined, undefined), false);
153-
assert.equal(movingTargetRectsStable(RECT, shifted({ width: Number.NaN })), false);
154-
});
155-
156-
test('the stability comparison is symmetric', () => {
157-
assert.equal(
158-
movingTargetRectsStable(shifted({ y: 205 }), RECT),
159-
movingTargetRectsStable(RECT, shifted({ y: 205 })),
160-
);
161-
});
162-
163-
// --- the refusal's published recovery ---
164-
165-
test('a refused selector press names the wait that recovers it', () => {
166-
const hint = targetStillMovingHint({ selector: 'label="Slide target"' });
167-
168-
assert.match(hint, /wait 'label="Slide target"'/);
169-
assert.match(hint, /same selector/);
170-
assert.match(hint, /--settle/);
171-
assert.match(hint, /nothing was tapped/);
172-
});
173-
174-
test('a refused @ref press is sent to a selector, because the wait would retire its frame', () => {
175-
// ADR 0014: the capture a `wait` takes expires the ref frame, so telling the caller to retry the
176-
// same ref would trade a motion refusal for a stale-ref refusal.
177-
const hint = targetStillMovingHint({ selector: undefined });
178-
179-
assert.match(hint, /snapshot -i/);
180-
assert.match(hint, /selector/);
181-
assert.match(hint, /ref frame/);
182-
assert.doesNotMatch(hint, /wait '/);
183-
});
119+
// The refusal's published recovery is asserted in the runtime gate's suite, where the hint lives
120+
// beside the refusal that publishes it (`movingTargetHint`); this module decides, it does not speak.
Lines changed: 17 additions & 68 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,24 @@
1-
import type { Rect } from '@agent-device/kernel/snapshot';
2-
import { normalizeRect } from '@agent-device/kernel/rect-center';
31
import type { SurfaceScopedNodes } from './interaction.ts';
42

53
/**
6-
* The moving-target gate (#3471): a press must not dispatch at a point an in-flight transition has
7-
* already vacated. A capture is one instant's photograph of a surface that may still be rearranging
8-
* itself, and the ADB-backed Android helper is measured reporting frames in flight — so a press
9-
* issued right after an action that moved the UI can resolve a point the target has already left and
10-
* report success on the vacancy. The exposure is the runtime path's own capture-to-dispatch
11-
* distance, so the gate is backend-neutral.
4+
* The pure half of the moving-target gate (#3471): a press must not dispatch at a point an
5+
* in-flight transition has already vacated. A capture is one instant's photograph of a surface that
6+
* may still be rearranging itself, and the ADB-backed Android helper is measured reporting frames in
7+
* flight — so a press issued right after an action that moved the UI can resolve a point the target
8+
* has already left and report success on the vacancy. The exposure is the runtime path's own
9+
* capture-to-dispatch distance, so the gate is backend-neutral.
1210
*
13-
* Two judgements decide when it is real, both pure over values the caller already holds so neither
14-
* is re-derived per platform: {@link movingTargetGateDecision} asks whether this position is still
15-
* owed a second observation, {@link movingTargetRectsStable} asks whether the target has stopped.
16-
* The window is anchored on the mutation's END, so the gate waits out only what is LEFT of it —
17-
* which is also why the refusal's hint names `--settle` as the caller-opted superset.
11+
* Two judgements decide when it is real: {@link movingTargetGateDecision} asks whether this position
12+
* is still owed a second observation, and kernel's `areCapturedRectsAtSamePosition` asks whether the
13+
* target has stopped — that one lives in `@agent-device/kernel/rect-center` because the post-gesture
14+
* no-effect comparison judges the same pair of capture rects and must not hold its own band. Both
15+
* are pure over values the caller already holds, so neither is re-derived per platform. The window is
16+
* anchored on the mutation's END, so the gate waits out only what is LEFT of it — which is also why
17+
* the refusal's hint names `--settle` as the caller-opted superset.
18+
*
19+
* What cannot be decided over values — spending the window, taking the re-observations, and the
20+
* refusal with its reason (`INTERACTION_ERROR_REASONS.targetStillMoving`) and hint — lives in
21+
* `src/commands/interaction/runtime/moving-target-gate.ts`, which produces all three together.
1822
*/
1923

2024
/** How long after a mutation its target positions stay owed a second observation. */
@@ -28,13 +32,6 @@ export const MOVING_TARGET_GATE_WINDOW_MS = 500;
2832
*/
2933
export const MOVING_TARGET_GATE_SAMPLE_GAP_MS = 50;
3034

31-
/**
32-
* How far a rect may shift between the two observations and still count as the same position.
33-
* Matches the tolerance the post-gesture surface comparison uses
34-
* (`src/daemon/interaction-surface-signature.ts`), so capture rounding never reads as motion.
35-
*/
36-
export const MOVING_TARGET_GATE_RECT_TOLERANCE_PX = 1;
37-
3835
/**
3936
* The tree a mutation resolved against, kept on the session with the instant that mutation
4037
* finished, so the next action can ask whether its own coordinates are still in play.
@@ -86,51 +83,3 @@ export function movingTargetGateDecision(params: {
8683
waitMs: Math.max(MOVING_TARGET_GATE_WINDOW_MS - ageMs, MOVING_TARGET_GATE_SAMPLE_GAP_MS),
8784
};
8885
}
89-
90-
/**
91-
* Whether two consecutive observations put the target at the same position. A rect either
92-
* observation could not measure is not stable: absence is the surface having changed under the
93-
* point, which is the exposure the gate exists to catch.
94-
*/
95-
export function movingTargetRectsStable(
96-
first: Rect | undefined,
97-
second: Rect | undefined,
98-
): boolean {
99-
// `normalizeRect` is the repository's one "this rect reports a position" rule, so the gate can
100-
// never measure a target the tap-point resolver itself would refuse to place. The tolerance stays
101-
// here rather than in kernel's 0.5 px `areRectsApproximatelyEqual`: that one asks whether two
102-
// values denote one point, this one asks whether capture rounding counts as motion, and 1 px is
103-
// the band the post-gesture surface comparison already uses.
104-
const a = normalizeRect(first);
105-
const b = normalizeRect(second);
106-
if (!a || !b) return false;
107-
return (
108-
Math.abs(a.x - b.x) <= MOVING_TARGET_GATE_RECT_TOLERANCE_PX &&
109-
Math.abs(a.y - b.y) <= MOVING_TARGET_GATE_RECT_TOLERANCE_PX &&
110-
Math.abs(a.width - b.width) <= MOVING_TARGET_GATE_RECT_TOLERANCE_PX &&
111-
Math.abs(a.height - b.height) <= MOVING_TARGET_GATE_RECT_TOLERANCE_PX
112-
);
113-
}
114-
115-
/**
116-
* The hint published beside a `target_still_moving` refusal — the recovery that works, with its
117-
* wording owned here so every producer publishes one text. Pairing the two is a convention rather
118-
* than something this module enforces: the reason is a literal in the vocabulary every interaction
119-
* adapter reads (`INTERACTION_ERROR_REASONS.targetStillMoving` in
120-
* `packages/selectors/src/interaction-error.ts`), so a producer could raise it without this hint.
121-
* The runtime moving-target gate is the only producer today and publishes both together.
122-
*
123-
* A selector re-resolves against a fresh capture and can be retried as-is. An `@ref` cannot survive
124-
* the wait: the capture a `wait` takes retires the ref frame (ADR 0014), which is the same reason
125-
* the off-screen guard sends its `@ref` refusals to a selector.
126-
*/
127-
export function targetStillMovingHint(params: { selector: string | undefined }): string {
128-
const reobserve = params.selector
129-
? `Run wait '${params.selector}' and retry with the same selector`
130-
: 'Run snapshot -i and retry with a selector (text=/id=) rather than this @ref — re-observing retires the ref frame';
131-
return (
132-
'The target was still moving when the transition window after the previous action ran out, so no resting ' +
133-
`position could be confirmed and nothing was tapped. ${reobserve}; or pass --settle to have the action itself ` +
134-
'wait for the UI to go quiet.'
135-
);
136-
}

‎packages/kernel/src/rect-center.test.ts‎

Lines changed: 54 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
import { expect, test } from 'vitest';
2-
import { interiorCoordinate, pointInsideRect } from './rect-center.ts';
2+
import {
3+
areCapturedRectsAtSamePosition,
4+
interiorCoordinate,
5+
pointInsideRect,
6+
} from './rect-center.ts';
37

48
test('interiorCoordinate preserves one-pixel edge controls', () => {
59
expect(interiorCoordinate(0, 1)).toBe(0);
@@ -11,3 +15,52 @@ test('pointInsideRect clamps center point inside the rect bounds', () => {
1115
y: 13,
1216
});
1317
});
18+
19+
const CAPTURED = { x: 100, y: 200, width: 120, height: 44 };
20+
21+
function shifted(over: Partial<typeof CAPTURED> = {}) {
22+
return { ...CAPTURED, ...over };
23+
}
24+
25+
test('two captures at the same rect report one position', () => {
26+
expect(areCapturedRectsAtSamePosition(CAPTURED, shifted())).toBe(true);
27+
});
28+
29+
test('a one-pixel shift is capture rounding, not motion', () => {
30+
expect(areCapturedRectsAtSamePosition(CAPTURED, shifted({ x: CAPTURED.x + 1 }))).toBe(true);
31+
expect(areCapturedRectsAtSamePosition(CAPTURED, shifted({ height: CAPTURED.height + 1 }))).toBe(
32+
true,
33+
);
34+
});
35+
36+
test('the band is one pixel on every axis, and one axis is enough to move', () => {
37+
// The slide-in case from the #3471 repro (ADB Android): a translate animation keeps width and
38+
// height constant, so only one axis says the target moved.
39+
expect(areCapturedRectsAtSamePosition(CAPTURED, shifted({ x: CAPTURED.x + 2 }))).toBe(false);
40+
expect(areCapturedRectsAtSamePosition(CAPTURED, shifted({ y: CAPTURED.y + 2 }))).toBe(false);
41+
expect(areCapturedRectsAtSamePosition(CAPTURED, shifted({ width: CAPTURED.width + 2 }))).toBe(
42+
false,
43+
);
44+
expect(areCapturedRectsAtSamePosition(CAPTURED, shifted({ height: CAPTURED.height + 2 }))).toBe(
45+
false,
46+
);
47+
});
48+
49+
test('a rect that reports no position never reports one position with another', () => {
50+
// Absence is the surface having changed under the point, so it can never be the observation that
51+
// certifies rest, for either the moving-target gate or the post-gesture no-effect claim.
52+
expect(areCapturedRectsAtSamePosition(CAPTURED, undefined)).toBe(false);
53+
expect(areCapturedRectsAtSamePosition(undefined, CAPTURED)).toBe(false);
54+
expect(areCapturedRectsAtSamePosition(undefined, undefined)).toBe(false);
55+
expect(areCapturedRectsAtSamePosition(CAPTURED, shifted({ width: Number.NaN }))).toBe(false);
56+
expect(areCapturedRectsAtSamePosition(CAPTURED, shifted({ width: -1 }))).toBe(false);
57+
});
58+
59+
test('the comparison is symmetric', () => {
60+
expect(areCapturedRectsAtSamePosition(shifted({ y: 201 }), CAPTURED)).toBe(
61+
areCapturedRectsAtSamePosition(CAPTURED, shifted({ y: 201 })),
62+
);
63+
expect(areCapturedRectsAtSamePosition(shifted({ y: 202 }), CAPTURED)).toBe(
64+
areCapturedRectsAtSamePosition(CAPTURED, shifted({ y: 202 })),
65+
);
66+
});

‎packages/kernel/src/rect-center.ts‎

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,14 @@ import { centerOfRect, type Point, type Rect } from '@agent-device/kernel/snapsh
33
const RECT_COMPARE_FIELDS = ['x', 'y', 'width', 'height'] as const;
44
const RECT_EQUALITY_TOLERANCE = 0.5;
55

6+
/**
7+
* The band within which two independently captured rects count as ONE position. Wider than
8+
* {@link areRectsApproximatelyEqual}'s band, which asks whether two values denote one point: this
9+
* one asks whether capture rounding counts as motion, and 1 px is the drift a backend's own
10+
* rounding can produce on a node that never moved.
11+
*/
12+
const CAPTURE_RECT_TOLERANCE_PX = 1;
13+
614
export function resolveRectCenter(rect: Rect | undefined): { x: number; y: number } | null {
715
const normalized = normalizeRect(rect);
816
if (!normalized) return null;
@@ -39,6 +47,26 @@ export function areRectsApproximatelyEqual(
3947
);
4048
}
4149

50+
/**
51+
* Whether two observations put a target at the SAME POSITION — the one rule that decides whether
52+
* capture rounding counts as motion, for every comparison of rects captured at different instants.
53+
*
54+
* Normalizes through {@link normalizeRect} first, so a rect that reports no position (absent,
55+
* non-finite, inverted) never compares equal to anything: absence is the surface having changed
56+
* under the point, never agreement.
57+
*/
58+
export function areCapturedRectsAtSamePosition(
59+
first: Rect | undefined,
60+
second: Rect | undefined,
61+
): boolean {
62+
const left = normalizeRect(first);
63+
const right = normalizeRect(second);
64+
if (!left || !right) return false;
65+
return RECT_COMPARE_FIELDS.every(
66+
(key) => Math.abs(left[key] - right[key]) <= CAPTURE_RECT_TOLERANCE_PX,
67+
);
68+
}
69+
4270
export function pointInsideRect(rect: Rect): Point {
4371
return {
4472
x: interiorCoordinate(rect.x, rect.width),

‎packages/selectors/src/interaction-error.ts‎

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -30,11 +30,13 @@ export const INTERACTION_ERROR_REASONS = {
3030
/** The target resolved, but another visible element covers it. */
3131
targetCovered: 'target_covered',
3232
/**
33-
* A press or click refused because its target's rect was still changing when the transition window
34-
* after the session's last mutating action ran out. `details.selector` or `details.ref` names the
35-
* target, `details.rect` where the command resolved it and `details.movedToRect` where the last
36-
* re-observation found it. Branch on this reason, not the message: the recovery is to wait for the
37-
* surface and retry, never to retry the same point immediately. The owner is
33+
* A press or click refused because it could not confirm a resting position for its target: the
34+
* target's rect was still changing when the transition window after the session's last mutating
35+
* action ran out, or a re-observation could not measure the position at all. `details.selector` or
36+
* `details.ref` names the target, `details.rect` is where the command resolved it, and
37+
* `details.movedToRect` where the last re-observation found it — present only when that look
38+
* measured one. Branch on this reason, not the message: the recovery is to wait for the surface
39+
* and retry, never to retry the same point immediately. The owner is
3840
* `src/commands/interaction/runtime/moving-target-gate.ts`, which raises the reason beside the
3941
* hint that names that recovery.
4042
*/

0 commit comments

Comments
 (0)