Repository navigation
fix(blender): unblock send_command hang against persistent-connection server (#1022) - #1026
Merged
Merged
Conversation
… server (#1022) Client used a chunk-until-EOF recv loop, but the Blender addon's server keeps the connection open to accept further commands on the same socket. Both ends blocked on recv() forever after the first response. Switch to incremental JSON parsing (matching the server's own framing in blender_mcp_server.py:128-166) and add a 30s socket timeout so a misbehaving server can't hang the agent indefinitely and Ctrl-C remains responsive. Adds a socket-level regression test using a fake persistent-connection server, so this can be exercised in CI without a real Blender install.
2 of 3 tasks
…t timeouts Follow-up hardening from a deeper review of the #1022 fix: * Tolerate UnicodeDecodeError in the recv loop. A multi-byte UTF-8 character (e.g. a non-ASCII object name in an error message) split across two recv() boundaries was raising UnicodeDecodeError and bubbling out as a hard MCPError; now treated identically to JSONDecodeError — keep buffering. * Treat ConnectionResetError as "connection closed before complete response received" rather than letting it surface as a raw OSError. Some servers send RST instead of FIN when closing mid-response. * Bump the default per-recv socket timeout from 30s to 120s. Long Blender operations such as render/simulate via execute_code can sit silent for tens of seconds at a time; the original 30s was tight enough to misfire in legitimate workflows. Tests added: * test_send_command_assembles_chunked_response — splits a non-ASCII response across two send() calls with a delay, exercising the incremental-parse loop and the UnicodeDecodeError tolerance. * test_send_command_raises_on_premature_close — server closes after sending a partial JSON; client must surface a clear MCPError. Also tightened the connection-refused test to use a kernel-assigned free port instead of port 1, for CI portability.
2 tasks done
Addresses items raised in a follow-up review of the original fix:
* Use json.JSONDecoder().raw_decode() instead of json.loads() so a
hypothetically pipelined server response ({"a":1}{"b":2}) yields the
first object instead of looping until timeout. The current server
sends one response per command, but raw_decode is cheap and removes
a foot-gun.
* Split UTF-8 decoding from JSON parsing into separate try blocks. The
prior single try caught UnicodeDecodeError but only because of the
combined except clause; this is clearer and more robust.
* Cap the response buffer at 16 MB. A misbehaving server that trickled
bytes just under each per-recv timeout would otherwise grow the
buffer without bound. 16 MB leaves enormous headroom for legitimate
execute_code stdout payloads.
* Broaden the close-mid-response catch to ConnectionResetError +
ConnectionAbortedError + BrokenPipeError. Previously only
ConnectionResetError was handled specifically; the others fell
through to the generic Exception handler with a less-actionable
message.
* Drop self.log.setLevel(logging.INFO) from MCPClient.__init__ — it
mutated the global module logger every time a client was constructed,
overriding the user's logging config.
* Bump execute_code's default timeout from 120s (inherited) to 600s
with a docstring explaining why — bpy.ops.render.render() and
similar can sit silent for many seconds without emitting data.
Test changes:
* test_send_command_assembles_chunked_response now actually splits
mid-emoji. The previous version split at offset 20, which landed in
pure ASCII; the UnicodeDecodeError path was uncovered. Compute the
split offset from the JSON-encoded payload (with ensure_ascii=False)
so the cut lands inside the 4-byte UTF-8 codepoint.
* New test_send_command_surfaces_enhanced_error_message — covers
_enhance_error_message, which had no prior test coverage.
* _ChunkedServer now serializes with ensure_ascii=False so multi-byte
payloads land on the wire as raw UTF-8 (matching the path the
UnicodeDecodeError tolerance defends against).
5/5 tests in tests/unit/mcp/test_blender_mcp_client.py pass; 123/123
in the broader scope; lint clean.
itomek
approved these changes
May 11, 2026
pull Bot
pushed a commit
to bhardwajRahul/gaia
that referenced
this pull request
May 12, 2026
…_refs (amd#1028) ## Why this matters Before: \`tests/unit/mcp/client/test_mcp_client.py::test_from_config_accepts_env\` fails at import on any dev environment without the optional \`keyring\` package, even though that test only passes plain string env vars and never exercises the \`\$keyring\` path. The unconditional \`import keyring\` at the top of \`_resolve_keyring_refs\` made keyring a hard dependency in practice for *every* config-driven MCP server load. After: imports for \`keyring\`, \`ConnectorsError\`, and \`SERVICE_NAME\` are deferred to the branch that actually needs them. Plain-env callers stay zero-dep on keyring; the security invariants and error handling for real \`\$keyring\` references are unchanged. Caught while reviewing amd#1026 — pre-existing issue, not introduced by that PR. ## Test plan - [x] \`pytest tests/unit/mcp/client/ -v\` — 25/25 pass (previously 24 pass + 1 fail) - [x] \`python util/lint.py --black --isort\` — clean --------- Co-authored-by: Ovtcharov <[email protected]>
pull Bot
pushed a commit
to bhardwajRahul/gaia
that referenced
this pull request
May 12, 2026
…md#1035) ## Why this matters Before: Code Quality CI fails on every PR with \`F401 'os' imported but unused\` at \`tests/unit/connectors/test_disconnect_clears_grants.py:18\`. Introduced incidentally by amd#998. Blocks amd#1026 and any subsequent PR from going green. After: import removed, flake8 exits clean. ## Test plan - [x] \`flake8 src/ tests/ --max-line-length=88 --extend-ignore=E203,W503,E501,F541,W291,W293,E402,F841,E722\` → 0 errors
pull Bot
pushed a commit
to bhardwajRahul/gaia
that referenced
this pull request
May 15, 2026
## Why this matters v0.18.0 ships agent memory v2 (hybrid-search second brain with LLM extraction and observability dashboard), ChatAgent split into three composable agents (Chat/FileIO/DocumentQA), parallel tool calls, and a Telegram adapter scaffold — plus fixes the RAG-on-PDF timeout with Gemma 4 that broke document Q&A since v0.17.6 and adds CI gates that enforce RAG quality baselines on every future PR. Full notes: `docs/releases/v0.18.0.mdx`. ## What's New - **Agent memory v2** ([amd#606](amd#606)) — Hybrid semantic + keyword search, LLM extraction, observability dashboard via SSE streaming ([amd#1032](amd#1032)). Per-user isolation enforced; extraction runs async so it doesn't add latency. - **ChatAgent split** ([amd#979](amd#979)) — `ChatAgent`, `FileIOAgent`, and `DocumentQAAgent` replace the monolithic class; each composable via `tools=`. Backward-compatible shim preserved. - **Parallel tool calls** ([amd#946](amd#946)) — Multiple `tool_calls` from a single LLM turn are executed concurrently, cutting round-trips for multi-tool workflows. - **Telegram adapter scaffold, Phase 0** ([amd#951](amd#951)) — `gaia telegram start|stop|status`, per-user session isolation, `[telegram]` extras. Phase 1 (message handling + allowed-users gate) tracked in [amd#889](amd#889). - **Connectors: per-MCP toggle + single-writer enforcement** ([amd#1018](amd#1018), [amd#998](amd#998)) — Disable individual MCP servers without removing them; concurrent writes serialised with actionable errors on contention. - **File navigation, web browsing, and write security** ([amd#495](amd#495)) — `FileSearchToolsMixin`, web browsing tool, and scratchpad mixin in `KNOWN_TOOLS`; write tools check `allowed_paths` before dispatch. - **Email UI and policy alerts** ([amd#995](amd#995), [amd#1039](amd#1039), [amd#952](amd#952)) — Pre-scan triage card, in-chat Connect, policy alert cards, and durable receipts for confirmation-gated actions. ## Bug Fixes - **RAG-on-PDF timeouts on Gemma 4** ([amd#1034](amd#1034), closes [amd#1030](amd#1030)) — Prompt-size budget check added at composition time; CI gates enforce it on every PR ([amd#1040](amd#1040)). - **Envelope-level parse failure crashed SD recovery** ([amd#1047](amd#1047), closes [amd#1023](amd#1023)) — Falls through to a clean recovery path with step-1 context preserved. - **Windows-path tool args corrupted** ([amd#1027](amd#1027)) — Backslash normalisation now happens after argument parsing. - **Blender `send_command` hung** ([amd#1026](amd#1026), closes [amd#1022](amd#1022)) — Read timeout applied to persistent-connection servers. - **`gaia chat init` in post-install banner** ([amd#1029](amd#1029), closes [amd#1024](amd#1024)) — Replaced with the correct `gaia init`. - **Keyring treated as required** ([amd#1028](amd#1028)) — Import guarded; optional on systems without `keyring`. - **electron-builder URLs stale** ([amd#953](amd#953)) — Three doc/installer files updated to current download paths. ## Tooling & Docs - **RAG eval CI gates** ([amd#1040](amd#1040), closes [amd#1033](amd#1033)) — RAG quality baselines + prompt-size budget enforced on every PR. - **Fork-PR authors now receive Claude review** ([amd#932](amd#932)) — `allowed_non_write_users: "*"` with prompt-injection mitigations documented. - **Eval runs mandated before merging** ([amd#1036](amd#1036)) — `CLAUDE.md` requires `gaia eval agent` for LLM-affecting changes. - **GAIA website** ([amd#369](amd#369)) — [amd-gaia.ai](https://amd-gaia.ai) live. - **Custom agent guide reorganised** ([amd#997](amd#997)), Lemonade PPA docs ([amd#801](amd#801)), broken Lemonade CLI URL fixed ([amd#996](amd#996)), WhatsApp adapter evaluation spec ([amd#950](amd#950)). ## Release checklist - [x] `util/validate_release_notes.py docs/releases/v0.18.0.mdx --tag v0.18.0` passes - [x] `src/gaia/version.py` → `0.18.0` - [x] `src/gaia/apps/webui/package.json` → `0.18.0` - [x] Navbar label in `docs/docs.json` → `v0.18.0 · Lemonade 10.2.0` - [x] All 28 commits in range (v0.17.6..HEAD) are represented in the notes - [ ] Review from @kovtcharov-amd addressed
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.
Why this matters
Before: on v0.17.6, running
gaia blender ...against the Blender MCP addon hangs forever after the first tool call (e.g.clear_scene), and Ctrl-C does not interrupt it. Reported in #1022.After:
send_commandreads the response incrementally and returns as soon as a complete JSON document parses out of the buffer — matching the framing the server already uses. A 30 s socket timeout also keeps Ctrl-C responsive.The bug was a protocol mismatch between client and server: the client looped on
recv()until FIN, but the Blender addon keeps the connection open to accept further commands on the same socket, so FIN never came. Both ends ended up blocked onrecv()waiting for each other.Adds
tests/unit/mcp/test_blender_mcp_client.py— a socket-level regression test using a fake persistent-connection server. Runs in CI without a Blender install.Fixes #1022. Plan for the broader Blender modernization is tracked in #1025.
Test plan