"""Completion windows shared by the native executor and one-shot transport. NativeControls waits up to four seconds; touch frames last at most ten seconds. The grace also covers callback/release and transport cleanup. Search deadlines stop new input, while already-dispatched input retains its resource until quiet. """ from typing import Any CONTROL_COMPLETION_SECONDS = 5.0 TOUCH_COMPLETION_GRACE_SECONDS = 5.0 def input_completion_seconds(command: str, args: dict[str, Any]) -> float: if command == "control_action": return CONTROL_COMPLETION_SECONDS if command != "touch_gesture": return 0.0 frames = args.get("frames") last = ( frames[-1].get("at_ms") if isinstance(frames, list) and frames and isinstance(frames[-1], dict) else None ) # A malformed raw call still gets the conservative maximum drain window. duration = min(max(last, 0), 10000) if type(last) is int else 10000 return duration / 1000 + TOUCH_COMPLETION_GRACE_SECONDS