Skip to content

studio-agent: a shader write goes on the live canvas at once, not only with the next compile - #257

Merged
petersalomonsen merged 1 commit into
masterfrom
agent-shader-applies-live
Oct 11, 2026
Merged

petersalomonsen merged 1 commit into
masterfrom
agent-shader-applies-live

Conversation

@petersalomonsen

Copy link
Copy Markdown
Owner

Problem

In a session where the agent built a starfield with text boxes, its shader changes often didn't show. To see them, the user had to say "text is not showing" or stop and start the song.

Cause: the visualizer only picks up a new shader inside compileSong(). set_shader / edit_shader only write the editor, and the prompt told the agent "compile also applies the shader". So a shader edit made after the agent's last compile never reached the canvas. The session log shows this every time:

  • set_shader → compile → edit_shader: the last edit wasn't live.
  • A turn with two edit_shader calls and no compile at all.

Each time the agent replied "Compiled; live now". It can't see the live canvas, only its own render_shader frames.

Fix

  • editorcontroller.js: new window.applyShaderToCanvas() puts the shader editor's source on the live canvas and returns the GLSL error or null. A shader that fails to compile throws before it's switched in, so the previous one keeps running. compileSong's change check is untouched, so the next compile still sees the new shader and saves it to the project.
  • client.js: every agent shader write (set_shader, edit_shader, run_script's setShader) calls it. The tool result says either live on the canvas now (compile saves it to the project) or ERROR: the shader does not compile, so the canvas keeps the previous one: followed by the GLSL log.
  • prompt.js: the one line that said compile applies the shader now describes this. It replaces that line rather than adding a rule.

Testing

  • New e2e test in studio-agent-mock.spec.js, local repo, no NEAR sandbox needed. It reads the live canvas pixels: green after set_shader, magenta after an edit_shader with no compile, and still magenta after a broken edit, which returns the GLSL error. With the fix stashed, it fails.
  • The existing render_shader test, npm run test-agent-tools (160/160), and the studio-agent performance/kit/nearai/abort and video-export specs (17) pass.

🤖 Generated with Claude Code

…y with the next compile

The visualizer only picked up a new shader in compileSong(), while
set_shader/edit_shader only wrote the editor. A shader edit made after the
agent's last compile never reached the canvas, and the agent, which cannot see
the canvas, still reported it live. The user had to say "it's not showing" or
stop and start the song.

Every agent shader write (set_shader, edit_shader, run_script setShader) now
calls window.applyShaderToCanvas(). The tool result says it is live, or gives
the GLSL error verbatim while the canvas keeps the previous shader. compile
still saves the shader to the project. The prompt line "compile also applies
the shader" now describes this instead.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@cloudflare-workers-and-pages

Copy link
Copy Markdown

Deploying webassemblymusic with  Cloudflare Pages  Cloudflare Pages

Latest commit: 35cf6a4
Status: ✅  Deploy successful!
Preview URL: https://73bd6133.webassemblymusic.pages.dev
Branch Preview URL: https://agent-shader-applies-live.webassemblymusic.pages.dev

View logs

@petersalomonsen
petersalomonsen merged commit 2b62810 into master Oct 11, 2026
9 checks passed
@petersalomonsen
petersalomonsen deleted the agent-shader-applies-live branch October 11, 2026 13:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant