Repository navigation
fix(tool): read the code search reply the request asked for - #785
Merged
Ishaan Gangwani (ishaan1124) merged 2 commits intoSep 29, 2026
Conversation
ANIRUDDHA ADAK (aniruddhaadak80)
requested review from
Aayam Bansal (aayambansal) and
Ishaan Gangwani (ishaan1124)
as code owners
September 28, 2026 09:23
|
ANIRUDDHA ADAK (@aniruddhaadak80) is attempting to deploy a commit to the InkVell Team on Vercel. A member of the Team first needs to authorize it. |
ANIRUDDHA ADAK (aniruddhaadak80)
force-pushed
the
fix/codesearch-json-response
branch
2 times, most recently
from
September 29, 2026 14:04
266c18a to
46ad740
Compare
… for The tool sends `Accept: application/json, text/event-stream` and a Streamable HTTP server is free to answer with the first type, so a perfectly good search came back as "nothing found" because the reader only looked for `data:` frames. Read the body directly when the response is JSON, keep the SSE path for everything else, and take a `data:` frame with or without the space after the colon. A rejected call arrives as a JSON-RPC `error` object with no `result` at all, which also fell through to the same "nothing found" text, so it is raised as a tool error carrying the server's message. Only a reply that really carried no content now reads as empty.
ANIRUDDHA ADAK (aniruddhaadak80)
force-pushed
the
fix/codesearch-json-response
branch
from
September 29, 2026 14:17
46ad740 to
d82b036
Compare
# Conflicts: # CHANGELOG.md
Ishaan Gangwani (ishaan1124)
merged commit Sep 29, 2026
a13fd66
into
synthetic-sciences:main
8 of 9 checks passed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What does this PR do, and why?
codesearchasks for two response types:and then reads only one of them:
Three shapes fall through that loop to the "nothing found" text. I ran today's
exact reader against each:
data: {…result…}text/event-stream{…result…}application/json{…error: invalid params}application/jsondata:{…result…}(no space)text/event-streamThe second row is the important one:
application/jsonis the first thing therequest asks for, and it is a legal Streamable HTTP reply, so a completely
successful search is reported as zero hits. The third is worse — a rejected call
(bad arguments, quota, auth) is a JSON-RPC object with no
resultat all, so themodel is told the library does not exist and rephrases and fans out instead of
seeing the failure. A missing space after
data:is legal per the SSE grammarand also missed.
The fix reads the declared content type and surfaces an error:
Malformed JSON still throws rather than being skipped, so a broken reply cannot
quietly become another "nothing found" — only the terminal sentinel is exempt.
Why the parser is exported
API_CONFIG.BASE_URLis a hardcodedhttps://mcp.exa.ai, so a test cannot pointthe tool at a fake peer without adding configuration surface that has no other
purpose. The defect is the parsing, so I extracted and tested that. If you would
rather have an end-to-end test through a local peer, say so and I will add a base-URL
override instead —
OPENSCIENCE_API_BASEintest/preload.tsshows there isprecedent for that shape.
Linked issue
Self-identified. Happy to file a report if you would rather track it; my issue
budget this turn went to the two
apply_patchdefects and thelocalStoragecopies.
How did you verify it?
backend/cli/test/tool/codesearch-reply.test.ts, five cases: an SSE frame, aplain JSON body (with and without a charset parameter), an SSE frame with no
space, a rejected call in both encodings, and replies that genuinely carry no
content.
A note on how that test earned its keep: the
no contentcase caught a bug inmy own first version of the fix — it threw
SyntaxError: JSON Parse error: Unexpected identifier "DONE"on the SSE terminal sentinel, which I had notexcluded. That is the reason the sentinel check is in the code.
Commands run:
bun test --timeout 60000 ./test/tool/codesearch-reply.test.ts→ 5 pass, 0 failbun run --cwd backend/cli typecheck→ exit 0Two adjacent things I did not change
Both are in the same function and both are real, but each is a separate concern
and I would rather not bundle them:
clearTimeout(timeoutId)runs beforeawait response.text(), so the 30 sbudget covers time-to-headers only and a slow body is unbounded.
webfetch, there is no response size cap onresponse.text().Checklist
bun run checkis green (format, typecheck, backend + frontend/ui + SDK tests) — blocked on this Windows checkout by the CRLF and symlink artifacts in my other pull requests; backend typecheck is clean and the new test is greenbun run --cwd frontend/workspace buildsucceeds if I touchedfrontend/workspaceorfrontend/ui— not touched./tooling/repo/generate.tswas run and thetooling/sdkoutput committed if I changedbackend/cli/src/server— not touchedfrontend/docs/src/content/openscience/is updated if behavior changed — no doc change needed: the tool's contract is unchanged, only its parsing of the replypackage.jsonversions and tags are written by the release workflow)installandfrontend/landing/public/installare still byte-identical if I touched either — not touched