Skip to content

Commit cee2da1

Browse files
authored
fix(record): record a remote client's default recording on the daemon host (#3696)
* fix(record): record a remote client's default recording on the daemon host A remote record start without a path left the default name to the daemon, which resolved ./recording-<ts>.mp4 against the client's cwd and failed with EACCES on the daemon host. The client now sends its local destination without an extension; the daemon completes it with the session platform's extension, records to a temp path on its own host, and the client downloads the file there on record stop. Found while driving an EAS cloud simulator session. * fix(record): choose the remote default recording path in the daemon record handler Keep resolveRecordingOutputPaths transport-free: capture-kit picks the extension and resolves paths, and only the daemon knows a request came from a remote client. Document where a remote record start without a path downloads.
1 parent 97c2fb2 commit cee2da1

5 files changed

Lines changed: 65 additions & 14 deletions

File tree

‎packages/daemon/src/sessions/handlers/__tests__/record-runtime-start.test.ts‎

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,26 @@ test('record start preserves the requested path while the runtime receives the e
3838
);
3939
});
4040

41+
test('record start without a path records a remote caller default on the daemon host', async () => {
42+
const harness = makeRecordRuntimeHarness('record-runtime-remote-default-');
43+
44+
const response = await harness.run(['start'], {
45+
cwd: '/client/project',
46+
clientArtifactPaths: { outPath: '/client/project/recording-1' },
47+
});
48+
49+
expect(response).toMatchObject({
50+
ok: true,
51+
data: { outPath: '/client/project/recording-1.mp4' },
52+
});
53+
expect(harness.runtime.start).toHaveBeenCalledWith(
54+
expect.objectContaining({
55+
outputPath: expect.stringMatching(/^\/tmp\/agent-device-recording-\d+-[a-z0-9]+\.mp4$/),
56+
clientOutputPath: '/client/project/recording-1.mp4',
57+
}),
58+
);
59+
});
60+
4161
test.each(['linux', 'vega'] as const)(
4262
'record start on %s reports public unsupported guidance',
4363
async (platform) => {

‎packages/daemon/src/sessions/handlers/record-runtime.ts‎

Lines changed: 36 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ import {
1818
} from '@agent-device/contracts/screen-recording-runtime-plan';
1919
import { isWholeScreenRecordingScope } from '@agent-device/contracts/recording';
2020
import { AppError, normalizeError } from '@agent-device/kernel/errors';
21+
import type { Platform } from '@agent-device/kernel/device';
2122
import { resolveTargetDevice } from '@agent-device/device-selection/dispatch-resolve';
2223
import { ensureBoundDeviceReady } from '../../core/request-runtime-binding.ts';
2324
import { type ScreenRecordingAdmissionLedger } from '@agent-device/capture-kit/screen-recording-admission-ledger';
@@ -46,7 +47,13 @@ import {
4647
prepareRecordingRequest,
4748
readRecordingScope,
4849
} from './record-runtime-request.ts';
49-
import { resolveRecordingOutputPaths } from '@agent-device/capture-kit/recording-output-path';
50+
import {
51+
appendRecordingExtensionWhenMissing,
52+
type RecordingOutputPaths,
53+
recordingExtensionForPlatform,
54+
resolveRecordingOutputPaths,
55+
} from '@agent-device/capture-kit/recording-output-path';
56+
import { buildRemoteTempArtifactPath } from '@agent-device/contracts/daemon-http';
5057
import {
5158
buildRecordingStartResponse,
5259
buildRecordingStartedAction,
@@ -163,7 +170,7 @@ async function startRecording(
163170
const { fence, outputPaths } = prepareRecordingStart(params, session);
164171
binding.assertAdoptable();
165172
const started = await runtime.operations.screenRecordingStart(
166-
screenRecordingStartInput(params, session, prepared, fence, outputPaths.outputPath),
173+
screenRecordingStartInput(params, session, prepared, fence, outputPaths),
167174
);
168175
await adoptStartedScreenRecording({
169176
admissionLedger: params.admissionLedger,
@@ -203,11 +210,30 @@ function prepareRecordingStart(params: RecordRuntimeHandlerParams, session: Sess
203210
resourcePath,
204211
device: session.device,
205212
}),
206-
outputPaths: resolveRecordingOutputPaths({
207-
requestedPath: params.req.positionals?.[1],
208-
platform: session.device.platform,
209-
cwd: params.req.meta?.cwd,
210-
}),
213+
outputPaths: resolveRecordingStartPaths(params.req, session.device.platform),
214+
};
215+
}
216+
217+
type RecordingStartPaths = RecordingOutputPaths & Readonly<{ clientOutputPath?: string }>;
218+
219+
function resolveRecordingStartPaths(req: DaemonRequest, platform: Platform): RecordingStartPaths {
220+
const requestedPath = req.positionals?.[1];
221+
const clientOutputPath = req.meta?.clientArtifactPaths?.outPath;
222+
if (requestedPath === undefined && clientOutputPath !== undefined) {
223+
// A remote caller that names no path cannot know the session platform's extension, so it sends
224+
// its local destination without one; its cwd does not exist on this host.
225+
const extension = recordingExtensionForPlatform(platform);
226+
return {
227+
...resolveRecordingOutputPaths({
228+
requestedPath: buildRemoteTempArtifactPath('recording', extension),
229+
platform,
230+
}),
231+
clientOutputPath: appendRecordingExtensionWhenMissing(clientOutputPath, extension),
232+
};
233+
}
234+
return {
235+
...resolveRecordingOutputPaths({ requestedPath, platform, cwd: req.meta?.cwd }),
236+
...(clientOutputPath === undefined ? {} : { clientOutputPath }),
211237
};
212238
}
213239

@@ -216,12 +242,12 @@ function screenRecordingStartInput(
216242
session: SessionState,
217243
prepared: ReturnType<typeof prepareRecordingRequest>,
218244
fence: ScreenRecordingStartInput['fence'],
219-
outputPath: string,
245+
outputPaths: RecordingStartPaths,
220246
): ScreenRecordingStartInput {
221247
return {
222248
sessionId: params.sessionName,
223-
outputPath,
224-
clientOutputPath: params.req.meta?.clientArtifactPaths?.outPath,
249+
outputPath: outputPaths.outputPath,
250+
clientOutputPath: outputPaths.clientOutputPath,
225251
scope: prepared.scope,
226252
showTouches: prepared.showTouches,
227253
hideTouchesRequested: prepared.hideTouchesRequested,

‎src/remote/daemon-artifacts.ts‎

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -272,7 +272,12 @@ function prepareRemoteArtifactCommand(
272272
}
273273
if (req.command === 'record' && (positionals[0] ?? '').toLowerCase() === 'start') {
274274
if (!recordingHasRequestedClientPath(req) && req.flags?.platform === undefined) {
275-
return null;
275+
// The extension follows the session platform, which only the daemon knows: it completes
276+
// this destination and records to a temp path on its own host.
277+
return {
278+
field: 'outPath',
279+
localPath: resolveAbsoluteClientPath(`recording-${Date.now()}`, req.meta?.cwd),
280+
};
276281
}
277282
const fallbackExtension = recordingFallbackExtension(req);
278283
const localPath = normalizeRecordingClientArtifactPath(

‎test/integration/provider-scenarios/remote-daemon-client.test.ts‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -709,7 +709,7 @@ test('remote web recording appends WebM extension to extensionless client paths'
709709
assert.equal(prepared.clientArtifactPaths?.outPath, '/tmp/project/recording.webm');
710710
});
711711

712-
test('remote recording without platform or requested path lets daemon choose session-specific default', async () => {
712+
test('remote recording without platform or requested path lets daemon name the client default', async () => {
713713
const prepared = await prepareRemoteRequestArtifacts(
714714
{
715715
session: 'default',
@@ -723,7 +723,7 @@ test('remote recording without platform or requested path lets daemon choose ses
723723
);
724724

725725
assert.deepEqual(prepared.positionals, ['start']);
726-
assert.equal(prepared.clientArtifactPaths, undefined);
726+
assert.match(prepared.clientArtifactPaths?.outPath ?? '', /^\/tmp\/project\/recording-\d+$/);
727727
});
728728

729729
test('Provider-backed integration daemon proxy forwards remote client RPC commands', async (t) => {

‎website/docs/docs/commands.md‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@ Remote daemons and tenants:
124124

125125
- `--tenant`, `--session-isolation tenant`, `--run-id`, and `--lease-id` enforce lease admission on tenant-scoped daemons.
126126
- `--daemon-base-url http(s)://host:port[/base-path]` calls a remote HTTP daemon directly instead of starting a local one. Add `--daemon-auth-token <token>` (or `AGENT_DEVICE_DAEMON_AUTH_TOKEN`) for non-loopback daemon URLs.
127-
- Screenshots and recordings from a remote daemon are downloaded to the path you pass, so `screenshot page.png` and `record start session.mp4` work as they do locally.
127+
- Screenshots and recordings from a remote daemon are downloaded to the path you pass, so `screenshot page.png` and `record start session.mp4` work as they do locally. `record start` without a path downloads to `recording-<timestamp>.mp4` (`.webm` on web) in your working directory.
128128
- To drive a Mac's simulators and devices from another machine, see [Remote Proxy](/docs/remote-proxy). For hosted devices in CI, see [BrowserStack](/docs/browserstack), [AWS Device Farm](/docs/aws-device-farm), or [TestMu AI](/docs/testmu). For `connect --remote-config`, see [Remote Metro workflow](#remote-metro-workflow).
129129

130130
```bash

0 commit comments

Comments
 (0)