Skip to content

Scrambled response order when message contains code blocks #1213

Description

@Napping-Lunar

Describe the bug

In responses from qwen3-coder:30b, the response is viewed out of order when there are code snippets in the response. Here is an example message that reproduces the issue:

Repeat the following messages to me:

# Section 1

Here is some code for section 1:
```
print("This is code for section 1")
```

# Section 2

Here is some code for section 2:
```
print("This is code for section 2")
```

When generating the response, I can see the model repeat the messages in the same order, and when running from Ollama CLI it also repeats the messages correctly. However, once the response is complete, Alpaca/the Markdown renderer completely scrambles the message. I have tried the same test for other models (qwen2.5-coder:7b, llama3.2:3b, mistral:latest) and they all repeat the messages correctly too. I have tried without the code blocks in my message, and it does repeat the message correctly, so I suspect the issue is caused by the handling of code blocks.

Expected behavior

Response contains the same sections, plain text, and code snippets, in the same order.

Screenshots

Image

Debugging information

flatpak run com.jeffser.Alpaca
INFO	[main.py | main] Alpaca version: 9.2.5
INFO	[_client.py | _send_single_request] HTTP Request: GET http://0.0.0.0:11434/api/tags "HTTP/1.1 200 OK"
INFO	[_client.py | _send_single_request] HTTP Request: POST http://0.0.0.0:11434/api/show "HTTP/1.1 200 OK"

(Alpaca:2): Gdk-WARNING **: 16:46:26.113: vkAcquireNextImageKHR(): A swapchain no longer matches the surface properties exactly, but can still be used to present to the surface successfully. (VK_SUBOPTIMAL_KHR) (1000001003)

(Alpaca:2): Gdk-WARNING **: 16:46:27.476: vkAcquireNextImageKHR(): A swapchain no longer matches the surface properties exactly, but can still be used to present to the surface successfully. (VK_SUBOPTIMAL_KHR) (1000001003)
INFO	[_client.py | _send_single_request] HTTP Request: POST http://0.0.0.0:11434/api/show "HTTP/1.1 200 OK"
INFO	[_client.py | _send_single_request] HTTP Request: GET http://0.0.0.0:11434/api/tags "HTTP/1.1 200 OK"
INFO	[_client.py | _send_single_request] HTTP Request: POST http://0.0.0.0:11434/api/show "HTTP/1.1 200 OK"
INFO	[_client.py | _send_single_request] HTTP Request: POST http://0.0.0.0:11434/api/chat "HTTP/1.1 200 OK"
INFO	[_client.py | _send_single_request] HTTP Request: POST http://0.0.0.0:11434/api/chat "HTTP/1.1 200 OK"

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions