← Back to Pull requests

fix: reset runtime config before each in-process Tesseract instance #703

Closed
unknown closed this pull request without merging on Sep 17, 2026 21:26 UTC
View on GitHub
unknown unknown commented on Aug 27, 2026 09:31 UTC
Author

Relevant issue or PR

Fixes #672

Description of changes

update_config() records every explicitly set field in the module-level _config_overrides set and re-applies the previous value on every subsequent call, so those settings are sticky for the lifetime of the process. Tesseract.from_tesseract_api relies on that stickiness to accumulate its config across its own three sequential update_config() calls (input_path, then output_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 the LocalClient (which defaults to a fresh temp directory) then disagree about where output goes. from_image doesn't have this problem since it passes config as TESSERACT_* environment variables to an isolated subprocess instead.

Added reset_config() to tesseract_core/runtime/config.py and call it once at the very start of from_tesseract_api, before any of its update_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.py has the same _config_overrides pattern, but nothing currently calls its update_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):

runtime output_path after 1st: /private/tmp/tess_repro_out1
runtime output_path after 2nd: .
2nd instance writes runs to:   /var/folders/.../T/tesseract_output_r2xibixr

Added test_Tesseract_from_tesseract_api_does_not_leak_config_between_instances to tests/sdk_tests/test_tesseract.py, covering output_path and output_format (the issue also names input_path, which goes through the identical code path). Confirmed it fails against main with 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 format clean on all three changed files (pre-existing lint findings elsewhere in tesseract.py/config.py/test_tesseract.py are untouched by this diff).

Diff: 336 lines (+252 / -84) across 4 files Reviewer: afonsojanu Review duration: 30955m
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
0.65
Model 2 · Review Depth (DistilBERT)
Depth Score: 0.17 · 1 substantive comment(s)
0.17
Model 3 · Review Timing & Attention
Session adequacy: 100% · Reviewer familiarity: 35%
60%
Bedrock Claude 3 · Risk Narration
(disconnected)
Groq
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
Reviewers
Assignees
Unassigned
Labels
risk: low confidence: 60.5% reviewed sensitive_module
Vouch Risk Breakdown
AI-powered review risk analysis
Change Risk
Change Risk · Model 1 (XGBoost)
Predicted defect probability (0.00–1.00) based on diff churn, modified sensitive files, and author risk history.
Score: 65.4% (HIGH) · Higher = larger blast radius
65.4%
Review Confidence
Review Confidence · Models 2 & 3
Scrutiny score (0.00–1.00) combining DistilBERT semantic review depth with reviewer familiarity and session dwell time.
Score: 60.5% · Lower = rushed or shallow review
60.5%
Residual Risk
Residual Risk · Core Equation
Residual = Change × (1 − Confidence)
Unmitigated risk surviving review. ≥ 0.65 triggers an automated re-queue to protect production.
Score: 25.8% · Safe to merge
25.8%