Simplify ServiceBusConsumer supervisor: remove double-loop, fix version, revert logging scope creep#4884
Merged
marrobi merged 2 commits intoMar 11, 2026
Conversation
…ert logging, move heartbeat, simplify tests Co-authored-by: marrobi <17089773+marrobi@users.noreply.github.com>
Copilot
AI
changed the title
[WIP] Remove _receive_messages_loop method and simplify supervision
Simplify ServiceBusConsumer supervisor: remove double-loop, fix version, revert logging scope creep
Mar 10, 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.
The initial service bus monitoring implementation had two nested restart mechanisms (
_receive_messages_loop+supervisor_with_heartbeat_check), an incorrect version bump, unrelated logging format changes, and heartbeat updates placed at the wrong point in the polling loop.What is being addressed
_receive_messages_loop+ supervisor created redundant, overlapping restart logic — the inner loop'swhile Truemeant the supervisor's task-done detection rarely triggered0.25.14→0.26.1, skipping0.26.0— this is a patch fix, not a minor releaseWorkerIdFilter,LOG_FORMAT, andapply_worker_id_to_loggerinservices/logging.pywere unrelated scope creep changing log format globallyupdate_heartbeat()was called at the top of each polling iteration, so a hang during message processing wouldn't be detected until after the next poll startedHow is this addressed
_receive_messages_loop: supervisor now creates tasks directly fromself.receive_messages()and owns all backoff/restart logic. Atask_just_startedflag ensures backoff resets only after the task has survived a full heartbeat cycle — not immediately on creation (which would have silently broken exponential backoff):0.26.1→0.25.15services/logging.pyto main branch state — removesimport os,LOG_FORMAT,WorkerIdFilter,apply_worker_id_to_logger, and the handler/filter setup ininitialize_logging()update_heartbeat()to the end of the try block in both consumers, so heartbeat reflects a completed polling cycle rather than a started one_receive_messages_looptests, backoff is now exercised through the supervisor, consolidated duplicates between the two test filesOriginal prompt
Apply the following review changes to the existing code on the
copilot/fix-4464branch:1. Remove
_receive_messages_loop— simplify to single supervisor layerIn
api_app/service_bus/service_bus_consumer.py, remove the_receive_messages_loop()method entirely. The supervisor (supervisor_with_heartbeat_check) should create tasks directly fromself.receive_messages()instead of fromself._receive_messages_loop(). The supervisor itself handles backoff on task failure. Here's the simplified approach:2. Fix the version number
In
api_app/_version.py, change the version from"0.26.1"to"0.25.15". The original version was0.25.14and this is a bug fix, so it should be a patch increment.3. Revert logging format changes (scope creep)
In
api_app/services/logging.py, revert ALL changes introduced by this PR. Specifically:import osadditionLOG_FORMATconstantWorkerIdFilterclassapply_worker_id_to_loggerfunctioninitialize_logging()to its original form — remove thelog_format=LOG_FORMATparameter fromLoggingInstrumentor().instrument(), remove the "Set up a handler if none exists" block, and remove the "Apply worker ID filter" call.The file should be restored to its state on the
mainbranch. The logging format changes are unrelated to the service bus monitoring fix.4. Move
update_heartbeat()to end of loop iteration in both consumersIn
api_app/service_bus/deployment_status_updater.pyandapi_app/service_bus/airlock_request_status_update.py:self.update_heartbeat()call from the top of the try block inside the while loop to the bottom of the try block (end of each successful iteration), so that heartbeat reflects "I just completed a polling cycle" rather than "I just started one". This ensures hangs during message processing are detected.5. Simplify tests to match simplified supervisor
Update `api_app/tests_ma/test_servic...
This pull request was created from Copilot chat.
💡 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.