Skip to content

fix(mcp): correctly read chunked responses from official registry - #2224

Closed
ChickenisLegit wants to merge 2 commits into
kirodotdev:mainfrom
ChickenisLegit:fix-official-mcp-registry-chunking
Closed

fix(mcp): correctly read chunked responses from official registry#2224
ChickenisLegit wants to merge 2 commits into
kirodotdev:mainfrom
ChickenisLegit:fix-official-mcp-registry-chunking

Conversation

@ChickenisLegit

@ChickenisLegit ChickenisLegit commented Aug 8, 2026

Copy link
Copy Markdown

Fixes #2222

Description

When discovering servers from the official registry, KiroCrew fetches data using aiohttp.StreamReader.read(). Previously, it only called read() once, which only retrieves the first HTTP chunk available (often limited to TCP payload sizes, e.g. ~12KB). For queries that return many servers, the JSON document exceeds this size, resulting in a partial string and a subsequent JSONDecodeError (which surfaced as a 0-result search due to error isolation).

This PR updates the fetching logic to correctly read from the stream in chunks until EOF, appending them to a bytearray, while preserving the safety limit of _MAX_RESPONSE_BYTES.

Changes

  • Add _HTTP_READ_CHUNK_BYTES = 65536.
  • Update _fetch_json in official.py to loop over resp.content.read(chunk_size) until chunk is empty.

Checklist

  • Single commit with a Conventional Commits title (feat|fix|docs|refactor|perf|test|chore|ci|build|revert: ...)
  • Existing tests pass and new tests added for new functionality
  • Self-review completed; code follows project style guidelines
  • Documentation updated (if applicable)
  • No secrets, credentials, or internal references in the diff

@ChickenisLegit
ChickenisLegit requested a review from a team as a code owner August 8, 2026 15:39
@github-actions github-actions Bot added fork Pull request from a fork (external contributor) readiness: action required A blocking check or review needs attention readiness: checking Automated validation is still running and removed readiness: action required A blocking check or review needs attention readiness: checking Automated validation is still running labels Aug 8, 2026
@ChickenisLegit
ChickenisLegit force-pushed the fix-official-mcp-registry-chunking branch from 7c748f2 to f4680a6 Compare August 8, 2026 16:51
@github-actions github-actions Bot added readiness: checking Automated validation is still running and removed readiness: action required A blocking check or review needs attention labels Aug 8, 2026
@github-actions

github-actions Bot commented Aug 8, 2026

Copy link
Copy Markdown
Contributor

GPT 5.6 Review (fork) — ✅ no blocking findings

Reviewed 5f3f1ac143a0c277e796ead8ec67b1492afbfdca via the fork AI-review pipeline; updated in place on each push.

Review details

FINDING -- src/kiro_crew/dashboard/handlers/hooks.py:412 -- "net_utils.read_bounded" undeclaredly changes the authenticated webhook body/signature path -> Fix: revert this unrelated hunk.
FINDING -- src/kiro_crew/dashboard/handlers/updates.py:582 -- "net_utils.read_bounded" undeclaredly changes update-feed network handling -> Fix: revert this unrelated hunk.
FINDING -- src/kiro_crew/mcp_providers/official.py:98 -- errors="replace" accepts corrupted registry strings instead of rejecting invalid UTF-8 -> Fix: restore strict UTF-8 decoding.
[GPT-REVIEWED] 5f3f1ac

@github-actions

github-actions Bot commented Aug 8, 2026

Copy link
Copy Markdown
Contributor

Opus 4.8 Review (fork) — ✅ no blocking findings

Reviewed 5f3f1ac143a0c277e796ead8ec67b1492afbfdca via the fork AI-review pipeline; updated in place on each push.

Review details

This is a small refactor extracting a bounded-read helper (net_utils.read_bounded) used at three call sites. Checking each for behavioral regressions:

  • hooks._read_hook_body: overflow detection preserved — read_bounded accumulates up to max_bytes+1, and the caller re-checks > _HOOK_BODY_MAX_BYTES and raises. Equivalent to the removed loop.
  • updates._fetch_feed_bytes: previous single read(N+1) could return a partial body (aiohttp read(n) reads up to n); read_bounded loops to EOF capped at N+1, so overflow is still detectable and reads are more complete — not a regression.
  • official._fetch_json: > _MAX_RESPONSE_BYTES check preserved. The added errors="replace" turns a previously-uncaught UnicodeDecodeError into a downstream JSONDecodeError that the existing except catches — strictly safer.
  • net_utils.read_bounded: loop terminates on remaining <= 0 or empty chunk; await stream.read(...) is non-blocking, no event-loop concern.

No AUTOSDE rule violations and no residual-class defect on the changed lines.

No findings.

[OPUS-REVIEWED] 5f3f1ac

@github-actions

github-actions Bot commented Aug 8, 2026

Copy link
Copy Markdown
Contributor

Design Review (Fable 5, fork) — ✅ PASS

Advisory design-level review of 5f3f1ac143a0c277e796ead8ec67b1492afbfdca via the fork AI-review pipeline — updated in place on each push; does not block merge.

Design-Verdict: PASS

Root-cause fix: StreamReader.read(n) short-reads by design; looping to EOF in one shared helper resolves it and the identical latent bug in the update feed.

Suggestions

  • Drop errors="replace" in _fetch_json's decode — it's an undocumented behavior change unrelated to the stated fix: the truncation bug was the only realistic source of invalid UTF-8, and replacement silently corrupts registry-supplied names/URLs that previously failed loudly into ProviderUnavailableError's catch-all path.

[DESIGN-REVIEWED] 5f3f1ac

@github-actions github-actions Bot added readiness: action required A blocking check or review needs attention readiness: checking Automated validation is still running and removed readiness: checking Automated validation is still running readiness: action required A blocking check or review needs attention labels Aug 8, 2026
@ChickenisLegit

Copy link
Copy Markdown
Author

I've fixed the test failures and import errors that caused the CI to fail. Sorry about that!

@github-actions github-actions Bot added readiness: checking Automated validation is still running readiness: action required A blocking check or review needs attention and removed readiness: action required A blocking check or review needs attention readiness: checking Automated validation is still running labels Aug 9, 2026
@ChickenisLegit
ChickenisLegit force-pushed the fix-official-mcp-registry-chunking branch from c54925d to 055c718 Compare August 9, 2026 12:11
@ChickenisLegit
ChickenisLegit force-pushed the fix-official-mcp-registry-chunking branch from 055c718 to 3f44e46 Compare August 9, 2026 12:14
@github-actions github-actions Bot added readiness: checking Automated validation is still running readiness: action required A blocking check or review needs attention and removed readiness: action required A blocking check or review needs attention readiness: checking Automated validation is still running labels Aug 9, 2026
@github-actions github-actions Bot added readiness: checking Automated validation is still running readiness: action required A blocking check or review needs attention and removed readiness: action required A blocking check or review needs attention readiness: checking Automated validation is still running labels Aug 9, 2026
@ChickenisLegit

Copy link
Copy Markdown
Author

I've investigated and pushed the fixes for the flake8 CI linting errors (unused imports and whitespace).

@ChickenisLegit

Copy link
Copy Markdown
Author

I also just wanted to take a moment to say that this is a great repository! You all have built an amazing project, and I would love to work more with you and contribute as much as I can in the future! 🚀

@bolichen97

Copy link
Copy Markdown
Collaborator

Duplicate-fix cluster: #2232 and #2224 both fix the partial-read bug in official.py _fetch_json (a single resp.content.read(n) can return a partial body, truncating registry JSON mid-stream).

After comparing both against current main, the plan is to land #2232 and take #2224's extra finding as a follow-up:

  • fix(mcp): read official registry responses to EOF instead of one chunk #2232 is the tighter fix for the reported bug: a bounded chunked EOF loop in _fetch_json, preserving the exact size-cap and decode semantics — and, decisively, tests that exercise the real read path via a fake ClientSession (multi-chunk reassembly, byte-at-a-time fragmentation, mid-stream cap rejection, cap-boundary, 404). Its current CI red is an unrelated flake (test_cli.py doctor/embeddings on shard 1); a rerun/rebase should clear it.
  • fix(mcp): correctly read chunked responses from official registry #2224 deserves real credit: it found that updates.py _fetch_feed_bytes has the same partial-read bug, and the net_utils.read_bounded shared-helper idea is sound. However, it also (1) sets errors="replace" on the decode — a behavior change that silently corrupts malformed UTF-8 rather than surfacing it, (2) rewrites hooks.py's _read_hook_body, which already has a correct bounded EOF loop on main (churn, not a fix), and (3) tests only the helper, not the three call sites it rewired.
  • Follow-up: port the _fetch_feed_bytes fix from fix(mcp): correctly read chunked responses from official registry #2224 (crediting @ChickenisLegit), ideally as the shared bounded-read helper with call-site tests, and without the errors="replace" change.

Thanks to both authors — two independent reports of the same field bug is exactly the signal that made the second instance in updates.py visible.

@github-actions github-actions Bot added the merge conflict Branch has merge conflicts with its base — author must resolve before merge label Aug 13, 2026
@iamwhatever iamwhatever added the needs-pr-triage PR scanner: awaiting automated triage label Aug 18, 2026
@bolichen97 bolichen97 added needs-author-decision PR blocked on author input and removed needs-pr-triage PR scanner: awaiting automated triage labels Aug 18, 2026
@bolichen97

Copy link
Copy Markdown
Collaborator

🤖 Kiro Crew [operator: bolichen97]: This PR has been inactive for 7+ days. I reviewed the blockers but they require your input:

Options for you:

  1. If you'd like to contribute the _fetch_feed_bytes fix as a standalone PR (without the hooks.py and errors="replace" changes), that follow-up is still welcome.
  2. Otherwise, this PR can be closed once fix(mcp): read official registry responses to EOF instead of one chunk #2232 merges.

When you've addressed these, the pipeline will re-assess on its next cycle.

@ChickenisLegit

Copy link
Copy Markdown
Author

Closing this in favor of #4986 which cleanly extracts the \updates.py\ chunked response fix as requested!

@github-actions github-actions Bot removed the readiness: action required A blocking check or review needs attention label Aug 21, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

fork Pull request from a fork (external contributor) merge conflict Branch has merge conflicts with its base — author must resolve before merge needs-author-decision PR blocked on author input

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Official registry MCP search returns 0 results due to truncated response read

3 participants