Every subtitle batch carries the whole glossary, up to 100 terms
A subtitle manager for Sonarr and Radarr that translates with hosted or local models, and already sends only the glossary terms a batch uses on its local and OpenAI-compatible path.
≈ 400,000 tokens per 1,000 calls, for glossary terms that do not occur in the batch, if half the calls carry a full glossary estimate
Audited with leanprompt 0.1.0-dev.15
Estimates, not measurements. Every figure on this page is an estimate from reading the code, not a measurement of the app in use.
- Repository
- Abrechen2/sublarr 51 GitHub stars
- Commit audited
76d1c08- leanprompt version
- 0.1.0-dev.15
- Audit date
- Status
- The maintainers have been told about this audit; no response yet.
- Maintainers
- the issue
- How it ran
- Unattended audit: nobody was asked during the run, so priority, volume and prices were left open; the questions for the owner are listed at the end.
leanprompt read the code at commit 76d1c08 and found 2 places where its LLM calls could use fewer tokens, 1 more that costs no tokens today, plus 5 other problems, not scored. Static score: 75 of 100 (an estimate from the findings). The code may have changed since.
Findings
-
LP-PD-04Trim tool results and retrieved context at the tool boundarybackend/translation/llm_base.py:481· severity medium · saves prefill · how often is assumedWhat happens. The five hosted backends (Claude, ChatGPT, Gemini, Mistral, DeepSeek) put every glossary term into the system prompt of every batch, up to 100 terms. The Ollama and OpenAI-compatible path already keeps only terms that occur in the batch and at most 15.
The change. In LLMBackend._assemble_messages, reuse the filter from build_prompt_with_glossary: keep an entry only when its source term occurs in the escaped lines being translated, and cap the count.
Why it helps. A default batch is 15 lines, about 180 tokens of subtitle text, while 100 terms are about 800 tokens that are sent again for every batch of the file. Terms that do not occur in the batch cannot change the output.
Estimate about 790 prompt tokens per call on a series with a full 100-term glossary; about 395k per 1,000 calls if half the calls run with one (estimate)
Assumptions. about 8 tokens per 'source -> target' pair (estimated from character count, not tokenised); batch_size 15 and lookback 10 / lookahead 5 as in config_settings.py; 1 to 3 terms occur per batch; half of all calls carry a full glossary, which is a guess.
Who reaches this. series with a large glossary, on the Claude, ChatGPT, Gemini, Mistral or DeepSeek backends
How often. how many approved glossary terms a typical series has in a real install (the cap is glossary_max_terms, default 100)
-
LP-GE-05Retry only retryable errors; never retry a truncation unchangedbackend/translation/llm_base.py:338· severity high · saves prefill and generation · how often is assumedWhat happens. When an answer is cut off at the output cap it comes back with too few lines, and the line-count retry sends the same batch again with the same cap, because the cap is computed from the source lines only. The retry that fails the same way is followed by a batch split.
The change. Read the stop reason in _attempt. On a length stop, retry with a larger max_tokens (or go straight to splitting the batch) instead of resending with the same cap.
Why it helps. A repeated cut-off pays for the whole prompt and the whole generated answer a second time and still ends short.
Estimate about 4k prompt and 4k output tokens per 1,000 calls if 1 percent of calls are cut off (estimate; the real rate is not known)
Assumptions. 1 percent of calls reach the cap; about 400 prompt and 400 output tokens per affected attempt; average call 800 prompt and 250 output tokens.
Who reaches this. only batches whose answer reaches the output cap
How often. how often finish_reason is length / max_tokens / MAX_TOKENS on translation calls, from the translation_events or provider logs
-
LP-PC-01Put cache marks where the provider needs thembackend/translation/claude.py:94· severity low · saves prefill · size is assumed · costs no tokens todayWhat happens. The cache mark covers the whole system block, and that block changes with every batch (line count, previous and following lines, glossary, strict flag), so it cannot be read back. Below the provider's minimum it does nothing; above it every batch pays the cache-write price and never gets a read.
The change. Keep the mark only on a block that is identical across the batches of a file, and put the per-batch parts after it, or remove the mark.
Why it helps. A cache write is billed above the normal input price and a block that differs on every call is never read.
Estimate no tokens lost today on a typical block of a few hundred tokens (estimate); about 25 percent extra on the system tokens once the block exceeds the minimum
Assumptions. typical system block of a few hundred tokens with 15 lines, 10 previous and 5 following lines; the 1,024-token minimum for claude-sonnet-4-6 is from the captured Anthropic page.
Who reaches this. Claude users whose system block exceeds 1,024 tokens
How big. the system block size on a real install with a large glossary or series context (the mark only matters above 1,024 tokens for claude-sonnet-4-6)
Other problems the audit found
Problems read in the code that cost no tokens of their own, such as a cost meter or an error path. Not scored.
-
A cut-off answer is stored as a complete translation
backend/translation/llm_base.py:307·LP-GE-12Read the finish reason before using an answer · severity high · the same problem as finding 2What happens. _attempt reads the finish reason only to catch content_filter. Claude's max_tokens, OpenAI-style length, Gemini's MAX_TOKENS and Ollama's done_reason are mapped into LLMResponse.finish_reason and then never read. If the cap is hit inside the last line, the line count is still right and the batch passes _verify_batch, so the cut-off last line is written to the translation memory and the subtitle file.
The change. Treat a length stop as a failed attempt in _attempt (raise a TranslationContentError subclass), so the batch is split or retried with a larger cap and nothing partial reaches the cache.
To check. Force a tiny max_tokens on a 3-line batch: before, 3 lines come back and the last one is cut; after, the attempt is rejected and nothing is cached.
-
The Gemini default and a shipped Claude preset name models that are scheduled or retired
backend/translation/gemini.py:24·LP-GE-13Default to a model the provider still serves · severity mediumWhat happens. GeminiBackend defaults to gemini-2.5-pro (also gemini.py:40 and the price sheet), which our retirements table lists as scheduled to shut down on 2026-12-01 (table checked 2026-11-27; the Gemini deprecations page itself would not render for our fetcher, so this needs confirming there). The claude_haiku preset in routes/translate/_helpers.py:44 uses claude-3-haiku-20240307, which Anthropic's deprecations page lists as retired.
The change. Change the Gemini default and price-sheet entries to a model Google still serves, and replace the claude_haiku preset id with a current Haiku id.
To check. Send the health check from the settings page after the change; with the old ids the provider answers with a model-not-found error once the shutdown date has passed.
-
Cost is recorded as zero for every model that is not in the price sheet, including the shipped presets
backend/translation/price_sheet.py:70·LP-GE-11Meter every billed token, cached and unfinished ones too · severity mediumWhat happens. get_llm_price returns (0, 0) for an unknown backend and model pair. The presets in routes/translate/_helpers.py use openai_compat with deepseek-chat, gemini-1.5-flash, claude-3-haiku and mistral-medium-latest, and the sheet has openai_compat entries only for gpt-4o and gpt-4o-mini, so their events record cost_micro_usd 0.
The change. Add the preset models to the sheet, or show the cost as unknown rather than 0.
To check. Translate a batch with the deepseek_v3 preset and compare cost_micro_usd with tokens times the provider price.
-
Per-line quality scoring cannot run on hosted backends and reports 50
backend/translation/__init__.py:327What happens. evaluate_line_quality asks only ollama and openai_compat, and _call_backend_raw calls backend._call_openai, which OpenAICompatBackend does not define. For an openai_compat chain the raw call returns None and the line gets DEFAULT_QUALITY_SCORE (50). With translation_quality_threshold above 50 every line would then be re-translated twice.
The change. Implement _call_openai (or route through _call_api) or hide the setting for chains without Ollama.
To check. Run the scoring pass on an openai_compat-only chain and check that scores differ from 50.
-
The openai_compat max_retries setting is never read
backend/translation/openai_compat.py:152·LP-GE-17Send the output cap the owner set, on every path · severity lowWhat happens. The settings page offers 'Number of retry attempts on failure' and the client is built with max_retries=0 'We handle retries ourselves', but _max_retries has no caller, so no retry happens on a transient API error; the batch goes straight to the next backend.
The change. Use the setting with backoff for 429 and 5xx, or remove the field.
To check. Return a 503 once from a stub server and check that a second request is sent.
The maintainers’ response
No response from the maintainers yet.
How this was made
The llm-call-audit skill read the code and wrote findings.json; nothing was run against the project’s providers. The full audit page is what leanprompt report --html writes from the same findings.
Corrections and takedown: email info@podwarden.com or open an issue.