Register services in Riverpod provider graph
epic-document-attachments-services-task-008 — Create Riverpod providers for AttachmentUploadService and AttachmentSignedUrlService. Inject StorageAdapter and ActivityAttachmentRepository as dependencies. Ensure providers are scoped correctly (per-org or global) so multi-org sessions do not share cache state across tenant boundaries. Export provider references for use in Bloc and UI layers.
Acceptance Criteria
Technical Requirements
Execution Context
Tier 4 - 323 tasks
Can start after Tier 3 completes
Implementation Notes
Use `riverpod` 2.x with code generation (`@riverpod` annotation) or manual `Provider`/`NotifierProvider` depending on the project's existing convention — match the existing pattern. For org-scoped providers, use `ProviderScope` overrides at the org-session level. The recommended pattern: define a `currentOrgIdProvider` (a `StateProvider
Place all attachment providers in `lib/features/attachments/providers/attachment_providers.dart`. Export via the feature barrel `lib/features/attachments/attachments.dart`. Keep providers thin — no business logic in provider bodies, only construction and dependency wiring.
Testing Requirements
Unit/integration tests (flutter_test with ProviderContainer): (1) `attachmentUploadServiceProvider` resolves to a non-null `AttachmentUploadService` instance with correct dependencies injected — verify via type check and mock dependency tracing, (2) `attachmentSignedUrlServiceProvider` resolves with default TTL of 3300 seconds unless overridden, (3) Override test: provide a mock StorageAdapter via `ProviderContainer(overrides: [...])` and verify AttachmentUploadService uses the mock, (4) Scope isolation test: two ProviderContainers with different org scopes — adding a cache entry to one does not appear in the other, (5) Disposal test: dispose a ProviderContainer and verify the service's cache map is cleared. Use Riverpod's `ProviderContainer` directly in tests — do not rely on widget tests for provider scoping verification.
The storage upload succeeds but the subsequent metadata insert fails. The rollback delete call to Supabase Storage could itself fail (network error, transient timeout), leaving an orphaned object in the bucket with no database record pointing to it — a cost and compliance risk that also breaks delete-on-cascade logic.
Mitigation & Contingency
Mitigation: Wrap the rollback delete in a retry loop (3 attempts, exponential back-off). Log orphaned-object incidents to a dedicated structured log stream for periodic audit. Consider a scheduled Supabase Edge Function that reconciles storage objects against database records and flags orphans.
Contingency: If orphaned objects accumulate, run the reconciliation edge function manually to identify and purge them. Add a monitoring alert for metadata insert failures after successful uploads so the issue is caught within minutes.
If the signed URL TTL is set too short, users browsing the attachment preview modal on slow connections will receive expired URLs before the content loads, causing a broken experience. If set too long, a URL shared outside the app (e.g., pasted into a chat) remains valid beyond the intended access window.
Mitigation & Contingency
Mitigation: Default TTL to 60 minutes, configurable via a named constant. The in-memory cache TTL should be set to TTL minus 5 minutes to ensure cached URLs are refreshed before they expire. Document the trade-off in code comments.
Contingency: If users report broken previews, shorten the cache TTL hotfix. If a URL leak is reported, rotate the Supabase storage signing secret to invalidate all outstanding signed URLs immediately.
The multi-attachment user story requires parallel uploads with individual progress indicators. Managing concurrent BLoC events for 3–5 simultaneous uploads risks state collisions, progress indicator mixups, or partial rollbacks that are difficult to reason about.
Mitigation & Contingency
Mitigation: Design the BLoC to maintain a per-attachment upload state map keyed by a client-generated UUID. Each upload runs as an isolated Future with its own result emitted as a typed event. Write integration tests for 3-concurrent-upload scenarios.
Contingency: If state collisions occur in production, fall back to sequential upload processing (one at a time) gated behind a feature flag until the concurrent model is stabilised.