Skip to content

fix(files): preserve discovered folder and file counts when shallow scan is stopped - #185

Merged
NityamPareek merged 1 commit into
files-shallow-scanfrom
fix/preserve-discovered-counts-on-stop
Sep 22, 2026
Merged

NityamPareek merged 1 commit into
files-shallow-scanfrom
fix/preserve-discovered-counts-on-stop

Conversation

@NityamPareek

Copy link
Copy Markdown
Collaborator

Description

When a Shallow Scan was stopped during Phase 2 (Drive Discovery), the folder and file counts discovered from libraries scanned prior to the stop were lost on the final dashboard and summary log (showing 0).

Root Cause

In ShallowFileEstimator.calculate_resource_metrics, when is_hard_stop_requested() was detected after _scan_document_libraries, the method returned immediately with early-exit phase runtimes, completely bypassing self._finalize_tenant_totals(...).
Because _finalize_tenant_totals was skipped:

  • Tenant-level metrics["folderCount"] and metrics["fileCount"] remained at default 0, even though metrics["siteMetrics"] had accumulated the discovered counts for scanned libraries.
  • tenantLevelLargeResourceCount, tenantLevelWarningResourceCount, and siteClassification were not populated.
  • Dashboard stat cards ("Folder Count", "File Count") in ui/files_ui.py and the summary log line displayed 0.

Changes

  1. Estimator Level (shallow_file_estimator.py):
    • self._finalize_tenant_totals(metrics, processed_count, failed_count) is now always executed after _scan_document_libraries, ensuring folderCount, fileCount, threshold counts, and siteClassification are aggregated from all scanned libraries before handling the hard stop.
    • Updated the phase log to distinguish between stopped vs completed ([Phase 2: Drive Discovery] Stopped after Xs and [Phase 2] Shallow Drive Discovery stopped).
    • If stopped before Phase 2 begins, safely calls _finalize_tenant_totals(metrics, 0, 0) so tenant totals and site classification are cleanly initialized.
  2. UI Defensive Safeguard (ui/files_ui.py):
    • In execute_migration_scan: If file_metrics.get("folderCount") or file_metrics.get("fileCount") are 0 or missing but siteMetrics contains data, defensively fall back to summing from siteMetrics.values().
    • In show_results_content: Defensively fall back to summing from data.get("siteMetrics", {}).values() for the Folder Count and File Count stat cards (matching the behavior of Total Corpus Size and other cards).
  3. Unit Tests (tests/files/shallow_estimator_test.py):
    • Added test_hard_stop_during_phase_two_preserves_discovered_counts to verify that stopping mid-phase preserves discovered folder and file counts (matching site metrics sums) and populates phase runtimes and site classification.

Testing

  • Ran python3 -m unittest discover -s tests/files -p "shallow_estimator_test.py": all 39 tests passed.
@NityamPareek
NityamPareek merged commit c782e9f into files-shallow-scan Sep 22, 2026
1 check passed
@NityamPareek
NityamPareek deleted the fix/preserve-discovered-counts-on-stop branch September 22, 2026 15:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

1 participant