Repository navigation
fix(runtime): create background job tasks on the loop thread - #4
Merged
Merged
Conversation
post_tool_call runs on a worker thread, so _schedule_background_job_poll and _schedule_background_job_cleanup called loop.create_task off-loop: the task sat in _ready without waking the selector, and asyncio debug mode raised RuntimeError. Both now go through schedule_task_on_loop, which hops to the loop with call_soon_threadsafe; the poll dedupe check moved into the loop-side callback. Regression tests drive a real debug-mode loop on its own thread; all three fail on 875a561 with the non-thread-safe RuntimeError.
…allback The loop-side _start callback races the started render, so the job record often does not exist yet and poll_task stayed empty for the poll lifetime (3/40 and 1/40 in review probes). _poll now claims its own task once the record exists. Regression assert: poll_task is set while the job is still running; it fails with this block removed.
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.
ZHA-2358.
post_tool_callruns on a worker thread, so_schedule_background_job_polland_schedule_background_job_cleanupcalledloop.create_taskoff the loop thread: the task sat in_readywithout waking the selector (poll deferred until an unrelated wakeup) and asyncio debug mode raisedRuntimeError: Non-thread-safe operation invoked on an event loop other than the current one.utils/scheduling.py: newschedule_task_on_loop(loop, start)runsstartinline when already on the loop, otherwise hands it toloop.call_soon_threadsafe;on_loop_threadis now the shared thread check (clarify._on_loopremoved).runtime/tool_events.py: both background-job schedulers use it; thepoll_taskdedupe check and claim moved into the loop-side callback so the guard stays single-threaded.delivery.schedule_delayed_live_flush,delivery.schedule_auto_delete,renderer._schedule_delegate_cleanupand the clarify bridges only run inside coroutines already on the loop (reachable throughsubmit_or_close/run_coroutine_threadsafe), so they keep the plaincreate_task_or_close._on_post_tool_calldriven from a foreign thread. All three fail on875a561with the non-thread-safeRuntimeError.