This specification is maintained by the AgentRules Working Group. Have enhancements or want to claim maintainership?Submit Specification →
devopscritical PriorityID: ebpf-cilium-ringbuffer-nonblocking-invariant

Cilium eBPF Ring Buffer Non-Blocking Telemetry & Drop Invariant

Mandates non-blocking, zero-contention ring buffer reservation patterns across Cilium datapath hooks to prevent kernel latency spikes and packet loss during telemetry saturation. Prohibits blocking calls, retry loops, and packet dropping due to telemetry exhaustion by enforcing atomic metrics increment and immediate event drops under backpressure.

Prohibited Anti-Pattern: Blocking or Unbounded BPF Ring Buffer Submissions Inducing Datapath Packet Drops Under Ingress Storms

Export Ready-to-Drop Configuration

Select format below to copy code or download file directly.

---
description: Cilium eBPF Ring Buffer Non-Blocking Telemetry & Drop Invariant - Mandates non-blocking, zero-contention ring buffer reservation patterns across Cilium datapath hooks to prevent kernel latency spikes and packet loss during telemetry saturation. Prohibits blocking calls, retry loops, and packet dropping due to telemetry exhaustion by enforcing atomic metrics increment and immediate event drops under backpressure.
globs: bpf/**/*.c, bpf/**/*.h, pkg/datapath/**/*.go, pkg/maps/**/*.go, pkg/bpf/**/*.go
alwaysApply: true
verified_by: "agentrules.org"
license: "CC-BY-4.0"
source: "https://agentrules.org/rules/ebpf-cilium-ringbuffer-nonblocking-invariant"
---

# Cilium eBPF Ring Buffer Non-Blocking Telemetry & Drop Invariant

> **Severity**: CRITICAL | **Category**: devops
> **Anti-Pattern Warning**: Blocking or Unbounded BPF Ring Buffer Submissions Inducing Datapath Packet Drops Under Ingress Storms

## System Constraints
You are a Principal Systems Engineer and Kernel Datapath Architect enforcing eBPF Cilium BPF Ring Buffer Non-Blocking Invariants. Mandate strict lockless reservation semantics, immediate telemetry dropping on buffer saturation, atomic drop-counter accounting, and guaranteed non-interference with forwarding verdicts across all eBPF TC and XDP hooks.

## Strict Guidelines
- Engineers MUST ALWAYS use `bpf_ringbuf_reserve` with an immediate NULL verification and non-blocking early return to protect the datapath forwarding path.
- Engineers MUST NEVER block, spin, retry, or allocate dynamic kernel memory within XDP or TC datapath handlers when ring buffer capacity is exhausted.
- Code MUST atomically increment a local per-CPU map drop counter prior to abandoning telemetry submission when `bpf_ringbuf_reserve` returns NULL.
- Services MUST prioritize packet forwarding verdicts (`TC_ACT_OK`, `XDP_PASS`) over telemetry persistence, ensuring that missing telemetry never stalls or drops live traffic.
- Components NEVER use `BPF_RB_FORCE_WAKEUP` unconditionally; instead, use `BPF_RB_NO_WAKEUP` or conditional wakeups based on watermarks to avoid catastrophic CPU inter-processor interrupt (IPI) storms.

## Bad vs Good Implementations
### eBPF Datapath Telemetry Emission: Blocking/Dropping Traffic vs Non-Blocking Ring Buffer Reservation

#### Bad Antipattern (AI Common Hallucination)
> **Why it fails**: Busy-retrying inside an eBPF datapath hook triggers kernel latency spikes and soft lockups. Dropping the actual network packet (TC_ACT_SHOT) when telemetry fails breaks data plane delivery. Forcing wakeups (BPF_RB_FORCE_WAKEUP) per packet causes severe context-switching overhead and IPI storms.
```c
#include <linux/bpf.h>
#include <bpf/bpf_helpers.h>
#include "types.h"

struct {
    __uint(type, BPF_MAP_TYPE_RINGBUF);
    __uint(max_entries, 1 << 24);
} telemetry_events SEC(".maps");

SEC("tc")
int handle_ingress_telemetry(struct __sk_buff *skb) {
    struct event_t *evt;
    int retries = 0;

    // ANTI-PATTERN: Busy-wait retry loop in kernel datapath causes soft lockup
    while (retries < 3) {
        evt = bpf_ringbuf_reserve(&telemetry_events, sizeof(*evt), 0);
        if (evt) {
            break;
        }
        retries++;
    }

    // ANTI-PATTERN: Dropping the network packet if telemetry reservation fails
    if (!evt) {
        return TC_ACT_SHOT;
    }

    evt->sip = skb->remote_ip4;
    evt->dip = skb->local_ip4;
    evt->len = skb->len;

    // ANTI-PATTERN: Forcing wakeups per packet triggers IPI storms under load
    bpf_ringbuf_submit(evt, BPF_RB_FORCE_WAKEUP);
    return TC_ACT_OK;
}
```

#### Production Standard (Correct)
> **Standard**: The good pattern attempts a single non-blocking ring buffer reservation. If saturated, it immediately increments a lockless per-CPU drop counter and forwards the network packet without delay, ensuring kernel stability and zero datapath packet loss during extreme traffic spikes.
```c
#include <linux/bpf.h>
#include <bpf/bpf_helpers.h>
#include "types.h"

struct {
    __uint(type, BPF_MAP_TYPE_RINGBUF);
    __uint(max_entries, 1 << 24);
} telemetry_events SEC(".maps");

struct {
    __uint(type, BPF_MAP_TYPE_PERCPU_ARRAY);
    __type(key, __u32);
    __type(value, __u64);
    __uint(max_entries, 1);
} telemetry_drops SEC(".maps");

SEC("tc")
int handle_ingress_telemetry(struct __sk_buff *skb) {
    struct event_t *evt;
    __u32 drop_key = 0;

    // GOOD: Lockless, single-attempt reservation
    evt = bpf_ringbuf_reserve(&telemetry_events, sizeof(*evt), 0);
    if (!evt) {
        // GOOD: Non-blocking telemetry drop with per-CPU counter metric tracking
        __u64 *drops = bpf_map_lookup_elem(&telemetry_drops, &drop_key);
        if (drops) {
            __sync_fetch_and_add(drops, 1);
        }
        // INVARIANT: Never fail the datapath forwarding verdict due to telemetry saturation
        return TC_ACT_OK;
    }

    evt->sip = skb->remote_ip4;
    evt->dip = skb->local_ip4;
    evt->len = skb->len;

    // GOOD: Let ring buffer adaptive wakeups batch notifications without IPI storms
    bpf_ringbuf_submit(evt, 0);
    return TC_ACT_OK;
}
```

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: Cilium eBPF Ring Buffer Non-Blocking Telemetry & Drop Invariant

Cilium eBPF Ring Buffer Non-Blocking Telemetry & Drop Invariant defines an industrial-grade behavioral standard for devops engineering. Mandates non-blocking, zero-contention ring buffer reservation patterns across Cilium datapath hooks to prevent kernel latency spikes and packet loss during telemetry saturation. Prohibits blocking calls, retry loops, and packet dropping due to telemetry exhaustion by enforcing atomic metrics increment and immediate event drops under backpressure. 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: Blocking or Unbounded BPF Ring Buffer Submissions Inducing Datapath Packet Drops Under Ingress Storms 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 DriftBlocking or Unbounded BPF Ring Buffer Submissions Inducing Datapath Packet Drops Under Ingress StormsCritical
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 `bpf_ringbuf_reserve` with an immediate NULL verification and non-blocking early return to protect the datapath forwarding path.

Engineers MUST ALWAYS use `bpf_ringbuf_reserve` with an immediate NULL verification and non-blocking early return to protect the datapath forwarding path.

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 NEVER block, spin, retry, or allocate dynamic kernel memory within XDP or TC datapath handlers when ring buffer capacity is exhausted.

Engineers MUST NEVER block, spin, retry, or allocate dynamic kernel memory within XDP or TC datapath handlers when ring buffer capacity is exhausted.

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 atomically increment a local per-CPU map drop counter prior to abandoning telemetry submission when `bpf_ringbuf_reserve` returns NULL.

Code MUST atomically increment a local per-CPU map drop counter prior to abandoning telemetry submission when `bpf_ringbuf_reserve` returns NULL.

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 prioritize packet forwarding verdicts (`TC_ACT_OK`, `XDP_PASS`) over telemetry persistence, ensuring that missing telemetry never stalls or drops live traffic.

Services MUST prioritize packet forwarding verdicts (`TC_ACT_OK`, `XDP_PASS`) over telemetry persistence, ensuring that missing telemetry never stalls or drops live traffic.

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 use `BPF_RB_FORCE_WAKEUP` unconditionally

Components NEVER use `BPF_RB_FORCE_WAKEUP` unconditionally; instead, use `BPF_RB_NO_WAKEUP` or conditional wakeups based on watermarks to avoid catastrophic CPU inter-processor interrupt (IPI) storms.

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 Cilium eBPF Ring Buffer Non-Blocking Telemetry & Drop Invariant critical for AI coding assistants?

Mandates non-blocking, zero-contention ring buffer reservation patterns across Cilium datapath hooks to prevent kernel latency spikes and packet loss during telemetry saturation. Prohibits blocking calls, retry loops, and packet dropping due to telemetry exhaustion by enforcing atomic metrics increment and immediate event drops under backpressure. 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 (Blocking or Unbounded BPF Ring Buffer Submissions Inducing Datapath Packet Drops Under Ingress Storms) 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.

1 Rule in Stack

Cilium