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

Ouverte
#13,383 0 commentaires 0 réactions 0 personnes assignées Voir sur GitHub

Les mainteneurs répondent en général sous 8 jours

Personne n'a encore pris cette issue.

Évaluation

Difficulté
3/5
Temps estimé
1-2 jours
Accessibilité débutants
62/100
Type d'issue
Bug
Clarté
Clairement spécifiée
Activité
Active
Stack technique
ollama, typescript
Domaine
ai

Piste de recherche

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.

Rédigé par le modèle d'indexation à partir du texte de l'issue.

Description

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.

Langage dominant
TypeScript
Étoiles
36.5k
Forks
5.6k
Métriques de merge des PR
Aucune PR mergée en 30 j

Préparer son environnement

Par où commencer

  1. Lisez l'issue en entier, puis le guide de contribution du projet.
  2. Signalez en commentaire que vous la prenez — cela évite que deux personnes fassent le même travail.
  3. Forkez le dépôt et travaillez sur une branche.
  4. Ouvrez une pull request qui référence le numéro de l'issue.

Autres issues de continuedev/continue

Toutes les issues de continuedev/continue

Issues similaires

Plus d'issues TypeScript

Recevez les nouvelles issues par e-mail

Un résumé court des issues GitHub adaptées aux débutants.