python student-tests/cleanup_race.py
A. failed b2299717-daa4-4704-afd1-19efe898e821 (retention expired); the janitor read the references and stopped
   operator replay while the janitor waits -> {'result': 'queued', 'attempt': 2, 'previous_error': 'retry_exhausted'}
   janitor continued: deleted 0, re-checked under the lock -> kept {'current_work': 1}; staging/b2299717... is still in S3
B. failed 6c7228dc-9d9f-4b3c-9f3d-aa6692124418 (retention expired); the janitor holds the lock: staging marked deleted, no COMMIT yet
   replay waited 8.0 s for the lock -> refused (source_missing); job stays failed; journal: staging_expired -> replay_refused
   A: worker started -> ready with ['thumbnail', 'crop', 'optimized'] (before the fix: failed / source_missing)
C. upload e0578869-000a-4a70-b43b-ab12f6d5ff49: staging written, no row in the database yet (API paused before COMMIT)
   janitor (grace 0): skipped_busy 1, deleted 0 — the upload holds the attachment lock
   upload -> 202, then ready with 3 variants
D. d4abfa4b-af5e-4208-8d4e-f69a1783891b: worker wrote the original and 3 variants, COMMIT not yet (status processing)
   janitor (grace 0): the snapshot marked the original and 3 variants as unreferenced; re-checked under the lock -> kept {'current_work': 4}, deleted 0
   worker committed -> ready; the original and all variants download with the same SHA-256
PASS: the janitor re-checks the state under the attachment lock before deleting: a replay accepted after its snapshot keeps the staging (A), a replay after the janitor's decision is refused safely (B), an upload in progress (C) and objects of a job in processing (D) are not deleted
