could you explain me the difference b/w livekit_wo...
# ask-ai
s
could you explain me the difference b/w livekit_worker dev and livekit_worker start
t
Thanks — I’m responding to your question about the difference between
livekit_worker dev
and
livekit_worker start
. Short answer •
dev
is for development and testing: it runs the worker in a development mode so the agent can connect to LiveKit for interactive testing and debugging (joins real rooms and is reachable from the internet for test calls). •
start
is for production: it runs the worker as a production agent to handle live jobs at scale. What each mode is typically used for • dev ◦ Use while building or debugging an agent. ◦ Enables quick iterative testing with real rooms/calls. ◦ Useful when you want the agent to be reachable for interactive testing from your development environment. • start ◦ Use when deploying the agent to handle live traffic. ◦ Intended for stable, long-running production operation. Why you’d pick one vs the other • Pick
dev
when you need rapid feedback, live debugging, or are validating behavior with real calls. • Pick
start
when you want the agent to run reliably in production and process tasks/jobs at scale. If you want, I can: • Show the exact differences in configuration or environment variables commonly used for each mode. • Suggest best practices for moving from
dev
to
start
(prewarming models, logging, instance types). Which would you like next? Sources: Voice AI quickstart | LiveKit Documentation | Simple Call Answering Agent | LiveKit Documentation | Build a multilingual voice agent that automatically switches languages | Li...
s
in start mode can we add all the debug logs
t
Thanks — I’m responding to your question about enabling debug logs while running the worker in
start
(production) mode. Yes — you can enable debug-level logging in
start
mode. Use the
--log-level
option to set the desired verbosity. For example:
Copy code
uv run agent.py start --log-level=DEBUG
Notes and best practices • Debug increases log volume and may include sensitive or high-frequency internal details. Use it temporarily for diagnostics rather than permanently in production. • If you’re running a Node.js agent, the equivalent would be your package run command (for example:
pnpm run start --log-level=debug
). • Combine debug logging with log rotation, centralized log collection (CloudWatch/Stackdriver/Datadog/etc.), and retention limits so you don’t exhaust disk or logging quotas. • When debugging startup timeouts (like the
proc.initialize()
TimeoutError you reported earlier), enable debug for a short window, reproduce the issue, and capture timestamps around the initialization steps to pinpoint the slow operation. If you want, I can: • Provide the exact command for your runtime (Python vs Node) or containerized deployment. • Suggest a minimal set of additional logs/timers to add around
initialize()
to identify where time is spent. Which environment are you running in? Sources: Server options | LiveKit Documentation
s
can you tell me the exact difference b/w dev and start like performance wise
t
Thanks — I’m responding to your request for the exact, performance-focused differences between
dev
and
start
(and whether you can enable debug logs in
start
). Short summary • Functionally both modes run the same agent code and use the same runtime; there is no inherent difference in core execution performance. • Differences that can affect observed performance are related to developer conveniences in
dev
(hot reload, rich logs) and production optimizations in
start
(stable operation, production-optimized logging). • You can enable debug logs in
start
using
--log-level=DEBUG
, but do so only temporarily because it increases log volume and I/O. Detailed points — what changes performance or behavior • Logging format and overhead ◦ dev: Human-friendly, colored, pretty logs. Slight CPU cost to format and print colorized output. Negligible for normal use, can be noticeable under very high throughput. ◦ start: Raw/structured logs (JSON) optimized for ingestion by logging systems. Slightly lower overhead and better for high-scale environments. • Hot reloading / file watching ◦ dev: Watches source files and restarts the process on changes. File watchers consume CPU and I/O while active; this can add small overhead and can trigger restarts during development. ◦ start: No hot reload. Avoids that overhead and prevents unintended restarts, improving stability in production. • Runtime behavior / resource usage ◦ Core runtime (task scheduling, model inference, network calls) is the same between modes. Any significant performance differences you see are most likely due to: ▪︎ Extra work from file watchers or pretty-print logging in dev. ▪︎ Different runtime configuration or environment (for example different instance size, CPU type, container limits) when you deploy start mode. ◦ In short: mode itself doesn’t change inference speed or networking; environment and configuration do. • Production readiness ◦ start is intended for production: stable long-running processes, structured logs, and no development conveniences that could interfere with reliability. ◦ dev is intended for iteration, testing, and debugging. Enabling debug logs in start • Command example (Python agent): ◦ uv run agent.py start --log-level=DEBUG • Node or package commands vary (e.g., pnpm/npm run start --log-level=debug). • Caveats: DEBUG increases log volume and I/O. Use it for short diagnostic windows, combine with log rotation and centralized collection to avoid disk or quota exhaustion. Performance recommendations when moving from dev → start • Prewarm heavy resources (models, VAD) at agent startup so per-job initialize time is minimized. • Run on non-burstable instances (e.g., c5/m5) to avoid CPU throttling that can cause long initialization times. • Disable hot reload and pretty console output in production (use start mode). • Instrument
initialize()
with timestamps and temporary DEBUG logs to find slow steps, then disable DEBUG once you’ve captured the data. • Stagger worker startups if you provision many at once to reduce resource contention. If you want, I can: • Give the exact command for your runtime/environment (Python vs Node/container). • Provide a small logging/timing snippet to add around
proc.initialize()
so you can identify which step is exceeding the timeout. Which runtime are you using and where is this deployed (local, Docker, AWS EC2, Kubernetes)? Sources: Voice AI quickstart | LiveKit Documentation | Server options | LiveKit Documentation | Simple Content Filter | LiveKit Documentation | Troubleshooting Latency and Timeout Errors with Turn Detection on AWS | Agents Framework | livekit/livekit_composite | DeepWiki
s
I want to set probes for livekit worker. on /health route which probe makes more sense liveness probe or readyness probe
t
Thanks — I’m responding to your question about which Kubernetes probe to use on the LiveKit worker’s
/health
route. Short answer • Use
/health
as a readiness probe. It should indicate whether the worker is fully initialized, connected to the LiveKit server, and ready to accept jobs. • Reserve a liveness probe for checks that detect a truly unhealthy or stuck process that should be restarted. Why readiness is the better fit • Readiness tells the scheduler whether the worker should receive traffic (job assignments). A LiveKit worker must complete startup steps (connect/register with LiveKit, prewarm models, open sockets) before it can handle jobs;
/health
should reflect that readiness. • If a worker temporarily cannot reach LiveKit (transient network blip or during startup), marking it Not Ready prevents new jobs from being dispatched without forcing a restart—this preserves in-flight state and is less disruptive. • Liveness probes cause container restarts when they fail. Using
/health
as a liveness check risks unnecessary restarts for transient conditions that are recoverable. When to also use a liveness probe • Add a separate liveness check only if you can reliably detect unrecoverable failure modes (deadlock, crashed event loop, or unrecoverable resource exhaustion). • Liveness checks should avoid firing on transient errors; they should validate that the process is alive and responsive at a deeper level (for example, a simple internal heartbeat or event-loop responsiveness check). Practical recommendations 1. Readiness probe (use
/health
): ◦ Path:
/health
◦ What it should verify: ▪︎ Worker has successfully connected/registered with LiveKit. ▪︎ Any required prewarm steps (models, VAD) completed. ▪︎ Worker is able to accept jobs. ◦ Kubernetes example: ▪︎ initialDelaySeconds: allow time for startup/prewarm ▪︎ periodSeconds: moderate frequency (e.g., 10s) 1. Liveness probe (optional, separate endpoint): ◦ Path:
/live
or
/internal/liveness
◦ What it should verify: ▪︎ Process responsiveness (e.g., event loop responding, thread liveliness). ▪︎ Not a simple external connectivity check. ◦ Use conservative thresholds so only true deadlocks/crashes trigger restarts. 1. Timing guidance: ◦ Give the readiness probe a generous initialDelaySeconds if you prewarm large models. ◦ Keep readiness checks frequent enough to remove unhealthy instances quickly but avoid overloading the worker with checks. 1. Logging and metrics: ◦ Emit metrics/events when readiness flips so you can correlate with job failures. ◦ Capture timestamps for prewarm/initialize so readiness timing is observable. If you’d like, I can: • Suggest exact Kubernetes probe YAML values (initialDelaySeconds, timeoutSeconds, periodSeconds, failureThreshold) tuned to your startup profile. • Provide a minimal readiness endpoint example that checks connection to LiveKit and prewarm completion. Which environment are you deploying to and how long do your worker startups typically take? Sources: Self-hosted deployments | LiveKit Documentation
s
what about startup probe and how can i set liveness probe like is there some other better ways to check like agent crashed bcz it need a database connection or something like that how can do that
t
Thanks — I’m responding to your question about using a startup probe and how to implement robust liveness checks (including dependency checks like DB connectivity) for a LiveKit worker. High-level guidance — roles of the three probes • Startup probe ◦ Use this when the process takes a long time to become runnable (heavy prewarming, model loads). ◦ Kubernetes will wait for the startup probe to succeed before running liveness/readiness checks. This prevents premature restarts while the agent is still initializing. • Readiness probe ◦ Indicates the worker is fully initialized and ready to accept jobs (connected/registered with LiveKit, prewarm complete). ◦ Should prevent job routing to instances that are still starting or temporarily unable to accept jobs. • Liveness probe ◦ Detects unrecoverable failures and triggers a restart when the process is stuck or dead. ◦ Should not be used to probe transient external dependencies (like temporary DB or network blips) unless a missing dependency truly means the process is in an unrecoverable state. When to use startup probe for LiveKit worker • If your worker needs significant time to: ◦ Load large ML models or weights ◦ Download artifacts over the network ◦ Perform expensive prewarm steps • Then add a startup probe with a generous timeout and interval so Kubernetes doesn’t restart the container while it’s still warming up. Designing robust liveness checks (beyond a simple HTTP ping) • Keep liveness check focused on process health and recoverability. Good signals include: ◦ Event loop responsiveness (able to respond to a simple internal request within X ms) ◦ Presence of essential background threads/processes ◦ Recent successful heartbeats with internal subsystems (not external transient services) • For dependency failures (DB, external services), decide if failure is: ◦ Transient/expected: treat via readiness (mark NotReady, do not restart). ◦ Unrecoverable (e.g., required DB schema missing, persistent auth failure): treat as liveness failure (restart). Practical strategy for LiveKit worker • /startup (or reuse /health with startup probe) ◦ Checks: process started, prewarm finished (models loaded), required local resources available. • /health or /ready (readiness) ◦ Checks: connection to LiveKit server established/registered, prewarm complete, worker can accept jobs. ◦ If LiveKit connection drops, return NotReady (HTTP 503) so scheduler stops sending new jobs; do not restart. • /live (liveness) ◦ Checks: event loop responding, worker thread(s) alive, memory/CPU not in unrecoverable state. ◦ Do NOT check transient external services here. If you do check DB, only fail liveness if the DB problem is known to be unrecoverable and a restart would help. Example endpoints (conceptual; adapt to your language/runtime) 1) Readiness endpoint (checks LiveKit connected + prewarm done)
Copy code
# pseudocode
@app.get("/ready")
def readiness():
    if not prewarm_completed:
        return Response(status_code=503)
    if not livekit_client.is_connected():
        return Response(status_code=503)
    return Response(status_code=200)
2) Liveness endpoint (checks event-loop / internal heartbeat)
Copy code
# pseudocode
@app.get("/live")
def liveness():
    if not internal_heartbeat_recent():   # e.g., last heartbeat < 30s
        return Response(status_code=500)
    if thread_count_missing_critical_task():
        return Response(status_code=500)
    return Response(status_code=200)
3) Optional dependency check endpoint (used by readiness, not liveness)
Copy code
@app.get("/deps")
def deps():
    results = {
      "db": check_db_connection(timeout=2),
      "ai_provider": check_provider_connectivity(timeout=2)
    }
    # Return 200 only if all required deps are OK. For optional deps, still return 200.
    if all_required_ok(results):
        return Response(status_code=200, content=results)
    return Response(status_code=503, content=results)
Kubernetes probe YAML suggestions • Startup probe (for long prewarm)
Copy code
startupProbe:
  httpGet:
    path: /startup
    port: 8080
  initialDelaySeconds: 5
  periodSeconds: 10
  failureThreshold: 60   # allows up to ~10 minutes (60*10s) for heavy prewarm
• Readiness probe (checks LiveKit connection + prewarm)
Copy code
readinessProbe:
  httpGet:
    path: /ready
    port: 8080
  initialDelaySeconds: 10
  periodSeconds: 10
  timeoutSeconds: 2
  failureThreshold: 3
• Liveness probe (internal responsiveness)
Copy code
livenessProbe:
  httpGet:
    path: /live
    port: 8080
  initialDelaySeconds: 120
  periodSeconds: 20
  timeoutSeconds: 2
  failureThreshold: 3
Notes on thresholds • initialDelaySeconds: give time for first cold start/prewarm. • timeoutSeconds: should be short for liveness/readiness (fast failure detection). • failureThreshold: larger for startup to allow long warm-up; smaller for liveness so truly stuck processes are restarted quickly. Handling DB or other required dependencies • If DB is required for the agent to function: ◦ Make dependency checks part of readiness (
/deps
or included in
/ready
) so the pod stays NotReady until DB is reachable. ◦ Only consider failing liveness if the DB failure is unrecoverable and a restart can reasonably fix it. For typical transient DB outages, returning NotReady is preferred. • Optionally implement backoff and alerting: ◦ If readiness flips repeatedly because of DB flakiness, emit metrics/alerts rather than immediate restarts. ◦ Use a circuit-breaker pattern for dependency calls to avoid resource exhaustion. Additional best practices • Centralized logs and metrics for readiness/liveness flips to correlate with job failures. • Use health check timeouts equal to or slightly larger than your worst expected dependency latency. • Consider readiness gating: block readiness until both local prewarm and remote registration confirmed. • Use PodDisruptionBudgets and rolling updates so restarts don’t remove capacity all at once. • If your environment supports it, use a sidecar or init container to run DB migrations or ensure dependencies before main container start. If you want, I can: • Provide an exact code snippet tailored to your runtime (Python FastAPI, Node Express, etc.) for /startup, /ready, and /live. • Suggest exact probe timings based on your measured startup time (tell me typical prewarm time). Which runtime and deployment environment are you using, and how long does a cold start typically take?
s
I am using agentserver s port option to expose health route and using that in startup and readiness probe is this good. not sure what to do in liveness probe
t
Thanks — I’m responding to your setup where the agentserver’s health route (exposed via the
--port
option) is used for the startup and readiness probes, and you’re unsure what to use for liveness. Short answer • Yes — using the agentserver
/health
route for the startup and readiness probes is appropriate if that endpoint verifies the worker has finished startup tasks (prewarm/models loaded) and is registered/connected to LiveKit. • For liveness, prefer a separate, lightweight endpoint that verifies the process is responsive (internal heartbeat/event-loop) rather than checking transient external dependencies. Only treat unrecoverable dependency failures as liveness failures. Why this separation matters • Startup probe: prevents Kubernetes from running liveness/readiness until long prewarm steps finish. • Readiness probe (
/health
): should reflect whether the worker can accept jobs (connected to LiveKit, prewarm complete). If this fails, Kubernetes removes the pod from service without restarting it. • Liveness probe: should detect irrecoverable hangs or deadlocks and trigger a restart. If liveness checked external services (DB, LiveKit connectivity) it could cause unnecessary restarts for transient outages. Practical recommendations 1) Use the agentserver
/health
for startup & readiness only if it does: • Confirm required prewarm steps are complete. • Confirm LiveKit connection/registration is established (or any other in-process readiness indicators). • Return 200 when ready, 503 when not ready. • Startup probe can hit the same endpoint or a
/startup
endpoint if you prefer to separate concerns. 2) Implement a dedicated liveness endpoint (e.g.,
/live
or
/internal/liveness
) that checks internal health: • Examples of good liveness checks: ◦ Event loop responsiveness (e.g., respond within 100–500ms). ◦ Internal heartbeat timestamp: return healthy if last heartbeat < X seconds. ◦ Critical internal threads/processes alive. • Avoid liveness checks for transient external dependencies (DB, network) unless the failure is known to be unrecoverable and a restart can help. 3) If DB or external dependency is required for correct function: • Include dependency checks in readiness (so the pod stays NotReady until DB is available). • Only fail liveness when the dependency failure is persistent and restarts have previously remedied it (rare). Usually, treat dependency outages as readiness failures, not liveness. 4) Example probe responsibilities (concept) • /startup: Ensure process started and prewarm finished. Used by startupProbe. • /health or /ready: Ensure LiveKit connection + prewarm done. Used by readinessProbe. • /live: Ensure event loop/heartbeat and internal components responsive. Used by livenessProbe. 5) Example Kubernetes probe settings (tune to your startup time) • Startup probe (long allowance for model prewarm)
Copy code
startupProbe:
  httpGet:
    path: /startup
    port: 8080
  initialDelaySeconds: 5
  periodSeconds: 10
  failureThreshold: 60
• Readiness probe (checks LiveKit registration)
Copy code
readinessProbe:
  httpGet:
    path: /health
    port: 8080
  initialDelaySeconds: 10
  periodSeconds: 10
  timeoutSeconds: 2
  failureThreshold: 3
• Liveness probe (fast internal responsiveness)
Copy code
livenessProbe:
  httpGet:
    path: /live
    port: 8080
  initialDelaySeconds: 120
  periodSeconds: 20
  timeoutSeconds: 2
  failureThreshold: 3
6) Logging & metrics • Emit metrics when readiness flips and when liveness triggers a restart so you can correlate with DB or network issues. • Temporarily enable DEBUG logs to capture why readiness/liveness changed when troubleshooting. If you’d like, I can: • Provide a concrete code snippet for
/live
(FastAPI/Express) that implements an internal heartbeat check. • Suggest specific probe timings based on your measured cold-start/prewarm time and deployment environment. Which runtime are you using (Python FastAPI, Node/Express, Go), and how long does a cold start typically take?
s
health route is not create by me i am using this localhost:8088/health server = AgentServer( setup_fnc=prewarm, num_idle_processes=2, job_memory_warn_mb=800, initialize_process_timeout=60.0, api_key=settings.livekit_api_key, api_secret=settings.livekit_api_secret, ws_url=settings.livekit_url, port=8088, )
t
Thanks — I’m responding to your setup where you’re using the AgentServer’s built-in
/health
endpoint at
localhost:8088/health
(with
port=8088
) for startup and readiness probes. That’s a good start — here’s clear guidance on how to proceed and what to do for liveness. Short answer • Keep using the AgentServer
/health
endpoint for startup and readiness probes if it already confirms prewarm/initialization and LiveKit registration. • Do not use that same
/health
endpoint as your liveness probe. Implement a separate lightweight liveness endpoint (e.g.,
/live
) that checks internal responsiveness (heartbeat/event loop/thread health) and not transient external dependencies (DB, LiveKit connectivity). Why • Startup/readiness: these endpoints should reflect whether the worker finished prewarm/model loads and successfully registered/connected to LiveKit so it can accept jobs. Using
AgentServer(..., port=8088)
exposing
/health
for this is appropriate. • Liveness: a liveness probe that checks external services (DB or LiveKit) can cause unnecessary restarts during transient outages. Liveness should detect unrecoverable process hangs or deadlocks and trigger a restart only when the process itself is unresponsive. What to implement 1) Keep
/health
for startup/readiness • Ensure
/health
returns 200 only when: ◦ prewarm completed (your
prewarm
/
setup_fnc
finished), ◦ connection/registration with LiveKit is established. • Kubernetes: ◦ Use
/health
for both startupProbe and readinessProbe (or
/startup
for startup if you want separation). 2) Add a dedicated liveness endpoint • Endpoint name:
/live
or
/internal/liveness
• What it should check (fast, in-process checks only): ◦ Event loop responsiveness (respond within a small timeout). ◦ A recent internal heartbeat timestamp (e.g., last heartbeat < 30s). ◦ Critical worker threads are alive. • Avoid checking DB or LiveKit connectivity here. Example minimal liveness implementation for Python (conceptual) • Add a periodic background heartbeat that updates a timestamp, and expose /live to check it:
Copy code
# conceptual example
from fastapi import FastAPI, Response
import time
import threading

app = FastAPI()
_last_heartbeat = time.time()

def heartbeat_loop():
    global _last_heartbeat
    while True:
        _last_heartbeat = time.time()
        time.sleep(5)

threading.Thread(target=heartbeat_loop, daemon=True).start()

@app.get("/live")
def liveness():
    # consider healthy if heartbeat updated within 30 seconds
    if time.time() - _last_heartbeat > 30:
        return Response(status_code=500)
    return Response(status_code=200)
(Adapt this pattern to your agent framework — you only need a small, cheap in-process check.) Suggested Kubernetes probes (tune times to your measured startup) • Startup probe (long allowance for model prewarm)
Copy code
startupProbe:
  httpGet:
    path: /health
    port: 8088
  initialDelaySeconds: 5
  periodSeconds: 10
  failureThreshold: 60
• Readiness probe (checks prewarm + LiveKit registration)
Copy code
readinessProbe:
  httpGet:
    path: /health
    port: 8088
  initialDelaySeconds: 10
  periodSeconds: 10
  timeoutSeconds: 2
  failureThreshold: 3
• Liveness probe (fast internal responsiveness)
Copy code
livenessProbe:
  httpGet:
    path: /live
    port: 8088
  initialDelaySeconds: 120
  periodSeconds: 20
  timeoutSeconds: 2
  failureThreshold: 3
Handling DB or other required dependencies • If DB is required for normal operation: ◦ Check DB in readiness (so pod stays NotReady until DB is reachable). ◦ Do not include DB checks in liveness unless DB failures are truly unrecoverable and restarts are known to fix them. ◦ If you need an endpoint to inspect dependencies for debugging, expose
/deps
(not used as liveness), returning per-dependency status. Logging & observability • Emit metrics when readiness flips or when liveness restarts occur so you can correlate with DB/LiveKit outages. • Temporarily enable DEBUG logs during troubleshooting to capture why readiness/liveness changed. If you want, I can: • Provide an exact code snippet integrated with AgentServer (show how to mount a small FastAPI/Flask endpoint alongside the AgentServer). • Suggest probe timings tailored to your measured cold-start time (tell me typical prewarm time and whether you prewarm synchronously). Which would you like?
s
could you explain how this builtin health endpoint works
t
Thanks — I’m responding to your request to understand how the AgentServer’s built-in
/health
endpoint works and what it reports. What the built-in
/health
endpoint is for • It’s a lightweight internal probe endpoint exposed by the AgentServer (you exposed it with
port=8088
) for orchestration/monitoring systems to check the agent’s status. • It is intended for use by startup/readiness probes to determine when the agent is ready to accept jobs, and to let orchestrators know when the agent should be removed from service during draining or overload. What the endpoint checks (behavior and intent) • Process is running: The endpoint only exists while the AgentServer process is alive. If the process is crashed or not listening, the probe will fail. • Registration/availability with LiveKit: The agent connects to LiveKit over WebSocket and registers itself. The health endpoint is intended to reflect whether the agent is able to accept new jobs — that typically implies the agent has successfully connected/registered with LiveKit. • Load-based availability: AgentServer uses a load function and a
load_threshold
. When current load exceeds that threshold, the server stops accepting new jobs. The /health endpoint is intended to reflect the server’s availability state (healthy when it can accept new jobs, unhealthy/not-ready when above threshold). • Draining state: On SIGINT/SIGTERM the agent begins draining (stops taking new jobs but finishes in-flight work). The health endpoint should indicate non-readiness in that state so orchestrators don’t send new work to that pod. What the endpoint does not (generally) do • It is not primarily a replacement for a deep liveness check. It should not be used to restart the container on transient external failures. • It typically does not perform heavy external dependency checks (e.g., full DB migrations, long network calls). Those belong in readiness or separate dependency endpoints if needed. • It is not necessarily a comprehensive diagnostic endpoint — it’s a quick boolean-like signal used by orchestration systems. How to use it correctly with probes • Startup probe: Good to point at
/health
(or an equivalent startup endpoint) if you want Kubernetes to wait until prewarm/model loading and registration complete before considering the pod started. • Readiness probe: Point Kubernetes’ readinessProbe at
/health
. The endpoint should return success only when prewarm is done and the worker is registered/under load threshold (so it can accept jobs). If it becomes unavailable (connection lost, overloaded), it should return NotReady to stop new job assignment. • Liveness probe: Do not reuse
/health
as the liveness endpoint. Liveness should detect unrecoverable process hangs or deadlocks and trigger restarts. Implement a small internal check endpoint (e.g.,
/live
) that verifies event-loop responsiveness, recent internal heartbeat, or critical threads are alive. Avoid checking transient external dependencies in liveness. Practical notes relevant to your AgentServer config • You already set
initialize_process_timeout=60.0
and
num_idle_processes=2
.
/health
should remain NotReady during heavy initialization/prewarm; use startupProbe with generous thresholds to avoid premature restarts. • If the AgentServer flips readiness because of load (exceeding
load_threshold
) or draining,
/health
should reflect that so the orchestrator will stop routing new jobs to the pod without restarting it. • Because the AgentServer registers over WebSocket, a healthy
/health
should imply the WebSocket registration completed — practical for readiness decisions. If you want more detail I can: • Show an example of a small
/live
endpoint (FastAPI/Express) that implements a heartbeat check you can run alongside the AgentServer. • Provide suggested Kubernetes probe values tuned to your observed cold-start/prewarm time. Which would you prefer? Sources: Self-hosted deployments | LiveKit Documentation
s
why can we use /health as liveness probe i am not getting this
t
Thanks — I hear the confusion. I’ll explain clearly why
/health
is appropriate for readiness/startup but usually not for liveness, and show what you should use instead. Core distinction (one-sentence) • Readiness = “Can I send traffic/jobs to this pod right now?” • Liveness = “Is this process alive and stuck/unrecoverable and therefore needs a restart?” Why
/health
fits readiness/startup • The AgentServer
/health
is designed to indicate whether the agent is ready to accept jobs: it reflects prewarm completion, LiveKit registration over WebSocket, and whether the server is under its load threshold. That’s exactly what readiness and startup probes need — they gate when the pod should start receiving work and prevent sending jobs to a pod that hasn’t finished initialization or is overloaded/draining. Why
/health
is not a good liveness check •
/health
usually depends on external conditions (LiveKit connection, prewarm, load). These can be transient: ◦ A brief network blip to LiveKit could make
/health
fail even though the process itself is functioning and will recover — you do not want Kubernetes to restart the whole pod for that. ◦ Load-related NotReady states are intentional: the process is alive but intentionally not accepting new jobs. Restarting because of load would make things worse. • Liveness should detect unrecoverable internal failures (deadlocks, hung event loop, process stuck) — conditions where a restart fixes the problem. If you use
/health
and it fails for recoverable external reasons, Kubernetes will keep restarting pods unnecessarily. Concrete examples to make it concrete • Scenario A (good for readiness): Agent loses its LiveKit registration briefly.
/health
returns 503 → Kubernetes marks pod NotReady and stops sending new jobs. Pod stays running; when connection recovers, readiness returns 200. No restart. • Scenario B (bad for liveness if using
/health
): Agent’s DB is briefly unreachable but process is fine. If
/health
checks DB and fails, Kubernetes restarts the pod — restart likely doesn’t help and only disrupts work. • Scenario C (what liveness should catch): The agent’s event loop is frozen or a critical thread died and the process no longer responds to internal requests. A liveness probe should detect this and restart the pod. What you should do instead • Keep using
/health
for startupProbe and readinessProbe (since it verifies prewarm, registration, and load). • Implement a separate lightweight liveness endpoint (e.g.,
/live
) that checks only internal signals: ◦ Event loop responsiveness (respond within X ms). ◦ Recent internal heartbeat timestamp (updated by an in-process timer). ◦ Critical background threads alive. • Do NOT check external transient dependencies (LiveKit connectivity, DB, network) in
/live
. Those belong in readiness or dedicated dependency endpoints. Minimal liveness pattern (concept) • Run a tiny in-process heartbeat (update timestamp every few seconds). •
/live
returns 200 if last heartbeat < 30s, otherwise 500. Probe wiring (example behavior) • startupProbe -> /health (long timeout to allow prewarm) • readinessProbe -> /health (indicates registration and ability to accept jobs) • livenessProbe -> /live (internal responsiveness only) Kubernetes impacts • Readiness failures remove pod from service but do not restart it. • Liveness failures trigger restarts. So liveness checks must be conservative and only fail for conditions where restart is the correct fix. If you’d like, I can: • Provide a small code snippet (FastAPI or Express) for a safe
/live
endpoint using a heartbeat. • Suggest probe timing values tuned to your measured cold-start/prewarm time. Which runtime would you like the snippet for (Python/Node)?
s
if env vars are not set will it go to liveness or readiness
t
Short answer • Missing required environment variables will most often cause a readiness failure — the agent won’t be considered ready to accept jobs. • Liveness will only fail if the process crashes or becomes unresponsive (for example, it exits because it couldn’t find required config). If the process is running but simply “not ready” due to missing env vars, liveness usually still passes. Why (clear distinction) • Readiness answers “can I send work to this pod now?” If essential env vars (LiveKit URL/key/secret or provider API keys) are missing, the agent can’t connect/authenticate or finish startup/prewarm — so it should report NotReady and the readiness probe should fail. That prevents new jobs from being dispatched to the pod without restarting it. • Liveness answers “is the process alive and stuck/unrecoverable?” If the agent process is alive and the event loop is responsive, the liveness probe should pass even if readiness fails. Only if missing env vars cause the process to crash or hang should the liveness probe fail and trigger a restart. Concrete examples • Required env var missing but process stays up: ◦ Agent starts, detects missing API key, logs an error, and refuses to register. Readiness: fail (pod not ready). Liveness: pass (pod not restarted). • Required env var missing and process exits: ◦ Agent throws on start and exits. Readiness: n/a (pod never becomes ready). Liveness: Kubernetes sees container not running → restart / CrashLoopBackOff. • Transient external dependency (DB or LiveKit unreachable): ◦ Readiness should fail (stop receiving work) while liveness should keep passing unless the process becomes unresponsive. Best practices • Validate all required env vars at container start and fail fast if values are missing and a restart is desired (this makes misconfiguration obvious). • Prefer failing readiness for missing dependencies/configuration that are recoverable (so pods aren’t restarted unnecessarily). • Use liveness for detecting stuck/hung processes (event-loop dead, threads died) — not for transient external checks. • Emit clear logs and metrics on readiness failures so you can distinguish config errors from network blips. • If you want the pod to crash immediately on missing critical env vars (so Kubernetes restarts it), make the agent exit on startup when required env vars are missing; otherwise keep the agent running and keep readiness failing until corrected. If you want, I can: • Show a small snippet that validates env vars at startup and either exits (to trigger liveness restarts) or sets readiness to false with explanatory logs. • Help you choose which env vars should be treated as “fatal” (exit) vs “deferred” (mark NotReady). Which behavior do you prefer for your deployment? Sources: Self-hosted deployments | LiveKit Documentation