Skip to content

feat: Add worker health check and auto-restart logic#119

Open
vominh1919 wants to merge 1 commit into
PrimeIntellect-ai:mainfrom
vominh1919:fix/worker-crash-recovery
Open

feat: Add worker health check and auto-restart logic#119
vominh1919 wants to merge 1 commit into
PrimeIntellect-ai:mainfrom
vominh1919:fix/worker-crash-recovery

Conversation

@vominh1919

Copy link
Copy Markdown

Fixes #41

Problem

If the validation engine worker thread crashes (e.g., due to a key error or OOM), there was no recovery mechanism. The engine would fail permanently.

Solution

  • Add _is_worker_alive() method to check if worker process is still running
  • Add _restart_worker() method to cleanly restart crashed workers:
    • Terminates old worker process
    • Clears input queue of stale items
    • Fails pending validations with CRASHED status
    • Starts new worker process
  • Add _restart_lock to prevent concurrent restart attempts
  • Add _pending_validations dict to track in-flight validations
  • Update validate_entries() and validate_grouped_entries() to:
    • Check worker health before starting validation
    • Monitor worker health while waiting (5-second intervals)
    • Handle worker crashes gracefully with CRASHED status

Testing

The changes are backwards compatible and maintain the existing API.

Fixes PrimeIntellect-ai#41

- Add _is_worker_alive() method to check if worker process is still running
- Add _restart_worker() method to cleanly restart crashed workers
  - Terminates old worker process
  - Clears input queue of stale items
  - Fails pending validations with CRASHED status
  - Starts new worker process
- Add _restart_lock to prevent concurrent restart attempts
- Add _pending_validations dict to track in-flight validations
- Update validate_entries() to:
  - Check worker health before starting validation
  - Monitor worker health while waiting (5s intervals)
  - Handle worker crashes gracefully
- Update validate_grouped_entries() with same worker health monitoring
- Add logging for worker PID on startup
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.

Recover from validation engine worker thread crash

1 participant