Skip to content

The RichLogHandler introduced in livekit-agents 1.3.x causes regressions on termination signals when stdout is piped #4552

@zaheerabbas-prodigal

Description

@zaheerabbas-prodigal

Bug Description

The RichLogHandler introduced in livekit-agents 1.3.x causes two regressions when stdout is piped (e.g., python main.py dev | tee log.txt):

  1. No colored output - Rich's TTY detection disables colors when piping
  2. Ctrl+C hangs - BrokenPipeError during shutdown prevents graceful termination

Both worked correctly in 1.2.17.

Expected Behavior

  • Colored log output (as in 1.2.17)
  • Ctrl+C gracefully terminates the process

Reproduction Steps

# Run agent with piped output
python main.py dev | tee -a debug.log

# Press Ctrl+C to stop
# Result: Process hangs, no colors in output

Operating System

macOS Tahoe

Models Used

Deepgram Nova-3, Cartesia

Package Versions

livekit==1.0.23
livekit-agents==1.3.10
livekit-api==1.0.7
livekit-blingfire==1.1.0
livekit-plugins-anthropic==1.3.10
livekit-plugins-cartesia==1.3.10
livekit-plugins-deepgram==1.3.10
livekit-plugins-elevenlabs==1.3.10
livekit-plugins-google==1.3.10
livekit-plugins-noise-cancellation==0.2.5
livekit-plugins-openai==1.3.10
livekit-plugins-silero==1.3.10
livekit-plugins-turn-detector==1.3.10
livekit-protocol==1.1.1

Session/Room/Call IDs

Local dev environment

Proposed Solution

Additional Context

Issue 1: No Colors

Rich checks sys.stdout.isatty() which returns False when piping. This disables all color output.

Issue 2: Ctrl+C Hangs

When Ctrl+C is pressed while piping:

  1. SIGINT sent to process group
  2. tee may terminate first, breaking the pipe
  3. Rich attempts to write to broken pipe
  4. Rich's on_broken_pipe() raises SystemExit(1) (rich/console.py:1305)
  5. This corrupts the shutdown sequence, causing hang

Traceback:

File ".../rich/console.py", line 1290, in _write_buffer
    self.file.write(text)
BrokenPipeError: [Errno 32] Broken pipe

During handling of the above exception, another exception occurred:
...
File ".../rich/console.py", line 1305, in _write_buffer
    raise SystemExit(1)
SystemExit: 1

Screenshots and Recordings

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions