Architectural Invariant Design: KMP StateFlow Telemetry Debounce & Conflation Barrier for Declarative UI
KMP StateFlow Telemetry Debounce & Conflation Barrier for Declarative UI defines an industrial-grade behavioral standard for mobile engineering. High-frequency streaming inputs (e.g., BLE packets, GPS fixes, sensor feeds, audio telemetry) emitted directly into shared Kotlin Multiplatform StateFlow pipelines saturate the main UI thread in Jetpack Compose and SwiftUI. Shared ViewModels must enforce a conflation and temporal sampling barrier on Dispatchers.Default before exposing UI state. This guarantees that frame rendering cycles (60Hz/120Hz) are never overwhelmed by non-visual intermediary state mutations. Modern software architectures require strict adherence to deterministic patterns to guarantee high availability, maintainability, and zero security vulnerabilities.
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 Mode | AI Symptom (The Anti-Pattern) | Severity | Production Impact & Remedy |
|---|---|---|---|
| AI Hallucination & Deprecation Drift | Binding Unbounded High-Frequency Telemetry Flows Directly to UI StateFlows Without Conflation Barriers | 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 Inconsistency | AI 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. |
Step-by-Step Production Directives
Each rule constraint below is injected into the AI agent's system prompt to establish deterministic boundaries:
Engineers MUST ALWAYS isolate high-frequency telemetry ingestion flows on `Dispatchers.Default` and apply `.conflate()` or `.sample(windowMillis)` before exposing data via `stateIn`.
Engineers MUST ALWAYS isolate high-frequency telemetry ingestion flows on `Dispatchers.Default` and apply `.conflate()` or `.sample(windowMillis)` before exposing data via `stateIn`.
Engineers MUST NOT bind raw sensor, BLE, or socket event streams directly to a `MutableStateFlow` consumed by declarative UI layers in Compose or SwiftUI.
Engineers MUST NOT bind raw sensor, BLE, or socket event streams directly to a `MutableStateFlow` consumed by declarative UI layers in Compose or SwiftUI.
Code SHOULD enforce a minimum 16ms to 33ms sampling window (30fps - 60fps ceiling) for continuous numeric/spatial telemetry intended solely for UI presentation.
Code SHOULD enforce a minimum 16ms to 33ms sampling window (30fps - 60fps ceiling) for continuous numeric/spatial telemetry intended solely for UI presentation.
Services MUST process lossless telemetry records on dedicated background coroutine scopes independent of presentation state holders.
Services MUST process lossless telemetry records on dedicated background coroutine scopes independent of presentation state holders.
Components NEVER collect unthrottled shared StateFlows on `Dispatchers.Main` without an upstream throttle or conflate operator.
Components NEVER collect unthrottled shared StateFlows on `Dispatchers.Main` without an upstream throttle or conflate operator.
Frequently Asked Technical Questions
Common questions developers face when configuring AI coding assistants for this stack:
Q:Why is KMP StateFlow Telemetry Debounce & Conflation Barrier for Declarative UI critical for AI coding assistants?
High-frequency streaming inputs (e.g., BLE packets, GPS fixes, sensor feeds, audio telemetry) emitted directly into shared Kotlin Multiplatform StateFlow pipelines saturate the main UI thread in Jetpack Compose and SwiftUI. Shared ViewModels must enforce a conflation and temporal sampling barrier on Dispatchers.Default before exposing UI state. This guarantees that frame rendering cycles (60Hz/120Hz) are never overwhelmed by non-visual intermediary state mutations. 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 (Binding Unbounded High-Frequency Telemetry Flows Directly to UI StateFlows Without Conflation Barriers) 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.