fix: set context.task for scheduler-run tasks so end-of-turn extensions fire#1777
Open
King0James0 wants to merge 1 commit into
Open
fix: set context.task for scheduler-run tasks so end-of-turn extensions fire#1777King0James0 wants to merge 1 commit into
King0James0 wants to merge 1 commit into
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #1776.
The scheduler runs tasks by calling
agent.monologue()directly, socontext.taskis never assigned for scheduler-run contexts — andagent.pygates bothmessage_loop_endandmonologue_endextension dispatch oncontext.task and context.task.is_alive(). Net effect: no end-of-turn extensions (including the built-in_memorymemorize extensions) ever fire for a Scheduled/AdHoc/Planned task.The scheduler already wraps each run in its own
DeferredTask(registered in_running_deferred_tasksbefore the wrapper starts); this assigns it tocontext.taskright after the run's context is resolved — the same contract the normal chat path establishes viarun_task(). 4-line diff in_run_task_wrapper.Effects:
message_loop_end/monologue_endnow dispatch for scheduler runs, so memorization and extension-based plugins see scheduled work. A killed run still correctly skips them — killing the task makesis_alive()false, so the post-mortem guard's intent is preserved.context.is_running()is now truthful for scheduler-run contexts.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_endnever fires for an ad-hoc scheduler run (while a normal chat turn fires it); patched = the same run firesmessage_loop_end+monologue_endwith the task's context id within seconds, and a killed run fires neither.