python student-tests/orphan_cleanup.py
injected: stale pending row + object (PUT ok, COMMIT failed), fresh pending row + object (upload in progress), orphan object without a row; plus one ready attachment
1. dry-run: {"dry_run": true, "grace_seconds": 900, "stale_pending": 1, "pending_deleted": 0, "orphan_objects": 0, "orphans_deleted": 0, "missing_objects": 0, "objects_in_bucket": 49, "ready_rows": 46, "pending_rows": 5, "seconds": 0.132}
2. cleanup, grace 900 s: {"dry_run": false, "grace_seconds": 900, "stale_pending": 1, "pending_deleted": 1, "orphan_objects": 0, "orphans_deleted": 0, "missing_objects": 0, "objects_in_bucket": 48, "ready_rows": 46, "pending_rows": 4, "seconds": 0.138}
   stale object and row removed; fresh pending, fresh orphan and the ready attachment kept
3. repeated run: {"dry_run": false, "grace_seconds": 900, "stale_pending": 0, "pending_deleted": 0, "orphan_objects": 0, "orphans_deleted": 0, "missing_objects": 0, "objects_in_bucket": 48, "ready_rows": 46, "pending_rows": 4, "seconds": 0.129}
4. cleanup, grace 2 s (test only): {"dry_run": false, "grace_seconds": 2, "stale_pending": 4, "pending_deleted": 4, "orphan_objects": 1, "orphans_deleted": 1, "missing_objects": 0, "objects_in_bucket": 47, "ready_rows": 46, "pending_rows": 0, "seconds": 0.165}
   after the grace period the old pending upload and the orphan object are removed too; the ready attachment is never touched
5. client aborted an upload after 800531 of 2401593 bytes: rows in chat 1 -> 1, objects in bucket 46 -> 46
PASS: failures between S3 and PostgreSQL leave no permanent unaccounted objects; the grace period protects uploads in progress; dry-run and repeated runs are safe; an aborted upload stores nothing
