Translation cache key ignores service, model and system prompt, entries never expire

Abierto Apto para principiantes
#480 0 comentarios 0 reacciones 0 asignados Ver en GitHub

Los mantenedores suelen responder en 1 día

Nadie ha tomado este issue todavía.

Evaluación

Dificultad
2/5
Tiempo estimado
1-3 horas
Aptitud para principiantes
76/100
Tipo de issue
Error
Claridad
Bien especificado
Estado de actividad
Activo
Stack tecnológico
php
Área
backend

Línea de trabajo

El informe identifica TranslateService::translate() como el lugar donde se crea y almacena la clave de caché. Lee primero ese método y el uso de la caché que lo rodea; comprueba si las pruebas de traducción existentes cubren el comportamiento del servicio, el modelo, el prompt y la caducidad. El trabajo estará hecho cuando las traducciones con configuraciones distintas no reutilicen una entrada incompatible y las entradas en caché tengan una vida útil limitada.

Escrito por el modelo de indexación a partir del texto del issue.

Descripción

Steps to reproduce
  1. Configure a distributed memory cache in config.php (e.g. APCu or Redis) (e.g. 'memcache.distributed' => '\OC\Memcache\Redis'), as recommended for production instances.
  2. Configure two different translation services, or a single service whose model you can change in the settings.
  3. Translate the same text with the same source and target languages using the first service or model, then using the second one.
Expected behaviour

The second translation is actually performed by the second service or model, since different providers and models produce different translations of the same input.

Actual behaviour

The second translation is served from the cache entry written by the first one. The provider is never called again.

The cache key is built in TranslateService::translate() as:

$cacheKey = $sourceLanguageCode . '/' . $targetLanguageCode . '/' . md5($chunk);

The key contains neither the service, nor the model, nor the system prompt, so a cache entry written through one configuration is necessarily hit by any other configuration translating the same text between the same languages. Entries are also stored without a TTL ($cache->set($cacheKey, ...)), so once written, a translation is served forever, even after the underlying model or service configuration is changed or fixed.

This also means the cache silently loses most of its value as soon as an instance uses more than one translation service, since hits become essentially random across configurations.

Side observation: on instances without a distributed memory cache configured, the distributed cache falls back to a per-request backend, so the translation cache never hits at all and every translation is recomputed. If that fallback is considered acceptable for small instances it may be worth documenting; if not, the cache could use a different backend.

Suggested direction

Include at least the service id and the model in the cache key (and ideally the system prompt, which is part of the translation behaviour), and store entries with a finite TTL so that configuration or model changes eventually invalidate stale translations.

Reproduction on a live instance

Reproduced end-to-end on a live Nextcloud 35.0.3 instance with APCu as the distributed cache, using a local mock provider that echoes what it receives and logs every request. Two distinct translation services were configured, both pointing at the mock, and the same text was translated three times in a row:

Call Service Model Provider called?
1 A model-aaa yes
2 A model-bbb no — served from cache
3 B model-ccc no — served from cache

Only the first of the three translations reached the provider, although each used a different model or an entirely different service.

Assisted by Devin:SWE-2.1

Lenguaje dominante
PHP
Estrellas
78
Forks
42
Merge medio
2 d 21 h
PR fusionados (30 d)
5

Preparar el entorno

Primeros pasos

  1. Lee el issue completo y luego la guía de contribución del proyecto.
  2. Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
  3. Haz un fork del repositorio y trabaja en una rama.
  4. Abre un pull request que haga referencia al número del issue.

Más de nextcloud/integration_openai

Todos los issues de nextcloud/integration_openai

Issues similares

Más issues de PHP

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.