Skip to content

ref(android): [Nav3 Lifecycle 1] Add NavLeaseCoordinator - #6302

Open
0xadam-brown wants to merge 3 commits into
feat/sentry-nav-effect-lifecyclefrom
feat/part-1-sentry-nav-effect-lifecycle
Open

0xadam-brown wants to merge 3 commits into
feat/sentry-nav-effect-lifecyclefrom
feat/part-1-sentry-nav-effect-lifecycle

Conversation

@0xadam-brown

@0xadam-brown 0xadam-brown commented Oct 20, 2026 •

Copy link
Copy Markdown
Member

PR Stack (Nav3 Lifecycle)


📜 Description

Add the lifecycle-aware lease state machine used to coordinate multiple Navigation 3 roots that share Sentry scope state.

The coordinator selects one eligible lifecycle owner at a time, preserves displaced navigation transactions for restoration, and clears or finishes retained state when owners leave.

💡 Motivation and Context

Overlapping Activities and Fragments can keep multiple SentryNavEffect instances alive simultaneously. A deterministic ownership policy is needed before their scope writes can be safely coordinated.

addresses: JAVA-785

💚 How did you test it?

  • Unit tests
  • Integration tests (included in a later PR)
  • New Nav3 sample app flows (also in a later PR) + having my clanker perform lots of thorough manual testing

📝 Checklist

  • I added GH Issue ID & Linear ID
  • I added tests to verify the changes.
  • No new PII added or SDK only sends newly added PII if sendDefaultPII is enabled.
  • I updated the docs if needed.
  • I updated the wizard if needed.
  • Review from the native team if needed.
  • No breaking change or entry added to the changelog.
  • No breaking change for hybrid SDKs or communicated to hybrid SDKs.
  • Public API changes reviewed by another Mobile SDK team member or implemented according to the develop docs spec.

🔮 Next steps

The next PR adds the lease-aware scope façade that consumes this coordinator.

#skip-changelog

⚠️ Merge this PR using a merge commit (not squash). Only the collection branch is squash-merged into main.

@linear-code

linear-code Bot commented Oct 20, 2026

Copy link
Copy Markdown

JAVA-274

@sentry

sentry Bot commented Oct 20, 2026 •

Copy link
Copy Markdown

📲 Install Builds

Android

🔗 App Name App ID Version Configuration
SDK Size io.sentry.tests.size 8.61.0 (1) release

⚙️ sentry-android Build Distribution Settings

@0xadam-brown
0xadam-brown marked this pull request as ready for review October 20, 2026 15:30
@0xadam-brown 0xadam-brown added the sanity-check PR needs a lightweight review for obvious issues label Oct 20, 2026
@0xadam-brown 0xadam-brown changed the title ref(android): [Nav3 Lifecycle 1] Add navigation lease coordinator ref(android): [Nav3 Lifecycle 1] Add NavLeaseCoordinator Oct 20, 2026
0xadam-brown and others added 3 commits October 21, 2026 12:10
Introduce the lifecycle-aware lease state machine that selects which navigation root may publish shared scope state and bind navigation transactions.

Refs JAVA-274
Always forget departing navigation candidates when transaction cleanup or
lease handoff fails. Preserve a successor selected before a callback throws.

Add regression coverage for cleanup failures and successor lease ownership.

Refs JAVA-274
Co-Authored-By: Codex <noreply@openai.com>
transferLeaseTo assigned the lease before clearing the previous owner's
published nav data. When that callback threw, the new leaseholder was
recorded against a stale publisher, so a later handoff cleared the wrong
owner's data and never cleared the leaseholder's own.

Always record the incoming candidate as the publisher once it takes the
lease. Add regression coverage for handoff cleanup failures.

Refs JAVA-274

@runningcode runningcode left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

LGTM! thanks for all the docs. Just a note, i feel like the exception semantics part doesn't really help me understand what I'm supposed to do here when using the class. Like does that mean I'm supposed to catch arbitrary exceptions or just ignore them?

implementation(projects.sentry)

compileOnly(libs.androidx.compose.runtime)
// Provides lifecycle types used to coordinate overlapping navigation roots. Hosts get it at

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

i don't think we need this comment

* **Thread safety**
*
* This class is ***not*** thread-safe. All `NavScopes` instances using this coordinator must
* confine their access to the same thread.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

just for my understanding? is this generally the main thread? mostly wondering about performance.

* confine their access to the same thread.
*/
@Suppress("TooManyFunctions")
internal class NavLeaseCoordinator {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

i guess i never asked myself this question before but if a class is internal, can we automatically assume it is @ApiStatus.Internal ?

private var resumeOrder: Long = 0

/**
* Registers [owner] as a candidate for the nav lease. No-ops if `owner` is already registered or

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

nit: owner being already registered is determined by object reference. makes sense! I'm just wondering noting in the doc. i imagine a case where there are many "WebViewScreens" and nobody writes equals/hashcode for those.

This branch has not been deployed

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

Labels

sanity-check PR needs a lightweight review for obvious issues

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants