feat(api): stale upload-session detection — spec 070 #1519
Loading…
Reference in a new issue
No description provided.
Delete branch "spec/070-stale-upload-sessions"
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?
Implements spec 070: server-side detection of dead upload sessions (client died mid-upload — battery drain, Doze kill, crash) that otherwise keep their non-terminal state forever and render 'Upload läuft…' indefinitely in the web dialog.
Backend job (new UploadSessionStaleScheduler)
@Scheduled(fixedDelay = 60000), single-instance conventions like DiscoveryReprocessScheduler.UPDATE upload_sessions SET status='stale', updated_at=:now WHERE status IN ('created','receiving','committing') AND updated_at < :cutoff(cutoff = now − timeout).memories.upload.stale-timeout, default10m, envMEMORIES_UPLOAD_STALE_TIMEOUT(Uploadproperties record extended, compact-constructor default likeMediaToken.ttl).Scope corrections vs. spec text
status IN ('receiving','processing')— no session-level 'processing' status exists, andcommit_requestedis a derived-only read status (never persisted). The job matches the persisted non-terminal set created/receiving/committing. Legacy file-levelhashingrecovery stays with UploadRecoveryService (untouched).updated_at = now()on transition — no DB trigger maintains the column; every writer updates it manually.Termination safety & UX paths
stalejoins CANCELLABLE_STATUSES in UploadActivityService — both clients expose discard for stale (web isDiscardableSession, Android cancel list); without this every discard on a persisted-stale session 409s (the incident's main UX path).staleadded to markCommitStarted/markPartialCommitFinished CASE lists and finishSession's NOT IN list; requireCommittableStatus now rejects stale up front with a clean 409 instead of a rollback at finishSession.Web — no changes
Recon confirmed the full render chain already handles persisted stale: uploadActivity.ts derivedStatus passthrough → uploadSessionServer 'Unterbrochen' label → stale-only isDiscardableSession → dialog discard button. The derived 15-minute staleness (STALE_AFTER) still covers rendering before the job's next tick — two mechanisms, one outcome.
Schema
No Flyway migration: upload_sessions.status is free TEXT (no CHECK constraint), confirmed in V001__baseline_domain.sql.
Tests
API (all green): UploadSessionStaleSchedulerTest (5: old non-terminal → stale + updated_at refreshed; recent → untouched; terminal/already-stale untouched incl. idempotence; custom timeout boundary with strict
<semantics; empty-table no-op) + UploadActivityTest extended (+2: cancel on persisted-stale succeeds; commit on persisted-stale does not resurrect).:apps:api:test --tests '*Upload*': 68 tests, 0 failures.Android (all green): BackupEngineTest +1 ('stale open batch with server-marked stale status is discarded and replaced'): 50 tests, 0 failures.