Skip to content

Prevent assistant image hash placeholders from leaking into follow-up LLM prompts#156

Draft
Copilot wants to merge 5 commits into
masterfrom
copilot/fix-image-hash-generation-issue
Draft

Prevent assistant image hash placeholders from leaking into follow-up LLM prompts#156
Copilot wants to merge 5 commits into
masterfrom
copilot/fix-image-hash-generation-issue

Conversation

Copilot AI commented Mar 26, 2026

Copy link
Copy Markdown
Contributor

Generated images were being persisted as internal markdown placeholders containing file-hash:..., and those placeholders could be replayed back into later assistant context. After a few image generations, the model could start echoing hash-like strings instead of treating prior outputs as images.

  • Prompt serialization

    • Strip internal assistant image placeholders from outbound OpenRouter text before sending history back to the model.
    • Keep image inputs intact by continuing to hydrate the real attachments from file_hashes.
  • Supported placeholder formats

    • Handles the current persisted form:
      • ![file-hash:HASH](...)
    • Handles legacy forms:
      • ![alt](file-hash:HASH)
      • ![alt](blob:file-hash:HASH)
  • Regression coverage

    • Added focused tests around buildOpenRouterMessages() to verify:
      • placeholder text is removed from assistant messages
      • whitespace is normalized after removal
      • images are still attached from file_hashes
const orMessages = await buildOpenRouterMessages([
  {
    role: 'assistant',
    content: 'Here is the image.\n\n![file-hash:abc123](...)',
    file_hashes: JSON.stringify(['abc123']),
  },
]);

// outbound assistant text no longer contains the internal placeholder
// but the hydrated image is still present as an image_url part

Warning

Firewall rules blocked me from connecting to one or more addresses (expand for details)

I tried to connect to the following addresses, but was blocked by firewall rules:

  • 0.0.0.0.in-addr.arpa
    • Triggering command: /home/REDACTED/work/_temp/ghcca-node/node/bin/node node /home/REDACTED/work/or3-chat/or3-chat/node_modules/.bin/nuxt dev --host 0.0.0.0 --port 3000 ash it} --global /usr/local/bin/git cat /pro�� (dns block)
  • api.fontshare.com
    • Triggering command: /home/REDACTED/work/_temp/ghcca-node/node/bin/node node /home/REDACTED/work/or3-chat/or3-chat/node_modules/.bin/nuxt build (dns block)
    • Triggering command: /home/REDACTED/work/_temp/ghcca-node/node/bin/node node /home/REDACTED/work/or3-chat/or3-chat/node_modules/.bin/nuxt build hat/node_modules/vite/node_modules/@esbuild/linux-x64/bin/esbuild -c o | grep "physical id" | sort |uniq | wc -l (dns block)
    • Triggering command: /home/REDACTED/work/_temp/ghcca-node/node/bin/node node /home/REDACTED/work/or3-chat/or3-chat/node_modules/.bin/nuxt dev --host 0.0.0.0 --port 3000 ash it} --global /usr/local/bin/git cat /pro�� (dns block)
  • api.fontsource.org
    • Triggering command: /home/REDACTED/work/_temp/ghcca-node/node/bin/node node /home/REDACTED/work/or3-chat/or3-chat/node_modules/.bin/nuxt build (dns block)
    • Triggering command: /home/REDACTED/work/_temp/ghcca-node/node/bin/node node /home/REDACTED/work/or3-chat/or3-chat/node_modules/.bin/nuxt build hat/node_modules/vite/node_modules/@esbuild/linux-x64/bin/esbuild -c o | grep "physical id" | sort |uniq | wc -l (dns block)
    • Triggering command: /home/REDACTED/work/_temp/ghcca-node/node/bin/node node /home/REDACTED/work/or3-chat/or3-chat/node_modules/.bin/nuxt dev --host 0.0.0.0 --port 3000 ash it} --global /usr/local/bin/git cat /pro�� (dns block)
  • fonts.bunny.net
    • Triggering command: /home/REDACTED/work/_temp/ghcca-node/node/bin/node node /home/REDACTED/work/or3-chat/or3-chat/node_modules/.bin/nuxt build (dns block)
    • Triggering command: /home/REDACTED/work/_temp/ghcca-node/node/bin/node node /home/REDACTED/work/or3-chat/or3-chat/node_modules/.bin/nuxt build hat/node_modules/vite/node_modules/@esbuild/linux-x64/bin/esbuild -c o | grep "physical id" | sort |uniq | wc -l (dns block)
    • Triggering command: /home/REDACTED/work/_temp/ghcca-node/node/bin/node node /home/REDACTED/work/or3-chat/or3-chat/node_modules/.bin/nuxt dev --host 0.0.0.0 --port 3000 ash it} --global /usr/local/bin/git cat /pro�� (dns block)
  • fonts.google.com
    • Triggering command: /home/REDACTED/work/_temp/ghcca-node/node/bin/node node /home/REDACTED/work/or3-chat/or3-chat/node_modules/.bin/nuxt build (dns block)
    • Triggering command: /home/REDACTED/work/_temp/ghcca-node/node/bin/node node /home/REDACTED/work/or3-chat/or3-chat/node_modules/.bin/nuxt build hat/node_modules/vite/node_modules/@esbuild/linux-x64/bin/esbuild -c o | grep "physical id" | sort |uniq | wc -l (dns block)
    • Triggering command: /home/REDACTED/work/_temp/ghcca-node/node/bin/node node /home/REDACTED/work/or3-chat/or3-chat/node_modules/.bin/nuxt dev --host 0.0.0.0 --port 3000 ash it} --global /usr/local/bin/git cat /pro�� (dns block)

If you need me to access, download, or install something from one of these locations, you can either:

Original prompt

When im talking in a chat and i have an image generation llm model it works ok, but after i one or two generations the llm starts sending back the image hash.

What i think is happening is that the image hash is being sent to the llm instead of the image, and it's confused/recognizing the hash pattern, so instead of generating another image it generates a hash.

Look into it and see if you can solve this issue


📍 Connect Copilot coding agent with Jira, Azure Boards or Linear to delegate work to Copilot in one click without leaving your project management tool.

@cloudflare-workers-and-pages

cloudflare-workers-and-pages Bot commented Mar 26, 2026

Copy link
Copy Markdown

Deploying or3-chat with  Cloudflare Pages  Cloudflare Pages

Latest commit: 166a6ed
Status:🚫  Build failed.

View logs

Copilot AI and others added 3 commits March 26, 2026 04:43
Copilot AI changed the title [WIP] Fix image hash being generated instead of images Prevent assistant image hash placeholders from leaking into follow-up LLM prompts Mar 26, 2026
Copilot AI requested a review from Saluana March 26, 2026 04:49
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.

2 participants