From e37852c8b312adf11b4535d216653da1429a8e9a Mon Sep 17 00:00:00 2001 From: no Date: Sat, 16 May 2026 23:58:16 +0300 Subject: [PATCH] CLI estimation mismatch fix --- modules/rpgmakermvmz.py | 3 ++- util/translation.py | 24 +++++++++++++++++------- 2 files changed, 19 insertions(+), 8 deletions(-) diff --git a/modules/rpgmakermvmz.py b/modules/rpgmakermvmz.py index e72b74a..472b65c 100644 --- a/modules/rpgmakermvmz.py +++ b/modules/rpgmakermvmz.py @@ -235,9 +235,10 @@ def _pat355655_captured_text(match): def handleMVMZ(filename, estimate): - global ESTIMATE, TOKENS, FILENAME + global ESTIMATE, TOKENS, FILENAME, MISMATCH ESTIMATE = estimate FILENAME = filename + MISMATCH = [] # Reset per-file; prevents cross-file contamination in CLI mode # Also record per-thread filename to avoid cross-thread interference try: THREAD_CTX.filename = filename diff --git a/util/translation.py b/util/translation.py index 5014071..bdbae86 100644 --- a/util/translation.py +++ b/util/translation.py @@ -1831,17 +1831,27 @@ def translateAI(text, history, config, filename=None, pbar=None, lock=None, mism # Check cache for this exact payload cached_result = get_cached_translation(subbedT, config.language) if cached_result is not None: - if isinstance(tItem, list): - tList[index] = cached_result - history = cached_result[-config.maxHistory:] + # In estimate mode, never replace tList[index] from cache — the cached value + # may have been stored for a batch with a different number of skip_indices, + # so its length can differ from the current tItem. Keeping tList[index] as + # the original tItem ensures the returned list always has the correct length. + if not config.estimateMode: + if isinstance(tItem, list): + tList[index] = cached_result + history = cached_result[-config.maxHistory:] + else: + tList[index] = cached_result + history = cached_result else: - tList[index] = cached_result - history = cached_result - + if isinstance(cached_result, list) and cached_result: + history = cached_result[-config.maxHistory:] + elif cached_result: + history = cached_result + if lock and pbar is not None: with lock: pbar.update(len(tItem) if isinstance(tItem, list) else 1) - + continue # Create context — static_system is the stable prompt.txt content;