Fix duration enforcement, JSON payload encoding, and error handling in workers#1
Draft
Fix duration enforcement, JSON payload encoding, and error handling in workers#1
Conversation
Co-authored-by: KidiXDev <100352770+KidiXDev@users.noreply.github.com>
Copilot
AI
changed the title
[WIP] Fix timer not stopping after set duration
Fix duration enforcement, JSON payload encoding, and error handling in workers
Mar 13, 2026
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.
Workers continued running past the configured duration because in-flight requests were awaited (not cancelled) at the deadline. Additionally,
--jsonalways crashed at runtime due to a broken.encode()call on a parsed dict, and worker crashes silently hung the parent process forever.Root causes & fixes
Timer not enforced: After the scheduler deadline,
asyncio.gather(*pending)waited for all in-flight requests — up totimeoutseconds pastduration. Fixed by cancelling all pending tasks before gathering:--jsonalways crashed:json.loads(args.json).encode()called.encode()on adict, raisingAttributeError. Fixed withjsonlib.dumps(jsonlib.loads(args.json)).encode()— validates then re-serialises to bytes.Unbounded catch-up burst: When the event loop stalled briefly,
next_fire += intervalwithout a bound caused a burst of accumulated missed requests. Capped by resettingnext_fire = now + intervalwhen it falls more than one interval behind.Worker crash hangs parent: An unhandled exception in
bootstrap_workerexited the process without putting anything in the queue, leavingq.get()blocked forever. Added a top-levelexcept Exceptioninbootstrap_workerthat always enqueues an error sentinel.q.get()had no timeout: Added a generous timeout (duration + request_timeout + 60 s) with aqueue.Emptywarning, preventing indefinite hangs even if the sentinel is somehow missed.No
KeyboardInterrupthandling: Ctrl+C left daemon processes running and printed no report. Wrapped the collection loop to catch interrupts, terminate workers cleanly, and still emit a partial report if data was collected.💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.