Skip to content

fix(blender,freecad): keep a blank port in the config from killing the server - #69

Merged
JJJYmmm merged 2 commits into
QwenLM:mainfrom
Lesereingrape:fix/tolerate-bad-port-config
Oct 1, 2026
Merged

JJJYmmm merged 2 commits into
QwenLM:mainfrom
Lesereingrape:fix/tolerate-bad-port-config

Conversation

@Lesereingrape

Copy link
Copy Markdown
Contributor

What changed

Six port reads go from int(get_env(...)) to a new shared.env.get_int_env(...), so a port the loader
cannot parse falls back to the documented default instead of aborting.

setting read by before after
BLENDER_PORT blender loader.get_connection / loader.probe / _launch ValueError out of int('') 9876
FREECAD_RPC_PORT freecad loader.get_connection / loader.probe / _launch ValueError out of int('') 9875

get_int_env is a sibling of the existing get_bool_env in src/shared/env.py, and it follows the
rule the repo already committed to for the QWEN_MM_* knobs — _int_env's docstring says a bad value
"logs a warning and falls back to the default instead of raising", and tests/test_env_config.py
opens with "a bad size/timeout config value must NOT crash the server". Unset, blank, and whitespace
count as unset; an unparseable value warns with the var name and returns the default. Unlike
_int_env it takes a plain integer, because a port has no byte-size spelling to accept.

Two of the six sites are the reason this matters more than a typo: on_start() → probe() runs once
the transport is open and before the MCP initialize handshake (mcp_framework.py:279), so the
raise kills the server rather than one tool call; and in get_connection() the raise replaces the
careful Could not connect to Blender at host:port … guidance with a bare traceback.

Before / after, same poisoned config

--set BLENDER_PORT= on the real CLI stores the blank line in the config file the server reads
(~/.qwen-mm-plugins/config, or $QWEN_MM_CONFIG), then loader.probe() runs on each checkout:

main (7f7ca38)  ValueError: invalid literal for int() with base 10: ''
                                  # at src/capabilities/blender/.../loader.py:192
this branch     Blender not reachable on localhost:9876. Start it with
                `qwen-mm-plugins-blender --launch-app` before using tools, or set
                QWEN_MM_AUTOLAUNCH=1 (see SKILL.md).

The second line is the behaviour the code already wants for a stopped Blender — the config parse
failure was preempting it, so the user never saw the actionable hint.

Why a blank value is reachable through the documented interface

--set is documented as the non-interactive path "for automation", and set_config filters None
but not "" (shared/env.py:122), so --set BLENDER_PORT=$PORT with PORT unset stores
BLENDER_PORT=. That line is what get_env then returns instead of the default. The repo already treats storing one as wrong in the
other two write paths — del_config's docstring ("Clearing must delete the line, not write KEY= —
an empty config value would shadow a real default", shared/env.py:130), install.sh:1668
(elif [ -n "$newv" ]) and --setup (mcp_framework.py:425, if not v: continue; the docstring at
:400 states the rule outright: "blank keeps the current value, - clears it (removed, not written
empty)"). This PR fixes the readers rather than changing --set's
contract, so a config file that is already poisoned stops breaking on upgrade.

Verification

F="src/shared/env.py src/capabilities/blender/qwen_mm_plugins_blender/loader.py \
src/capabilities/blender/qwen_mm_plugins_blender/_launch.py \
src/capabilities/freecad/qwen_mm_plugins_freecad/loader.py \
src/capabilities/freecad/qwen_mm_plugins_freecad/_launch.py tests/test_env_config.py"

python3 -m pytest -q -m "not reachability" tests/test_env_config.py           # 34 passed
python3 -m pytest -q -m "not reachability" tests/test_env_config.py \
        tests/test_blender.py tests/test_freecad.py                           # 52 passed
python3 scripts/check_manifests.py                                            # OK — 15 capabilities consistent
python3 -m ruff format --check $F                                             # 6 files already formatted
python3 -m ruff check $F                                                      # All checks passed!

RED/GREEN for the new startup regression:

  • RED — the test run verbatim against 7f7ca38's own source in a separate checkout: 2 failed,
    ValueError: invalid literal for int() with base 10: '' at blender/loader.py:192 and
    freecad/loader.py:169
  • GREEN — tests/test_env_config.py on this branch: 34 passed

The full suite was run on Windows, where CI has no test job (the matrix is ubuntu + macOS and the
windows job only checks out): 15 failed / 1056 passed / 97 skipped on this branch and
16 failed / 1046 passed / 97 skipped on the untouched 7f7ca38 checkout, with identical failure
lists apart from test_isolated_worker.py::test_isolated_worker_timeout, a subprocess-spawn
PermissionError that failed on main in its full run and passed there when re-run alone, and the
other way round on this branch. The remaining 15 names are bash-/POSIX-dependent
(test_install_sh.py, test_tag_plugin_release.py) or Windows-path-dependent (test_mhs.py,
test_omni_*.py); since the two lists otherwise match line for line, this change adds no failure.

No tool name, input schema or output changed, so no docs or plugin-versions.json update is needed.

Two things I deliberately left out

  • src/capabilities/video-memory/skill/script/build_memory/build_graph.py:55 has the same
    int(get_env("OSS_URL_EXPIRY", …)) shape, but that tree reads a trimmed private copy of the env
    module (build_memory/env_config.py, no get_int_env in it), so fixing it is a separate change
    with a different blast radius. Happy to follow up.
  • Making --set KEY= refuse to write the blank line (matching --setup) is arguably the other half of
    this. I kept it out to keep this PR to one concern; the reader fix alone already covers both the
    --set and the hand-edited-file cases.

Relates to #60 — that PR routes four on/off flags through get_bool_env; this one covers the
integer reads, so different settings and different behaviour. We do both touch
src/capabilities/freecad/qwen_mm_plugins_freecad/loader.py, on two separate lines: its
only_text_feedback() body, and this file's import plus the two port reads. If #60 lands first the from shared.env import … line needs
both names, which is a one-word merge.

Fixes #68

…e server

Both launchable-app servers read their port with int(get_env(...)) inside
on_start() -> probe(), which runs once the transport is open and before the MCP
initialize handshake. A `BLENDER_PORT=` line -- what `--set BLENDER_PORT=` writes,
since set_config filters None but not "" -- makes get_env return an empty string
instead of the documented default, and int('') aborts the whole server with a raw
ValueError instead of the actionable "Could not connect to Blender at ..." message.

shared.env._int_env already encodes this rule for the QWEN_MM_* knobs ("a bad value
must not crash the server"), and tests/test_env_config.py exists to lock it in. This
completes the migration for the plain integers: a new get_int_env sibling of
get_bool_env falls back to the default for unset/blank/unparseable values, and the
six port reads go through it.
@JJJYmmm
JJJYmmm merged commit b96cd87 into QwenLM:main Oct 1, 2026
11 checks passed
@JJJYmmm

JJJYmmm commented Oct 1, 2026

Copy link
Copy Markdown
Collaborator

TY! the other bugs are fixed in #79 and #80.

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Blank or unparseable BLENDER_PORT / FREECAD_RPC_PORT in the config aborts the server at startup

2 participants