Skip to content

Commit 1eb2e39

Browse files
fix: move start_coverage_collection after _initialized guard, reset _source_root on stop
- start_coverage_collection() was before the _initialized check, causing repeated initialize() calls to stop/restart coverage and lose data - stop_coverage_collection() now resets _source_root for cleanup completeness
1 parent 9b197f7 commit 1eb2e39

2 files changed

Lines changed: 8 additions & 8 deletions

File tree

drift/core/coverage_server.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ def start_coverage_collection() -> bool:
9191

9292
def stop_coverage_collection() -> None:
9393
"""Stop coverage collection and clean up. Thread-safe."""
94-
global _cov_instance, _branch_cache
94+
global _cov_instance, _branch_cache, _source_root
9595
with _lock:
9696
if _cov_instance is not None:
9797
try:
@@ -100,6 +100,7 @@ def stop_coverage_collection() -> None:
100100
pass
101101
_cov_instance = None
102102
_branch_cache = None
103+
_source_root = None
103104

104105

105106
def take_coverage_snapshot(baseline: bool = False) -> dict:

drift/core/drift_sdk.py

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -179,17 +179,16 @@ def initialize(
179179
)
180180
env = env_from_var
181181

182-
# Start coverage collection early (before any SDK mode checks that might return early),
183-
# but after the _initialized guard so we don't re-invoke on repeated initialize() calls.
184-
# Coverage data is accessed via protobuf channel (communicator handles requests).
185-
from .coverage_server import start_coverage_collection
186-
187-
start_coverage_collection()
188-
189182
if cls._initialized:
190183
logger.debug("Already initialized, skipping...")
191184
return instance
192185

186+
# Start coverage collection after the _initialized guard so repeated
187+
# initialize() calls don't stop/restart coverage and lose accumulated data.
188+
from .coverage_server import start_coverage_collection
189+
190+
start_coverage_collection()
191+
193192
file_config = instance.file_config
194193

195194
if (

0 commit comments

Comments
 (0)