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
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