Skip to content

fix: mark partial streaming scans inconclusive#908

Open
mldangelo-oai wants to merge 3 commits intomainfrom
mdangelo/codex/large-file-outcome-audit
Open

fix: mark partial streaming scans inconclusive#908
mldangelo-oai wants to merge 3 commits intomainfrom
mdangelo/codex/large-file-outcome-audit

Conversation

@mldangelo-oai
Copy link
Copy Markdown
Contributor

@mldangelo-oai mldangelo-oai commented Apr 10, 2026

Summary

  • mark partial stream:// scans as inconclusive before aggregation so no-finding partial reads fail closed
  • mark direct streaming helper results as incomplete when only a bounded prefix was analyzed
  • add regressions for no-finding partial streams, security-finding precedence, and direct streaming metadata

Validation

  • uv run ruff format modelaudit/ packages/modelaudit-picklescan/src packages/modelaudit-picklescan/tests tests/
  • uv run ruff check --fix modelaudit/ packages/modelaudit-picklescan/src packages/modelaudit-picklescan/tests tests/
  • uv run mypy modelaudit/ packages/modelaudit-picklescan/src packages/modelaudit-picklescan/tests tests/
  • uv run pytest tests/test_streaming_scan.py tests/utils/file/test_streaming_analysis.py
  • uv run pytest -n auto -m "not slow and not integration" --maxfail=1
  • uv run ruff format --check modelaudit/ packages/modelaudit-picklescan/src packages/modelaudit-picklescan/tests tests/
  • uv run ruff check modelaudit/ packages/modelaudit-picklescan/src packages/modelaudit-picklescan/tests tests/

Summary by CodeRabbit

  • Bug Fixes

    • Partial/unfinished streaming analyses are now marked as "inconclusive" in scan metadata, flagging incomplete scans and preserving an explanatory message and reason.
  • Tests

    • Added and updated tests to verify incomplete streaming analysis is recorded as inconclusive, with correct metadata, outcome reasons, and exit-code behavior.

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai bot commented Apr 10, 2026

Warning

Rate limit exceeded

@mldangelo-oai has exceeded the limit for the number of commits that can be reviewed per hour. Please wait 16 minutes and 58 seconds before requesting another review.

Your organization is not enrolled in usage-based pricing. Contact your admin to enable usage-based pricing to continue reviews beyond the rate limit, or try again in 16 minutes and 58 seconds.

⌛ How to resolve this issue?

After the wait time has elapsed, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout.

Please see our FAQ for further information.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: ASSERTIVE

Plan: Pro

Run ID: 28b760f4-d717-4f24-834e-1d2676a8e5b8

📥 Commits

Reviewing files that changed from the base of the PR and between 771b148 and f1cc7da.

📒 Files selected for processing (3)
  • modelaudit/utils/file/streaming.py
  • tests/test_streaming_scan.py
  • tests/utils/file/test_streaming_analysis.py

Walkthrough

Partial streaming analyses are now marked as inconclusive in scan metadata. Helpers set analysis_incomplete, scan_outcome to inconclusive, and append "streaming_analysis_incomplete" to reasons; the streaming scan path marks and records incomplete results. Tests added/updated to validate these outcomes.

Changes

Cohort / File(s) Summary
Changelog
CHANGELOG.md
Added entry noting that partial streaming analyses are marked as inconclusive in scan metadata.
Streaming Metadata Handling
modelaudit/utils/file/streaming.py
Added _mark_streaming_analysis_incomplete(result); stream_analyze_file() now preserves partial results, marks incomplete metadata when was_complete is False, and sets final finish(success=...) based on was_complete and scanner success.
Core Scan Integration
modelaudit/core.py
Added _mark_inconclusive_scan_outcome(scan_result, reason) and updated scan_model_directory_or_file() streaming branch to call it before recording partial ScanResults.
Tests
tests/test_streaming_scan.py, tests/utils/file/test_streaming_analysis.py
Added tests for partial streaming results with and without findings; updated fallback test to assert inconclusive metadata and success/exit-code behavior.
sequenceDiagram
    participant Client
    participant ScannerRunner as scan_model_directory_or_file
    participant StreamScanner as stream_analyze_file
    participant Marker as _mark_streaming_analysis_incomplete
    participant Results as ScanResultsStore

    Client->>ScannerRunner: request scan (stream://)
    ScannerRunner->>StreamScanner: stream_analyze_file(...)
    StreamScanner->>StreamScanner: streaming runs, was_complete = False
    StreamScanner->>Marker: mark result inconclusive
    Marker-->>StreamScanner: result.metadata updated
    StreamScanner-->>ScannerRunner: return (ScanResult, was_complete=False)
    ScannerRunner->>Results: record marked ScanResult
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Poem

🐰 I nibbled bytes and gave a hop,

Partial streams made my whiskers stop.
Marked as "inconclusive", reasons in tow,
I left a note so truth would show.
Happy hops for tests that glow!

🚥 Pre-merge checks | ✅ 2 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 60.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title 'fix: mark partial streaming scans inconclusive' directly and clearly describes the main change: marking partial streaming scans as inconclusive.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch mdangelo/codex/large-file-outcome-audit

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@github-actions
Copy link
Copy Markdown
Contributor

github-actions bot commented Apr 10, 2026

Workflow run and artifacts

Performance Benchmarks

Compared 6 shared benchmarks with a regression threshold of 15%.
Status: 0 regressions, 0 improved, 6 stable, 0 new, 0 missing.
Aggregate shared-benchmark median: 699.10ms -> 687.60ms (-1.6%).

Benchmark Target Size Files Baseline Current Change Status
tests/benchmarks/test_scan_benchmarks.py::test_detect_file_format_safe_pickle safe_model.pkl 49.4 KiB 1 127.3us 134.4us +5.6% stable
tests/benchmarks/test_scan_benchmarks.py::test_validate_file_type_pytorch_zip state_dict.pt 1.5 MiB 1 41.7us 43.0us +3.3% stable
tests/benchmarks/test_scan_benchmarks.py::test_scan_duplicate_directory duplicate-corpus 840.0 KiB 81 498.71ms 487.42ms -2.3% stable
tests/benchmarks/test_scan_benchmarks.py::test_scan_safe_pickle safe_model.pkl 49.4 KiB 1 28.83ms 28.57ms -0.9% stable
tests/benchmarks/test_scan_benchmarks.py::test_scan_pytorch_zip state_dict.pt 1.5 MiB 1 35.33ms 35.11ms -0.6% stable
tests/benchmarks/test_scan_benchmarks.py::test_scan_mixed_directory mixed-corpus 1.7 MiB 54 136.06ms 136.33ms +0.2% stable

@mldangelo-oai mldangelo-oai enabled auto-merge (squash) April 10, 2026 17:08
Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 3

🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@modelaudit/utils/file/streaming.py`:
- Around line 229-232: When scan_stream()/scan_bytes() returns a clean
ScanResult for a bounded prefix (scan_result exists, issues is empty,
was_complete is False) the helper currently falls through and returns None;
change the logic so this case is handled: if scan_result is not None and not
was_complete and not issues (i.e. a clean but partial result), call
_mark_streaming_analysis_incomplete(result), compute scanner_success from
scan_result, call result.finish(success=False) and return (result, False) so the
caller receives the inconclusive partial outcome instead of None; update the
branch around scan_result/was_complete/issues to explicitly return this tuple.

In `@tests/test_streaming_scan.py`:
- Around line 113-119: The test must also assert an explicit fail-closed
operational message is present in the file metadata so a disappearing INFO log
doesn't mask the reason; update the assertions after metadata =
result.file_metadata[stream_url] (using result and stream_url) to check that the
metadata includes a human-readable fail-closed message (e.g., an entry like
metadata.get("scan_outcome_message") or any value in metadata.values() contains
the substring "fail" or "failed closed") in addition to the existing checks of
scan_outcome, analysis_incomplete, scan_outcome_reasons, result.success and
determine_exit_code(result).

In `@tests/utils/file/test_streaming_analysis.py`:
- Around line 83-86: The test currently asserts fail-closed metadata but doesn't
verify warning vs error flags; update the test (e.g., in test_streaming_analysis
where `result` is asserted) to also assert `result.has_warnings is True` and
`result.has_errors is False` so bounded-prefix inconclusive cases remain
classified as WARNING-severity and not CRITICAL; add these two assertions
immediately after the existing metadata checks referencing the same `result`
variable.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: ASSERTIVE

Plan: Pro

Run ID: 17ce4e3f-a630-4299-bdda-4473ef7bf8e0

📥 Commits

Reviewing files that changed from the base of the PR and between f285a05 and ee03123.

📒 Files selected for processing (5)
  • CHANGELOG.md
  • modelaudit/core.py
  • modelaudit/utils/file/streaming.py
  • tests/test_streaming_scan.py
  • tests/utils/file/test_streaming_analysis.py

Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

♻️ Duplicate comments (1)
modelaudit/utils/file/streaming.py (1)

221-240: ⚠️ Potential issue | 🟠 Major

A clean bounded read can still fall through as (None, False).

If the streamed prefix is partial, the scanner returns no result, and the header heuristics also find nothing, this still returns None. The stream:// caller treats that as a generic streaming failure instead of the new inconclusive fail-closed outcome.

🔧 Proposed fix
-        # Create scan result
-        if scan_result is not None or issues or was_complete:
-            result = ScanResult(scanner_name="streaming")
-            scanned = getattr(scan_result, "bytes_scanned", 0) if scan_result is not None else 0
-            result.bytes_scanned = scanned or bytes_to_read
-            result.issues = issues
-            result.metadata = {
-                "streaming_analysis": True,
-                "bytes_analyzed": bytes_to_read,
-                "analysis_complete": was_complete,
-                "file_size": file_size,
-            }
-            result.metadata.update(metadata)
-            if not was_complete:
-                _mark_streaming_analysis_incomplete(result)
-            scanner_success = bool(getattr(scan_result, "success", True)) if scan_result is not None else True
-            result.finish(success=was_complete and scanner_success)
-            return result, was_complete
-        else:
-            # Partial analysis with no findings
-            return None, was_complete
+        # Create a result for any successful streamed read; reserve `None` for
+        # transport/setup failures so callers can distinguish fallback from an
+        # inconclusive partial analysis.
+        result = ScanResult(scanner_name="streaming")
+        scanned = getattr(scan_result, "bytes_scanned", 0) if scan_result is not None else 0
+        result.bytes_scanned = scanned or bytes_to_read
+        result.issues = issues
+        result.metadata = {
+            "streaming_analysis": True,
+            "bytes_analyzed": bytes_to_read,
+            "analysis_complete": was_complete,
+            "file_size": file_size,
+        }
+        result.metadata.update(metadata)
+        if not was_complete:
+            _mark_streaming_analysis_incomplete(result)
+        scanner_success = bool(getattr(scan_result, "success", True)) if scan_result is not None else True
+        result.finish(success=was_complete and scanner_success)
+        return result, was_complete
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@modelaudit/utils/file/streaming.py` around lines 221 - 240, When a bounded
partial read (bytes_scanned == bytes_to_read) yields no scan_result and no
issues, we currently return (None, False) and the caller treats that as a
generic streaming failure; instead create and return a ScanResult that marks the
analysis as incomplete/inconclusive so the caller can treat it as the
fail-closed inconclusive outcome. Modify the branch in streaming_analyze where
scan_result is None and issues is empty: instantiate
ScanResult(scanner_name="streaming"), set result.bytes_scanned = bytes_to_read,
fill result.metadata with "streaming_analysis": True, "bytes_analyzed":
bytes_to_read, "analysis_complete": was_complete and add a flag like
"inconclusive_fail_closed": True, call
_mark_streaming_analysis_incomplete(result) (since was_complete is False),
compute scanner_success as before, call result.finish(success=False) to indicate
inconclusive/fail-closed, and return result, was_complete instead of None; keep
using the existing symbols ScanResult, _mark_streaming_analysis_incomplete,
result.finish, and the variables scan_result, bytes_to_read, was_complete,
issues.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@tests/test_streaming_scan.py`:
- Around line 113-118: The assertions access result.file_metadata[stream_url] as
if it were a plain dict but scan_model_directory_or_file() stores
FileMetadataModel instances; convert or dump the model before subscripting (use
.model_dump() on the FileMetadataModel) so the keys like "scan_outcome",
"analysis_incomplete", "scan_outcome_reasons", and "scan_outcome_message" exist;
update both the block referencing result.file_metadata[stream_url] at the
current assertion group and the similar assertions around lines 147-148 to call
.model_dump() first (or replace direct subscripting with attribute access on
FileMetadataModel) so the fail-closed behavior is actually exercised.

---

Duplicate comments:
In `@modelaudit/utils/file/streaming.py`:
- Around line 221-240: When a bounded partial read (bytes_scanned ==
bytes_to_read) yields no scan_result and no issues, we currently return (None,
False) and the caller treats that as a generic streaming failure; instead create
and return a ScanResult that marks the analysis as incomplete/inconclusive so
the caller can treat it as the fail-closed inconclusive outcome. Modify the
branch in streaming_analyze where scan_result is None and issues is empty:
instantiate ScanResult(scanner_name="streaming"), set result.bytes_scanned =
bytes_to_read, fill result.metadata with "streaming_analysis": True,
"bytes_analyzed": bytes_to_read, "analysis_complete": was_complete and add a
flag like "inconclusive_fail_closed": True, call
_mark_streaming_analysis_incomplete(result) (since was_complete is False),
compute scanner_success as before, call result.finish(success=False) to indicate
inconclusive/fail-closed, and return result, was_complete instead of None; keep
using the existing symbols ScanResult, _mark_streaming_analysis_incomplete,
result.finish, and the variables scan_result, bytes_to_read, was_complete,
issues.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: ASSERTIVE

Plan: Pro

Run ID: dc7dce83-59c1-4390-a30e-55fb5b9305f2

📥 Commits

Reviewing files that changed from the base of the PR and between ee03123 and 771b148.

📒 Files selected for processing (4)
  • modelaudit/core.py
  • modelaudit/utils/file/streaming.py
  • tests/test_streaming_scan.py
  • tests/utils/file/test_streaming_analysis.py

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.

1 participant