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

Tauri 2.0 IPC Zero-Copy Binary Channel Backpressure Protocol

Enforces credit-based flow control and raw binary ArrayBuffer payload delivery via Tauri 2.0 Channels for high-frequency hardware sensor streams. Prevents unbounded native-to-webview IPC message queue allocation, serialization overhead, and frame drops on Android WebView and iOS WebKit runtimes.

Prohibited Anti-Pattern: Unbounded JSON Event Emitter Flooding WebView IPC Without Consumer Flow Control

Export Ready-to-Drop Configuration

Select format below to copy code or download file directly.

---
description: Tauri 2.0 IPC Zero-Copy Binary Channel Backpressure Protocol - Enforces credit-based flow control and raw binary ArrayBuffer payload delivery via Tauri 2.0 Channels for high-frequency hardware sensor streams. Prevents unbounded native-to-webview IPC message queue allocation, serialization overhead, and frame drops on Android WebView and iOS WebKit runtimes.
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-ipc-binary-channel-backpressure-protocol"
---

# Tauri 2.0 IPC Zero-Copy Binary Channel Backpressure Protocol

> **Severity**: CRITICAL | **Category**: mobile
> **Anti-Pattern Warning**: Unbounded JSON Event Emitter Flooding WebView IPC Without Consumer Flow Control

## System Constraints
You are a Principal Mobile Systems Architect enforcing the Tauri 2.0 IPC Zero-Copy Binary Channel Backpressure Protocol. Mandate that all high-frequency sensor streams (>= 60Hz) employ typed binary ArrayBuffer channels paired with a credit-based or frame-ack backpressure mechanism. Prohibit JSON event emitters (`app_handle.emit`), intermediate UTF-8 string allocations, and unmetered fire-and-forget native loops across mobile IPC boundaries.

## Strict Guidelines
- Engineers MUST ALWAYS use Tauri 2.0 `Channel<Vec<u8>>` or `Channel<ipc::Response>` instead of `app_handle.emit` for sensor telemetry exceeding 30Hz.
- Engineers MUST NOT serialize high-frequency telemetry into JSON or intermediate UTF-8 strings across the native-to-webview IPC bridge.
- Code SHOULD implement an explicit credit-based or sliding-window acknowledgement (ACK) loop before the native side pushes subsequent binary frames.
- Services MUST process incoming binary chunks directly via `DataView` or typed array views (`Float32Array`, `Int16Array`) without creating intermediate JS object allocations per sample.
- Components NEVER attach high-frequency IPC listeners directly to React state setters; data MUST be buffered into a pre-allocated typed ring buffer and drained during `requestAnimationFrame`.

## Bad vs Good Implementations
### High-Frequency IMU Sensor Streaming via Tauri 2.0 IPC

#### Bad Antipattern (AI Common Hallucination)
> **Why it fails**: Using generic event listeners with JSON payloads allocates intermediate strings and parsed objects at sensor frequencies, quickly exhausting the mobile webview IPC buffer and causing V8 garbage collection freezes and frame drops.
```typescript
import { listen } from '@tauri-apps/api/event';
import { useEffect, useState } from 'react';

interface SensorReading {
  x: number;
  y: number;
  z: number;
  timestamp: number;
}

// ANTI-PATTERN: Emitting JSON strings at 200Hz overwhelms the mobile webview
// IPC message queue, triggering massive GC thrashing and frame drops.
export function useSensorStream() {
  const [reading, setReading] = useState<SensorReading | null>(null);

  useEffect(() => {
    const unlistenPromise = listen<SensorReading>('imu-sample', (event) => {
      // Inefficient JSON-deserialized object allocation 200 times per second
      setReading(event.payload);
    });

    return () => {
      unlistenPromise.then((unlisten) => unlisten());
    };
  }, []);

  return reading;
}
```

#### Production Standard (Correct)
> **Standard**: Employs Tauri 2.0's binary Channel to transmit zero-copy raw byte slices, decodes attributes with zero allocations using DataView, and uses an explicit credit ACK to ensure the Rust sensor thread never overruns the mobile webview's frame budget.
```typescript
import { Channel, invoke } from '@tauri-apps/api/core';
import { useEffect, useRef } from 'react';

// PRODUCTION FIX: Pre-allocated typed views with explicit consumer ACK backpressure
export function useSensorStream(onFrame: (x: number, y: number, z: number) => void) {
  const onFrameRef = useRef(onFrame);
  onFrameRef.current = onFrame;

  useEffect(() => {
    let active = true;
    const channel = new Channel<Uint8Array>();

    channel.onmessage = (bytes: Uint8Array) => {
      if (!active) return;
      // Zero-copy typed parsing over raw binary buffer (16 bytes: 3x f32 + 1x u32 seq)
      const view = new DataView(bytes.buffer, bytes.byteOffset, bytes.byteLength);
      const x = view.getFloat32(0, true);
      const y = view.getFloat32(4, true);
      const z = view.getFloat32(8, true);
      const sequence = view.getUint32(12, true);

      onFrameRef.current(x, y, z);

      // Backpressure ACK: grant next frame credit only after handling UI workload
      invoke('ack_sensor_frame', { sequence }).catch(console.error);
    };

    invoke('start_sensor_stream', { channel }).catch(console.error);

    return () => {
      active = false;
      invoke('stop_sensor_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 IPC Zero-Copy Binary Channel Backpressure Protocol

Tauri 2.0 IPC Zero-Copy Binary Channel Backpressure Protocol defines an industrial-grade behavioral standard for mobile engineering. Enforces credit-based flow control and raw binary ArrayBuffer payload delivery via Tauri 2.0 Channels for high-frequency hardware sensor streams. Prevents unbounded native-to-webview IPC message queue allocation, serialization overhead, and frame drops on Android WebView and iOS WebKit runtimes. 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 JSON Event Emitter Flooding WebView IPC Without Consumer Flow Control 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 JSON Event Emitter Flooding WebView IPC Without Consumer Flow ControlCritical
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 use Tauri 2.0 `Channel<Vec<u8>>` or `Channel<ipc

Engineers MUST ALWAYS use Tauri 2.0 `Channel<Vec<u8>>` or `Channel<ipc::Response>` instead of `app_handle.emit` for sensor telemetry exceeding 30Hz.

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 serialize high-frequency telemetry into JSON or intermediate UTF-8 strings across the native-to-webview IPC bridge.

Engineers MUST NOT serialize high-frequency telemetry into JSON or intermediate UTF-8 strings across the native-to-webview IPC 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.
3

Code SHOULD implement an explicit credit-based or sliding-window acknowledgement (ACK) loop before the native side pushes subsequent binary frames.

Code SHOULD implement an explicit credit-based or sliding-window acknowledgement (ACK) loop before the native side pushes subsequent binary frames.

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 process incoming binary chunks directly via `DataView` or typed array views (`Float32Array`, `Int16Array`) without creating intermediate JS object allocations per sample.

Services MUST process incoming binary chunks directly via `DataView` or typed array views (`Float32Array`, `Int16Array`) without creating intermediate JS object allocations per sample.

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 attach high-frequency IPC listeners directly to React state setters

Components NEVER attach high-frequency IPC listeners directly to React state setters; data MUST be buffered into a pre-allocated typed ring buffer and drained during `requestAnimationFrame`.

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 IPC Zero-Copy Binary Channel Backpressure Protocol critical for AI coding assistants?

Enforces credit-based flow control and raw binary ArrayBuffer payload delivery via Tauri 2.0 Channels for high-frequency hardware sensor streams. Prevents unbounded native-to-webview IPC message queue allocation, serialization overhead, and frame drops on Android WebView and iOS WebKit runtimes. 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 JSON Event Emitter Flooding WebView IPC Without Consumer Flow Control) 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