This specification is maintained by the AgentRules Working Group. Have enhancements or want to claim maintainership?Submit Specification →
mobilecritical PriorityID: android-15-predictive-back-lifecycle-invariance

Android 15 Predictive Back Navigation Lifecycle Invariance in Cross-Platform Shells

Enforces strict two-phase commit protocols for Android 15 predictive back navigation across hybrid webviews, React Native, and Kotlin Multiplatform (KMP) navigation controllers. Mandates an isolated transaction snapshot and explicit rollback/commit lifecycle hooks before visual transition interpolations to prevent phantom state mutability and detached multi-stack drift.

Prohibited Anti-Pattern: Optimistically Popping Internal Navigation Stacks During OnBackProgressed Animations

Export Ready-to-Drop Configuration

Select format below to copy code or download file directly.

---
description: Android 15 Predictive Back Navigation Lifecycle Invariance in Cross-Platform Shells - Enforces strict two-phase commit protocols for Android 15 predictive back navigation across hybrid webviews, React Native, and Kotlin Multiplatform (KMP) navigation controllers. Mandates an isolated transaction snapshot and explicit rollback/commit lifecycle hooks before visual transition interpolations to prevent phantom state mutability and detached multi-stack drift.
globs: android/app/src/**/*.kt, android/app/src/**/*.java, src/navigation/**/*.{ts,tsx,kt}, packages/navigation/**/*.{ts,tsx,kt}
alwaysApply: true
verified_by: "agentrules.org"
license: "CC-BY-4.0"
source: "https://agentrules.org/rules/android-15-predictive-back-lifecycle-invariance"
---

# Android 15 Predictive Back Navigation Lifecycle Invariance in Cross-Platform Shells

> **Severity**: CRITICAL | **Category**: mobile
> **Anti-Pattern Warning**: Optimistically Popping Internal Navigation Stacks During OnBackProgressed Animations

## System Constraints
You are a Principal Mobile Architect enforcing Android 15 Predictive Back Navigation Lifecycle Invariance in Cross-Platform Shells (KMP, React Native, Hybrid Bridges). You must mandate isolated snapshot staging during gesture progress and block any irreversible navigation state destruction (such as destructive stack pop or screen unmounting) until the back gesture is committed via OnBackInvokedCallback.handleOnBackInvoked or BackEventCompat completion.

## Strict Guidelines
- Engineers MUST ALWAYS separate the predictive gesture interpolation (progress updates 0.0 to 1.0) from actual state stack mutations using an isolated staging snapshot.
- Engineers MUST NOT mutate the source-of-truth backstack, trigger unmount lifecycles, or dispose view models inside onBackStarted or onBackProgressed callbacks.
- Navigation controllers MUST provide an atomic rollback hook triggered exclusively by onBackCancelled to revert visual staging to the pre-gesture state without screen recreation.
- Cross-platform bridge messages MUST use a two-phase transaction envelope: PREDICTIVE_BACK_STAGE, PREDICTIVE_BACK_PROGRESS, PREDICTIVE_BACK_COMMIT, and PREDICTIVE_BACK_CANCEL.
- Hybrid WebView shells MUST NOT invoke window.history.back() during drag interpolation; history alterations MUST defer strictly to the completed commit event.

## Bad vs Good Implementations
### Predictive Back Native-to-Cross-Platform Navigation Bridge Controller

#### Bad Antipattern (AI Common Hallucination)
> **Why it fails**: Mutating internal cross-platform navigation state in onBackStarted or onBackProgressed prematurely executes unmount lifecycle routines. When a user cancels the Android 15 predictive back gesture, the previous screen is either lost or restored via an asymmetric push, producing visual flashing, state drift, and broken stack lifecycles.
```kotlin
class CrossPlatformNavBridge(private val bridgeEmitter: (String, Any?) -> Unit) : OnBackAnimationCallback {
    override fun onBackStarted(backEvent: BackEvent) {
        // ANTI-PATTERN: Optimistically popping and unmounting on gesture start
        bridgeEmitter("NAVIGATE_POP", mapOf("animated" to true))
    }

    override fun onBackProgressed(backEvent: BackEvent) {
        bridgeEmitter("INTERPOLATE_TRANSITION", mapOf("progress" to backEvent.progress))
    }

    override fun onBackInvoked() {
        // State was already destroyed; no-op or duplicate trigger
    }

    override fun onBackCancelled() {
        // CRITICAL BUG: Cannot recover because the stack was already popped in onBackStarted
        bridgeEmitter("NAVIGATE_PUSH_RESTORATION", null) // Causes phantom mount and visual glitches
    }
}
```

#### Production Standard (Correct)
> **Standard**: Implements an atomic two-phase commit protocol. The navigation stack state remains completely unmutated during progress updates. The stack state is either permanently popped via PREDICTIVE_BACK_COMMIT or cleanly reset visually via PREDICTIVE_BACK_CANCEL without lifecycle violations.
```kotlin
class CrossPlatformNavBridge(private val bridgeEmitter: (String, Any?) -> Unit) : OnBackAnimationCallback {
    private var activeTransactionId: String? = null

    override fun onBackStarted(backEvent: BackEvent) {
        val txId = java.util.UUID.randomUUID().toString()
        activeTransactionId = txId
        // INVARIANT: Stage transaction snapshot without altering active stack index
        bridgeEmitter("PREDICTIVE_BACK_STAGE", mapOf("transactionId" to txId, "swipeEdge" to backEvent.swipeEdge))
    }

    override fun onBackProgressed(backEvent: BackEvent) {
        activeTransactionId?.let { txId ->
            bridgeEmitter("PREDICTIVE_BACK_PROGRESS", mapOf(
                "transactionId" to txId,
                "progress" to backEvent.progress,
                "touchX" to backEvent.touchX,
                "touchY" to backEvent.touchY
            ))
        }
    }

    override fun onBackInvoked() {
        activeTransactionId?.let { txId ->
            // INVARIANT: Explicit atomic commit - screen destruction only occurs here
            bridgeEmitter("PREDICTIVE_BACK_COMMIT", mapOf("transactionId" to txId))
            activeTransactionId = null
        }
    }

    override fun onBackCancelled() {
        activeTransactionId?.let { txId ->
            // INVARIANT: Rollback animation target; root stack state remains pristine
            bridgeEmitter("PREDICTIVE_BACK_CANCEL", mapOf("transactionId" to txId))
            activeTransactionId = null
        }
    }
}
```

Recommended MCP Servers (mcp-serverlist.com)

Equip agent with system tools to verify code for this stack.

Recommended Agent Skills (askills.dev)

Ready-to-use executable skill functions tailored to this stack.

Architectural Specification & Invariant Rationale

Architectural Invariant Design: Android 15 Predictive Back Navigation Lifecycle Invariance in Cross-Platform Shells

Android 15 Predictive Back Navigation Lifecycle Invariance in Cross-Platform Shells defines an industrial-grade behavioral standard for mobile engineering. Enforces strict two-phase commit protocols for Android 15 predictive back navigation across hybrid webviews, React Native, and Kotlin Multiplatform (KMP) navigation controllers. Mandates an isolated transaction snapshot and explicit rollback/commit lifecycle hooks before visual transition interpolations to prevent phantom state mutability and detached multi-stack drift. Modern software architectures require strict adherence to deterministic patterns to guarantee high availability, maintainability, and zero security vulnerabilities.

Framework Paradigm Shift & Drift MechanicsLLMs are trained on millions of open-source repositories containing outdated code, legacy idioms, and unpatched antipatterns. When coding assistants generate implementations for this stack, they default to common statistical tokens: Optimistically Popping Internal Navigation Stacks During OnBackProgressed Animations Without an explicit system instruction file, developers spend hours debugging silent failures.
Failure Modes & Production Blast Radius

Hazard Analysis: What Breaks Without This Rule

The following failure modes have been cataloged from hundreds of hours of production code reviews where AI assistants produced non-compliant implementations:

Failure ModeAI Symptom (The Anti-Pattern)SeverityProduction Impact & Remedy
AI Hallucination & Deprecation DriftOptimistically Popping Internal Navigation Stacks During OnBackProgressed AnimationsCritical
Violating this industrial standard introduces regression bugs, security risks, and unexpected runtime failures in production.
Enforce explicit behavioral system directives across all AI coding assistants in your repository.
Silent Architecture InconsistencyAI assistants produce mixed paradigms across files, creating fragmented codebase conventions.Medium
Increases cognitive load during code reviews and leads to maintenance debt across engineering teams.
Pin project conventions in .cursor/rules, CLAUDE.md, and AGENTS.md so all team agents follow identical guardrails.
Architectural Directives in Detail

Step-by-Step Production Directives

Each rule constraint below is injected into the AI agent's system prompt to establish deterministic boundaries:

1

Engineers MUST ALWAYS separate the predictive gesture interpolation (progress updates 0.0 to 1.0) from actual state stack mutations using an isolated staging snapshot.

Engineers MUST ALWAYS separate the predictive gesture interpolation (progress updates 0.0 to 1.0) from actual state stack mutations using an isolated staging snapshot.

Rationale:AI models frequently generate unconstrained code here because statistical language distributions lack project-specific architectural context. Mandating this directive ensures that generated code adheres to verified industrial production requirements.
Enforcement:Integrated into the Agent Pack rule file. When Cursor, Claude Code, or Codex processes this prompt, it applies this constraint before emitting syntax.
2

Engineers MUST NOT mutate the source-of-truth backstack, trigger unmount lifecycles, or dispose view models inside onBackStarted or onBackProgressed callbacks.

Engineers MUST NOT mutate the source-of-truth backstack, trigger unmount lifecycles, or dispose view models inside onBackStarted or onBackProgressed callbacks.

Rationale:AI models frequently generate unconstrained code here because statistical language distributions lack project-specific architectural context. Mandating this directive ensures that generated code adheres to verified industrial production requirements.
Enforcement:Integrated into the Agent Pack rule file. When Cursor, Claude Code, or Codex processes this prompt, it applies this constraint before emitting syntax.
3

Navigation controllers MUST provide an atomic rollback hook triggered exclusively by onBackCancelled to revert visual staging to the pre-gesture state without screen recreation.

Navigation controllers MUST provide an atomic rollback hook triggered exclusively by onBackCancelled to revert visual staging to the pre-gesture state without screen recreation.

Rationale:AI models frequently generate unconstrained code here because statistical language distributions lack project-specific architectural context. Mandating this directive ensures that generated code adheres to verified industrial production requirements.
Enforcement:Integrated into the Agent Pack rule file. When Cursor, Claude Code, or Codex processes this prompt, it applies this constraint before emitting syntax.
4

Cross-platform bridge messages MUST use a two-phase transaction envelope

Cross-platform bridge messages MUST use a two-phase transaction envelope: PREDICTIVE_BACK_STAGE, PREDICTIVE_BACK_PROGRESS, PREDICTIVE_BACK_COMMIT, and PREDICTIVE_BACK_CANCEL.

Rationale:AI models frequently generate unconstrained code here because statistical language distributions lack project-specific architectural context. Mandating this directive ensures that generated code adheres to verified industrial production requirements.
Enforcement:Integrated into the Agent Pack rule file. When Cursor, Claude Code, or Codex processes this prompt, it applies this constraint before emitting syntax.
5

Hybrid WebView shells MUST NOT invoke window.history.back() during drag interpolation

Hybrid WebView shells MUST NOT invoke window.history.back() during drag interpolation; history alterations MUST defer strictly to the completed commit event.

Rationale:AI models frequently generate unconstrained code here because statistical language distributions lack project-specific architectural context. Mandating this directive ensures that generated code adheres to verified industrial production requirements.
Enforcement:Integrated into the Agent Pack rule file. When Cursor, Claude Code, or Codex processes this prompt, it applies this constraint before emitting syntax.
Technical Questions & Answers

Frequently Asked Technical Questions

Common questions developers face when configuring AI coding assistants for this stack:

Q:Why is Android 15 Predictive Back Navigation Lifecycle Invariance in Cross-Platform Shells critical for AI coding assistants?

Enforces strict two-phase commit protocols for Android 15 predictive back navigation across hybrid webviews, React Native, and Kotlin Multiplatform (KMP) navigation controllers. Mandates an isolated transaction snapshot and explicit rollback/commit lifecycle hooks before visual transition interpolations to prevent phantom state mutability and detached multi-stack drift. Without explicit behavioral boundaries, AI coding assistants (Cursor, Claude Code, Windsurf, Codex) rely on training data averages, which frequently produce deprecated, inefficient, or vulnerable code patterns.

Q:How does adopting this rule prevent AI hallucinations?

This rule explicitly declares what the AI must avoid (Optimistically Popping Internal Navigation Stacks During OnBackProgressed Animations) and prescribes verified positive examples. Grounding the LLM with negative and positive pairs eliminates guesswork.

Q:Which AI coding environments are supported?

This specification is multi-platform compatible: Cursor (.cursor/rules/*.mdc & .cursorrules), Anthropic Claude Code (CLAUDE.md), Windsurf (.windsurfrules), Codex / Cline (AGENTS.md), and GitHub Copilot (.github/copilot-instructions.md).

Q:Can I combine this rule with other technology stacks?

Yes. Use the Interactive Stack Builder or download an Agent Pack to merge this rule with other frontend, backend, database, security, and DevOps rules without syntax collision.

Open Specification · CC BY 4.0·Free for Personal, Team & Commercial In-Repo Use

Citation & Open Source Attribution Guidelines

This specification is licensed under Creative Commons Attribution 4.0 International (CC BY 4.0). You are completely free to adapt and share this rule in your workspace. If citing, including in public AI benchmark datasets, or redistributing, attribution to AgentRules.org is required.

Related MOBILE Rules

View all rules →
1 Rule in Stack

Android