feat(api): owner cancel endpoint for active upload sessions #952
Loading…
Reference in a new issue
No description provided.
Delete branch "feat/dismiss-interrupted-uploads"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Summary
Adds
POST /api/upload-activity/{sessionId}/cancelso the owner can discard interrupted (stale) upload sessions from the media activity dialog — the manual escape hatch for sessions stuck inreceiving(see ISSUE-060).code: upload_session_not_cancellable; malformed UUID → 400 (Spring default).UPDATE ... SET status='cancelled' WHERE status IN (created/receiving/commit_requested/committing); pre-read only classifies outcomes, post-race re-read avoids stale classification.upload_activity_changedpublished after commit, only on actual change — dialog updates via existing refetch flow.UploadReceiveService: rejects files for sessions not increated/receiving(409) before staging IO; the trailingSET status='receiving'is WHERE-guarded so receive can never resurrect a cancelled session.UploadCommitService: rejects commits oncancelled/expired/failed(409);finishSessioncompletion UPDATE is WHERE-guarded + row-checked so a cancel landing mid-commit rolls back the whole transaction.Test plan
rtk ./gradlew :apps:api:test --tests 'dev.memories.api.upload.*'— 52 tests, 0 failures (UploadActivityTest +5: success+SSE, idempotent no-op, terminal→409 for completed/expired, unknown/foreign→404 incl. no-leak, MockMvc contract; UploadCommitServiceTest +1; UploadReceiveServiceTest +1).Known residual window (accepted, documented)
Receive/commit check-then-act is not fully serializable against cancel, but every state-writing UPDATE is WHERE-guarded:
cancelledcan never be overwritten. A racing partial commit may leave already-committed files under acancelledsession (same semantics as a mid-commit crash; feed shows cancelled with committedCount>0). Full-commit races roll back atomically.Web half (Discard button in ActivityDialog) follows in a separate PR against this contract. Version bump 1.21.58.
POST /api/upload-activity/{sessionId}/cancel lets the session owner discard an interrupted (stale) upload so it disappears from the cross-device activity feed (spec 049 S6, ADR-0097 scoping). - Owner-scoped guarded UPDATE (status IN created/receiving/ commit_requested/committing -> cancelled); unknown/foreign 404, other terminal 409 ProblemDetail code=upload_session_not_cancellable, already-cancelled idempotent 200 no-op; upload_activity_changed SSE published only on actual transition. - Cancellation-safety: receive now rejects non-created/receiving sessions before staging and its status UPDATE is WHERE-guarded; commit rejects cancelled/expired/failed sessions and finishSession's completion UPDATE is guarded + row-checked so a concurrent cancel rolls the in-flight commit back instead of resurrecting the session.