367 files, from working commit b1a079a. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
43 lines
2.0 KiB
Python
43 lines
2.0 KiB
Python
"""Read-only pause when the official Octo client reclaims startup focus."""
|
|
import time
|
|
|
|
_OCTO_FOCUS_GUARD = 'Official Octo is focused; pause automation until a fresh ten-second notice and explicit focus transfer'
|
|
_OCTO_CAPTURE_RACES = frozenset((_OCTO_FOCUS_GUARD,
|
|
'Refusing capture without WowB focus', 'Focus changed during capture; image discarded',
|
|
'WowB lost focus; input stopped'))
|
|
|
|
|
|
def octo_focus_race(error, *, ui, display):
|
|
"""Recognize only an observed Octo focus race, not other UI failures."""
|
|
return isinstance(error, RuntimeError) and str(error) in _OCTO_CAPTURE_RACES and ui.official_octo_focused(display)
|
|
|
|
|
|
def wait_for_owned_startup_focus(*, ui, display, window, owned_alive, stage,
|
|
context, timeout=300, clock=time.monotonic,
|
|
sleep=time.sleep):
|
|
"""Wait for an externally announced owned-window transfer; never inject input.
|
|
|
|
Only the existing Octo-specific focus guard is recoverable. Window identity
|
|
changes, process exit and unrelated focus errors continue to fail closed.
|
|
"""
|
|
started = clock()
|
|
try:
|
|
ui.ensure_focus(display, window)
|
|
return 0.0
|
|
except RuntimeError as error:
|
|
if str(error) != _OCTO_FOCUS_GUARD:
|
|
raise
|
|
stage('startup_focus_required', reason='official_octo_focused', **context())
|
|
until = clock() + timeout
|
|
while clock() < until:
|
|
if not owned_alive():
|
|
raise RuntimeError('Owned client exited during startup focus pause')
|
|
if ui.owns_input(display, window.id) and not ui.official_octo_focused(display):
|
|
if ui.target(display).id != window.id:
|
|
raise RuntimeError('WowB main window changed; no input sent')
|
|
stage('startup_focus_resumed', **context())
|
|
return max(0.0, clock() - started)
|
|
sleep(.5)
|
|
stage('startup_focus_timeout', seconds=timeout, **context())
|
|
raise RuntimeError('Startup focus pause timed out; no authentication replay')
|