Repository navigation
Description
Summary
Pasting one image from the clipboard and sending the message shows the user message as [Image 1] [Image 1] even though only one image was attached and sent.
Steps to Reproduce
- On macOS take a screenshot to the clipboard (cmd+ctrl+shift+4 and select an area).
- In the chat input press cmd+v (or ctrl+v) once. The input shows
[Image 1]. - Press Enter to send.
- The user message in the conversation reads
[Image 1] [Image 1].
Expected Behavior
The sent message is rendered once as [Image 1] (or [Image 1] <text> when text was typed next to it), matching the single attachment.
Actual Behavior
The message is rendered as [Image 1] [Image 1]. Only one image is actually attached and sent, so this is a display duplicate, not a double paste.
Root cause
Two independent places produce the same [Image N] placeholder:
InputView.AddImageAttachment(internal/presentation/tui/components/input_view.go) inserts a literal[Image 1]token into the textarea text when the clipboard image is attached. That text is then sent verbatim as the text content part inChatMessageProcessor.buildUserMessage(internal/presentation/tui/handlers/chat_message_processor.go), followed by the image content part.formatting.ExtractTextFromContent(internal/platform/formatting/formatting.go) renders multimodal content by joining the text parts withand appending a generated[Image N]for every image part. For the message above it yields the text part[Image 1]plus the generated[Image 1].
So the second token is not a second paste: GetImageAttachments() holds one attachment, the key handler ran once, and the request carries one image part. The paste key path (handlePaste in internal/presentation/tui/keybinding/actions.go) is not involved beyond the single AddImageAttachment call.
Side effect of the same design: the literal [Image 1] text token is also sent to the model as prose and saved to the prompt history, and the conversation view, headless run encoder, queue box and judge all go through ExtractTextFromContent, so they all show the duplicate.
Reproduction (unit test, fails on main)
func TestRepro1603_PastedImageRendersTwice(t *testing.T) {
textPart, _ := sdk.NewTextContentPart("[Image 1]")
imagePart, _ := sdk.NewImageContentPart("data:image/png;base64,AAAA", nil)
content := sdk.NewMessageContent([]sdk.ContentPart{textPart, imagePart})
got := formatting.ExtractTextFromContent(content, nil)
if got != "[Image 1]" {
t.Fatalf("expected one placeholder, got %q", got)
}
}--- FAIL: TestRepro1603_PastedImageRendersTwice (0.00s)
repro_issue_1603_test.go:19: expected one placeholder, got "[Image 1] [Image 1]"
Proposed fix
Make one of the two sources own the placeholder. The smallest change is in ExtractTextFromContent: when a text part already contains the [Image N] token for image part N, do not append the generated one. That fixes every renderer at once and keeps the in-input token (which is what tells the user where the image sits in the text). Alternatively strip the [Image N] tokens from the text part in buildUserMessage before sending, but then an image-only message has an empty text part and renders with a leading space, so that path needs a trim too.
Either way add the test above (adjusted to the chosen behaviour) next to TestInputView_AddImageAttachment in input_view_test.go and the ExtractTextFromContent tests in formatting_extra_test.go.
Activity
inference-gateway-maintainer commentedon Oct 26, 2026
Reproduced and refined the description above.
It is not a double paste: one key press, one attachment, one image part in the request. The duplicate comes from two places both emitting the
[Image N]placeholder:InputView.AddImageAttachmentinserts a literal[Image 1]into the input text, andformatting.ExtractTextFromContentappends a generated[Image 1]for the image part when rendering the sent message. A failing unit test againstExtractTextFromContentis in the body, along with the suggested fix (skip the generated placeholder when the text part already carries the token).edenreich commentedon Oct 26, 2026
@infer can you fix this? use /ponytail:ponytail /go
inference-gateway-maintainer commentedon Oct 26, 2026
Model:
ollama_cloud/glm-5.3-flash· Action:v0.59.0· CLI:v0.235.0· Gateway:v0.60.1· View JobTodos
Pull Request
#1604
✅ Infer Result: Success
All done. Since my last tree check nothing in the repo changed (only PR/issue metadata), and earlier
git status -sbshowed a clean, synced branch. Work summary:Fixed: pasted image renders as duplicate
[Image 1] [Image 1]PR: #1604 (ready for review, branch
fix/issue-1603, resolves #1603)Root cause: Two independent sources produced the placeholder for the same image - the chat paste inserts a literal
[Image N]token into the user's input text (InputView.AddImageAttachment), which is sent verbatim as the text content part, andformatting.ExtractTextFromContentappended its own generated[Image N]for the image part. Every renderer (conversation view, headless run encoder, queue box, judge) goes through the extractor, so all showed the duplicate.Fix (one place, all renderers):
ExtractTextFromContentininternal/platform/formatting/formatting.gonow skips the generated placeholder when the accumulated text already carries that exact[Image N]token. This is the option the issue proposed as smallest and most complete: the in-input token (which tells the user where the image sits in the text) stays, image-only and token-plus-prose forms still render correctly, and multi-image messages keep unique numbering ([Image 1]in text + two image parts still yields[Image 1] [Image 2]).Tests:
formatting_extra_test.go: three new table cases forTestExtractTextFromContent(repro renders once, token beside prose stays as typed, one token suppresses only its own image).input_view_test.go:TestInputView_AddImageAttachmentRendersOncereproduces the user flow end to end (one paste, message built the waybuildUserMessagebuilds it, single render) - it fails on main and passes with the fix.Validation: full
task testsuite,task vet, andtask precommit:run(mod tidy, mocks, fmt, lint:imports, golangci-lint 0 issues, markdownlint) all pass; branch is pushed and synced.Board/docs: issue added to Roadmap 2026 (In progress, then QA), and a best-effort
[DOCS]tracking issue filed as inference-gateway/docs#1029 since this is a user-facing rendering change no docs page currently describes (checked configuration-reference, directory-structure and shortcuts-guide).I did not rerun mock-gateway TUI e2e scenarios or verify against a live model; the dedupe is a whole-string token check, so a user typing the literal text
[Image 1]alongside a real paste now gets one placeholder where the extractor path is used (the in-input display is unaffected).ponytail: 6-line diff + 2 tests, everything else left alone - the remaining risk is the literal-token heuristic above.
Model:
ollama_cloud/glm-5.3-flash· Action:v0.59.0· CLI:v0.235.0· Gateway:v0.60.1· Exit Code:0· Duration: 11m 34sTokens: 2,970,521 in · 21,055 out · 2,991,576 total (49 requests)
Tool calls: 53 total · 100% success rate
Traces
Stats
Triggered by edenreich · Infer Action · OSS
fix(formatting): render a pasted image placeholder only once (#1604)
inference-gateway-releaser commentedon Oct 26, 2026
🎉 This issue has been resolved in version 0.236.1 🎉
The release is available on:
Your semantic-release bot 📦🚀