Technical Disclosure — Published Record

IKANDY AI Shader Error Sandbox:
Self-Healing GPU Shader Generation
via Closed-Loop Compile Feedback

Author: IKANDY / ikandyapp  ·  Published: May 14, 2026  ·  Project: IKANDY Music Visualizer

Abstract

This document describes a method implemented in IKANDY for detecting GPU shader compile errors produced by AI-generated GLSL and WGSL code, sending compiler error strings back to the originating large language model, and retrying compilation up to a configurable maximum before surfacing a failure to the user. This method is referred to internally as the AI Shader Error Sandbox.

This publication is a dated technical record. Implementation specifics such as runtime and model versions describe the build published in May 2026 and are preserved for that record; current builds may differ. This page does not provide a legal opinion on patentability, novelty, infringement, validity, or prior-art effect.

Background & Problem Statement

GPU shader languages (GLSL, WGSL) are strictly typed and structurally rigid. Large language models produce syntactically valid code for common patterns but frequently generate shaders that fail at the GPU driver's compile stage due to:

Failure Mode Example Frequency
Immutable binding violation let x = 1.0; x = 2.0; (WGSL let is immutable) Common
Undeclared struct / binding Referencing u.bass without a declared uniform block Common
Type mismatch Assigning vec3 to vec4 field Occasional
Invalid built-in usage Wrong @builtin attribute for vertex vs fragment stage Occasional

In existing LLM-integrated tools, shader compile errors are surfaced directly to the user as raw driver error strings, requiring manual code intervention. No prior system in the music visualizer or real-time graphics domain closes the feedback loop by automatically returning compiler output to the model for self-correction.

Method Overview

1
AI Generation

User submits a natural-language prompt (e.g., "neon audio-reactive waves"). The application sends it to a large language model (Claude Sonnet) with a structured system prompt that constrains output to only the fragment function body — no struct declarations, no binding boilerplate (these are prepended by the host). The model returns a GLSL or WGSL fragment.

generate
2
Compile & Error Capture

The generated fragment is compiled via the WebGL driver (gl.getShaderInfoLog()) or WebGPU driver (device.createShaderModule().getCompilationInfo()). The raw error string from the GPU driver is captured in full — not parsed or summarized.

compile
3
Silent Retry Decision

If compilation succeeds, the shader runs immediately. If it fails and the retry counter is below AUTO_RETRY_MAX (default: 2), the system enters the silent fix loop without notifying the user of a failure. A transient status string (e.g., "compile failed — silent AI auto-fix 1/2…") is shown only in the developer status line.

decide
4
Closed-Loop Feedback to LLM

The system constructs a new LLM request containing the original user prompt, the failed shader source, and the exact GPU compiler error string. The prompt instructs the model: "The shader you wrote produced this GPU compile error: [error]. Rewrite only the fragment function to fix it." No user interaction is required.

ai fix
5
Overwrite & Re-compile

The model's corrected fragment replaces the previous version in memory and on disk (the saved .glsl / .wgsl file is overwritten via IPC). Compilation is attempted again. The loop returns to step 2.

overwrite
6
Fallback or Success

If all retries are exhausted without a successful compile, the manual "Fix with AI" button is exposed so the user can intervene. If any retry succeeds, the shader runs immediately and the retry counter resets. From the user's perspective, the shader either works or it doesn't — intermediate failures are invisible.

resolve
// Pseudocode — error sandbox retry loop
const AUTO_RETRY_MAX = 2;
let retryCount = 0;

async function compileWithSandbox(source, userPrompt, mode) {
  const result = await compile(source, mode);

  if (result.ok) {
    retryCount = 0;
    return result;
  }

  if (retryCount >= AUTO_RETRY_MAX) {
    showManualFixButton();
    return result;
  }

  retryCount++;
  setStatus(`compile failed — silent AI auto-fix ${retryCount}/${AUTO_RETRY_MAX}…`);

  const fixed = await requestAiFix({
    originalPrompt: userPrompt,
    failedSource: source,
    compilerError: result.error,  // raw GPU driver string
    mode
  });

  await saveScene(fixed.code);     // overwrite on disk
  return compileWithSandbox(fixed.code, userPrompt, mode);
}

Technical Characteristics

Existing LLM-integrated shader editors (ShaderToy's community, ISF Editor, Bonzomatic) display compiler errors to the user and require manual correction. No prior system in real-time graphics or music visualizer software implements automatic GPU driver error capture → LLM re-submission → silent on-disk overwrite → recompile as a fully closed, user-invisible feedback loop.

The method combines these elements:

1 AI fragment generation with structural boilerplate isolation
2 Raw GPU driver error string capture (not parsed or summarized)
3 Closed-loop LLM re-submission with error as context
4 Silent on-disk overwrite of the corrected fragment
5 Configurable retry ceiling with user-visible fallback
6 Zero user interaction required during the fix loop

Shader Type Coverage

Shader Type Compiler Error Source Retry Loop Active Notes
GLSL (fragment) gl.getShaderInfoLog() Yes — at generate time + at scene mount scrubGLSL / wrapGLSL applied before each compile
WGSL (fragment) createShaderModule().getCompilationInfo() Yes — at generate time + at scene mount stripUserWgslDuplicates applied before compile; WebGPU async

The loop applies at two distinct points: during the AI generation flow (immediately after first compile attempt) and during browser-mount (when a user clicks a saved user scene card). This means a shader saved from an older AI output that later fails due to a driver update will also self-correct on next load.

Implementation Context

The AI Shader Error Sandbox is implemented in IKANDY, an Electron 30-based music visualizer running on Windows. AI generation calls target the Anthropic Claude API (claude-sonnet-4-20250514). GLSL shaders compile into inline WebGL contexts; WGSL shaders compile into WebGPU pipelines via _wgpuUserScene() in scenes.js. IPC handlers in main.js manage file writes with strict filename regex validation and size caps.

This technical disclosure was published at ikandy.app on its effective date.

Prior Art Search Summary

A limited search of npm, GitHub, and general web sources conducted in May 2026 did not identify a publicly available implementation combining GPU compiler-error capture with closed-loop LLM re-submission for automatic shader self-correction in the sources reviewed. This is a research note, not a comprehensive patent search or legal conclusion.