Hosted rollback and remove refuse every Hatch 1.18 locked environment, because Hatch writes pylock.toml with --no-header

Ouverte
#2,295 0 commentaires 0 réactions 0 personnes assignées Voir sur GitHub

Les mainteneurs répondent en général sous 1 jour

Personne n'a encore pris cette issue.

Évaluation

Difficulté
4/5
Temps estimé
3-5 jours
Accessibilité débutants
45/100
Type d'issue
Bug
Clarté
Clairement spécifiée
Activité
Active
Stack technique
python, rust
Domaine
backend, cli

Piste de recherche

Start at crates/socket-patch-core/src/patch/redirect/upstream/uv.rs around the reported check near line 428, then trace how Hatch locked environments and their config are identified. Read the hosted restore tests and docs/testing/hatch.md; add coverage for a Hatch 1.18 lock without the uv header, including rollback and remove. Done when those operations restore the lock and paired pyproject.toml as expected while arbitrary headerless uv locks still follow the documented refusal.

Rédigé par le modèle d'indexation à partir du texte de l'issue.

Description

agent:triaged bug bughunt pm:hatch priority:p1

[agent] Found by the scheduled Hatch bug-hunt routine (ledger #314).

Summary

Hatch 1.18.0 and newer write every locked environment's pylock.toml / pylock.<env>.toml with uv pip compile ... --generate-hashes --no-header (hatch/env/lockers/uv.py), so the lock has no # uv pip compile ... header. Since #1614 (8127450, 2026-10-21) the hosted restore refuses any uv-written PEP 751 lock that doesn't record its command line. So on Hatch 1.18.x, socket-patch rollback and socket-patch remove refuse every hosted-wired locked Hatch environment, even with a PyPI sibling package in the lock. They exit 1 with nothing rolled back:

Error: Cannot restore pkg:pypi/[email protected] to its upstream registry entry: pylock.toml: pylock.toml: the lock does not record the `uv pip compile` command line, whose flags may filter which release files it records; restore it from version control instead (`git checkout -- pylock.toml pyproject.toml`)

The same project locked by Hatch 1.17.0, which still writes the header, rolls back byte-exact. Adding that header back to a Hatch 1.18.2 lock by hand also makes the same rollback byte-exact, so the missing header is the only trigger.

Hatch's locker command line isn't unknown. Hatch builds it from the project's own config: --generate-hashes --no-header, the env's python, extras / groups and index-source args. Hatch also re-derives the lock from pyproject whenever the dependency hash changes (#479 / docs/testing/hatch.md). The refusal is meant for an arbitrary uv pip compile --no-header lock whose filter flags really are unknowable, but it also fires on Hatch's own locks.

Impact

On the newest Hatch, hosted rollback and remove don't work for any project that uses Hatch locked environments (locked = true, lock-envs = true, lock-filename). The common path for those projects (scan → install → rollback) ends at an error. It fails closed: nothing is written, the project still installs the patched wheel, and git checkout gets you out. But remove can't take a patch out, and a user without the original in version control has no way back except hand-editing two files.

Repro (Linux, Hatch 1.18.2 with bundled uv 0.13.10, local mock patch API serving a patched six 1.16.0 wheel)

mkdir demo && cd demo && git init -q
cat > pyproject.toml <<'T'
[build-system]
requires = ["hatchling"]
build-backend = "hatchling.build"
[project]
name = "demo"
version = "0.1.0"
dependencies = [
  "six==1.16.0",
  "toml==0.10.2",
]
[tool.hatch.envs.default]
installer = "uv"
locked = true
T
mkdir -p src/demo && echo 'import six' > src/demo/__init__.py
hatch dep lock                       # pylock.toml, no header
git add -A && git commit -qm init
socket-patch scan --mode hosted --yes --ecosystems pypi --api-url $MOCK --patch-server-url $MOCK --org test-org --api-token x
# exit 0; rewrites pyproject.toml + pylock.toml; a fresh `hatch run` gets the patched six
socket-patch rollback --yes --api-url $MOCK --patch-server-url $MOCK --org test-org --api-token x
# exit 1, error above; git status still shows both files modified
socket-patch remove pkg:pypi/[email protected] --yes ...   # same error, exit 1

Expected

CLI_CONTRACT.md (rollback, hosted restore): for PEP 751 pylock*.toml "+ the paired pyproject.toml", the original entry is restored with hashes re-derived from PyPI's JSON API. This worked for Hatch 1.17 locks, and the Hatch 1.18.1 hosted rollback / remove cell passed on main before #1614. docs/testing/hatch.md doesn't list locked-env rollback as a refusal.

Actual

rollback / remove exit 1 (rollback_failed, "nothing was rolled back: 1 patch failed") for every Hatch 1.18 locked env.

Versions

socket-patch Hatch Lock rollback / remove
main cfc870f 1.17.0 pylock.toml (header) pass, byte-exact
main cfc870f 1.18.1 pylock.toml (--no-header) fail
main cfc870f 1.18.2 pylock.toml (locked = true) fail
main cfc870f 1.18.2 pylock.lint.toml (lock-envs = true, env-only dep) fail
main cfc870f 1.18.2 same lock with the 1.17-style header added by hand pass, byte-exact
v5.1.0 1.17.0 header pass
v5.1.0 1.18.1 / 1.18.2 --no-header fail

Not a regression since v5.1.0 (the release fails the same way). It is a regression in the 5.1 cycle: the bug-hunt ledger recorded Hatch 1.18.1 hosted rollback / remove passing on main before 2026-10-21. First bad commit by pickaxe: 8127450 "Fix uv restore ignoring lock file filters (#1604, #1613) (#1614)".

Suspect code

crates/socket-patch-core/src/patch/redirect/upstream/uv.rs:428: if pep751 && pip_compiled(...) refuses when uv_header_command finds no header, and doesn't check whether the lock is a Hatch locked environment's lock, whose locker flags can be derived from the Hatch config.

Linux only. Hatch's locker passes the same flags on macOS and Windows, so I expect the same result there.


Generated by Claude Code

Langage dominant
Rust
Étoiles
9
Forks
2
Merge moyen
1 j 8 h
PR mergées (30 j)
313

Préparer son environnement

Par où commencer

  1. Lisez l'issue en entier, puis le guide de contribution du projet.
  2. Signalez en commentaire que vous la prenez — cela évite que deux personnes fassent le même travail.
  3. Forkez le dépôt et travaillez sur une branche.
  4. Ouvrez une pull request qui référence le numéro de l'issue.

Autres issues de SocketDev/socket-patch

Toutes les issues de SocketDev/socket-patch

Issues similaires

Plus d'issues Rust

Recevez les nouvelles issues par e-mail

Un résumé court des issues GitHub adaptées aux débutants.