From 37bc3f89509d7c9c420374f75c779d10d5f4edbd Mon Sep 17 00:00:00 2001 From: EtienneLescot Date: Sat, 21 Nov 2026 21:49:31 +0100 Subject: [PATCH] fix(capture): close an open pause before a Linux take's stopped snapshot The helper can emit capture-stopped while the take is paused, before stop() runs. That snapshot was compacted with the completed pause ranges only, so cursor samples from the open pause stayed in the take, past the video's end. Both snapshot paths now close the open pause first, at the helper's stop timestamp when it gives one. Refs #1637 --- .../capture/linuxNativeCaptureSession.test.ts | 33 +++++++++++++++++++ .../capture/linuxNativeCaptureSession.ts | 20 ++++++----- 2 files changed, 45 insertions(+), 8 deletions(-) diff --git a/electron/native-bridge/capture/linuxNativeCaptureSession.test.ts b/electron/native-bridge/capture/linuxNativeCaptureSession.test.ts index 52eb42e09..95cd4f127 100644 --- a/electron/native-bridge/capture/linuxNativeCaptureSession.test.ts +++ b/electron/native-bridge/capture/linuxNativeCaptureSession.test.ts @@ -700,6 +700,39 @@ describe("LinuxNativeCaptureSession", () => { expect(helper.stdinWrites).not.toContain("resume\n"); }); + it("closes the cursor pause range when the helper stops while paused, before stop() (#1637)", async () => { + const now = vi.spyOn(Date, "now").mockReturnValue(900); + const session = newSession(); + await startReady(session); + + emitCaptureStarted(1_000); + emitCursorSample(1_100); + await flushStdout(); + + now.mockReturnValue(1_200); + session.pause(); + emitCursorSample(1_300); + await flushStdout(); + + now.mockReturnValue(1_500); + helper.emitEvent({ + event: "capture-stopped", + timestampMs: 1_500, + path: "/tmp/recording.mp4", + durationMs: 200, + frames: 6, + dropped: 0, + }); + await flushStdout(); + + now.mockReturnValue(1_600); + const stopping = session.stop(); + helper.emit("exit", 0, null); + const result = await stopping; + + expect(result.cursor.samples.map((sample) => sample.timeMs)).toEqual([100]); + }); + /** * A non-fatal `error` event after the first frame does not end the capture; * a later wait is still satisfied. diff --git a/electron/native-bridge/capture/linuxNativeCaptureSession.ts b/electron/native-bridge/capture/linuxNativeCaptureSession.ts index fa4a3767d..d2512a87f 100644 --- a/electron/native-bridge/capture/linuxNativeCaptureSession.ts +++ b/electron/native-bridge/capture/linuxNativeCaptureSession.ts @@ -409,6 +409,16 @@ export class LinuxNativeCaptureSession { this.cursorPauseStartedAtMs = null; } + /** + * The cursor telemetry of a finished take, without its paused stretches. A take can + * end while paused, and the helper can end it before `stop()` runs: the open pause + * closes here, where every stopped snapshot is built. + */ + private stoppedCursorData(endMs?: number) { + this.completeCursorPauseRange(endMs); + return compactCursorTelemetryPauseRanges(this.cursor.toRecordingData(), this.cursorPauseRanges); + } + get isPaused() { return this.paused; } @@ -535,10 +545,7 @@ export class LinuxNativeCaptureSession { durationMs: Math.round(salvage.durationSec * 1000), frames: salvage.videoSamples, droppedFrames: 0, - cursor: compactCursorTelemetryPauseRanges( - this.cursor.toRecordingData(), - this.cursorPauseRanges, - ), + cursor: this.stoppedCursorData(), ...(this.sourceKind ? { sourceKind: this.sourceKind } : {}), ...(this.videoEncoder ? { videoEncoder: this.videoEncoder } : {}), ...(this.audioLost ? { audioLost: true as const } : {}), @@ -696,10 +703,7 @@ export class LinuxNativeCaptureSession { durationMs: payload.durationMs, frames: payload.frames, droppedFrames: payload.dropped, - cursor: compactCursorTelemetryPauseRanges( - this.cursor.toRecordingData(), - this.cursorPauseRanges, - ), + cursor: this.stoppedCursorData(payload.timestampMs), ...(this.sourceKind ? { sourceKind: this.sourceKind } : {}), ...(this.videoEncoder ? { videoEncoder: this.videoEncoder } : {}), ...(this.audioLost ? { audioLost: true as const } : {}),