Skip to content

v0.21.2-alpha — list_documents and sandbox segfault fixes

Latest

Choose a tag to compare

@ghbalf ghbalf released this 15 Aug 20:32
· 3 commits to master since this release

Two crash fixes, both reported and fixed by @s-light, merged with regression tests.

Fixed

list_documents raised AttributeError on every FreeCAD 1.1.x session (#57, PR #56)

The handler read doc.Modified, but App.Document has no such property — the dirty flag lives on the Gui document. This broke the tool for all users on 1.1.x, not only the Flatpak build it was reported against. The flag now comes from Gui.getDocument(name).Modified, falling back to False when there is no GUI (the STDIO MCP server entry point runs headless) or when the document is unknown to the Gui layer.

Sandbox pre-check picked the wrong FreeCAD install (#58)

_find_freecad_cmd() guessed from ~/bin AppImages and PATH, which could resolve to a completely unrelated install — a Snap package on PATH while the live session runs from a Flatpak. That foreign binary loads its own incompatible Draft/Arch/PySide stack and segfaults. The console binary is now resolved from the running session's own FreeCAD.getHomePath() first, which is guaranteed to match; the existing AppImage/PATH chain remains as a fallback for builds that ship no freecadcmd.

Sandbox segfaulted on any code importing Arch/BIM (#58)

The harness imported the real FreeCADGui and then patched ActiveDocument to a no-op — but the crash happens during the import: the real module pulls in PySide/Qt, and anything that later touches Arch dies in C++ where no Python handler can catch it. The harness now installs a fake FreeCADGui module into sys.modules, so the real one is never imported. Together with the fix above, this unblocks any execute_code path that imports Arch/BIM, which was previously impossible to run.

Upgrade note

The fake FreeCADGui used by the sandbox pre-check defines exactly three names — ActiveDocument, SendMsgToActiveView and updateGui. The no-op absorption applies below Gui.ActiveDocument (so view cosmetics like viewIsometric() and fitAll() still succeed silently), not to the module itself.

Any other Gui attribute now raises AttributeError in the pre-check — notably Gui.Selection and Gui.getDocument(), which the real module provides. Generated code that reads the selection will fail the pre-check while running fine against the live document. Guard the access with getattr(Gui, "Selection", None), pass object names explicitly instead, or use Dangerous mode, which skips the pre-check entirely.

Testing

1076 unit tests pass. Both defects had zero prior coverage — _handle_list_documents and _find_freecad_cmd were untested, which is why #57 shipped broken for every 1.1.x user. All new tests were confirmed failing against the unfixed code.

Verification was the unit suite plus a headless reproduction; the Flatpak and Snap resolution paths could not be exercised directly on the maintainer's setup (AppImage on Linux). Please open an issue if the pre-check still resolves the wrong binary for you.

Full changelog: v0.21.1-alpha...v0.21.2-alpha