Skip to content

fix(capture): drain native temporaries while Annotate records - #2980

Merged
kitlangton merged 1 commit into
devfrom
fix-capture-autoreleasepool
Nov 27, 2026
Merged

kitlangton merged 1 commit into
devfrom
fix-capture-autoreleasepool

Conversation

@kitlangton

Copy link
Copy Markdown
Collaborator

Drain macOS temporary objects while Annotate records.

Reported symptom: Annotate runs out of memory or crashes after a few minutes of recording. This fixes missing autorelease pools found in its Rust capture workers; the full recording crash has not been reproduced here.

Before

  1. The screenshot sampler in crates/capture/src/capture/macos.rs ran screenshot conversion, prompt checks, and ScreenCaptureKit filter refreshes without a per-tick pool.
  2. window_log.rs pooled snapshots but not its frequent cursor/frontmost-app polls. The HID poller and Accessibility lookup worker also lacked per-iteration pools.
  3. Screen probes, target/window discovery, app queries/activation polling, and text/PNG clipboard handoffs could call native APIs on workers without a pool.

After

  1. The sampler drains each tick, including skipped shots, with separate pools for setup and stop.
  2. Window/HID polls and each Accessibility lookup drain before the next iteration.
  3. The other native entry points drain on return. Returned values remain owned.
- worker tick -> native temporaries wait for a pool to drain
+ worker tick -> autoreleasepool(native work) -> drain -> wait

Verified

Case Before After
Autoreleased object survives into the next Accessibility worker lookup Yes No
Multi-minute recording memory growth Not measured Not measured

The new macOS regression test failed before the worker pool was added and passes with it, without screen or Accessibility permissions. 514 related tests passed.

Read: run_sampler in crates/capture/src/capture/macos.rs: early skips return from the pool closure, then park once, preserving the sampling schedule. Most changed lines are indentation.

Checks run
  • python3 scripts/code-shape.py --check: passed.
  • cargo fmt --all --check: passed via the check script.
  • cargo clippy --locked -p scrawl-capture -p capture-core --all-targets -- -D warnings: passed.
  • scripts/check capture window_log ax:: handoff::: passed.
  • cargo nextest run --locked -p scrawl-capture -E 'test(the_prober_drains_autoreleased_objects_between_lookups)': failed before the fix, as intended; the test passed in the check run above.
  • Existing Cargo unused-dependency and linker unwind-size warnings remain.
  • Live-recording OOM verification still needs a permissioned, multi-minute capture.

@kitlangton
kitlangton merged commit 2a70e58 into dev Nov 27, 2026
4 checks passed
@kitlangton
kitlangton deleted the fix-capture-autoreleasepool branch November 27, 2026 19:41
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