Skip to content

refactor: consolidate scan routing and result contracts - #1872

Open
mldangelo-oai wants to merge 18 commits into
mdangelo/codex/modelaudit-04-picklescanfrom
mdangelo/codex/modelaudit-05-scanning
Open

mldangelo-oai wants to merge 18 commits into
mdangelo/codex/modelaudit-04-picklescanfrom
mdangelo/codex/modelaudit-05-scanning

Conversation

@mldangelo-oai

@mldangelo-oai mldangelo-oai commented Oct 3, 2026 •

Copy link
Copy Markdown
Contributor

Repeated scan-routing decisions, failure-result construction, and scanner helpers had separate implementations. Consolidate these paths while preserving detection ownership, finding order, fail-closed outcomes, archive budgets, public result models, and optional-dependency handling.

Part 5 of the six-PR simplification series, based on the standalone picklescan PR. This removes redundant result conversions/state, duplicated scanner policy/configuration helpers, unused Flax preanalysis and buffered SentencePiece paths, and JIT wrappers. The root dependency remains modelaudit-picklescan>=0.1.11,<0.2.0.

Measured scope: 2,360 fewer maintained lines across 70 changed paths: production −2,423; tests +63; tooling/generated code unchanged. This includes both new helpers and uses normal Ruff formatting (1,582 additions, 3,942 deletions; the identity helper move contributes zero net reduction).

Validation:

Current-main integration (2a5185a): preserves the upstream SafeTensors FDICT fix and deterministic initial/retried cache interruption fixture. Focused cache/routing checks and five neighboring compression cases pass on this branch; real benign/malicious CLI scans preserve scanner selection, JSON findings, SHA-256 metadata, and exit codes 0/1. Ruff checks pass. Changed-file mypy passes; full local mypy retains the previously documented optional TensorFlow baseline error. Hosted CI validates the published head.

  • Retained ZIP-routing regressions cover malicious Keras/PyTorch archives, benign lookalikes, and nested fallback/selection. All 17 focused cases pass on both the parent and current PR5, without skips (tests/test_core.py, tests/scanners/test_zip_scanner.py, and tests/test_scanner_selection.py). Independent AST comparison confirms the extracted selector matches both former branch bodies.

  • The integrated committed prefix passed 1,956 affected tests with three Windows-only and two opt-in integration skips. Four fresh-process regressions cover package import order; identity normalization retains the exact historical URL-normalization expression.

  • 13,390 nonoverlapping cases passed across completed scanner/core/model/analysis/registry cohorts and bounded JIT/PyTorch ZIP checks. Subsequent integration corrections are covered by the affected-prefix run above.

  • On the actual stacked prefix, 383 focused model/result/registry/routing/JIT cases passed, plus 98 adapter cases with the local standalone package and 98 against published modelaudit-picklescan==0.1.10.

  • 28 actual CLI executions (14 parent/candidate pairs) match for JSON/SARIF and SBOM output, terminal output, finding/detail order, and exit codes 0/1/2. Only measured run metadata, checkout/output locations, and generated archive extraction paths are normalized; native counter-map key order is excluded because it is already nondeterministic in the parent.

  • Independent source review found no actionable boundary issue; an extracted JIT UTF-8 decoder differential matched 66,876 inputs.

  • Ruff format/check pass. Mypy 2.3.1 with the installed Python 3.12 dependency profile reports only the existing unreachable TensorFlow test import; the devbox package index cannot currently install upstream-pinned mypy 2.4.0 because its required librt is unavailable.

Limits: this is not a complete-suite pass. Full JIT, PyTorch ZIP, and filetype runs exceeded local time bounds; their bounded changed-contract cohorts completed. An obsolete masking assertion found in the interrupted PyTorch ZIP run was corrected and revalidated in PR3. Framework/platform skips and network-dependent deselections remain; remote acquisition and cross-platform CI are not claimed as locally verified.

The _matching_path_extensions helper is introduced here for the acquisition consolidation in PR6, where utils/sources/cloud_storage.py and utils/sources/jfrog.py consume it.

PRs 1: tooling and 2: tests have landed. Remaining review order: 3: raw evidence → 4: picklescan → 5: scanning/results → 6: acquisition/cache/progress. PR3 targets main; PRs 4–6 target the preceding branch.

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 3, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-10-03T22:22:49.355947Z 36ef1f2 New commits
🔒 Security Review ✅ Completed 2026-10-03T22:21:34.277355Z 36ef1f2 New commits
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@github-actions

github-actions Bot commented Oct 3, 2026 •

Copy link
Copy Markdown
Contributor

Workflow run and artifacts

Performance Benchmarks

Compared 13 shared benchmarks with a regression threshold of 15%.
Status: 0 regressions, 0 improved, 13 stable, 0 new, 0 missing.
Aggregate shared-benchmark median: 4.370s -> 4.375s (+0.1%).

Workload Benchmark Target Size Files Baseline Current Change Status
padded-multi-stream-upload tests/benchmarks/test_picklescan_benchmarks.py::test_picklescan_padded_multi_stream_upload multi_stream_padded 4.1 KiB 1 336.5us 368.2us +9.4% stable
warm-cache-rescan tests/benchmarks/test_scan_benchmarks.py::test_scan_warm_cached_repository_rescan release-candidate 547.3 KiB 32 153.75ms 158.91ms +3.4% stable
suspicious-pickle-intake tests/benchmarks/test_scan_benchmarks.py::test_scan_suspicious_pickle_intake suspicious-intake 183.8 KiB 4 122.26ms 126.02ms +3.1% stable
nested-payload-review tests/benchmarks/test_picklescan_benchmarks.py::test_picklescan_nested_payload_review[nested_hex] nested_hex 130 B 1 301.2us 309.4us +2.7% stable
nested-payload-review tests/benchmarks/test_picklescan_benchmarks.py::test_picklescan_nested_payload_review[nested_raw] nested_raw 78 B 1 273.3us 279.6us +2.3% stable
mixed-model-repository tests/benchmarks/test_scan_benchmarks.py::test_scan_release_candidate_repository release-candidate 547.3 KiB 32 656.97ms 666.56ms +1.5% stable
duplicate-heavy-registry tests/benchmarks/test_scan_benchmarks.py::test_scan_duplicate_registry_snapshot registry-snapshot 915.2 KiB 13 571.84ms 578.70ms +1.2% stable
single-checkpoint-preflight tests/benchmarks/test_scan_benchmarks.py::test_scan_single_checkpoint_before_load single_checkpoint.pkl 183.0 KiB 1 103.52ms 104.65ms +1.1% stable
rejected-basic-auth-candidates tests/benchmarks/test_scan_benchmarks.py::test_rejected_basic_auth_candidates_scan_linearly - 371.1 KiB 1 2.539s 2.518s -0.8% stable
clean-training-checkpoint tests/benchmarks/test_picklescan_benchmarks.py::test_picklescan_clean_training_checkpoint safe_large 278.2 KiB 1 109.48ms 108.65ms -0.8% stable
nested-payload-review tests/benchmarks/test_picklescan_benchmarks.py::test_picklescan_nested_payload_review[nested_base64] nested_base64 98 B 1 297.5us 299.6us +0.7% stable
direct-malicious-upload tests/benchmarks/test_picklescan_benchmarks.py::test_picklescan_direct_malicious_upload malicious_reduce 52 B 1 223.1us 221.8us -0.6% stable
chunked-upload-stream tests/benchmarks/test_picklescan_benchmarks.py::test_picklescan_chunked_upload_stream chunked_stream 278.2 KiB 1 111.89ms 111.99ms +0.1% stable

@mldangelo-oai

Copy link
Copy Markdown
Contributor Author

@codex review

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Copilot review overview

🔵 Needs a closer look

It spans many security-sensitive routing and result contracts without a complete full-suite or cross-platform validation run.

Review effort: Balanced
Findings: None

What changed in this PR

Consolidates security scan routing, result handling, and duplicated scanner utilities while preserving existing detection and fail-closed contracts.

Changes:

  • Centralizes routing, inconclusive-result, finding-identity, and scanner helper logic.
  • Removes unused wrappers and duplicate implementations across scanners.
  • Adds import-isolation, conversion-contract, and UTF-8 offset regressions.
File Description
tests/​test_models.py Tests imports and result conversion contracts.
tests/​scanners/​test_catboost_scanner.py Reformats scanner imports.
tests/​integrations/​test_sarif_formatter.py Updates finding-identity imports.
tests/​detectors/​test_jit_script_detector.py Updates helper usage and UTF-8 coverage.
modelaudit/​utils/​helpers/​secure_hasher.py Removes unused hashing wrappers.
modelaudit/​utils/​file/​detection.py Removes obsolete routing and buffered parsers.
modelaudit/​utils/​__init__.py Uses supported Path.is_relative_to.
modelaudit/​scanners/​zip_scanner.py Uses shared symlink resolution.
modelaudit/​scanners/​xgboost_scanner.py Uses shared inconclusive metadata handling.
modelaudit/​scanners/​weight_distribution_scanner.py Removes unused tensor sizing logic.
modelaudit/​scanners/​torchserve_mar_scanner.py Reuses configuration and normalization helpers.
modelaudit/​scanners/​torch7_scanner.py Reuses statement-boundary parsing.
modelaudit/​scanners/​tf_savedmodel_scanner.py Inlines obsolete filesystem wrappers.
modelaudit/​scanners/​text_scanner.py Removes unused documentation analysis.
modelaudit/​scanners/​tar_scanner.py Removes unused TAR validation wrapper.
modelaudit/​scanners/​sevenzip_scanner.py Simplifies extraction-budget state.
modelaudit/​scanners/​safetensors_scanner.py Uses shared inconclusive metadata handling.
modelaudit/​scanners/​rknn_scanner.py Reuses public-IP classification.
modelaudit/​scanners/​r_serialized_scanner.py Reuses public-IP classification.
modelaudit/​scanners/​pytorch_zip_scanner.py Reuses memo and base-scanner helpers.
modelaudit/​scanners/​openvino_scanner.py Reuses XML parsing and path APIs.
modelaudit/​scanners/​onnx_scanner.py Removes thin wrappers and inlines parsing logic.
modelaudit/​scanners/​oci_layer_scanner.py Removes unused model-prefix detection.
modelaudit/​scanners/​nemo_scanner.py Reuses stat identity and bounded evidence logic.
modelaudit/​scanners/​mxnet_scanner.py Reuses inconclusive-result handling.
modelaudit/​scanners/​metadata_scanner.py Calls URL redaction directly.
modelaudit/​scanners/​manifest_scanner.py Reuses integer configuration handling.
modelaudit/​scanners/​llamafile_scanner.py Removes redundant signal wrappers.
modelaudit/​scanners/​lightgbm_scanner.py Reuses public-IP classification.
modelaudit/​scanners/​keras_zip_scanner.py Shares Keras policy and result helpers.
modelaudit/​scanners/​keras_utils.py Defines shared exact-module policy.
modelaudit/​scanners/​keras_h5_scanner.py Shares Keras policy and result helpers.
modelaudit/​scanners/​joblib_scanner.py Reuses pickle and base-scanner helpers.
modelaudit/​scanners/​jinja2_template_scanner.py Removes unused buffered analysis paths.
modelaudit/​scanners/​jax_checkpoint_scanner.py Reuses configuration and memo helpers.
modelaudit/​scanners/​gguf_scanner.py Removes redundant URL wrappers.
modelaudit/​scanners/​executorch_scanner.py Reuses stat identity logic.
modelaudit/​scanners/​coreml_scanner.py Inlines bounded decoding and containment checks.
modelaudit/​scanners/​compressed_scanner.py Removes unused stream-copy helper.
modelaudit/​scanners/​cntk_scanner.py Inlines single-use predicates.
modelaudit/​scanners/​catboost_scanner.py Uses shared inconclusive metadata handling.
modelaudit/​scanners/​base.py Adds shared scanner result and utility helpers.
modelaudit/​scanners/​archive_member_security.py Consolidates executable-prefix and AST helpers.
modelaudit/​scanners/​archive_dispatch.py Centralizes routing and failure-result construction.
modelaudit/​scanners/​_pickle_memo.py Adds shared pickle memo coercion.
modelaudit/​scanners/​_network_indicators.py Adds shared public-IP classification.
modelaudit/​scanners/​_evidence_redaction.py Removes redundant redaction wrappers.
modelaudit/​scanner_selection.py Simplifies aliases and adds extension matching.
modelaudit/​scanner_results.py Inlines member-hash identity serialization.
modelaudit/​models.py Consolidates finding conversion and coverage checks.
modelaudit/​integrations/​sbom_generator.py Updates finding-identity import.
modelaudit/​integrations/​sarif_formatter.py Updates finding-identity import.
modelaudit/​integrations/​mlflow.py Updates finding-identity import.
modelaudit/​integrations/​_mlflow_identity.py Inlines URL redaction behavior.
modelaudit/​finding_identity.py Relocates finding-identity helpers.
modelaudit/​detectors/​secrets.py Removes an unused authentication predicate.
modelaudit/​detectors/​network_comm.py Removes redundant URL/context wrappers.
modelaudit/​detectors/​cve_patterns.py Consolidates CVE attribution construction.
modelaudit/​core.py Delegates routing and result helpers.
modelaudit/​core_results.py Centralizes result classification and merging.
modelaudit/​cli.py Updates finding-identity imports.
modelaudit/​analysis/​unified_context.py Removes unused layer counting.
modelaudit/​analysis/​semantic_analyzer.py Removes unused visitor state.
modelaudit/​analysis/​opcode_sequence_analyzer.py Simplifies severity aggregation.
modelaudit/​analysis/​entropy_analyzer.py Derives float count from collected values.

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

@chatgpt-codex-connector

Copy link
Copy Markdown

🛡️ Codex Security Review · Automatically triggered

Security review completed. No security issues were found in this pull request.

Reviewed commit: 64b58bf593

View security finding report

Only the user who started this review can view the report in Codex.

ℹ️ About Codex security reviews in GitHub

This is an experimental Codex feature. Security reviews are triggered when:

  • You comment "@codex security review"
  • A regular code review gets triggered (for example, "@codex review" or when a PR is opened), and you’re opted in so security review runs alongside code review

Once complete, Codex will leave suggestions, or a comment if no findings are found.

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Hooray!

Reviewed commit: 64b58bf593

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

@mldangelo-oai

Copy link
Copy Markdown
Contributor Author

@codex review

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Nice work!

Reviewed commit: 4b04aacf06

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Copilot review overview

🔵 Needs a closer look

The broad security-sensitive routing refactor and incomplete full-platform validation require final human review.

Review effort: Balanced
Findings: 1 Low severity

Open (1)

Comment thread modelaudit/scanner_selection.py
@chatgpt-codex-connector

Copy link
Copy Markdown

🛡️ Codex Security Review · Automatically triggered

Security review completed. No security issues were found in this pull request.

Reviewed commit: 4b04aacf06

View security finding report

Only the user who started this review can view the report in Codex.

ℹ️ About Codex security reviews in GitHub

This is an experimental Codex feature. Security reviews are triggered when:

  • You comment "@codex security review"
  • A regular code review gets triggered (for example, "@codex review" or when a PR is opened), and you’re opted in so security review runs alongside code review

Once complete, Codex will leave suggestions, or a comment if no findings are found.

@mldangelo-oai

Copy link
Copy Markdown
Contributor Author

@codex review

@mldangelo-oai

Copy link
Copy Markdown
Contributor Author

@codex review

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. 👍

Reviewed commit: 47ff4b78f1

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

@chatgpt-codex-connector

Copy link
Copy Markdown

🛡️ Codex Security Review · Automatically triggered

Security review completed. No security issues were found in this pull request.

Reviewed commit: 47ff4b78f1

View security finding report

Only the user who started this review can view the report in Codex.

ℹ️ About Codex security reviews in GitHub

This is an experimental Codex feature. Security reviews are triggered when:

  • You comment "@codex security review"
  • A regular code review gets triggered (for example, "@codex review" or when a PR is opened), and you’re opted in so security review runs alongside code review

Once complete, Codex will leave suggestions, or a comment if no findings are found.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Copilot review overview

🔵 Needs a closer look

It broadly refactors security-sensitive routing and fail-closed behavior without a complete suite or cross-platform validation.

Review effort: Balanced
Findings: 1 Low severity

Open (1)

@mldangelo-oai

Copy link
Copy Markdown
Contributor Author

@codex review

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Nice work!

Reviewed commit: 4a1b28de59

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Copilot review overview

🔵 Needs a closer look

The broad security-sensitive refactor spans routing and fail-closed behavior without a complete-suite or cross-platform validation run.

Review effort: Balanced
Findings: 1 Low severity

Open (1)

@chatgpt-codex-connector

Copy link
Copy Markdown

🛡️ Codex Security Review · Automatically triggered

Security review completed. No security issues were found in this pull request.

Reviewed commit: 4a1b28de59

View security finding report

Only the user who started this review can view the report in Codex.

ℹ️ About Codex security reviews in GitHub

This is an experimental Codex feature. Security reviews are triggered when:

  • You comment "@codex security review"
  • A regular code review gets triggered (for example, "@codex review" or when a PR is opened), and you’re opted in so security review runs alongside code review

Once complete, Codex will leave suggestions, or a comment if no findings are found.

@mldangelo-oai

Copy link
Copy Markdown
Contributor Author

@codex review

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Copilot review overview

🔵 Needs a closer look

The broad security-sensitive refactor spans many routing and fail-closed paths without a complete full-suite or cross-platform validation run.

Review effort: Balanced
Findings: 1 Low severity

Open (1)

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. More of your lovely PRs please.

Reviewed commit: 1644507375

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

@chatgpt-codex-connector

Copy link
Copy Markdown

🛡️ Codex Security Review · Automatically triggered

Security review completed. No security issues were found in this pull request.

Reviewed commit: 1644507375

View security finding report

Only the user who started this review can view the report in Codex.

ℹ️ About Codex security reviews in GitHub

This is an experimental Codex feature. Security reviews are triggered when:

  • You comment "@codex security review"
  • A regular code review gets triggered (for example, "@codex review" or when a PR is opened), and you’re opted in so security review runs alongside code review

Once complete, Codex will leave suggestions, or a comment if no findings are found.

@mldangelo-oai

Copy link
Copy Markdown
Contributor Author

@codex review

Please review the current head after integration with main 2a5185a. The new changes preserve the upstream SafeTensors FDICT fix and deterministic cache cleanup regressions. Existing review-thread replies document validated fixes, parent comparisons, and the explicit raw local evidence policy in AGENTS.md. Please verify current source and avoid repeating already addressed or intentional behavior.

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Bravo.

Reviewed commit: 687e7b08cb

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Copilot review overview

🔵 Needs a closer look

It spans security-critical routing and result contracts across many scanners without a complete full-suite or cross-platform validation run.

Review effort: Balanced
Findings: None

Resolved since last review (1)

@chatgpt-codex-connector

Copy link
Copy Markdown

🛡️ Codex Security Review · Automatically triggered

Security review completed. No security issues were found in this pull request.

Reviewed commit: 687e7b08cb

View security finding report

Only the user who started this review can view the report in Codex.

ℹ️ About Codex security reviews in GitHub

This is an experimental Codex feature. Security reviews are triggered when:

  • You comment "@codex security review"
  • A regular code review gets triggered (for example, "@codex review" or when a PR is opened), and you’re opted in so security review runs alongside code review

Once complete, Codex will leave suggestions, or a comment if no findings are found.

This branch has not been deployed

No deployments
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.

2 participants