Skip to content

armgit / cua

Public Imported from GitHub
0

Scale computer-use 2.0 with open-source drivers, cross-OS sandboxes, and benchmarks for training, evaluation, and data generation.

fix(cua-driver): preserve recording start timestamp in session.json (#5145)

injaneityd7d8ed8c690e
diff --git a/.github/release-attribution-config.json b/.github/release-attribution-config.json
index ede0be68e2..816a22d8d9 100644
--- a/.github/release-attribution-config.json
+++ b/.github/release-attribution-config.json
@@ -28,6 +28,7 @@
"[email protected]": "f-trycua",
"fbonacci@fbonacci-xfce-vm.b40fumexvs1ujlod2ppcyfh5qa.bx.internal.cloudapp.net": "f-trycua",
"[email protected]": "HsiangNianian",
+ "[email protected]": "Iflaqbhat",
"[email protected]": "0xjohnnydev",
"[email protected]": "kevinherron",
"[email protected]": "pavelklymenko",
diff --git a/libs/cua-driver/rust/crates/cua-driver-core/src/recording.rs b/libs/cua-driver/rust/crates/cua-driver-core/src/recording.rs
index a3c9eaf04d..34f4f23c89 100644
--- a/libs/cua-driver/rust/crates/cua-driver-core/src/recording.rs
+++ b/libs/cua-driver/rust/crates/cua-driver-core/src/recording.rs
@@ -690,9 +690,10 @@ impl RecordingSession {
// Write initial session.json — final video metadata is rewritten on
// stop. We mark `present` based on whether ffmpeg actually started,
// not just whether the caller asked for video.
+ let started_at_ms = now_ms();
let session_payload = serde_json::json!({
"schema_version": 1,
- "started_at_monotonic_ms": now_ms(),
+ "started_at_monotonic_ms": started_at_ms,
"video": video_session_payload(video_present, video_error.as_deref(), None),
"cursor": { "present": inner.cursor.is_some(), "sample_count": 0 }
});
@@ -709,7 +710,7 @@ impl RecordingSession {
inner.output_dir = Some(dir);
inner.state_budget = state_budget;
inner.next_turn = 1;
- inner.session_start_ms = now_ms();
+ inner.session_start_ms = started_at_ms;
inner.session_monotonic_start = Some(monotonic_start);
inner.last_error = video_error;
inner.last_video = None;
@@ -751,6 +752,7 @@ impl RecordingSession {
}
inner.owner = None;
let dir = inner.output_dir.clone();
+ let started_at_ms = inner.session_start_ms;
let (video_meta, stop_error) = match inner.video.take().map(|rec| rec.stop()) {
Some(Ok(meta)) => match validate_video_metadata(meta) {
Ok(meta) => (Some(meta), None),
@@ -786,7 +788,7 @@ impl RecordingSession {
};
let session_payload = serde_json::json!({
"schema_version": 1,
- "started_at_monotonic_ms": now_ms(),
+ "started_at_monotonic_ms": started_at_ms,
"video": video_block,
"cursor": { "present": cursor_samples > 0, "sample_count": cursor_samples }
});
@@ -2829,6 +2831,35 @@ mod tests {
);
}
+ #[test]
+ fn stop_preserves_recording_start_timestamp_in_session_manifest() {
+ let root = tempfile::tempdir().expect("temp dir");
+ let output_dir = root.path().join("recording");
+ let session = RecordingSession::new();
+ session
+ .start(output_dir.to_str().expect("utf-8 output dir"), false, None)
+ .expect("start recording");
+
+ let read_manifest = || -> Value {
+ serde_json::from_slice(
+ &std::fs::read(output_dir.join("session.json")).expect("read session manifest"),
+ )
+ .expect("parse session manifest")
+ };
+ let started_at_ms = read_manifest()["started_at_monotonic_ms"]
+ .as_u64()
+ .expect("start timestamp is an integer");
+
+ std::thread::sleep(Duration::from_millis(100));
+ session.stop_owner(None).expect("stop recording");
+
+ assert_eq!(
+ read_manifest()["started_at_monotonic_ms"],
+ started_at_ms,
+ "finalizing the manifest must not replace the recording start time"
+ );
+ }
+
#[test]
fn unlabelled_recording_keeps_named_sessions_on_its_own_transport() {
let root = tempfile::tempdir().expect("temp dir");