This specification is maintained by the AgentRules Working Group. Have enhancements or want to claim maintainership?Submit Specification →
mobilecritical PriorityID: tauri2-mobile-zerocopy-ipc-ringbuffer-standard

Tauri 2.0 Mobile Zero-Copy IPC Shared Memory Ring Buffer Standard

High-throughput telemetry and media streaming between Rust core and mobile WebViews must bypass JSON serialization and Base64 bridge encoding to prevent fatal GC pauses and OOM termination. Engineers must utilize Tauri 2.0 binary IPC channels or custom URI streaming protocols consuming pre-allocated circular ArrayBuffers with atomic index synchronization. Enforces bounded heap allocation and sub-millisecond transmission latencies on memory-constrained iOS and Android devices.

Prohibited Anti-Pattern: Streaming High-Frequency Telemetry or Media as JSON/Base64 over Tauri Standard Invoke Bridge

Export Ready-to-Drop Configuration

Select format below to copy code or download file directly.

---
description: Tauri 2.0 Mobile Zero-Copy IPC Shared Memory Ring Buffer Standard - High-throughput telemetry and media streaming between Rust core and mobile WebViews must bypass JSON serialization and Base64 bridge encoding to prevent fatal GC pauses and OOM termination. Engineers must utilize Tauri 2.0 binary IPC channels or custom URI streaming protocols consuming pre-allocated circular ArrayBuffers with atomic index synchronization. Enforces bounded heap allocation and sub-millisecond transmission latencies on memory-constrained iOS and Android devices.
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-mobile-zerocopy-ipc-ringbuffer-standard"
---

# Tauri 2.0 Mobile Zero-Copy IPC Shared Memory Ring Buffer Standard

> **Severity**: CRITICAL | **Category**: mobile
> **Anti-Pattern Warning**: Streaming High-Frequency Telemetry or Media as JSON/Base64 over Tauri Standard Invoke Bridge

## System Constraints
You are a Principal Software Architect enforcing the Tauri 2.0 Zero-Copy Shared Memory Ring Buffer Standard for mobile runtimes. Mobile operating systems (iOS WebKit and Android WebView) enforce strict RAM thresholds and aggressive low-memory app termination. Standard Tauri IPC commands serialize payloads to UTF-8 JSON, which incurs quadruple-buffering overhead (Rust struct -> serde JSON string -> WebView IPC string -> JS Object parse) causing massive heap spikes and frame drops. You must mandate zero-copy binary streaming via Tauri 2.0 Channel/Response abstractions and client-side pre-allocated typed ArrayBuffer ring buffers.

## Strict Guidelines
- Engineers MUST ALWAYS transmit high-throughput (>30Hz) telemetry, audio, or video frames using Tauri 2.0 `Channel<tauri::ipc::InvokeResponseBody>` or raw binary byte buffers (`Vec<u8>`) rather than serde-serialized JSON structs.
- Engineers MUST NOT convert binary buffers to Base64 strings or JSON arrays (`number[]`) when crossing the IPC bridge.
- Frontend consumers MUST initialize a fixed-size `ArrayBuffer` ring buffer once on component mount, writing binary payloads via `Uint8Array.set` to bounded slots governed by atomic write/read heads.
- Services MUST implement backpressure handling in Rust; if the mobile WebView reader head falls behind the writer head beyond the ring capacity, subsequent frames MUST either drop or trigger explicit backpressure signals instead of infinitely buffering.
- Components NEVER allocate fresh `Uint8Array` or `ArrayBuffer` instances inside frame-rate rendering loops or IPC packet callbacks.

## Bad vs Good Implementations
### Consuming High-Frequency Sensor/Telemetry Stream in Mobile WebView

#### Bad Antipattern (AI Common Hallucination)
> **Why it fails**: Fetching high-frequency telemetry via standard invoke with JSON-serialized numeric arrays creates millions of temporary heap allocations per second. In mobile WebViews (WKWebView/Android Chromium), this triggers aggressive garbage collection cycles, UI freezes, and eventual operating system OOM kills.
```typescript
import { invoke } from '@tauri-apps/api/core';

interface TelemetryFrame {
  timestamp: number;
  samples: number[]; // Serialized as a dynamic JSON array
}

// ANTI-PATTERN: Polling or streaming via serde JSON creates severe memory churn
export function startTelemetryListener(onFrame: (frame: TelemetryFrame) => void) {
  const interval = setInterval(async () => {
    // Incurs Rust -> JSON string -> IPC bridge -> V8 parse overhead every 16ms
    const data = await invoke<TelemetryFrame>('fetch_telemetry_batch');
    onFrame(data);
  }, 16);

  return () => clearInterval(interval);
}
```

#### Production Standard (Correct)
> **Standard**: Uses Tauri 2.0's binary-capable `Channel<Uint8Array>`, passing raw binary chunks directly across the native-to-web IPC boundary. The receiver writes directly into a pre-allocated fixed-size ring buffer (`ArrayBuffer`), eliminating all dynamic memory allocations and JSON deserialization overhead during execution.
```typescript
import { Channel } from '@tauri-apps/api/core';
import { invoke } from '@tauri-apps/api/core';

const SLOT_SIZE = 4096; // 4KB per frame
const SLOT_COUNT = 64;
const TOTAL_BUFFER_SIZE = SLOT_SIZE * SLOT_COUNT;

export class TelemetryRingBuffer {
  private readonly storage = new ArrayBuffer(TOTAL_BUFFER_SIZE);
  private readonly view = new Uint8Array(this.storage);
  private writeIndex = 0;

  public writeFrame(chunk: Uint8Array): void {
    if (chunk.byteLength > SLOT_SIZE) {
      throw new Error(`Frame exceeds allocated slot capacity: ${chunk.byteLength}`);
    }
    const offset = (this.writeIndex % SLOT_COUNT) * SLOT_SIZE;
    this.view.set(chunk, offset);
    this.writeIndex = (this.writeIndex + 1) >>> 0;
  }

  public getLatestSlot(target: Uint8Array): void {
    const latestSlot = ((this.writeIndex - 1 + SLOT_COUNT) % SLOT_COUNT) * SLOT_SIZE;
    target.set(this.view.subarray(latestSlot, latestSlot + SLOT_SIZE));
  }
}

export async function initZeroCopyTelemetryStream(ringBuffer: TelemetryRingBuffer): Promise<() => void> {
  // Pre-allocated consumer channel for raw binary buffers
  const onEvent = new Channel<Uint8Array>();
  
  onEvent.onmessage = (rawBytes: Uint8Array) => {
    ringBuffer.writeFrame(rawBytes);
  };

  await invoke('subscribe_binary_telemetry', { channel: onEvent });

  return () => {
    // Tear down channel on unmount
    void invoke('unsubscribe_binary_telemetry');
  };
}
```

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 Mobile Zero-Copy IPC Shared Memory Ring Buffer Standard

Tauri 2.0 Mobile Zero-Copy IPC Shared Memory Ring Buffer Standard defines an industrial-grade behavioral standard for mobile engineering. High-throughput telemetry and media streaming between Rust core and mobile WebViews must bypass JSON serialization and Base64 bridge encoding to prevent fatal GC pauses and OOM termination. Engineers must utilize Tauri 2.0 binary IPC channels or custom URI streaming protocols consuming pre-allocated circular ArrayBuffers with atomic index synchronization. Enforces bounded heap allocation and sub-millisecond transmission latencies on memory-constrained iOS and Android devices. 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: Streaming High-Frequency Telemetry or Media as JSON/Base64 over Tauri Standard Invoke Bridge 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 DriftStreaming High-Frequency Telemetry or Media as JSON/Base64 over Tauri Standard Invoke BridgeCritical
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 transmit high-throughput (>30Hz) telemetry, audio, or video frames using Tauri 2.0 `Channel<tauri

Engineers MUST ALWAYS transmit high-throughput (>30Hz) telemetry, audio, or video frames using Tauri 2.0 `Channel<tauri::ipc::InvokeResponseBody>` or raw binary byte buffers (`Vec<u8>`) rather than serde-serialized JSON structs.

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 convert binary buffers to Base64 strings or JSON arrays (`number[]`) when crossing the IPC bridge.

Engineers MUST NOT convert binary buffers to Base64 strings or JSON arrays (`number[]`) when crossing the 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

Frontend consumers MUST initialize a fixed-size `ArrayBuffer` ring buffer once on component mount, writing binary payloads via `Uint8Array.set` to bounded slots governed by atomic write/read heads.

Frontend consumers MUST initialize a fixed-size `ArrayBuffer` ring buffer once on component mount, writing binary payloads via `Uint8Array.set` to bounded slots governed by atomic write/read heads.

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 implement backpressure handling in Rust

Services MUST implement backpressure handling in Rust; if the mobile WebView reader head falls behind the writer head beyond the ring capacity, subsequent frames MUST either drop or trigger explicit backpressure signals instead of infinitely buffering.

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 allocate fresh `Uint8Array` or `ArrayBuffer` instances inside frame-rate rendering loops or IPC packet callbacks.

Components NEVER allocate fresh `Uint8Array` or `ArrayBuffer` instances inside frame-rate rendering loops or IPC packet 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.
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 Mobile Zero-Copy IPC Shared Memory Ring Buffer Standard critical for AI coding assistants?

High-throughput telemetry and media streaming between Rust core and mobile WebViews must bypass JSON serialization and Base64 bridge encoding to prevent fatal GC pauses and OOM termination. Engineers must utilize Tauri 2.0 binary IPC channels or custom URI streaming protocols consuming pre-allocated circular ArrayBuffers with atomic index synchronization. Enforces bounded heap allocation and sub-millisecond transmission latencies on memory-constrained iOS and Android devices. 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 (Streaming High-Frequency Telemetry or Media as JSON/Base64 over Tauri Standard Invoke Bridge) 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