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

Tauri 2.0 Zero-Copy Binary Stream Buffer Protocol for Mobile WebViews

Prohibits base64 stringification and standard JSON serialization across the Tauri 2.0 IPC boundary for media payloads, model weights, and embeddings exceeding 64KB. Mandates direct binary buffer transfers via Tauri 2.0 raw byte streaming channels or custom protocol schemes to eliminate V8/JavaScriptCore heap pressure and prevent immediate mobile OS low-memory termination (OOM).

Prohibited Anti-Pattern: Base64-Encoding Multi-Megabyte Buffers Over JSON IPC Causing Mobile WebView OOM Terminations

Export Ready-to-Drop Configuration

Select format below to copy code or download file directly.

---
description: Tauri 2.0 Zero-Copy Binary Stream Buffer Protocol for Mobile WebViews - Prohibits base64 stringification and standard JSON serialization across the Tauri 2.0 IPC boundary for media payloads, model weights, and embeddings exceeding 64KB. Mandates direct binary buffer transfers via Tauri 2.0 raw byte streaming channels or custom protocol schemes to eliminate V8/JavaScriptCore heap pressure and prevent immediate mobile OS low-memory termination (OOM).
globs: src/**/*.{ts,tsx}, src-tauri/src/**/*.rs
alwaysApply: true
verified_by: "agentrules.org"
license: "CC-BY-4.0"
source: "https://agentrules.org/rules/tauri-v2-mobile-zero-copy-ipc-protocol"
---

# Tauri 2.0 Zero-Copy Binary Stream Buffer Protocol for Mobile WebViews

> **Severity**: CRITICAL | **Category**: mobile
> **Anti-Pattern Warning**: Base64-Encoding Multi-Megabyte Buffers Over JSON IPC Causing Mobile WebView OOM Terminations

## System Constraints
You are a Principal Mobile Systems Architect enforcing the Tauri 2.0 IPC Zero-Copy Binary Stream Buffer Protocol. WebViews on iOS (WebKit) and Android (Chromium) operate under stringent OS memory ceilings (typically 200MB-400MB total RSS before jetsam or low-memory killer SIGKILL). Base64 encoding inflates payloads by 33%, and V8/JSC JSON parsing duplicates buffers 3-4x across the boundary, causing catastrophic memory spikes on files >1MB. You must enforce Tauri 2.0 Channel/Response raw binary streaming APIs and custom asset protocols for all binary transport.

## Strict Guidelines
- Engineers MUST ALWAYS transfer binary data (audio, images, SQLite databases, vector embeddings) using Tauri 2.0 `tauri::ipc::Channel` with raw byte chunks (`Vec<u8>`) or direct ArrayBuffer responses rather than JSON-wrapped base64 strings.
- Engineers MUST NOT convert `Uint8Array` or `ArrayBuffer` instances to base64 strings (`btoa`, `Buffer.from().toString('base64')`) prior to calling `invoke()` on mobile targets.
- Rust commands handling payloads larger than 64KB MUST accept or return `tauri::ipc::Response` with binary data or stream chunks through `tauri::ipc::Channel<Vec<u8>>` to avoid Serde JSON tree generation.
- Code streaming multi-megabyte files to the UI MUST implement chunking with a bounded buffer size (recommended 64KB to 256KB per frame) to prevent event loop starvation and garbage collection latency spikes on mobile runtimes.
- Components NEVER store duplicate in-memory ArrayBuffers; instances MUST be transferred to blobs via `URL.createObjectURL` or consumed via `ReadableStream` and immediately dereferenced for garbage collection.

## Bad vs Good Implementations
### Tauri 2.0 IPC Binary Streaming vs JSON Base64 Transport

#### Bad Antipattern (AI Common Hallucination)
> **Why it fails**: Transporting files via Base64 strings inside JSON causes 33% payload inflation and forces JavaScriptCore/V8 to allocate the raw JSON string, parsed base64 string, intermediate binary string, and final Uint8Array simultaneously, triggering mobile OS OOM kills.
```typescript
import { invoke } from '@tauri-apps/api/core';

interface MediaPayload {
  fileName: string;
  base64Data: string; // Anti-pattern: explodes memory 3-4x in JSC/V8 heap
}

export async function loadMediaFile(path: string): Promise<Uint8Array> {
  // Crashes mobile WebViews on 10MB+ files due to JSON parser allocation spikes
  const response = await invoke<MediaPayload>('get_media_base64', { path });
  const binaryString = atob(response.base64Data);
  const bytes = new Uint8Array(binaryString.length);
  for (let i = 0; i < binaryString.length; i++) {
    bytes[i] = binaryString.charCodeAt(i);
  }
  return bytes;
}
```

#### Production Standard (Correct)
> **Standard**: Tauri 2.0 Channels stream raw binary data directly over the platform native IPC as raw `ArrayBuffer` objects without base64 conversion or JSON parsing, keeping memory footprint constant regardless of file size.
```typescript
import { invoke, Channel } from '@tauri-apps/api/core';

export async function streamMediaFile(
  filePath: string,
  onChunk: (chunk: Uint8Array) => void
): Promise<void> {
  const onData = new Channel<Uint8Array>();
  
  onData.onmessage = (chunk: Uint8Array) => {
    // Direct zero-copy transfer of raw binary slice
    onChunk(chunk);
  };

  // Rust streams binary Vec<u8> directly across IPC without JSON serialization overhead
  await invoke('stream_media_binary', {
    path: filePath,
    onChunk: onData,
  });
}
```

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 Binary Stream Buffer Protocol for Mobile WebViews

Tauri 2.0 Zero-Copy Binary Stream Buffer Protocol for Mobile WebViews defines an industrial-grade behavioral standard for mobile engineering. Prohibits base64 stringification and standard JSON serialization across the Tauri 2.0 IPC boundary for media payloads, model weights, and embeddings exceeding 64KB. Mandates direct binary buffer transfers via Tauri 2.0 raw byte streaming channels or custom protocol schemes to eliminate V8/JavaScriptCore heap pressure and prevent immediate mobile OS low-memory termination (OOM). 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: Base64-Encoding Multi-Megabyte Buffers Over JSON IPC Causing Mobile WebView OOM Terminations 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 DriftBase64-Encoding Multi-Megabyte Buffers Over JSON IPC Causing Mobile WebView OOM TerminationsCritical
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 binary data (audio, images, SQLite databases, vector embeddings) using Tauri 2.0 `tauri

Engineers MUST ALWAYS transfer binary data (audio, images, SQLite databases, vector embeddings) using Tauri 2.0 `tauri::ipc::Channel` with raw byte chunks (`Vec<u8>`) or direct ArrayBuffer responses rather than JSON-wrapped base64 strings.

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 `Uint8Array` or `ArrayBuffer` instances to base64 strings (`btoa`, `Buffer.from().toString('base64')`) prior to calling `invoke()` on mobile targets.

Engineers MUST NOT convert `Uint8Array` or `ArrayBuffer` instances to base64 strings (`btoa`, `Buffer.from().toString('base64')`) prior to calling `invoke()` on mobile targets.

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

Rust commands handling payloads larger than 64KB MUST accept or return `tauri

Rust commands handling payloads larger than 64KB MUST accept or return `tauri::ipc::Response` with binary data or stream chunks through `tauri::ipc::Channel<Vec<u8>>` to avoid Serde JSON tree generation.

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

Code streaming multi-megabyte files to the UI MUST implement chunking with a bounded buffer size (recommended 64KB to 256KB per frame) to prevent event loop starvation and garbage collection latency spikes on mobile runtimes.

Code streaming multi-megabyte files to the UI MUST implement chunking with a bounded buffer size (recommended 64KB to 256KB per frame) to prevent event loop starvation and garbage collection latency spikes on mobile 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.
5

Components NEVER store duplicate in-memory ArrayBuffers

Components NEVER store duplicate in-memory ArrayBuffers; instances MUST be transferred to blobs via `URL.createObjectURL` or consumed via `ReadableStream` and immediately dereferenced for garbage collection.

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 Binary Stream Buffer Protocol for Mobile WebViews critical for AI coding assistants?

Prohibits base64 stringification and standard JSON serialization across the Tauri 2.0 IPC boundary for media payloads, model weights, and embeddings exceeding 64KB. Mandates direct binary buffer transfers via Tauri 2.0 raw byte streaming channels or custom protocol schemes to eliminate V8/JavaScriptCore heap pressure and prevent immediate mobile OS low-memory termination (OOM). 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 (Base64-Encoding Multi-Megabyte Buffers Over JSON IPC Causing Mobile WebView OOM Terminations) 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