@@ -8,6 +8,7 @@ export type { AndroidSnapshotFreshness } from './types.ts';
88// and can lag behind real transitions by up to ~2 s; 2.5 s gives a comfortable margin
99// while avoiding unnecessary retries for steady-state interactions like typing.
1010const ANDROID_FRESHNESS_WINDOW_MS = 2_500 ;
11+ const ANDROID_COMPARISON_BASELINE_MAX_AGE_MS = 5_000 ;
1112
1213// Retry suspicious snapshots until this post-action deadline expires. The delay
1314// sequence stays short in the happy path; the 600 ms tail retry is opportunistic
@@ -28,21 +29,34 @@ export function markAndroidSnapshotFreshness(
2829 baseline = session . snapshot ,
2930) : void {
3031 if ( session . device . platform !== 'android' ) return ;
32+ const comparisonBaseline = resolveAndroidComparisonBaseline ( session , baseline ) ;
3133 // Route-stuck recovery only makes sense against a baseline captured in a broad, comparable
3234 // shape. Interactive/scoped/depth-limited snapshots are still useful for users, but they are
3335 // too pruned to serve as a reliable "same route vs new route" baseline.
34- const routeComparable = baseline ?. comparisonSafe === true ;
36+ const routeComparable = comparisonBaseline ?. comparisonSafe === true ;
3537 session . androidSnapshotFreshness = {
3638 action,
3739 markedAt : Date . now ( ) ,
38- baselineCount : baseline ?. nodes . length ?? 0 ,
40+ baselineCount : ( comparisonBaseline ?? baseline ) ?. nodes . length ?? 0 ,
3941 baselineSignatures : routeComparable
40- ? buildSnapshotSignatures ( baseline ?. nodes ?? [ ] )
42+ ? buildSnapshotSignatures ( comparisonBaseline ?. nodes ?? [ ] )
4143 : undefined ,
4244 routeComparable,
4345 } ;
4446}
4547
48+ function resolveAndroidComparisonBaseline (
49+ session : SessionState ,
50+ baseline : SnapshotState | undefined ,
51+ ) : SnapshotState | undefined {
52+ if ( baseline ?. comparisonSafe === true ) return baseline ;
53+ const previous = session . lastComparisonSafeSnapshot ;
54+ if ( ! previous || previous . comparisonSafe !== true ) return baseline ;
55+ return Date . now ( ) - previous . createdAt <= ANDROID_COMPARISON_BASELINE_MAX_AGE_MS
56+ ? previous
57+ : baseline ;
58+ }
59+
4660export function getActiveAndroidSnapshotFreshness (
4761 session : SessionState | undefined ,
4862) : AndroidSnapshotFreshness | undefined {
0 commit comments