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

オープン
#13,383 コメント 0 件 リアクション 0 件 担当者 0 名 GitHub で見る

メンテナーはふだん 8 日以内に返信

まだ誰も着手していません。

評価

難易度
3/5
見積もり時間
1〜2日
初心者へのやさしさ
62/100
issue の種類
バグ
明瞭さ
明確に書かれている
活発さ
活発
技術スタック
ollama, typescript
領域
ai

調査の方向性

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.

索引モデルが issue の本文から書いたものです。

説明

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.

主要言語
TypeScript
スター
36.5k
フォーク
5.6k
PR マージ指標
30日以内にマージされた PR はありません

環境構築

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

continuedev/continue のほかの issue

continuedev/continue の issue をすべて見る

似ている issue

TypeScript の issue をもっと見る

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。