Skip to content

fix(mcp): isolate orphan-reap sleep mock - #27676

Closed
bbernstein616 wants to merge 1 commit into
NousResearch:mainfrom
bbernstein616:fix/mcp-orphan-reap-sleep-isolation-clean
Closed

fix(mcp): isolate orphan-reap sleep mock#27676
bbernstein616 wants to merge 1 commit into
NousResearch:mainfrom
bbernstein616:fix/mcp-orphan-reap-sleep-isolation-clean

Conversation

@bbernstein616

Copy link
Copy Markdown

Summary

  • Replaces the orphan-reap SIGTERM→SIGKILL delay with a private _orphan_reap_sleep indirection so tests can patch only the MCP sleep call instead of global time.sleep.
  • Updates MCP stability tests to patch the private helper and assert the intended single 2-second delay on both SIGKILL-present and SIGKILL-absent branches.

Why

PR #27656 currently includes an unrelated nous_portal security commit because it was based on the wrong branch. This is the same MCP fix rebased cleanly onto current origin/main, with only tools/mcp_tool.py and tests/tools/test_mcp_stability.py changed.

Verification

Supersedes #27656.

… threads

Patching ``tools.mcp_tool.time.sleep`` (the previous "fix") is identical to
patching the global ``time.sleep`` — ``tools.mcp_tool.time`` *is* the time
module, and ``sleep`` is a module attribute. On CI under pytest-xdist the
test_kill_orphaned_uses_sigkill_when_available mock captured 207k calls
because worker/heartbeat threads kept calling ``time.sleep(1)`` while the
mock was active, blowing up ``assert_called_once_with(2)``.

Introduce a private ``_orphan_reap_sleep`` indirection in tools.mcp_tool and
have the test patch that symbol instead. The wrapper is unique to mcp_tool
so unrelated background sleepers can't pollute the mock's call list.

Verified with a stress harness (background thread spamming time.sleep(1))
that previously caused thousands of phantom call(1)s — mock now sees only
the intended call(2).

Tests: tests/tools/test_mcp_stability.py — 16/16 pass.
       tests/tools/ -k mcp — 399/399 pass.
@alt-glitch alt-glitch added type/test Test coverage or test infrastructure P3 Low — cosmetic, nice to have comp/tools Tool registry, model_tools, toolsets tool/mcp MCP client and OAuth labels May 18, 2026
@bbernstein616

Copy link
Copy Markdown
Author

Hermes watchdog review: diff is scoped to tools/mcp_tool.py and tests/tools/test_mcp_stability.py; old polluted PR #27656 is closed. Independent verification on Bryan's machine using scripts/run_tests.sh: tests/tools/test_mcp_stability.py -> 16 passed; tests/tools/ -k mcp -> 399 passed (4 existing pytest.mark.ssh warnings). I attempted to merge after verification, but GitHub denied mergePullRequest for bbernstein616, so this is ready for someone with merge rights.

@bbernstein616

Copy link
Copy Markdown
Author

Watchdog verification update:

  • Reviewed patch: isolated MCP orphan-reap sleep via _orphan_reap_sleep; tests now patch that private helper instead of global time.sleep.
  • Independently verified:
    • scripts/run_tests.sh tests/tools/test_mcp_stability.py → 16 passed
    • scripts/run_tests.sh tests/tools/ -k mcp → 399 passed
  • Attempted squash merge after verification, but GitHub rejected it: bbernstein616 does not have the correct permissions to execute MergePullRequest.

Ready to merge by a maintainer. No force-push, no gateway restart.

@bbernstein616

Copy link
Copy Markdown
Author

Closing from my fork while moving this work private/protected.

@bbernstein616
bbernstein616 deleted the fix/mcp-orphan-reap-sleep-isolation-clean branch May 20, 2026 17:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

comp/tools Tool registry, model_tools, toolsets P3 Low — cosmetic, nice to have tool/mcp MCP client and OAuth type/test Test coverage or test infrastructure

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants