-
-
Notifications
You must be signed in to change notification settings - Fork 328
fix(android): back off a timed-out snapshot helper session and bound content re-captures #3160
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
thymikee
merged 5 commits into
callstack:main
from
okwasniewski:oskar/android-snapshot-helper-timeout-ownership
Oct 3, 2026
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
b0a0820
fix(android): back off a timed-out snapshot helper session and bound …
okwasniewski 60446b3
fix(android): recheck re-capture window after the delay before it
okwasniewski da59b7a
refactor(android): retire a failed helper session by its own identity
okwasniewski f93d8ea
test(android): assert typed reason of a zero-exit helper failure
okwasniewski 12757c4
refactor(android): split content re-capture loop out of helper capture
okwasniewski File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
100 changes: 100 additions & 0 deletions
100
packages/platform-android/src/__tests__/snapshot-content-recapture.test.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,100 @@ | ||
| import { afterEach, beforeEach, test, vi } from 'vitest'; | ||
| import assert from 'node:assert/strict'; | ||
|
|
||
| vi.mock('../adb.ts', async (importOriginal) => { | ||
| const actual = await importOriginal<typeof import('../adb.ts')>(); | ||
| return { ...actual, sleep: vi.fn(async () => {}) }; | ||
| }); | ||
|
|
||
| import type { DeviceInfo } from '@agent-device/kernel/device'; | ||
| import { AppError } from '@agent-device/kernel/errors'; | ||
| import { sleep } from '../adb.ts'; | ||
| import { snapshotAndroid } from '../snapshot.ts'; | ||
| import { resetAndroidSnapshotHelperInstallCache } from '../snapshot-helper-install.ts'; | ||
| import { resetAndroidSnapshotHelperSessions } from '../snapshot-helper-session-lifecycle.ts'; | ||
| import { ANDROID_SNAPSHOT_HELPER_FIXTURE_ARTIFACT } from './test-utils/android-snapshot-helper.ts'; | ||
| import { | ||
| androidSystemWindowOnlyXml, | ||
| createPersistentSnapshotHelperProvider, | ||
| type FakeAndroidProcess, | ||
| } from './snapshot-helper-session.fixtures.ts'; | ||
|
|
||
| const device: DeviceInfo = { | ||
| platform: 'android', | ||
| id: 'emulator-5554', | ||
| name: 'Pixel', | ||
| kind: 'emulator', | ||
| booted: true, | ||
| }; | ||
|
|
||
| beforeEach(async () => { | ||
| await resetAndroidSnapshotHelperSessions(); | ||
| resetAndroidSnapshotHelperInstallCache(); | ||
| }); | ||
|
|
||
| afterEach(async () => { | ||
| vi.restoreAllMocks(); | ||
| await resetAndroidSnapshotHelperSessions(); | ||
| }); | ||
|
|
||
| /** | ||
| * Captures of a busy screen that each answer with system chrome only, after `captureCostMs`. | ||
| * Every sleep advances the clock by the time it was asked to wait. | ||
| */ | ||
| async function captureBusyScreen(captureCostMs: number): Promise<{ | ||
| error: unknown; | ||
| sessionCaptures: number; | ||
| }> { | ||
| let clockOffsetMs = 0; | ||
| const realNow = Date.now.bind(Date); | ||
| vi.spyOn(Date, 'now').mockImplementation(() => realNow() + clockOffsetMs); | ||
| vi.mocked(sleep).mockImplementation(async (ms: number) => { | ||
| clockOffsetMs += ms; | ||
| }); | ||
| let sessionCaptures = 0; | ||
| const provider = createPersistentSnapshotHelperProvider({ | ||
| calls: [], | ||
| spawnArgs: [], | ||
| processes: [] as FakeAndroidProcess[], | ||
| sessionXml: () => { | ||
| sessionCaptures += 1; | ||
| clockOffsetMs += captureCostMs; | ||
| return androidSystemWindowOnlyXml(); | ||
| }, | ||
| }); | ||
| const error = await snapshotAndroid(device, { | ||
| helperAdb: provider, | ||
| helperArtifact: ANDROID_SNAPSHOT_HELPER_FIXTURE_ARTIFACT, | ||
| appBundleId: 'com.example.app', | ||
| }).then( | ||
| () => undefined, | ||
| (error: unknown) => error, | ||
| ); | ||
| return { error, sessionCaptures }; | ||
| } | ||
|
|
||
| test('a busy screen whose captures are cheap is re-captured before its verdict', async () => { | ||
| const { error, sessionCaptures } = await captureBusyScreen(10); | ||
|
|
||
| assert.ok(error instanceof AppError); | ||
| assert.equal(error.details?.attempts, 3); | ||
| assert.equal(sessionCaptures, 3); | ||
| }); | ||
|
|
||
| test('a busy screen whose captures are slow is not re-captured past the window', async () => { | ||
| // One attempt that spends a whole helper command budget leaves no room in the daemon request | ||
| // envelope for two more of the same. | ||
| const { error, sessionCaptures } = await captureBusyScreen(30_000); | ||
|
|
||
| assert.ok(error instanceof AppError); | ||
| assert.equal(error.details?.attempts, 1); | ||
| assert.equal(sessionCaptures, 1); | ||
| }); | ||
|
|
||
| test('a busy screen is not re-captured when the delay before it crosses the window', async () => { | ||
| const { error, sessionCaptures } = await captureBusyScreen(9_900); | ||
|
|
||
| assert.ok(error instanceof AppError); | ||
| assert.equal(error.details?.attempts, 1); | ||
| assert.equal(sessionCaptures, 1); | ||
| }); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.