Skip to content

armgit / Cap

Public Imported from GitHub
0

Open source Loom alternative. Beautiful, shareable screen recordings.

test: preserve input timestamps in recording verification

Richie McIlroy3dd86ca7c222
diff --git a/scripts/recording-reliability.md b/scripts/recording-reliability.md
index 3d1b703d2..587915264 100644
--- a/scripts/recording-reliability.md
+++ b/scripts/recording-reliability.md
@@ -77,7 +77,7 @@ SQLite's crash-testing approach is a useful model for a persistence harness: inj
The measured candidate is not yet at 0.5.9 parity. A Linux 120-second Studio pair took 537.342 ms versus 362.396 ms from Stop to process exit. Windows 12-second Instant pairs took 446.028 versus 405.319 ms and 473.999 versus 376.941 ms from capture-thread completion to process exit. These are different boundaries and limited samples, not universal latency distributions. The Linux project occupied about 141 MB versus 70 MB because original media was retained.
-The original PR introduced the private copy and repeated full snapshots. Current repairs reduced decoding and temporary-write overhead, but retained the complete-media copy. A slow disk or long recording magnifies that work. Do not remove preservation merely to match a stopwatch.
+The original PR introduced the private copy and repeated full snapshots. Repairs reduced decoding and temporary-write overhead, but retained the complete-media copy. A subsequent bounded clean-Studio change removes one redundant original-input scan while retaining the independently verified staged copy, final source snapshot, track-failure guard and publication transaction. Full recovery keeps its earlier check. The timings above precede that scan reduction; new native parity measurements remain required. A slow disk or long recording magnifies the remaining work. Do not remove preservation merely to match a stopwatch.
Apply optimizations in increasing order of risk:
@@ -108,6 +108,8 @@ On Windows use `python` and add `--windows-job-source scripts/recording-reliabil
Run the same assertion schema on all three OSes. A VM proves its guest capture and filesystem paths, not every physical microphone/camera/GPU. Missing devices, silent stimuli, unavailable editor controls or inaccessible cloud environments are `PENDING`, not `PASS`. Requested audio must be present and demonstrably non-silent; A/V synchronization needs an independently measurable flash/tone or equivalent stimulus, not just container timestamps.
+The decode oracle preserves the demuxer timebase and passes every frame through. FFmpeg's default output encoder timebase can round distinct input timestamps together when writing to a null sink; a synthetic monotonic-timestamp fixture reproduced that false error. Input packet decode timestamps are therefore checked independently, while reordered presentation timestamps and audio preroll remain valid. Decode errors are still failures, and each file's initial hash is retained even when verification fails. [FFmpeg timestamp options](https://ffmpeg.org/ffmpeg.html#Advanced-options).
+
| Scenario family | Required evidence |
| --- | --- |
| Clean Instant and Studio | Start/stop events, complete local metadata, expected tracks, duration/cadence, full decode, project validation |
@@ -131,6 +133,6 @@ Record exact source/build identity, OS/filesystem, requested inputs, fixture ide
## Implementation and release gates
-First changes are deliberately bounded: atomic recording metadata replacement, fail-closed Tauri segment completion, and a common local recording oracle. They do not implement the entire lifecycle described above. In particular, background GPUI upload/restart reconciliation, final-object-based deletion, filesystem durability ordering and strict performance parity remain separate work until verified.
+First changes are deliberately bounded: atomic recording metadata replacement with Windows open-reader support, fail-closed Tauri segment completion, validated restart inventories, exact multipart retry reads, one redundant clean-Studio scan removed, and a common local recording oracle. They do not implement the entire lifecycle described above. In particular, background GPUI upload/restart reconciliation, final-object-based deletion, filesystem durability ordering and strict performance parity remain separate work until verified.
Before release: all required native scenarios must pass on the final source/build; every false-success/data-loss finding must be fixed; 0.5.9 projects and supported recording combinations must remain compatible; performance comparisons must meet the agreed parity requirement; and a fresh independent/Greptile review must cover the final changes. A review score or green CI job cannot replace missing native or cloud evidence.
diff --git a/scripts/recording-reliability.py b/scripts/recording-reliability.py
index 6060d2a50..1ce288e7b 100644
--- a/scripts/recording-reliability.py
+++ b/scripts/recording-reliability.py
@@ -129,6 +129,25 @@ def media_metrics(probe, expected_duration, fps, kind):
return measurements
+def packet_timestamps(probe):
+ streams = {stream["index"] for stream in probe.get("streams", []) if stream.get("codec_type") in {"video", "audio"}}
+ previous, counts = {}, {}
+ for packet in probe.get("packets", []):
+ index = packet.get("stream_index")
+ if index not in streams:
+ continue
+ dts, pts = packet.get("dts"), packet.get("pts")
+ if type(dts) is not int or type(pts) is not int:
+ raise ValueError("Media packet has no integer decode/presentation timestamp")
+ if index in previous and dts <= previous[index]:
+ raise ValueError("Input packet decode timestamps are not strictly increasing")
+ previous[index] = dts
+ counts[index] = counts.get(index, 0) + 1
+ if not streams or set(counts) != streams:
+ raise ValueError("Missing timestamped packets for a media stream")
+ return counts
+
+
def audio_levels(stderr):
levels = re.findall(r"RMS level dB:\s*(-?inf|[-+0-9.eE]+)", stderr)
if not levels:
@@ -315,12 +334,14 @@ def checked_json(stdout, stderr):
def check_media(runner, args, prefix, media):
path = Path(media["path"])
before = sha256(path)
- stdout, stderr = runner.run(prefix + "-probe", [str(args.ffprobe), "-v", "error", "-count_frames", "-show_streams", "-show_format", "-of", "json", str(path)])
+ write_json(runner.root / f"{prefix}-media-before.json", {**media, "bytes": path.stat().st_size, "sha256Before": before})
+ stdout, stderr = runner.run(prefix + "-probe", [str(args.ffprobe), "-v", "error", "-count_frames", "-show_streams", "-show_format", "-show_packets", "-show_entries", "packet=stream_index,dts,pts:stream:format", "-of", "json", str(path)])
if stderr.strip():
raise ValueError("FFprobe emitted an error while counting decoded frames")
probe = strict_json(stdout)
metrics = media_metrics(probe, args.duration, args.fps, media["kind"])
- _, errors = runner.run(prefix + "-decode", [str(args.ffmpeg), "-v", "error", "-nostdin", "-xerror", "-err_detect", "explode+crccheck", "-i", str(path), "-map", "0:v?", "-map", "0:a?", "-f", "null", "-"], 120)
+ packets = packet_timestamps(probe)
+ _, errors = runner.run(prefix + "-decode", [str(args.ffmpeg), "-v", "error", "-nostdin", "-xerror", "-err_detect", "explode+crccheck", "-i", str(path), "-map", "0:v?", "-map", "0:a?", "-fps_mode", "passthrough", "-enc_time_base", "demux", "-f", "null", "-"], 120)
if errors.strip():
raise ValueError("Full decode emitted errors")
audio = [stream for stream in probe["streams"] if stream.get("codec_type") == "audio"]
@@ -334,7 +355,7 @@ def check_media(runner, args, prefix, media):
after = sha256(path)
if before != after:
raise ValueError("Read-only media verification changed the artifact")
- return {**media, "bytes": path.stat().st_size, "sha256Before": before, "sha256After": after, "measurements": metrics, "audio": levels}
+ return {**media, "bytes": path.stat().st_size, "sha256Before": before, "sha256After": after, "measurements": metrics, "packetCounts": packets, "audio": levels}
def run_case(runner, args, label, binary, head, mode):
diff --git a/scripts/test-recording-reliability.py b/scripts/test-recording-reliability.py
index e37431d40..32d2b9708 100644
--- a/scripts/test-recording-reliability.py
+++ b/scripts/test-recording-reliability.py
@@ -109,6 +109,28 @@ class RecordingReliabilityTests(unittest.TestCase):
reliability.audio_levels(stderr)
self.assertEqual(reliability.audio_levels("RMS level dB: -24.5")["maximumRmsDbfs"], -24.5)
+ def test_packet_timestamps_preserve_reordered_presentation_and_audio_preroll(self):
+ probe = {"streams": [{"index": 0, "codec_type": "video"}, {"index": 1, "codec_type": "audio"}], "packets": [
+ {"stream_index": 0, "dts": -2, "pts": 0},
+ {"stream_index": 1, "dts": -1024, "pts": -1024},
+ {"stream_index": 0, "dts": -1, "pts": 2},
+ {"stream_index": 1, "dts": 0, "pts": 0},
+ {"stream_index": 0, "dts": 0, "pts": 1},
+ ]}
+ self.assertEqual(reliability.packet_timestamps(probe), {0: 3, 1: 2})
+
+ def test_duplicate_reversed_and_missing_packet_timestamps_fail(self):
+ for second in [0, -1, None, "1", True]:
+ probe = {"streams": [{"index": 0, "codec_type": "video"}], "packets": [
+ {"stream_index": 0, "dts": 0, "pts": 0},
+ {"stream_index": 0, "dts": second, "pts": 1},
+ ]}
+ with self.subTest(second=second), self.assertRaises(ValueError):
+ reliability.packet_timestamps(probe)
+ for probe in [{"streams": [], "packets": []}, {"streams": [{"index": 0, "codec_type": "audio"}], "packets": []}]:
+ with self.subTest(probe=probe), self.assertRaises(ValueError):
+ reliability.packet_timestamps(probe)
+
def test_pending_and_failed_requirements_cannot_become_success(self):
self.assertEqual(reliability.aggregate([]), "FAIL")
self.assertEqual(reliability.aggregate([{"status": "PASS"}, {"status": "PENDING"}]), "PENDING")