Feature hasn't been suggested before.
Describe the enhancement you want to request
I am experiencing significant performance issues when using OpenCode with local LLMs (inference engines like vLLM or Ollama). The context cache prefix is frequently invalidated, forcing the engine to reprocess the entire conversation history, which is very slow on local hardware.
According to technical analysis (e.g., tests conducted by the Nicefox YouTube channel), OpenCode breaks the cache for several reasons:
Tool Switching: When switching between "Plan" and "Build" modes, the list of available tools changes. Since tools are part of the request prefix, this modification invalidates the cache.
History Modification: Instead of only appending new messages, OpenCode sometimes modifies previous messages in the history (for example, adding/removing "system reminders" about the current mode). Any change in the middle of the message history forces a full reprocessing of the context.
Compaction: The conversation compaction process does not seem to preserve the cache prefix.
Expected Behavior: The tools and the system prompt should remain constant (or be managed incrementally) across different modes to allow the inference engine to reuse the cached prefix. Previous messages should not be altered once they are part of the context.
Comment reproduire le bug ?
Pour prouver que le cache est "cassé", vous pouvez suivre ce protocole expérimental décrit dans les sources :
Préparation : Utilisez un moteur d'inférence local (comme vLLM) et, si possible, un proxy (comme LiteLLM) qui permet de voir si le préfixe de cache est réutilisé ou si le texte est "re-processé".
Étape 1 (Mode Plan) : Démarrez une session en mode Plan et envoyez un message simple (par exemple : "Bonjour"). Notez le temps de réponse.
Étape 2 (Bascule de mode) : Passez en mode Build et renvoyez un message (par exemple : "Peux-tu m'aider ?").
Observation : Vous remarquerez que le moteur d'IA doit analyser à nouveau toute la conversation car OpenCode a changé la liste des outils disponibles entre les deux modes, ce qui "invalide" le cache.
Étape 3 (Vérification de l'historique) : Regardez les requêtes envoyées. Vous constaterez qu'OpenCode modifie souvent le contenu de votre premier message (en y insérant des rappels système au lieu de les mettre dans un nouveau message), ce qui change le "hash" du préfixe et casse le cache.
Étape 4 (Compaction) : Continuez la conversation jusqu'à ce que l'outil déclenche automatiquement le compactage de l'historique. Vous verrez que le temps de traitement devient extrêmement long car l'intégralité du contexte est à nouveau recalculée.
Feature hasn't been suggested before.
Describe the enhancement you want to request
I am experiencing significant performance issues when using OpenCode with local LLMs (inference engines like vLLM or Ollama). The context cache prefix is frequently invalidated, forcing the engine to reprocess the entire conversation history, which is very slow on local hardware.
According to technical analysis (e.g., tests conducted by the Nicefox YouTube channel), OpenCode breaks the cache for several reasons:
Expected Behavior: The tools and the system prompt should remain constant (or be managed incrementally) across different modes to allow the inference engine to reuse the cached prefix. Previous messages should not be altered once they are part of the context.
Comment reproduire le bug ?
Pour prouver que le cache est "cassé", vous pouvez suivre ce protocole expérimental décrit dans les sources :