compileChatMessages prunes the user turn out of a tool loop; Ollama's qwen3.8 renderer then returns 500 "no user query found in messages"

Đang mở
#13,383 0 bình luận 0 reaction 0 người được giao Xem trên GitHub

Maintainer thường phản hồi trong vòng 8 ngày

Chưa có ai nhận issue này.

Đánh giá

Độ khó
3/5
Thời gian dự kiến
1-2 ngày
Mức phù hợp với người mới
62/100
Loại issue
Lỗi
Độ rõ ràng
Đặc tả rõ ràng
Mức độ hoạt động
Sôi nổi
Công nghệ
ollama, typescript
Lĩnh vực
ai

Hướng nghiên cứu

Start in compileChatMessages in core/llm/countTokens, where the trailing tool sequence is protected and older history is shifted off the front. Run the repro: [system, user, 30 × (assistant toolCalls, tool 2000 chars)] with knownContextLength: 4000 and maxTokens: 1000, then inspect compiledChatMessages. Done means the last user message survives pruning, its tokens are reserved alongside the system and tool sequence, and the reporter's regression test passes. The reporter's local patch is a useful reference, but check it against the existing pruning tests.

Do mô hình lập chỉ mục viết ra từ nội dung của issue.

Mô tả

Version: Continue 2.0.0 (VS Code, Windows), provider openai against Ollama 0.34.0 /v1,
model qwen3.8:27b with num_ctx 131072 and contextLength: 131072.

What happens. In a long agent session (many tool calls, large tool results),
compileChatMessages (core/llm/countTokens) prunes history from the top until it fits
contextLength. It protects the system message and the trailing tool sequence returned by
extractToolSequence, and shifts everything else from the front. When the trailing sequence is
[assistant(tool_calls), tool, …], the first message to go is the opening user turn. The request
then reaches the provider as [system, assistant(tool_calls), tool, …] with no user message.

Ollama's qwen3.8 renderer (model/renderers/qwen35.go, validateMessages, qwen3.8 variant only)
rejects that list: HTTP 500 no user query found in messages. The chat shows the 500 and the
session is dead until the user compacts or starts over. ollama/ollama#17778 tracks the server side
(Ollama's own truncation can produce the same shape), and the maintainer there says the client
should manage the message list rather than rely on the server.

Independent of the 500, a pruned user turn also means the model keeps calling tools without the
task it was asked to do.

Expected. Pruning never drops the last user message. Reserve its tokens next to the system
message and the trailing tool sequence, and keep it in place (or move it to the head) when the
history before it is pruned.

Repro. Any tool loop that exceeds the window; or call compileChatMessages with
[system, user, 30 × (assistant toolCalls, tool 2000 chars)], knownContextLength: 4000,
maxTokens: 1000 and inspect compiledChatMessages: no user role remains. (We run exactly that
against the installed bundle as a regression test.)

Local patch we run (in compileChatMessages, 2.0.0 bundle, works in our sessions):

  inputTokensAvailable -= lastMessagesTokens;
  const pinnedUserMsg = toolSequence.some((m) => m.role === "user") ? void 0 : [...msgsCopy].reverse().find((m) => m.role === "user");
  inputTokensAvailable -= pinnedUserMsg ? countChatMessageTokens(modelName, pinnedUserMsg) : 0;
  …
  const pinnedIndex = pinnedUserMsg ? msgsCopy.indexOf(pinnedUserMsg) : -1;
  const pinnedEntry = pinnedIndex >= 0 ? historyWithTokens.splice(pinnedIndex, 1)[0] : void 0;
  if (pinnedEntry) currentTotal -= pinnedEntry.tokens;
  let prunedCount = 0;
  while (historyWithTokens.length > 0 && currentTotal > inputTokensAvailable) {
    … existing loop, counting shifted entries in prunedCount …
  }
  if (pinnedEntry) {
    historyWithTokens.splice(Math.max(0, pinnedIndex - prunedCount), 0, pinnedEntry);
    currentTotal += pinnedEntry.tokens;
  }

Happy to open a PR if this shape is acceptable.

Ngôn ngữ chính
TypeScript
Star
36.5k
Fork
5.6k
Chỉ số merge pull request
Không có pull request nào được merge trong 30 ngày

Chuẩn bị môi trường

Bắt đầu từ đâu

  1. Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
  2. Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
  3. Fork repository và làm thay đổi trên một nhánh.
  4. Mở pull request có tham chiếu số hiệu của issue.

Issue khác của continuedev/continue

Tất cả issue của continuedev/continue

Issue tương tự

Thêm issue về TypeScript

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.