Deploying feature/cli-liveness-tracking to production#14
Merged
yuxiang-wu merged 11 commits intomainfrom May 19, 2025
Merged
Conversation
Introduces mechanisms for the CLI to signal its liveness to the backend and report its termination reason, ensuring more robust state management.
- Adds a background heartbeat thread (`HeartbeatSender`) that periodically sends PUT requests to `/api/sessions/{session_id}/heartbeat` every 30 seconds during an active run via the new `send_heartbeat` API function. Heartbeat failures are logged but non-fatal.
- Implements signal handlers for SIGINT and SIGTERM to gracefully stop the heartbeat thread and report termination due to user interruption via a new `report_termination` API function and endpoint (`/terminate`).
- Wraps the main optimization loop in a `try...except...finally` block:
- Catches runtime errors during the optimization loop.
- Ensures the heartbeat thread is stopped on exit (normal completion, error, or signal).
- Calls `report_termination` in the `finally` block to inform the backend of the final status (completed or error), unless already reported by the signal handler.
- Improves error handling for existing API calls (`start_optimization_session`, `evaluate_feedback_then_suggest_next_solution`) to be more specific and prevent unexpected exits.
using the rich Console's print method instead of print with sys.stderr to maintain consistent output styling across the CLI. Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
…ination The HeartbeatSender thread was intermittently dying silently, leading to the backend not receiving heartbeats and prematurely marking the CLI session as errored. This commit addresses the issue by: 1. Replacing Rich `console.print` calls within the `HeartbeatSender.run()` method with standard Python `print(..., file=sys.stderr)`. This mitigates potential intermittent exceptions when using Rich `Console` methods from a background thread, which was identified as the likely primary cause of the silent thread crashes. 2. Wrapping the main loop within `HeartbeatSender.run()` with a `try...except Exception...finally` block. This ensures that any other unexpected exceptions are caught, logged with a traceback to `stderr`, and allow the thread to terminate gracefully rather than silently. 3. Ensuring a log message is printed to `stderr` when the thread starts and when it is stopping (in the `finally` block). These changes make the heartbeat mechanism more resilient and improve debuggability by ensuring that thread failures are logged.
Dynamically load package version in weco/__init__.py from pyproject.toml using importlib.metadata. This removes the need to maintain the version number in multiple locations, making version bumps simpler and less error-prone.
…cli.py to streamline error handling by removing redundant try-except blocks, enhancing code clarity and maintainability.
feat: Implement CLI Liveness Tracking and Sync with Dev
…te check from 1 to 2 seconds for improved user experience
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.
No description provided.