Repository navigation
fix: stop --reproduce from crashing for installations from an archive URL - #35
Merged
Merged
Conversation
… 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>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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 withmetadata.type = "unknown". That happens, for example, after(GitHub's "Source code" archive of a release) or
pip install <wheel URL>.format_version_information()knew onlypypi,gitandlocal, and raisedValueError: unknown metadata.type value in version information: unknownfor anything else.check_environment()formats both the installed version and the manifest'senvironment.heretic, soheretic --reproducecrashed on such an installation, and for any model made with one.Changes.
reproduce.py: any type other thanpypi,gitandlocalis now formatted like metadata without a type: the version,-unknown-and a random number. That coversunknown, 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_mismatchesor the prompt then decides, as for any other mismatch.system.py: for an archive or wheel URL (direct_url.jsonwithurlandarchive_info, notfile://), the metadata now also recordsurlandarchive_info, and the origin isArchive (<url>). The URL is recorded withoutuser:password@and without its query string.reproduce.jsonis uploaded with the model, and a query string can carry access tokens or signatures, such as GitLab'sprivate_token=or pre-signed S3 URLs. pip removes onlyuser: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.
archive_info). Git installations already record their URL."unknown"instead of a new value such as"archive". In this casereproduce.jsongains two keys and nothing else changes. Thepypi,gitandlocalmetadata is unchanged, so versions with and without this fix still write and compare the same strings for them. Other readers ofreproduce.json, such as other Heretic versions or tools that process the manifests collected for the Heretic Grimoire, see no newtypevalue.ValueErrorfor a manifest with"type": "unknown", with or without the new keys, as they already did. Writing notypeat 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
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.
ruff format --check,ruff check --extend-select I,ty check --error-on-warninganduv buildpass. The unit tests pass: 179 OK, plus the 2 expected failures as on master.tests/run_tests.pyon this branch and on master 2f31b2c, on the same machine.tests/*/model/*files, 66 are byte-identical between the two runs. The other 3 areadapter_config.jsonfiles with the sametarget_modulesin a different order (PEFT keeps them in a set).local), and the version information doesn't reach the hashed files.tests/test_version_info.pyhas 14 tests. Theget_heretic_version_info()tests use a real.dist-infodirectory holding thedirect_url.jsonunder test. The cases are nodirect_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 coverformat_version_information()for every type,check_environment()reporting the mismatch, and the reproduction guide. Run on master, 6 of the 14 fail (theValueError, the missing URL and the generic warning). The PyPI, Git and local cases pass on both.pip install --no-deps https://github.com/redchupa/ai-security/archive/refs/heads/master.zip, followed byheretic --reproduce, reproduces the crash.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.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 saysThis system installed Heretic from an archive: <that URL>.AI use declaration
understand it, and can answer questions about it without relying on the AI.
🤖 Generated with Claude Code