Skip to content

Conversation

@jmartinesp
Copy link
Member

@jmartinesp jmartinesp commented Dec 12, 2025

Content

What the title says.

Motivation and context

Fix a crash observed in the wild, when there is an activity recreation with a room opened:

Exception java.lang.IllegalStateException: Room object has already been destroyed
  at org.matrix.rustcomponents.sdk.Room.predecessorRoom (matrix_sdk_ffi.kt:59362)
  at io.element.android.libraries.matrix.impl.room.RustBaseRoom.predecessorRoom (RustBaseRoom.kt:88)
  at io.element.android.libraries.matrix.impl.room.JoinedRustRoom.predecessorRoom (JoinedRustRoom.java:86)
  at io.element.android.features.messages.impl.timeline.TimelinePresenter.present$lambda$20$0 (TimelinePresenter.java:298)
  at androidx.compose.runtime.snapshots.Snapshot$Companion.observe (Snapshot.java:2495)
  at androidx.compose.runtime.DerivedSnapshotState.currentRecord (DerivedState.kt:210)
  at androidx.compose.runtime.DerivedSnapshotState.getCurrentRecord (DerivedState.kt:292)
  at androidx.compose.runtime.CompositionImpl.recordReadOf (Composition.kt:1026)
  at androidx.compose.runtime.Recomposer.readObserverOf$lambda$86 (Recomposer.java:1492)
  at androidx.compose.runtime.DerivedSnapshotState.getValue (DerivedState.kt:280)
  at io.element.android.features.messages.impl.timeline.TimelinePresenter.present$lambda$21 (TimelinePresenter.kt:586)
  at io.element.android.features.messages.impl.timeline.TimelinePresenter.present (TimelinePresenter.kt:310)
  at io.element.android.features.messages.impl.timeline.TimelinePresenter.present (TimelinePresenter.kt:77)
  at io.element.android.features.messages.impl.MessagesPresenter.present (MessagesPresenter.kt:158)
  at io.element.android.features.messages.impl.MessagesNode.View$lambda$0 (MessagesNode.java:242)
  at androidx.compose.runtime.internal.ComposableLambdaImpl.invoke (ComposableLambda.kt:121)
  at androidx.compose.runtime.internal.ComposableLambdaImpl.invoke (ComposableLambda.kt:51)
  at androidx.compose.runtime.CompositionLocalKt.CompositionLocalProvider (CompositionLocal.kt:390)
  at io.element.android.features.messages.impl.MessagesNode.View (MessagesNode.kt:239)
  at com.bumble.appyx.core.node.Node$Compose$1.invoke (Node.java:129)
  at com.bumble.appyx.core.node.Node$Compose$1.invoke (Node.java:127)
  at androidx.compose.runtime.internal.ComposableLambdaImpl.invoke (ComposableLambda.kt:121)
  at androidx.compose.runtime.internal.ComposableLambdaImpl.invoke (ComposableLambda.kt:51)
  at androidx.compose.runtime.CompositionLocalKt.CompositionLocalProvider (CompositionLocal.kt:370)
  at com.bumble.appyx.core.node.Node.Compose (Node.kt:124)
  at com.bumble.appyx.core.composable.ChildRendererImpl.invoke (Child.kt:84)
  at com.bumble.appyx.core.composable.ComposableSingletons$ChildrenKt$lambda-1$1.invoke (Children.kt:48)
  at com.bumble.appyx.core.composable.ComposableSingletons$ChildrenKt$lambda-1$1.invoke (Children.kt:47)
  at androidx.compose.runtime.internal.ComposableLambdaImpl.invoke (ComposableLambda.kt:142)
  at androidx.compose.runtime.internal.ComposableLambdaImpl.invoke (ComposableLambda.kt:51)
  at com.bumble.appyx.core.composable.ChildrenTransitionScope$children$1.invoke (Children.kt:139)
  at com.bumble.appyx.core.composable.ChildrenTransitionScope$children$1.invoke (Children.kt:138)
  at androidx.compose.runtime.internal.ComposableLambdaImpl.invoke (ComposableLambda.kt:154)
  at androidx.compose.runtime.internal.ComposableLambdaImpl.invoke (ComposableLambda.kt:51)
  at com.bumble.appyx.core.composable.ChildKt$Child$1.invoke (Child.kt:57)
  at com.bumble.appyx.core.composable.ChildKt$Child$1.invoke (Child.kt:46)
  at androidx.compose.runtime.internal.ComposableLambdaImpl.invoke (ComposableLambda.kt:121)
  at androidx.compose.runtime.internal.ComposableLambdaImpl.invoke (ComposableLambda.kt:51)
  at androidx.compose.runtime.CompositionLocalKt.CompositionLocalProvider (CompositionLocal.kt:370)
  at androidx.compose.runtime.saveable.SaveableStateHolderImpl.SaveableStateProvider (SaveableStateHolder.kt:82)
  at com.bumble.appyx.core.composable.ChildKt.Child (Child.kt:46)
  at com.bumble.appyx.core.composable.ChildrenTransitionScope$_children$3$1.invoke (ChildrenTransitionScope.java:202)
  at com.bumble.appyx.core.composable.ChildrenTransitionScope$_children$3$1.invoke (ChildrenTransitionScope.java:201)
  at androidx.compose.runtime.internal.ComposableLambdaImpl.invoke (ComposableLambda.kt:121)
  at androidx.compose.runtime.internal.ComposableLambdaImpl.invoke (ComposableLambda.kt:51)
  at androidx.compose.runtime.CompositionLocalKt.CompositionLocalProvider (CompositionLocal.kt:390)
  at com.bumble.appyx.core.composable.ChildrenTransitionScope._children (Children.kt:198)
  at com.bumble.appyx.core.composable.ChildrenTransitionScope.children (Children.kt:138)
  at io.element.android.features.messages.impl.MessagesFlowNode$View$lambda$0$$inlined$BackstackWithOverlayBox$2.invoke (Children.kt:215)
  at io.element.android.features.messages.impl.MessagesFlowNode$View$lambda$0$$inlined$BackstackWithOverlayBox$2.invoke (Children.kt:46)
  at androidx.compose.runtime.internal.ComposableLambdaImpl.invoke (ComposableLambda.kt:130)
  at androidx.compose.runtime.internal.ComposableLambdaImpl.invoke (ComposableLambda.kt:51)
  at io.element.android.features.messages.impl.MessagesFlowNode$View$lambda$0$$inlined$BackstackWithOverlayBox$5.invoke (MessagesFlowNode.java:96)
  at io.element.android.features.messages.impl.MessagesFlowNode$View$lambda$0$$inlined$BackstackWithOverlayBox$5.invoke (MessagesFlowNode.java:95)
  at androidx.compose.runtime.internal.ComposableLambdaImpl.invoke (ComposableLambda.kt:121)
  at androidx.compose.runtime.internal.ComposableLambdaImpl.invoke (ComposableLambda.kt:51)
  at androidx.compose.runtime.CompositionLocalKt.CompositionLocalProvider (CompositionLocal.kt:370)
  at io.element.android.features.messages.impl.MessagesFlowNode.View$lambda$0 (MessagesFlowNode.java:875)
  at androidx.compose.runtime.internal.ComposableLambdaImpl.invoke (ComposableLambda.kt:121)
  at androidx.compose.runtime.internal.ComposableLambdaImpl.invoke (ComposableLambda.kt:51)
  at androidx.compose.runtime.CompositionLocalKt.CompositionLocalProvider (CompositionLocal.kt:390)
  at io.element.android.features.messages.impl.MessagesFlowNode.View (MessagesFlowNode.kt:628)
  at com.bumble.appyx.core.node.Node$Compose$1.invoke (Node.java:129)
  at com.bumble.appyx.core.node.Node$Compose$1.invoke (Node.java:127)
  at androidx.compose.runtime.internal.ComposableLambdaImpl.invoke (ComposableLambda.kt:121)
  at androidx.compose.runtime.internal.ComposableLambdaImpl.invoke (ComposableLambda.kt:51)
  at androidx.compose.runtime.CompositionLocalKt.CompositionLocalProvider (CompositionLocal.kt:370)
  at com.bumble.appyx.core.node.Node.Compose (Node.kt:124)
  at com.bumble.appyx.core.composable.ChildRendererImpl.invoke (Child.kt:84)
  at com.bumble.appyx.core.composable.ComposableSingletons$ChildrenKt$lambda-1$1.invoke (Children.kt:48)
  at com.bumble.appyx.core.composable.ComposableSingletons$ChildrenKt$lambda-1$1.invoke (Children.kt:47)
  at androidx.compose.runtime.internal.ComposableLambdaImpl.invoke (ComposableLambda.kt:142)
  at androidx.compose.runtime.internal.ComposableLambdaImpl.invoke (ComposableLambda.kt:51)
  at com.bumble.appyx.core.composable.ChildrenTransitionScope$children$1.invoke (Children.kt:139)
  at com.bumble.appyx.core.composable.ChildrenTransitionScope$children$1.invoke (Children.kt:138)
  at androidx.compose.runtime.internal.ComposableLambdaImpl.invoke (ComposableLambda.kt:154)
  at androidx.compose.runtime.internal.ComposableLambdaImpl.invoke (ComposableLambda.kt:51)
  at com.bumble.appyx.core.composable.ChildKt$Child$1.invoke (Child.kt:57)
  at com.bumble.appyx.core.composable.ChildKt$Child$1.invoke (Child.kt:46)
  at androidx.compose.runtime.internal.ComposableLambdaImpl.invoke (ComposableLambda.kt:121)
  at androidx.compose.runtime.internal.ComposableLambdaImpl.invoke (ComposableLambda.kt:51)
  at androidx.compose.runtime.CompositionLocalKt.CompositionLocalProvider (CompositionLocal.kt:370)
  at androidx.compose.runtime.saveable.SaveableStateHolderImpl.SaveableStateProvider (SaveableStateHolder.kt:82)
  at com.bumble.appyx.core.composable.ChildKt.Child (Child.kt:46)
  at com.bumble.appyx.core.composable.ChildrenTransitionScope$_children$3$1.invoke (ChildrenTransitionScope.java:202)
  at com.bumble.appyx.core.composable.ChildrenTransitionScope$_children$3$1.invoke (ChildrenTransitionScope.java:201)
  at androidx.compose.runtime.internal.ComposableLambdaImpl.invoke (ComposableLambda.kt:121)
  at androidx.compose.runtime.internal.ComposableLambdaImpl.invoke (ComposableLambda.kt:51)
  at androidx.compose.runtime.CompositionLocalKt.CompositionLocalProvider (CompositionLocal.kt:390)
  at com.bumble.appyx.core.composable.ChildrenTransitionScope._children (Children.kt:198)
  at com.bumble.appyx.core.composable.ChildrenTransitionScope._children$lambda$7 (ChildrenTransitionScope.java:164)
  at androidx.compose.runtime.RecomposeScopeImpl.compose (RecomposeScopeImpl.java:196)
  at androidx.compose.runtime.ComposerImpl.recomposeToGroupEnd (Composer.kt:2895)
  at androidx.compose.runtime.ComposerImpl.skipCurrentGroup (Composer.kt:3231)
  at androidx.compose.runtime.ComposerImpl.doCompose-aFTiNEg (Composer.kt:3855)
  at androidx.compose.runtime.ComposerImpl.recompose-aFTiNEg$runtime (ComposerImpl.java:3779)
  at androidx.compose.runtime.CompositionImpl.recompose (Composition.kt:1075)
  at androidx.compose.runtime.Recomposer.performRecompose (Recomposer.kt:1373)
  at androidx.compose.runtime.Recomposer.access$performRecompose (Recomposer.kt:156)
  at androidx.compose.runtime.Recomposer$runRecomposeAndApplyChanges$2.invokeSuspend$lambda$22 (Recomposer.kt:627)
  at androidx.compose.ui.platform.AndroidUiFrameClock$withFrameNanos$2$callback$1.doFrame (AndroidUiFrameClock.java:39)
  at androidx.compose.ui.platform.AndroidUiDispatcher.performFrameDispatch (AndroidUiDispatcher.java:108)
  at androidx.compose.ui.platform.AndroidUiDispatcher.access$performFrameDispatch (AndroidUiDispatcher.java:41)
  at androidx.compose.ui.platform.AndroidUiDispatcher$dispatchCallback$1.doFrame (AndroidUiDispatcher.java:69)
  at android.view.Choreographer$CallbackRecord.run (Choreographer.java:1899)
  at android.view.Choreographer$CallbackRecord.run (Choreographer.java:1910)
  at android.view.Choreographer.doCallbacks (Choreographer.java:1367)
  at android.view.Choreographer.doFrame (Choreographer.java:1282)
  at android.view.Choreographer$FrameDisplayEventReceiver.run (Choreographer.java:1870)
  at android.os.Handler.handleCallback (Handler.java:995)
  at android.os.Handler.dispatchMessage (Handler.java:103)
  at android.os.Looper.loopOnce (Looper.java:273)
  at android.os.Looper.loop (Looper.java:363)
  at android.app.ActivityThread.main (ActivityThread.java:10060)
  at java.lang.reflect.Method.invoke
  at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run (RuntimeInit.java:632)
  at com.android.internal.os.ZygoteInit.main (ZygoteInit.java:975)

Tests

With a room open, cause an activity recreation. This can be quickly done with a foldable emulator or device by folding/unfolding the device.

Tested devices

  • Physical
  • Emulator
  • OS version(s): 16

Checklist

  • Changes have been tested on an Android device or Android emulator with API 24
  • UI change has been tested on both light and dark themes
  • Accessibility has been taken into account. See https://github.com/element-hq/element-x-android/blob/develop/CONTRIBUTING.md#accessibility
  • Pull request is based on the develop branch
  • Pull request title will be used in the release note, it clearly define what will change for the user
  • Pull request includes screenshots or videos if containing UI changes
  • You've made a self review of your PR

@jmartinesp jmartinesp requested a review from a team as a code owner December 12, 2025 07:10
@jmartinesp jmartinesp requested review from bmarty and removed request for a team December 12, 2025 07:10
@jmartinesp jmartinesp added the PR-Bugfix For bug fix label Dec 12, 2025
@github-actions
Copy link
Contributor

github-actions bot commented Dec 12, 2025

📱 Scan the QR code below to install the build (arm64 only) for this PR.
QR code
If you can't scan the QR code you can install the build via this link: https://i.diawi.com/jVQMue

@codecov
Copy link

codecov bot commented Dec 12, 2025

Codecov Report

❌ Patch coverage is 0% with 3 lines in your changes missing coverage. Please review.
✅ Project coverage is 81.38%. Comparing base (881877b) to head (4ac2322).
⚠️ Report is 2 commits behind head on develop.

Files with missing lines Patch % Lines
...android/libraries/matrix/impl/room/RustBaseRoom.kt 0.00% 3 Missing ⚠️
Additional details and impacted files
@@             Coverage Diff             @@
##           develop    #5894      +/-   ##
===========================================
- Coverage    81.38%   81.38%   -0.01%     
===========================================
  Files         2479     2479              
  Lines        66200    66202       +2     
  Branches      8431     8433       +2     
===========================================
+ Hits         53876    53877       +1     
- Misses        9221     9223       +2     
+ Partials      3103     3102       -1     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@jmartinesp
Copy link
Member Author

Actually, the root cause of this issue seems to be activity recreation causing the Room FFI object to be destroyed, but kept in memory and reused later.

Copy link
Member

@bmarty bmarty left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the fix! 2 non-blocking questions

override val graph = roomGraphFactory.create(inputs.room)

// This is an ugly hack to check activity recreation
private val currentActivity = mutableStateOf<Activity?>(null)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does it need to be a MutableState? Can't it just be of type Activity?? (like in LoginFlowNode for instance)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd need to double check if this could affect the stability of the composable. Since we're only assigning the value, maybe it won't.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It seems to be fine:

restartable skippable open scheme("[androidx.compose.ui.UiComposable]") fun io.element.android.appnav.room.joined.JoinedRoomLoadedFlowNode.View(
  unused stable modifier: Modifier
  stable <this>: JoinedRoomLoadedFlowNode
)

if (currentActivity.value?.isChangingConfigurations != true) {
activeRoomsHolder.removeRoom(inputs.room.sessionId, inputs.room.roomId)
inputs.room.destroy()
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe also reset the value of currentActivity?

@jmartinesp jmartinesp force-pushed the fix/fix-crash-when-calling-predecessorroom-from-timelinepresenter branch from 746f49a to 9012160 Compare December 12, 2025 09:06
@jmartinesp jmartinesp force-pushed the fix/fix-crash-when-calling-predecessorroom-from-timelinepresenter branch from 9012160 to 4ac2322 Compare December 12, 2025 09:28
@sonarqubecloud
Copy link

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

PR-Bugfix For bug fix

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants