feat(api): owner cancel endpoint for active upload sessions #952

Merged
chris merged 3 commits from feat/dismiss-interrupted-uploads into main 2026-09-28 23:22:29 +02:00
Owner

Summary

Adds POST /api/upload-activity/{sessionId}/cancel so the owner can discard interrupted (stale) upload sessions from the media activity dialog — the manual escape hatch for sessions stuck in receiving (see ISSUE-060).

  • Endpoint: owner-scoped; unknown/foreign sessions → 404 (no existence leak); already-cancelled → 200 idempotent no-op (no SSE); other terminal states → 409 ProblemDetail with code: upload_session_not_cancellable; malformed UUID → 400 (Spring default).
  • Atomic transition: single guarded UPDATE ... SET status='cancelled' WHERE status IN (created/receiving/commit_requested/committing); pre-read only classifies outcomes, post-race re-read avoids stale classification.
  • SSE: upload_activity_changed published after commit, only on actual change — dialog updates via existing refetch flow.
  • Cancellation-safety guards (race-hardening):
    • UploadReceiveService: rejects files for sessions not in created/receiving (409) before staging IO; the trailing SET status='receiving' is WHERE-guarded so receive can never resurrect a cancelled session.
    • UploadCommitService: rejects commits on cancelled/expired/failed (409); finishSession completion 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).
  • Module compiles clean (main + test).

Known residual window (accepted, documented)

Receive/commit check-then-act is not fully serializable against cancel, but every state-writing UPDATE is WHERE-guarded: cancelled can never be overwritten. A racing partial commit may leave already-committed files under a cancelled session (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.

## Summary Adds `POST /api/upload-activity/{sessionId}/cancel` so the owner can discard interrupted (stale) upload sessions from the media activity dialog — the manual escape hatch for sessions stuck in `receiving` (see ISSUE-060). - **Endpoint**: owner-scoped; unknown/foreign sessions → 404 (no existence leak); already-cancelled → 200 idempotent no-op (no SSE); other terminal states → 409 ProblemDetail with `code: upload_session_not_cancellable`; malformed UUID → 400 (Spring default). - **Atomic transition**: single guarded `UPDATE ... SET status='cancelled' WHERE status IN (created/receiving/commit_requested/committing)`; pre-read only classifies outcomes, post-race re-read avoids stale classification. - **SSE**: `upload_activity_changed` published after commit, only on actual change — dialog updates via existing refetch flow. - **Cancellation-safety guards** (race-hardening): - `UploadReceiveService`: rejects files for sessions not in `created`/`receiving` (409) before staging IO; the trailing `SET status='receiving'` is WHERE-guarded so receive can never resurrect a cancelled session. - `UploadCommitService`: rejects commits on `cancelled`/`expired`/`failed` (409); `finishSession` completion 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). - Module compiles clean (main + test). ## Known residual window (accepted, documented) Receive/commit check-then-act is not fully serializable against cancel, but every state-writing UPDATE is WHERE-guarded: `cancelled` can never be overwritten. A racing partial commit may leave already-committed files under a `cancelled` session (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.
feat(api): owner cancel endpoint for active upload sessions
All checks were successful
Wiki Sync / Sync wiki from docs (push) Has been skipped
Build and Deploy / Detect changed services and test scopes (push) Successful in 6s
Build and Deploy / Android unit tests and debug APK (push) Has been skipped
Build and Deploy / Smoke API and media worker (push) Has been skipped
Build and Deploy / Smoke web (push) Has been skipped
Build and Deploy / Smoke ML worker (push) Has been skipped
Build and Deploy / Smoke people worker (push) Has been skipped
Build and Deploy / Build postgres image (push) Has been skipped
Build and Deploy / Build plants worker image (push) Has been skipped
Build and Deploy / Build converter worker image (push) Has been skipped
Build and Deploy / Deploy postgres (push) Has been skipped
Build and Deploy / Build API image (push) Has been skipped
Build and Deploy / Build media worker image (push) Has been skipped
Build and Deploy / Build ML worker image (push) Has been skipped
Build and Deploy / Build people worker image (push) Has been skipped
Build and Deploy / Build web image (push) Has been skipped
Build and Deploy / Deploy API (push) Has been skipped
Build and Deploy / Deploy web (push) Has been skipped
Build and Deploy / Deploy media worker (push) Has been skipped
Build and Deploy / Deploy ML worker (push) Has been skipped
Build and Deploy / Deploy plants worker (push) Has been skipped
Build and Deploy / Deploy people worker (push) Has been skipped
Build and Deploy / Deploy converter worker (push) Has been skipped
Build and Deploy / Clean Docker build artifacts (push) Has been skipped
Build and Deploy / Run scoped PR tests (push) Successful in 18m41s
c5f6b6f2c3
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.
chore: version bump 1.21.58
All checks were successful
Wiki Sync / Sync wiki from docs (push) Has been skipped
Build and Deploy / Detect changed services and test scopes (push) Successful in 9s
Build and Deploy / Android unit tests and debug APK (push) Has been skipped
Build and Deploy / Smoke API and media worker (push) Has been skipped
Build and Deploy / Smoke web (push) Has been skipped
Build and Deploy / Smoke ML worker (push) Has been skipped
Build and Deploy / Smoke people worker (push) Has been skipped
Build and Deploy / Build postgres image (push) Has been skipped
Build and Deploy / Build plants worker image (push) Has been skipped
Build and Deploy / Build converter worker image (push) Has been skipped
Build and Deploy / Deploy postgres (push) Has been skipped
Build and Deploy / Build API image (push) Has been skipped
Build and Deploy / Build media worker image (push) Has been skipped
Build and Deploy / Build ML worker image (push) Has been skipped
Build and Deploy / Build people worker image (push) Has been skipped
Build and Deploy / Build web image (push) Has been skipped
Build and Deploy / Deploy API (push) Has been skipped
Build and Deploy / Deploy web (push) Has been skipped
Build and Deploy / Deploy media worker (push) Has been skipped
Build and Deploy / Deploy ML worker (push) Has been skipped
Build and Deploy / Deploy plants worker (push) Has been skipped
Build and Deploy / Deploy people worker (push) Has been skipped
Build and Deploy / Deploy converter worker (push) Has been skipped
Build and Deploy / Clean Docker build artifacts (push) Has been skipped
Build and Deploy / Run scoped PR tests (push) Successful in 7m43s
17c9dda3eb
merge: resolve version bump conflict (1.21.58)
All checks were successful
Wiki Sync / Sync wiki from docs (push) Has been skipped
Build and Deploy / Detect changed services and test scopes (push) Successful in 4s
Build and Deploy / Android unit tests and debug APK (push) Has been skipped
Build and Deploy / Smoke API and media worker (push) Has been skipped
Build and Deploy / Smoke web (push) Has been skipped
Build and Deploy / Smoke ML worker (push) Has been skipped
Build and Deploy / Smoke people worker (push) Has been skipped
Build and Deploy / Build postgres image (push) Has been skipped
Build and Deploy / Build plants worker image (push) Has been skipped
Build and Deploy / Build converter worker image (push) Has been skipped
Build and Deploy / Deploy postgres (push) Has been skipped
Build and Deploy / Build API image (push) Has been skipped
Build and Deploy / Build media worker image (push) Has been skipped
Build and Deploy / Build ML worker image (push) Has been skipped
Build and Deploy / Build people worker image (push) Has been skipped
Build and Deploy / Build web image (push) Has been skipped
Build and Deploy / Deploy API (push) Has been skipped
Build and Deploy / Deploy web (push) Has been skipped
Build and Deploy / Deploy media worker (push) Has been skipped
Build and Deploy / Deploy ML worker (push) Has been skipped
Build and Deploy / Deploy plants worker (push) Has been skipped
Build and Deploy / Deploy people worker (push) Has been skipped
Build and Deploy / Deploy converter worker (push) Has been skipped
Build and Deploy / Clean Docker build artifacts (push) Has been skipped
Build and Deploy / Run scoped PR tests (push) Successful in 3m51s
968f8f9efd
chris merged commit 6335973eaf into main 2026-09-28 23:22:29 +02:00
Sign in to join this conversation.
No reviewers
No labels
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
chris/memories!952
No description provided.