Skip to content

Conversation

harlan-zw
Copy link
Owner

@harlan-zw harlan-zw commented Jun 23, 2025

Whenever we run Lighthouse we run it in its own process, this is to allow it to fail gracefully without taking down the rest of the scans.

However, the management of these Lighthouse processes isn't exactly handled gracefully and may result in their being rogue Lighthouse processes.

This PR aims to solve that by adding a process management interface that hooks into the signals from the parent process, ensuring processes remain in sync.

We also implement safer and more granular messaging between the Lighthouse process and the parent process using a strict IPC format.

Resolves ENOENT errors when lighthouse subprocess fails by implementing:

- **Structured IPC Communication**: Replace file-based error detection with
  JSON message protocol for lighthouse subprocess communication
- **Custom Process Registry**: Functional lighthouse process manager with
  proper cleanup, monitoring, and global state management via globalThis
- **Enhanced Error Handling**: Categorize retryable vs non-retryable errors
  with intelligent retry logic for network/timeout issues
- **Comprehensive Monitoring**: Process stats API endpoint, stuck process
  detection, and graceful termination with SIGTERM/SIGKILL
- **Shared Utilities**: Extract message parsing and error categorization
  to reusable util functions with proper type exports

**Technical Improvements:**
- Factory function pattern with `createLighthouseProcessRegistry()`
- Consola logger integration for consistent user feedback
- GlobalThis state management for singleton registry
- Comprehensive test coverage (31 tests) for all functionality
- Clean architecture with proper separation of concerns

**API Changes:**
- Added `/api/process-stats` endpoint for monitoring
- Enhanced lighthouse task with structured message parsing
- Proper type exports via main types.ts file
Copy link

netlify bot commented Jun 23, 2025

Deploy Preview for unlighthouse-crux-api canceled.

Name Link
🔨 Latest commit 032e7f0
🔍 Latest deploy log https://app.netlify.com/projects/unlighthouse-crux-api/deploys/6858f403552425000868ac52

@harlan-zw harlan-zw changed the title fix: implement structured lighthouse process management fix: structured lighthouse process management Jun 23, 2025
@harlan-zw harlan-zw closed this Jun 23, 2025
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