stt-gpu-service / LOGGING_FIX_SUMMARY.md
Peter Michael Gits
fix: Resolve ZeroGPU logging conflicts with MCP integration
6cdc99b

A newer version of the Gradio SDK is available: 6.12.0

Upgrade

STT Service Logging Conflict Fix

Problem

The STT service at https://huggingface.co/spaces/pgits/stt-gpu-service was experiencing logging conflicts when starting up:

ValueError: I/O operation on closed file
ValueError: Unable to configure formatter 'default'

This occurred due to stdout/stderr conflicts between:

  • ZeroGPU environment logging
  • uvicorn server logging
  • Gradio interface logging
  • MCP server stdio protocol

Solution Implemented

1. ZeroGPU-Compatible Logging Setup

  • Custom formatter: [STT-{level}] {message} format to avoid conflicts
  • Safe stream handling: Uses sys.__stdout__ instead of potentially closed streams
  • Handler cleanup: Removes existing handlers before adding new ones
  • Library silencing: Reduces verbosity from transformers, torch, gradio, uvicorn

2. Fallback Safety Mechanism

  • Safe logging function: safe_log() that falls back to print statements
  • Error handling: Graceful degradation if logging configuration fails
  • Dual protocol support: Maintains both Gradio and MCP functionality

3. MCP Server Error Handling

  • Thread isolation: MCP server runs in separate thread with own event loop
  • Graceful failures: Service continues if MCP server fails to start
  • Stream protection: MCP stdio protocol doesn't interfere with Gradio

4. Enhanced Startup Process

  • Warning suppression: Filters out UserWarning and FutureWarning
  • Configuration staging: Logging setup happens before other imports
  • Error recovery: Gradio continues even if MCP fails

Code Changes Made

Key Functions Added:

  1. setup_zerogpu_logging() - ZeroGPU-compatible logging configuration
  2. safe_log() - Robust logging with print fallback
  3. Enhanced start_mcp_server_thread() - Better error handling
  4. Improved run_mcp_server() - Exception handling for stdio conflicts

Environment Variables:

  • GRADIO_SERVER_NAME=0.0.0.0
  • GRADIO_SERVER_PORT=7860

Launch Parameters:

  • quiet=True - Reduces Gradio logging noise
  • enable_queue=True - Better request handling
  • max_threads=4 - ZeroGPU thread limit

Testing

  • βœ… Logging setup logic verified
  • βœ… Safe logging fallback tested
  • βœ… Stream isolation confirmed
  • βœ… Dual server mode compatibility

Expected Results

  1. Clean startup - No more "I/O operation on closed file" errors
  2. Dual protocol support - Both Gradio UI and MCP API available
  3. Graceful degradation - Service continues if one component fails
  4. ZeroGPU compatibility - Optimized for HuggingFace Pro environment

Deployment

The fixed service should now start cleanly in the ZeroGPU environment with both:

  • Gradio Interface: Available on port 7860 for web UI
  • MCP Server: Available on stdio protocol for API integration

Monitoring

Check logs for these success indicators:

  • [STT-INFO] πŸš€ Starting STT service with dual protocol support...
  • [STT-INFO] βœ… MCP Server: Available on stdio protocol
  • [STT-INFO] βœ… Gradio Interface: Starting on port 7860...