fix(allocator): Fix VM startup race condition and organize logging#262
Merged
fix(allocator): Fix VM startup race condition and organize logging#262
Conversation
- Fix race condition in /vm_startup where client would miss CRD command if user submitted it before client called the endpoint. Now checks if CRD is already assigned before starting PostgreSQL LISTEN/NOTIFY. - Reorganize logging in database.py: - Use INFO for important business events (VM assignment, CRD received) - Use WARNING for expected conditions (VM not found) - Remove verbose DEBUG logs for routine operations - Fix line-too-long warnings - Update tests to match new behavior and add new test cases: - test_vm_startup_already_has_crd for race condition handling - test_vm_startup_vm_not_found for 404 case Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
- Reorganize logging in client service modules: - Use INFO for service startup and important events - Use WARNING for retryable failures - Remove verbose DEBUG logs for routine operations - Standardize log message format - Changes by file: - check_gpu.py: Remove verbose nvidia-smi output, streamline status logs - connect_crd.py: Remove debug logs for args and command, add success log - subscribe.py: Clean up retry logs, remove config dump - update_inuse_status.py: Remove process iteration debug logs - Update tests to match new log message formats Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
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
Fix a race condition in the
/vm_startupendpoint where VMs would miss their CRD command assignment, and reorganize logging throughout both allocator and client packages for better admin visibility.Changes
Fixed
/vm_startupendpoint (main.py:385-398) where clients would miss CRD commands if users submitted them before the client called the endpoint. Now checks if CRD is already assigned before starting PostgreSQL LISTEN/NOTIFY.Changed (Allocator)
database.py:"Failed to <action> for VM '<hostname>': {e}"insert_vm,assign_vm,update_vm_in_use, etc.)get_assigned_vms()now returns[]instead ofNoneon error for consistency withget_unassigned_vms()Changed (Client)
check_gpu.py: Removed verbose nvidia-smi output, streamlined status logsconnect_crd.py: Removed debug logs for args/command, added success logsubscribe.py: Cleaned up retry logs, removed config dumpupdate_inuse_status.py: Removed process iteration debug logsAdded
test_vm_startup_already_has_crd- tests race condition handling when CRD is pre-assignedtest_vm_startup_vm_not_found- tests 404 response when VM doesn't existTechnical Details
The race condition occurred when:
/api/request_vmat time T/vm_startupat time T+N (after startup delay)The fix adds a check before listening: if the VM already has
crdcommandandpinpopulated, return immediately with those values instead of waiting for a NOTIFY that will never come.Testing
test_database.py+test_api_calls.py)ruff check)Checklist
🤖 Generated with Claude Code