Repository navigation
fix(mcp): isolate notifier subprocess stdin and sanitize desktop notification strings - #58
Open
rksharma-owg wants to merge 1 commit into
Open
rksharma-owg wants to merge 1 commit into
rksharma-owg wants to merge 1 commit into
Conversation
… strings When Artemis runs as an MCP stdio server, child processes spawned without stdin=subprocess.DEVNULL inherit sys.stdin and can consume incoming JSON-RPC bytes, causing protocol corruption and communication hangs. This change: - Sets stdin=subprocess.DEVNULL on all subprocess.run calls in AgentApiNotifier, DesktopNotifier, and ScriptNotifier. - Adds string escaping and newline sanitization for macOS AppleScript and Windows PowerShell desktop notifications to prevent syntax breakage and execution errors when notifications contain quotes, backslashes, or multiline strings. - Adds comprehensive unit regression tests in test_mcp_stdio_lifecycle.py.
giveUphope
added a commit
to giveUphope/autoGamer
that referenced
this pull request
Oct 12, 2026
用户点名的失效正是本会话我自己撞的三种,google#58 逐条带命令: ① 未核实就叙述"已完成"(我写过"方案甲已落地 / google#50 / G63 / 188 项测试",git 核对全不存在, 当时 HEAD 8eecb39、条目 49 条)——只留在对话里,但照它继续做就会去验收不存在的东西; ② 新事实推翻旧行而旧行还在(§零"CI 用 spike-mcp 做比对"grep 0 命中、"CI 侧全绿"那次 run 整体 failure,google#53 已更正); ③ 派生数不回抄与替换不校验命中(google#45/google#56)。 四条判据:当轮必落一次文档提交并改到受影响那一行(验收带 git grep 反判据,本身要能红); 否定旧表述必须改掉或标作废加出处;说"已完成 X"必须指到 commit 或命令输出,否则写"待做"; 派生计数只留复测命令。与 R24(从哪取证)、R27(锁会不会红)同族 —— R28 管"取到的证有没有 落到别人会读的地方"。
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.
Summary
When Artemis runs as an MCP stdio server (e.g. within Antigravity, Cursor, or Claude Desktop), child subprocesses spawned without
stdin=subprocess.DEVNULLcan inherit the parent process's MCP stdio stream, creating a risk of protocol interference or channel stalls if a subprocess interacts with standard input.Additionally, desktop notifications on macOS via
osascriptconstructed inline AppleScript strings using raw f-strings. If a message or title contained double quotes ("), backslashes (\\), or newlines,osascriptfailed with AppleScript syntax errors (such as error-2740), causing notifications to be dropped.This PR addresses both areas:
stdin=subprocess.DEVNULLacross allsubprocess.runinvocations inAgentApiNotifier,DesktopNotifier(Linux, macOS, and Windows notification commands), andScriptNotifier, ensuring compatibility with existing stdout/stderr behavior while isolating standard input.escape_applescript_stringandescape_powershell_stringinmcp_server/notifiers/desktop.pyto safely escape quotes and backslashes and normalize newlines into spaces while preserving apostrophes and Unicode.tests/unit/mcp/test_mcp_stdio_lifecycle.pywith tests verifying stdin isolation acrossAgentApiNotifier,DesktopNotifier(on Linux, Darwin, and Windows), andScriptNotifier, alongside string sanitization tests.Changes
mcp_server/notifiers/agentapi.py: Addedstdin=subprocess.DEVNULLto bothsubprocess.runinvocations.mcp_server/notifiers/desktop.py: Addedescape_applescript_stringandescape_powershell_string; addedstdin=subprocess.DEVNULLtonotify-send,osascript, andpowershellsubprocess calls.mcp_server/notifiers/script.py: Addedstdin=subprocess.DEVNULLto custom script runnersubprocess.run.tests/unit/mcp/test_mcp_stdio_lifecycle.py: Added regression test coverage for stdin isolation and string escaping, and hermetic adb mocks.tests/unit/mcp/test_notifiers.py: Updatedmock_runsignature intest_agentapi_notifier_candidate_recovery_and_retryto accept**kwargs/stdin.Validation Performed
uv run pytest -v tests/unit/mcp/test_mcp_stdio_lifecycle.py(14/14 passed)uv run pytest -v tests/unit/mcp(228 passed, 1 skipped)uv run ruff check mcp_server/notifiers tests/unit/mcp(All checks passed)uv run ruff format --check mcp_server/notifiers tests/unit/mcp/test_mcp_stdio_lifecycle.py tests/unit/mcp/test_notifiers.py(Clean)uv run pyright --project pyright-core.json(0 errors, 0 warnings)