Skip to content

fix: stop status polling from cancelling running scheduled tasks - #5789

Merged
alteixeira20 merged 2 commits into
odysseus-dev:devfrom
Christian-Sidak:fix/issue-5782
Aug 14, 2026
Merged

alteixeira20 merged 2 commits into
odysseus-dev:devfrom
Christian-Sidak:fix/issue-5782

Conversation

@Christian-Sidak

@Christian-Sidak Christian-Sidak commented Jul 28, 2026 •

Copy link
Copy Markdown
Contributor

Linked Issue

Fixes #5782

Type of Change

  • Bug fix (non-breaking change that fixes an issue)

Summary

Two paths caused the scheduler to cancel a running background task the moment the frontend Activity view polled for status.

Bug 1: GET /api/tasks/runs/recent was not in _PASSIVE_EXACT_PATHS in src/interactive_gate.py. The _InteractiveActivityMiddleware treated it as a foreground request and called stop_background_tasks_for_foreground, cancelling any in-flight task immediately. Added it to _PASSIVE_EXACT_PATHS alongside the other read-only polling endpoints.

Bug 2: The /api/activity/heartbeat handler called stop_background_tasks_for_foreground unconditionally, ignoring BACKGROUND_TASK_FOREGROUND_GATE=false. The call is now guarded by _gate_enabled().

Both issues combined to produce the log pattern from the issue:

[agent-timing] round_start round=1 ...
Stopped 2 background scheduler task(s): foreground request GET /api/tasks/runs/recent

Checklist

  • I searched existing open issues and PRs and did not find a duplicate.

How to Test

  1. Start a scheduled LLM task (e.g. an email-reading task with Ollama).
  2. While the task is running (after Starting... appears in the Activity view), open or refresh the Activity view so it polls GET /api/tasks/runs/recent.
  3. Before this fix, the task would be immediately cancelled with "Stopped 2 background scheduler task(s): foreground request GET /api/tasks/runs/recent" in the logs. After the fix, the task continues to run.

Unit-level: python -c "import src.interactive_gate as ig; assert not ig.should_track_interactive_request('/api/tasks/runs/recent', 'GET'); print('OK')"

@github-actions github-actions Bot added needs work PR description incomplete — please update before review ready for review Description complete — ready for maintainer review and removed needs work PR description incomplete — please update before review labels Jul 28, 2026
@Christian-Sidak

Copy link
Copy Markdown
Contributor Author

Friendly bump -- let me know if anything needs changing.

@Christian-Sidak

Copy link
Copy Markdown
Contributor Author

Friendly bump -- let me know if anything needs changing.

Christian-Sidak and others added 2 commits August 14, 2026 10:30
…tasks

Two paths caused the scheduler to interrupt a running background task
when the frontend Activity view polled for status:

1. GET /api/tasks/runs/recent was not in _PASSIVE_EXACT_PATHS, so
   _InteractiveActivityMiddleware treated it as a foreground request
   and called stop_background_tasks_for_foreground, cancelling any
   in-flight scheduled task. Add it to _PASSIVE_EXACT_PATHS alongside
   the other read-only polling endpoints.

2. The /api/activity/heartbeat handler called
   stop_background_tasks_for_foreground unconditionally, ignoring
   BACKGROUND_TASK_FOREGROUND_GATE=false. Wrap the call in a
   _gate_enabled() guard so the env var fully disables heartbeat-
   triggered cancellations.

Fixes odysseus-dev#5782

Signed-off-by: Christian Sidak <[email protected]>
Signed-off-by: Christian-Sidak <[email protected]>

@alteixeira20 alteixeira20 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewed and updated against current dev. The task-status polling endpoint is now correctly classified as passive, the browser heartbeat respects BACKGROUND_TASK_FOREGROUND_GATE, the heartbeat policy has direct behavioral regression coverage, and the updated CI/security suite is green.

@alteixeira20
alteixeira20 merged commit b2789d0 into odysseus-dev:dev Aug 14, 2026
3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ready for review Description complete — ready for maintainer review

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Scheduled tasks are interrupted by /api/tasks/runs/recent polling and remain stuck at "Starting..."

2 participants