|
1 | 1 | import { isIosFamily, type DeviceInfo } from '@agent-device/kernel/device'; |
2 | 2 | import { AppError, asAppError } from '@agent-device/kernel/errors'; |
| 3 | +import { execFailureDetails } from '@agent-device/host-kit/command'; |
3 | 4 | import type { CleanupOutcome } from '@agent-device/contracts/durable-resource'; |
4 | 5 | import type { HostCommandResult } from '@agent-device/contracts/platform-runtime-host'; |
5 | 6 | import type { RuntimeOwnerRef } from '@agent-device/contracts/platform-runtime'; |
6 | 7 | import type { ScreenRecordingRuntimeHost } from '@agent-device/contracts/screen-recording-runtime-host'; |
7 | | -import type { |
8 | | - ScreenRecordingLiveSnapshot, |
9 | | - ScreenRecordingRuntimeOperations, |
10 | | - ScreenRecordingStartInput, |
| 8 | +import { |
| 9 | + RECORDING_OUTPUT_UNPLAYABLE_REASON, |
| 10 | + type ScreenRecordingLiveSnapshot, |
| 11 | + type ScreenRecordingRuntimeOperations, |
| 12 | + type ScreenRecordingStartInput, |
11 | 13 | } from '@agent-device/contracts/screen-recording-runtime'; |
12 | 14 | import { PendingTransferGuard } from '@agent-device/contracts/async-lifecycle'; |
13 | 15 | import { createScreenRecordingLiveHandle } from '@agent-device/capture-kit'; |
@@ -134,7 +136,7 @@ async function startAppleSimulatorRecording(params: AppleRecordingStartParams) { |
134 | 136 | `${exit} before record stop; the video covers only what the recorder wrote before it stopped.`, |
135 | 137 | ); |
136 | 138 | } catch (exportError) { |
137 | | - throw recorderExitLostTheExport(exportError, exit, result); |
| 139 | + throw recorderExitEndedTheRecording(exportError, exit, result); |
138 | 140 | } |
139 | 141 | }, |
140 | 142 | cleanup: async () => { |
@@ -250,28 +252,29 @@ function describeSimctlRecorderExit(result: HostCommandResult): string | undefin |
250 | 252 | : `simctl recordVideo exited with code ${result.exitCode}`; |
251 | 253 | } |
252 | 254 |
|
253 | | -// The exit is the fact that makes an unreadable file permanent, so it belongs in the error the |
254 | | -// operator reads: the next `record stop` re-reads the same settled exit and the same bytes. |
255 | | -function recorderExitLostTheExport( |
| 255 | +// An unreadable file is the one export failure the recorder's exit explains: the next `record stop` |
| 256 | +// re-reads the same settled exit and the same bytes, so it names the exit and the way out. Anything |
| 257 | +// else the export path raised keeps its own verdict — a telemetry or transport failure a retry can fix |
| 258 | +// must not be told to close the session. |
| 259 | +function recorderExitEndedTheRecording( |
256 | 260 | exportError: unknown, |
257 | 261 | exit: string, |
258 | 262 | result: HostCommandResult, |
259 | | -): AppError { |
| 263 | +): unknown { |
260 | 264 | const original = asAppError(exportError, 'COMMAND_FAILED'); |
261 | | - const { reason } = original.details ?? {}; |
262 | | - // `processExitError` is what makes normalizeError append the recorder's first stderr line, so the |
263 | | - // exit facts reach the operator without repeating them in this message. |
264 | | - return new AppError(original.code, `${original.message}; ${exit}`, { |
265 | | - stderr: result.stderr, |
266 | | - exitCode: result.exitCode, |
267 | | - processExitError: true, |
268 | | - ...(typeof reason === 'string' ? { reason } : {}), |
269 | | - ...(result.signal === undefined ? {} : { signal: result.signal }), |
270 | | - retriable: false, |
271 | | - hint: |
272 | | - 'The recorder exited before record stop, so the next record stop reads the same file. ' + |
273 | | - 'Close this session to release the device, then record again.', |
274 | | - }); |
| 265 | + if (original.details?.reason !== RECORDING_OUTPUT_UNPLAYABLE_REASON) return exportError; |
| 266 | + return new AppError( |
| 267 | + original.code, |
| 268 | + `${original.message}; ${exit}`, |
| 269 | + execFailureDetails(result, { |
| 270 | + ...(original.details ?? {}), |
| 271 | + ...(result.signal === undefined ? {} : { signal: result.signal }), |
| 272 | + retriable: false, |
| 273 | + hint: |
| 274 | + 'The recorder exited before record stop, so the next record stop reads the same file. ' + |
| 275 | + 'Close this session to release the device, then record again.', |
| 276 | + }), |
| 277 | + ); |
275 | 278 | } |
276 | 279 |
|
277 | 280 | function runnerDescriptorMatchesDevice( |
|
0 commit comments