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

Tauri 2.0 Mobile Zero-Copy Binary IPC Buffer Safety Guardrail

Enforces memory-safe, zero-copy binary streaming protocols between Tauri 2.0 native Rust host engines and mobile webviews (iOS WKWebView and Android WebView). Prevents mobile operating system terminations (iOS Jetsam, Android LowMemoryKiller), GC thrashing from Base64 string serialization, and cross-thread buffer mutations during high-bandwidth media and sensor ingestion.

Prohibited Anti-Pattern: Serializing high-bandwidth binary streams via Base64/JSON strings or mutating in-flight Rust memory buffers without atomic ownership handoff.

Export Ready-to-Drop Configuration

Select format below to copy code or download file directly.

---
description: Tauri 2.0 Mobile Zero-Copy Binary IPC Buffer Safety Guardrail - Enforces memory-safe, zero-copy binary streaming protocols between Tauri 2.0 native Rust host engines and mobile webviews (iOS WKWebView and Android WebView). Prevents mobile operating system terminations (iOS Jetsam, Android LowMemoryKiller), GC thrashing from Base64 string serialization, and cross-thread buffer mutations during high-bandwidth media and sensor ingestion.
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-guardrail"
---

# Tauri 2.0 Mobile Zero-Copy Binary IPC Buffer Safety Guardrail

> **Severity**: CRITICAL | **Category**: mobile
> **Anti-Pattern Warning**: Serializing high-bandwidth binary streams via Base64/JSON strings or mutating in-flight Rust memory buffers without atomic ownership handoff.

## System Constraints
You are a Principal Mobile Systems Architect and Rust/WebKit IPC Specialist enforcing Tauri 2.0 Rust-to-Webview Zero-Copy IPC Buffer Guardrails. Mandate non-allocating binary data transfers, strict buffer ownership semantics, deterministic memory backpressure, and zero-copy TypedArray consumption across iOS WKWebView and Android WebView runtimes.

## Strict Guidelines
- Engineers MUST ALWAYS transfer high-bandwidth binary payloads via Tauri 2.0 raw binary responses (`tauri::ipc::Response::new(vec)`) or typed binary `Channel` instances instead of JSON or Base64 string serialization.
- Engineers MUST NOT mutate, reallocate, or deallocate underlying native memory buffers while an asynchronous mobile IPC bridge transfer is in flight without deterministic Rust ownership transfer.
- Code SHOULD consume raw binary payloads on the mobile webview main thread exclusively as `Uint8Array` views and immediately transfer ownership to a Web Worker via transferable `postMessage([buffer], [buffer])` to prevent UI thread frame drops.
- Services MUST enforce bounded ring buffers with explicit backpressure signaling between the Rust producer thread and mobile webview consumer to avoid triggering OS-level out-of-memory terminations (iOS Jetsam, Android LMK).
- Components NEVER decode binary payloads using `atob()` or JSON string conversions on mobile webview runtimes.

## Bad vs Good Implementations
### Tauri 2.0 Binary IPC Ingestion on Mobile Webview

#### Bad Antipattern (AI Common Hallucination)
> **Why it fails**: Transfers binary data as Base64 inside a JSON payload. This causes a 33% memory footprint expansion, creates thousands of short-lived string allocations, and triggers aggressive garbage collection pauses on mobile devices, often resulting in Jetsam kills on iOS.
```typescript
import { invoke } from '@tauri-apps/api/core';

interface FramePayload {
  frameId: number;
  base64Data: string; // Anti-pattern: High-overhead Base64 encoding over IPC
}

export async function subscribeToVideoFrames(onFrame: (data: Uint8Array) => void): Promise<void> {
  // Incurs 33% payload expansion, JSON parsing overhead, and massive V8/JSC GC pauses
  const payload = await invoke<FramePayload>('get_next_camera_frame');
  const binaryString = atob(payload.base64Data);
  const bytes = new Uint8Array(binaryString.length);
  for (let i = 0; i < binaryString.length; i++) {
    bytes[i] = binaryString.charCodeAt(i);
  }
  onFrame(bytes);
}
```

#### Production Standard (Correct)
> **Standard**: Utilizes Tauri 2.0 typed binary Channel delivering direct raw ArrayBuffers. The payload bypasses Base64 encoding entirely, and the memory buffer is immediately transferred to a Web Worker using Transferable Objects, ensuring zero-copy overhead and 60fps UI responsiveness on mobile devices.
```typescript
import { Channel, invoke } from '@tauri-apps/api/core';

export async function subscribeToVideoFrames(
  worker: Worker,
  signal: AbortSignal
): Promise<void> {
  // Tauri 2.0 Channel transmitting raw ArrayBuffer chunks without Base64/JSON overhead
  const onFrameChannel = new Channel<ArrayBuffer>();
  
  onFrameChannel.onmessage = (frameBuffer: ArrayBuffer) => {
    if (signal.aborted) return;
    // Direct zero-copy transfer to dedicated processing Web Worker
    worker.postMessage({ frame: frameBuffer }, [frameBuffer]);
  };

  await invoke('stream_camera_frames_binary', {
    onFrame: onFrameChannel
  });
}
```

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 Binary IPC Buffer Safety Guardrail

Tauri 2.0 Mobile Zero-Copy Binary IPC Buffer Safety Guardrail defines an industrial-grade behavioral standard for mobile engineering. Enforces memory-safe, zero-copy binary streaming protocols between Tauri 2.0 native Rust host engines and mobile webviews (iOS WKWebView and Android WebView). Prevents mobile operating system terminations (iOS Jetsam, Android LowMemoryKiller), GC thrashing from Base64 string serialization, and cross-thread buffer mutations during high-bandwidth media and sensor ingestion. 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: Serializing high-bandwidth binary streams via Base64/JSON strings or mutating in-flight Rust memory buffers without atomic ownership handoff. 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 DriftSerializing high-bandwidth binary streams via Base64/JSON strings or mutating in-flight Rust memory buffers without atomic ownership handoff.Critical
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 transfer high-bandwidth binary payloads via Tauri 2.0 raw binary responses (`tauri

Engineers MUST ALWAYS transfer high-bandwidth binary payloads via Tauri 2.0 raw binary responses (`tauri::ipc::Response::new(vec)`) or typed binary `Channel` instances instead of JSON or Base64 string serialization.

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, reallocate, or deallocate underlying native memory buffers while an asynchronous mobile IPC bridge transfer is in flight without deterministic Rust ownership transfer.

Engineers MUST NOT mutate, reallocate, or deallocate underlying native memory buffers while an asynchronous mobile IPC bridge transfer is in flight without deterministic Rust ownership transfer.

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 consume raw binary payloads on the mobile webview main thread exclusively as `Uint8Array` views and immediately transfer ownership to a Web Worker via transferable `postMessage([buffer], [buffer])` to prevent UI thread frame drops.

Code SHOULD consume raw binary payloads on the mobile webview main thread exclusively as `Uint8Array` views and immediately transfer ownership to a Web Worker via transferable `postMessage([buffer], [buffer])` to prevent UI thread frame drops.

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 enforce bounded ring buffers with explicit backpressure signaling between the Rust producer thread and mobile webview consumer to avoid triggering OS-level out-of-memory terminations (iOS Jetsam, Android LMK).

Services MUST enforce bounded ring buffers with explicit backpressure signaling between the Rust producer thread and mobile webview consumer to avoid triggering OS-level out-of-memory terminations (iOS Jetsam, Android LMK).

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 decode binary payloads using `atob()` or JSON string conversions on mobile webview runtimes.

Components NEVER decode binary payloads using `atob()` or JSON string conversions on mobile webview runtimes.

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 Binary IPC Buffer Safety Guardrail critical for AI coding assistants?

Enforces memory-safe, zero-copy binary streaming protocols between Tauri 2.0 native Rust host engines and mobile webviews (iOS WKWebView and Android WebView). Prevents mobile operating system terminations (iOS Jetsam, Android LowMemoryKiller), GC thrashing from Base64 string serialization, and cross-thread buffer mutations during high-bandwidth media and sensor ingestion. 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 (Serializing high-bandwidth binary streams via Base64/JSON strings or mutating in-flight Rust memory buffers without atomic ownership handoff.) 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