Skip to content

Prevent crashes and silent automation interruptions#457

Open
JE-Chen wants to merge 1 commit into
devfrom
fix/crash-and-interruption-hardening
Open

Prevent crashes and silent automation interruptions#457
JE-Chen wants to merge 1 commit into
devfrom
fix/crash-and-interruption-hardening

Conversation

@JE-Chen

@JE-Chen JE-Chen commented Jul 18, 2026

Copy link
Copy Markdown
Member

Follow-up hardening from a crash/hang-focused audit (two agents swept the background-service and automation-hot-path subsystems). Fixes the class of defects where a long-running service dies silently or a whole automation run aborts on an escaping exception. No API changes.

Automation-abort / silent-death (Tier 1)

  • Float coordinates aborting the whole script (Windows + X11): a float x/y (computed/random var, or JSON literal {"x":100.5}) reached an un-prototyped SetCursorPos / Xlib fake_inputctypes.ArgumentError/struct.error → escaped the executor. Now coerced to int in mouse_preprocess/set_mouse_position (+ Win32 cursor argtypes, _convert_position zero-size guard).
  • Hotkey daemon dying on a normal script failure (all platforms): a missing/renamed script or an image-not-found raised AutoControlException, which wasn't in _fire_binding's catch → the daemon thread died and every hotkey silently stopped. Widened to catch AutoControlException (mirrors scheduler/triggers).
  • Observer / PopupWatchdog / ChatOps loops dying on a user callback: catch tuples omitted LookupError/StopIteration/ArithmeticError, so a callback doing dict[key] killed the poll loop. Widened.
  • cv2.error from AC_match_template* now contained as AutoControlScreenException instead of aborting the run.

Resource leaks / hangs over time (Tier 2)

  • REST / Webhook / socket-command handlers get read timeouts (+ daemon_threads) so a stalled/slowloris client can't pin a worker thread forever.
  • USB/IP server prunes finished workers (was leaking a Thread object per connection).
  • Webhook fire() lock is bounded (120s) and answers 503 busy rather than piling up handler threads while a long script runs (serialisation preserved).
  • host_service daemon loop and WebRTC input dispatch survive transient/unexpected errors instead of exiting.

Verified: 568 changed-module tests pass locally; full headless suite green (test _FakeRequest gained a settimeout no-op to match a real socket).

Fixes a class of defects where a long-running service dies silently or a whole
automation run aborts on an escaping exception:

- Coordinate coercion: a float x/y (computed/random var or JSON literal) no
  longer reaches an un-prototyped SetCursorPos / Xlib fake_input and raises
  ctypes.ArgumentError / struct.error that aborts the whole script; coerce to
  int in mouse_preprocess / set_mouse_position (+ Win32 cursor argtypes and a
  0-size-screen guard in _convert_position).
- Service-loop containment: the hotkey daemon (all platforms), Observer and
  PopupWatchdog poll loops, and the ChatOps command boundary widened to catch
  the failure types a normal script / user callback raises (AutoControlException,
  LookupError, StopIteration, ArithmeticError) instead of the thread dying and
  silently stopping every binding/rule.
- cv2.error from AC_match_template* is now contained as AutoControlScreenException
  rather than aborting the run.
- Server robustness: REST / Webhook / socket-command handlers get read timeouts
  (+ daemon_threads) so stalled clients can't pin worker threads; USB/IP prunes
  finished workers; the webhook fire lock is bounded and answers 503 busy rather
  than piling up handler threads; host_service and WebRTC input dispatch survive
  transient errors.

Test _FakeRequest gains a settimeout no-op to match a real socket.
@codacy-production

Copy link
Copy Markdown

Up to standards ✅

🟢 Issues 0 issues

Results:
0 new issues

View in Codacy

🟢 Metrics 0 complexity · 2 duplication

Metric Results
Complexity 0
Duplication 2

View in Codacy

NEW Get contextual insights on your PRs based on Codacy's metrics, along with PR and Jira context, without leaving GitHub. Enable AI reviewer
TIP This summary will be updated as you push new changes.

@sonarqubecloud

Copy link
Copy Markdown

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