Skip to content

Troubleshooting stream issue#10

Merged
hh54188 merged 4 commits intomasterfrom
troubleshooting-stream-issue
Sep 25, 2025
Merged

Troubleshooting stream issue#10
hh54188 merged 4 commits intomasterfrom
troubleshooting-stream-issue

Conversation

@hh54188
Copy link
Owner

@hh54188 hh54188 commented Sep 25, 2025

No description provided.

hh54188 and others added 4 commits September 23, 2025 10:02
- Added a new method `streamGeminiFake` to simulate chunked streaming responses for debugging purposes, allowing developers to test without actual API calls.
- Updated the chat route to include a `useFakeStream` parameter, enabling the use of the fake stream when requested.
- Adjusted the chat service to pass the `useFakeStream` flag, facilitating easier debugging of streaming interactions.
…g functionality

- Updated the App component to render CopilotApp instead of ChatListTroubleshooting.
- Modified CopilotSidebar to include onFirstChunk callback for improved message status handling during streaming.
- Adjusted chatService to support onFirstChunk callback, ensuring accurate status updates when the first chunk of data is received.
@gemini-code-assist
Copy link
Contributor

Summary of Changes

Hello @hh54188, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request introduces a robust fake streaming mechanism for Gemini AI responses, primarily aimed at enhancing debugging capabilities for streaming-related issues without incurring API costs. It integrates this fake stream into the backend API, updates the frontend to better reflect streaming states, and provides extensive documentation and test scripts for its usage. Additionally, it includes a minor dependency update and a new UI component for chat list troubleshooting.

Highlights

  • Fake Stream Implementation: A new streamGeminiFake method has been added to aiService.js to simulate Gemini streaming responses for debugging purposes, complete with configurable delays, chunking, and tool call simulation.
  • API Integration for Debugging: The backend's /api/chat/stream endpoint now accepts a useFakeStream parameter, allowing developers to easily switch to the fake Gemini stream for testing without hitting actual AI APIs.
  • Enhanced Frontend Streaming Status: The CopilotSidebar.jsx component now utilizes an onFirstChunk callback to update the UI message status to 'streaming' as soon as the initial data chunk is received, improving user experience by providing immediate feedback.
  • Comprehensive Debugging Tools & Documentation: New example usage scripts (example-fake-stream-usage.js, test-fake-stream.js, test-fake-stream-api.js) and a detailed FAKE_STREAM_DEBUG_README.md have been introduced to guide developers on effectively using and customizing the fake streaming feature.
  • Dependency Update: The @ant-design/x dependency in the Chrome extension has been updated from version ^1.4.0 to ^1.6.1.
  • Chat List Troubleshooting Component: A new ChatListTroubleshooting.jsx component and ChatListTest.jsx have been added to the Chrome extension's proof-of-concept section, providing a dedicated environment for testing and debugging the chat list UI's streaming behavior.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Copy link
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request introduces a valuable fake streaming mechanism for debugging Gemini API responses, which is a great addition for development and troubleshooting. The implementation spans the backend and frontend, including new test scripts and documentation. The frontend also sees a nice UX improvement with the onFirstChunk callback to better indicate streaming activity. My review includes a few suggestions to enhance the new code, such as fixing an incorrect import path, making console.log statements conditional to keep logs clean, removing some leftover debugging code, and correcting commands in the new documentation. Overall, this is a solid contribution that will improve the development workflow.

* This helps debug streaming response issues without making real API calls
*/

import aiService from './services/aiService.js';
Copy link
Contributor

Choose a reason for hiding this comment

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

high

The import path './services/aiService.js' is relative to the current working directory, which makes the script fragile. It's better to use a path relative to the file's location to ensure it works regardless of where it's executed from.

Suggested change
import aiService from './services/aiService.js';
import aiService from '../services/aiService.js';

console.log('─'.repeat(60));
console.log(`Total chunks: ${chunkCount}`);
console.log(`Total length: ${totalLength} characters`);
console.log(`Average chunk size: ${Math.round(totalLength / chunkCount)} characters`);
Copy link
Contributor

Choose a reason for hiding this comment

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

medium

There's a potential division by zero error here if chunkCount is 0, which would happen if the stream is empty. It's good practice to add a guard to prevent this.

Suggested change
console.log(`Average chunk size: ${Math.round(totalLength / chunkCount)} characters`);
console.log(`Average chunk size: ${chunkCount > 0 ? Math.round(totalLength / chunkCount) : 0} characters`);

Comment on lines +383 to +388
console.log('🔧 Using FAKE Gemini stream for debugging');
console.log('Message:', message);
console.log('Model:', model);
console.log('Session ID:', sessionId);
console.log('Files:', files);
console.log('Use MCP Tools:', useMCPTools);
Copy link
Contributor

Choose a reason for hiding this comment

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

medium

These console.log statements are useful for debugging but can create a lot of noise if this code is ever used in a staging or production environment. It's a good practice to wrap them in a condition that checks for a development environment, like if (process.env.NODE_ENV === 'development') { ... }.

timestamp: new Date().toISOString()
};

console.log(`📦 Chunk ${i + 1}/${chunks.length}: "${chunks[i].trim()}"`);
Copy link
Contributor

Choose a reason for hiding this comment

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

medium

This log inside the generator loop can be very verbose. Consider making it conditional, for example, by wrapping it in an if (process.env.NODE_ENV === 'development') block, to avoid cluttering logs in other environments.

Comment on lines +112 to +116
const response = await fetch(`${API_BASE_URL}/api/chat/test`);
if (response.ok) {
console.log('✅ Server is running');
return true;
}
Copy link
Contributor

Choose a reason for hiding this comment

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

medium

The checkServer function is missing a return false in the if block, which means it will implicitly return undefined if the server is running but the /api/chat/test endpoint returns a non-OK status. It's better to explicitly return false in that case.

        const response = await fetch(`${API_BASE_URL}/api/chat/test`);
        if (response.ok) {
            console.log('✅ Server is running');
            return true;
        }
        return false;

import ComponentHandleStream from './proof-of-concept/ComponentHandleStream';
import StorageDemo from './proof-of-concept/StorageDemo';
import ScreenCaptureTest from './proof-of-concept/ScreenCaptureTest';
import ChatListTroubleshooting from './proof-of-concept/ChatListTroubleshooting';
Copy link
Contributor

Choose a reason for hiding this comment

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

medium

The ChatListTroubleshooting component is imported but not used. This unused import should be removed to keep the code clean.

Comment on lines +22 to +23
const loadingMessage = messages.find(message => message.status === 'loading');
console.log(loadingMessage?.message?.content);
Copy link
Contributor

Choose a reason for hiding this comment

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

medium

This console.log statement appears to be for debugging. It should be removed to avoid cluttering the browser console.

Comment on lines +32 to +33
// loading: i.status === 'loading',
// typing: i.status === 'loading' ? { step: 5, interval: 20, suffix: <>💗</> } : false,
Copy link
Contributor

Choose a reason for hiding this comment

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

medium

This code is commented out. If it's no longer needed, it should be removed to improve code clarity.

// Reset to start over
currentIndex = 0;
}
}, 100); // Update every 500ms
Copy link
Contributor

Choose a reason for hiding this comment

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

medium

The comment indicates an update interval of 500ms, but the code uses 100ms. The comment should be updated to match the code for accuracy.

Suggested change
}, 100); // Update every 500ms
}, 100); // Update every 100ms

Comment on lines +58 to +68
#### Test Direct Method
```bash
cd backend
node test-fake-stream.js
```

#### Test API Endpoint
```bash
cd backend
node test-fake-stream-api.js
```
Copy link
Contributor

Choose a reason for hiding this comment

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

medium

The commands for running the test scripts are incorrect because the scripts are located in the tests/ subdirectory. The paths should be updated to reflect their correct location.

Suggested change
#### Test Direct Method
```bash
cd backend
node test-fake-stream.js
```
#### Test API Endpoint
```bash
cd backend
node test-fake-stream-api.js
```
#### Test Direct Method
```bash
cd backend
node tests/test-fake-stream.js

Test API Endpoint

cd backend
node tests/test-fake-stream-api.js

@hh54188 hh54188 merged commit b0d04d9 into master Sep 25, 2025
3 checks passed
@github-actions
Copy link

DOCS_SYNC: docs/troubleshooting-stream-issue

Updated docs for fake stream debugging. Compare and open PR:
master...docs/troubleshooting-stream-issue

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