Skip to content

fix(blender): unblock send_command hang against persistent-connection server (#1022) - #1026

Merged
kovtcharov merged 3 commits into
mainfrom
kalin/fix-1022-blender-hang
May 11, 2026
Merged

kovtcharov merged 3 commits into
mainfrom
kalin/fix-1022-blender-hang

Conversation

@kovtcharov

Copy link
Copy Markdown
Contributor

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_command reads 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 on recv() 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

  • `pytest tests/unit/mcp/test_blender_mcp_client.py -v` — passes in <1 s
  • `pytest src/gaia/agents/blender/tests/test_mcp_client.py -v` — still skips cleanly without a Blender server
  • `python util/lint.py --black --isort` — clean
  • Manual smoke: `gaia blender --example 1` against a real Blender 4.5 + addon (delegated to issue reporter via [Bug]: blender agent hangs in tool execution #1022)

… 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.
@github-actions github-actions Bot added mcp MCP integration changes tests Test changes labels May 10, 2026
…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.
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.
@kovtcharov
kovtcharov added this pull request to the merge queue May 11, 2026
Merged via the queue into main with commit 546a226 May 11, 2026
30 of 31 checks passed
@kovtcharov
kovtcharov deleted the kalin/fix-1022-blender-hang branch May 11, 2026 20:31
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
@itomek itomek mentioned this pull request May 14, 2026
5 of 6 tasks
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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

mcp MCP integration changes tests Test changes

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: blender agent hangs in tool execution

2 participants