Skip to content

perf(android): skip the freshness window after a settle on a proved-fresh tree - #4605

Merged
thymikee merged 5 commits into
mainfrom
perf/android-skip-freshness-after-fresh-settle
Nov 16, 2026
Merged

thymikee merged 5 commits into
mainfrom
perf/android-skip-freshness-after-fresh-settle

Conversation

@thymikee

@thymikee thymikee commented Nov 16, 2026 •

Copy link
Copy Markdown
Member

Summary

After a press/click whose --settle converged, the daemon still armed the Android freshness window, so the next command bypassed the snapshot cache, lost the short helper idle wait, and ran stale-tree recovery. Now the window is skipped only when the settle stored its final capture (diff present) and the helper proved that capture fresh (cache cleared, root present, no truncation, no missing window roots: the #3815 proof, now one shared predicate carried as SnapshotState.freshTraversal). Convergence alone still arms the window, because two stale dumps can agree. back (bare or --settle), open, and unconverged or unproved settles still arm the window; a new test pins bare back. 10 files.

Refs #4105

Validation

Head ae68544, rebased on cb33595. Typecheck, lint and focused vitest pass; request-path test fails without the fix. CI owns check:affected.

Emulator API 35 (Settings), N=16 per arm, interleaved, load avg 25–490. Follow-up wall time (CLI included); measured at ac43329 (base 244d1ff); this PR's production diff is unchanged since then:

after press --settle base p50/p95 branch p50/p95 paired p50 Δ
navigate → snapshot 491 / 1589 416 / 883 −108 ms (10/16 faster)
navigate → press 1206 / 7990 952 / 1953 −254 ms (12/16)
toggle → snapshot 347 / 1980 328 / 1086 ≈0 (7/16)

Stale-route captures, failed presses, and wrong toggle states: 0 in both arms. Freshness retries: 0 in both arms. On API 34+ the proof already suppresses stuck-route retries, so the gain is the cache and idle-wait path. Devices without the proof keep today's behavior.

Lag check: after a plain navigating press, the first capture showed the new screen in 15/15 runs (done 427–1511 ms after the press, CLI floor ~400 ms). The old ~2 s lag does not appear.

🤖 Generated with Claude Code

@github-actions

github-actions Bot commented Nov 16, 2026 •

Copy link
Copy Markdown
Contributor

Size Report

Metric Base Current Diff
Installed (including dependencies) 6.33 MB 6.33 MB +309 B
Package (unpacked) 6.33 MB 6.33 MB +309 B
Package (download) 1.92 MB 1.92 MB +152 B

Startup median (7 runs, lower is better):

Scenario Base Current Diff
CLI --version 33.5 ms 44.9 ms +11.4 ms
CLI --help 71.3 ms 84.6 ms +13.3 ms

@cubic-dev-ai cubic-dev-ai Bot left a comment •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All reported issues were addressed

You’re at about 97% of the monthly reviewed-line limit. You may want to disable incremental reviews to conserve quota. Reviews will continue until that limit is exceeded. If you need help avoiding interruptions, please contact contact@cubic.dev.

Reply with feedback, questions, or to request a fix.

View guided diff | Turn on auto-fix | Re-trigger cubic

Comment thread android/snapshot-helper/README.md Resolved
thymikee and others added 4 commits November 16, 2026 18:28
…resh tree

A press or click whose --settle converged stored its final capture as the
session snapshot. When the helper proved that capture a complete read after
a cache reset, it is already the fresh post-action tree, so marking a new
freshness window only made the next command bypass the cache and run
freshness recovery. Convergence alone still arms the window: two stale dumps
can agree.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…ution capture

Also name click in the helper README and the tap-outcome waiver, which
still said the freshness mark is always set after press/click.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@thymikee
thymikee force-pushed the perf/android-skip-freshness-after-fresh-settle branch from 74f6cbd to b9cdd4a Compare November 16, 2026 17:30
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@apex-sentinel-staging

Copy link
Copy Markdown

Apex Sentinel · ✅ Approve

No open findings.

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

💬 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.

@thymikee

Copy link
Copy Markdown
Member Author

Android / Smoke Tests failure at ae68544 (run 43919820425, job 133483871649, live-automation-scenario.ts:202): this is not caused by this PR. Evidence:

From the artifact (android-artifacts):

  • Timing, from events.ndjson: back 17:39:22.261–22.399 (138 ms, mode in-app), then diff snapshot -i 22.609–22.822 (213 ms). The diff started 210 ms after back returned.
  • The diff took 213 ms in total. That is shorter than the first freshness retry delay (250 ms), so the capture ran no freshness retry.
  • The diff's only warning is "Recent snapshots dropped sharply in node count…". That text comes from formatRecentSnapshotDropWarning (snapshot.ts), which fires only when the capture carries no freshness annotation. The other source, formatFreshnessWarnings, needs staleAfterRetries. So freshness recovery classified the first capture as trustworthy (reason null) and published it.
  • That capture had 2 nodes: the scroll area and [button] "Navigate up". The baseline had 21.
  • The artifact has no per-request log for the diff (the retained request logs stop at 17:39:19), so androidSnapshot metadata for that capture is not available.

From code, every new call site:

  1. provesFreshAndroidTraversal has two callers:
    • session-snapshot-freshness.ts:100. This is an exact extraction of main's inline expression (diff against origin/main: 0 removed lines in android.ts; the classifier androidFreshnessReason is unchanged).
    • snapshot-capture.ts:155. This only sets SnapshotState.freshTraversal.
  2. freshTraversal has one reader: deferred-interaction-outcome.ts:96, gated on settle?.diff !== undefined. The generic route that bare back takes calls markDeferredInteractionOutcome without settle (request-generic-dispatch.ts:182). Bare back therefore arms the window as on main. The new test a bare back keeps the freshness window over a fresh stored tree pins this.
  3. In androidFreshnessReason, the sharp-drop branch returns before the proof is read. I ran the unchanged classifier on a tree shaped like the failing capture: a 21-node baseline and current nodes [ScrollView, ImageButton "Navigate up" hittable]. The result is null in all four combinations (proof on or off, route-comparable or not). The same drop without the labeled button returns sharp-drop. The lone labeled Navigate up counts as meaningful content, so main's guard declines to retry, with or without this PR.

I'll add the occurrence to #4105.

@thymikee

Copy link
Copy Markdown
Member Author

This PR is ready for the maintainer: I found no problems at ae68544. The 20 checks all pass. The Android Smoke Tests failure reported at this head was on back followed by diff snapshot -i. That route passes no settle (https://github.com/callstack/agent-device/blob/ae68544/packages/daemon/src/request-generic-dispatch.ts#L182) and the classifier is unchanged, so this change does not touch it. There are no conflicts.

Not blocking, and fine to take or leave: the skip at https://github.com/callstack/agent-device/blob/ae68544/packages/daemon/src/core/deferred-interaction-outcome.ts#L96 also retires the sharp-drop and empty-interactive guards for the next capture, not only stuck-route, so the comment could say so. The settle proof is also inferred from settle.diff !== undefined, so the same sentence on the diff comment in settle.ts would make that link visible from both sides. freshTraversal?: true is a literal while its siblings are boolean, which is a naming nit.

The live numbers cover API 35 only. The open inline thread on the README is fixed at this head, so the author can resolve it: #4605 (comment)

@thymikee thymikee added the ready-for-human Valid work that needs human implementation, judgment, or maintainer merge label Nov 16, 2026
@thymikee
thymikee merged commit 68f52b6 into main Nov 16, 2026
20 of 21 checks passed
@thymikee
thymikee deleted the perf/android-skip-freshness-after-fresh-settle branch November 16, 2026 20:55
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.

1 participant