Skip to content

fix: set context.task for scheduler-run tasks so end-of-turn extensions fire#1777

Open
King0James0 wants to merge 1 commit into
agent0ai:mainfrom
King0James0:fix/scheduler-context-task
Open

fix: set context.task for scheduler-run tasks so end-of-turn extensions fire#1777
King0James0 wants to merge 1 commit into
agent0ai:mainfrom
King0James0:fix/scheduler-context-task

Conversation

@King0James0

Copy link
Copy Markdown

Fixes #1776.

The scheduler runs tasks by calling agent.monologue() directly, so context.task is never assigned for scheduler-run contexts — and agent.py gates both message_loop_end and monologue_end extension dispatch on context.task and context.task.is_alive(). Net effect: no end-of-turn extensions (including the built-in _memory memorize extensions) ever fire for a Scheduled/AdHoc/Planned task.

The scheduler already wraps each run in its own DeferredTask (registered in _running_deferred_tasks before the wrapper starts); this assigns it to context.task right after the run's context is resolved — the same contract the normal chat path establishes via run_task(). 4-line diff in _run_task_wrapper.

Effects:

  • message_loop_end / monologue_end now dispatch for scheduler runs, so memorization and extension-based plugins see scheduled work. A killed run still correctly skips them — killing the task makes is_alive() false, so the post-mortem guard's intent is preserved.
  • context.is_running() is now truthful for scheduler-run contexts.
  • A user message sent to a task context mid-run routes as an intervention (like a normal chat) instead of spawning a second concurrent monologue on the same context.

The if not (context.task and context.task.is_alive()) guard leaves the context untouched in the edge case where a live task already exists on it (e.g. a user actively chatting in the task context when the run starts).

Verified on a v2.4 container: stock = a probe extension on monologue_end never fires for an ad-hoc scheduler run (while a normal chat turn fires it); patched = the same run fires message_loop_end + monologue_end with the task's context id within seconds, and a killed run fires neither.

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.

Scheduler-run tasks never fire message_loop_end / monologue_end extensions (context.task is never set)

1 participant