Skip to content

Conversation

@andrewnitu
Copy link

@andrewnitu andrewnitu commented Jan 23, 2026

Description

Implement the placeholder health check function.

Changes Made

  • Modify the health check function to return healthy when all of the below conditions are met:
    • inference executor is running
    • websocket with livekit server is open

Pre-Review Checklist

  • Build passes: All builds (lint, typecheck, tests) pass locally
  • AI-generated code reviewed: Removed unnecessary comments and ensured code quality
  • Changes explained: All changes are properly documented and justified above
  • Scope appropriate: All changes relate to the PR title, or explanations provided for why they're included
  • Video demo: A small video demo showing changes works as expected and did not break any existing functionality using Agent Playground (if applicable)

Testing

  • All tests pass
  • running node ./examples/src/basic_agent.ts dev locally
    • if livekit URL is wrong, it can't connect, so health check fails
    • if livekit URL is correct, health check passes
  • Make sure both restaurant_agent.ts and realtime_agent.ts work properly (for major changes)

Additional Notes


Note to reviewers: Please ensure the pre-review checklist is completed before starting your review.

Summary by CodeRabbit

  • New Features

    • Health endpoint now reports live system status with clear diagnostic messages.
    • Server accepts a pluggable health provider so root-status responses reflect actual runtime state.
    • Added a process liveness indicator that reflects runtime and connection health.
  • Refactor

    • Root status handling updated to use the new health provider and return accurate HTTP status codes.

✏️ Tip: You can customize this high-level summary in your review settings.

@changeset-bot
Copy link

changeset-bot bot commented Jan 23, 2026

⚠️ No Changeset found

Latest commit: f8b0605

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

@coderabbitai
Copy link

coderabbitai bot commented Jan 23, 2026

📝 Walkthrough

Walkthrough

Introduces a dynamic health check: new exported HealthCheckResult, HTTPServer constructor now accepts a healthCheckListener, root handler returns 200/503 based on health, adds isAlive getter to SupervisedProc, and worker passes a health function that checks inference process and LiveKit connection. (≤50 words)

Changes

Cohort / File(s) Summary
HTTP Server API Enhancement
agents/src/http_server.ts
Added export interface HealthCheckResult { healthy: boolean; message: string }. Changed HTTPServer constructor signature to accept healthCheckListener: () => HealthCheckResult before workerListener. Root / handler now uses health result to return 200 or 503 with the message.
Process Monitoring
agents/src/ipc/supervised_proc.ts
Added public getter get isAlive(): boolean that returns true when the process started, not closing, and its IPC channel is connected.
Worker Health Check Implementation
agents/src/worker.ts
Replaced static health payload with a dynamic health() passed to HTTPServer. health() checks: if inference executor missing or not alive → { healthy: false, message: 'inference process not running' }; if not connected to LiveKit → { healthy: false, message: 'not connected to livekit' }; else { healthy: true, message: 'OK' }.

Sequence Diagram(s)

sequenceDiagram
  participant Client as Client
  rect rgba(200,220,255,0.5)
    participant HTTP as HTTPServer
  end
  rect rgba(200,255,200,0.5)
    participant Proc as InferenceProc (SupervisedProc)
    participant LK as LiveKitConnector
  end

  Client->>HTTP: GET /
  HTTP->>HTTP: invoke healthCheckListener()
  HTTP->>Proc: check isAlive
  Proc-->>HTTP: isAlive (true/false)
  HTTP->>LK: check connection state
  LK-->>HTTP: connected (true/false)
  alt healthy
    HTTP-->>Client: 200 OK + message
  else unhealthy
    HTTP-->>Client: 503 Service Unavailable + message
  end
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Poem

🐰 I peeked at processes, ears all perked and bright,
Pondered LiveKit whispers in the quiet night,
If the proc is hopping and the session's near,
I'll chirp "OK!" — else thump a gentle fear.
🥕✨

🚥 Pre-merge checks | ✅ 3
✅ Passed checks (3 passed)
Check name Status Explanation
Description check ✅ Passed The description includes main sections (Description, Changes Made, Pre-Review Checklist, Testing) with relevant details about the health check implementation and testing performed locally.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Title check ✅ Passed The title 'Fill out implementation for health check' directly and accurately describes the main change—implementing the health check function that was previously a placeholder.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing touches
  • 📝 Generate docstrings

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🤖 Fix all issues with AI agents
In `@agents/src/worker.ts`:
- Around line 351-354: The health check currently treats an existing `#session`
object as "connected" even if the WebSocket is closed; update the condition in
the health check to verify the socket's readyState (e.g., check that
this.#session exists and this.#session.readyState === WebSocket.OPEN or
readyState === 1) instead of solely checking !this.#session, keeping the
surrounding checks for this.#closed and this.#connecting intact (refer to the
fields `#session`, `#closed`, `#connecting` and the health-checking block in the
worker). Ensure you guard access to readyState by confirming this.#session is
truthy before reading it and use the WebSocket.OPEN constant (or numeric 1) so
closed/closing states are treated as unhealthy.
📜 Review details

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 15dd71b and 804162f.

📒 Files selected for processing (3)
  • agents/src/http_server.ts
  • agents/src/ipc/supervised_proc.ts
  • agents/src/worker.ts
🧰 Additional context used
📓 Path-based instructions (3)
**/*.{ts,tsx,js,jsx}

📄 CodeRabbit inference engine (.cursor/rules/agent-core.mdc)

Add SPDX-FileCopyrightText and SPDX-License-Identifier headers to all newly added files with '// SPDX-FileCopyrightText: 2025 LiveKit, Inc.' and '// SPDX-License-Identifier: Apache-2.0'

Files:

  • agents/src/ipc/supervised_proc.ts
  • agents/src/http_server.ts
  • agents/src/worker.ts
**/*.{ts,tsx}?(test|example|spec)

📄 CodeRabbit inference engine (.cursor/rules/agent-core.mdc)

When testing inference LLM, always use full model names from agents/src/inference/models.ts (e.g., 'openai/gpt-4o-mini' instead of 'gpt-4o-mini')

Files:

  • agents/src/ipc/supervised_proc.ts
  • agents/src/http_server.ts
  • agents/src/worker.ts
**/*.{ts,tsx}?(test|example)

📄 CodeRabbit inference engine (.cursor/rules/agent-core.mdc)

Initialize logger before using any LLM functionality with initializeLogger({ pretty: true }) from '@livekit/agents'

Files:

  • agents/src/ipc/supervised_proc.ts
  • agents/src/http_server.ts
  • agents/src/worker.ts
🧬 Code graph analysis (1)
agents/src/worker.ts (1)
agents/src/http_server.ts (1)
  • HTTPServer (20-76)
🔇 Additional comments (4)
agents/src/ipc/supervised_proc.ts (1)

62-64: LGTM!

The isAlive getter correctly combines the three essential conditions for determining process health: started, not closing, and IPC channel connected. The optional chaining with double negation ensures a proper boolean return.

agents/src/worker.ts (1)

358-365: LGTM!

The worker listener callback cleanly provides the required metadata with proper enum-to-string conversion for worker_type.

agents/src/http_server.ts (2)

7-10: LGTM!

Clean and minimal interface definition for health check results.


26-52: LGTM!

The constructor signature update and route handler logic correctly implement the dynamic health check mechanism. The 503 status for unhealthy states follows standard HTTP semantics for service availability.

✏️ Tip: You can disable this entire section by setting review_details to false in your review settings.

@andrewnitu andrewnitu changed the title health check implementation Fill out implementation for health check Jan 23, 2026
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.

2 participants