Skip to content

Deploying feature/cli-liveness-tracking to production#14

Merged
yuxiang-wu merged 11 commits intomainfrom
dev
May 19, 2025
Merged

Deploying feature/cli-liveness-tracking to production#14
yuxiang-wu merged 11 commits intomainfrom
dev

Conversation

@yuxiang-wu
Copy link
Copy Markdown
Contributor

No description provided.

yuxiang-wu and others added 11 commits May 12, 2025 22:27
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
@yuxiang-wu yuxiang-wu merged commit 4fee3b1 into main May 19, 2025
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant