fix(interaction): measure the moving-target gate by adoption, not bounds (#3471)
Summary
Part of #3471 (layer 2 of 3), on top of #3538. Judgement defects in the moving-target gate found in #3538's review, plus the disclosure and hint fixes they imply.
- A
@reflook measured the wrong node.measuredaccepted 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 reconciliation of the frame model says it read the dispatched node out of the observation (see the provenance bullet below) — the ADR 0014 adoption question, reported rather than re-derived. - Rest was granted across surfaces. Screening for
stationarycompared positions without comparingsurfaceBundleId, so a same-identity node on a newly arrived iOS system sheet could excuse both re-observations. It now requires one surface, the linepost-action-surface.tsalready draws. - The two looks that certify rest repeated the same hole. A sheet presented during the sample gap carries the same control at the same rect, and the pair agreed. A measured look now carries its surface, and a look taken on another presentation is demoted to the shape that already means "this look measured nothing": it cannot certify agreement and cannot contribute a reported position.
- One tolerance comparison, in one place.
movingTargetRectsStableandMOVING_TARGET_GATE_RECT_TOLERANCE_PXwere a second copy of the 4-field abs-compare against 1 px thatrectsWithinTolerancealready ran for the post-gesture surface checks.areCapturedRectsAtSamePositionis that comparison once, exported from@agent-device/kernel/rect-centerbesidenormalizeRectandareRectsApproximatelyEqual: it takes a rect pair, normalizes first, and owns the 1 px band.rectsWithinTolerance's five call sites call it directly and the gate calls it too; both local constants and both loops are deleted. A third copy then turned up in review:stableCaptureSignalsEqual, the settle loop's quiet-window comparison, held its ownGEOMETRY_TOLERANCE_PX = 1and its own loop, and it now calls the same helper, so the rule covers the three places that ask the question and no others. That loop rounded each field before comparing, and the rounding was load-bearing: raw geometry compared against 1 px is stricter than what that loop has always run, since a rect quantized to the pixel can sit 1.9 px apart raw while being one pixel apart in the unit the band measures. With no device in this pass to re-tune a timing rule that decides how long every iOS settle waits, the quantization moved tostableCaptureNodeSignal— the one place a signal mints a rect — and the shared comparison runs over integers, which is the old band, kept as a test rather than as a claim.areRectsApproximatelyEqualkeeps its 0.5 px band — it asks whether two values denote one point, which is a different question. - Ref adoption is reported, not re-derived.
reconcileFreshObservationnow states what it chose on every branch —adoptedFrom: 'observation' | 'authorized-frame'— riding the ref'sResolvedInteractionTarget, andmeasureRefObservationreads that value instead of matching node and rect identity a second time. The look's surface also comes from the same capture throughsurfaceScopedNodes, the way the selector branch reads its resolution'spreAction, instead of readingsnapshot.iosSystemSurfaceBundleIddirectly. - The suggested recovery could not run. The hint interpolated a raw selector inside single quotes, so
label="It's done"taught a broken command. It goes through the kernel'sshellQuoteIfNeeded, which also moves the hint beside the refusal that publishes it.
One unmeasured look ends the recheck, so a refusal reports no movedToRect rather than a stale one, and the reason's disclosure says which fields are optional. The screening tier's docblock now states that its claim is an inference from one tree and that the re-observations are the tier carrying evidence. Tests name the outcomes they were accepting-any-rejection about: refNotFound with dispatched: 'no', the withheld movedToRect, and the @ref branch of the hint.
13 files, 781 gross lines. Behaviour is still unreachable in production: no writer of movingTargetBaseline exists until #3539.
Where this layer's evidence is
This layer carries the code and its regression tests. The two evidence classes #3471 asks for live on #3539, and cannot live here:
- The ADR 0011
targetStabilitycells (packages/contracts/src/interaction-guarantees.ts) and the contract scenarios that fill them are in #3539, because a cell must name a guarantee the shipped paths actually provide. Until #3539 lands there is no writer ofmovingTargetBaseline, so the gate cannot fire and no cell could be filled honestly. - Live device evidence (Android ADB and Appium trials, the iOS runner route, the
--settlebaseline path and a guarded@refpress) is likewise collected on #3539 — the layer where a press can actually be refused. The measured SHA there isd7a95c683; the open gap noted in #3539's body is a guarded@refpress and a--settle-backed baseline, both recorded live after that SHA.
Validation
Tested at d1e251aa6.
pnpm check:affected --run --base feat/3471-moving-target-judgement— result recorded in a comment on this PR.typecheck,lint,format:check,check:layering— clean.vitest run packages/kernel packages/contracts src/daemon src/commands/interaction test/integration packages/selectors packages/ad-script packages/maestro packages/replay— pass.- Every new test fails when its guard is reverted, verified by mutation:
- narrowing the band to 0.5 px reddens
a one-pixel shift is capture rounding, not motion; - reporting
adoptedFrom: 'authorized-frame'on the adopt branch reddensthe @ref path takes its own observations, because its resolution spends none; - reporting
'observation'on either keep-the-frame branch reddensa ref the second observation cannot re-measure is refused, never self-agreedanda replacement that took the ref at the frame coordinates is refused, not agreed; - dropping the screening surface comparison reddens
a target newly arrived on a different surface is re-observed, not certified stationary; - dropping the between-looks surface rule, or reporting the cross-surface rect, reddens
a surface that arrives between the two looks is not rest; - substituting the selector text for the
@refrecovery reddensa ref the second observation cannot re-measure is refused, never self-agreed; - passing the rect through unrounded reddens
sub-pixel geometry is quantized before the band, so the band stays in whole pixels.
- narrowing the band to 0.5 px reddens
- Device evidence lives on #3539, where the refusal is reachable.