This specification is maintained by the AgentRules Working Group. Have enhancements or want to claim maintainership?Submit Specification →
mobilecritical PriorityID: tauri2-zero-copy-ipc-backpressure-protocol

Tauri 2.0 Zero-Copy IPC Backpressure Protocol for Mobile WebViews

Enforces pull-based reactive streaming and credit-gated flow control across the Rust-to-WebView binary bridge on mobile targets. Unbounded event emission across Tauri 2.0 IPC causes microtask queue backlog and uncollectable ArrayBuffer allocations in mobile V8/JavaScriptCore heaps, leading to non-catchable low-memory kills (OOM). This guardrail mandates bounded chunk windows, deterministic ACK handshakes, and native channel disposal.

Prohibited Anti-Pattern: Unbounded Push-Based Event Streaming Saturating Mobile WebView Heap

Export Ready-to-Drop Configuration

Select format below to copy code or download file directly.

---
description: Tauri 2.0 Zero-Copy IPC Backpressure Protocol for Mobile WebViews - Enforces pull-based reactive streaming and credit-gated flow control across the Rust-to-WebView binary bridge on mobile targets. Unbounded event emission across Tauri 2.0 IPC causes microtask queue backlog and uncollectable ArrayBuffer allocations in mobile V8/JavaScriptCore heaps, leading to non-catchable low-memory kills (OOM). This guardrail mandates bounded chunk windows, deterministic ACK handshakes, and native channel disposal.
globs: src/**/*.{ts,tsx}, src-tauri/src/**/*.rs
alwaysApply: true
verified_by: "agentrules.org"
license: "CC-BY-4.0"
source: "https://agentrules.org/rules/tauri2-zero-copy-ipc-backpressure-protocol"
---

# Tauri 2.0 Zero-Copy IPC Backpressure Protocol for Mobile WebViews

> **Severity**: CRITICAL | **Category**: mobile
> **Anti-Pattern Warning**: Unbounded Push-Based Event Streaming Saturating Mobile WebView Heap

## System Constraints
You are a Principal Mobile Systems Architect enforcing deterministic memory limits and IPC backpressure in Tauri 2.0 applications. Mandate pull-based or windowed-credit IPC streaming for any high-throughput or binary payload transfer (e.g., audio streams, camera frames, continuous sensor feeds) between Rust and the mobile WebView runtime. Reject any implementation using raw `emit()` or unbounded push channels that can overwhelm the mobile V8/JavaScriptCore heap.

## Strict Guidelines
- Engineers MUST ALWAYS implement credit-based flow control or pull-streams via Tauri 2.0 `Channel<T>` for high-frequency or binary data transfers.
- Engineers MUST NOT emit unbounded IPC events via `app.emit()` or `window.emit()` for streaming continuous frames or ArrayBuffers.
- Code SHOULD enforce a bounded ring buffer or sliding window on the Rust side, dropping oldest unread frames with explicit telemetry if the frontend consumer breaches its processing threshold.
- Services MUST explicitly signal chunk consumption back to the Rust native loop via an acknowledgment token (`ack(seq)`) before requesting subsequent allocations.
- Components NEVER keep active channel listeners open across unmount cycles without invoking native channel teardown to prevent orphan allocations in the bridge.

## Bad vs Good Implementations
### Unbounded Push Stream vs. Credit-Gated Backpressure Channel

#### Bad Antipattern (AI Common Hallucination)
> **Why it fails**: Pushing binary frames through `window.emit()` creates asynchronous microtask queuing in the mobile WebView. Because the JavaScript runtime cannot signal backpressure to the Rust emitter, the uncollected ArrayBuffers quickly breach mobile system memory thresholds (typically 200-400MB on mobile OS WebViews), resulting in an instantaneous OS SIGKILL without stack trace.
```typescript
import { listen } from '@tauri-apps/api/event';

// ANTI-PATTERN: Native Rust pushes frames unconditionally using window.emit()
// Mobile V8 cannot drain microtasks fast enough, causing ArrayBuffer accumulation and OOM
export async function subscribeToFrameStream(onFrame: (buf: Uint8Array) => void) {
  const unlisten = await listen<ArrayBuffer>('camera-frame', (event) => {
    const view = new Uint8Array(event.payload);
    onFrame(view);
  });
  return unlisten;
}
```

#### Production Standard (Correct)
> **Standard**: Implements an explicit credit-based windowing protocol using Tauri 2.0 `Channel`. The Rust stream only dispatches new binary chunks when granted credit via frontend `ack_frame_stream` invocations, strictly capping in-flight ArrayBuffers to `highWatermark` and completely eliminating uncollectable heap saturation.
```typescript
import { Channel, invoke } from '@tauri-apps/api/core';

interface StreamChunk {
  seq: number;
  data: Uint8Array;
}

// PRODUCTION INVARIANT: Bounded credit window with deterministic pull/ACK
export async function subscribeToFrameStream(
  onFrame: (buf: Uint8Array) => Promise<void>,
  highWatermark = 2
): Promise<() => void> {
  const channel = new Channel<StreamChunk>();
  let active = true;
  let inflight = 0;

  channel.onmessage = async ({ seq, data }) => {
    if (!active) return;
    try {
      await onFrame(data);
    } finally {
      inflight--;
      // Signal credit return to Rust core to trigger next chunk delivery
      if (active && inflight < highWatermark) {
        inflight++;
        invoke('ack_frame_stream', { seq }).catch(console.error);
      }
    }
  };

  // Initial credit grant
  inflight = highWatermark;
  await invoke('start_frame_stream', { onEvent: channel, initialCredit: highWatermark });

  return () => {
    active = false;
    invoke('stop_frame_stream').catch(console.error);
  };
}
```

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: Tauri 2.0 Zero-Copy IPC Backpressure Protocol for Mobile WebViews

Tauri 2.0 Zero-Copy IPC Backpressure Protocol for Mobile WebViews defines an industrial-grade behavioral standard for mobile engineering. Enforces pull-based reactive streaming and credit-gated flow control across the Rust-to-WebView binary bridge on mobile targets. Unbounded event emission across Tauri 2.0 IPC causes microtask queue backlog and uncollectable ArrayBuffer allocations in mobile V8/JavaScriptCore heaps, leading to non-catchable low-memory kills (OOM). This guardrail mandates bounded chunk windows, deterministic ACK handshakes, and native channel disposal. 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: Unbounded Push-Based Event Streaming Saturating Mobile WebView Heap 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 DriftUnbounded Push-Based Event Streaming Saturating Mobile WebView HeapCritical
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 implement credit-based flow control or pull-streams via Tauri 2.0 `Channel<T>` for high-frequency or binary data transfers.

Engineers MUST ALWAYS implement credit-based flow control or pull-streams via Tauri 2.0 `Channel<T>` for high-frequency or binary data transfers.

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 emit unbounded IPC events via `app.emit()` or `window.emit()` for streaming continuous frames or ArrayBuffers.

Engineers MUST NOT emit unbounded IPC events via `app.emit()` or `window.emit()` for streaming continuous frames or ArrayBuffers.

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

Code SHOULD enforce a bounded ring buffer or sliding window on the Rust side, dropping oldest unread frames with explicit telemetry if the frontend consumer breaches its processing threshold.

Code SHOULD enforce a bounded ring buffer or sliding window on the Rust side, dropping oldest unread frames with explicit telemetry if the frontend consumer breaches its processing threshold.

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

Services MUST explicitly signal chunk consumption back to the Rust native loop via an acknowledgment token (`ack(seq)`) before requesting subsequent allocations.

Services MUST explicitly signal chunk consumption back to the Rust native loop via an acknowledgment token (`ack(seq)`) before requesting subsequent allocations.

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

Components NEVER keep active channel listeners open across unmount cycles without invoking native channel teardown to prevent orphan allocations in the bridge.

Components NEVER keep active channel listeners open across unmount cycles without invoking native channel teardown to prevent orphan allocations in the bridge.

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 Tauri 2.0 Zero-Copy IPC Backpressure Protocol for Mobile WebViews critical for AI coding assistants?

Enforces pull-based reactive streaming and credit-gated flow control across the Rust-to-WebView binary bridge on mobile targets. Unbounded event emission across Tauri 2.0 IPC causes microtask queue backlog and uncollectable ArrayBuffer allocations in mobile V8/JavaScriptCore heaps, leading to non-catchable low-memory kills (OOM). This guardrail mandates bounded chunk windows, deterministic ACK handshakes, and native channel disposal. 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 (Unbounded Push-Based Event Streaming Saturating Mobile WebView Heap) 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

Tauri