Skip to content

[Bug]: DeepResearch cause content duplication when processing SSE streams #128

@teebu

Description

@teebu

Bug Description

Performing deep research with SSE endpoint, sometimes returns duplicate the final report text.

Version: 0.9.20

Steps to Reproduce

Using SSE endpoint, sometimes duplicate final report is returned.

code:

  const response = await fetch("http://localhost:3000/api/sse", {
    method: "POST",
    headers: { "Content-Type": "application/json" },
    body: JSON.stringify({
      query: formattedPrompt,
      provider: "google",
      thinkingModel: "gemini-2.5-flash",
      taskModel: "gemini-2.5-flash",
      searchProvider: "model",
      language: "en-US",
      maxResult: 5,
      enableCitationImage: false,
      enableReferences: true
    }),
    signal: ctrl.signal as any
  });

let finalReportResult: {
    title: string;
    finalReport: string;
    sources?: { url: string; title?: string }[];
  } | null = null;

  const parser = createParser({
    onEvent(event) {
      const { event: evt, data } = event;
      const msgData = JSON.parse(data);

      if (evt !== "message") {
        //console.log(evt, msgData.step, msgData.status);
      }

      if (evt === "progress" && msgData.step === "final-report") {
        console.log(evt, msgData.step, msgData.status);
      }

      if (evt === "progress" && msgData.step === "final-report" && msgData.status === "end") {
        finalReportResult = msgData.data;
      }
    }
  });

  for await (const chunk of response.body) {
    parser.feed(chunk.toString());
  }

  if (!finalReportResult) {
    console.error("No final report result received.");
    return;
  }

  const { title, finalReport, sources } = finalReportResult as FinalReportResult;

  // if finalReport is empty or small throw an error
  if (!finalReport || finalReport.trim() === "" || finalReport.length <= 20000) {
    throw new Error("Final report is empty");
  }

Expected Behavior

Single full final report should be returned.

Screenshots

No response

Deployment Method

  • Docker
  • Vercel
  • Server

Desktop OS

No response

Desktop Browser

No response

Desktop Browser Version

No response

Smartphone Device

No response

Smartphone OS

No response

Smartphone Browser

No response

Smartphone Browser Version

No response

Additional Logs

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions