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

オープン 初心者向け
#480 コメント 0 件 リアクション 0 件 担当者 0 名 GitHub で見る

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

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

評価

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

調査の方向性

レポートでは、TranslateService::translate()がキャッシュキーを作成して保存する箇所として特定されています。まずこのメソッドとその周辺のキャッシュ使用箇所を読み、既存の翻訳テストでサービス、モデル、プロンプト、有効期限の各動作が網羅されているか確認してください。異なる設定を使う翻訳が互換性のないエントリーを再利用せず、キャッシュされたエントリーに有限の有効期間がある状態が完了の条件です。

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

説明

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

主要言語
PHP
スター
78
フォーク
42
平均マージ
2日 21時間
マージ済み PR(30日)
5

環境構築

はじめの一歩

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

nextcloud/integration_openai のほかの issue

nextcloud/integration_openai の issue をすべて見る

似ている issue

PHP の issue をもっと見る

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

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