Skip to content

Fix/annotated screenshot race - #378

Merged
Jeomon merged 3 commits into
CursorTouch:mainfrom
Anantctrl:fix/annotated-screenshot-race
Aug 12, 2026
Merged

Fix/annotated screenshot race#378
Jeomon merged 3 commits into
CursorTouch:mainfrom
Anantctrl:fix/annotated-screenshot-race

Conversation

@Anantctrl

Copy link
Copy Markdown
Contributor

This PR fixes the annotated-screenshot race condition.

Problem: Desktop.get_annotated_screenshot() drew annotations onto one shared PIL ImageDraw object from ThreadPoolExecutor threads. PIL's ImageDraw isn't thread-safe, so labels rendered corrupted and output was non-deterministic.

Fix: draw annotations sequentially in a for-loop. PIL drawing is GIL-bound, so the thread pool never gave real parallelism — same speed, no race.

Testing: added tests/test_annotation_thread_safety.py — renders identical input repeatedly and asserts byte-identical output. Passes here; fails on the old threaded code (reproduced 100 distinct outputs). Full suite: 200 passed (6 pre-existing unrelated failures in tests/test_tree_views.py). Ruff clean.

@Jeomon
Jeomon merged commit dc6d06c into CursorTouch:main Aug 12, 2026
1 check failed
@Jeomon

Jeomon commented Aug 12, 2026

Copy link
Copy Markdown
Member

Thanks

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.

2 participants