Fix live edit regression for Composable with nodes

Insert fixups were not cleaned up correctly on error, adding changes from the failed pass to next passes. This caused live edit to silently fail in 1.4 and crash in 1.5 if the exception was introduced during composition.

Test: LiveEditApiTests
Fixes: 275569974

Change-Id: Id92153ef0564ba68c4a39f461ba5e03a62cfeca5
diff --git a/compose/runtime/runtime/integration-tests/src/androidAndroidTest/kotlin/androidx/compose/runtime/BaseComposeTest.kt b/compose/runtime/runtime/integration-tests/src/androidAndroidTest/kotlin/androidx/compose/runtime/BaseComposeTest.kt
index 9eebe15..187595c 100644
--- a/compose/runtime/runtime/integration-tests/src/androidAndroidTest/kotlin/androidx/compose/runtime/BaseComposeTest.kt
+++ b/compose/runtime/runtime/integration-tests/src/androidAndroidTest/kotlin/androidx/compose/runtime/BaseComposeTest.kt
@@ -81,7 +81,7 @@
     uiThread {
         Choreographer.getInstance().postFrameCallback { latch.countDown() }
     }
-    assertTrue(latch.await(1, TimeUnit.HOURS), "Time-out waiting for choreographer frame")
+    assertTrue(latch.await(1, TimeUnit.MINUTES), "Time-out waiting for choreographer frame")
 }
 
 abstract class BaseComposeTest {
diff --git a/compose/runtime/runtime/integration-tests/src/androidAndroidTest/kotlin/androidx/compose/runtime/LiveEditApiTests.kt b/compose/runtime/runtime/integration-tests/src/androidAndroidTest/kotlin/androidx/compose/runtime/LiveEditApiTests.kt
index 549814d..b0e4d91 100644
--- a/compose/runtime/runtime/integration-tests/src/androidAndroidTest/kotlin/androidx/compose/runtime/LiveEditApiTests.kt
+++ b/compose/runtime/runtime/integration-tests/src/androidAndroidTest/kotlin/androidx/compose/runtime/LiveEditApiTests.kt
@@ -422,6 +422,36 @@
             assertThat(errors).hasSize(0)
         }
     }
+
+    @Test
+    @MediumTest
+    fun throwErrorOnReload_withNode() {
+        var shouldThrow = false
+        activity.show {
+            TestTextWError(text = "abc") { shouldThrow }
+        }
+
+        activity.waitForAFrame()
+
+        activityRule.runOnUiThread {
+            shouldThrow = true
+            simulateHotReload(Unit)
+
+            val start = textInvoked
+            var errors = compositionErrors()
+            assertThat(errors).hasSize(1)
+            assertThat(errors[0].first.message).isEqualTo("Text error!")
+            assertThat(errors[0].second).isEqualTo(true)
+
+            shouldThrow = false
+            invalidateGroup(errorKey) // wrong key, but composition should be retried regardless
+
+            assertTrue("TestTextWError should be invoked!", textInvoked > start)
+
+            errors = compositionErrors()
+            assertThat(errors).hasSize(0)
+        }
+    }
 }
 
 const val someFunctionKey = -1580285603 // Extracted from .class file
@@ -533,4 +563,16 @@
             error("Effect error!")
         }
     }
+}
+
+private var textInvoked = 0
+@Composable
+fun TestTextWError(text: String, shouldThrow: () -> Boolean = { true }) {
+    textInvoked++
+
+    Text(text)
+
+    if (shouldThrow()) {
+        error("Text error!")
+    }
 }
\ No newline at end of file
diff --git a/compose/runtime/runtime/src/commonMain/kotlin/androidx/compose/runtime/Composer.kt b/compose/runtime/runtime/src/commonMain/kotlin/androidx/compose/runtime/Composer.kt
index 7df2c189..a8119e1 100644
--- a/compose/runtime/runtime/src/commonMain/kotlin/androidx/compose/runtime/Composer.kt
+++ b/compose/runtime/runtime/src/commonMain/kotlin/androidx/compose/runtime/Composer.kt
@@ -1477,6 +1477,7 @@
         if (!writer.closed) {
             writer.close()
         }
+        insertFixups.clear()
         createFreshInsertTable()
         compoundKeyHash = 0
         childrenComposing = 0
@@ -1485,6 +1486,7 @@
         reusing = false
         isComposing = false
         forciblyRecompose = false
+        reusingGroup = -1
     }
 
     internal fun changesApplied() {