@@ -144,6 +144,9 @@ class RepoUpdateResult:
144144 # reached the store, so the caller can stamp ``last_full_rescore_at`` /
145145 # ``health_analyzer_version``.
146146 health_rescored : bool = False
147+ # True when every tracked file's security findings were rescanned with this
148+ # build's scanner, so the caller can stamp ``security_scanner_version``.
149+ security_rescanned : bool = False
147150 # The graph rebuild's patch-or-rebuild decision, stamped as state.json
148151 # "graph_update"; None leaves the stored record alone.
149152 graph_update : dict [str , Any ] | None = None
@@ -185,6 +188,7 @@ async def _incremental_repo_update(
185188 force_full_git : bool = False ,
186189 products_sink : list [UpdateProducts ] | None = None ,
187190 rescore_health : bool = False ,
191+ rescan_security : bool = False ,
188192) -> RepoUpdateResult | None :
189193 """Refresh an already-indexed repo through the incremental update path.
190194
@@ -199,6 +203,8 @@ async def _incremental_repo_update(
199203 rebuilt; a run with no relevant changes rebuilds nothing and appends
200204 nothing. *rescore_health* re-scores every file's health after persisting,
201205 in place of the changed-files health pass that re-score would replace.
206+ *rescan_security* rescans every file's security findings after persisting,
207+ for a scanner version bump the changed-files scan cannot reach.
202208
203209 The result's ``phase_timings`` carries the seconds each phase took.
204210
@@ -220,10 +226,10 @@ async def _incremental_repo_update(
220226 file_diffs , working_tree_paths = await asyncio .to_thread (
221227 _changed_file_diffs , repo_path , state , base_ref , include_working_tree , merged_excludes
222228 )
223- if not file_diffs and not force_full_git and not rescore_health :
229+ if not file_diffs and not force_full_git and not rescore_health and not rescan_security :
224230 # Nothing the index cares about changed: report success so the caller
225231 # bumps ``last_sync_commit`` instead of re-diffing forever. A re-score
226- # still runs: it is owed for every file, changed or not.
232+ # or rescan still runs: it is owed for every file, changed or not.
227233 return RepoUpdateResult (alias = alias , updated = True , working_tree_paths = working_tree_paths )
228234
229235 # A moved or copied checkout's store still names the old path; adopt its
@@ -324,6 +330,10 @@ async def _incremental_repo_update(
324330 rescored_report = await _rescore_repo_health (
325331 repo_path , graph_builder , parsed_files , merged_excludes , timings
326332 )
333+ security_rescanned = False
334+ if rescan_security :
335+ with timed (timings , "security_rescan" ):
336+ security_rescanned = await _rescan_repo_security (repo_path , parsed_files , source_map )
327337 if products_sink is not None :
328338 health_report = (
329339 rescored_report
@@ -360,6 +370,7 @@ async def _incremental_repo_update(
360370 # The re-score reads git rows from the store: scored over rows that did
361371 # not land, it is not stamped, so the next run re-scores with the walk.
362372 health_rescored = rescored_report is not None and "Git persist" not in failed_steps ,
373+ security_rescanned = security_rescanned ,
363374 graph_update = getattr (graph_builder , "incremental_graph_decision" , None ),
364375 pending_repair = marker .get ("pending_repair" ),
365376 )
@@ -395,6 +406,22 @@ async def _rescore_repo_health(
395406 return None
396407
397408
409+ async def _rescan_repo_security (repo_path : Path , parsed_files : Any , source_map : Any ) -> bool :
410+ """Every file's security findings rescanned, or ``False`` when the rescan failed.
411+
412+ Best-effort, as the CLI update's rescan is: a failure leaves the old stamp,
413+ so the next update retries.
414+ """
415+ from ...pipeline .persist import rescan_repo_security
416+
417+ try :
418+ await rescan_repo_security (repo_path , parsed_files , source_map )
419+ except Exception :
420+ _log .warning ("Full security rescan failed for %s" , repo_path , exc_info = True )
421+ return False
422+ return True
423+
424+
398425async def _stored_health_report (repo_path : Path ) -> Any :
399426 """The whole-repo health report read back from the store, or ``None``.
400427
@@ -586,6 +613,7 @@ async def update_single_repo_index(
586613 products_sink : list [UpdateProducts ] | None = None ,
587614 full_index_fallback : bool = True ,
588615 rescore_health : bool = False ,
616+ rescan_security : bool = False ,
589617) -> RepoUpdateResult :
590618 """Refresh the index for a single repo.
591619
@@ -607,6 +635,8 @@ async def update_single_repo_index(
607635 changed ones, after the incremental write. The products' health report
608636 covers the whole repo either way, so a caller needs it only to refresh
609637 every file's scores, not to get a whole-repo report.
638+ - ``rescan_security=True`` rescans every file's security findings, not
639+ only the changed ones: the rescan a ``SECURITY_SCANNER_VERSION`` bump owes.
610640 """
611641 from ...repo_config import load_repo_config
612642
@@ -651,6 +681,7 @@ async def update_single_repo_index(
651681 include_working_tree ,
652682 products_sink = products_sink ,
653683 rescore_health = rescore_health ,
684+ rescan_security = rescan_security ,
654685 )
655686 if incremental_result is not None :
656687 if unrepaired is not None and incremental_result .pending_repair is None :
@@ -759,6 +790,7 @@ async def _try_incremental_update(
759790 * ,
760791 products_sink : list [UpdateProducts ] | None = None ,
761792 rescore_health : bool = False ,
793+ rescan_security : bool = False ,
762794) -> tuple [RepoUpdateResult | None , str | None ]:
763795 """The incremental update's result, or ``None`` and the error to fall back on."""
764796 from ...ingestion .document_extractors import DocumentExtractionError
@@ -773,6 +805,7 @@ async def _try_incremental_update(
773805 force_full_git = git_history_stale (state ),
774806 products_sink = products_sink ,
775807 rescore_health = rescore_health ,
808+ rescan_security = rescan_security ,
776809 )
777810 except DocumentExtractionError :
778811 raise
@@ -830,6 +863,8 @@ async def _full_index_update(
830863 git_history_refreshed = getattr (result , "git_summary" , None ) is not None ,
831864 # The full pipeline scores every file with this build's analyzer.
832865 health_rescored = getattr (result , "health_report" , None ) is not None ,
866+ # The full pipeline scans every file with this build's scanner.
867+ security_rescanned = True ,
833868 )
834869 except Exception as exc :
835870 return RepoUpdateResult (
0 commit comments