Skip to content

fix(core): parse web search SSE events - #55611

Closed
sdivyanshu90 wants to merge 1 commit into
anomalyco:devfrom
sdivyanshu90:parse-websearch-sse
Closed

sdivyanshu90 wants to merge 1 commit into
anomalyco:devfrom
sdivyanshu90:parse-websearch-sse

Conversation

@sdivyanshu90

Copy link
Copy Markdown
Contributor

Issue for this PR

Closes #55609

Type of change

  • Bug fix
  • New feature
  • Refactor / code improvement
  • Documentation

What does this PR do?

Use Effect's existing SSE parser for MCP web-search responses. Valid data:{...} fields now return results, and multiple data fields are joined before JSON decoding. Plain JSON responses keep their existing path.

How did you verify your code works?

From packages/core, using Bun 1.4.3:

  • bun run test test/plugin/websearch-mcp.test.ts test/plugin/websearch.test.ts test/websearch.test.ts test/tool-websearch.test.ts: 63 passed. Five parser cases and the Exa integration regression fail before the fix.
  • Covers optional spacing, LF/CRLF/CR framing, multiline data, separate events, comments, retry directives, and plain JSON.
  • bun typecheck: passed.
  • Focused Oxlint, Prettier, and git diff --check: passed.

Repository-wide verification is limited by the filtered dependency installation: the shared baseline's bun run check passed lint with existing warnings, then stopped at the GUI package's missing @tsconfig/node22 dependency.

Screenshots / recordings

Not applicable; no rendered UI changes.

Checklist

  • I have tested my changes locally
  • I have not included unrelated changes in this PR

@sdivyanshu90

Copy link
Copy Markdown
Contributor Author

Hi @kitlangton, could you please review this PR whenever you have some time. Thanks!

@github-actions

Copy link
Copy Markdown
Contributor

The following comment was made by an LLM, it may be inaccurate:

@opencode-agent opencode-agent Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

The approach looks right: it reuses Effect's SSE parser, which packages/core/src/aisdk.ts already uses, instead of matching the data: prefix by hand. That covers both cases in #55609: data: with no space, and JSON split across several data: lines. The plain-JSON path is unchanged. I could not run the tests or the #55609 reproduction in time (the dependency install had not finished), so this is a code read only.

Public API is unchanged. WebSearchMcp.parseResponse keeps its signature. Its error type may now include an SSE parser error, but it is only used inside the built-in web search providers.

One case is worth checking (inline): does the parser dispatch the last event when the body ends without a blank line? The old line-by-line loop handled that.

const parser = makeParser((event) => {
if (event._tag === "Event") events.push(event.data)
})
const error = parser.feed(body)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

SSE parsers usually dispatch an event only when they reach the blank line that ends it. If an MCP server's response body ends straight after the last data: line (no trailing \n\n), the event may never be dispatched. events would then be empty and this would return undefined, which is a regression: the old split("\n") loop decoded that line. Could you confirm how makeParser behaves here? If it drops the event, feed a final "\n\n" (or call the parser's finish/reset step, if it has one) after body, and add a test for a body with no trailing newline.

@github-actions

Copy link
Copy Markdown
Contributor

Automated PR Cleanup

Thank you for contributing to opencode.

Due to the high volume of PRs from users and AI agents, we periodically close older PRs using automated criteria so maintainers can focus review time on the most active and community-supported contributions.

This PR was closed because it matched the following cleanup criteria:

  • The PR was created more than 1 month ago
  • The PR had fewer than 2 positive reactions
  • Positive reactions are counted as thumbs-up, heart, celebration, or rocket reactions on the PR

PRs created within the last month are not affected by this cleanup.

If you believe this PR was closed incorrectly, or if you are still actively working on it, please leave a comment explaining why it should be reopened. A maintainer can review and reopen it if appropriate.

Thanks again for taking the time to contribute.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

V2 web search ignores valid SSE data fields without a space

1 participant