Skip to content

fix: harden model validation and doctor checks - #6

Merged
programmersd21 merged 8 commits into
mainfrom
audit/model-validation-doctor-docs
Nov 28, 2026
Merged

programmersd21 merged 8 commits into
mainfrom
audit/model-validation-doctor-docs

Conversation

@programmersd21

@programmersd21 programmersd21 commented Nov 28, 2026 •

Copy link
Copy Markdown
Owner

Summary

  • reject custom model files when their header cannot be read instead of silently accepting them
  • report model-cache directory state accurately without claiming untested write access
  • add regression coverage for truncated headers and cache-path states
  • clarify the read-only doctor scope and tighten issue / pull request templates

Verification

  • added focused unit tests; CI will run formatting, Clippy, tests and MSRV checks

Summary by Sourcery

Harden custom model validation and doctor diagnostics while improving contribution templates.

Bug Fixes:

  • Reject custom model files when their headers cannot be read instead of accepting truncated or unreadable files.
  • Accurately classify model-cache paths without claiming that write access has been tested.

Enhancements:

  • Clarify that the doctor command is read-only and does not probe write permissions.

Documentation:

  • Update issue and pull request templates to request clearer reproduction details, environment information, verification steps, and relevant trade-offs.

Tests:

  • Add regression coverage for unreadable custom model headers and model-cache path states.

@sourcery-ai

sourcery-ai Bot commented Nov 28, 2026 •

Copy link
Copy Markdown

Reviewer's Guide

Implementation

Make custom-model validation reject files whose four-byte header cannot be read, rather than silently accepting truncated or unreadable headers.

  • src/model.rs L498-507, L519-520

Report cache-path readiness based on whether the cache is a directory, an invalid file path, or has a usable parent, without claiming write access was tested.

  • src/doctor.rs L28-42, L127-131

Documentation

Clarify that doctor checks configured paths but neither modifies files nor probes write permissions.

  • readme.md L336

Revise the bug-report template to request reproducible steps, environment details, doctor output, and useful transcription-quality context.

  • .github/ISSUE_TEMPLATE/bug_report.md L3, L9-16, L25-32

Refocus the feature-request template on the problem, expected behavior, alternatives, and potential trade-offs.

  • .github/ISSUE_TEMPLATE/feature_request.md L3, L9-16

Update the pull-request template to request verification commands, relevant failure modes and trade-offs, and explicit quality checks.

  • .github/pull_request_template.md L1-5, L11-20

Tests

Add regression tests for truncated custom-model headers and cache-path readiness and invalid-file states.

  • src/doctor.rs L287-320
  • src/model.rs L1386-1395

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

@coderabbitai

coderabbitai Bot commented Nov 28, 2026 •

Copy link
Copy Markdown

Important

  • Trigger review

This repository does not receive automatic reviews because it has fewer than 10 stars.

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: defaults
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: af77254b-0b4b-4fa0-8c84-5a5d3cc3e1d3
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

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

sourcery-ai[bot]
sourcery-ai Bot previously approved these changes Nov 28, 2026

@sourcery-ai sourcery-ai Bot 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.

Sourcery assessment

Approved.

@sourcery-ai sourcery-ai Bot 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.

Hey - I've found 3 issues

Prompt for AI Agents
Please address the comments from this code review:

## Individual Comments

### Comment 1
<location path="src/doctor.rs" line_range="36" />
<code_context>
+    } else if cache.parent().is_some_and(std::path::Path::is_dir) {
+        (Verdict::Warn, "will be created on first download; write access not tested")
+    } else {
+        (Verdict::Fail, "parent directory is missing")
+    }
+}
</code_context>
<issue_to_address>
**Fresh cache reports failure**

When the cache directory or one of its parent directories has not been created yet, `cache_status` returns `Fail` because it checks only the immediate parent, so `scribe --doctor` exits with status 1 for a cache tree that `DownloadLock::acquire` can create recursively; the regression test also fails because it expects `Warn`.

Treat a missing cache path as creatable when its directory tree can be created on first download, and return a warning instead of a failure.

Also at `src/doctor.rs:37`, `src/doctor.rs:290-292`.
</issue_to_address>

### Comment 2
<location path="src/doctor.rs" line_range="31" />
<code_context>
+fn cache_status(cache: &std::path::Path) -> (Verdict, &'static str) {
+    if cache.is_dir() {
+        (Verdict::Ok, "directory exists; write access not tested")
+    } else if cache.exists() {
+        (Verdict::Fail, "path exists but is not a directory")
+    } else if cache.parent().is_some_and(std::path::Path::is_dir) {
</code_context>
<issue_to_address>
**Doctor misses unusable cache**

When the configured cache path is a dangling symlink and its parent directory exists, `cache.exists()` follows symlinks and returns false, so `cache_status` reports that the cache will be created; `DownloadLock::acquire` then fails when `create_dir_all` encounters the symlink, and the user sees a download error despite the doctor warning.

Detect an occupied dangling-symlink path without following it and report it as unusable instead of saying it will be created.

Also at `src/doctor.rs:33-34`.
</issue_to_address>

### Comment 3
<location path="src/model.rs" line_range="1392" />
<code_context>
+        fs::create_dir_all(&dir).unwrap();
+        let path = dir.join("truncated.bin");
+        fs::write(&path, b"gg").unwrap();
+        assert!(read_model_header(&path).is_err());
+        fs::remove_dir_all(&dir).unwrap();
+    }
</code_context>
<issue_to_address>
**Validator rejection goes untested**

When `validate_custom` is changed to ignore a header-read error, `custom_model_header_read_errors_are_rejected` asserts only that `read_model_header` returns an error, so it still passes if `validate_custom` stops propagating that error and accepts an unreadable header.

Exercise `validate_custom` with an input that passes the minimum-size check but produces a header-read error, and assert that validation rejects it.
</issue_to_address>

Sourcery assessment

Approval pending. 3 findings to address first.

Blocking findings: src/doctor.rs:36, src/doctor.rs:31, src/model.rs:1392


Sourcery is free for open source - if you like our reviews please consider sharing them ✨

Comment thread src/doctor.rs
} else if cache.parent().is_some_and(std::path::Path::is_dir) {
(Verdict::Warn, "will be created on first download; write access not tested")
} else {
(Verdict::Fail, "parent directory is missing")

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🔴 Critical · Fresh cache reports failure

When the cache directory or one of its parent directories has not been created yet, cache_status returns Fail because it checks only the immediate parent, so scribe --doctor exits with status 1 for a cache tree that DownloadLock::acquire can create recursively; the regression test also fails because it expects Warn.

Treat a missing cache path as creatable when its directory tree can be created on first download, and return a warning instead of a failure.

Also at src/doctor.rs:37, src/doctor.rs:290-292.

Prompt for AI agents
In `src/doctor.rs` at line 36:

**Fresh cache reports failure**

When the cache directory or one of its parent directories has not been created yet, `cache_status` returns `Fail` because it checks only the immediate parent, so `scribe --doctor` exits with status 1 for a cache tree that `DownloadLock::acquire` can create recursively; the regression test also fails because it expects `Warn`.

Treat a missing cache path as creatable when its directory tree can be created on first download, and return a warning instead of a failure.

Also at `src/doctor.rs:37`, `src/doctor.rs:290-292`.

Comment thread src/doctor.rs
fn cache_status(cache: &std::path::Path) -> (Verdict, &'static str) {
if cache.is_dir() {
(Verdict::Ok, "directory exists; write access not tested")
} else if cache.exists() {

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🟡 Medium · Doctor misses unusable cache

When the configured cache path is a dangling symlink and its parent directory exists, cache.exists() follows symlinks and returns false, so cache_status reports that the cache will be created; DownloadLock::acquire then fails when create_dir_all encounters the symlink, and the user sees a download error despite the doctor warning.

Detect an occupied dangling-symlink path without following it and report it as unusable instead of saying it will be created.

Also at src/doctor.rs:33-34.

Prompt for AI agents
In `src/doctor.rs` at line 31:

**Doctor misses unusable cache**

When the configured cache path is a dangling symlink and its parent directory exists, `cache.exists()` follows symlinks and returns false, so `cache_status` reports that the cache will be created; `DownloadLock::acquire` then fails when `create_dir_all` encounters the symlink, and the user sees a download error despite the doctor warning.

Detect an occupied dangling-symlink path without following it and report it as unusable instead of saying it will be created.

Also at `src/doctor.rs:33-34`.

Comment thread src/model.rs
fs::create_dir_all(&dir).unwrap();
let path = dir.join("truncated.bin");
fs::write(&path, b"gg").unwrap();
assert!(read_model_header(&path).is_err());

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🟡 Medium · Validator rejection goes untested

When validate_custom is changed to ignore a header-read error, custom_model_header_read_errors_are_rejected asserts only that read_model_header returns an error, so it still passes if validate_custom stops propagating that error and accepts an unreadable header.

Exercise validate_custom with an input that passes the minimum-size check but produces a header-read error, and assert that validation rejects it.

Prompt for AI agents
In `src/model.rs` at line 1392:

**Validator rejection goes untested**

When `validate_custom` is changed to ignore a header-read error, `custom_model_header_read_errors_are_rejected` asserts only that `read_model_header` returns an error, so it still passes if `validate_custom` stops propagating that error and accepts an unreadable header.

Exercise `validate_custom` with an input that passes the minimum-size check but produces a header-read error, and assert that validation rejects it.

@sourcery-ai
sourcery-ai Bot dismissed their stale review November 28, 2026 03:49

Sourcery withdrew this approval because the latest commits introduced blocking findings.

@programmersd21
programmersd21 merged commit 797e77b into main Nov 28, 2026
5 checks passed
@programmersd21
programmersd21 deleted the audit/model-validation-doctor-docs branch November 28, 2026 03:50
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