Prompt History Repository
Component Detail
Description
Tracks which scenario prompts have been sent to which users, their delivery status, and whether the user acted on or dismissed them. Used by the scheduler to prevent duplicate prompt delivery and by the UI to mark prompts as read or acted upon.
prompt-history-repository
Summaries
The Prompt History Repository is a critical guardrail that prevents the scenario prompting system from degrading into spam. By maintaining a precise record of which prompts have been sent, acted upon, or dismissed for each user, it ensures members only receive timely, relevant suggestions — not repeated nudges for situations already handled. This protects user trust and app retention, which are foundational to the platform's long-term engagement value. Without this component, the scenario engine would risk alienating users through over-notification, directly undermining the relationship-building mission the product is designed to support and eroding the perceived quality of the platform's intelligence features.
Medium complexity with dual execution context (backend and mobile), this repository must be delivered before end-to-end scenario evaluation testing can occur, as the Scenario Evaluation Edge Function depends on hasPromptBeenSent for its core deduplication guarantee. Coordinate delivery with the edge function team to ensure the backend query interface is finalized early in the sprint cycle. Testing requires simulating multi-user, multi-scenario states to validate deduplication logic under concurrent scheduler runs. The watchActivePrompts streaming interface needs UI integration testing with the notification inbox or badge system.
Plan for QA data-seeding scripts to populate realistic prompt history states across test accounts, as empty-database test runs will not surface timing or deduplication issues.
Backed by a Supabase table (e.g., scenario_prompt_history) with columns for user_id, scenario_id, activity_id, status (sent/acted/dismissed), and sent_at timestamp. The hasPromptBeenSent query uses a composite lookup on (userId, scenarioId, activityId) — index this combination for scheduler performance during bulk evaluation runs across large chapters. recordSentPrompt should use upsert logic to handle race conditions from concurrent edge function invocations. watchActivePrompts subscribes to Supabase Realtime filtered by userId and status not in (dismissed, acted).
markActedUpon is called by the deep-link handler post-navigation; markDismissed is called by UI gesture handlers. Both mutations should be fire-and-forget on the mobile side with structured error logging. On the backend, both must be awaited within the scheduler's try/catch block to confirm state before the next evaluation cycle.
Responsibilities
- Record sent prompts with user ID, scenario ID, and activity reference
- Query sent prompt history for deduplication
- Update prompt status (sent, acted, dismissed)
- Fetch active (unacted, undismissed) prompts for a user
Interfaces
recordSentPrompt(ScenarioPrompt prompt): Future<void>
hasPromptBeenSent(String userId, String scenarioId, String activityId): Future<bool>
getActivePromptsForUser(String userId): Future<List<ScenarioPrompt>>
markActedUpon(String promptId): Future<void>
markDismissed(String promptId): Future<void>
watchActivePrompts(String userId): Stream<List<ScenarioPrompt>>
Relationships
Dependents (3)
Components that depend on this component
Related Data Entities (2)
Data entities managed by this component