fix(interaction): measure the moving-target gate by adoption, not bounds (#3471)

Merged
TH
2mo ago
+523-258

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 @ref look measured the wrong node. measured 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 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 stationary compared positions without comparing surfaceBundleId, so a same-identity node on a newly arrived iOS system sheet could excuse both re-observations. It now requires one surface, the line post-action-surface.ts already 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. movingTargetRectsStable and MOVING_TARGET_GATE_RECT_TOLERANCE_PX were a second copy of the 4-field abs-compare against 1 px that rectsWithinTolerance already ran for the post-gesture surface checks. areCapturedRectsAtSamePosition is that comparison once, exported from @agent-device/kernel/rect-center beside normalizeRect and areRectsApproximatelyEqual: 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 own GEOMETRY_TOLERANCE_PX = 1 and 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 to stableCaptureNodeSignal — 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. areRectsApproximatelyEqual keeps 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. reconcileFreshObservation now states what it chose on every branch — adoptedFrom: 'observation' | 'authorized-frame' — riding the ref's ResolvedInteractionTarget, and measureRefObservation reads that value instead of matching node and rect identity a second time. The look's surface also comes from the same capture through surfaceScopedNodes, the way the selector branch reads its resolution's preAction, instead of reading snapshot.iosSystemSurfaceBundleId directly.
  • 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's shellQuoteIfNeeded, 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 targetStability cells (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 of movingTargetBaseline, 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 --settle baseline path and a guarded @ref press) is likewise collected on #3539 — the layer where a press can actually be refused. The measured SHA there is d7a95c683; the open gap noted in #3539's body is a guarded @ref press 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 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;
    • 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 @ref recovery reddens a 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.
  • Device evidence lives on #3539, where the refusal is reachable.