cua icon indicating copy to clipboard operation
cua copied to clipboard

[Bug]: Trajectory recorder is daemon-wide, not session-scoped — unrelated CLI calls write end_session turns into another session's recording

Open 0p9b opened this issue 3 months ago • 1 comments

Primary area

Cua Driver

Summary

start_recording is documented as a session-scoped recorder over a fixed set of action tools. In practice the recorder is daemon-wide while active: it writes turn folders for tool calls belonging to other transports' sessions, and for end_session, which is not an action tool and is not in the documented recorded set.

The practical effect is that any one-shot CLI use of cua-driver running concurrently with a recording silently pollutes that recording's turn numbering, and replay_trajectory then re-executes unrelated lifecycle calls.

Reproduction

Every command below is read-only apart from starting and stopping the recorder. No windows are touched.

Note on the path: on macOS /tmp is a symlink, and start_recording refuses such a path with {"code":"protected_resource_scope_invalid","message":"the output path's existing ancestor is not a directory"}. The steps therefore use a real directory.

R=/private/tmp/cua-recorder-scope
rm -rf "$R" && mkdir -p "$R"

cua-driver start_recording "{\"output_dir\":\"$R\",\"record_video\":false,\"session\":\"owner\"}"

# three unrelated, read-only, one-shot calls
cua-driver get_screen_size '{}'
cua-driver list_apps '{}'
cua-driver get_cursor_position '{}'

cua-driver stop_recording '{}'

ls "$R" | grep turn
cat "$R"/turn-00001/action.json

Reproduces every time; observed on two independent runs.

Expected behavior

The recording belongs to session owner. Three read-only calls that perform no action, and that belong to other implicit sessions, should produce no turn folders.

RECORDING.md in the bundled skill pack states the recorded set is click, right_click, scroll, type_text, press_key, hotkey, set_value, and describes the recorder as session-scoped.

Actual behavior

Four turn folders are written. Each records end_session for a foreign implicit session id — the transport teardown of each one-shot CLI process as it exits, plus the start_recording process's own:

turn-00001: end_session {"session": "sdk-<uuid>"}
turn-00002: end_session {"session": "sdk-<uuid>"}
turn-00003: end_session {"session": "sdk-<uuid>"}
turn-00004: end_session {"session": "sdk-<uuid>"}

None of these session ids is the recording's owner. start_recording returned "owner": "owner" and "recording": true.

Environment

  • cua-driver 0.22.2 (stable channel; latest release at time of report)
  • macOS 26.6.2, arm64
  • Permission mode standard; daemon started from the signed app bundle via a LaunchAgent
  • Reproduced entirely through the CLI. Also observed with start_recording / stop_recording issued over MCP while the intervening calls came from the CLI.

Evidence

start_recording response:

{"enabled":true,"output_dir":"/private/tmp/cua-recorder-scope","owner":"owner","recording":true,"video_active":false}

A turn folder's action.json, showing a tool outside the documented recorded set and a session other than the owner:

{"tool":"end_session","arguments":{"session":"sdk-<uuid>"}}

The same pattern appeared at larger scale during a full tool-surface test: 9 of 13 turns in one recording and 7 of 11 in another were foreign end_session entries. A subsequent replay_trajectory over that directory re-executed them and reported success on each.

Impact:

  • Turn numbering in a recording is non-deterministic, since it depends on unrelated CLI activity elsewhere on the machine.
  • replay_trajectory re-invokes lifecycle calls that were never part of the recorded workflow.
  • Recordings are documented as suitable for regression diffs and training data; both uses assume the turn sequence reflects only the recorded session's actions.
  • Most visible for CLI-driven workflows, where every invocation creates and tears down its own implicit session. A single long-lived MCP connection triggers it far less often.

No configuration works around it: there is no flag, config key, or environment variable that scopes the recorder to its owning session. The only recorder-related environment variable in the binary is CUA_DRIVER_RS_RECORDING_IDLE_TTL_SECS, which is an idle timeout, and cua-driver recording accepts only start <dir>, stop, status, and render.

Also, minor doc mismatch

Unrelated to the above and a one-line fix. The shipped tool and the bundled skill documentation disagree on the video default:

  • cua-driver describe start_recording states "Video is off by default.", and its record_video schema says Default: false.
  • The bundled skill pack says the opposite in two places: RECORDING.md line 20, "Video on by default. … Opt out with record_video: false", and SKILL.md line 1059, "Video capture … is on by default; pass record_video: false to opt out."

Observed behaviour matches the tool, so the prose is the stale side. An agent that trusts the skill file reports a phantom defect when no recording.mp4 appears.

0p9b avatar Aug 29 '26 03:08 0p9b

Opened #3632 for this.

Scope implemented: turn reservation is gated on the caller's runtime session id (the same trusted _session_id start_recording already stamps as the recording's owner), checked inside the same lock as the reservation so a concurrent start() can't hand a foreign call a turn. An anonymously started recording (cua-driver recording start, legacy configure() shim) has no owner and stays daemon-wide, which is what the CLI recorder needs. start_session/end_session are excluded from recording outright — that's what removes the foreign end_session turns you saw.

The video-default doc mismatch you noted is fixed in the same PR (RECORDING.md, SKILL.md, and the start_recording description), with the prose treated as the stale side.

Acceptance evidence: three new tests (two unit, one end-to-end through the tool registry with the recording and session tools registered), each verified to fail on unmodified main; cargo test -p cua-driver-core --locked green.

c8dhjp4tyv-bit avatar Sep 07 '26 21:09 c8dhjp4tyv-bit