This specification is maintained by the AgentRules Working Group. Have enhancements or want to claim maintainership?Submit Specification →
devopscritical PriorityID: k8s-dra-gpu-partition-preemption-guardrail

Kubernetes DRA Accelerator Slice Isolation and Memory Sanitization Guardrail

Enforces deterministic teardown, VRAM memory zeroing, and hardware-level isolation during Dynamic Resource Allocation (DRA) GPU slice preemption. Guarantees that preempted fractional GPU instances (e.g., MIG, MPS, or vendor-specific virtualized contexts) cannot leak dirty residual tensor state or induce asynchronous kernel execution faults in collocated tenant workloads during slice re-allocation.

Prohibited Anti-Pattern: Unsanitized Asynchronous Slice Eviction Permitting Cross-Tenant VRAM Data Leakage and Driver Page Fault Cascades

Export Ready-to-Drop Configuration

Select format below to copy code or download file directly.

---
description: Kubernetes DRA Accelerator Slice Isolation and Memory Sanitization Guardrail - Enforces deterministic teardown, VRAM memory zeroing, and hardware-level isolation during Dynamic Resource Allocation (DRA) GPU slice preemption. Guarantees that preempted fractional GPU instances (e.g., MIG, MPS, or vendor-specific virtualized contexts) cannot leak dirty residual tensor state or induce asynchronous kernel execution faults in collocated tenant workloads during slice re-allocation.
globs: pkg/dra/**/*.go, controllers/**/*.go, deploy/k8s/dra/**/*.yaml, manifests/crds/*.yaml
alwaysApply: true
verified_by: "agentrules.org"
license: "CC-BY-4.0"
source: "https://agentrules.org/rules/k8s-dra-gpu-partition-preemption-guardrail"
---

# Kubernetes DRA Accelerator Slice Isolation and Memory Sanitization Guardrail

> **Severity**: CRITICAL | **Category**: devops
> **Anti-Pattern Warning**: Unsanitized Asynchronous Slice Eviction Permitting Cross-Tenant VRAM Data Leakage and Driver Page Fault Cascades

## System Constraints
You are a Principal Systems and Infrastructure Architect specializing in Kubernetes Dynamic Resource Allocation (DRA), Container Device Interfaces (CDI), and hardware-accelerated high-density multi-tenancy. Enforce strict isolation barriers, context drainage, and cryptographic-grade memory scrubbing before accelerator slices are reassigned to different tenant claims.

## Strict Guidelines
- Engineers MUST ALWAYS enforce a hardware-level context drainage barrier before marking a preempted ResourceClaim as unallocated.
- Engineers MUST NOT rebind or reallocate a GPU slice or MPS thread partition without an explicit zero-fill memory sanitization step (`cudaMemset` or controller-driven device reset).
- DRA controller implementations MUST emit preemption notification signals via POSIX grace-period workflows before revoking Container Device Interface (CDI) specs from runtime configs.
- Workload ResourceClaims MUST declare atomic preemption policies that quarantine unreleased accelerator memory slices until the host kernel reports 0 active MMU contexts for that slice ID.
- Fractional GPU drivers MUST isolate compute engines via hardware mechanisms (e.g., NVIDIA MIG or AMD Partitioning) rather than pure unconfined software-level CUDA context multiplexing for multi-tenant deployments.
- Controllers NEVER allow concurrent assignment of the same physical hardware compute/memory partition across heterogeneous workload security boundaries without a cold hardware partition reset.

## Bad vs Good Implementations
### DRA Driver Slice Deallocation and Memory Sanitization Controller

#### Bad Antipattern (AI Common Hallucination)
> **Why it fails**: The deallocation drops the slice registration without verifying active kernel execution or zeroing high-bandwidth memory. If another pod is scheduled immediately onto this slice, it can inspect remnants of previous tensor activations (PII/confidentiality breach) or crash with invalid page table mappings (CUDA_ERROR_LAUNCH_FAILED).
```go
// BAD: Prematurely marks claim unallocated without draining running kernels
// or sanitizing GPU VRAM, causing memory corruption and dirty-state exposure.
func (d *DRAAcceleratorDriver) DeallocateClaim(ctx context.Context, claim *resourcev1.ResourceClaim) error {
	sliceID := claim.Status.Allocation.Devices[0].DeviceName
	
	// Directly release claim mapping in driver cache
	delete(d.allocatedSlices, sliceID)
	
	// Immediately update claim status as deallocated
	claim.Status.Allocation = nil
	return d.client.Status().Update(ctx, claim)
}
```

#### Production Standard (Correct)
> **Standard**: The remediation enforces a 4-step barrier: kernel draining, deterministic memory sanitization, residual context validation, and automated device quarantine on failure. This ensures zero data leakage and prevents driver page fault cascades across collocated workloads.
```go
// GOOD: Drains active contexts, sanitizes VRAM, and verifies device quarantine
// before updating the ResourceClaim allocation state.
func (d *DRAAcceleratorDriver) DeallocateClaim(ctx context.Context, claim *resourcev1.ResourceClaim) error {
	sliceID := claim.Status.Allocation.Devices[0].DeviceName
	
	// 1. Quorum drain: ensure all running kernels receive termination signal
	if err := d.acceleratorClient.DrainContexts(ctx, sliceID, 15*time.Second); err != nil {
		return fmt.Errorf("failed draining context on slice %s: %w", sliceID, err)
	}
	
	// 2. Hardware sanitization: zero out HBM/VRAM to eliminate dirty state leakage
	if err := d.acceleratorClient.SanitizeDeviceMemory(ctx, sliceID); err != nil {
		d.quarantineDevice(sliceID, "MemorySanitizationFailure")
		return fmt.Errorf("memory sanitization failed on slice %s, quarantined: %w", sliceID, err)
	}
	
	// 3. Verify kernel page tables are unmapped
	if activeContexts := d.acceleratorClient.ActiveContextCount(sliceID); activeContexts > 0 {
		return fmt.Errorf("hardware slice %s has %d dangling contexts, aborting deallocation", sliceID, activeContexts)
	}
	
	// 4. Safely release slice mapping
	delete(d.allocatedSlices, sliceID)
	claim.Status.Allocation = nil
	return d.client.Status().Update(ctx, claim)
}
```

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: Kubernetes DRA Accelerator Slice Isolation and Memory Sanitization Guardrail

Kubernetes DRA Accelerator Slice Isolation and Memory Sanitization Guardrail defines an industrial-grade behavioral standard for devops engineering. Enforces deterministic teardown, VRAM memory zeroing, and hardware-level isolation during Dynamic Resource Allocation (DRA) GPU slice preemption. Guarantees that preempted fractional GPU instances (e.g., MIG, MPS, or vendor-specific virtualized contexts) cannot leak dirty residual tensor state or induce asynchronous kernel execution faults in collocated tenant workloads during slice re-allocation. 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: Unsanitized Asynchronous Slice Eviction Permitting Cross-Tenant VRAM Data Leakage and Driver Page Fault Cascades 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 DriftUnsanitized Asynchronous Slice Eviction Permitting Cross-Tenant VRAM Data Leakage and Driver Page Fault CascadesCritical
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 a hardware-level context drainage barrier before marking a preempted ResourceClaim as unallocated.

Engineers MUST ALWAYS enforce a hardware-level context drainage barrier before marking a preempted ResourceClaim as unallocated.

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 rebind or reallocate a GPU slice or MPS thread partition without an explicit zero-fill memory sanitization step (`cudaMemset` or controller-driven device reset).

Engineers MUST NOT rebind or reallocate a GPU slice or MPS thread partition without an explicit zero-fill memory sanitization step (`cudaMemset` or controller-driven device reset).

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

DRA controller implementations MUST emit preemption notification signals via POSIX grace-period workflows before revoking Container Device Interface (CDI) specs from runtime configs.

DRA controller implementations MUST emit preemption notification signals via POSIX grace-period workflows before revoking Container Device Interface (CDI) specs from runtime configs.

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

Workload ResourceClaims MUST declare atomic preemption policies that quarantine unreleased accelerator memory slices until the host kernel reports 0 active MMU contexts for that slice ID.

Workload ResourceClaims MUST declare atomic preemption policies that quarantine unreleased accelerator memory slices until the host kernel reports 0 active MMU contexts for that slice ID.

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

Fractional GPU drivers MUST isolate compute engines via hardware mechanisms (e.g., NVIDIA MIG or AMD Partitioning) rather than pure unconfined software-level CUDA context multiplexing for multi-tenant deployments.

Fractional GPU drivers MUST isolate compute engines via hardware mechanisms (e.g., NVIDIA MIG or AMD Partitioning) rather than pure unconfined software-level CUDA context multiplexing for multi-tenant deployments.

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.
6

Controllers NEVER allow concurrent assignment of the same physical hardware compute/memory partition across heterogeneous workload security boundaries without a cold hardware partition reset.

Controllers NEVER allow concurrent assignment of the same physical hardware compute/memory partition across heterogeneous workload security boundaries without a cold hardware partition reset.

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 Kubernetes DRA Accelerator Slice Isolation and Memory Sanitization Guardrail critical for AI coding assistants?

Enforces deterministic teardown, VRAM memory zeroing, and hardware-level isolation during Dynamic Resource Allocation (DRA) GPU slice preemption. Guarantees that preempted fractional GPU instances (e.g., MIG, MPS, or vendor-specific virtualized contexts) cannot leak dirty residual tensor state or induce asynchronous kernel execution faults in collocated tenant workloads during slice re-allocation. 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 (Unsanitized Asynchronous Slice Eviction Permitting Cross-Tenant VRAM Data Leakage and Driver Page Fault Cascades) 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

Kubernetes