Skip to content

fix(snapshot): revalidate Apple runner payloads with the producer's fold policy - #4700

Merged
thymikee merged 2 commits into
mainfrom
fix/tvos-focus-fold-policy
Nov 18, 2026
Merged

thymikee merged 2 commits into
mainfrom
fix/tvos-focus-fold-policy

Conversation

@thymikee

@thymikee thymikee commented Nov 18, 2026 •

Copy link
Copy Markdown
Member

Summary

Fixes the tvOS snapshot refusal and missing tile focus in #4654. Host validation uses the runner’s plain-viewport fold. On the tvOS regular tree route, Swift retains the reported focus bit on the parent tile when it collapses a same-identity child wrapper into that parent. The fixture uses synthetic identifiers. This PR touches 18 files. Refusal index provenance is tracked in #4701.

Validation

  • Live tvOS 27.2 report for b2dff79348ca989ab7a00a6ebb18ec9356d119a3. The control was npm 0.21.39. Both regular modes succeeded on that candidate. Raw followed focus. Both regular modes omitted it.
  • An anonymized routed fixture failed at the Swift regular output with the old duplicate handling. On a5eda40287a66bdb95e66d3251ac84aed1ea738d, it passes three focus positions through Swift, host presentation, and ref publication. The differential suite, XCTest selection, and generic tvOS Simulator runner build passed.
  • pnpm check:affected --run --head a5eda40287a66bdb95e66d3251ac84aed1ea738d passed with exactCommit: true (receipt run-SlV1gH). GitHub owns the skipped CI checks.

Live tvOS retest

The reporter built the CLI and runner at a5eda40287a66bdb95e66d3251ac84aed1ea738d and tested on an Apple TV 4K (3rd generation) Simulator, tvOS 27.2, with fresh state and runner paths. Nine captures and two right presses succeeded. Both regular modes reported exactly one focused, hittable tile per position, matching the raw capture at each stop.

Position snapshot index snapshot -i index Raw index Tile x
Start 10 9 24 96
After right 12 11 41 441.5
After right again 14 13 58 787

The regular views preserve focus on the surviving outer wrapper. The report includes the anonymized node excerpts. Live evidence


Autofix with [code]smith
Open in [code]smith · Need help on this PR? Tag @codesmith-bot with what you need.

View guided diff Turn on auto-fix

…old policy (#4654)

A regular tvOS snapshot refused the whole home screen: the focused cell's
content is scaled by the tvOS focus effect past its row, and the host
revalidated the already presented payload with the cursor clip it does not
use. The runner compiles its fold policy per runtime, so the host now reads
that policy from the same Apple OS leaf instead of defaulting to
cursor-projected. Finite viewport, clipping, and actionable-point checks stay.
@github-actions

github-actions Bot commented Nov 18, 2026 •

Copy link
Copy Markdown
Contributor

Size Report

Metric Base Current Diff
Installed (including dependencies) 6.40 MB 6.40 MB +604 B
Package (unpacked) 6.40 MB 6.40 MB +604 B
Package (download) 1.94 MB 1.94 MB +305 B

Startup median (7 runs, lower is better):

Scenario Base Current Diff
CLI --version 42.2 ms 63.4 ms +21.2 ms
CLI --help 74.5 ms 102.0 ms +27.5 ms

@apex-sentinel-staging

This comment has been minimized.

@thymikee

Copy link
Copy Markdown
Member Author

The fold-policy change at b2dff79 needs live tvOS evidence before it can merge. It changes how the host validates the runner's live snapshot payload on tvOS and visionOS, which is a device-facing capture path, and the PR body lists live tvOS evidence as not run.

The only tvOS evidence today is the reporter's raw geometry replayed through fixtures (snapshot-presentation.ts#L223). Fixtures cannot show that the real runner payload (hittable bits, quality payload, viewport evidence, system-surface residue) now passes every host check beyond the one clip the reporter hit. The base refusal came from the first violated invariant, so another tvOS invariant could be hiding behind it. Until a real tvOS capture succeeds, #4654 stays unproven, and docs/agents/pull-requests.md asks for live evidence on device-facing changes.

Please run on a tvOS Simulator (boot an Apple TV 4K from the tvOS 27.0 runtime) with the PR head build. Use an app whose screen is rows of focusable collection-view cells, or the tvOS home screen if its tiles scale. Both snapshot -i and plain snapshot must succeed, with the focused node showing focused:true. After tv-remote press right, snapshot -i must succeed again with focus on the next tile. On base, the same sequence must show regular-node-outside-cumulative-clip. Please record the device and runtime, the exit codes, and the focused node line in the PR body. If no app with collection-view rows is available, say so and attach the closest live tvOS screen, noting it is weaker evidence.

Not blocking, and you can take or leave these: presentIosRunnerSnapshot in runner-presentation.ts#L12 still defaults foldPolicy to 'cursor-projected', but both production callers now pass a policy, so making the parameter required would remove the superseded default and let the compiler list the callers (check scripts/layering/ios-snapshot-engine-policy.ts, which inspects that function body); and the Swift-to-TS parity test in snapshot-presentation-fold-policy.test.ts#L26 matches the source text of platformDefault, so a harmless reformat or a new #elseif os(tvOS) branch would break or bypass it, and it overlaps the behavior tests already in snapshot-presentation.test.ts.

The 17 checks at b2dff79 are all passing. Draft PRs skip device lanes, so that does not cover live tvOS. There are no known conflicts. Before merge, the live tvOS evidence above needs to land in the PR body.

@nstfn

nstfn commented Nov 18, 2026

Copy link
Copy Markdown

Live tvOS evidence for head b2dff79348ca989ab7a00a6ebb18ec9356d119a3 (clean tree), as requested under "Blocker for merge".

Environment: macOS 27.2.1, Xcode 27.2 (27B52), Node 26.13.1, Apple TV 4K (3rd generation) Simulator, tvOS 27.2 (24K150), fr-FR. Same production tvOS app as #4654 (a home of horizontal collection-view rows). Head CLI 0.21.40-dev: pnpm install --frozen-lockfile && pnpm build, run as node bin/agent-device.mjs, tvOS runner built from the same checkout into its .tmp/ derived path. Control: npm 0.21.39. Same simulator, same home, one session per CLI.

Every command ran as agent-device <command> --platform ios --target tv --device <sim> --session <s> --state-dir <dir> --json.

Result: the refusal is gone, but the regular output does not show or follow the focus.

Step 0.21.39 head
snapshot -i, tile 1 focused regular-node-outside-cumulative-clip, index 11, frame (87.6625, 197.475, 350.175, 526.05), clip (0, 210, 1920, 501) success, 40 nodes, snapshotQuality.state: healthy, backend tree
snapshot, tile 1 focused same refusal (#4654) success, 51 nodes; the scaled frame (87.6625, 197.475, 350.175, 526.05) is published verbatim
tv-remote press right, snapshot -i success, 40 nodes
tv-remote press right, snapshot -i success, 40 nodes

The second half of the requested live case fails:

  • No node in any regular output (snapshot -i or snapshot) has a focused key.
  • The snapshot -i nodes arrays after 0, 1 and 2 right presses are identical, while the three screenshots differ.
  • snapshot -i --raw on the head after two presses shows exactly one focused node: tile 3 (raw index 58). The 0.21.39 --raw capture with tile 1 focused shows tile 1 (raw index 24).
  • In the regular output each tile appears as its outer Other wrapper (width 333.6, the raw parent of the focused node). The focused wrapper itself (width 333.5, focused: true) is not in the output. Our reading, from the widths and not traced in the code: the regular projection folds the node that carries the focus.

So on this home, snapshot -i succeeds but cannot tell the focused tile from its neighbours. --raw still can.

Excerpts (labels and identifiers replaced)

Head snapshot -i after two right presses (same as with 0 presses):

{"index": 9, "type": "Other", "label": "<tile 1>", "rect": {"x": 96, "y": 210, "width": 333.6, "height": 501}, "hittable": true, "parentIndex": 8}
{"index": 13, "type": "Other", "label": "<tile 3>", "rect": {"x": 787, "y": 210, "width": 333.6, "height": 501}, "hittable": true, "parentIndex": 12}

Head snapshot -i --raw after two right presses, focused node and its parents:

{"index": 58, "type": "Other", "label": "<tile 3>", "rect": {"x": 787, "y": 210, "width": 333.5, "height": 501}, "focused": true, "hittable": true, "parentIndex": 57}
{"index": 57, "type": "Other", "label": "<tile 3>", "rect": {"x": 787, "y": 210, "width": 333.6, "height": 501}, "hittable": true, "parentIndex": 56}
{"index": 56, "type": "Cell", "identifier": "<cell id>", "rect": {"x": 787, "y": 210, "width": 333.6, "height": 501}, "hittable": true, "parentIndex": 21}
{"index": 21, "type": "CollectionView", "rect": {"x": 0, "y": 210, "width": 1920, "height": 501}, "hittable": true, "parentIndex": 20}

Not covered: other screens and rows, tvOS 18.5, and a base-SHA build of the CLI (npm 0.21.39 stands as the control).

@nstfn

nstfn commented Nov 18, 2026 •

Copy link
Copy Markdown

One request before merge: the fixture in packages/platform-apple/src/snapshot-presentation.test.ts (lines 649 and 671 at b2dff79348) copies two accessibility identifiers from our app. Could you replace them with neutral names, as you did for the label (Focused tile)? We removed them from #4654 too. Thanks.

@thymikee

Copy link
Copy Markdown
Member Author

Thanks, @nstfn. The two fixture identifiers are now synthetic, and neither original appears in the tracked tree at a5eda40287a66bdb95e66d3251ac84aed1ea738d. Your live capture also helped us find where the Swift tree walk was dropping the focus marker. The new regression follows that marker through three tile positions.

Could you rerun the same tvOS 27.2 case with the CLI and runner built from a5eda40287a66bdb95e66d3251ac84aed1ea738d, using a fresh state directory and runner build path? At the starting tile and after each of two tv-remote press right commands, please compare snapshot --json, snapshot -i --json, and snapshot -i --raw --json. We expect both regular views to succeed and show focused: true and hittable: true on the same tile that raw identifies. The tested SHA and anonymized excerpts are enough.

@thymikee

Copy link
Copy Markdown
Member Author

Thanks for the update. a5eda40 addresses the earlier review, but one piece of evidence is still missing. The code change itself looks consistent. 16 checks pass or are skipped, and the remaining one is a review check.

The live tvOS 27.2 run on the earlier head showed regular snapshot and snapshot -i succeeding but carrying no focused key, with identical nodes after tv-remote press right. This head changes the runner's regular tree walk to fix that, and the only proof so far is a fixture replayed through the conformance harness. That fixture was built from the report, so it may not match the real hierarchy. The new merge guard (focused, type Other, direct child, equal label/identifier) must match the reporter's real tree, or the second half of #4654 stays unfixed. Please run a live tvOS Simulator capture with the CLI and runner built from a5eda40, using a fresh state dir and runner build path. Run snapshot --json, snapshot -i --json and snapshot -i --raw --json at the starting tile and after each of two tv-remote press right. Every run must exit 0. Each regular view must show exactly one focused:true, hittable:true node on the same tile that --raw marks focused, and that tile must advance after each press. Please record the SHA, device/runtime and the focused node lines in the PR body.

Not blocking, take or leave: the conformance harness re-implements the runner's parent re-mapping around RegularSnapshotTree.append (https://github.com/callstack/agent-device/blob/a5eda40/apple/snapshot-presentation/Sources/SnapshotPresentationConformance/main.swift#L88), so the runner's own index/stack loop has no focus regression test, and append takes an elementType string although node.type already holds it (https://github.com/callstack/agent-device/blob/a5eda40/apple/snapshot-presentation/Sources/AgentDeviceSnapshotPresentation/RegularSnapshotTree.swift#L36).

Once the live tvOS capture is in the PR body, this is ready to merge from my side.

@apex-sentinel-staging

Copy link
Copy Markdown

Apex Sentinel · ✅ Approve · review of a5eda40

Since the review of b2dff79: 0 new · 0 still open · 0 no longer raised

No open findings.

3 findings below minor hidden (user_settings.min_severity).

Reviewed with this repository's own Sentinel configuration (894c80ac681c).

💬 Talking to Sentinel

In a finding's thread, reply with:

Command What it does
@apex-sentinel-staging note <context> Adds context; Sentinel re-checks the cited code
@apex-sentinel-staging pivot <why> Says the finding is wrong; Sentinel re-checks the cited code
@apex-sentinel-staging like Marks the finding as useful
@apex-sentinel-staging dislike <why> Marks it as not useful, so it is not raised again

On this conversation, comment @apex-sentinel-staging review to run a full review once again.

@nstfn

nstfn commented Nov 18, 2026

Copy link
Copy Markdown

Live tvOS evidence for head a5eda40287a66bdb95e66d3251ac84aed1ea738d (clean tree): all four conditions pass at the three positions.

Environment: macOS 27.2.1, Xcode 27.2 (27B52), Node 26.13.1, Apple TV 4K (3rd generation) Simulator, tvOS 27.2 (24K150), fr-FR. Same production tvOS app and home as in the earlier run. CLI 0.21.40-dev from pnpm install --frozen-lockfile && pnpm build at this SHA, run as node bin/agent-device.mjs. Fresh state directory, and a new, empty runner derived path under .tmp/. The built test bundle contains RegularSnapshotTree, which this head adds and the b2dff79348 build does not. prepare ios-runner still reported cache: exact, buildMs: 0 for that build.

Every command ran as agent-device <command> --platform ios --target tv --device <sim> --session <s> --state-dir <dir> --json. Sequence: starting tile, tv-remote press right, tv-remote press right. At each position: snapshot --json, snapshot -i --json, snapshot -i --raw --json.

Condition Result
Every run exits 0 pass: 9 captures and 2 presses, success: true, empty stderr
Each regular view has exactly one focused: true, hittable: true node pass: snapshot and snapshot -i, at the 3 positions
That node is the tile that --raw marks focused pass: same label and same rect.x, at the 3 positions
The tile advances after each press pass: tile 1, then tile 2, then tile 3; the three screenshots differ

Focused node lines (labels replaced, rects rounded to 4 decimals):

pos 0  snapshot     {"index": 10, "type": "Other", "label": "<tile 1>", "rect": {"x": 96, "y": 210, "width": 333.6, "height": 501}, "focused": true, "hittable": true}
pos 0  snapshot -i  {"index": 9, "type": "Other", "label": "<tile 1>", "rect": {"x": 96, "y": 210, "width": 333.6, "height": 501}, "focused": true, "hittable": true}
pos 0  --raw        {"index": 24, "type": "Other", "label": "<tile 1>", "rect": {"x": 96, "y": 210, "width": 333.5, "height": 501}, "focused": true, "hittable": true}
pos 1  snapshot     {"index": 12, "type": "Other", "label": "<tile 2>", "rect": {"x": 441.5, "y": 210, "width": 333.6, "height": 501}, "focused": true, "hittable": true}
pos 1  snapshot -i  {"index": 11, "type": "Other", "label": "<tile 2>", "rect": {"x": 441.5, "y": 210, "width": 333.6, "height": 501}, "focused": true, "hittable": true}
pos 1  --raw        {"index": 41, "type": "Other", "label": "<tile 2>", "rect": {"x": 441.5, "y": 210, "width": 333.5, "height": 501}, "focused": true, "hittable": true}
pos 2  snapshot     {"index": 14, "type": "Other", "label": "<tile 3>", "rect": {"x": 787, "y": 210, "width": 333.6, "height": 501}, "focused": true, "hittable": true}
pos 2  snapshot -i  {"index": 13, "type": "Other", "label": "<tile 3>", "rect": {"x": 787, "y": 210, "width": 333.6, "height": 501}, "focused": true, "hittable": true}
pos 2  --raw        {"index": 58, "type": "Other", "label": "<tile 3>", "rect": {"x": 787, "y": 210, "width": 333.5, "height": 501}, "focused": true, "hittable": true}

The regular views carry the focus on the outer Other wrapper (width 333.6). --raw keeps it on the inner one (width 333.5).

Not covered: other screens and rows, tvOS 18.5, and iOS (not re-run here).

@thymikee
thymikee marked this pull request as ready for review November 18, 2026 17:11
@thymikee thymikee added the ready-for-human Valid work that needs human implementation, judgment, or maintainer merge label Nov 18, 2026
@thymikee

Copy link
Copy Markdown
Member Author

Thanks for the live run. It covers what the a5eda40 review asked for. On a tvOS 27.2 Simulator with the CLI and runner built from this head, all nine captures exit 0. Each regular view has exactly one focused, hittable tile, matching the tile --raw marks focused, and that tile advances after each tv-remote press right. With the code findings already addressed and the PR out of draft, this is ready for review. The two optional notes from the last review still stand: a focus regression test for the runner's own index/stack loop, and the redundant elementType parameter.

@thymikee
thymikee merged commit b2338f3 into main Nov 18, 2026
23 checks passed
@thymikee
thymikee deleted the fix/tvos-focus-fold-policy branch November 18, 2026 17:22
@thymikee

Copy link
Copy Markdown
Member Author

Closing out my side of this: the merged head is the maintainer's rework, and the live evidence this review asked for is already in the body from @nstfn's run at a5eda40. My candidate branch was superseded by it, so I pushed nothing further.

The two non-blocking notes, dispositioned against main at b2338f377d:

One note on my superseded candidate: my branch also made presentIosRunnerSnapshot's foldPolicy required, in the first review's optional list. The merged head keeps the = 'cursor-projected' default. That is a maintainer call, and both production callers pass a policy explicitly, so the default is inert rather than wrong — I left it alone rather than reopen it here.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ready-for-human Valid work that needs human implementation, judgment, or maintainer merge

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants