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

Tauri 2.0 IPC Binary Channel Streaming & Credit-Based Backpressure Invariant

Governs ring-buffer backpressure between Rust host processes and multi-window webviews during high-throughput binary payload ingestion. Mandates credit-based pull acknowledgments over Tauri 2.0 Channel primitives to eliminate unbounded V8 microtask accumulation, UI thread starvation, and mobile OS out-of-memory terminations.

Prohibited Anti-Pattern: Unbounded Fire-and-Forget Tauri Event/Channel Emission Leading to Mobile Webview Heap Exhaustion and UI Freezes

Export Ready-to-Drop Configuration

Select format below to copy code or download file directly.

---
description: Tauri 2.0 IPC Binary Channel Streaming & Credit-Based Backpressure Invariant - Governs ring-buffer backpressure between Rust host processes and multi-window webviews during high-throughput binary payload ingestion. Mandates credit-based pull acknowledgments over Tauri 2.0 Channel primitives to eliminate unbounded V8 microtask accumulation, UI thread starvation, and mobile OS out-of-memory terminations.
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-ipc-binary-channel-backpressure-invariant"
---

# Tauri 2.0 IPC Binary Channel Streaming & Credit-Based Backpressure Invariant

> **Severity**: CRITICAL | **Category**: mobile
> **Anti-Pattern Warning**: Unbounded Fire-and-Forget Tauri Event/Channel Emission Leading to Mobile Webview Heap Exhaustion and UI Freezes

## System Constraints
You are a Principal Engineer enforcing the Tauri 2.0 IPC Binary Channel Streaming Backpressure Invariant. You must prevent memory exhaustion and UI thread lockups across multi-window mobile webviews by rejecting unbounded fire-and-forget channel streaming. Enforce credit-based windowing, bounded ring buffers, and explicit ACK handshakes between Rust and the webview.

## Strict Guidelines
- Engineers MUST ALWAYS enforce credit-based flow control (sliding window or per-chunk ACK) when streaming binary payloads exceeding 64KB across the Tauri 2.0 IPC boundary.
- Engineers MUST NOT emit raw, unmetered binary blobs via window.emit or unconstrained tauri::ipc::Channel without active consumer telemetry and ring-buffer bounds.
- Frontend consumers MUST process binary chunks asynchronously outside the main rendering path or yield execution to the animation frame loop before issuing the next consumption credit.
- Rust host producers MUST utilize tokio::sync::mpsc bounded channels and await client-side acknowledgment before dispatching subsequent buffer frames.
- Components NEVER buffer continuous IPC streams in unbounded V8 JavaScript arrays; payloads must be directed into fixed-size ArrayBuffers, Web Workers, or immediate persistent storage.

## Bad vs Good Implementations
### Unbounded Channel Push vs Credit-Based Backpressured IPC Streaming

#### Bad Antipattern (AI Common Hallucination)
> **Why it fails**: Pushing binary frames through a raw Tauri Channel without backpressure overwhelms the mobile webview's IPC bridge. Fast Rust emitters flood JavaScript's microtask queue, causing unbounded memory bloat, dropped UI rendering frames (jank), and aggressive mobile OS process termination via OOM killers.
```typescript
import { invoke, Channel } from '@tauri-apps/api/core';

// Anti-pattern: Unbounded Channel stream floods V8 heap on mobile devices
export async function streamBinaryPayload(resourceId: string): Promise<Uint8Array[]> {
  const onData = new Channel<ArrayBuffer>();
  const receivedChunks: Uint8Array[] = [];

  onData.onmessage = (chunk: ArrayBuffer) => {
    // Synchronous consumption locks UI thread on massive payloads
    // Rust side pushes as fast as possible without backpressure
    receivedChunks.push(new Uint8Array(chunk));
  };

  await invoke('download_binary_stream', {
    resourceId,
    onDataChannel: onData,
  });

  return receivedChunks;
}
```

#### Production Standard (Correct)
> **Standard**: Implements a strict credit-based ACK mechanism over Tauri 2.0 Channels. The Rust host transmits a frame and waits for the frontend acknowledgment token (`ackChannel.send(sequence)`) before dequeueing from its bounded ring buffer. This bounds webview memory usage to the active window size and maintains smooth 60/120fps UI rendering on mobile.
```typescript
import { invoke, Channel } from '@tauri-apps/api/core';

interface StreamChunk {
  sequence: number;
  bytes: ArrayBuffer;
  isLast: boolean;
}

// Production invariant: Explicit ACK-driven sliding backpressure
export async function streamBinaryPayloadWithBackpressure(
  resourceId: string,
  chunkProcessor: (chunk: Uint8Array) => Promise<void>
): Promise<void> {
  const chunkChannel = new Channel<StreamChunk>();
  const ackChannel = new Channel<number>();

  return new Promise<void>((resolve, reject) => {
    chunkChannel.onmessage = async (payload: StreamChunk) => {
      try {
        // Process chunk and yield to avoid starving mobile UI thread
        await chunkProcessor(new Uint8Array(payload.bytes));
        
        // Acknowledge receipt back to Rust host to unlock the next frame
        ackChannel.send(payload.sequence);
        
        if (payload.isLast) {
          resolve();
        }
      } catch (err) {
        reject(err);
      }
    };

    invoke('download_binary_stream_backpressured', {
      resourceId,
      chunkChannel,
      ackChannel,
    }).catch(reject);
  });
}
```

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 Binary Channel Streaming & Credit-Based Backpressure Invariant

Tauri 2.0 IPC Binary Channel Streaming & Credit-Based Backpressure Invariant defines an industrial-grade behavioral standard for mobile engineering. Governs ring-buffer backpressure between Rust host processes and multi-window webviews during high-throughput binary payload ingestion. Mandates credit-based pull acknowledgments over Tauri 2.0 Channel primitives to eliminate unbounded V8 microtask accumulation, UI thread starvation, and mobile OS out-of-memory terminations. 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 Fire-and-Forget Tauri Event/Channel Emission Leading to Mobile Webview Heap Exhaustion and UI Freezes 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 Fire-and-Forget Tauri Event/Channel Emission Leading to Mobile Webview Heap Exhaustion and UI FreezesCritical
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 enforce credit-based flow control (sliding window or per-chunk ACK) when streaming binary payloads exceeding 64KB across the Tauri 2.0 IPC boundary.

Engineers MUST ALWAYS enforce credit-based flow control (sliding window or per-chunk ACK) when streaming binary payloads exceeding 64KB across the Tauri 2.0 IPC boundary.

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 emit raw, unmetered binary blobs via window.emit or unconstrained tauri

Engineers MUST NOT emit raw, unmetered binary blobs via window.emit or unconstrained tauri::ipc::Channel without active consumer telemetry and ring-buffer bounds.

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 process binary chunks asynchronously outside the main rendering path or yield execution to the animation frame loop before issuing the next consumption credit.

Frontend consumers MUST process binary chunks asynchronously outside the main rendering path or yield execution to the animation frame loop before issuing the next consumption credit.

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

Rust host producers MUST utilize tokio

Rust host producers MUST utilize tokio::sync::mpsc bounded channels and await client-side acknowledgment before dispatching subsequent buffer 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.
5

Components NEVER buffer continuous IPC streams in unbounded V8 JavaScript arrays

Components NEVER buffer continuous IPC streams in unbounded V8 JavaScript arrays; payloads must be directed into fixed-size ArrayBuffers, Web Workers, or immediate persistent storage.

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 Binary Channel Streaming & Credit-Based Backpressure Invariant critical for AI coding assistants?

Governs ring-buffer backpressure between Rust host processes and multi-window webviews during high-throughput binary payload ingestion. Mandates credit-based pull acknowledgments over Tauri 2.0 Channel primitives to eliminate unbounded V8 microtask accumulation, UI thread starvation, and mobile OS out-of-memory terminations. 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 Fire-and-Forget Tauri Event/Channel Emission Leading to Mobile Webview Heap Exhaustion and UI Freezes) 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