Skip to content

fix(cua-driver-rs)(macos): isolate and clean up window capture temp files - #2281

Open
z-x-yang wants to merge 1 commit into
trycua:mainfrom
z-x-yang:fix/cua-driver-macos-capture-tempfiles
Open

fix(cua-driver-rs)(macos): isolate and clean up window capture temp files#2281
z-x-yang wants to merge 1 commit into
trycua:mainfrom
z-x-yang:fix/cua-driver-macos-capture-tempfiles

Conversation

@z-x-yang

Copy link
Copy Markdown

Summary

  • Generate a unique temporary path for every macOS window capture using the process ID, window ID, and a process-local atomic sequence.
  • Own the path with an RAII guard so partial or unreadable capture files are removed on every return path.
  • Add deterministic unit tests for per-call path uniqueness and cleanup-on-drop behavior.

Why

Window capture currently reuses /tmp/cua-driver-rs-capture-{window_id}.png.

Concurrent captures of the same window can therefore overwrite, read, or remove each other's files. Cleanup also happens only after a successful file read, so a failed screencapture invocation or read can leave a partial file behind.

A per-capture path removes the same-window collision, while RAII cleanup keeps failure paths from leaking temporary files.

Relation to #2104

This PR is intentionally separate from #2104.

#2104 adds display-asleep diagnostics and surfaces screenshot failures. This PR does not add or duplicate screenshot_error, text diagnostics, display-state detection, or action-result changes. It only hardens the temporary-file lifecycle used by window capture.

After #2104 is rebased onto current main, the changes remain complementary: its diagnostics run inside capture failure branches, while this PR ensures the associated temporary file is unique and removed when those branches return.

Test Plan

  • rustfmt --edition 2021 --check crates/platform-macos/src/capture.rs
  • cargo check -p platform-macos
  • cargo test -p platform-macos — 134 passed, 0 failed
  • git diff --check

The new tests deterministically verify unique paths and cleanup-on-drop without requiring Screen Recording permission or live TCC changes.

Caveats

  • This focused change covers the window-capture temporary file extracted from the original fix; full-display capture handling is unchanged.
  • A package-wide cargo fmt -p platform-macos -- --check currently reports pre-existing formatting drift in unrelated files, beginning with src/apps/mod.rs. The modified capture.rs passes a targeted rustfmt check, and unrelated formatting was intentionally left out of this PR.
  • The current fix(cua-driver-rs)(macos): surface display-asleep state in capture errors and action results #2104 head predates capture error-handling changes already present on main and therefore requires rebasing independently of this PR.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant