Skip to content

Commit ad71d03

Browse files
committed
fix(limrun): isolate recordings with recording session IDs
1 parent a2c169f commit ad71d03

7 files changed

Lines changed: 87 additions & 36 deletions

File tree

‎package.json‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -340,7 +340,7 @@
340340
"@agent-device/xml": "workspace:*",
341341
"@arethetypeswrong/cli": "^0.18.5",
342342
"@chenglou/freerange": "^0.0.4",
343-
"@limrun/api": "^0.64.1",
343+
"@limrun/api": "^0.68.1",
344344
"@nkzw/eslint-plugin": "^2.0.0",
345345
"@nkzw/oxlint-config": "^1.3.0",
346346
"@statelyai/graph": "2.4.0",

‎packages/provider-limrun/package.json‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,6 @@
1717
}
1818
},
1919
"devDependencies": {
20-
"@limrun/api": "^0.64.1"
20+
"@limrun/api": "^0.68.1"
2121
}
2222
}

‎packages/provider-limrun/src/device-session.test.ts‎

Lines changed: 21 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -73,8 +73,8 @@ const TEST_DEPENDENCIES = {
7373
test('iOS device session exposes reusable capabilities without its raw client', async () => {
7474
const pressKey = vi.fn(async () => undefined);
7575
const readLogs = vi.fn(async () => 'line one\nline two\n');
76-
const startRecording = vi.fn(async () => undefined);
77-
const stopRecording = vi.fn(async () => 'https://ios.example/recording');
76+
const startRecordingSession = vi.fn(async () => 'recording-id');
77+
const stopRecordingSession = vi.fn(async () => 'https://ios.example/recording');
7878
const simctlWait = vi.fn(async () => ({ code: 0, stdout: 'ok', stderr: '' }));
7979
const simctl = vi.fn(() => commandExecution(simctlWait));
8080
const session = createLimrunDeviceSession(
@@ -83,8 +83,8 @@ test('iOS device session exposes reusable capabilities without its raw client',
8383
listApps: vi.fn(async () => IOS_APPS),
8484
pressKey,
8585
appLogTail: readLogs,
86-
startRecording,
87-
stopRecording,
86+
startRecordingSession,
87+
stopRecordingSession,
8888
simctl,
8989
}),
9090
);
@@ -103,8 +103,10 @@ test('iOS device session exposes reusable capabilities without its raw client',
103103
assert.deepEqual(session.viewport, { width: 402, height: 874 });
104104
await session.pressKey('enter', ['command']);
105105
assert.equal(await session.readLogs('com.example.ios', 200), 'line one\nline two\n');
106-
await session.startRecording({ quality: 8 });
107-
assert.deepEqual(await session.stopRecording(), { downloadUrl: 'https://ios.example/recording' });
106+
await session.startRecording({ recordingId: 'recording-id', quality: 8 });
107+
assert.deepEqual(await session.stopRecording('recording-id'), {
108+
downloadUrl: 'https://ios.example/recording',
109+
});
108110
await session.downloadRecording({
109111
downloadUrl: 'https://ios.example/recording',
110112
outPath: '/tmp/ios-recording.mp4',
@@ -117,8 +119,10 @@ test('iOS device session exposes reusable capabilities without its raw client',
117119

118120
assert.deepEqual(pressKey.mock.calls[0], ['enter', ['command']]);
119121
assert.deepEqual(readLogs.mock.calls[0], ['com.example.ios', 200]);
120-
assert.deepEqual(startRecording.mock.calls[0], [{ quality: 8 }]);
121-
assert.deepEqual(stopRecording.mock.calls[0], [{}]);
122+
assert.deepEqual(startRecordingSession.mock.calls[0], [
123+
{ recordingId: 'recording-id', quality: 8 },
124+
]);
125+
assert.deepEqual(stopRecordingSession.mock.calls[0], ['recording-id']);
122126
assert.deepEqual(downloadFile.mock.calls.at(-1), [
123127
{
124128
url: 'https://ios.example/recording',
@@ -175,11 +179,11 @@ test('Android device session exposes semantic ADB capabilities without its raw c
175179
},
176180
};
177181
const pressKey = vi.fn(async () => undefined);
178-
const startRecording = vi.fn(async () => undefined);
179-
const stopRecording = vi.fn(async () => 'https://android.example/recording');
182+
const startRecordingSession = vi.fn(async () => 'recording-id');
183+
const stopRecordingSession = vi.fn(async () => 'https://android.example/recording');
180184
const sendAsset = vi.fn(async () => undefined);
181185
const session = createLimrunDeviceSession(
182-
androidSession(provider, { pressKey, startRecording, stopRecording, sendAsset }),
186+
androidSession(provider, { pressKey, startRecordingSession, stopRecordingSession, sendAsset }),
183187
);
184188

185189
assert.equal(session.platform, 'android');
@@ -195,8 +199,8 @@ test('Android device session exposes semantic ADB capabilities without its raw c
195199
assert.equal(await session.readLogs(20), 'log line\n');
196200
assert.equal(await session.installRemoteApp('https://assets.example/android.apk'), undefined);
197201
await session.pressKey('KEYCODE_ENTER', ['shift']);
198-
await session.startRecording({ quality: 7 });
199-
assert.deepEqual(await session.stopRecording(), {
202+
await session.startRecording({ recordingId: 'recording-id', quality: 7 });
203+
assert.deepEqual(await session.stopRecording('recording-id'), {
200204
downloadUrl: 'https://android.example/recording',
201205
});
202206
await session.downloadRecording({
@@ -207,8 +211,10 @@ test('Android device session exposes semantic ADB capabilities without its raw c
207211

208212
assert.deepEqual(sendAsset.mock.calls[0], ['https://assets.example/android.apk']);
209213
assert.deepEqual(pressKey.mock.calls[0], ['KEYCODE_ENTER', ['shift']]);
210-
assert.deepEqual(startRecording.mock.calls[0], [{ quality: 7 }]);
211-
assert.deepEqual(stopRecording.mock.calls[0], [{}]);
214+
assert.deepEqual(startRecordingSession.mock.calls[0], [
215+
{ recordingId: 'recording-id', quality: 7 },
216+
]);
217+
assert.deepEqual(stopRecordingSession.mock.calls[0], ['recording-id']);
212218
assert.deepEqual(downloadFile.mock.calls.at(-1), [
213219
{
214220
url: 'https://android.example/recording',

‎packages/provider-limrun/src/device-session.ts‎

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -59,16 +59,19 @@ type LimrunDeviceSessionBase = {
5959
readonly interactor: Interactor;
6060
listApps(filter?: AppsFilter): Promise<LimrunInstalledApp[]>;
6161
pressKey(key: string, modifiers?: string[]): Promise<void>;
62-
startRecording(options?: { quality?: LimrunRecordingQuality }): Promise<void>;
63-
/** Stops the instance recorder and answers where the finished file is served; nothing is downloaded. */
64-
stopRecording(): Promise<{ downloadUrl: string }>;
62+
startRecording(options: { recordingId: string; quality?: LimrunRecordingQuality }): Promise<void>;
63+
/** Stops the identified recorder and answers where the finished file is served; nothing is downloaded. */
64+
stopRecording(recordingId: string): Promise<{ downloadUrl: string }>;
6565
/** Fetches a served recording to `outPath` within a fixed deadline. Retriable while the instance lives. */
6666
downloadRecording(input: { downloadUrl: string; outPath: string }): Promise<void>;
6767
};
6868

6969
type LimrunRecordingClient = {
70-
startRecording(options?: { quality?: LimrunRecordingQuality }): Promise<void>;
71-
stopRecording(saveTo: { localPath?: string }): Promise<string>;
70+
startRecordingSession(options: {
71+
recordingId: string;
72+
quality?: LimrunRecordingQuality;
73+
}): Promise<string>;
74+
stopRecordingSession(recordingId: string): Promise<string>;
7275
};
7376

7477
/**
@@ -170,12 +173,13 @@ function createRecordingOperations(
170173
host: Pick<LimrunHostAdapter, 'downloadFile'>,
171174
) {
172175
return {
173-
startRecording: async (options?: { quality?: LimrunRecordingQuality }) => {
174-
await client.startRecording(options);
176+
startRecording: async (options: { recordingId: string; quality?: LimrunRecordingQuality }) => {
177+
await client.startRecordingSession(options);
175178
},
176-
// Without `localPath` the SDK only stops the recorder and returns the served URL; a download
177-
// tied to the one-shot stop could not be retried after a dropped transfer.
178-
stopRecording: async () => ({ downloadUrl: await client.stopRecording({}) }),
179+
// Keep downloads separate from stopping so a dropped transfer can be retried.
180+
stopRecording: async (recordingId: string) => ({
181+
downloadUrl: await client.stopRecordingSession(recordingId),
182+
}),
179183
downloadRecording: async (input: { downloadUrl: string; outPath: string }) => {
180184
await host.downloadFile({
181185
url: input.downloadUrl,

‎packages/provider-limrun/src/recording-runtime.test.ts‎

Lines changed: 39 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,10 @@ test('the high preset maps onto the low end of the legacy high band', async () =
112112

113113
await operations.screenRecordingStart(input({ exportQuality: 'high' }));
114114

115-
expect(session.startRecording).toHaveBeenCalledWith({ quality: 8 });
115+
expect(session.startRecording).toHaveBeenCalledWith({
116+
recordingId: expect.any(String),
117+
quality: 8,
118+
});
116119
});
117120

118121
test('stop asks the instance once, downloads the served MP4 to the output path, finalizes, and confirms the recorder', async () => {
@@ -258,3 +261,38 @@ test('the bound owner serves record start and stop through the live device sessi
258261
'finalize',
259262
]);
260263
});
264+
265+
test('finishing or cleaning one recording leaves other recordings on the instance active', async () => {
266+
const active = new Set(['external-recording']);
267+
const calls: string[] = [];
268+
const session: LimrunScreenRecordingSession = {
269+
startRecording: async ({ recordingId }) => {
270+
if (active.has(recordingId)) throw new Error('Recording ID already exists');
271+
active.add(recordingId);
272+
},
273+
stopRecording: async (recordingId) => {
274+
if (!active.delete(recordingId)) throw new Error('Recording does not exist');
275+
return { downloadUrl: `${DOWNLOAD_URL}&recordingId=${recordingId}` };
276+
},
277+
downloadRecording: async () => {},
278+
};
279+
const operations = createLimrunScreenRecordingOperations({
280+
host: fakeRecordingHost(calls),
281+
device: limrunIosSimulator,
282+
owner,
283+
signal: new AbortController().signal,
284+
getDeviceSession: () => session,
285+
});
286+
const first = (await operations.screenRecordingStart(input())).pendingHandle.transfer();
287+
const second = (
288+
await operations.screenRecordingStart(input({ outputPath: '/tmp/second-recording.mp4' }))
289+
).pendingHandle.transfer();
290+
expect(active.size).toBe(3);
291+
292+
await expect(first.finish()).resolves.toMatchObject({ status: 'completed' });
293+
expect(active.size).toBe(2);
294+
expect(active.has('external-recording')).toBe(true);
295+
296+
await expect(second.forceCleanup()).resolves.toEqual({ status: 'cleaned' });
297+
expect([...active]).toEqual(['external-recording']);
298+
});

‎packages/provider-limrun/src/recording-runtime.ts‎

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import { randomUUID } from 'node:crypto';
12
import type { DeviceInfo } from '@agent-device/kernel/device';
23
import { AppError } from '@agent-device/kernel/errors';
34
import type { RuntimeOwnerRef } from '@agent-device/contracts/platform-runtime';
@@ -67,6 +68,7 @@ async function startLimrunRecording(
6768
{ deviceId: params.device.id },
6869
);
6970
}
71+
const recordingId = randomUUID();
7072
return await startTransportScreenRecording({
7173
host: params.host,
7274
device: params.device,
@@ -78,10 +80,11 @@ async function startLimrunRecording(
7880
targetLabel: 'Limrun recording',
7981
start: async () => {
8082
await session.startRecording({
83+
recordingId,
8184
quality: LIMRUN_QUALITY_BY_EXPORT[input.exportQuality ?? 'medium'],
8285
});
8386
},
84-
stop: async () => (await session.stopRecording()).downloadUrl,
87+
stop: async () => (await session.stopRecording(recordingId)).downloadUrl,
8588
collect: async (downloadUrl, outputPath) => {
8689
await session.downloadRecording({ downloadUrl, outPath: outputPath });
8790
},

‎pnpm-lock.yaml‎

Lines changed: 7 additions & 7 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)