Skip to content

debug(streaming): add logging for AI SDK v5 lifecycle events#858

Open
vdimarco wants to merge 1 commit into
masterfrom
terragon/fix-model-routing-issue
Open

debug(streaming): add logging for AI SDK v5 lifecycle events#858
vdimarco wants to merge 1 commit into
masterfrom
terragon/fix-model-routing-issue

Conversation

@vdimarco

@vdimarco vdimarco commented Jan 20, 2026

Copy link
Copy Markdown
Contributor

Summary

  • Added detailed logging for AI SDK v5 fullStream lifecycle events (start, start-step, finish-step, raw)
  • This helps diagnose empty response issues where models return lifecycle events but no text-delta content

Problem

When GPT-4o (and potentially other models) return empty responses, the error message shows "Part types received: start, start-step, finish-step, finish" but no actual content. This makes it difficult to diagnose why the model isn't generating text.

Changes

  • Log start, start-step, and finish-step lifecycle events with their full content
  • Log raw provider responses for debugging
  • Log finish event details including usage information

Related

This helps investigate issues where models like openai/gpt-4o return no content despite receiving valid requests.

🤖 Generated with Claude Code

Greptile Summary

This PR adds detailed logging for AI SDK v5 fullStream lifecycle events to help diagnose empty response issues where models return lifecycle events but no actual content.

Changes:

  • Added logging for start, start-step, and finish-step lifecycle events with full content (truncated to 300 chars)
  • Added logging for raw provider responses (truncated to 500 chars)
  • Added logging for finish event details including finishReason, contentReceived flag, and usage information

Impact:

  • No functional changes to request/response handling
  • Logging follows existing patterns in the codebase (using [AI SDK Route] prefix and truncating long content)
  • Will help investigate issues where models like openai/gpt-4o return empty responses despite receiving valid requests

Confidence Score: 5/5

  • Safe to merge with minimal risk - logging-only changes for debugging
  • This PR adds debug logging for AI SDK v5 lifecycle events without modifying any functional code paths. The changes are non-invasive, consist only of console.log statements, and follow existing logging patterns in the codebase. The logging will help diagnose empty response issues as described in the PR description.
  • No files require special attention

Important Files Changed

Filename Overview
src/app/api/chat/ai-sdk-completions/route.ts Added logging for AI SDK v5 lifecycle events (start, start-step, finish-step, raw, finish) to debug empty response issues - no functional changes, logging only

Sequence Diagram

sequenceDiagram
    participant Client
    participant Route as AI SDK Route
    participant AISDK as AI SDK v5
    participant Backend as Gatewayz Backend

    Client->>Route: POST /api/chat/ai-sdk-completions
    Note over Route: Validate request
    Note over Route: Convert messages format
    Route->>AISDK: streamText(model, messages)
    AISDK->>Backend: Stream request
    
    loop Stream lifecycle
        Backend->>AISDK: start event
        AISDK->>Route: part.type = 'start'
        Note over Route: Log lifecycle event
        
        Backend->>AISDK: start-step event
        AISDK->>Route: part.type = 'start-step'
        Note over Route: Log lifecycle event
        
        Backend->>AISDK: text-delta
        AISDK->>Route: part.type = 'text-delta'
        Route->>Client: SSE: content chunk
        
        Backend->>AISDK: raw response
        AISDK->>Route: part.type = 'raw'
        Note over Route: Log raw response
        
        Backend->>AISDK: finish-step event
        AISDK->>Route: part.type = 'finish-step'
        Note over Route: Log lifecycle event
        
        Backend->>AISDK: finish event
        AISDK->>Route: part.type = 'finish'
        Note over Route: Log finish details (usage)
        Route->>Client: SSE: [DONE]
    end
Loading

Add detailed logging for AI SDK v5 fullStream lifecycle events (start,
start-step, finish-step, raw) to help diagnose empty response issues
where models return lifecycle events but no text-delta content.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
@vercel

vercel Bot commented Jan 20, 2026

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Review Updated (UTC)
gatewayz-frontend Error Error Jan 20, 2026 6:42pm

@chatgpt-codex-connector

Copy link
Copy Markdown

You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard.

@sentry

sentry Bot commented Jan 20, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 20.00000% with 4 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
src/app/api/chat/ai-sdk-completions/route.ts 20.00% 2 Missing and 2 partials ⚠️

📢 Thoughts on this report? Let us know!

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