This specification is maintained by the AgentRules Working Group. Have enhancements or want to claim maintainership?Submit Specification →
mobilecritical PriorityID: tauri-v2-shm-ring-buffer-invariant

Tauri 2.0 Inter-Webview SharedArrayBuffer Ring Buffer Protocol

Enforces a zero-copy lock-free ring buffer backed by SharedArrayBuffer and Atomics across Tauri 2.0 multi-webview instances. Bypasses IPC JSON-serialization latency to guarantee deterministic 120 FPS binary telemetry rendering on resource-constrained mobile and desktop platforms. Eliminates event-loop starvation and GC pressure by prohibiting JSON marshalling for high-frequency binary streams.

Prohibited Anti-Pattern: Marshalling 120 FPS Binary Telemetry via Stringified IPC Events Across Webviews

Export Ready-to-Drop Configuration

Select format below to copy code or download file directly.

---
description: Tauri 2.0 Inter-Webview SharedArrayBuffer Ring Buffer Protocol - Enforces a zero-copy lock-free ring buffer backed by SharedArrayBuffer and Atomics across Tauri 2.0 multi-webview instances. Bypasses IPC JSON-serialization latency to guarantee deterministic 120 FPS binary telemetry rendering on resource-constrained mobile and desktop platforms. Eliminates event-loop starvation and GC pressure by prohibiting JSON marshalling for high-frequency binary streams.
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-shm-ring-buffer-invariant"
---

# Tauri 2.0 Inter-Webview SharedArrayBuffer Ring Buffer Protocol

> **Severity**: CRITICAL | **Category**: mobile
> **Anti-Pattern Warning**: Marshalling 120 FPS Binary Telemetry via Stringified IPC Events Across Webviews

## System Constraints
You are a Principal Mobile Systems Architect enforcing lock-free binary communication across isolated webview runtimes in Tauri 2.0. Mandate the use of SharedArrayBuffer with Atomics-driven circular ring buffers for any data streams exceeding 30Hz or 64KB/sec. Never allow serde_json serialization, IPC invoke overhead, or Tauri standard event emitters for high-frequency binary telemetry.

## Strict Guidelines
- Engineers MUST ALWAYS enforce Cross-Origin-Opener-Policy (same-origin) and Cross-Origin-Embedder-Policy (require-corp) headers in tauri.conf.json to enable SharedArrayBuffer instantiation.
- Engineers MUST NOT serialize binary telemetry through Tauri core IPC channels (invoke or emit) when frequency exceeds 30 FPS.
- Code SHOULD align ring buffer memory layouts to 64-bit boundaries with atomic head/tail pointers placed in a dedicated 64-byte metadata header.
- Services MUST synchronize ring buffer read/write indices using Atomics.wait, Atomics.notify, and memory barriers (Atomics.load/store with SeqCst).
- Components NEVER allocate memory inside the consumption loop; render directly from typed array views mapped to the SharedArrayBuffer.

## Bad vs Good Implementations
### High-Frequency Telemetry Transmission Across Webviews

#### Bad Antipattern (AI Common Hallucination)
> **Why it fails**: Array.from() allocates heavily every frame, and Tauri's standard IPC parses and stringifies JSON across the webview boundary. At 120 FPS, this causes GC thrashing, event-loop starvation, and frame drops on mobile devices.
```typescript
import { emit, listen } from '@tauri-apps/api/event';

// ANTI-PATTERN: High-frequency telemetry via Tauri IPC event emitter
// Causes catastrophic JSON serialization overhead, GC pauses, and drops below 120 FPS
export function streamTelemetry(telemetryData: Float64Array) {
  const payload = Array.from(telemetryData); // Unnecessary allocation
  setInterval(async () => {
    await emit('telemetry-update', { data: payload, timestamp: performance.now() });
  }, 8); // ~120 Hz target
}

export function subscribeTelemetry() {
  listen<{ data: number[]; timestamp: number }>('telemetry-update', (event) => {
    console.log('Received telemetry frame:', event.payload.timestamp);
  });
}
```

#### Production Standard (Correct)
> **Standard**: Implements a zero-copy lock-free ring buffer across SharedArrayBuffer with atomic pointer management. Decouples reader and writer execution, eliminates JSON serialization, incurs zero runtime GC allocations, and maintains deterministic 120 FPS performance.
```typescript
export const HEADER_SIZE_BYTES = 64; // 8 bytes head, 8 bytes tail, 48 bytes reserved padding
export const HEAD_INDEX = 0; // Int32 index in Int32Array view
export const TAIL_INDEX = 1;

export class TelemetryRingBuffer {
  private readonly meta: Int32Array;
  private readonly data: Float32Array;
  private readonly capacity: number;

  constructor(private readonly sab: SharedArrayBuffer, capacitySamples: number) {
    this.meta = new Int32Array(sab, 0, HEADER_SIZE_BYTES / Int32Array.BYTES_PER_ELEMENT);
    this.data = new Float32Array(sab, HEADER_SIZE_BYTES, capacitySamples);
    this.capacity = capacitySamples;
  }

  public write(samples: Float32Array): boolean {
    const count = samples.length;
    const head = Atomics.load(this.meta, HEAD_INDEX);
    const tail = Atomics.load(this.meta, TAIL_INDEX);
    
    // Check available space
    const available = this.capacity - ((head - tail) & (this.capacity - 1));
    if (count > available) return false; // Buffer overflow dropped deterministically

    const start = head & (this.capacity - 1);
    const toWrite = Math.min(count, this.capacity - start);
    
    this.data.set(samples.subarray(0, toWrite), start);
    if (count > toWrite) {
      this.data.set(samples.subarray(toWrite), 0);
    }

    Atomics.store(this.meta, HEAD_INDEX, (head + count) | 0);
    Atomics.notify(this.meta, HEAD_INDEX, 1);
    return true;
  }

  public read(out: Float32Array): number {
    const head = Atomics.load(this.meta, HEAD_INDEX);
    const tail = Atomics.load(this.meta, TAIL_INDEX);
    const available = (head - tail) & (this.capacity - 1);
    if (available === 0) return 0;

    const count = Math.min(available, out.length);
    const start = tail & (this.capacity - 1);
    const toRead = Math.min(count, this.capacity - start);

    out.set(this.data.subarray(start, start + toRead), 0);
    if (count > toRead) {
      out.set(this.data.subarray(0, count - toRead), toRead);
    }

    Atomics.store(this.meta, TAIL_INDEX, (tail + count) | 0);
    return count;
  }
}
```

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 Inter-Webview SharedArrayBuffer Ring Buffer Protocol

Tauri 2.0 Inter-Webview SharedArrayBuffer Ring Buffer Protocol defines an industrial-grade behavioral standard for mobile engineering. Enforces a zero-copy lock-free ring buffer backed by SharedArrayBuffer and Atomics across Tauri 2.0 multi-webview instances. Bypasses IPC JSON-serialization latency to guarantee deterministic 120 FPS binary telemetry rendering on resource-constrained mobile and desktop platforms. Eliminates event-loop starvation and GC pressure by prohibiting JSON marshalling for high-frequency binary streams. 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: Marshalling 120 FPS Binary Telemetry via Stringified IPC Events Across Webviews 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 DriftMarshalling 120 FPS Binary Telemetry via Stringified IPC Events Across WebviewsCritical
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 Cross-Origin-Opener-Policy (same-origin) and Cross-Origin-Embedder-Policy (require-corp) headers in tauri.conf.json to enable SharedArrayBuffer instantiation.

Engineers MUST ALWAYS enforce Cross-Origin-Opener-Policy (same-origin) and Cross-Origin-Embedder-Policy (require-corp) headers in tauri.conf.json to enable SharedArrayBuffer instantiation.

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 serialize binary telemetry through Tauri core IPC channels (invoke or emit) when frequency exceeds 30 FPS.

Engineers MUST NOT serialize binary telemetry through Tauri core IPC channels (invoke or emit) when frequency exceeds 30 FPS.

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 align ring buffer memory layouts to 64-bit boundaries with atomic head/tail pointers placed in a dedicated 64-byte metadata header.

Code SHOULD align ring buffer memory layouts to 64-bit boundaries with atomic head/tail pointers placed in a dedicated 64-byte metadata header.

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 synchronize ring buffer read/write indices using Atomics.wait, Atomics.notify, and memory barriers (Atomics.load/store with SeqCst).

Services MUST synchronize ring buffer read/write indices using Atomics.wait, Atomics.notify, and memory barriers (Atomics.load/store with SeqCst).

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 memory inside the consumption loop

Components NEVER allocate memory inside the consumption loop; render directly from typed array views mapped to the SharedArrayBuffer.

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 Inter-Webview SharedArrayBuffer Ring Buffer Protocol critical for AI coding assistants?

Enforces a zero-copy lock-free ring buffer backed by SharedArrayBuffer and Atomics across Tauri 2.0 multi-webview instances. Bypasses IPC JSON-serialization latency to guarantee deterministic 120 FPS binary telemetry rendering on resource-constrained mobile and desktop platforms. Eliminates event-loop starvation and GC pressure by prohibiting JSON marshalling for high-frequency binary streams. 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 (Marshalling 120 FPS Binary Telemetry via Stringified IPC Events Across Webviews) 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