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

Aperta
#2,295 0 commenti 0 reazioni 0 assegnatari Vedi su GitHub

I maintainer di solito rispondono entro 1 giorno

Nessuno ha ancora preso questa issue.

Valutazione

Difficoltà
4/5
Tempo stimato
3-5 giorni
Idoneità per principianti
45/100
Tipo di issue
Bug
Chiarezza
Specificata chiaramente
Stato di attività
Attiva
Stack tecnologico
python, rust
Ambito
backend, cli

Direzione di ricerca

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.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

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

Lingua principale
Rust
Stelle
9
Fork
2
Merge medio
1g 8h
PR unite (30g)
313

Preparare l'ambiente

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di SocketDev/socket-patch

Tutte le issue di SocketDev/socket-patch

Issue simili

Altre issue su Rust

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.