fix: reset runtime config before each in-process Tesseract instance #703
All Vouch review confidence checks passed
Residual risk 0.26 = Change Risk (0.65) × (1 − Review Confidence (0.60)).
Review depth and reviewer attention state are adequate.
Model 1 · Change Risk (XGBoost)
Score: 0.65 · 336 lines diff across 4 files
Model 2 · Review Depth (DistilBERT)
Depth Score: 0.17 · 1 substantive comment(s)
Model 3 · Review Timing & Attention
Session adequacy: 100% · Reviewer familiarity: 35%
Bedrock Claude 3 · Risk Narration
(disconnected)
Groq Risk Narration
AWS Bedrock is currently disconnected. Generate high-confidence PR triage narration on-demand using Groq.
Model 1 · Change Risk Attribution
SHAP Weights
Diff Size
diff_size
0.348
Shallow Review Depth
shallow_review_depth
0.289
Sensitive Paths
sensitive_paths
0.065
Real PR Conversation Timeline
1 comments
"Review active on #703"
general
weight: 0.35
afonsojanu
Relevant issue or PR
Fixes #672
Description of changes
update_config()records every explicitly set field in the module-level_config_overridesset and re-applies the previous value on every subsequent call, so those settings are sticky for the lifetime of the process.Tesseract.from_tesseract_apirelies on that stickiness to accumulate its config across its own three sequentialupdate_config()calls (input_path, thenoutput_path, then general kwargs) — but the same stickiness means a second, independent in-process Tesseract silently inherits the first one's explicit overrides even when it requests none. The runtime config and theLocalClient(which defaults to a fresh temp directory) then disagree about where output goes.from_imagedoesn't have this problem since it passes config asTESSERACT_*environment variables to an isolated subprocess instead.Added
reset_config()totesseract_core/runtime/config.pyand call it once at the very start offrom_tesseract_api, before any of itsupdate_config()calls. A new instance now starts from environment variables and its own arguments only — not a prior instance's overrides — while the three calls within one instance's own setup still correctly accumulate together (resetting between those three would break that accumulation).I kept this scoped to
runtime/config.py/from_tesseract_api, which is what the issue's repro exercises.tesseract_core/sdk/config.pyhas the same_config_overridespattern, but nothing currently calls itsupdate_config()with explicit kwargs outside its own zero-arg initialization, so the leak doesn't currently manifest there — happy to look at that too if it's wanted, but didn't want to expand scope speculatively.Testing done
Reproduced the issue's exact repro script before the fix (confirmed the reported leak) and after (confirmed it's gone):
Added
test_Tesseract_from_tesseract_api_does_not_leak_config_between_instancestotests/sdk_tests/test_tesseract.py, coveringoutput_pathandoutput_format(the issue also namesinput_path, which goes through the identical code path). Confirmed it fails againstmainwith the exact same symptom as the issue, and passes with the fix.pytest --skip-endtoend: 652 passed, 130 skipped (Docker-dependent, not run here).ruff check/ruff formatclean on all three changed files (pre-existing lint findings elsewhere intesseract.py/config.py/test_tesseract.pyare untouched by this diff).