fix: don't take a screenshot at import time (breaks headless imports)#23
Merged
Conversation
recorder.py computed monitor dimensions via utils.take_screenshot() at module scope, so `import openadapt_capture` crashed in any headless environment whose display reported a zero-size region. This took down `openadapt version` and `openadapt doctor` (found via the new CLI smoke tests in OpenAdaptAI/OpenAdapt). Move the computation into the video- setup function that is its only consumer. Adds tests/test_headless_import.py: a deterministic AST guard that no package module calls a display API (take_screenshot/get_monitor_dims/ grab) at import scope. A subprocess import test is unreliable (only reproduces on a genuinely headless display); this fails regardless of environment. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
5e97386 to
1097148
Compare
abrichr
added a commit
that referenced
this pull request
Jul 12, 2026
…tio on the recording model (#24) * fix: tolerate headless screenshot failure on import The recorder no longer takes a screenshot at module load (PR #23), but the package import guard only caught ImportError. Broaden it so a display/screenshot failure (mss ScreenShotError) during recorder import also degrades to `Recorder = None` instead of crashing the whole package on a headless host (CI, containers, sandboxes). Add a runtime headless-import test that imports the package fresh in a subprocess where mss.grab raises ScreenShotError, complementing the existing static (AST) guard. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01CKrVJJy5jWVCkXAqgUqtqZ * fix: persist pixel_ratio on the SQLAlchemy recording model CaptureSession.pixel_ratio read `pixel_ratio` off the SQLAlchemy Recording model, but that model had no such column (only the legacy raw-sqlite schema did), so a HiDPI capture whose config JSON lacked it silently scaled at 1.0, under-scaling downstream coordinate mapping. Add a nullable `pixel_ratio` column to the Recording model and write the captured display's ratio (platform.get_display_pixel_ratio()) at record time in create_recording. Add an additive ALTER TABLE ADD COLUMN migration (migrate_missing_columns) run when opening any per-capture DB, so older recording.db files that predate the column still load: the column is added as NULL, and CaptureSession.pixel_ratio falls back to the config JSON, then 1.0 when genuinely unknown. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01CKrVJJy5jWVCkXAqgUqtqZ --------- Co-authored-by: Claude Opus 4.8 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
recorder.pycomputed monitor dimensions at module scope viautils.take_screenshot().size. Soimport openadapt_captureexecutes a screenshot on import, and crashes in any headless environment whose display reports a zero-size region:That also took down
openadapt versionandopenadapt doctor, which import sibling packages to read their versions — found via the new CLI smoke tests in OpenAdaptAI/OpenAdapt#1003.Fix: move the dimension computation into
record_video's setup, its only consumer (the screenshot now runs when recording starts, not on import).Regression guard
tests/test_headless_import.pyis a deterministic AST check that no package module calls a display API (take_screenshot/get_monitor_dims/grab) at import scope. A subprocessimporttest is unreliable — it only reproduces on a genuinely headless display — so this asserts the invariant statically instead. Verified: passes on this fix, fails on the pre-fix code.Verification
import openadapt_capturesucceeds headless after the fix2 failed, 16 errorsare pre-existing in this sandbox and identical with/without this change)🤖 Generated with Claude Code