gabriel / muse public
fix minor fix/hub-trust-parallel-race #1 / 1
AI Agent gabriel · 64 days ago · Apr 12, 2026 · Diff

fix: thread-safe hub_trust check_and_pin — eliminate parallel-pack warnings

Parallel pack uploads (_PACK_WORKERS=8 threads) all call check_and_pin() simultaneously. The old code: each thread writes to the same .toml.tmp path then calls os.replace(tmp, hub_trust.toml). Race:

Thread A: writes .toml.tmp Thread B: writes .toml.tmp (overwrites A's content) Thread A: os.replace(.toml.tmp, hub_trust.toml) ← succeeds, deletes .tmp Thread B: os.replace(.toml.tmp, hub_trust.toml) ← FAILS, .tmp is gone → '[Errno 2] No such file or directory' warning x4 per 8-pack push

Fix: _TRUST_LOCK = threading.Lock() guards the entire read-modify-write cycle (load_hub_trust_store → update → _save_hub_trust_store).

The slow part (TLS handshake via _cert_fingerprint_from_response) runs BEFORE acquiring the lock, so threads only serialize on the file I/O portion (~microseconds), not on the network round-trip.

sha256:b4cbb591e22097e5d224fca501da5569fdf31a75c2a7c81d4fc1fc499afa4d0a sha
sha256:170e16e1275589a7422bb93d21ef05717ac4742e0ddd8f4a6c101e10cd26ff95 snapshot
← Older Oldest on fix/hub-trust-parallel-race
All commits
Newer → Latest on fix/hub-trust-parallel-race

0 comments

No comments yet. Be the first to start the discussion.

To add a comment, use the Muse CLI: muse hub commit comment sha256:b4cbb591e22097e5d224fca501da5569fdf31a75c2a7c81d4fc1fc499afa4d0a --body "your comment"