Keep Drive permission expiry across delivery retry
Keep Drive permission expiry across delivery retries
Description
When deliver_recording (src/recording/transfer.rs) shares a file through Google Drive, share_file grants a time-limited permission with expires_at = clock.now() + retention_seconds and stores drive_permission_id via set_drive_permission, while finish_delivery previously wrote recordings.expires_at only in the subsequent finish step. When finish_delivery failed and the delivery was retried after DELIVERY_BACKOFF_SECONDS, the next attempt computed a fresh, later expires_at from the clock, skipped the Drive share call because existing_permission was already set, and overwrote recordings.expires_at with the later timestamp—leaving the row and the status route (GET /api/recordings/{id}) reporting a deadline later than the expirationTime that Google Drive holds.
This change implements Option 1 from #665:
set_drive_permission(src/recording/transfer.rs) writesSET drive_permission_id = ?2, expires_at = ?3atomically when the Drive permission is recorded, andfinish_deliverytransitions the row tostate = 'ready'without overwritingexpires_aton retry.forget_drive_file(src/recording/transfer.rs) clearsexpires_at = NULLalongsidedrive_file_id = NULLanddrive_permission_id = NULLwhen a lost race cleans up an uncompleted delivery.
Validation Plan
- Retried delivery expiry preservation (
tests/recording.rs—transfer_retry_after_share_keeps_the_drive_expiry):- Run
run_delivery_queuewith aFakeDeliverydouble that records theexpires_atpassed toshare, while a SQLite trigger aborts thefinish_deliveryupdate (WHEN NEW.state = 'ready') on the first attempt. - Remove the trigger, advance the clock by
DELIVERY_BACKOFF_SECONDS[0](60seconds), and runrun_delivery_queuea second time. - Assert that
FakeDeliveryreceived only onesharecall and thatrecordings.expires_atequals the originalt0 + RETENTION_SECONDSfrom the Drive permission rather thant0 + 60 + RETENTION_SECONDS.
- Run
- Lost-race cleanup (
tests/recording.rs—failure_drive_loser_stops_naming_the_file_it_deleted):- Verify that when a delivery loses the row race and
forget_drive_fileruns,(drive_file_id, drive_permission_id, expires_at)are all reset to(None, None, None).
- Verify that when a delivery loses the row race and
- Repository gates & mutation coverage:
cargo fmt -- --checkandcargo clippy --all-targets -- -D warningscargo test --test recording
Closes #665
Summary by cubic
Keeps the Google Drive permission's expiry across delivery retries. A retry after a failed finish_delivery used to recompute a later expires_at from the clock, skip re-sharing because the permission already existed, and overwrite the stored deadline; now the stored expiry survives, an expired grant blocks the retry and is cleared so the next attempt shares afresh. Closes #665.
Bug Fixes
set_drive_permissionstoresexpires_atalongsidedrive_permission_id, andfinish_deliverykeeps it on retry.finish_deliveryrefuses to mark the recordingreadywhen the saved grant has expired or carries no recorded expiry, then revokes and clears the grant so the next retry shares afresh.forget_drive_fileclearsexpires_atwith the Drive handles during lost-race cleanup.due_for_deletion, the cleanup script, and the summary and replay views honorexpires_atonly forreadyor operator-deleted rows, ignoring it fortransferringandfailed.