fix(server): offload cron job listing from dashboard event loop - #50979
Closed
PINKIIILQWQ wants to merge 1 commit into
Closed
fix(server): offload cron job listing from dashboard event loop#50979PINKIIILQWQ wants to merge 1 commit into
PINKIIILQWQ wants to merge 1 commit into
Conversation
Collaborator
Contributor
Author
|
Thanks for the triage — I missed #45491 and #50948. I'll close this PR as a duplicate of #45491. The only potentially useful extra here is the regression test that reproduces the event-loop starvation with slow synchronous cron/profile I/O; if helpful, I'm happy to port that test or leave the reproduction notes on #45491. Thanks for pointing me to the earlier PRs. |
Contributor
Author
|
Closing as duplicate of #45491. |
This was referenced Jul 30, 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.
Summary
GET /api/cron/jobsis an async dashboard endpoint, but it performs synchronous profile enumeration and per-profile cron file I/O directly on the event loop thread.If those filesystem operations become slow, the dashboard event loop is blocked for the duration of the sync call, starving other HTTP requests and WebSocket traffic.
This PR offloads only the synchronous cron/profile work to
asyncio.to_thread(...):_cron_profile_dicts()— profile enumeration_call_cron_for_profile(...)— per-profile cron module calls, for both the single-profile and all-profiles pathsThe handler shape, response format, profile parameter behavior, error handling, and per-profile sequential processing order are preserved.
Related Issue
Relates to #45072.
This addresses only the
/api/cron/jobsportion of the broader event-loop blocking issue.Type of Change
Changes Made
hermes_cli/web_server.py_cron_profile_dicts()and both_call_cron_for_profile(...)calls inlist_cron_jobs()withawait asyncio.to_thread(...).tests/hermes_cli/test_web_server_cron_profiles.pyHow to Test
Targeted tests:
Results:
tests/hermes_cli/test_web_server_cron_profiles.py: 9 passedtests/hermes_cli/test_web_server.py -k "cron": 6 passedtests/hermes_cli/test_cron*.py -q: 19 passedBroader filtered run (
pytest tests -q -k "cron or web_server") has pre-existingfailures on
origin/main, unrelated to this change:tests/cron/test_scheduler.py::test_all_token_case_insensitivetests/hermes_cli/test_web_server.py::TestPtyWebSocket(3 tests)The cron/event-loop tests added by this PR pass.
Regression Proof
Before this change, the slow-sync regression test failed: a concurrent 10ms
heartbeat received 0 ticks while
list_cron_jobs()was running with simulatedsynchronous I/O.
After this change, the heartbeat continues ticking while the cron/profile work
runs in the thread pool.
Checklist
Code
I've read the Contributing Guide
My commit message follows Conventional Commits (
fix(server): offload cron job listing from event loop)I searched for existing PRs to make sure this isn't a duplicate
My PR contains only changes related to this fix
I've run
pytest tests/ -qand all tests passNot checked: broader filtered runs have pre-existing failures on
origin/main, documented above.I've added tests for my changes
I've tested on my platform: macOS, Apple Silicon, Python 3.11.14
Documentation & Housekeeping