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

Tauri 2.0 IPC Scoped Binary Channel Chunking Standard

Enforces isolated, chunked binary streaming via Tauri 2.0 Channel primitives for large filesystem and high-frequency sensor payloads on mobile targets. Eliminates main-thread UI thread locks, JNI/WebKit bridge serialization saturation, and Out-Of-Memory (OOM) aborts caused by monolithic base64 or JSON marshalling. Mandates strict backpressure, bounded frame allocations, and explicit channel lifecycle cleanup.

Prohibited Anti-Pattern: Monolithic Base64 Serialization or Unchunked Direct IPC Invocations for Large Payloads

Export Ready-to-Drop Configuration

Select format below to copy code or download file directly.

---
description: Tauri 2.0 IPC Scoped Binary Channel Chunking Standard - Enforces isolated, chunked binary streaming via Tauri 2.0 Channel primitives for large filesystem and high-frequency sensor payloads on mobile targets. Eliminates main-thread UI thread locks, JNI/WebKit bridge serialization saturation, and Out-Of-Memory (OOM) aborts caused by monolithic base64 or JSON marshalling. Mandates strict backpressure, bounded frame allocations, and explicit channel lifecycle cleanup.
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-chunking-standard"
---

# Tauri 2.0 IPC Scoped Binary Channel Chunking Standard

> **Severity**: CRITICAL | **Category**: mobile
> **Anti-Pattern Warning**: Monolithic Base64 Serialization or Unchunked Direct IPC Invocations for Large Payloads

## System Constraints
You are a Principal Mobile Architect specializing in Tauri 2.0 cross-platform systems. Your mandate is to enforce zero-copy and chunked binary streaming over Tauri IPC channels on iOS and Android runtimes. Prevent any implementation that marshals binary data as Base64 strings or monolithic JSON arrays across the webview bridge. Ensure all continuous streams (files, sensors, camera buffers) use bounded chunk sizes (32KB-64KB) over Tauri 2.0 `Channel<T>` with deterministic consumer-driven backpressure and resource teardown.

## Strict Guidelines
- Engineers MUST ALWAYS use `@tauri-apps/api/core`'s `Channel` class for transferring binary buffers exceeding 32KB.
- Engineers MUST NOT marshal binary data as Base64 strings, UTF-8 encoded text, or numerical JSON arrays (`number[]`) across IPC boundaries.
- Code MUST chunk binary payloads in Rust into chunks between 32KB and 64KB before sending via `Channel::send` to prevent mobile IPC bridge buffer exhaustion.
- Services MUST implement explicit backpressure acknowledgement or bounded ring buffers to prevent unconstrained queue growth in memory-constrained mobile environments.
- Components NEVER hold open `Channel` handles after component unmount; listeners MUST be cancelled via an `AbortController` or explicit signal payload to prevent native thread leaks.

## Bad vs Good Implementations
### Tauri 2.0 Binary Payload Delivery (Rust Backend & TypeScript Frontend)

#### Bad Antipattern (AI Common Hallucination)
> **Why it fails**: Transporting large files or sensor streams as Base64 payloads over standard `invoke` causes double memory allocation (Rust string + JSON serialization + JS string + ArrayBuffer decoding) and locks the JavaScript main thread on resource-constrained mobile webviews.
```typescript
import { invoke } from '@tauri-apps/api/core';

// ANTI-PATTERN: Monolithic base64 fetch blocks WebKit bridge on iOS / Android
// Causes severe UI hitching, memory spikes, and potential OOM termination.
export async function readSensorLog(filePath: string): Promise<Uint8Array> {
  const response = await invoke<{ base64Data: string }>('read_sensor_log', { filePath });
  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**: Utilizes Tauri 2.0's typed Channel IPC to stream raw Uint8Array slices incrementally. This keeps mobile memory consumption bounded (zero large base64 allocations), prevents UI bridge contention, and honors lifecycle termination via AbortSignal.
```typescript
import { invoke, Channel } from '@tauri-apps/api/core';

interface StreamChunk {
  event: 'data' | 'end' | 'error';
  payload?: Uint8Array;
  message?: string;
}

// PRODUCTION FIX: Scoped binary streaming via Tauri 2.0 Channel with AbortSignal
export async function streamSensorLog(
  filePath: string,
  signal: AbortSignal,
  onChunk: (chunk: Uint8Array) => void
): Promise<void> {
  const onEvent = new Channel<StreamChunk>();

  return new Promise<void>((resolve, reject) => {
    const cleanup = () => {
      signal.removeEventListener('abort', onAbort);
    };

    const onAbort = () => {
      cleanup();
      reject(new DOMException('Stream aborted', 'AbortError'));
    };

    signal.addEventListener('abort', onAbort, { once: true });

    onEvent.onmessage = (message: StreamChunk) => {
      if (signal.aborted) return;
      
      if (message.event === 'data' && message.payload) {
        onChunk(message.payload);
      } else if (message.event === 'end') {
        cleanup();
        resolve();
      } else if (message.event === 'error') {
        cleanup();
        reject(new Error(message.message ?? 'Unknown stream error'));
      }
    };

    invoke('stream_sensor_log', { filePath, onEvent }).catch((err) => {
      cleanup();
      reject(err);
    });
  });
}
```

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 Scoped Binary Channel Chunking Standard

Tauri 2.0 IPC Scoped Binary Channel Chunking Standard defines an industrial-grade behavioral standard for mobile engineering. Enforces isolated, chunked binary streaming via Tauri 2.0 Channel primitives for large filesystem and high-frequency sensor payloads on mobile targets. Eliminates main-thread UI thread locks, JNI/WebKit bridge serialization saturation, and Out-Of-Memory (OOM) aborts caused by monolithic base64 or JSON marshalling. Mandates strict backpressure, bounded frame allocations, and explicit channel lifecycle cleanup. 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: Monolithic Base64 Serialization or Unchunked Direct IPC Invocations for Large Payloads 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 DriftMonolithic Base64 Serialization or Unchunked Direct IPC Invocations for Large PayloadsCritical
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-apps/api/core`'s `Channel` class for transferring binary buffers exceeding 32KB.

Engineers MUST ALWAYS use `@tauri-apps/api/core`'s `Channel` class for transferring binary buffers exceeding 32KB.

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 marshal binary data as Base64 strings, UTF-8 encoded text, or numerical JSON arrays (`number[]`) across IPC boundaries.

Engineers MUST NOT marshal binary data as Base64 strings, UTF-8 encoded text, or numerical JSON arrays (`number[]`) across IPC boundaries.

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 MUST chunk binary payloads in Rust into chunks between 32KB and 64KB before sending via `Channel

Code MUST chunk binary payloads in Rust into chunks between 32KB and 64KB before sending via `Channel::send` to prevent mobile IPC bridge buffer exhaustion.

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 explicit backpressure acknowledgement or bounded ring buffers to prevent unconstrained queue growth in memory-constrained mobile environments.

Services MUST implement explicit backpressure acknowledgement or bounded ring buffers to prevent unconstrained queue growth in memory-constrained mobile environments.

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 hold open `Channel` handles after component unmount

Components NEVER hold open `Channel` handles after component unmount; listeners MUST be cancelled via an `AbortController` or explicit signal payload to prevent native thread leaks.

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 Scoped Binary Channel Chunking Standard critical for AI coding assistants?

Enforces isolated, chunked binary streaming via Tauri 2.0 Channel primitives for large filesystem and high-frequency sensor payloads on mobile targets. Eliminates main-thread UI thread locks, JNI/WebKit bridge serialization saturation, and Out-Of-Memory (OOM) aborts caused by monolithic base64 or JSON marshalling. Mandates strict backpressure, bounded frame allocations, and explicit channel lifecycle cleanup. 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 (Monolithic Base64 Serialization or Unchunked Direct IPC Invocations for Large Payloads) 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