You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Cancellation watcher polls the database every 100 ms per running task #22
For every running task, TaskManager._watch_cancellation() opens a new database session and polls the cancellation flag every 100 ms for the entire executor run. A single one-hour task therefore issues roughly 36,000 cancellation queries, each with a session acquire/release.
Environment
apflow 0.24.3 (main @ 479d578)
Evidence
src/apflow/core/execution/task_manager.py:1765-1798 — while not event.is_set(): await asyncio.sleep(0.1) then a new Session/AsyncSession and get_task_by_id
Impact
SQLite write contention and disk I/O on a laptop-class machine for the whole render.
Contributes to the session-expiry problem in a busy pool.
Proposed fix
Make the poll interval configurable and use adaptive backoff (e.g. 100 ms → 1 s → 5 s) for long runs.
Prefer a notification channel where available (in-process asyncio.Event, DB notification/LISTEN, or an explicit cancel_task() call that sets the event directly).
Reuse a dedicated lightweight session for cancellation checks instead of opening one per tick.
Acceptance criteria
An idle one-hour task issues O(1) cancellation queries per minute, not ~36,000.
Cancellation still takes effect within a documented bound (e.g. ≤ 2 s).
Tests cover the interval/backoff behavior.
Workaround
Pass a shared cancellation event and call cancel_task() in-process; the poller still runs, but nothing can be done from the caller side today.
Activity