Skip to content

Remove the empty results dir of a scan that wrote nothing - #50

Open
adityaanikam wants to merge 1 commit into
capitalone:mainfrom
adityaanikam:fix-48-empty-results-dir
Open

adityaanikam wants to merge 1 commit into
capitalone:mainfrom
adityaanikam:fix-48-empty-results-dir

Conversation

@adityaanikam

Copy link
Copy Markdown

Fixes #48.

scan_folder pre-creates <clone>/<clone>_VULNHUNT_RESULTS_<timestamp>/ before it launches claude. If the scan fails before it writes anything (auth error, crash, early timeout), it returns results_dir=None but leaves the empty directory in the clone. batch.utils.collect_results accepts any untracked results directory named for the repo, so it copies the empty one and counts the repo as Copied. The failed repo never shows up under Missing results, and an empty result set ends up in to_upload/.

Change

In harness/local_harness/scan.py, scan_folder now removes the results directory when it is still empty after the run. An OSError is ignored, since an --execute agent may have removed or replaced it already.

This is the first option from the issue. I did not change collect_results to skip results directories that have no README. A scan that is killed after it wrote some files still leaves a non-empty directory without a README, and collect_results collects that as before. That is a separate behaviour change.

Tests

In harness/tests/test_scan.py:

  • test_scan_folder_removes_empty_results_dir: no results directory is left after a scan that wrote nothing.
  • test_scan_folder_tolerates_failure_to_remove_empty_results_dir: a failing rmdir does not raise, and results_dir is still None.
  • test_failed_scan_is_reported_missing_by_collect_results: runs a fake scan that writes nothing, then collect_results, and expects copied to be empty and the repo to be under missing (the scenario from the issue).

test_scan_folder_prompt_has_preresolved_metadata asserted that the results directory exists after the scan, which only held because the empty directory was left behind. That check now runs when claude is launched (in _capture_scan_argv), which is what the test is about.

With scan.py reverted and the new tests kept, test_scan_folder_removes_empty_results_dir and test_failed_scan_is_reported_missing_by_collect_results fail. The full harness suite passes on Linux (WSL, Python 3.12): pytest tests/ --cov=local_harness gives 215 passed, with total coverage at 95%. I did not run a real scan against claude.

scan_folder pre-creates <clone>/<clone>_VULNHUNT_RESULTS_<ts> before it
launches claude. When the scan wrote nothing (auth error, crash, early
timeout) it returned results_dir=None but left the empty directory in
the clone. collect_results accepts any results dir named for the repo,
so the failed scan was copied to the upload dir and counted as Copied
instead of Missing results.

Remove the directory when it is still empty after the run. An OSError
is ignored, in case an --execute agent already removed or replaced it.

Fixes capitalone#48
Copilot AI balanced review requested due to automatic review settings October 9, 2026 20:09
@adityaanikam
adityaanikam requested a review from a team as a code owner October 9, 2026 20:09

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

harness: failed scan leaves empty results dir that batch collect reports as Copied

2 participants