Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions packages/platform-android/src/recording/chunks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,18 @@ export class AndroidScreenRecordingStartRollbackUnconfirmed extends Error {
}
}

/**
* Refusal raised when the recording's stop was claimed before a chunk launch was dispatched. It is
* how the launch owner reports that the stop outran it, so the rotation withdraws without starting a
* recorder. Only `startPendingChunk` raises it: a commit already in flight runs to its real outcome,
* because cancelling the host command cannot prove what the device's rename did.
*/
export class AndroidScreenRecordingStopClaimed extends Error {
constructor() {
super('Android screenrecord rotation refused: the recording stop was already claimed');
}
}

export function candidateRemotePaths(
preferredDir: string | undefined,
now = Date.now(),
Expand Down
10 changes: 9 additions & 1 deletion packages/platform-android/src/recording/finalize.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,12 @@
startedAtMs: number;
progress?: DurableCaptureProgress;
reachedLimit?: boolean;
/**
Comment thread
thymikee marked this conversation as resolved.
Resolved
* Whether a rotation retired the active chunk's recorder itself and withdrew before replacing
* it. That retirement explains an already-gone active recorder, so its absence is not the
* platform's 180 s limit truncating a recording that was still running.
*/
activeRecorderRetired?: boolean;

Check notice on line 61 in packages/platform-android/src/recording/finalize.ts

View check run for this annotation

apex-sentinel-staging / Apex Sentinel

nit: `activeRecorderRetired` is an optional flag whose only producer passes it; the recovery caller silently relies on its absence

`finalizeAndroidRecording` adds `activeRecorderRetired?: boolean` (finalize.ts:56-61) and reads it with `!== true` (finalize.ts:77). The only caller that passes it is runtime.ts:266; the recovery caller (recovery.ts:189-197) does not, and its correctness depends on the field staying absent there — a re-adopted recording has no in-process rotation to credit. Making the flag required (or naming it as the caller's provenance of the active recorder's absence) makes that dependency explicit instead of resting on an omitted optional property; `isValidNativeManifest`/`AndroidRecordingDescriptor` (manifest.ts:14-55) show this codebase expressing such per-field obligations as required shapes.
}>,
): Promise<FinishOutcome<ScreenRecordingCompletion>> {
const { host, transport, evidence, recording, startedAtMs, progress } = params;
Expand All @@ -66,7 +72,9 @@
// growing is the evidence the recorder stopped writing (ADR 0024 2.2). The platform limit is
// disclosed here rather than at the export because it is a fact about the recorder, and the
// journal is what keeps it attached to a stop that has to be driven again.
reachedLimit = (await stopOwnedChunks(transport, evidence.chunks)) || reachedLimit;
const activeRecorderAlreadyGone = await stopOwnedChunks(transport, evidence.chunks);
reachedLimit =
(activeRecorderAlreadyGone && params.activeRecorderRetired !== true) || reachedLimit;
Comment thread
thymikee marked this conversation as resolved.
Resolved
Comment thread
thymikee marked this conversation as resolved.
Resolved
await waitForStableArtifacts(transport, evidence.chunks);
return {
observation: { recorder: 'confirmed' },
Expand Down
7 changes: 5 additions & 2 deletions packages/platform-android/src/recording/fixtures.ts
Original file line number Diff line number Diff line change
Expand Up @@ -88,8 +88,11 @@ export function recordingHost(overrides: Record<string, unknown>): PlatformRunti
legacy.readManifest
? await legacy.readManifest(manifestPath)
: { status: 'missing' as const },
writeManifest: async (request: { manifestPath: string; contents: string }) => {
await legacy.writeManifest?.(request);
writeManifest: async (
Comment thread
thymikee marked this conversation as resolved.
Resolved
request: { manifestPath: string; contents: string },
signal?: AbortSignal,
) => {
await legacy.writeManifest?.(request, signal);
},
removeManifest: async (manifestPath: string) =>
legacy.removeManifest ? await legacy.removeManifest(manifestPath) : true,
Expand Down
20 changes: 19 additions & 1 deletion packages/platform-android/src/recording/launch.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import type { ScreenRecordingStartInput } from '@agent-device/contracts/screen-recording-runtime';
import {
AndroidScreenRecordingStartRollbackUnconfirmed,
AndroidScreenRecordingStopClaimed,
candidateRemotePaths,
rollbackChunks,
startChunkAt,
Expand Down Expand Up @@ -99,24 +100,41 @@
chunks: readonly NativeChunk[];
manifestPath: string;
preferredDir: string;
// Refuses a device start once the recording's stop has been claimed.
launchAdmission: AbortSignal;
}): Promise<NativeChunk> {
const { transport, device, input, startedAt, chunks, manifestPath, preferredDir } = params;
const {
transport,
device,
input,
startedAt,
chunks,
manifestPath,
preferredDir,
launchAdmission,
} = params;
let last: unknown;
Comment thread
thymikee marked this conversation as resolved.
Resolved
for (const remotePath of candidateRemotePaths(preferredDir)) {
Comment thread
thymikee marked this conversation as resolved.
Resolved
Comment thread
thymikee marked this conversation as resolved.
Resolved
if (launchAdmission.aborted) throw new AndroidScreenRecordingStopClaimed();
Comment thread
cubic-dev-ai[bot] marked this conversation as resolved.
Resolved
await persistNativeManifest(
transport,
manifestPath,
createNativeManifest(device, input, startedAt, chunks, remotePath, transport.mode),
);
try {
Comment thread
thymikee marked this conversation as resolved.
Resolved
// The pending evidence is on the device, but the stop may have been claimed while it was being
// written. Refuse here rather than dispatch a recorder the recording has already given up.
if (launchAdmission.aborted) throw new AndroidScreenRecordingStopClaimed();
return await startChunkAt(transport, remotePath, input);
} catch (error) {
if (error instanceof AndroidScreenRecordingStartRollbackUnconfirmed) throw error;
Comment thread
thymikee marked this conversation as resolved.
Resolved
try {
// Clears the pending marker, which names a recorder nothing launched when the refusal raised
// this error.
await persistNativeManifest(
transport,
manifestPath,
createNativeManifest(device, input, startedAt, chunks, undefined, transport.mode),

Check notice on line 137 in packages/platform-android/src/recording/launch.ts

View check run for this annotation

apex-sentinel-staging / Apex Sentinel

nit: stale comment: the clear-marker rollback in startPendingChunk never clears the marker

The new comment over the rollback persist says it 'Clears the pending marker, which names a recorder nothing launched'. It does the opposite: it writes `createNativeManifest(..., chunks, undefined, ...)`, i.e. a marker that drops pendingRemotePath, keeping the committed chunk set. Worse, in the launchAdmission.aborted branch that rollback itself calls persistNativeManifest without re-checking admission, so the refused rotation's last act is one more host write after the stop was claimed. Rewrite the comment to what the line does and say why the write is still wanted after a refusal.
);
} catch {
throw new AndroidScreenRecordingStartRollbackUnconfirmed(error);
Expand Down
26 changes: 18 additions & 8 deletions packages/platform-android/src/recording/manifest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,23 @@ export const androidScreenRecordingDescriptorCodec = Object.freeze({
: ({ status: 'invalid', message: 'Invalid Android screen-recording descriptor' } as const),
});

/**
* The requested recording options, carried unchanged by every durable record of the recording: an
* option recorded in one place and not another would make that record disagree about what was asked.
*/
export function recordingRequestFields(input: ScreenRecordingStartInput) {
Comment thread
thymikee marked this conversation as resolved.
Resolved
Comment thread
thymikee marked this conversation as resolved.
Resolved
return {
outputPath: input.outputPath,
...(input.clientOutputPath === undefined ? {} : { clientOutputPath: input.clientOutputPath }),
scope: input.scope,
showTouches: input.showTouches,
recordOnlySession: input.recordOnlySession,
...(input.activeSessionApp === undefined ? {} : { activeSessionApp: input.activeSessionApp }),
...(input.exportQuality === undefined ? {} : { exportQuality: input.exportQuality }),
...(input.fps === undefined ? {} : { fps: input.fps }),
};
}

export function createNativeManifest(
device: DeviceInfo,
input: ScreenRecordingStartInput,
Expand All @@ -106,14 +123,7 @@ export function createNativeManifest(
sessionId: input.sessionId,
deviceId: device.id,
startedAt,
outputPath: input.outputPath,
...(input.clientOutputPath === undefined ? {} : { clientOutputPath: input.clientOutputPath }),
scope: input.scope,
showTouches: input.showTouches,
recordOnlySession: input.recordOnlySession,
...(input.activeSessionApp === undefined ? {} : { activeSessionApp: input.activeSessionApp }),
...(input.exportQuality === undefined ? {} : { exportQuality: input.exportQuality }),
...(input.fps === undefined ? {} : { fps: input.fps }),
...recordingRequestFields(input),
chunks,
...(pendingRemotePath === undefined ? {} : { pendingRemotePath }),
transportMode,
Expand Down
Loading
Loading