Skip to content

fix: stop --reproduce from crashing for installations from an archive URL - #35

Merged
redchupa merged 1 commit into
masterfrom
fix/reproduce-archive-installs
Dec 4, 2026
Merged

redchupa merged 1 commit into
masterfrom
fix/reproduce-archive-installs

Conversation

@redchupa

@redchupa redchupa commented Dec 4, 2026

Copy link
Copy Markdown
Owner

What and why

This is not a roadmap item. It fixes a pre-existing bug (upstream p-e-w/heretic has the same code) that was found while preparing the v2.2.0 release in #33.

Problem. get_heretic_version_info() records Heretic installed from an archive or wheel URL with metadata.type = "unknown". That happens, for example, after

pip install https://github.com/redchupa/ai-security/archive/refs/tags/v2.2.0.zip

(GitHub's "Source code" archive of a release) or pip install <wheel URL>. format_version_information() knew only pypi, git and local, and raised ValueError: unknown metadata.type value in version information: unknown for anything else. check_environment() formats both the installed version and the manifest's environment.heretic, so heretic --reproduce crashed on such an installation, and for any model made with one.

Changes.

  • reproduce.py: any type other than pypi, git and local is now formatted like metadata without a type: the version, -unknown- and a random number. That covers unknown, a missing type and a type that a newer version might write. The result never matches, so the mismatch is reported with severity critical instead of crashing. ignore_mismatches or the prompt then decides, as for any other mismatch.
  • system.py: for an archive or wheel URL (direct_url.json with url and archive_info, not file://), the metadata now also records url and archive_info, and the origin is Archive (<url>). The URL is recorded without user:password@ and without its query string. reproduce.json is uploaded with the model, and a query string can carry access tokens or signatures, such as GitLab's private_token= or pre-signed S3 URLs. pip removes only user:password@. The cost is that a URL that needs its query string to pick the file is recorded without it, but the SHA-256 that pip records still identifies what was installed.
  • utils.py: the "Non-standard installation" warning in the reproduction guide now names the archive (This system installed Heretic from an archive: <url>), and the Environment section shows (Origin: Archive (<url>)). Other unknown sources keep the old sentence.

Decisions.

  • The archive URL is recorded. Until now the reproduction guide said to install Heretic "from its original source" without saying what that was. The URL, and the SHA-256 that pip records, tell others where Heretic came from and let them check their download (uv records an empty archive_info). Git installations already record their URL.
  • The type stays "unknown" instead of a new value such as "archive". In this case reproduce.json gains two keys and nothing else changes. The pypi, git and local metadata is unchanged, so versions with and without this fix still write and compare the same strings for them. Other readers of reproduce.json, such as other Heretic versions or tools that process the manifests collected for the Heretic Grimoire, see no new type value.
  • Archive installations never match, not even two from the same URL. What a URL serves can change: a branch archive follows the branch, and the checksums of GitHub's generated archives have changed before. Matching on the recorded SHA-256 would be possible, but this PR doesn't do it.
  • What older versions still can't read: versions without this fix (upstream up to 2.1.0, and master before this PR) still raise the same ValueError for a manifest with "type": "unknown", with or without the new keys, as they already did. Writing no type at all would let them read such manifests (they treat a missing type as unknown), but it would drop a key that every manifest has had. That seemed the bigger change to a public format, so this PR doesn't do it.

Release notes. v2.2.0 isn't tagged yet. If this merges first:

Testing

  • The checks listed in CLAUDE.md pass locally, or I explain below why not.
  • No tests/*/SHA256SUMS.* file changes, or the description explains why model outputs are meant to change.

Windows 11, Python 3.12.13, torch 2.14.1+cpu.

  • CI commands: ruff format --check, ruff check --extend-select I, ty check --error-on-warning and uv build pass. The unit tests pass: 179 OK, plus the 2 expected failures as on master.
  • Reproducibility tests: I ran tests/run_tests.py on this branch and on master 2f31b2c, on the same machine.
    • The same 5 tests differ from the committed hashes in both runs: deepseek-v4, deepseek-v4-ara, gemma-3, gemma-4e and qwen3.5-moe. They are known to fail on this machine.
    • Of the 69 tests/*/model/* files, 66 are byte-identical between the two runs. The other 3 are adapter_config.json files with the same target_modules in a different order (PEFT keeps them in a set).
    • The development install is editable (local), and the version information doesn't reach the hashed files.
  • Unit tests: the new tests/test_version_info.py has 14 tests. The get_heretic_version_info() tests use a real .dist-info directory holding the direct_url.json under test. The cases are no direct_url.json (PyPI), Git, a local directory, a local wheel, an archive as written by pip 26.3, an archive as written by uv, a URL with credentials and a query string, and a Mercurial URL. The other tests cover format_version_information() for every type, check_environment() reporting the mismatch, and the reproduction guide. Run on master, 6 of the 14 fail (the ValueError, the missing URL and the generic warning). The PyPI, Git and local cases pass on both.
  • End to end:
    • pip install --no-deps https://github.com/redchupa/ai-security/archive/refs/heads/master.zip, followed by heretic --reproduce, reproduces the crash.
    • The same with this branch's archive prints the mismatch table (heretic-llm │ 2.2.0.dev0-unknown-94805 │ 2.2.0.dev0-unknown-99171 │ critical) and exits normally with --ignore-mismatches=false. That holds both for a manifest with {"type": "unknown"} and for one with the new keys.
    • From that installation, generate_reproduce_json() writes "metadata": {"type": "unknown", "url": "https://github.com/redchupa/ai-security/archive/refs/heads/fix/reproduce-archive-installs.zip", "archive_info": {"hash": "sha256=003b…", "hashes": {"sha256": "003b…"}}}, and the reproduction guide says This system installed Heretic from an archive: <that URL>.

AI use declaration

  • I wrote this pull request (code and description) entirely by myself.
  • I used AI to write some or all of this pull request, and I have reviewed all of it myself,
    understand it, and can answer questions about it without relying on the AI.

🤖 Generated with Claude Code

… URL

get_heretic_version_info() records an installation from an archive or a
wheel URL (pip install <URL>, for example GitHub's "Source code" archive
of a release) with the metadata type "unknown", which
format_version_information() rejected with a ValueError. check_environment()
formats both the installed version and the one in reproduce.json, so
heretic --reproduce failed on such an installation and for any model made
with one.

Any type other than pypi, git and local (unknown, missing, or one that a
newer version writes) is now formatted like metadata without a type: the
version, "-unknown-" and a random number, so it never matches and the
mismatch is reported.

For an archive installation, the metadata now also records the URL and
archive_info from direct_url.json, and the reproduction guide names the
URL. The URL is recorded without user info and query string, which can
carry access tokens and is published with reproduce.json. The type stays
"unknown", so reproduce.json only gains keys.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@redchupa
redchupa merged commit 5ab5062 into master Dec 4, 2026
5 checks passed
@redchupa
redchupa deleted the fix/reproduce-archive-installs branch December 4, 2026 23:17
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