Skip to content

fix(connector): forward stop_requested parameter from run_loop to _run_loop - #2544

Merged
abrichr merged 1 commit into
mainfrom
gemini/fix-main-daemon-ruff
Nov 22, 2026
Merged

abrichr merged 1 commit into
mainfrom
gemini/fix-main-daemon-ruff

Conversation

@abrichr

@abrichr abrichr commented Nov 22, 2026

Copy link
Copy Markdown
Member

Summary

Urgent main CI hotfix: restores packages / flow core lint (ruff, mypy) across all PRs.

Root Cause

When #2300 split run_loop(...) into run_loop(...) + _run_loop(...) for _stop_signals_interrupt(), run_loop(...) accepted stop_requested: Optional[threading.Event] = None (passed by windows_service.py:285), but did not forward stop_requested into _run_loop(...) or declare it on _run_loop's signature. As a result, line 455 (retry_stop = stop_requested if stop_requested is not None else stop) triggered two Ruff F821 undefined-name errors and would raise NameError at runtime when once=False.

Fix

  • Forward stop_requested=stop_requested from run_loop() to _run_loop() and add stop_requested: Optional[threading.Event] = None to _run_loop() in packages/flow/openadapt_flow/connector/daemon.py (+2 lines).

Verification

  • ruff check openadapt_flow/connector — passed
  • ruff format --check openadapt_flow/connector/daemon.py — passed
  • mypy openadapt_flow/connector/daemon.py — 0 issues
  • pytest -q tests/test_connector*.py — 211 passed, 81 subtests passed

Generality & Durability

  1. No per-app code in the engine: Yes — connector daemon lifecycle wiring only.
  2. Fix the class, not the instance: Yes — completes the run_loop -> _run_loop parameter forwarding so every caller (including windows_service.py) gets cooperative stop signaling.
  3. Held-out evidence: Not applicable — parameter-forwarding bug fix verified by the full 211-test connector suite.

@abrichr

abrichr commented Nov 22, 2026

Copy link
Copy Markdown
Member Author

Independent adversarial review: APPROVE

From: Grok
Reviewed-Head: 29ee8ac

Review only. I am not merging this hotfix.

The unique diff vs current main (c71d463de7821b898eb5367803ce5b45947ec7c6) is the two lines claimed: run_loop now forwards stop_requested=stop_requested into _run_loop, and _run_loop declares stop_requested: Optional[threading.Event] = None. That is the name _run_loop already reads at retry_stop = stop_requested if stop_requested is not None else stop (now line 457). On main that read is an F821 / runtime NameError whenever once=False.

This matches the Windows service caller, which already passes stop_requested=stop_event into run_loop. When that event is set, the poll loop exits, and the existing finally: stop.set() still stops the heartbeat thread and drains jobs. Callers that omit the argument keep the previous behavior (retry_stop is the local stop event). No app-specific engine change.

This is the straightforward fix for the #2300 split. I did not find a remaining unbound use of stop_requested.

Nit, not blocking this hotfix: there is still no regression test that run_loop(..., once=False, stop_requested=event) actually forwards the event and exits without a NameError. The existing connector tests did not catch the #2300 miss. Worth adding in a follow-up.

I approve this head. I am not merging it.

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