Index: modules/contextual/contextual.module
===================================================================
RCS file: /cvs/drupal/drupal/modules/contextual/contextual.module,v
retrieving revision 1.8
diff -u -r1.8 contextual.module
--- modules/contextual/contextual.module	11 Sep 2010 14:35:13 -0000	1.8
+++ modules/contextual/contextual.module	13 Sep 2010 16:51:03 -0000
@@ -106,7 +106,11 @@
     $element = $variables[$key];
   }
 
-  if (isset($element) && is_array($element) && !empty($element['#contextual_links'])) {
+  // If the element has theme wrappers, we only render the contextual links
+  // when the outermost theme wrapper function is being called. This allows
+  // blocks and other containing elements to properly inherit the contextual
+  // links of their children, without the links being rendered multiple times.
+  if (isset($element) && is_array($element) && !empty($element['#contextual_links']) && (empty($element['#theme_wrappers']) || $hook == end($element['#theme_wrappers']))) {
     // Initialize the template variable as a renderable array.
     $variables['title_suffix']['contextual_links'] = array(
       '#type' => 'contextual_links',
