Repository navigation
feat(gateway_sessions): prioritize user commands over status polls in command queue (#680) - #685
Merged
GreenGrassBlueOcean merged 4 commits intoOct 10, 2026
Conversation
…methods, and refine tier classification (OpenWebNet-HA#680)
GreenGrassBlueOcean
force-pushed
the
feat/issue-680-command-priority
branch
from
October 10, 2026 09:24
569e64d to
44e04b1
Compare
|
Codecov Report✅ All modified and coverable lines are covered by tests. 📢 Thoughts on this report? Let us know! |
… and storage complexity
GreenGrassBlueOcean
merged commit Oct 10, 2026
ac602b4
into
OpenWebNet-HA:v2-phase1-architecture
16 checks passed
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.
What is the problem
User commands and background status requests previously shared a single FIFO
asyncio.QueueinCommandWorkerPool.send_buffer(custom_components/myhome/gateway_sessions.py).On busy installations, during reconnect discovery sweeps, or when the gateway experiences slow NACKs on unresponsive zones (#675), user-initiated actions (e.g. toggling a light, adjusting a shutter, changing climate setpoints) were queued behind dozens of telemetry and status polls. Even though
is_status_requestwas already tracked on command envelopes, the queue made no priority distinction, causing noticeable real-world latency for interactive user commands.Closes #680.
How it is solved
Multi-Tier Priority Storage (
_PriorityQueueStorage):CommandPriorityQueue, decomposing queued items into three priority tiers:_commands): High-priority user state mutations (is_status_request=False)._status): Lower-priority background telemetry and status polling (is_status_request=True)._others): Worker shutdown sentinels (Noneand custom termination tokens).__len__,__bool__,__iter__,__reversed__,__getitem__,__contains__,__eq__,append,appendleft,popleft,pop,remove,clear,copy,count, andindex. This preserves 100% backward compatibility for tests directly inspectinglist(handler.send_buffer._queue).Prioritized Backpressure & Deadlock-Free Cancellation (
CommandPriorityQueue):asyncio.Queue[Any].maxsize, waiting command putters take precedence over waiting status poll putters via head-of-line insertion inself._putters.BaseExceptionduringawait putter(in Python 3.8+,asyncio.CancelledErrorinherits fromBaseException, notException), cleanly removing cancelled putters fromself._puttersand preventing orphaned waiter futures.self._wakeup_next(self._putters)is immediately invoked, preventing downstream waiters from starving or deadlocking.Invariants Preserved:
#302).How it is tested
Dedicated Unit Tests (
tests/test_gateway_sessions.py):test_command_priority_queue_ordering: Verifies user commands dequeue ahead of queued status requests while preserving FIFO within each class.test_command_priority_queue_read_back_after_write: Confirms write commands execute before their subsequent status read-back.test_command_priority_queue_sentinels: ConfirmsNoneand custom sentinels dequeue strictly after all commands and status polls.test_command_priority_queue_full_backpressure: Confirms waiting command putters take precedence when capacity frees up.test_command_priority_queue_backpressure_cancellation: Proves cancelled waiting putters are cleanly removed from_putters.test_command_priority_queue_woken_putter_cancellation_unblocks_next: Proves a woken putter cancelled during wake does not deadlock the queue.test_command_priority_queue_storage_methods: Thorough verification of deque and sequence protocols.test_worker_sends_user_command_ahead_of_pending_status_polls: End-to-endsending_looptest proving user commands are dispatched first to the mock gateway session.Test Suite & Verification Results:
tests/test_gateway_sessions.py: 19 passed in 1.73s.test_gateway_sessions,test_blank_start,test_command_session_contract,test_issue_302,test_poll_health): 65 passed in 17.28s.gateway_sessions.py).custom_components,tests,scripts.scripts/verify_ha_standards.py): All 54 rules satisfied.scripts/sync_documentation.py --check): All documentation and references verified in sync.